From 0f575619a4fdebb97e11aee062d7bf36e3f26927 Mon Sep 17 00:00:00 2001 From: Aliaksei Chapyzhenka Date: Sun, 20 Oct 2019 23:56:23 -0700 Subject: [PATCH] improved $scope and $var commands --- bin/build.js | 104 ++++++++++++++++++++++++++++++++++++++++++++++---- test/basic.js | 2 +- vcd.c | 17 ++++++++- 3 files changed, 114 insertions(+), 9 deletions(-) diff --git a/bin/build.js b/bin/build.js index 3dbd6c6..65249d9 100755 --- a/bin/build.js +++ b/bin/build.js @@ -10,8 +10,29 @@ const p = new llparse.LLParse(prj); // Add custom uint8_t property to the state p.property('i8', 'command'); +p.property('i8', 'type'); +p.property('i32', 'size'); const declaration = p.node('declaration'); + +const scopeType = p.node('scopeType'); +const scopeTypeEnd = p.node('scopeTypeEnd'); + +const scopeIdentifier = p.node('scopeIdentifier'); +const scopeIdentifierSpan = p.span(p.code.span('scopeIdentifierSpan')); +const scopeIdentifierEnd = p.node('scopeIdentifierEnd'); + +const varType = p.node('varType'); +const varTypeEnd = p.node('varTypeEnd'); + +const varSize = p.node('varSize'); +const varSizeSpan = p.span(p.code.span('varSizeSpan')); +const varSizeEnd = p.node('varSizeEnd'); + +const varId = p.node('varId'); +const varIdSpan = p.span(p.code.span('varIdSpan')); +const varIdEnd = p.node('varIdEnd'); + const commandSpan = p.span(p.code.span('commandSpan')); const inDeclaration = p.node('inDeclaration'); const enddefinitions = p.node('inDeclarationEnd'); @@ -19,17 +40,87 @@ const simulation = p.node('simulation'); const inSimulation = p.node('inSimulation'); const simulationTime = p.node('simulationTime'); +const spaces = [' ', '\n', '\r', '\t']; + declaration - .match([' ', '\n', '\t'], declaration) + .match(spaces, declaration) + .select({$scope: 3}, p.invoke(p.code.store('command'), commandSpan.start(scopeType))) + .select({$var: 6}, p.invoke(p.code.store('command'), commandSpan.start(varType))) .select({ - '$comment': 1, '$date': 2, '$scope': 3, '$timescale': 4, - '$upscope': 5, '$var': 6, '$version': 7 + $comment: 1, $date: 2, $timescale: 4, $upscope: 5, $version: 7 }, p.invoke(p.code.store('command'), commandSpan.start(inDeclaration))) .select({ - '$enddefinitions': 100 + $enddefinitions: 100 }, p.invoke(p.code.store('command'), commandSpan.start(enddefinitions))) .otherwise(p.error(1, 'Expected declaration command')); +// $scope + +scopeType + .match(spaces, scopeType) + .otherwise(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 + .match(spaces, scopeIdentifier) + .otherwise(scopeIdentifierSpan.start(scopeIdentifierEnd)); + +scopeIdentifierEnd + .match(spaces, scopeIdentifierSpan.end(inDeclaration)) + .skipTo(scopeIdentifierEnd); + +// $var + +varType + .match(spaces, varType) + .otherwise(varTypeEnd); + +varTypeEnd + .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 + .match(spaces, varSize) + .otherwise(varSizeSpan.start(varSizeEnd)); + +varSizeEnd + .match(spaces, varSizeSpan.end(varId)) + .skipTo(varSizeEnd); + +varId + .match(spaces, varId) + .otherwise(varIdSpan.start(varIdEnd)); + +varIdEnd + .match(spaces, varIdSpan.end(inDeclaration)) + .skipTo(varIdEnd); + +// $end + inDeclaration .match('$end', commandSpan.end(declaration)) .skipTo(inDeclaration); @@ -41,8 +132,7 @@ enddefinitions simulation .match([' ', '\n', '\t'], simulation) .select({ - '$dumpall': 8, '$dumpoff': 9, '$dumpon': 10, '$dumpvars': 11, - '$comment': 1 + $dumpall: 8, $dumpoff: 9, $dumpon: 10, $dumpvars: 11, $comment: 1 }, p.invoke(p.code.store('command'), commandSpan.start(inSimulation))) .select({'#': 12}, p.invoke(p.code.store('command'), commandSpan.start(simulationTime))) .select({'0': 13}, p.invoke(p.code.store('command'), commandSpan.start(simulationTime))) @@ -54,7 +144,7 @@ inSimulation .skipTo(inSimulation); simulationTime - .match([' ', '\n', '\r', '\t'], commandSpan.end(simulation)) + .match(spaces, commandSpan.end(simulation)) .skipTo(simulationTime); diff --git a/test/basic.js b/test/basic.js index 8a6a5e7..ed5008f 100644 --- a/test/basic.js +++ b/test/basic.js @@ -38,7 +38,7 @@ $date Wed Sep 18 22:59:07 2019 $end $timescale 1ns $end - $scope module top $end + $scope module top $end $var wire 1 "}G clock $end $scope module leaf $end $var wire 64 "}> counter [63:0] $end diff --git a/vcd.c b/vcd.c index 020ed38..8704463 100644 --- a/vcd.c +++ b/vcd.c @@ -142,7 +142,22 @@ napi_value Init(napi_env env, napi_value exports) { } int commandSpan(vcd_parser_t* s, const unsigned char* p, const unsigned char* endp) { - printf("(%d)%.*s\n", s->command, (int)(endp - p), p); + printf("(%d:%d:%d)(%.*s)\n", s->command, s->type, s->size, (int)(endp - p), p); + return 0; +}; + +int scopeIdentifierSpan(vcd_parser_t* s, const unsigned char* p, const unsigned char* endp) { + printf("{%.*s}", (int)(endp - p - 1), p); + return 0; +}; + +int varSizeSpan(vcd_parser_t* s, const unsigned char* p, const unsigned char* endp) { + s->size = strtol(p, &endp, 10); + return 0; +}; + +int varIdSpan(vcd_parser_t* s, const unsigned char* p, const unsigned char* endp) { + printf("{%.*s}", (int)(endp - p - 1), p); return 0; };