Skip to content

Commit

Permalink
close, off by 1 somewhere
Browse files Browse the repository at this point in the history
  • Loading branch information
esromneb committed Sep 28, 2020
1 parent c95aeaf commit 3a56ab2
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 53 deletions.
8 changes: 5 additions & 3 deletions lib/wasmparser.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ module.exports = async () => {
const cxt = lib.init(lifemit, triemit, info);

s._write = function (chunk, encoding, callback) {
console.log('about to write', chunk);
// console.log('about to write', chunk);
lib.execute(cxt, lifemit, triemit2, info, chunk);
console.log(util.inspect(info, {showHidden: true, depth : null, colorize: true}));
// console.log(info);
// console.log(util.inspect(info, {showHidden: true, depth : null, colorize: true}));
// console.log(info.stack[0].top);
// console.log(info.stack[1]);
// console.log(info.stack[0].top == info.stack[1]);
callback();
};

Expand Down
43 changes: 37 additions & 6 deletions lib/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@ function _waitForStart(mod) {
});
}

function u8ToBn(u8) {
var hex = [];
// let u8 = Uint8Array.from(buf);

u8.forEach(function (i) {
var h = i.toString(16);
if (h.length % 2) { h = '0' + h; }
hex.push(h);
});

return BigInt('0x' + hex.join(''));
}



