added value/mask arguments to the onChange callback

This commit is contained in:
Aliaksei Chapyzhenka 2020-09-13 18:29:59 -07:00
parent 9da99afa88
commit 9ebcbacb4d
3 changed files with 135 additions and 7 deletions

View File

@ -26,11 +26,13 @@ const generate = cb => {
p.property('i8', 'command'); p.property('i8', 'command');
p.property('i8', 'type'); p.property('i8', 'type');
p.property('i32', 'size'); p.property('i32', 'size');
p.property('i32', 'time'); p.property('i64', 'time');
p.property('ptr', 'trigger'); p.property('ptr', 'trigger');
p.property('ptr', 'triee'); p.property('ptr', 'triee');
p.property('ptr', 'lifee'); p.property('ptr', 'lifee');
p.property('ptr', 'info'); p.property('ptr', 'info');
p.property('i64', 'value');
p.property('i64', 'mask');
p.property('ptr', 'tmpStr'); p.property('ptr', 'tmpStr');
p.property('i32', 'stackPointer'); p.property('i32', 'stackPointer');
p.property('ptr', 'id'); p.property('ptr', 'id');

112
test/dump.js Normal file
View File

@ -0,0 +1,112 @@
'use strict';
const expect = require('chai').expect;
const lib = require('../lib/index.js');
describe('dump', () => {
it('simple', done => {
const inst = lib.parser();
const dump = [];
['"}G', '{u', 'u)'] // array of all signal ids
.map(id =>
inst.change.on(id, (time, cmd, value, mask) => {
dump.push({
id,
time,
cmd,
value,
mask
});
})
);
inst.on('finish', () => {
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: '"}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: 19, 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();
});
inst.write(`
$version Generated by VerilatedVcd $end
$date Wed Sep 18 22:59:07 2019
$end
$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
#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();
});
});
/* eslint-env mocha */

View File

@ -114,22 +114,36 @@ 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) { int idSpan(vcd_parser_t* state, const unsigned char* p, const unsigned char* endp) {
napi_env env = state->napi_env; napi_env env = state->napi_env;
if (stringEq((state->trigger), p, endp)) { if (stringEq((state->trigger), p, endp)) {
napi_value undefined, eventName, eventPayload1, eventPayload2, return_val; const uint8_t command = state->command;
uint64_t value = state->value;
uint64_t mask = state->mask;
if (command == 14) {
value = 0;
mask = 0;
} else
if (command == 15) {
value = 1;
mask = 0;
}
napi_value undefined, eventName, aTime, aCommand, aValue, aMask, return_val;
ASSERT(undefined, napi_get_undefined(env, &undefined)) ASSERT(undefined, napi_get_undefined(env, &undefined))
ASSERT(eventName, napi_create_string_latin1(env, (char*)p, (endp - p - 1), &eventName)) ASSERT(eventName, napi_create_string_latin1(env, (char*)p, (endp - p - 1), &eventName))
ASSERT(eventPayload1, napi_create_int32(env, state->time, &eventPayload1)) ASSERT(aTime, napi_create_int64(env, state->time, &aTime))
ASSERT(eventPayload2, napi_create_int32(env, state->command, &eventPayload2)) ASSERT(aCommand, napi_create_int32(env, command, &aCommand))
napi_value* argv[] = { &eventName, &eventPayload1, &eventPayload2 }; ASSERT(aValue, napi_create_bigint_uint64(env, value, &aValue))
ASSERT(state->triee, napi_call_function(env, undefined, state->triee, 3, *argv, &return_val)) ASSERT(aMask, napi_create_bigint_uint64(env, mask, &aMask))
napi_value* argv[] = {&eventName, &aTime, &aCommand, &aValue, &aMask};
ASSERT(state->triee, napi_call_function(env, undefined, state->triee, 5, *argv, &return_val))
} }
return 0; return 0;
} }
int vectorSpan(vcd_parser_t* state, const unsigned char* p, const unsigned char* endp) { int vectorSpan(vcd_parser_t* state, const unsigned char* p, const unsigned char* endp) {
state->value = strtoul((const char *)p, (char **)&endp, 2);
return 0; return 0;
} }
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) {
state->time = strtol((const char *)p, (char **)&endp, 10); state->time = strtoul((const char *)p, (char **)&endp, 10);
return 0; return 0;
} }