Skip to content

Commit

Permalink
compiles and also removing lint from test for now
Browse files Browse the repository at this point in the history
  • Loading branch information
esromneb committed Sep 27, 2020
1 parent cff21ab commit d045f1d
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 34 deletions.
38 changes: 6 additions & 32 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,13 @@ wasm: out/vcd.wasm
WASM_MAIN = wasm_main.cpp

HPP_FILES = \
# csrc/wrapper.hpp \
vcd_parser.h \


CPP_FILES = \
# csrc/wrapper.cpp \
# lib/BehaviorTree.CPP/src/action_node.cpp \
# lib/BehaviorTree.CPP/src/basic_types.cpp \
# lib/BehaviorTree.CPP/src/behavior_tree.cpp \
# lib/BehaviorTree.CPP/src/blackboard.cpp \
# lib/BehaviorTree.CPP/src/bt_factory.cpp \
# lib/BehaviorTree.CPP/src/decorator_node.cpp \
# lib/BehaviorTree.CPP/src/condition_node.cpp \
# lib/BehaviorTree.CPP/src/control_node.cpp \
# lib/BehaviorTree.CPP/src/shared_library.cpp \
# lib/BehaviorTree.CPP/src/tree_node.cpp \
# lib/BehaviorTree.CPP/src/decorators/inverter_node.cpp \
# lib/BehaviorTree.CPP/src/decorators/repeat_node.cpp \
# lib/BehaviorTree.CPP/src/decorators/retry_node.cpp \
# lib/BehaviorTree.CPP/src/decorators/subtree_node.cpp \
# lib/BehaviorTree.CPP/src/decorators/delay_node.cpp \
# lib/BehaviorTree.CPP/src/controls/if_then_else_node.cpp \
# lib/BehaviorTree.CPP/src/controls/fallback_node.cpp \
# lib/BehaviorTree.CPP/src/controls/parallel_node.cpp \
# lib/BehaviorTree.CPP/src/controls/reactive_sequence.cpp \
# lib/BehaviorTree.CPP/src/controls/reactive_fallback.cpp \
# lib/BehaviorTree.CPP/src/controls/sequence_node.cpp \
# lib/BehaviorTree.CPP/src/controls/sequence_star_node.cpp \
# lib/BehaviorTree.CPP/src/controls/switch_node.cpp \
# lib/BehaviorTree.CPP/src/controls/while_do_else_node.cpp \
# lib/BehaviorTree.CPP/src/loggers/bt_cout_logger.cpp \
# lib/BehaviorTree.CPP/src/loggers/bt_file_logger.cpp \
# lib/BehaviorTree.CPP/src/private/tinyxml2.cpp \
# lib/BehaviorTree.CPP/src/xml_parsing.cpp \
vcd_parser.c \
vcd_spans.c \



# this is a list of all C functions we want to publish to javascript
Expand Down Expand Up @@ -81,7 +55,7 @@ CLANG_WARN_FLAGS = \


CLANG_OTHER_FLAGS = \
-DBT_NO_COROUTINES \
-DVCDWASM \



Expand All @@ -106,7 +80,7 @@ out/vcd.wasm: $(WASM_MAIN) $(CPP_FILES) $(HPP_FILES) Makefile
-s ALLOW_TABLE_GROWTH=1 \
-s EXPORTED_FUNCTIONS='[$(EXPORT_STRING) "_main"]' \
-s EXTRA_EXPORTED_RUNTIME_METHODS='["ccall", "cwrap", "addOnPostRun", "addFunction", "setValue", "getValue"]' \
'-std=c++2a' $(CLANG_O_FLAG) $(CLANG_WARN_FLAGS) $(CLANG_OTHER_FLAGS)
$(CLANG_O_FLAG) $(CLANG_WARN_FLAGS) $(CLANG_OTHER_FLAGS)


.PHONY: patchlib patchlib1 patchlib2
Expand Down
4 changes: 3 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ const pkg = require('../package.json');
const parser = require('./parser.js');
const and = require('./and.js');
const activity = require('./activity.js');
const wrapper = require('./wrapper.js');

module.exports = {
version: pkg.version,
and: and,
activity: activity,
parser: parser
parser: parser,
wrapper: wrapper
};
40 changes: 40 additions & 0 deletions lib/wrapper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
'use strict';

function _waitForStart(mod) {
return new Promise((resolve, reject)=>{
mod.addOnPostRun(resolve);
});
}

