diff --git a/lib/parser.js b/lib/parser.js index ef82e6c..e5fafa5 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -40,5 +40,7 @@ module.exports = () => { s.info = info; + s.getTime = () => lib.getTime(cxt); + return s; }; diff --git a/test/dump.js b/test/dump.js index 3e0baff..fe3ed9e 100644 --- a/test/dump.js +++ b/test/dump.js @@ -22,6 +22,7 @@ describe('dump', () => { ); 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 }, diff --git a/vcd.c b/vcd.c index 36abeb0..9da6991 100644 --- a/vcd.c +++ b/vcd.c @@ -196,11 +196,22 @@ METHOD(setTrigger) { return res; } +METHOD(getTime) { + ASSERT_ARGC(1) + struct vcd_parser_s *state; + ASSERT_EXTERNAL(args[0], state) + + napi_value res; + ASSERT(res, napi_create_bigint_uint64(env, state->time, &res)) + return res; +} + napi_value Init(napi_env env, napi_value exports) { DECLARE_NAPI_METHOD("init", init) DECLARE_NAPI_METHOD("done", done) DECLARE_NAPI_METHOD("execute", execute) DECLARE_NAPI_METHOD("setTrigger", setTrigger) + DECLARE_NAPI_METHOD("getTime", getTime) return exports; }