streaming version of parser
This commit is contained in:
parent
948293213f
commit
08144a4d7b
20
bin/find.js
20
bin/find.js
@ -10,7 +10,7 @@ const dir = './tmp/';
|
|||||||
|
|
||||||
fs.readdir(dir).then(files => {
|
fs.readdir(dir).then(files => {
|
||||||
const tt0 = Date.now();
|
const tt0 = Date.now();
|
||||||
async.eachLimit(files, 1, (fileName, callback) => {
|
async.eachLimit(files, 2, (fileName, callback) => {
|
||||||
|
|
||||||
let start = 0;
|
let start = 0;
|
||||||
let stop = 0;
|
let stop = 0;
|
||||||
@ -18,11 +18,9 @@ fs.readdir(dir).then(files => {
|
|||||||
|
|
||||||
let inst = vcd();
|
let inst = vcd();
|
||||||
|
|
||||||
// inst.on('$enddefinitions', () => {
|
inst.on('$enddefinitions', () => {
|
||||||
// console.log(res);
|
// console.log(res);
|
||||||
// console.log(inst.info);
|
// console.log(inst.info);
|
||||||
// });
|
|
||||||
|
|
||||||
inst.onTrigger('D1', time => {
|
inst.onTrigger('D1', time => {
|
||||||
if (time > 10) {
|
if (time > 10) {
|
||||||
if (start == 0) {
|
if (start == 0) {
|
||||||
@ -32,15 +30,19 @@ fs.readdir(dir).then(files => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
const s = fs.createReadStream(dir + fileName);
|
inst.on('finish', () => {
|
||||||
|
|
||||||
s.on('data', inst.execute);
|
|
||||||
|
|
||||||
s.on('end', () => {
|
|
||||||
console.log(fileName, (stop - start), ((Date.now() - t0) / 1000 + 's'));
|
console.log(fileName, (stop - start), ((Date.now() - t0) / 1000 + 's'));
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
inst.on('error', err => {
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
fs.createReadStream(dir + fileName).pipe(inst);
|
||||||
|
|
||||||
}, () => {
|
}, () => {
|
||||||
console.log('Total time: ' + (Date.now() - tt0) / 1000 + 's');
|
console.log('Total time: ' + (Date.now() - tt0) / 1000 + 's');
|
||||||
});
|
});
|
||||||
|
37
index.js
37
index.js
@ -1,38 +1,37 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const stream = require('stream');
|
||||||
const EventEmitter = require('events').EventEmitter;
|
const EventEmitter = require('events').EventEmitter;
|
||||||
const pkg = require('./package.json');
|
const pkg = require('./package.json');
|
||||||
let lib = require('bindings')('vcd.node');
|
let lib = require('bindings')('vcd.node');
|
||||||
|
|
||||||
const version = pkg.version;
|
|
||||||
|
|
||||||
module.exports = () => {
|
module.exports = () => {
|
||||||
const lifee = new EventEmitter();
|
|
||||||
const triee = new EventEmitter();
|
|
||||||
|
|
||||||
const lifemit = lifee.emit.bind(lifee);
|
|
||||||
const triemit = triee.emit.bind(triee);
|
|
||||||
|
|
||||||
const info = {path: []};
|
const info = {path: []};
|
||||||
|
|
||||||
|
const s = new stream.Writable();
|
||||||
|
|
||||||
|
// const lifee = new EventEmitter();
|
||||||
|
const lifemit = s.emit.bind(s);
|
||||||
|
|
||||||
|
const triee = new EventEmitter();
|
||||||
|
const triemit = triee.emit.bind(triee);
|
||||||
|
|
||||||
const cxt = lib.init(lifemit, triemit, info);
|
const cxt = lib.init(lifemit, triemit, info);
|
||||||
|
|
||||||
const execute = chunk => lib.execute(cxt, lifemit, triemit, info, chunk);
|
s._write = function (chunk, encoding, callback) {
|
||||||
|
lib.execute(cxt, lifemit, triemit, info, chunk);
|
||||||
const on = (id, fn) => {
|
callback();
|
||||||
lifee.on(id, fn);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const onTrigger = (id, fn) => {
|
s.onTrigger = (id, fn) => {
|
||||||
lib.setTrigger(cxt, id);
|
lib.setTrigger(cxt, id);
|
||||||
triee.on(id, fn);
|
triee.on(id, fn);
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
s.version = pkg.version;
|
||||||
version,
|
|
||||||
info,
|
s.info = info;
|
||||||
execute,
|
|
||||||
on,
|
return s;
|
||||||
onTrigger
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
@ -17,7 +17,7 @@ describe('basic', () => {
|
|||||||
|
|
||||||
it('fail: foo bar', done => {
|
it('fail: foo bar', done => {
|
||||||
const inst = vcd();
|
const inst = vcd();
|
||||||
expect(inst.execute(Buffer.from(' foo bar ???'))).to.eq(1);
|
expect(inst.write(Buffer.from(' foo bar ???'))).to.eq(true);
|
||||||
expect(inst.info).to.deep.eq({
|
expect(inst.info).to.deep.eq({
|
||||||
path: [],
|
path: [],
|
||||||
status: 'declaration'
|
status: 'declaration'
|
||||||
@ -27,9 +27,9 @@ describe('basic', () => {
|
|||||||
|
|
||||||
it('$comment', done => {
|
it('$comment', done => {
|
||||||
const inst = vcd();
|
const inst = vcd();
|
||||||
expect(inst.execute(Buffer.from(
|
expect(inst.write(Buffer.from(
|
||||||
' \n $comment some text $end $comment more text $end ???'
|
' \n $comment some text $end $comment more text $end ???'
|
||||||
))).to.eq(1);
|
))).to.eq(true);
|
||||||
expect(inst.info).to.deep.eq({
|
expect(inst.info).to.deep.eq({
|
||||||
path: [],
|
path: [],
|
||||||
status: 'declaration'
|
status: 'declaration'
|
||||||
@ -39,7 +39,7 @@ describe('basic', () => {
|
|||||||
|
|
||||||
it('$version', done => {
|
it('$version', done => {
|
||||||
const inst = vcd();
|
const inst = vcd();
|
||||||
expect(inst.execute(Buffer.from(`
|
expect(inst.write(`
|
||||||
$version Generated by VerilatedVcd $end
|
$version Generated by VerilatedVcd $end
|
||||||
$date Wed Sep 18 22:59:07 2019
|
$date Wed Sep 18 22:59:07 2019
|
||||||
$end
|
$end
|
||||||
@ -54,9 +54,9 @@ $timescale 1ns $end
|
|||||||
|
|
||||||
$enddefinitions $end
|
$enddefinitions $end
|
||||||
`
|
`
|
||||||
))).to.eq(0);
|
)).to.eq(true);
|
||||||
|
|
||||||
expect(inst.execute(Buffer.from(`
|
expect(inst.write(`
|
||||||
|
|
||||||
#1
|
#1
|
||||||
0"}G
|
0"}G
|
||||||
@ -72,7 +72,7 @@ b0000000011110000 {u
|
|||||||
#303
|
#303
|
||||||
b0000000000001111 {u
|
b0000000000001111 {u
|
||||||
`
|
`
|
||||||
))).to.eq(0);
|
)).to.eq(true);
|
||||||
|
|
||||||
expect(inst.info).to.deep.eq({
|
expect(inst.info).to.deep.eq({
|
||||||
path: [],
|
path: [],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user