module.exports = () => {
// let state = 0; // idle
// let total = 0;
Expand Down Expand Up @@ -56,6 +71,7 @@ module.exports = () => {

let context = -1;


// wasm.addFunction can't be called until after
// start finishes
bindCallback = () => {
Expand All @@ -77,17 +93,17 @@ module.exports = () => {
// set string to path
case 2:
dotProp.set(boundInfo, prop, getString(v0, v1));
console.log(`setting ${prop} to ${getString(v0, v1)}`);
// console.log(`setting ${prop} to ${getString(v0, v1)}`);
break;
// path to path (any type)
case 3:
let tmp = dotProp.get(boundInfo, getString(v0, v1));
console.log(`for ${getString(v0, v1)} got ${tmp}, set to ${prop}`);
// console.log(`for ${getString(v0, v1)} got ${tmp}, set to ${prop}`);
dotProp.set(boundInfo, prop, tmp);
break;
// create empty object at path
case 4:
console.log(`${prop} is new {}`);
// console.log(`${prop} is new {}`);
dotProp.set(boundInfo, prop, {});
break;

Expand All @@ -108,9 +124,24 @@ module.exports = () => {
ee[0](getString(name, len));
}, 'vii');

boundEE1 = wasm.addFunction(function(eventName, l0, time, command, value, mask) {
ee[1](getString(eventName, l0), time, command, value, mask);
}, 'viiiiii');
// const char* name, const size_t len, const uint64_t time, const uint8_t command, const int valueWords, const uint64_t* aValue, const uint64_t* aMask);
// boundEE1 = wasm.addFunction(function(eventName, l0, time, command, valueWords, value, mask) {
boundEE1 = wasm.addFunction(function(eventName, l0, time, command, valueWords, value, mask) {
const name = getString(eventName, l0);
// console.log(`event name`);
// console.log(`event ${name} time ${time} cmd ${command} wrds ${valueWords}`);


const view0 = wasm.HEAPU8.subarray(value, value+(valueWords*8));
const view1 = wasm.HEAPU8.subarray(mask, mask+(valueWords*8));

let big_value = u8ToBn(view0);
let big_mask = u8ToBn(view1);

console.log(big_value.toString(16));

ee[1](name, time, command, big_value, big_mask);
}, 'viiiiiii');

};

Expand Down
95 changes: 66 additions & 29 deletions test/wasmdump.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,30 @@ 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 },
// { id: '{u', time: 200, cmd: 19, 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: '"}G', time: 316, cmd: 15, value: 1n, mask: 0n },
// ])
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 },
{ id: '{u', time: 200, cmd: 19, 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: '"}G', time: 316, cmd: 15, value: 1n, mask: 0n },
])
// console.log(dump);
done();
});
Expand All @@ -68,18 +68,55 @@ $timescale 1ns $end
$scope module top $end
$var wire 1 "}G clock $end
$scope module leaf $end
$var wire 64 {u counter [63:0] $end
$upscope $end
$scope module fruit $end
$var wire 4 u) point [3:0] $end
$upscope $end
$upscope $end
$enddefinitions $end
#100
0"}G
#200
1"}G
`);

// break in the middle of the number scan

inst.write( `x11110000zzzzxxxx11110000 {u
bzzzzxxxx11110000ZZZZXXXX11110000zzzzxxxx11110000zzzzxxxx11110000 {u
#300
0"}G
b1111000000000000000000000000000000000000000000000000000000000000 {u
#301
b0000111100000000000000000000000000000000000000000000000000000000 {u
#302
b0000000011110000000000000000000000000000000000000000000000000000 {u
#303
b0000000000001111000000000000000000000000000000000000000000000000 {u
#304
b0000000000000000111100000000000000000000000000000000000000000000 {u
#305
b0000000000000000000011110000000000000000000000000000000000000000 {u
#306
b0000000000000000000000001111000000000000000000000000000000000000 {u
#307
b0000000000000000000000000000111100000000000000000000000000000000 {u
#308
B0000000000000000000000000000000011110000000000000000000000000000 {u
#309
b0000000000000000000000000000000000001111000000000000000000000000 {u
#310
b0000000000000000000000000000000000000000111100000000000000000000 {u
#311
b0000000000000000000000000000000000000000000011110000000000000000 {u
#312
b0000000000000000000000000000000000000000000000001111000000000000 {u
#313
b0000000000000000000000000000000000000000000000000000111100000000 {u
#314
b0000000000000000000000000000000000000000000000000000000011110000 {u
#315
b0000000000000000000000000000000000000000000000000000000000001111 {u
#316
1"}G
`);
inst.end();
});
Expand Down
44 changes: 33 additions & 11 deletions vcd_spans.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ int commandSpan(vcd_parser_t* state, const unsigned char* p, const unsigned char
}

int scopeIdentifierSpan(vcd_parser_t* state, const unsigned char* p, const unsigned char* endp) {
LOGSPAN;
// LOGSPAN;
#ifndef VCDWASM
napi_env env = state->napi_env;
strcopy(p, endp, state->tmpStr);
Expand All @@ -107,14 +107,14 @@ int scopeIdentifierSpan(vcd_parser_t* state, const unsigned char* p, const unsig
ASSERT(state->info, napi_get_named_property(env, state->info, "stack", &stack))

// get the top of the stack in top
printf("Got stack %d\n", state->stackPointer);
// printf("Got stack %d\n", state->stackPointer);
ASSERT(top, napi_get_element(env, stack, state->stackPointer, &top))

// set top.prop to new object
printf("Set top of stack[%d].%s to {}\n", state->stackPointer, (char*)state->tmpStr);
// printf("Set top of stack[%d].%s to {}\n", state->stackPointer, (char*)state->tmpStr);
ASSERT(top, napi_set_named_property(env, top, state->tmpStr, obj))

printf("Set top+1 of stack to top %d, %d\n", state->stackPointer, state->stackPointer+1);
// printf("Set top+1 of stack to top %d, %d\n", state->stackPointer, state->stackPointer+1);
state->stackPointer += 1;
ASSERT(top, napi_set_element(env, stack, state->stackPointer, obj))
#else
Expand All @@ -136,13 +136,13 @@ int scopeIdentifierSpan(vcd_parser_t* state, const unsigned char* p, const unsig
}

int varSizeSpan(vcd_parser_t* state, const unsigned char* p, const unsigned char* endp) {
LOGSPAN;
// LOGSPAN;
state->size = strtol((const char *)p, (char **)&endp, 10);
return 0;
}

int varIdSpan(vcd_parser_t* state, const unsigned char* p, const unsigned char* endp) {
LOGSPAN;
// LOGSPAN;
#ifndef VCDWASM
napi_env env = state->napi_env;
napi_value varId;
Expand All @@ -156,7 +156,7 @@ int varIdSpan(vcd_parser_t* state, const unsigned char* p, const unsigned char*
}

int varNameSpan(vcd_parser_t* state, const unsigned char* p, const unsigned char* endp) {
LOGSPAN;
// LOGSPAN;
#ifndef VCDWASM
napi_env env = state->napi_env;
// *(endp - 1) = 0; // FIXME NULL termination of ASCII string
Expand All @@ -177,10 +177,18 @@ int varNameSpan(vcd_parser_t* state, const unsigned char* p, const unsigned char
}

int idSpan(vcd_parser_t* state, const unsigned char* p, const unsigned char* endp) {
LOGSPAN;
#ifndef VCDWASM
napi_env env = state->napi_env;
#endif

// uint64_t foo = 0x123456789abcdef0;

// printf(" '%s' ", state->trigger);

const int valueWords = (state->digitCount >> 6) + 1;
uint64_t* value = state->value;
// value = &foo;
uint64_t* mask = state->mask;
if (stringEq((state->trigger), p, endp)) {
const uint8_t command = state->command;
Expand All @@ -192,22 +200,33 @@ int idSpan(vcd_parser_t* state, const unsigned char* p, const unsigned char* end
value[0] = 1;
mask[0] = 0;
}
printf("valueWords %d %d %d\n", valueWords, (int)command, state->digitCount);
printf("\ntriee %lx\n", *value);
#ifndef VCDWASM
napi_value undefined, eventName, aTime, aCommand, aValue, aMask, return_val;
ASSERT(undefined, napi_get_undefined(env, &undefined))
ASSERT(eventName, napi_create_string_latin1(env, (char*)p, (endp - p - 1), &eventName))
ASSERT(aTime, napi_create_int64(env, state->time, &aTime))
ASSERT(aCommand, napi_create_int32(env, command, &aCommand))
ASSERT(aValue, napi_create_bigint_words(env, 0, valueWords, value, &aValue))
ASSERT(aMask, napi_create_bigint_words(env, 0, valueWords, mask, &aMask))


napi_value* argv[] = {&eventName, &aTime, &aCommand, &aValue, &aMask};
ASSERT(state->triee, napi_call_function(env, undefined, state->triee, 5, *argv, &return_val))

#else

// printf("\ntriee %lx\n", *value);
strcopy(p, endp, state->tmpStr);
emit_triee(state->tmpStr, state->time, command, valueWords, value, mask);
#endif
}
for (int i = 0; i < valueWords; i++) {
value[i] = 0;
mask[i] = 0;
}
state->digitCount = 0;
#endif
return 0;
}

Expand All @@ -217,7 +236,6 @@ int onDigit(
const unsigned char* endp,
int digit
) {
#ifndef VCDWASM
unsigned int valueCin = (digit & 1);
unsigned int maskCin = ((digit >> 1) & 1);
unsigned int valueCout;
Expand All @@ -234,10 +252,14 @@ int onDigit(
maskCout = mask[i] >> 63;
mask[i] = (mask[i] << 1) + maskCin;
maskCin = maskCout;

// unsigned char* c = p;
// while(c != endp) {
// puts(c); c++;
// }
}
char c = *p;
printf("%c", c);
state->digitCount += 1;
#endif
return 0;
}

Expand Down
Loading

0 comments on commit 3a56ab2

Please sign in to comment.