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