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