module.exports = () => {
// let state = 0; // idle
// let total = 0;
// let start = 0;

const wasm = require('../out/vcd.js');


let start = async() => {
await _waitForStart(wasm);
}

return {
start,
log: () => {
console.log(wasm);
},
onB: (time, cmd) => {

},
onNotB: (time, cmd) => {
switch(state) {
case 0: if (cmd === 14) { state = 2; } break;
case 1: if (cmd === 14) { state = 3; start = time; } break;
case 2: if (cmd === 15) { state = 0; } break;
case 3: if (cmd === 15) { state = 1; total += (time - start); start = 0; } break;
default: throw new Error();
}
},
time: () => total + start
};
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "Value Change Dump (VCD) parser",
"main": "lib/index.js",
"scripts": {
"test": "eslint bin lib && nyc -r=text -r=lcov mocha",
"testlint": "eslint bin lib && nyc -r=text -r=lcov mocha",
"test": "nyc -r=text -r=lcov mocha",
"testonly": "nyc -r=text -r=lcov mocha",
"watch": "mocha --watch",
"install": "node bin/build.js",
Expand Down
34 changes: 34 additions & 0 deletions test/wasm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';

const expect = require('chai').expect;
// const lib = require('../lib/index.js');

const dut = require('../lib/index.js');


describe('basic', () => {

let wrapper;

// return a promise from before and mocha
// will wait for it
before(() => {
wrapper = dut.wrapper();
return wrapper.start();
});


it('wasm basic', done => {

console.log("test");

// console.log(wrapper.log());


// expect(lib.parser).to.be.an('function');
done();
});


});

22 changes: 22 additions & 0 deletions vcd_spans.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
#include <stdio.h>
#include <stdlib.h>
#include "vcd_parser.h"

#ifndef VCDWASM
#include <node_api.h>
#endif

#ifdef VCDWASM
typedef void* napi_env;
#endif




#define ASSERT(val, expr) \
if (expr != napi_ok) { \
Expand Down Expand Up @@ -60,6 +70,7 @@ int commandSpan(vcd_parser_t* state, const unsigned char* p, const unsigned char
}

if (state->command == 8) { // $enddefinitions
#ifndef VCDWASM
napi_value status, undefined, eventName, eventPayload, return_val;
ASSERT(status, napi_create_string_latin1(env, "simulation", NAPI_AUTO_LENGTH, &status))
ASSERT(state->info, napi_set_named_property(env, state->info, "status", status))
Expand All @@ -68,13 +79,15 @@ int commandSpan(vcd_parser_t* state, const unsigned char* p, const unsigned char
// ASSERT(eventPayload, napi_create_string_latin1(env, "payload", NAPI_AUTO_LENGTH, &eventPayload))
napi_value* argv[] = { &eventName }; // , &eventPayload };
ASSERT(state->lifee, napi_call_function(env, undefined, state->lifee, 1, *argv, &return_val))
#endif
return 0;
}

return 0;
}

int scopeIdentifierSpan(vcd_parser_t* state, const unsigned char* p, const unsigned char* endp) {
#ifndef VCDWASM
napi_env env = state->napi_env;
// *(endp - 1) = 0; // FIXME NULL termination of ASCII string
strcopy(p, endp, state->tmpStr);
Expand All @@ -86,6 +99,7 @@ int scopeIdentifierSpan(vcd_parser_t* state, const unsigned char* p, const unsig
ASSERT(top, napi_set_named_property(env, top, state->tmpStr, obj))
state->stackPointer += 1;
ASSERT(top, napi_set_element(env, stack, state->stackPointer, obj))
#endif
return 0;
}

Expand All @@ -95,14 +109,17 @@ int varSizeSpan(vcd_parser_t* state, const unsigned char* p, const unsigned char
}

int varIdSpan(vcd_parser_t* state, const unsigned char* p, const unsigned char* endp) {
#ifndef VCDWASM
napi_env env = state->napi_env;
napi_value varId;
ASSERT(varId, napi_create_string_latin1(env, (char*)p, (endp - p - 1), &varId))
ASSERT(state->info, napi_set_named_property(env, state->info, "varId", varId))
#endif
return 0;
}

int varNameSpan(vcd_parser_t* state, const unsigned char* p, const unsigned char* endp) {
#ifndef VCDWASM
napi_env env = state->napi_env;
// *(endp - 1) = 0; // FIXME NULL termination of ASCII string
strcopy(p, endp, state->tmpStr);
Expand All @@ -111,10 +128,12 @@ int varNameSpan(vcd_parser_t* state, const unsigned char* p, const unsigned char
ASSERT(top, napi_get_element(env, stack, state->stackPointer, &top))
ASSERT(state->info, napi_get_named_property(env, state->info, "varId", &varId))
ASSERT(state->info, napi_set_named_property(env, top, state->tmpStr, varId))
#endif
return 0;
}

int idSpan(vcd_parser_t* state, const unsigned char* p, const unsigned char* endp) {
#ifndef VCDWASM
napi_env env = state->napi_env;
const int valueWords = (state->digitCount >> 6) + 1;
uint64_t* value = state->value;
Expand Down Expand Up @@ -144,6 +163,7 @@ int idSpan(vcd_parser_t* state, const unsigned char* p, const unsigned char* end
mask[i] = 0;
}
state->digitCount = 0;
#endif
return 0;
}

Expand All @@ -153,6 +173,7 @@ int onDigit(
const unsigned char* endp,
int digit
) {
#ifndef VCDWASM
unsigned int valueCin = (digit & 1);
unsigned int maskCin = ((digit >> 1) & 1);
unsigned int valueCout;
Expand All @@ -172,6 +193,7 @@ int onDigit(

}
state->digitCount += 1;
#endif
return 0;
}

Expand Down
17 changes: 17 additions & 0 deletions wasm_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,24 @@

using namespace std;



static struct vcd_parser_s* state;


static void init(void) {
state = (struct vcd_parser_s*) malloc(sizeof *state);

const int32_t error = vcd_parser_init(state);
if (error) {
cout << "ERROR: " << error << "\n";
return;
}
}

int main(void) {
cout << "main()\n";
init();
return 0;
}

0 comments on commit d045f1d

Please sign in to comment.