Skip to content

Commit

Permalink
time -> i64 -> BigInt; 9-sate values
Browse files Browse the repository at this point in the history
  • Loading branch information
drom committed Sep 7, 2021
1 parent b5907f5 commit 7daa36c
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 97 deletions.
20 changes: 3 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,16 @@
all: wasm
wasm: out/vcd.wasm


WASM_MAIN = wasm_main.cpp

HPP_FILES = \
vcd_parser.h \
wasm_main.hpp \


CPP_FILES = \
vcd_parser.c \
vcd_spans.c \



# this is a list of all C functions we want to publish to javascript
# In the main cpp file, each of these is wrapped in extern "C" {}
# the version here has a prepended underscore
Expand All @@ -39,12 +35,9 @@ CLANG_WARN_FLAGS = \
-Wshadow \
# -Wconversion


CLANG_OTHER_FLAGS = \
-DVCDWASM \



CLANG_O_FLAG = '-Oz'

ifdef NOOPT
Expand All @@ -58,15 +51,17 @@ endif
# works however slows down
#-s DISABLE_EXCEPTION_CATCHING=0 \

out/vcd.wasm: $(WASM_MAIN) $(CPP_FILES) $(HPP_FILES) Makefile
mkdir -p out
emcc \
$(WASM_MAIN) \
$(CPP_FILES) \
-o out/vcd.html \
-s DISABLE_EXCEPTION_CATCHING=1 \
-s WASM_BIGINT \
-s ALLOW_MEMORY_GROWTH=1 \
-s INITIAL_MEMORY=1GB \
-s MAXIMUM_MEMORY=2GB \
-s ALLOW_TABLE_GROWTH=1 \
-s MODULARIZE=1 \
-s EXPORT_NAME=createVCD \
Expand Down Expand Up @@ -99,10 +94,6 @@ out/vcd.wasm: $(WASM_MAIN) $(CPP_FILES) $(HPP_FILES) Makefile
# @echo "$(PTSRC1) already patched, skipping..."
# endif





# PTSRC2=lib/BehaviorTree.CPP/src/tree_node.cpp
# PTPAT2=patch/tree_node.patch
# PAPPLIED2 := $(shell patch -R -p0 -s -f --dry-run $(PTSRC2) < $(PTPAT2) 1>&2 2> /dev/null > /dev/null; echo $$?)
Expand All @@ -115,13 +106,9 @@ out/vcd.wasm: $(WASM_MAIN) $(CPP_FILES) $(HPP_FILES) Makefile
# @echo "$(PTSRC2) already patched, skipping..."
# endif




.PHONY: all build watch dev start test pretest lint jestc copydist cleandist prepare
.PHONY: test testonly


watch:
npm run watch

Expand All @@ -134,6 +121,5 @@ testonly:
prepare:
npm run prepare


