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
run: |
npm i
npm run build
npm test
env:
CI: true

View File

@ -1,76 +1,90 @@
#!/usr/bin/env node
'use strict';
const fs = require('fs');
const fs = require('fs-extra');
const cp = require('child_process');
const llparse = require('llparse');
const llparseDot = require('llparse-dot');
const prj = 'vcd_parser';
const p = new llparse.LLParse(prj);
const gyp = cb => {
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
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 generate = cb => {
// const llparseDot = require('llparse-dot');
const scopeIdentifierSpan = p.span(p.code.span('scopeIdentifierSpan'));
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 prj = 'vcd_parser';
const p = new llparse.LLParse(prj);
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 scopeTypeEnd = p.node('scopeTypeEnd');
const scopeIdentifierSpan = p.span(p.code.span('scopeIdentifierSpan'));
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 scopeIdentifierEnd = p.node('scopeIdentifierEnd');
const declaration = p.node('declaration');
const varType = p.node('varType');
const varTypeEnd = p.node('varTypeEnd');
const scopeType = p.node('scopeType');
const scopeTypeEnd = p.node('scopeTypeEnd');
const varSize = p.node('varSize');
const varSizeEnd = p.node('varSizeEnd');
const scopeIdentifier = p.node('scopeIdentifier');
const scopeIdentifierEnd = p.node('scopeIdentifierEnd');
const varId = p.node('varId');
const varIdEnd = p.node('varIdEnd');
const varType = p.node('varType');
const varTypeEnd = p.node('varTypeEnd');
const varName = p.node('varName');
const varNameEnd = p.node('varNameEnd');
const varSize = p.node('varSize');
const varSizeEnd = p.node('varSizeEnd');
const inDeclaration = p.node('inDeclaration');
const enddefinitions = p.node('inDeclarationEnd');
const simulation = p.node('simulation');
const inSimulation = p.node('inSimulation');
const varId = p.node('varId');
const varIdEnd = p.node('varIdEnd');
const simulationTime = p.node('simulationTime');
const simulationVector = p.node('simulationVector');
const simulationId = p.node('simulationId');
const varName = p.node('varName');
const varNameEnd = p.node('varNameEnd');
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');
const simulationVector = p.node('simulationVector');
const simulationId = p.node('simulationId');
const spaces = [' ', '\n', '\r', '\t'];
const objection = lut => arg => arg.split(/\s+/).reduce((res, key) => {
if (lut[key] === undefined) {
throw new Error(key);
}
res[key] = lut[key];
return res;
}, {});
}, {});
const cmd = objection({
const cmd = objection({
$comment: 1,
$date: 2,
$scope: 3,
@ -86,9 +100,9 @@ const cmd = objection({
'#': 13,
'0': 14, '1': 15, x: 16, X: 17, Z: 18,
b: 19, B: 20, r: 21, R: 22
});
});
declaration
declaration
.match(spaces, declaration)
.select(cmd('$scope'),
p.invoke(p.code.store('command'), commandSpan.start(scopeType)))
@ -100,32 +114,32 @@ declaration
p.invoke(p.code.store('command'), commandSpan.start(enddefinitions)))
.otherwise(p.error(1, 'Expected declaration command'));
// $scope
// $scope
scopeType
scopeType
.match(spaces, scopeType)
.otherwise(scopeTypeEnd);
scopeTypeEnd
scopeTypeEnd
.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
scopeIdentifier
.match(spaces, scopeIdentifier)
.otherwise(scopeIdentifierSpan.start(scopeIdentifierEnd));
scopeIdentifierEnd
scopeIdentifierEnd
.match(spaces, scopeIdentifierSpan.end(inDeclaration))
.skipTo(scopeIdentifierEnd);
// $var
// $var
varType
varType
.match(spaces, varType)
.otherwise(varTypeEnd);
varTypeEnd
varTypeEnd
.select({
event: 1,
integer: 2,
@ -148,41 +162,41 @@ varTypeEnd
}, p.invoke(p.code.store('type'), varSize))
.otherwise(p.error(3, 'Expected var type'));
varSize
varSize
.match(spaces, varSize)
.otherwise(varSizeSpan.start(varSizeEnd));
varSizeEnd
varSizeEnd
.match(spaces, varSizeSpan.end(varId))
.skipTo(varSizeEnd);
varId
varId
.match(spaces, varId)
.otherwise(varIdSpan.start(varIdEnd));
varIdEnd
varIdEnd
.match(spaces, varIdSpan.end(varName))
.skipTo(varIdEnd);
varName
varName
.match(spaces, varName)
.otherwise(varNameSpan.start(varNameEnd));
varNameEnd
varNameEnd
.match(spaces, varNameSpan.end(inDeclaration))
.skipTo(varNameEnd);
// $end
// $end
inDeclaration
inDeclaration
.match('$end', commandSpan.end(declaration))
.skipTo(inDeclaration);
enddefinitions
enddefinitions
.match('$end', commandSpan.end(simulation))
.skipTo(enddefinitions);
simulation
simulation
.match([' ', '\n', '\t'], simulation)
.select(cmd('$dumpall $dumpoff $dumpon $dumpvars $comment'),
p.invoke(p.code.store('command'), commandSpan.start(inSimulation)))
@ -194,32 +208,34 @@ simulation
p.invoke(p.code.store('command'), vectorSpan.start(simulationVector)))
.otherwise(p.error(4, 'Expected simulation command'));
inSimulation
inSimulation
.match('$end', commandSpan.end(simulation))
.skipTo(inSimulation);
simulationTime
simulationTime
.match(spaces, timeSpan.end(simulation))
.skipTo(simulationTime);
simulationVector
simulationVector
.match(spaces, vectorSpan.end(idSpan.start(simulationId)))
.skipTo(simulationVector);
simulationId
simulationId
.match(spaces, idSpan.end(simulation))
.skipTo(simulationId);
// Build
const artifacts = p.build(declaration);
const artifacts = p.build(declaration);
fs.writeFileSync(prj + '.h', artifacts.header);
// fs.writeFileSync('verilog_preprocessor.bc', artifacts.bitcode);
fs.writeFileSync(prj + '.c', artifacts.c);
fs.writeFileSync(prj + '.h', artifacts.header);
// fs.writeFileSync('verilog_preprocessor.bc', artifacts.bitcode);
fs.writeFileSync(prj + '.c', artifacts.c);
// const dot = new llparseDot.Dot();
// fs.writeFileSync(prj + '.dot', dot.build(declaration));
const dot = new llparseDot.Dot();
cb();
};
fs.writeFileSync(prj + '.dot', dot.build(declaration));
generate(gyp);
/* eslint camelcase: 0 */

View File

@ -5,7 +5,8 @@
"main": "lib/index.js",
"scripts": {
"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": [
"*.c",