time -> i64 -> BigInt; 9-sate values

This commit is contained in:
Aliaksei Chapyzhenka 2021-09-06 20:40:00 -07:00
parent b5907f541f
commit 7daa36c80b
12 changed files with 124 additions and 97 deletions

View File

@ -3,20 +3,16 @@
all: wasm all: wasm
wasm: out/vcd.wasm wasm: out/vcd.wasm
WASM_MAIN = wasm_main.cpp WASM_MAIN = wasm_main.cpp
HPP_FILES = \ HPP_FILES = \
vcd_parser.h \ vcd_parser.h \
wasm_main.hpp \ wasm_main.hpp \
CPP_FILES = \ CPP_FILES = \
vcd_parser.c \ vcd_parser.c \
vcd_spans.c \ vcd_spans.c \
# this is a list of all C functions we want to publish to javascript # 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" {} # In the main cpp file, each of these is wrapped in extern "C" {}
# the version here has a prepended underscore # the version here has a prepended underscore
@ -39,12 +35,9 @@ CLANG_WARN_FLAGS = \
-Wshadow \ -Wshadow \
# -Wconversion # -Wconversion
CLANG_OTHER_FLAGS = \ CLANG_OTHER_FLAGS = \
-DVCDWASM \ -DVCDWASM \
CLANG_O_FLAG = '-Oz' CLANG_O_FLAG = '-Oz'
ifdef NOOPT ifdef NOOPT
@ -58,7 +51,6 @@ endif
# works however slows down # works however slows down
#-s DISABLE_EXCEPTION_CATCHING=0 \ #-s DISABLE_EXCEPTION_CATCHING=0 \
out/vcd.wasm: $(WASM_MAIN) $(CPP_FILES) $(HPP_FILES) Makefile out/vcd.wasm: $(WASM_MAIN) $(CPP_FILES) $(HPP_FILES) Makefile
mkdir -p out mkdir -p out
emcc \ emcc \
@ -66,7 +58,10 @@ out/vcd.wasm: $(WASM_MAIN) $(CPP_FILES) $(HPP_FILES) Makefile
$(CPP_FILES) \ $(CPP_FILES) \
-o out/vcd.html \ -o out/vcd.html \
-s DISABLE_EXCEPTION_CATCHING=1 \ -s DISABLE_EXCEPTION_CATCHING=1 \
-s WASM_BIGINT \
-s ALLOW_MEMORY_GROWTH=1 \ -s ALLOW_MEMORY_GROWTH=1 \
-s INITIAL_MEMORY=1GB \
-s MAXIMUM_MEMORY=2GB \
-s ALLOW_TABLE_GROWTH=1 \ -s ALLOW_TABLE_GROWTH=1 \
-s MODULARIZE=1 \ -s MODULARIZE=1 \
-s EXPORT_NAME=createVCD \ -s EXPORT_NAME=createVCD \
@ -99,10 +94,6 @@ out/vcd.wasm: $(WASM_MAIN) $(CPP_FILES) $(HPP_FILES) Makefile
# @echo "$(PTSRC1) already patched, skipping..." # @echo "$(PTSRC1) already patched, skipping..."
# endif # endif
# PTSRC2=lib/BehaviorTree.CPP/src/tree_node.cpp # PTSRC2=lib/BehaviorTree.CPP/src/tree_node.cpp
# PTPAT2=patch/tree_node.patch # PTPAT2=patch/tree_node.patch
# PAPPLIED2 := $(shell patch -R -p0 -s -f --dry-run $(PTSRC2) < $(PTPAT2) 1>&2 2> /dev/null > /dev/null; echo $$?) # PAPPLIED2 := $(shell patch -R -p0 -s -f --dry-run $(PTSRC2) < $(PTPAT2) 1>&2 2> /dev/null > /dev/null; echo $$?)
@ -115,13 +106,9 @@ out/vcd.wasm: $(WASM_MAIN) $(CPP_FILES) $(HPP_FILES) Makefile
# @echo "$(PTSRC2) already patched, skipping..." # @echo "$(PTSRC2) already patched, skipping..."
# endif # endif
.PHONY: all build watch dev start test pretest lint jestc copydist cleandist prepare .PHONY: all build watch dev start test pretest lint jestc copydist cleandist prepare
.PHONY: test testonly .PHONY: test testonly
watch: watch:
npm run watch npm run watch
@ -134,6 +121,5 @@ testonly:
prepare: prepare:
npm run prepare npm run prepare
clean: clean:
rm -rf out/* rm -rf out/*

View File

@ -117,8 +117,15 @@ const generate = cb => {
$dumpon: 11, $dumpon: 11,
$dumpvars: 12, $dumpvars: 12,
'#': 13, '#': 13,
'0': 14, '1': 15, x: 16, X: 17, Z: 18, '0': 14, '1': 15,
b: 19, B: 20, r: 21, R: 22 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 declaration
@ -221,7 +228,7 @@ const generate = cb => {
p.invoke(p.code.store('command'), commandSpan.start(inSimulation))) p.invoke(p.code.store('command'), commandSpan.start(inSimulation)))
.select(cmd('#'), .select(cmd('#'),
p.invoke(p.code.store('command'), timeSpan.start(simulationTime))) 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))) p.invoke(p.code.store('command'), idSpan.start(simulationId)))
.select(cmd('b B r R'), .select(cmd('b B r R'),
p.invoke(p.code.store('command'), simulationVector)) p.invoke(p.code.store('command'), simulationVector))
@ -237,7 +244,17 @@ const generate = cb => {
simulationVector simulationVector
.select( .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.invoke(
// p.code.mulAdd('value', {base: 2, signed: false}), // p.code.mulAdd('value', {base: 2, signed: false}),
p.code.value('onDigit'), p.code.value('onDigit'),

View File

@ -5,11 +5,11 @@ const EventEmitter = require('events').EventEmitter;
const dotProp = require('dot-prop'); const dotProp = require('dot-prop');
function _waitForStart(mod) { // function _waitForStart(mod) {
return new Promise((resolve)=>{ // return new Promise((resolve)=>{
mod.addOnPostRun(resolve); // mod.addOnPostRun(resolve);
}); // });
} // }
function u8ToBn(u8) { function u8ToBn(u8) {
var hex = []; var hex = [];
@ -26,7 +26,7 @@ function u8ToBn(u8) {
return BigInt('0x' + hex.join('')); return BigInt('0x' + hex.join(''));
} }
let startCalled = 0; // let startCalled = 0;
const getWrapper = wasm => { const getWrapper = wasm => {
@ -148,7 +148,7 @@ const getWrapper = wasm => {
// console.log(bigValue.toString(16)); // console.log(bigValue.toString(16));
ee[1](name, time, command, bigValue, bigMask); ee[1](name, time, command, bigValue, bigMask);
}, 'viiiiiii'); }, 'viijiiii');
}; };

View File

@ -47,11 +47,11 @@
"chai": "^4.3.4", "chai": "^4.3.4",
"dot-prop": "^6.0.1", "dot-prop": "^6.0.1",
"eslint": "^7.31.0", "eslint": "^7.31.0",
"http-server": "^0.12.3", "http-server": "^13.0.1",
"llparse-dot": "^1.0.1", "llparse-dot": "^1.0.1",
"mocha": "^9.0.3", "mocha": "^9.1.1",
"nyc": "^15.1.0", "nyc": "^15.1.0",
"terser": "^5.7.1", "terser": "^5.7.2",
"watchify": "^4.0.0" "watchify": "^4.0.0"
}, },
"eslintConfig": { "eslintConfig": {

File diff suppressed because one or more lines are too long

View File

@ -26,24 +26,24 @@ describe('dump', () => {
expect(dump).to.deep.eq([ expect(dump).to.deep.eq([
{ id: '"}G', time: 100, cmd: 14, value: 0n, mask: 0n }, { id: '"}G', time: 100, cmd: 14, value: 0n, mask: 0n },
{ id: '"}G', time: 200, cmd: 15, value: 1n, 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: '"}G', time: 300, cmd: 14, value: 0n, mask: 0n },
{ id: '{u', time: 300, cmd: 19, value: 0xf000000000000000n, mask: 0n }, { id: '{u', time: 300, cmd: 30, value: 0xf000000000000000n, mask: 0n },
{ id: '{u', time: 301, cmd: 19, value: 0x0f00000000000000n, mask: 0n }, { id: '{u', time: 301, cmd: 30, value: 0x0f00000000000000n, mask: 0n },
{ id: '{u', time: 302, cmd: 19, value: 0x00f0000000000000n, mask: 0n }, { id: '{u', time: 302, cmd: 30, value: 0x00f0000000000000n, mask: 0n },
{ id: '{u', time: 303, cmd: 19, value: 0x000f000000000000n, mask: 0n }, { id: '{u', time: 303, cmd: 30, value: 0x000f000000000000n, mask: 0n },
{ id: '{u', time: 304, cmd: 19, value: 0x0000f00000000000n, mask: 0n }, { id: '{u', time: 304, cmd: 30, value: 0x0000f00000000000n, mask: 0n },
{ id: '{u', time: 305, cmd: 19, value: 0x00000f0000000000n, mask: 0n }, { id: '{u', time: 305, cmd: 30, value: 0x00000f0000000000n, mask: 0n },
{ id: '{u', time: 306, cmd: 19, value: 0x000000f000000000n, mask: 0n }, { id: '{u', time: 306, cmd: 30, value: 0x000000f000000000n, mask: 0n },
{ id: '{u', time: 307, cmd: 19, value: 0x0000000f00000000n, 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: 308, cmd: 31, value: 0x00000000f0000000n, mask: 0n },
{ id: '{u', time: 309, cmd: 19, value: 0x000000000f000000n, mask: 0n }, { id: '{u', time: 309, cmd: 30, value: 0x000000000f000000n, mask: 0n },
{ id: '{u', time: 310, cmd: 19, value: 0x0000000000f00000n, mask: 0n }, { id: '{u', time: 310, cmd: 30, value: 0x0000000000f00000n, mask: 0n },
{ id: '{u', time: 311, cmd: 19, value: 0x00000000000f0000n, mask: 0n }, { id: '{u', time: 311, cmd: 30, value: 0x00000000000f0000n, mask: 0n },
{ id: '{u', time: 312, cmd: 19, value: 0x000000000000f000n, mask: 0n }, { id: '{u', time: 312, cmd: 30, value: 0x000000000000f000n, mask: 0n },
{ id: '{u', time: 313, cmd: 19, value: 0x0000000000000f00n, mask: 0n }, { id: '{u', time: 313, cmd: 30, value: 0x0000000000000f00n, mask: 0n },
{ id: '{u', time: 314, cmd: 19, value: 0x00000000000000f0n, mask: 0n }, { id: '{u', time: 314, cmd: 30, value: 0x00000000000000f0n, mask: 0n },
{ id: '{u', time: 315, cmd: 19, value: 0x000000000000000fn, mask: 0n }, { id: '{u', time: 315, cmd: 30, value: 0x000000000000000fn, mask: 0n },
{ id: '"}G', time: 316, cmd: 15, value: 1n, mask: 0n } { id: '"}G', time: 316, cmd: 15, value: 1n, mask: 0n }
]); ]);
// console.log(dump); // console.log(dump);

File diff suppressed because one or more lines are too long

View File

@ -36,24 +36,24 @@ describe('wasm dump', () => {
expect(dump).to.deep.eq([ expect(dump).to.deep.eq([
{ id: '"}G', time: 100, cmd: 14, value: 0n, mask: 0n }, { id: '"}G', time: 100, cmd: 14, value: 0n, mask: 0n },
{ id: '"}G', time: 200, cmd: 15, value: 1n, 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: '"}G', time: 300, cmd: 14, value: 0n, mask: 0n },
{ id: '{u', time: 300, cmd: 19, value: 0xf000000000000000n, mask: 0n }, { id: '{u', time: 300, cmd: 30, value: 0xf000000000000000n, mask: 0n },
{ id: '{u', time: 301, cmd: 19, value: 0x0f00000000000000n, mask: 0n }, { id: '{u', time: 301, cmd: 30, value: 0x0f00000000000000n, mask: 0n },
{ id: '{u', time: 302, cmd: 19, value: 0x00f0000000000000n, mask: 0n }, { id: '{u', time: 302, cmd: 30, value: 0x00f0000000000000n, mask: 0n },
{ id: '{u', time: 303, cmd: 19, value: 0x000f000000000000n, mask: 0n }, { id: '{u', time: 303, cmd: 30, value: 0x000f000000000000n, mask: 0n },
{ id: '{u', time: 304, cmd: 19, value: 0x0000f00000000000n, mask: 0n }, { id: '{u', time: 304, cmd: 30, value: 0x0000f00000000000n, mask: 0n },
{ id: '{u', time: 305, cmd: 19, value: 0x00000f0000000000n, mask: 0n }, { id: '{u', time: 305, cmd: 30, value: 0x00000f0000000000n, mask: 0n },
{ id: '{u', time: 306, cmd: 19, value: 0x000000f000000000n, mask: 0n }, { id: '{u', time: 306, cmd: 30, value: 0x000000f000000000n, mask: 0n },
{ id: '{u', time: 307, cmd: 19, value: 0x0000000f00000000n, 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: 308, cmd: 20, value: 0x00000000f0000000n, mask: 0n },
{ id: '{u', time: 309, cmd: 19, value: 0x000000000f000000n, mask: 0n }, { id: '{u', time: 309, cmd: 30, value: 0x000000000f000000n, mask: 0n },
{ id: '{u', time: 310, cmd: 19, value: 0x0000000000f00000n, mask: 0n }, { id: '{u', time: 310, cmd: 30, value: 0x0000000000f00000n, mask: 0n },
{ id: '{u', time: 311, cmd: 19, value: 0x00000000000f0000n, mask: 0n }, { id: '{u', time: 311, cmd: 30, value: 0x00000000000f0000n, mask: 0n },
{ id: '{u', time: 312, cmd: 19, value: 0x000000000000f000n, mask: 0n }, { id: '{u', time: 312, cmd: 30, value: 0x000000000000f000n, mask: 0n },
{ id: '{u', time: 313, cmd: 19, value: 0x0000000000000f00n, mask: 0n }, { id: '{u', time: 313, cmd: 30, value: 0x0000000000000f00n, mask: 0n },
{ id: '{u', time: 314, cmd: 19, value: 0x00000000000000f0n, mask: 0n }, { id: '{u', time: 314, cmd: 30, value: 0x00000000000000f0n, mask: 0n },
{ id: '{u', time: 315, cmd: 19, value: 0x000000000000000fn, mask: 0n }, { id: '{u', time: 315, cmd: 30, value: 0x000000000000000fn, mask: 0n },
{ id: '"}G', time: 316, cmd: 15, value: 1n, mask: 0n } { id: '"}G', time: 316, cmd: 15, value: 1n, mask: 0n }
]); ]);
done(); done();

4
vcd.c
View File

@ -136,7 +136,7 @@ METHOD(init) {
state->tmpStr2 = tmpStr2; state->tmpStr2 = tmpStr2;
state->value = valueBuf; state->value = valueBuf;
state->mask = maskBuf; state->mask = maskBuf;
state->time = 0; // UINT64_MAX; state->time = INT64_MAX;
state->digitCount = 0; state->digitCount = 0;
napi_value status; napi_value status;
@ -206,7 +206,7 @@ METHOD(getTime) {
ASSERT_EXTERNAL(args[0], state) ASSERT_EXTERNAL(args[0], state)
napi_value res; 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; return res;
} }

View File

@ -263,11 +263,11 @@ int onDigit(
int timeSpan(vcd_parser_t* state, const unsigned char* p, const unsigned char* endp) { int timeSpan(vcd_parser_t* state, const unsigned char* p, const unsigned char* endp) {
int64_t time = strtoul((const char *)p, (char **)&endp, 10); int64_t time = strtoul((const char *)p, (char **)&endp, 10);
if (state->time == UINT64_MAX) { if (state->time == INT64_MAX) {
#ifndef VCDWASM #ifndef VCDWASM
napi_env env = state->napi_env; napi_env env = state->napi_env;
napi_value val; 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)) ASSERT(state->info, napi_set_named_property(env, state->info, "t0", val))
#else #else
set_property_int("t0", time); set_property_int("t0", time);

View File

@ -10,8 +10,18 @@ using namespace std;
/// Typedef used as part of c->js call /// Typedef used as part of c->js call
typedef void externalJsMethodZero(const char* name, const size_t len); 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 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 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); typedef void externalJsSetProperty(const char* name, const size_t len, const int type, const int v0, const int v1);
@ -55,7 +65,14 @@ void emit_lifee(const char* name) {
externalZero(name, strlen(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; // return;
// externalOne( // externalOne(
@ -120,7 +137,7 @@ int init(
state->value = valueBuf; state->value = valueBuf;
state->mask = maskBuf; state->mask = maskBuf;
state->digitCount = 0; state->digitCount = 0;
state->time = 0; // UINT64_MAX; state->time = INT64_MAX;
set_property_string("status", "declaration"); set_property_string("status", "declaration");
@ -164,7 +181,7 @@ int setTrigger(const int context, char* triggerString) {
return 0; return 0;
} }
uint64_t getTime(const int context) { int64_t getTime(const int context) {
return state->time; return state->time;
} }

View File

@ -8,4 +8,11 @@ void set_path_to_path(const char* name, const char* value);
void new_object_path(const char* name); void new_object_path(const char* name);
int get_property_int(const char* name); int get_property_int(const char* name);
void emit_lifee(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
);