From 50a7b817df9574587df484442d6f06523265570d Mon Sep 17 00:00:00 2001 From: Staf Verhaegen Date: Sat, 14 Apr 2018 11:20:36 +0200 Subject: [PATCH] Added SVF grammar parser Using modgrammar (can be installed with pip) TODO: PIO, PIOMAP --- sim/cocotb/c4m_jtag_svfgrammar.py | 96 +++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 sim/cocotb/c4m_jtag_svfgrammar.py diff --git a/sim/cocotb/c4m_jtag_svfgrammar.py b/sim/cocotb/c4m_jtag_svfgrammar.py new file mode 100644 index 0000000..faf3aeb --- /dev/null +++ b/sim/cocotb/c4m_jtag_svfgrammar.py @@ -0,0 +1,96 @@ +from modgrammar import * + +grammar_whitespace_mode = 'explicit' +grammar_whitespace = WS_NOEOL + +class SVFEol(Grammar): + grammar = (OPTIONAL(SPACE), EOL) + grammar_collapse = True + +class SemicolonEol(Grammar): + grammar = (OPTIONAL(SPACE), L(";"), SVFEol) + grammar_collapse = True + +class Integer(Grammar): + grammar = WORD("0-9") + grammar_collapse = True + +class Float(Grammar): + grammar = (Integer, (L("."), OPTIONAL(Integer)), OPTIONAL(L("E"), Integer)) + +class Hexadecimal(Grammar): + grammar = (L("("), WORD("0-9A-F"), L(")")) + grammar_collapse = True + +class StableState(Grammar): + grammar = (L("IRPAUSE") | L("DRPAUSE") | L("RESET") | L("IDLE")) + grammar_collapse = True + + +class ScanSpec(Grammar): + """The specification of Scan In/Scan out data""" + grammar = (SPACE, Integer, SPACE, + OPTIONAL(L("TDI"), OPTIONAL(SPACE), Hexadecimal), + OPTIONAL(OPTIONAL(SPACE), L("TDO"), OPTIONAL(SPACE), Hexadecimal), + OPTIONAL(OPTIONAL(SPACE), L("MASK"), OPTIONAL(SPACE), Hexadecimal), + OPTIONAL(OPTIONAL(SPACE), L("SMASK"), OPTIONAL(SPACE), Hexadecimal) + ) + grammar_collapse = True + + +class EmptyLine(Grammar): + grammar = SVFEol + +class Comment(Grammar): + grammar = (L("!"), REST_OF_LINE, SVFEol) + +class EndDR(Grammar): + grammar = (L("ENDDR"), SPACE, StableState, SemicolonEol) + +class EndIR(Grammar): + grammar = (L("ENDIR"), SPACE, StableState, SemicolonEol) + +class Frequency(Grammar): + grammar = (L("FREQUENCY"), OPTIONAL(SPACE, Float, OPTIONAL(SPACE), L("HZ")), OPTIONAL(SPACE), SemicolonEol) + +class HDR(Grammar): + grammar = (L("HDR"), ScanSpec, SemicolonEol) + +class HIR(Grammar): + grammar = (L("HIR"), ScanSpec, SemicolonEol) + +#TODO: PIO, PIOMAP + +class Runtest(Grammar): + grammar = ( + L("RUNTEST"), + OPTIONAL(SPACE, StableState), + OPTIONAL(SPACE, Integer, OPTIONAL(SPACE), (L("TCK") | L("SCK"))), + OPTIONAL(SPACE, Float, OPTIONAL(SPACE), L("SEC")), + OPTIONAL(SPACE, L("MAXIMUM"), SPACE, Float, OPTIONAL(SPACE), L("SEC")), + OPTIONAL(SPACE, L("ENDSTATE"), SPACE, StableState), + SemicolonEol + ) + +class SDR(Grammar): + grammar = (L("SDR"), ScanSpec, SemicolonEol) + +class SIR(Grammar): + grammar = (L("SIR"), ScanSpec, SemicolonEol) + +class State(Grammar): + # TODO: Path to reach state + grammar = (L("STATE"), SPACE, StableState, SemicolonEol) + +class TDR(Grammar): + grammar = (L("TDR"), ScanSpec, SemicolonEol) + +class TIR(Grammar): + grammar = (L("TIR"), ScanSpec, SemicolonEol) + +class Trst(Grammar): + grammar = (L("TRST"), SPACE, (L("ON") | L("OFF") | L("Z") | L("ABSENT")), SemicolonEol) + + +class SVFFile(Grammar): + grammar = ONE_OR_MORE(EmptyLine | Comment | Trst | EndDR | EndIR | SIR | SDR | Runtest | State) -- 2.30.2