added more VCD grammar rules

This commit is contained in:
Aliaksei Chapyzhenka 2019-10-09 13:52:42 -07:00
parent 13b129ad10
commit 76d7c2bc62

View File

@ -9,20 +9,58 @@ const prj = 'vcd_parser';
const p = new llparse.LLParse(prj); const p = new llparse.LLParse(prj);
const start = p.node('start'); const declaration = p.node('declaration');
const stop = p.node('stop'); const inDeclaration = p.node('inDeclaration');
const enddefinitions = p.node('inDeclarationEnd');
const simulation = p.node('simulation');
const inSimulation = p.node('inSimulation');
start // Add custom uint8_t property to the state
.match('stop', stop) p.property('i8', 'declaration');
.otherwise(p.error(1, 'Expected start')); p.property('i8', 'simulation');
stop // Store method inside a custom property
.match('start', start) const onDeclaration = p.invoke(p.code.store('declaration'), inDeclaration);
.otherwise(p.error(2, 'Expected start')); const onSimulation = p.invoke(p.code.store('simulation'), inSimulation);
declaration
.select({
'$comment': 0,
'$date': 1,
'$scope': 2,
'$timescale': 3,
'$upscope': 4,
'$var': 5,
'$version': 6
}, onDeclaration)
.match('$enddefinitions', enddefinitions)
.otherwise(p.error(1, 'Expected declaration'));
inDeclaration
.match('$end', declaration)
.otherwise(p.error(2, 'Expected end of declaration'));
enddefinitions
.match('$end', simulation)
.otherwise(p.error(3, 'Expected end of all declaration'));
simulation
.select({
'$dumpall': 0,
'$dumpoff': 1,
'$dumpon': 2,
'$dumpvars': 3,
'$comment': 4
}, onSimulation)
.otherwise(p.error(4, 'Expected simulation command'));
inSimulation
.match('$end', simulation)
.otherwise(p.error(5, 'Expected end simulation command'));
// Build // Build
const artifacts = p.build(start); const artifacts = p.build(declaration);
fs.writeFileSync(prj + '.h', artifacts.header); fs.writeFileSync(prj + '.h', artifacts.header);
// fs.writeFileSync('verilog_preprocessor.bc', artifacts.bitcode); // fs.writeFileSync('verilog_preprocessor.bc', artifacts.bitcode);
@ -30,6 +68,6 @@ fs.writeFileSync(prj + '.c', artifacts.c);
const dot = new llparseDot.Dot(); const dot = new llparseDot.Dot();
fs.writeFileSync(prj + '.dot', dot.build(start)); fs.writeFileSync(prj + '.dot', dot.build(declaration));
/* eslint camelcase: 0 */ /* eslint camelcase: 0 */