prepare for parsing
This commit is contained in:
parent
f46ad25c19
commit
4378dc826e
@ -19,7 +19,7 @@ module.exports = () => {
|
|||||||
|
|
||||||
const bindCWrap = () => {
|
const bindCWrap = () => {
|
||||||
const w = wasm.cwrap;
|
const w = wasm.cwrap;
|
||||||
c.execute = w('execute', 'void', ['number', 'number', 'number', 'number', 'number', 'string']);
|
c.execute = w('execute', 'number', ['number', 'number', 'number', 'number', 'number', 'string']);
|
||||||
c.init = w('init', 'number', ['number', 'number', 'number', 'number']);
|
c.init = w('init', 'number', ['number', 'number', 'number', 'number']);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ describe('basic', () => {
|
|||||||
|
|
||||||
wrapper.execute();
|
wrapper.execute();
|
||||||
|
|
||||||
expect(info.foo).to.equal(10);
|
// expect(info.foo).to.equal(10);
|
||||||
// console.log(wrapper.log());
|
// console.log(wrapper.log());
|
||||||
|
|
||||||
|
|
||||||
|
124
test/wasmdump.js
Normal file
124
test/wasmdump.js
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const expect = require('chai').expect;
|
||||||
|
// const lib = require('../lib/index.js');
|
||||||
|
const lib = require('../lib/wrapper.js')();
|
||||||
|
|
||||||
|
describe('dump', () => {
|
||||||
|
|
||||||
|
before(() => {
|
||||||
|
return lib.start();
|
||||||
|
});
|
||||||
|
|
||||||
|
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(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();
|
||||||
|
});
|
||||||
|
|
||||||
|
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
|
||||||
|
bzzzzxxxx11110000ZZZZXXXX11110000zzzzxxx`);
|
||||||
|
|
||||||
|
// break in the middle of the number scan
|
||||||
|
|
||||||
|
inst.write( `x11110000zzzzxxxx11110000 {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();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
/* eslint-env mocha */
|
@ -11,6 +11,8 @@ typedef void* napi_env;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// #define LOGSPAN
|
||||||
|
#define LOGSPAN printf("%s\n", __FUNCTION__);
|
||||||
|
|
||||||
|
|
||||||
#define ASSERT(val, expr) \
|
#define ASSERT(val, expr) \
|
||||||
@ -62,6 +64,7 @@ int stringEq (
|
|||||||
}
|
}
|
||||||
|
|
||||||
int commandSpan(vcd_parser_t* state, const unsigned char* p, const unsigned char* endp) {
|
int commandSpan(vcd_parser_t* state, const unsigned char* p, const unsigned char* endp) {
|
||||||
|
LOGSPAN;
|
||||||
napi_env env = state->napi_env;
|
napi_env env = state->napi_env;
|
||||||
|
|
||||||
if (state->command == 5) { // $upscope
|
if (state->command == 5) { // $upscope
|
||||||
@ -87,6 +90,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) {
|
int scopeIdentifierSpan(vcd_parser_t* state, const unsigned char* p, const unsigned char* endp) {
|
||||||
|
LOGSPAN;
|
||||||
#ifndef VCDWASM
|
#ifndef VCDWASM
|
||||||
napi_env env = state->napi_env;
|
napi_env env = state->napi_env;
|
||||||
// *(endp - 1) = 0; // FIXME NULL termination of ASCII string
|
// *(endp - 1) = 0; // FIXME NULL termination of ASCII string
|
||||||
@ -104,6 +108,7 @@ 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) {
|
int varSizeSpan(vcd_parser_t* state, const unsigned char* p, const unsigned char* endp) {
|
||||||
|
LOGSPAN;
|
||||||
state->size = strtol((const char *)p, (char **)&endp, 10);
|
state->size = strtol((const char *)p, (char **)&endp, 10);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -88,34 +88,56 @@ int init(
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int32_t execute(
|
||||||
|
|
||||||
|
|
||||||
void execute(
|
|
||||||
const int context,
|
const int context,
|
||||||
externalJsMethodOne* f1,
|
externalJsMethodOne* f1,
|
||||||
externalJsMethodTwo* f2,
|
externalJsMethodTwo* f2,
|
||||||
externalJsSetProperty* sfn,
|
externalJsSetProperty* sfn,
|
||||||
externalJsGetProperty* gfn,
|
externalJsGetProperty* gfn,
|
||||||
char* chunk
|
char* p
|
||||||
) {
|
) {
|
||||||
|
|
||||||
// cout << "execute got " << p << "\n";
|
// cout << "execute got " << p << "\n";
|
||||||
cout << "execute " << (int)sfn << " and got " << chunk << "\n";
|
cout << "execute " << (int)sfn << " and got " << p << "\n";
|
||||||
bound_set_property = sfn;
|
bound_set_property = sfn;
|
||||||
bound_get_property = gfn;
|
bound_get_property = gfn;
|
||||||
externalOne = f1;
|
externalOne = f1;
|
||||||
externalTwo = f2;
|
externalTwo = f2;
|
||||||
|
|
||||||
set_property_int("foo", 10);
|
const size_t plen = strlen(p);
|
||||||
|
|
||||||
|
const int32_t error = vcd_parser_execute(state, p, p + plen);
|
||||||
|
|
||||||
int got = get_property("bar");
|
return error;
|
||||||
|
|
||||||
cout << "got " << got << " for bar\n";
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// void execute(
|
||||||
|
// const int context,
|
||||||
|
// externalJsMethodOne* f1,
|
||||||
|
// externalJsMethodTwo* f2,
|
||||||
|
// externalJsSetProperty* sfn,
|
||||||
|
// externalJsGetProperty* gfn,
|
||||||
|
// char* chunk
|
||||||
|
// ) {
|
||||||
|
|
||||||
|
// // cout << "execute got " << p << "\n";
|
||||||
|
// cout << "execute " << (int)sfn << " and got " << chunk << "\n";
|
||||||
|
// bound_set_property = sfn;
|
||||||
|
// bound_get_property = gfn;
|
||||||
|
// externalOne = f1;
|
||||||
|
// externalTwo = f2;
|
||||||
|
|
||||||
|
// set_property_int("foo", 10);
|
||||||
|
|
||||||
|
|
||||||
|
// int got = get_property("bar");
|
||||||
|
|
||||||
|
// cout << "got " << got << " for bar\n";
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
cout << "main()\n";
|
cout << "main()\n";
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user