getting commandSpans now
This commit is contained in:
parent
4378dc826e
commit
98eb19cd69
2
Makefile
2
Makefile
@ -24,6 +24,8 @@ vcd_spans.c \
|
||||
EXPORT_STRING = \
|
||||
"_execute", \
|
||||
"_init", \
|
||||
"_setTrigger", \
|
||||
"_getTime", \
|
||||
|
||||
# warning and error flags
|
||||
CLANG_WARN_FLAGS = \
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
const pkg = require('../package.json');
|
||||
const parser = require('./parser.js');
|
||||
const wasmparser = require('./wasmparser.js');
|
||||
const and = require('./and.js');
|
||||
const activity = require('./activity.js');
|
||||
const wrapper = require('./wrapper.js');
|
||||
@ -11,5 +12,6 @@ module.exports = {
|
||||
and: and,
|
||||
activity: activity,
|
||||
parser: parser,
|
||||
wasmparser: wasmparser,
|
||||
wrapper: wrapper
|
||||
};
|
||||
|
62
lib/wasmparser.js
Normal file
62
lib/wasmparser.js
Normal file
@ -0,0 +1,62 @@
|
||||
'use strict';
|
||||
|
||||
const stream = require('stream');
|
||||
const EventEmitter = require('events').EventEmitter;
|
||||
// let lib = require('bindings')('vcd.node');
|
||||
|
||||
|
||||
module.exports = async () => {
|
||||
|
||||
const lib = require('../lib/wrapper.js')();
|
||||
await lib.start();
|
||||
|
||||
const wires = {};
|
||||
const info = {stack: [wires], wires: wires};
|
||||
|
||||
const s = new stream.Writable();
|
||||
|
||||
|
||||
// gets called by c with 1 argument, a number
|
||||
const lifemit = s.emit.bind(s);
|
||||
|
||||
const triee = new EventEmitter();
|
||||
|
||||
// gets called by c with 5 arguments
|
||||
// string eventName
|
||||
// number state->time
|
||||
// int command
|
||||
// int state->value
|
||||
// int state->mask
|
||||
|
||||
const triemit = triee.emit.bind(triee);
|
||||
let triemit2 = triemit;
|
||||
|
||||
const cxt = lib.init(lifemit, triemit, info);
|
||||
|
||||
s._write = function (chunk, encoding, callback) {
|
||||
console.log('about to write', chunk);
|
||||
lib.execute(cxt, lifemit, triemit2, info, chunk);
|
||||
callback();
|
||||
};
|
||||
|
||||
s.change = {
|
||||
on: (id, fn) => {
|
||||
triemit2 = triemit;
|
||||
triee.on(id, fn);
|
||||
const triggerString = triee.eventNames().join(' ') + ' ';
|
||||
lib.setTrigger(cxt, triggerString);
|
||||
},
|
||||
any: fn => {
|
||||
triemit2 = fn;
|
||||
lib.setTrigger(cxt, '\0');
|
||||
}
|
||||
};
|
||||
|
||||
s.info = info;
|
||||
|
||||
s.getTime = () => lib.getTime(cxt);
|
||||
|
||||
s.start = lib.start;
|
||||
|
||||
return s;
|
||||
};
|
@ -19,8 +19,10 @@ module.exports = () => {
|
||||
|
||||
const bindCWrap = () => {
|
||||
const w = wasm.cwrap;
|
||||
c.execute = w('execute', 'number', ['number', 'number', 'number', 'number', 'number', 'string']);
|
||||
c.init = w('init', 'number', ['number', 'number', 'number', 'number']);
|
||||
c.execute = w('execute', 'number', ['number', 'number', 'number', 'number', 'number', 'string']);
|
||||
c.init = w('init', 'number', ['number', 'number', 'number', 'number']);
|
||||
c.getTime = w('getTime', 'number', ['number']);
|
||||
c.setTrigger = w('setTrigger', 'number', ['number', 'string']);
|
||||
};
|
||||
|
||||
const start = async() => {
|
||||
@ -45,6 +47,11 @@ module.exports = () => {
|
||||
let boundSet;
|
||||
let boundGet;
|
||||
|
||||
let ee = [];
|
||||
|
||||
let boundEE0;
|
||||
let boundEE1;
|
||||
|
||||
let context = -1;
|
||||
|
||||
// wasm.addFunction can't be called until after
|
||||
@ -72,7 +79,16 @@ module.exports = () => {
|
||||
boundGet = wasm.addFunction(function(name, len) {
|
||||
let prop = getString(name, len);
|
||||
return 42;
|
||||
}, 'iii');
|
||||
}, 'iii');
|
||||
|
||||
boundEE0 = wasm.addFunction(function(val) {
|
||||
ee[0].emit(val);
|
||||
}, 'vi');
|
||||
|
||||
boundEE1 = wasm.addFunction(function(eventName, l0, time, command, value, mask) {
|
||||
ee[1].emit(getString(eventName, l0), time, command, value, mask);
|
||||
}, 'viiiiii');
|
||||
|
||||
};
|
||||
|
||||
return {
|
||||
@ -83,22 +99,18 @@ module.exports = () => {
|
||||
},
|
||||
init: (cb0, cb1, info) => {
|
||||
boundInfo = info;
|
||||
context = c.init(0,0,boundSet,boundGet);
|
||||
ee[0] = cb0;
|
||||
ee[1] = cb1;
|
||||
context = c.init(boundEE0,boundEE1,boundSet,boundGet);
|
||||
},
|
||||
execute: () => {
|
||||
c.execute(context,0,0,boundSet,boundGet,"hi");
|
||||
execute: (ctx, lifemit, triemit, info, chunk) => {
|
||||
c.execute(ctx,0,0,boundSet,boundGet,chunk.toString());
|
||||
},
|
||||
onB: (time, cmd) => {
|
||||
|
||||
setTrigger: (ctx, triggerString) => {
|
||||
return c.setTrigger(ctx, triggerString);
|
||||
},
|
||||
onNotB: (time, cmd) => {
|
||||
switch(state) {
|
||||
case 0: if (cmd === 14) { state = 2; } break;
|
||||
case 1: if (cmd === 14) { state = 3; start = time; } break;
|
||||
case 2: if (cmd === 15) { state = 0; } break;
|
||||
case 3: if (cmd === 15) { state = 1; total += (time - start); start = 0; } break;
|
||||
default: throw new Error();
|
||||
}
|
||||
getTime: (ctx) => {
|
||||
return c.getTime(ctx);
|
||||
},
|
||||
time: () => total + start
|
||||
};
|
||||
|
@ -5,7 +5,7 @@
|
||||
"main": "lib/index.js",
|
||||
"scripts": {
|
||||
"testlint": "eslint bin lib && nyc -r=text -r=lcov mocha",
|
||||
"test": "nyc -r=text -r=lcov mocha",
|
||||
"test": "eslint bin lib; nyc -r=text -r=lcov mocha",
|
||||
"testonly": "nyc -r=text -r=lcov mocha",
|
||||
"watch": "mocha --watch",
|
||||
"install": "node bin/build.js",
|
||||
|
@ -1,17 +1,22 @@
|
||||
'use strict';
|
||||
|
||||
const expect = require('chai').expect;
|
||||
// const lib = require('../lib/index.js');
|
||||
const lib = require('../lib/wrapper.js')();
|
||||
const lib = require('../lib/index.js');
|
||||
|
||||
describe('dump', () => {
|
||||
|
||||
let inst;
|
||||
|
||||
// return a promise, and mocha will wait until it resolves
|
||||
before(() => {
|
||||
return lib.start();
|
||||
const fn = async () => {
|
||||
inst = await lib.wasmparser();
|
||||
};
|
||||
return fn();
|
||||
});
|
||||
|
||||
it('simple', done => {
|
||||
const inst = lib.parser();
|
||||
|
||||
const dump = [];
|
||||
['"}G', '{u', 'u)'] // array of all signal ids
|
||||
.map(id =>
|
||||
|
@ -7,8 +7,8 @@ using namespace std;
|
||||
|
||||
|
||||
/// Typedef used as part of c->js call
|
||||
typedef void externalJsMethodOne(const int sz);
|
||||
typedef void externalJsMethodTwo(const char*, const uint64_t time, const uint8_t command, const int dnc0, const int dnc1);
|
||||
typedef void externalJsMethodZero(const int sz);
|
||||
typedef void externalJsMethodOne (const char*, const uint64_t time, const uint8_t command, const int dnc0, const int dnc1);
|
||||
|
||||
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);
|
||||
@ -16,8 +16,8 @@ typedef void externalJsSetProperty(const char* name, const size_t len, const int
|
||||
|
||||
|
||||
/// function pointer for c->js
|
||||
static externalJsMethodOne* externalOne = 0;
|
||||
static externalJsMethodTwo* externalTwo = 0;
|
||||
static externalJsMethodZero* externalZero = 0;
|
||||
static externalJsMethodOne* externalOne = 0;
|
||||
static externalJsSetProperty* bound_set_property = 0;
|
||||
static externalJsGetProperty* bound_get_property = 0;
|
||||
|
||||
@ -40,8 +40,8 @@ extern "C" {
|
||||
|
||||
// returns context
|
||||
int init(
|
||||
externalJsMethodOne* f1,
|
||||
externalJsMethodTwo* f2,
|
||||
externalJsMethodZero* f0,
|
||||
externalJsMethodOne* f1,
|
||||
externalJsSetProperty* sfn,
|
||||
externalJsGetProperty* gfn
|
||||
) {
|
||||
@ -57,11 +57,11 @@ int init(
|
||||
|
||||
bound_set_property = sfn;
|
||||
bound_get_property = gfn;
|
||||
externalOne = f1;
|
||||
externalTwo = f2;
|
||||
externalZero = f0;
|
||||
externalOne = f1;
|
||||
|
||||
state->lifee = (void*) externalOne;
|
||||
state->triee = (void*) externalTwo;
|
||||
state->lifee = (void*) externalZero;
|
||||
state->triee = (void*) externalOne;
|
||||
|
||||
static char triggerString [4096] = " ";
|
||||
static char tmpStr [4096] = " ";
|
||||
@ -90,19 +90,19 @@ int init(
|
||||
|
||||
int32_t execute(
|
||||
const int context,
|
||||
externalJsMethodOne* f1,
|
||||
externalJsMethodTwo* f2,
|
||||
externalJsMethodZero* f0,
|
||||
externalJsMethodOne* f1,
|
||||
externalJsSetProperty* sfn,
|
||||
externalJsGetProperty* gfn,
|
||||
char* p
|
||||
) {
|
||||
|
||||
// cout << "execute got " << p << "\n";
|
||||
cout << "execute " << (int)sfn << " and got " << p << "\n";
|
||||
// cout << "execute " << (int)sfn << " and got " << p << "\n";
|
||||
bound_set_property = sfn;
|
||||
bound_get_property = gfn;
|
||||
externalOne = f1;
|
||||
externalTwo = f2;
|
||||
externalZero = f0;
|
||||
externalOne = f1;
|
||||
|
||||
const size_t plen = strlen(p);
|
||||
|
||||
@ -111,12 +111,21 @@ int32_t execute(
|
||||
return error;
|
||||
}
|
||||
|
||||
int setTrigger(const int context, char* triggerString) {
|
||||
cout << "setTrigger() got " << triggerString << "\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
int getTime(const int context) {
|
||||
return state->time;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// void execute(
|
||||
// const int context,
|
||||
// externalJsMethodZero* f0,
|
||||
// externalJsMethodOne* f1,
|
||||
// externalJsMethodTwo* f2,
|
||||
// externalJsSetProperty* sfn,
|
||||
// externalJsGetProperty* gfn,
|
||||
// char* chunk
|
||||
@ -126,8 +135,8 @@ int32_t execute(
|
||||
// cout << "execute " << (int)sfn << " and got " << chunk << "\n";
|
||||
// bound_set_property = sfn;
|
||||
// bound_get_property = gfn;
|
||||
// externalZero = f0;
|
||||
// externalOne = f1;
|
||||
// externalTwo = f2;
|
||||
|
||||
// set_property_int("foo", 10);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user