clean up build

This commit is contained in:
Aliaksei Chapyzhenka 2019-12-17 17:47:48 -08:00
parent f94792b9ec
commit 7e9c08e591
3 changed files with 194 additions and 178 deletions

View File

@ -17,7 +17,6 @@ jobs:
- name: npm install, build, and test - name: npm install, build, and test
run: | run: |
npm i npm i
npm run build
npm test npm test
env: env:
CI: true CI: true

View File

@ -1,225 +1,241 @@
#!/usr/bin/env node #!/usr/bin/env node
'use strict'; 'use strict';
const fs = require('fs'); const fs = require('fs-extra');
const cp = require('child_process');
const llparse = require('llparse'); const llparse = require('llparse');
const llparseDot = require('llparse-dot');
const prj = 'vcd_parser'; const gyp = cb => {
const p = new llparse.LLParse(prj); console.log('build');
const proc = cp.spawn('node-gyp', ['configure', 'build']);
proc.stderr.on('data', data => {
console.error(data.toString());
});
proc.on('close', (cb || (() => {
console.log('done');
})));
};
// Add custom uint8_t property to the state const generate = cb => {
p.property('i8', 'command'); // const llparseDot = require('llparse-dot');
p.property('i8', 'type');
p.property('i32', 'size');
p.property('i32', 'time');
p.property('ptr', 'trigger');
p.property('ptr', 'triee');
p.property('ptr', 'lifee');
p.property('ptr', 'info');
p.property('ptr', 'tmpStr');
p.property('i32', 'stackPointer');
p.property('ptr', 'id');
p.property('ptr', 'napi_env');
const scopeIdentifierSpan = p.span(p.code.span('scopeIdentifierSpan')); const prj = 'vcd_parser';
const varSizeSpan = p.span(p.code.span('varSizeSpan')); const p = new llparse.LLParse(prj);
const varIdSpan = p.span(p.code.span('varIdSpan'));
const varNameSpan = p.span(p.code.span('varNameSpan'));
const idSpan = p.span(p.code.span('idSpan'));
const commandSpan = p.span(p.code.span('commandSpan'));
const timeSpan = p.span(p.code.span('timeSpan'));
const vectorSpan = p.span(p.code.span('vectorSpan'));
const declaration = p.node('declaration'); // Add custom uint8_t property to the state
p.property('i8', 'command');
p.property('i8', 'type');
p.property('i32', 'size');
p.property('i32', 'time');
p.property('ptr', 'trigger');
p.property('ptr', 'triee');
p.property('ptr', 'lifee');
p.property('ptr', 'info');
p.property('ptr', 'tmpStr');
p.property('i32', 'stackPointer');
p.property('ptr', 'id');
p.property('ptr', 'napi_env');
const scopeType = p.node('scopeType'); const scopeIdentifierSpan = p.span(p.code.span('scopeIdentifierSpan'));
const scopeTypeEnd = p.node('scopeTypeEnd'); const varSizeSpan = p.span(p.code.span('varSizeSpan'));
const varIdSpan = p.span(p.code.span('varIdSpan'));
const varNameSpan = p.span(p.code.span('varNameSpan'));
const idSpan = p.span(p.code.span('idSpan'));
const commandSpan = p.span(p.code.span('commandSpan'));
const timeSpan = p.span(p.code.span('timeSpan'));
const vectorSpan = p.span(p.code.span('vectorSpan'));
const scopeIdentifier = p.node('scopeIdentifier'); const declaration = p.node('declaration');
const scopeIdentifierEnd = p.node('scopeIdentifierEnd');
const varType = p.node('varType'); const scopeType = p.node('scopeType');
const varTypeEnd = p.node('varTypeEnd'); const scopeTypeEnd = p.node('scopeTypeEnd');
const varSize = p.node('varSize'); const scopeIdentifier = p.node('scopeIdentifier');
const varSizeEnd = p.node('varSizeEnd'); const scopeIdentifierEnd = p.node('scopeIdentifierEnd');
const varId = p.node('varId'); const varType = p.node('varType');
const varIdEnd = p.node('varIdEnd'); const varTypeEnd = p.node('varTypeEnd');
const varName = p.node('varName'); const varSize = p.node('varSize');
const varNameEnd = p.node('varNameEnd'); const varSizeEnd = p.node('varSizeEnd');
const inDeclaration = p.node('inDeclaration'); const varId = p.node('varId');
const enddefinitions = p.node('inDeclarationEnd'); const varIdEnd = p.node('varIdEnd');
const simulation = p.node('simulation');
const inSimulation = p.node('inSimulation');
const simulationTime = p.node('simulationTime'); const varName = p.node('varName');
const simulationVector = p.node('simulationVector'); const varNameEnd = p.node('varNameEnd');
const simulationId = p.node('simulationId');
const spaces = [' ', '\n', '\r', '\t']; const inDeclaration = p.node('inDeclaration');
const enddefinitions = p.node('inDeclarationEnd');
const simulation = p.node('simulation');
const inSimulation = p.node('inSimulation');
const objection = lut => arg => arg.split(/\s+/).reduce((res, key) => { const simulationTime = p.node('simulationTime');
if (lut[key] === undefined) { const simulationVector = p.node('simulationVector');
throw new Error(key); const simulationId = p.node('simulationId');
}
res[key] = lut[key];
return res;
}, {});
const cmd = objection({ const spaces = [' ', '\n', '\r', '\t'];
$comment: 1,
$date: 2,
$scope: 3,
$timescale: 4,
$upscope: 5,
$var: 6,
$version: 7,
$enddefinitions: 8,
$dumpall: 9,
$dumpoff: 10,
$dumpon: 11,
$dumpvars: 12,
'#': 13,
'0': 14, '1': 15, x: 16, X: 17, Z: 18,
b: 19, B: 20, r: 21, R: 22
});
declaration const objection = lut => arg => arg.split(/\s+/).reduce((res, key) => {
.match(spaces, declaration) if (lut[key] === undefined) {
.select(cmd('$scope'), throw new Error(key);
p.invoke(p.code.store('command'), commandSpan.start(scopeType))) }
.select(cmd('$var'), res[key] = lut[key];
p.invoke(p.code.store('command'), commandSpan.start(varType))) return res;
.select(cmd('$comment $date $timescale $upscope $version'), }, {});
p.invoke(p.code.store('command'), commandSpan.start(inDeclaration)))
.select(cmd('$enddefinitions'),
p.invoke(p.code.store('command'), commandSpan.start(enddefinitions)))
.otherwise(p.error(1, 'Expected declaration command'));
// $scope const cmd = objection({
$comment: 1,
$date: 2,
$scope: 3,
$timescale: 4,
$upscope: 5,
$var: 6,
$version: 7,
$enddefinitions: 8,
$dumpall: 9,
$dumpoff: 10,
$dumpon: 11,
$dumpvars: 12,
'#': 13,
'0': 14, '1': 15, x: 16, X: 17, Z: 18,
b: 19, B: 20, r: 21, R: 22
});
scopeType declaration
.match(spaces, scopeType) .match(spaces, declaration)
.otherwise(scopeTypeEnd); .select(cmd('$scope'),
p.invoke(p.code.store('command'), commandSpan.start(scopeType)))
.select(cmd('$var'),
p.invoke(p.code.store('command'), commandSpan.start(varType)))
.select(cmd('$comment $date $timescale $upscope $version'),
p.invoke(p.code.store('command'), commandSpan.start(inDeclaration)))
.select(cmd('$enddefinitions'),
p.invoke(p.code.store('command'), commandSpan.start(enddefinitions)))
.otherwise(p.error(1, 'Expected declaration command'));
scopeTypeEnd // $scope
.select({begin: 1, fork: 2, function: 3, module: 4, task: 5},
p.invoke(p.code.store('type'), scopeIdentifier))
.otherwise(p.error(2, 'Expected scope type'));
scopeIdentifier scopeType
.match(spaces, scopeIdentifier) .match(spaces, scopeType)
.otherwise(scopeIdentifierSpan.start(scopeIdentifierEnd)); .otherwise(scopeTypeEnd);
scopeIdentifierEnd scopeTypeEnd
.match(spaces, scopeIdentifierSpan.end(inDeclaration)) .select({begin: 1, fork: 2, function: 3, module: 4, task: 5},
.skipTo(scopeIdentifierEnd); p.invoke(p.code.store('type'), scopeIdentifier))
.otherwise(p.error(2, 'Expected scope type'));
// $var scopeIdentifier
.match(spaces, scopeIdentifier)
.otherwise(scopeIdentifierSpan.start(scopeIdentifierEnd));
varType scopeIdentifierEnd
.match(spaces, varType) .match(spaces, scopeIdentifierSpan.end(inDeclaration))
.otherwise(varTypeEnd); .skipTo(scopeIdentifierEnd);
varTypeEnd // $var
.select({
event: 1,
integer: 2,
parameter: 3,
// real: 4,
realtime: 5,
reg: 6,
supply0: 7,
supply1: 8,
time: 9,
// tri: 10,
triand: 11,
trior: 12,
trireg: 13,
tri0: 14,
tri1: 15,
wand: 16,
wire: 17,
wor: 18
}, p.invoke(p.code.store('type'), varSize))
.otherwise(p.error(3, 'Expected var type'));
varSize varType
.match(spaces, varSize) .match(spaces, varType)
.otherwise(varSizeSpan.start(varSizeEnd)); .otherwise(varTypeEnd);
varSizeEnd varTypeEnd
.match(spaces, varSizeSpan.end(varId)) .select({
.skipTo(varSizeEnd); event: 1,
integer: 2,
parameter: 3,
// real: 4,
realtime: 5,
reg: 6,
supply0: 7,
supply1: 8,
time: 9,
// tri: 10,
triand: 11,
trior: 12,
trireg: 13,
tri0: 14,
tri1: 15,
wand: 16,
wire: 17,
wor: 18
}, p.invoke(p.code.store('type'), varSize))
.otherwise(p.error(3, 'Expected var type'));
varId varSize
.match(spaces, varId) .match(spaces, varSize)
.otherwise(varIdSpan.start(varIdEnd)); .otherwise(varSizeSpan.start(varSizeEnd));
varIdEnd varSizeEnd
.match(spaces, varIdSpan.end(varName)) .match(spaces, varSizeSpan.end(varId))
.skipTo(varIdEnd); .skipTo(varSizeEnd);
varName varId
.match(spaces, varName) .match(spaces, varId)
.otherwise(varNameSpan.start(varNameEnd)); .otherwise(varIdSpan.start(varIdEnd));
varNameEnd varIdEnd
.match(spaces, varNameSpan.end(inDeclaration)) .match(spaces, varIdSpan.end(varName))
.skipTo(varNameEnd); .skipTo(varIdEnd);
// $end varName
.match(spaces, varName)
.otherwise(varNameSpan.start(varNameEnd));
inDeclaration varNameEnd
.match('$end', commandSpan.end(declaration)) .match(spaces, varNameSpan.end(inDeclaration))
.skipTo(inDeclaration); .skipTo(varNameEnd);
enddefinitions // $end
.match('$end', commandSpan.end(simulation))
.skipTo(enddefinitions);
simulation inDeclaration
.match([' ', '\n', '\t'], simulation) .match('$end', commandSpan.end(declaration))
.select(cmd('$dumpall $dumpoff $dumpon $dumpvars $comment'), .skipTo(inDeclaration);
p.invoke(p.code.store('command'), commandSpan.start(inSimulation)))
.select(cmd('#'),
p.invoke(p.code.store('command'), timeSpan.start(simulationTime)))
.select(cmd('0 1 x X Z'),
p.invoke(p.code.store('command'), idSpan.start(simulationId)))
.select(cmd('b B r R'),
p.invoke(p.code.store('command'), vectorSpan.start(simulationVector)))
.otherwise(p.error(4, 'Expected simulation command'));
inSimulation enddefinitions
.match('$end', commandSpan.end(simulation)) .match('$end', commandSpan.end(simulation))
.skipTo(inSimulation); .skipTo(enddefinitions);
simulationTime simulation
.match(spaces, timeSpan.end(simulation)) .match([' ', '\n', '\t'], simulation)
.skipTo(simulationTime); .select(cmd('$dumpall $dumpoff $dumpon $dumpvars $comment'),
p.invoke(p.code.store('command'), commandSpan.start(inSimulation)))
.select(cmd('#'),
p.invoke(p.code.store('command'), timeSpan.start(simulationTime)))
.select(cmd('0 1 x X Z'),
p.invoke(p.code.store('command'), idSpan.start(simulationId)))
.select(cmd('b B r R'),
p.invoke(p.code.store('command'), vectorSpan.start(simulationVector)))
.otherwise(p.error(4, 'Expected simulation command'));
simulationVector inSimulation
.match(spaces, vectorSpan.end(idSpan.start(simulationId))) .match('$end', commandSpan.end(simulation))
.skipTo(simulationVector); .skipTo(inSimulation);
simulationId simulationTime
.match(spaces, idSpan.end(simulation)) .match(spaces, timeSpan.end(simulation))
.skipTo(simulationId); .skipTo(simulationTime);
// Build simulationVector
.match(spaces, vectorSpan.end(idSpan.start(simulationId)))
.skipTo(simulationVector);
const artifacts = p.build(declaration); simulationId
.match(spaces, idSpan.end(simulation))
.skipTo(simulationId);
fs.writeFileSync(prj + '.h', artifacts.header); const artifacts = p.build(declaration);
// fs.writeFileSync('verilog_preprocessor.bc', artifacts.bitcode);
fs.writeFileSync(prj + '.c', artifacts.c);
const dot = new llparseDot.Dot(); fs.writeFileSync(prj + '.h', artifacts.header);
// fs.writeFileSync('verilog_preprocessor.bc', artifacts.bitcode);
fs.writeFileSync(prj + '.c', artifacts.c);
fs.writeFileSync(prj + '.dot', dot.build(declaration)); // const dot = new llparseDot.Dot();
// fs.writeFileSync(prj + '.dot', dot.build(declaration));
cb();
};
generate(gyp);
/* eslint camelcase: 0 */ /* eslint camelcase: 0 */

View File

@ -5,7 +5,8 @@
"main": "lib/index.js", "main": "lib/index.js",
"scripts": { "scripts": {
"test": "eslint bin lib && nyc -r=text -r=lcov mocha", "test": "eslint bin lib && nyc -r=text -r=lcov mocha",
"build": "node bin/build.js && node-gyp rebuild" "install": "node bin/build.js",
"prepare": "node bin/build.js"
}, },
"files": [ "files": [
"*.c", "*.c",