clean:
rm -rf out/*
25 changes: 21 additions & 4 deletions bin/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,15 @@ const generate = cb => {
$dumpon: 11,
$dumpvars: 12,
'#': 13,
'0': 14, '1': 15, x: 16, X: 17, Z: 18,
b: 19, B: 20, r: 21, R: 22
'0': 14, '1': 15,
x: 16, X: 17,
z: 18, Z: 19,
u: 20, U: 21, // VHDL states
w: 22, W: 23,
l: 24, L: 25,
h: 26, H: 27,
'-': 28,
b: 30, B: 31, r: 32, R: 33
});

declaration
Expand Down Expand Up @@ -221,7 +228,7 @@ const generate = cb => {
p.invoke(p.code.store('command'), commandSpan.start(inSimulation)))
.select(cmd('#'),
p.invoke(p.code.store('command'), timeSpan.start(simulationTime)))
.select(cmd('0 1 x X Z'),
.select(cmd('0 1 x X z Z u U w W l L h H -'),
p.invoke(p.code.store('command'), idSpan.start(simulationId)))
.select(cmd('b B r R'),
p.invoke(p.code.store('command'), simulationVector))
Expand All @@ -237,7 +244,17 @@ const generate = cb => {

simulationVector
.select(
{0: 0, 1: 1, x: 2, z: 3, X: 2, Z: 3},
{
0: 0,
1: 1,
x: 2, X: 2,
z: 3, Z: 3,
u: 3, U: 3, // VHDL states
w: 3, W: 3,
l: 3, L: 3,
h: 3, H: 3,
'-': 3
},
p.invoke(
// p.code.mulAdd('value', {base: 2, signed: false}),
p.code.value('onDigit'),
Expand Down
14 changes: 7 additions & 7 deletions lib/web-vcd-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ const EventEmitter = require('events').EventEmitter;

const dotProp = require('dot-prop');

function _waitForStart(mod) {
return new Promise((resolve)=>{
mod.addOnPostRun(resolve);
});
}
// function _waitForStart(mod) {
// return new Promise((resolve)=>{
// mod.addOnPostRun(resolve);
// });
// }

function u8ToBn(u8) {
var hex = [];
Expand All @@ -26,7 +26,7 @@ function u8ToBn(u8) {
return BigInt('0x' + hex.join(''));
}

let startCalled = 0;
// let startCalled = 0;

const getWrapper = wasm => {

Expand Down Expand Up @@ -148,7 +148,7 @@ const getWrapper = wasm => {
// console.log(bigValue.toString(16));

ee[1](name, time, command, bigValue, bigMask);
}, 'viiiiiii');
}, 'viijiiii');

};

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@
"chai": "^4.3.4",
"dot-prop": "^6.0.1",
"eslint": "^7.31.0",
"http-server": "^0.12.3",
"http-server": "^13.0.1",
"llparse-dot": "^1.0.1",
"mocha": "^9.0.3",
"mocha": "^9.1.1",
"nyc": "^15.1.0",
"terser": "^5.7.1",
"terser": "^5.7.2",
"watchify": "^4.0.0"
},
"eslintConfig": {
Expand Down
24 changes: 12 additions & 12 deletions test/napi_any.js

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions test/napi_dump.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,24 @@ describe('dump', () => {
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: '{u', time: 200, cmd: 30, 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: '{u', time: 300, cmd: 30, value: 0xf000000000000000n, mask: 0n },
{ id: '{u', time: 301, cmd: 30, value: 0x0f00000000000000n, mask: 0n },
{ id: '{u', time: 302, cmd: 30, value: 0x00f0000000000000n, mask: 0n },
{ id: '{u', time: 303, cmd: 30, value: 0x000f000000000000n, mask: 0n },
{ id: '{u', time: 304, cmd: 30, value: 0x0000f00000000000n, mask: 0n },
{ id: '{u', time: 305, cmd: 30, value: 0x00000f0000000000n, mask: 0n },
{ id: '{u', time: 306, cmd: 30, value: 0x000000f000000000n, mask: 0n },
{ id: '{u', time: 307, cmd: 30, value: 0x0000000f00000000n, mask: 0n },
{ id: '{u', time: 308, cmd: 31, value: 0x00000000f0000000n, mask: 0n },
{ id: '{u', time: 309, cmd: 30, value: 0x000000000f000000n, mask: 0n },
{ id: '{u', time: 310, cmd: 30, value: 0x0000000000f00000n, mask: 0n },
{ id: '{u', time: 311, cmd: 30, value: 0x00000000000f0000n, mask: 0n },
{ id: '{u', time: 312, cmd: 30, value: 0x000000000000f000n, mask: 0n },
{ id: '{u', time: 313, cmd: 30, value: 0x0000000000000f00n, mask: 0n },
{ id: '{u', time: 314, cmd: 30, value: 0x00000000000000f0n, mask: 0n },
{ id: '{u', time: 315, cmd: 30, value: 0x000000000000000fn, mask: 0n },
{ id: '"}G', time: 316, cmd: 15, value: 1n, mask: 0n }
]);
// console.log(dump);
Expand Down
24 changes: 12 additions & 12 deletions test/wasm_any.js

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions test/wasm_dump.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,24 @@ describe('wasm dump', () => {
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: '{u', time: 200, cmd: 30, 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: 300, cmd: 30, value: 0xf000000000000000n, mask: 0n },
{ id: '{u', time: 301, cmd: 30, value: 0x0f00000000000000n, mask: 0n },
{ id: '{u', time: 302, cmd: 30, value: 0x00f0000000000000n, mask: 0n },
{ id: '{u', time: 303, cmd: 30, value: 0x000f000000000000n, mask: 0n },
{ id: '{u', time: 304, cmd: 30, value: 0x0000f00000000000n, mask: 0n },
{ id: '{u', time: 305, cmd: 30, value: 0x00000f0000000000n, mask: 0n },
{ id: '{u', time: 306, cmd: 30, value: 0x000000f000000000n, mask: 0n },
{ id: '{u', time: 307, cmd: 30, 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: '{u', time: 309, cmd: 30, value: 0x000000000f000000n, mask: 0n },
{ id: '{u', time: 310, cmd: 30, value: 0x0000000000f00000n, mask: 0n },
{ id: '{u', time: 311, cmd: 30, value: 0x00000000000f0000n, mask: 0n },
{ id: '{u', time: 312, cmd: 30, value: 0x000000000000f000n, mask: 0n },
{ id: '{u', time: 313, cmd: 30, value: 0x0000000000000f00n, mask: 0n },
{ id: '{u', time: 314, cmd: 30, value: 0x00000000000000f0n, mask: 0n },
{ id: '{u', time: 315, cmd: 30, value: 0x000000000000000fn, mask: 0n },
{ id: '"}G', time: 316, cmd: 15, value: 1n, mask: 0n }
]);
done();
Expand Down
4 changes: 2 additions & 2 deletions vcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ METHOD(init) {
state->tmpStr2 = tmpStr2;
state->value = valueBuf;
state->mask = maskBuf;
state->time = 0; // UINT64_MAX;
state->time = INT64_MAX;
state->digitCount = 0;

napi_value status;
Expand Down Expand Up @@ -206,7 +206,7 @@ METHOD(getTime) {
ASSERT_EXTERNAL(args[0], state)

napi_value res;
ASSERT(res, napi_create_bigint_uint64(env, state->time, &res))
ASSERT(res, napi_create_bigint_int64(env, state->time, &res))
return res;
}

Expand Down
4 changes: 2 additions & 2 deletions vcd_spans.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,11 @@ int onDigit(

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 == UINT64_MAX) {
if (state->time == INT64_MAX) {
#ifndef VCDWASM
napi_env env = state->napi_env;
napi_value val;
ASSERT(val, napi_create_int32(env, time, &val))
ASSERT(val, napi_create_int64(env, time, &val))
ASSERT(state->info, napi_set_named_property(env, state->info, "t0", val))
#else
set_property_int("t0", time);
Expand Down
25 changes: 21 additions & 4 deletions wasm_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,18 @@ using namespace std;

/// Typedef used as part of c->js call
typedef void externalJsMethodZero(const char* name, const size_t len);

// typedef void externalJsMethodOne (const char* name, const size_t len, const uint64_t time, const uint8_t command, const int valueWords, const int aValue, const int aMask);
typedef void externalJsMethodOne (const char* name, const size_t len, const int time, const int command, const int valueWords, const int aValue, const int aMask);

typedef void externalJsMethodOne (
const char* name,
const size_t len,
const int64_t time,
const int command,
const int valueWords,
const int aValue,
const int aMask
);

typedef int externalJsGetProperty(const char* name, const size_t len);
typedef void externalJsSetProperty(const char* name, const size_t len, const int type, const int v0, const int v1);
Expand Down Expand Up @@ -55,7 +65,14 @@ void emit_lifee(const char* name) {
externalZero(name, strlen(name));
}

void emit_triee(const char* name, const int64_t time, const int command, const int valueWords, uint64_t* aValue, uint64_t* aMask) {
void emit_triee(
const char* name,
const int64_t time,
const int command,
const int valueWords,
uint64_t* aValue,
uint64_t* aMask
) {

// return;
// externalOne(
Expand Down Expand Up @@ -120,7 +137,7 @@ int init(
state->value = valueBuf;
state->mask = maskBuf;
state->digitCount = 0;
state->time = 0; // UINT64_MAX;
state->time = INT64_MAX;

set_property_string("status", "declaration");

Expand Down Expand Up @@ -164,7 +181,7 @@ int setTrigger(const int context, char* triggerString) {
return 0;
}

uint64_t getTime(const int context) {
int64_t getTime(const int context) {
return state->time;
}

Expand Down
9 changes: 8 additions & 1 deletion wasm_main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,11 @@ void set_path_to_path(const char* name, const char* value);
void new_object_path(const char* name);
int get_property_int(const char* name);
void emit_lifee(const char* name);
void emit_triee(const char* name, const int64_t time, const int command, const int valueWords, uint64_t* aValue, uint64_t* aMask);
void emit_triee(
const char* name,
const int64_t time,
const int command,
const int valueWords,
uint64_t* aValue,
uint64_t* aMask
);

0 comments on commit 7daa36c

Please sign in to comment.