From 51296f30b8ad83cb986ce498254aa51059cf840d Mon Sep 17 00:00:00 2001 From: Aliaksei Chapyzhenka Date: Tue, 29 Sep 2020 13:11:09 -0700 Subject: [PATCH] dump initial timestamp "t0" --- test/basic.js | 1 + test/wasm_basic.js | 1 + vcd.c | 2 ++ vcd_spans.c | 14 +++++++++++++- wasm_main.cpp | 8 +++++--- 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/test/basic.js b/test/basic.js index 7bbb60a..dc8e97a 100644 --- a/test/basic.js +++ b/test/basic.js @@ -85,6 +85,7 @@ b0000000000001111 {u date: ' Wed Sep 18 22:59:07 2019\n ', version: ' Generated by VerilatedVcd ', timescale: ' 1ns ', + t0: 1, varId: 'u)', wires: { top: { diff --git a/test/wasm_basic.js b/test/wasm_basic.js index 1cf8e1d..040529b 100644 --- a/test/wasm_basic.js +++ b/test/wasm_basic.js @@ -83,6 +83,7 @@ b0000000000001111 {u date: ' Wed Sep 18 22:59:07 2019\n ', version: ' Generated by VerilatedVcd ', timescale: ' 1ns ', + t0: 1, varId: 'u)', wires: { top: { diff --git a/vcd.c b/vcd.c index 04ace22..4f1a8a4 100644 --- a/vcd.c +++ b/vcd.c @@ -1,5 +1,6 @@ #define NAPI_VERSION 1 #include +#include #include #include "vcd_parser.h" #include @@ -135,6 +136,7 @@ METHOD(init) { state->tmpStr2 = tmpStr2; state->value = valueBuf; state->mask = maskBuf; + state->time = UINT64_MAX; state->digitCount = 0; napi_value status; diff --git a/vcd_spans.c b/vcd_spans.c index 185527b..8dcc38e 100644 --- a/vcd_spans.c +++ b/vcd_spans.c @@ -1,6 +1,7 @@ #include #include #include +#include #include "vcd_parser.h" #ifndef VCDWASM @@ -261,6 +262,17 @@ int onDigit( } int timeSpan(vcd_parser_t* state, const unsigned char* p, const unsigned char* endp) { - state->time = strtoul((const char *)p, (char **)&endp, 10); + int64_t time = strtoul((const char *)p, (char **)&endp, 10); + if (state->time == UINT64_MAX) { +#ifndef VCDWASM + napi_env env = state->napi_env; + napi_value val; + ASSERT(val, napi_create_int32(env, time, &val)) + ASSERT(state->info, napi_set_named_property(env, state->info, "t0", val)) +#else + set_property_int("t0", time); +#endif + } + state->time = time; return 0; } diff --git a/wasm_main.cpp b/wasm_main.cpp index 27e8266..0975f23 100644 --- a/wasm_main.cpp +++ b/wasm_main.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include "vcd_parser.h" @@ -87,7 +88,7 @@ int init( externalJsSetProperty* sfn, externalJsGetProperty* gfn ) { - + state = (struct vcd_parser_s*) malloc(sizeof *state); @@ -119,6 +120,7 @@ int init( state->value = valueBuf; state->mask = maskBuf; state->digitCount = 0; + state->time = UINT64_MAX; set_property_string("status", "declaration"); @@ -185,7 +187,7 @@ uint64_t getTime(const int context) { // externalOne = f1; // set_property_int("foo", 10); - + // int got = get_property_int("bar"); @@ -199,4 +201,4 @@ int main(void) { } -} // extern C \ No newline at end of file +} // extern C