Added SVF grammar parser
[c4m-jtag.git] / sim / cocotb / c4m_jtag_svfgrammar.py
1 from modgrammar import *
2
3 grammar_whitespace_mode = 'explicit'
4 grammar_whitespace = WS_NOEOL
5
6 class SVFEol(Grammar):
7 grammar = (OPTIONAL(SPACE), EOL)
8 grammar_collapse = True
9
10 class SemicolonEol(Grammar):
11 grammar = (OPTIONAL(SPACE), L(";"), SVFEol)
12 grammar_collapse = True
13
14 class Integer(Grammar):
15 grammar = WORD("0-9")
16 grammar_collapse = True
17
18 class Float(Grammar):
19 grammar = (Integer, (L("."), OPTIONAL(Integer)), OPTIONAL(L("E"), Integer))
20
21 class Hexadecimal(Grammar):
22 grammar = (L("("), WORD("0-9A-F"), L(")"))
23 grammar_collapse = True
24
25 class StableState(Grammar):
26 grammar = (L("IRPAUSE") | L("DRPAUSE") | L("RESET") | L("IDLE"))
27 grammar_collapse = True
28
29
30 class ScanSpec(Grammar):
31 """The specification of Scan In/Scan out data"""
32 grammar = (SPACE, Integer, SPACE,
33 OPTIONAL(L("TDI"), OPTIONAL(SPACE), Hexadecimal),
34 OPTIONAL(OPTIONAL(SPACE), L("TDO"), OPTIONAL(SPACE), Hexadecimal),
35 OPTIONAL(OPTIONAL(SPACE), L("MASK"), OPTIONAL(SPACE), Hexadecimal),
36 OPTIONAL(OPTIONAL(SPACE), L("SMASK"), OPTIONAL(SPACE), Hexadecimal)
37 )
38 grammar_collapse = True
39
40
41 class EmptyLine(Grammar):
42 grammar = SVFEol
43
44 class Comment(Grammar):
45 grammar = (L("!"), REST_OF_LINE, SVFEol)
46
47 class EndDR(Grammar):
48 grammar = (L("ENDDR"), SPACE, StableState, SemicolonEol)
49
50 class EndIR(Grammar):
51 grammar = (L("ENDIR"), SPACE, StableState, SemicolonEol)
52
53 class Frequency(Grammar):
54 grammar = (L("FREQUENCY"), OPTIONAL(SPACE, Float, OPTIONAL(SPACE), L("HZ")), OPTIONAL(SPACE), SemicolonEol)
55
56 class HDR(Grammar):
57 grammar = (L("HDR"), ScanSpec, SemicolonEol)
58
59 class HIR(Grammar):
60 grammar = (L("HIR"), ScanSpec, SemicolonEol)
61
62 #TODO: PIO, PIOMAP
63
64 class Runtest(Grammar):
65 grammar = (
66 L("RUNTEST"),
67 OPTIONAL(SPACE, StableState),
68 OPTIONAL(SPACE, Integer, OPTIONAL(SPACE), (L("TCK") | L("SCK"))),
69 OPTIONAL(SPACE, Float, OPTIONAL(SPACE), L("SEC")),
70 OPTIONAL(SPACE, L("MAXIMUM"), SPACE, Float, OPTIONAL(SPACE), L("SEC")),
71 OPTIONAL(SPACE, L("ENDSTATE"), SPACE, StableState),
72 SemicolonEol
73 )
74
75 class SDR(Grammar):
76 grammar = (L("SDR"), ScanSpec, SemicolonEol)
77
78 class SIR(Grammar):
79 grammar = (L("SIR"), ScanSpec, SemicolonEol)
80
81 class State(Grammar):
82 # TODO: Path to reach state
83 grammar = (L("STATE"), SPACE, StableState, SemicolonEol)
84
85 class TDR(Grammar):
86 grammar = (L("TDR"), ScanSpec, SemicolonEol)
87
88 class TIR(Grammar):
89 grammar = (L("TIR"), ScanSpec, SemicolonEol)
90
91 class Trst(Grammar):
92 grammar = (L("TRST"), SPACE, (L("ON") | L("OFF") | L("Z") | L("ABSENT")), SemicolonEol)
93
94
95 class SVFFile(Grammar):
96 grammar = ONE_OR_MORE(EmptyLine | Comment | Trst | EndDR | EndIR | SIR | SDR | Runtest | State)