diff --git a/lib/wrapper.js b/lib/wrapper.js index 4a03171..a1f24d9 100644 --- a/lib/wrapper.js +++ b/lib/wrapper.js @@ -19,7 +19,7 @@ module.exports = () => { const bindCWrap = () => { const w = wasm.cwrap; - c.execute = w('execute', 'void', ['number', 'number', 'number', 'number', 'number', 'string']); + c.execute = w('execute', 'number', ['number', 'number', 'number', 'number', 'number', 'string']); c.init = w('init', 'number', ['number', 'number', 'number', 'number']); }; diff --git a/test/wasm.js b/test/wasm.js index 8ce9889..f55b022 100644 --- a/test/wasm.js +++ b/test/wasm.js @@ -35,7 +35,7 @@ describe('basic', () => { wrapper.execute(); - expect(info.foo).to.equal(10); + // expect(info.foo).to.equal(10); // console.log(wrapper.log()); diff --git a/test/wasmdump.js b/test/wasmdump.js new file mode 100644 index 0000000..95dbdcf --- /dev/null +++ b/test/wasmdump.js @@ -0,0 +1,124 @@ +'use strict'; + +const expect = require('chai').expect; +// const lib = require('../lib/index.js'); +const lib = require('../lib/wrapper.js')(); + +describe('dump', () => { + + before(() => { + return lib.start(); + }); + + it('simple', done => { + const inst = lib.parser(); + const dump = []; + ['"}G', '{u', 'u)'] // array of all signal ids + .map(id => + inst.change.on(id, (time, cmd, value, mask) => { + dump.push({ + id, + time, + cmd, + value, + mask + }); + }) + ); + + inst.on('finish', () => { + expect(inst.getTime()).to.eq(316n); + expect(dump).to.deep.eq([ + { id: '"}G', time: 100, cmd: 14, value: 0n, mask: 0n }, + { id: '"}G', time: 200, cmd: 15, value: 1n, mask: 0n }, + { id: '{u', time: 200, cmd: 19, value: 0xf0f0f0f0f0f0f0f0n, mask: 0xff00ff00ff00ff00n }, + { id: '"}G', time: 300, cmd: 14, value: 0n, mask: 0n }, + { id: '{u', time: 300, cmd: 19, value: 0xf000000000000000n, mask: 0n }, + { id: '{u', time: 301, cmd: 19, value: 0x0f00000000000000n, mask: 0n }, + { id: '{u', time: 302, cmd: 19, value: 0x00f0000000000000n, mask: 0n }, + { id: '{u', time: 303, cmd: 19, value: 0x000f000000000000n, mask: 0n }, + { id: '{u', time: 304, cmd: 19, value: 0x0000f00000000000n, mask: 0n }, + { id: '{u', time: 305, cmd: 19, value: 0x00000f0000000000n, mask: 0n }, + { id: '{u', time: 306, cmd: 19, value: 0x000000f000000000n, mask: 0n }, + { id: '{u', time: 307, cmd: 19, value: 0x0000000f00000000n, mask: 0n }, + { id: '{u', time: 308, cmd: 20, value: 0x00000000f0000000n, mask: 0n }, + { id: '{u', time: 309, cmd: 19, value: 0x000000000f000000n, mask: 0n }, + { id: '{u', time: 310, cmd: 19, value: 0x0000000000f00000n, mask: 0n }, + { id: '{u', time: 311, cmd: 19, value: 0x00000000000f0000n, mask: 0n }, + { id: '{u', time: 312, cmd: 19, value: 0x000000000000f000n, mask: 0n }, + { id: '{u', time: 313, cmd: 19, value: 0x0000000000000f00n, mask: 0n }, + { id: '{u', time: 314, cmd: 19, value: 0x00000000000000f0n, mask: 0n }, + { id: '{u', time: 315, cmd: 19, value: 0x000000000000000fn, mask: 0n }, + { id: '"}G', time: 316, cmd: 15, value: 1n, mask: 0n }, + ]) + // console.log(dump); + done(); + }); + + inst.write(` +$version Generated by VerilatedVcd $end +$date Wed Sep 18 22:59:07 2019 + $end +$timescale 1ns $end + + $scope module top $end + $var wire 1 "}G clock $end + $scope module leaf $end + $var wire 64 {u counter [63:0] $end + $upscope $end + $scope module fruit $end + $var wire 4 u) point [3:0] $end + $upscope $end + $upscope $end + + $enddefinitions $end +#100 +0"}G +#200 +1"}G +bzzzzxxxx11110000ZZZZXXXX11110000zzzzxxx`); + +// break in the middle of the number scan + + inst.write( `x11110000zzzzxxxx11110000 {u +#300 +0"}G +b1111000000000000000000000000000000000000000000000000000000000000 {u +#301 +b0000111100000000000000000000000000000000000000000000000000000000 {u +#302 +b0000000011110000000000000000000000000000000000000000000000000000 {u +#303 +b0000000000001111000000000000000000000000000000000000000000000000 {u +#304 +b0000000000000000111100000000000000000000000000000000000000000000 {u +#305 +b0000000000000000000011110000000000000000000000000000000000000000 {u +#306 +b0000000000000000000000001111000000000000000000000000000000000000 {u +#307 +b0000000000000000000000000000111100000000000000000000000000000000 {u +#308 +B0000000000000000000000000000000011110000000000000000000000000000 {u +#309 +b0000000000000000000000000000000000001111000000000000000000000000 {u +#310 +b0000000000000000000000000000000000000000111100000000000000000000 {u +#311 +b0000000000000000000000000000000000000000000011110000000000000000 {u +#312 +b0000000000000000000000000000000000000000000000001111000000000000 {u +#313 +b0000000000000000000000000000000000000000000000000000111100000000 {u +#314 +b0000000000000000000000000000000000000000000000000000000011110000 {u +#315 +b0000000000000000000000000000000000000000000000000000000000001111 {u +#316 +1"}G +`); + inst.end(); + }); +}); + +/* eslint-env mocha */ diff --git a/vcd_spans.c b/vcd_spans.c index f872288..af0602d 100644 --- a/vcd_spans.c +++ b/vcd_spans.c @@ -11,6 +11,8 @@ typedef void* napi_env; #endif +// #define LOGSPAN +#define LOGSPAN printf("%s\n", __FUNCTION__); #define ASSERT(val, expr) \ @@ -62,6 +64,7 @@ int stringEq ( } int commandSpan(vcd_parser_t* state, const unsigned char* p, const unsigned char* endp) { + LOGSPAN; napi_env env = state->napi_env; if (state->command == 5) { // $upscope @@ -87,6 +90,7 @@ int commandSpan(vcd_parser_t* state, const unsigned char* p, const unsigned char } int scopeIdentifierSpan(vcd_parser_t* state, const unsigned char* p, const unsigned char* endp) { + LOGSPAN; #ifndef VCDWASM napi_env env = state->napi_env; // *(endp - 1) = 0; // FIXME NULL termination of ASCII string @@ -104,6 +108,7 @@ int scopeIdentifierSpan(vcd_parser_t* state, const unsigned char* p, const unsig } int varSizeSpan(vcd_parser_t* state, const unsigned char* p, const unsigned char* endp) { + LOGSPAN; state->size = strtol((const char *)p, (char **)&endp, 10); return 0; } diff --git a/wasm_main.cpp b/wasm_main.cpp index f203312..057f011 100644 --- a/wasm_main.cpp +++ b/wasm_main.cpp @@ -88,33 +88,55 @@ int init( - - - -void execute( +int32_t execute( const int context, externalJsMethodOne* f1, externalJsMethodTwo* f2, externalJsSetProperty* sfn, externalJsGetProperty* gfn, - char* chunk + char* p ) { // cout << "execute got " << p << "\n"; - cout << "execute " << (int)sfn << " and got " << chunk << "\n"; + cout << "execute " << (int)sfn << " and got " << p << "\n"; bound_set_property = sfn; bound_get_property = gfn; externalOne = f1; externalTwo = f2; - set_property_int("foo", 10); + const size_t plen = strlen(p); + + const int32_t error = vcd_parser_execute(state, p, p + plen); + + return error; +} + + + +// void execute( +// const int context, +// externalJsMethodOne* f1, +// externalJsMethodTwo* f2, +// externalJsSetProperty* sfn, +// externalJsGetProperty* gfn, +// char* chunk +// ) { + +// // cout << "execute got " << p << "\n"; +// cout << "execute " << (int)sfn << " and got " << chunk << "\n"; +// bound_set_property = sfn; +// bound_get_property = gfn; +// externalOne = f1; +// externalTwo = f2; + +// set_property_int("foo", 10); - int got = get_property("bar"); +// int got = get_property("bar"); - cout << "got " << got << " for bar\n"; +// cout << "got " << got << " for bar\n"; -} +// } int main(void) { cout << "main()\n";