diff --git a/bin/build.js b/bin/build.js index 254594f..669f4ae 100755 --- a/bin/build.js +++ b/bin/build.js @@ -43,6 +43,9 @@ const properties = { napi_env: 'ptr' }; +const spaces = [' ', '\n', '\r', '\t']; +const lineSpaces = [' ', '\t']; + const generate = (cb) => { // const llparseDot = require('llparse-dot'); @@ -79,7 +82,7 @@ const generate = (cb) => { simulation, inSimulation, simulationTime, - simulationVector, simulationVectorEnd, + simulationVector, simulationVectorEnd, simulationVectorRecovery, simulationId } = ` declaration @@ -93,7 +96,7 @@ const generate = (cb) => { simulation inSimulation simulationTime - simulationVector simulationVectorEnd + simulationVector simulationVectorEnd simulationVectorRecovery simulationId ` .trim().split(/\s+/) @@ -101,8 +104,6 @@ const generate = (cb) => { const enddefinitions = p.node('inDeclarationEnd'); - const spaces = [' ', '\n', '\r', '\t']; - const cmd = objection({ $comment: 1, $date: 2, @@ -147,7 +148,22 @@ const generate = (cb) => { .otherwise(scopeTypeEnd); scopeTypeEnd - .select({begin: 1, fork: 2, function: 3, module: 4, task: 5}, + .select( + { + module: 0, + task: 1, + function: 2, + begin: 3, + fork: 4, + // extra scopes from Verilator + generate: 5, + struct: 6, + union: 7, + class: 8, + interface: 9, + package: 10, + program: 11 + }, p.invoke(p.code.store('type'), scopeIdentifier)) .otherwise(p.error(2, 'Expected scope type')); @@ -258,15 +274,28 @@ const generate = (cb) => { p.invoke( // p.code.mulAdd('value', {base: 2, signed: false}), p.code.value('onDigit'), - {1: p.error(1, 'Content-Length overflow')}, + {1: p.error(5, 'Content-Length overflow')}, simulationVector ) ) .otherwise(simulationVectorEnd); simulationVectorEnd - .match(spaces, idSpan.start(simulationId)) - .skipTo(simulationVectorEnd); + .match(lineSpaces, idSpan.start(simulationId)) + .skipTo(simulationVectorRecovery); + + simulationVectorRecovery + .select( + { + '\n': 1, '\r': 1 + }, + p.invoke( + p.code.value('onRecover'), + {1: p.error(6, 'recover')}, + simulation + ) + ) + .skipTo(simulationVectorRecovery); simulationId .match(spaces, idSpan.end(simulation)) diff --git a/out/vcd.wasm b/out/vcd.wasm index 33fef06..62d4285 100755 Binary files a/out/vcd.wasm and b/out/vcd.wasm differ diff --git a/test/napi_any.js b/test/napi_any.js index 2a7cf42..e496cf5 100644 --- a/test/napi_any.js +++ b/test/napi_any.js @@ -1,12 +1,12 @@ 'use strict'; const expect = require('chai').expect; -const lib = require('../lib/index.js'); +const parser = require('../lib/parser.js'); describe('any', () => { it('simple', done => { - const inst = lib.parser(); + const inst = parser(); const dump = []; inst.change.any((id, time, cmd, value, mask) => { dump.push({ @@ -46,6 +46,7 @@ $enddefinitions $end 0XyZ #400 b1010101010101010101010101010101010101010101010101010101010101010 64b +b0001010101010xx010101000000ggg b10101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010 128b b1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010 256b b10101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010 512b diff --git a/test/napi_basic.js b/test/napi_basic.js index d06e14d..0f19519 100644 --- a/test/napi_basic.js +++ b/test/napi_basic.js @@ -1,22 +1,22 @@ 'use strict'; const expect = require('chai').expect; -const lib = require('../lib/index.js'); +const parser = require('../lib/parser.js'); describe('basic', () => { it('typeof vcd', done => { - expect(lib.parser).to.be.an('function'); + expect(parser).to.be.an('function'); done(); }); it('typeof vcd instance', done => { - expect(lib.parser()).to.be.an('object'); + expect(parser()).to.be.an('object'); done(); }); it('fail: foo bar', done => { - const inst = lib.parser(); + const inst = parser(); expect(inst.write(Buffer.from(' foo bar ???'))).to.eq(true); expect(inst.info).to.deep.eq({ stack: [{}], @@ -27,7 +27,7 @@ describe('basic', () => { }); it('$comment', done => { - const inst = lib.parser(); + const inst = parser(); expect(inst.write(Buffer.from( ' \n $comment some text $end $comment more text $end ???' ))).to.eq(true); @@ -41,7 +41,7 @@ describe('basic', () => { }); it('$version', done => { - const inst = lib.parser(); + const inst = parser(); expect(inst.write(` $version Generated by VerilatedVcd $end $date Wed Sep 18 22:59:07 2019 diff --git a/test/napi_dump.js b/test/napi_dump.js index c17f7fd..ac54bb3 100644 --- a/test/napi_dump.js +++ b/test/napi_dump.js @@ -1,12 +1,12 @@ 'use strict'; const expect = require('chai').expect; -const lib = require('../lib/index.js'); +const parser = require('../lib/parser.js'); describe('dump', () => { it('simple', done => { - const inst = lib.parser(); + const inst = parser(); const dump = []; ['"}G', '{u', 'u)'] // array of all signal ids .map(id => diff --git a/test/napi_events.js b/test/napi_events.js index 3929f6f..099a14d 100644 --- a/test/napi_events.js +++ b/test/napi_events.js @@ -1,12 +1,12 @@ 'use strict'; const expect = require('chai').expect; -const lib = require('../lib/index.js'); +const parser = require('../lib/parser.js'); describe('events', () => { it('$enddefinitions', done => { - const inst = lib.parser(); + const inst = parser(); inst.on('$enddefinitions', () => { expect(inst.info).to.deep.eq({ status: 'simulation', diff --git a/test/wasm_any.js b/test/wasm_any.js index 985dfba..a5e9012 100644 --- a/test/wasm_any.js +++ b/test/wasm_any.js @@ -49,6 +49,7 @@ $enddefinitions $end 0XyZ #400 b1010101010101010101010101010101010101010101010101010101010101010 64b +b0001010101010xx010101000000ggg b10101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010 128b b1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010 256b b10101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010 512b diff --git a/vcd_spans.c b/vcd_spans.c index e417f83..f1fba78 100644 --- a/vcd_spans.c +++ b/vcd_spans.c @@ -260,6 +260,16 @@ int onDigit( return 0; } +int onRecover( + vcd_parser_t* state, + const unsigned char* p, + const unsigned char* endp, + int digit +) { + state->digitCount = 0; + return 0; +} + int timeSpan(vcd_parser_t* state, const unsigned char* p, const unsigned char* endp) { int64_t time = strtoul((const char *)p, (char **)&endp, 10); if (state->time == INT64_MAX) {