From 54332dfef3c34f34db01c1baa65bb79b85bf113b Mon Sep 17 00:00:00 2001 From: Aliaksei Chapyzhenka Date: Tue, 29 Sep 2020 11:21:39 -0700 Subject: [PATCH] support for $comment, $date, $timescale, $version --- test/basic.js | 4 ++++ test/events.js | 3 +++ test/wasm_basic.js | 4 ++++ test/wasm_events.js | 5 ++++- vcd_spans.c | 24 ++++++++++++++++++++++++ 5 files changed, 39 insertions(+), 1 deletion(-) diff --git a/test/basic.js b/test/basic.js index 874f5b9..7bbb60a 100644 --- a/test/basic.js +++ b/test/basic.js @@ -32,6 +32,7 @@ describe('basic', () => { ' \n $comment some text $end $comment more text $end ???' ))).to.eq(true); expect(inst.info).to.deep.eq({ + comment: ' more text ', stack: [{}], status: 'declaration', wires: {} @@ -81,6 +82,9 @@ b0000000000001111 {u expect(inst.info).to.deep.eq({ status: 'simulation', + date: ' Wed Sep 18 22:59:07 2019\n ', + version: ' Generated by VerilatedVcd ', + timescale: ' 1ns ', varId: 'u)', wires: { top: { diff --git a/test/events.js b/test/events.js index 85c0cce..3929f6f 100644 --- a/test/events.js +++ b/test/events.js @@ -10,6 +10,9 @@ describe('events', () => { inst.on('$enddefinitions', () => { expect(inst.info).to.deep.eq({ status: 'simulation', + date: ' Wed Sep 18 22:59:07 2019\n ', + version: ' Generated by VerilatedVcd ', + timescale: ' 1ns ', varId: 'u)', wires: { top: { diff --git a/test/wasm_basic.js b/test/wasm_basic.js index 1d6355d..1cf8e1d 100644 --- a/test/wasm_basic.js +++ b/test/wasm_basic.js @@ -31,6 +31,7 @@ describe('wasm basic', () => { ' \n $comment some text $end $comment more text $end ???' ))).to.eq(true); expect(inst.info).to.deep.eq({ + comment: ' more text ', stack: [{}], status: 'declaration', wires: {} @@ -79,6 +80,9 @@ b0000000000001111 {u expect(inst.info).to.deep.eq({ status: 'simulation', + date: ' Wed Sep 18 22:59:07 2019\n ', + version: ' Generated by VerilatedVcd ', + timescale: ' 1ns ', varId: 'u)', wires: { top: { diff --git a/test/wasm_events.js b/test/wasm_events.js index 33eeb26..3fad5ea 100644 --- a/test/wasm_events.js +++ b/test/wasm_events.js @@ -14,10 +14,13 @@ describe('wasm events', () => { }); it('$enddefinitions', done => { - + inst.on('$enddefinitions', () => { expect(inst.info).to.deep.eq({ status: 'simulation', + timescale: ' 1ns ', + date: ' Wed Sep 18 22:59:07 2019\n ', + version: ' Generated by VerilatedVcd ', varId: 'u)', wires: { top: { diff --git a/vcd_spans.c b/vcd_spans.c index 94b1433..185527b 100644 --- a/vcd_spans.c +++ b/vcd_spans.c @@ -74,6 +74,30 @@ int commandSpan(vcd_parser_t* state, const unsigned char* p, const unsigned char return 0; } + if ( + (state->command == 1) || // $comment + (state->command == 2) || // $date + (state->command == 4) || // $timescale + (state->command == 7) // $version + ) { + char* key; + switch(state->command) { + case 1: key = "comment"; break; + case 2: key = "date"; break; + case 4: key = "timescale"; break; + case 7: key = "version"; break; + } +#ifndef VCDWASM + napi_value val; + ASSERT(val, napi_create_string_latin1(env, (char*)p, (endp - p - 4), &val)) + ASSERT(state->info, napi_set_named_property(env, state->info, key, val)) +#else + strcopy(p, endp - 3, state->tmpStr); + set_property_string(key, state->tmpStr); +#endif + return 0; + } + if (state->command == 8) { // $enddefinitions #ifndef VCDWASM napi_value status, undefined, eventName, eventPayload, return_val;