From 47fd7856e2c065611b92b76a691e69411c915b25 Mon Sep 17 00:00:00 2001 From: Aliaksei Chapyzhenka Date: Sun, 10 Nov 2019 18:11:19 -0800 Subject: [PATCH] library refactoring --- bin/find.js | 11 +++++------ lib/activity.js | 18 ++++++++++++++++++ lib/{utils.js => and.js} | 0 lib/index.js | 13 +++++++++++++ lib/parser.js | 3 --- test/basic.js | 12 ++++++------ 6 files changed, 42 insertions(+), 15 deletions(-) create mode 100644 lib/activity.js rename lib/{utils.js => and.js} (100%) create mode 100644 lib/index.js diff --git a/bin/find.js b/bin/find.js index 464481a..5f8e7c8 100755 --- a/bin/find.js +++ b/bin/find.js @@ -4,8 +4,7 @@ const fs = require('fs-extra'); const async = require('async'); -const vcd = require('../lib/index.js'); -const utils = require('../lib/utils'); +const lib = require('../lib/index.js'); const dir = './tmp/'; @@ -19,11 +18,11 @@ fs.readdir(dir).then(files => { const t0 = Date.now(); - let inst = vcd(); + let inst = lib.parser(); - const loads = utils.and(); - const stores = utils.and(); - const duration = utils.activity(10); + const loads = lib.and(); + const stores = lib.and(); + const duration = lib.activity(10); inst.on('$enddefinitions', () => { // console.log(res); diff --git a/lib/activity.js b/lib/activity.js new file mode 100644 index 0000000..b75c914 --- /dev/null +++ b/lib/activity.js @@ -0,0 +1,18 @@ +'use strict'; + +module.exports = skip => { + let start = 0; + let stop = 0; + return { + on: time => { + if (time > skip) { + if (start == 0) { + start = time; + } else { + stop = time; + } + } + }, + time: () => stop - start + }; +}; diff --git a/lib/utils.js b/lib/and.js similarity index 100% rename from lib/utils.js rename to lib/and.js diff --git a/lib/index.js b/lib/index.js new file mode 100644 index 0000000..9c813d0 --- /dev/null +++ b/lib/index.js @@ -0,0 +1,13 @@ +'use strict'; + +const pkg = require('../package.json'); +const parser = require('./parser.js'); +const and = require('./and.js'); +const activity = require('./activity.js'); + +module.exports = { + version: pkg.version, + and: and, + activity: activity, + parser: parser +}; diff --git a/lib/parser.js b/lib/parser.js index 246c6f8..3ed8ee2 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -2,7 +2,6 @@ const stream = require('stream'); const EventEmitter = require('events').EventEmitter; -const pkg = require('../package.json'); let lib = require('bindings')('vcd.node'); module.exports = () => { @@ -35,8 +34,6 @@ module.exports = () => { } }; - s.version = pkg.version; - s.info = info; return s; diff --git a/test/basic.js b/test/basic.js index 469979a..6af9d96 100644 --- a/test/basic.js +++ b/test/basic.js @@ -1,22 +1,22 @@ 'use strict'; const expect = require('chai').expect; -const vcd = require('../lib/index.js'); +const lib = require('../lib/index.js'); describe('basic', () => { it('typeof vcd', done => { - expect(vcd).to.be.an('function'); + expect(lib.parser).to.be.an('function'); done(); }); it('typeof vcd instance', done => { - expect(vcd()).to.be.an('object'); + expect(lib.parser()).to.be.an('object'); done(); }); it('fail: foo bar', done => { - const inst = vcd(); + const inst = lib.parser(); expect(inst.write(Buffer.from(' foo bar ???'))).to.eq(true); expect(inst.info).to.deep.eq({ path: [], @@ -26,7 +26,7 @@ describe('basic', () => { }); it('$comment', done => { - const inst = vcd(); + const inst = lib.parser(); expect(inst.write(Buffer.from( ' \n $comment some text $end $comment more text $end ???' ))).to.eq(true); @@ -38,7 +38,7 @@ describe('basic', () => { }); it('$version', done => { - const inst = vcd(); + const inst = lib.parser(); expect(inst.write(` $version Generated by VerilatedVcd $end $date Wed Sep 18 22:59:07 2019