10
10
11
11
12
12
_reserved_keywords = {
13
- "always" , "and" , "assign" , "automatic" , "begin" , "buf" , "bufif0" , "bufif1" ,
14
- "case" , "casex" , "casez" , "cell" , "cmos" , "config" , "deassign" , "default" ,
15
- "defparam" , "design" , "disable" , "edge" , "else" , "end" , "endcase" , "endconfig" ,
16
- "endfunction" , "endgenerate" , "endmodule" , "endprimitive" , "endspecify" ,
17
- "endtable" , "endtask" , "event" , "for" , "force" , "forever" , "fork" , "function" ,
18
- "generate" , "genvar" , "highz0" , "highz1" , "if" , "ifnone" , "incdir" , "include" ,
19
- "initial" , "inout" , "input" , "instance" , "integer" , "join" , "large" , "liblist" ,
20
- "library" , "localparam" , "macromodule" , "medium" , "module" , "nand" , "negedge" ,
21
- "nmos" , "nor" , "noshowcancelled" , "not" , "notif0" , "notif1" , "or" , "output" ,
22
- "parameter" , "pmos" , "posedge" , "primitive" , "pull0" , "pull1" "pulldown"
23
- "pullup" ,"pulsestyle_onevent" , "pulsestyle_ondetect" , "remos" , "real" ,
24
- "realtime" , "reg" , "release" , "repeat" , "rnmos" , "rpmos" , "rtran" , "rtranif0" ,
25
- "rtranif1" , "scalared" , "showcancelled" , "signed" , "small" , "specify" ,
26
- "specparam" , "strong0" , "strong1" , "supply0" , "supply1" , "table" , "task" ,
27
- "time" , "tran" , "tranif0" , "tranif1" , "tri" , "tri0" , "tri1" , "triand" ,
28
- "trior" , "trireg" , "unsigned" , "use" , "vectored" , "wait" , "wand" , "weak0" ,
29
- "weak1" , "while" , "wire" , "wor" ,"xnor" ,"xor"
13
+ "always" , "and" , "assign" , "automatic" , "begin" , "buf" , "bufif0" , "bufif1" ,
14
+ "case" , "casex" , "casez" , "cell" , "cmos" , "config" , "deassign" , "default" ,
15
+ "defparam" , "design" , "disable" , "edge" , "else" , "end" , "endcase" ,
16
+ "endconfig" , "endfunction" , "endgenerate" , "endmodule" , "endprimitive" ,
17
+ "endspecify" , "endtable" , "endtask" , "event" , "for" , "force" , "forever" ,
18
+ "fork" , "function" , "generate" , "genvar" , "highz0" , "highz1" , "if" ,
19
+ "ifnone" , "incdir" , "include" , "initial" , "inout" , "input" ,
20
+ "instance" , "integer" , "join" , "large" , "liblist" , "library" , "localparam" ,
21
+ "macromodule" , "medium" , "module" , "nand" , "negedge" , "nmos" , "nor" ,
22
+ "noshowcancelled" , "not" , "notif0" , "notif1" , "or" , "output" , "parameter" ,
23
+ "pmos" , "posedge" , "primitive" , "pull0" , "pull1" "pulldown" ,
24
+ "pullup" , "pulsestyle_onevent" , "pulsestyle_ondetect" , "remos" , "real" ,
25
+ "realtime" , "reg" , "release" , "repeat" , "rnmos" , "rpmos" , "rtran" ,
26
+ "rtranif0" , "rtranif1" , "scalared" , "showcancelled" , "signed" , "small" ,
27
+ "specify" , "specparam" , "strong0" , "strong1" , "supply0" , "supply1" ,
28
+ "table" , "task" , "time" , "tran" , "tranif0" , "tranif1" , "tri" , "tri0" ,
29
+ "tri1" , "triand" , "trior" , "trireg" , "unsigned" , "use" , "vectored" , "wait" ,
30
+ "wand" , "weak0" , "weak1" , "while" , "wire" , "wor" ,"xnor" , "xor"
30
31
}
31
32
32
33
@@ -41,25 +42,17 @@ def _printsig(ns, s):
41
42
return n
42
43
43
44
44
- def _printintbool (node ):
45
- if isinstance (node , bool ):
46
- if node :
47
- return "1'd1" , False
48
- else :
49
- return "1'd0" , False
50
- elif isinstance (node , int ):
51
- nbits = bits_for (node )
52
- if node >= 0 :
53
- return str (nbits ) + "'d" + str (node ), False
54
- else :
55
- return str (nbits ) + "'sd" + str (2 ** nbits + node ), True
45
+ def _printconstant (node ):
46
+ if node .signed :
47
+ return (str (node .nbits ) + "'sd" + str (2 ** node .nbits + node .value ),
48
+ True )
56
49
else :
57
- raise TypeError
50
+ return str ( node . nbits ) + "'d" + str ( node . value ), False
58
51
59
52
60
53
def _printexpr (ns , node ):
61
- if isinstance (node , ( int , bool ) ):
62
- return _printintbool (node )
54
+ if isinstance (node , Constant ):
55
+ return _printconstant (node )
63
56
elif isinstance (node , Signal ):
64
57
return ns .get_name (node ), node .signed
65
58
elif isinstance (node , _Operator ):
@@ -116,7 +109,7 @@ def _printexpr(ns, node):
116
109
elif isinstance (node , Replicate ):
117
110
return "{" + str (node .n ) + "{" + _printexpr (ns , node .v )[0 ] + "}}" , False
118
111
else :
119
- raise TypeError ("Expression of unrecognized type: " + str (type (node )))
112
+ raise TypeError ("Expression of unrecognized type: '{}'" . format (type (node ). __name__ ))
120
113
121
114
122
115
(_AT_BLOCKING , _AT_NONBLOCKING , _AT_SIGNAL ) = range (3 )
@@ -148,7 +141,7 @@ def _printnode(ns, at, level, node):
148
141
elif isinstance (node , Case ):
149
142
if node .cases :
150
143
r = "\t " * level + "case (" + _printexpr (ns , node .test )[0 ] + ")\n "
151
- css = sorted ([(k , v ) for (k , v ) in node .cases .items () if k != "default" ], key = itemgetter (0 ))
144
+ css = sorted ([(k , v ) for (k , v ) in node .cases .items () if isinstance ( k , Constant ) ], key = itemgetter (0 ))
152
145
for choice , statements in css :
153
146
r += "\t " * (level + 1 ) + _printexpr (ns , choice )[0 ] + ": begin\n "
154
147
r += _printnode (ns , at , level + 2 , statements )
@@ -183,7 +176,7 @@ def _printheader(f, ios, name, ns,
183
176
wires = _list_comb_wires (f ) | special_outs
184
177
r = "module " + name + "(\n "
185
178
firstp = True
186
- for sig in sorted (ios , key = lambda x : x .huid ):
179
+ for sig in sorted (ios , key = lambda x : x .duid ):
187
180
if not firstp :
188
181
r += ",\n "
189
182
firstp = False
@@ -197,7 +190,7 @@ def _printheader(f, ios, name, ns,
197
190
else :
198
191
r += "\t input " + _printsig (ns , sig )
199
192
r += "\n );\n \n "
200
- for sig in sorted (sigs - ios , key = lambda x : x .huid ):
193
+ for sig in sorted (sigs - ios , key = lambda x : x .duid ):
201
194
if sig in wires :
202
195
r += "wire " + _printsig (ns , sig ) + ";\n "
203
196
else :
@@ -280,7 +273,7 @@ def _call_special_classmethod(overrides, obj, method, *args, **kwargs):
280
273
def _lower_specials_step (overrides , specials ):
281
274
f = _Fragment ()
282
275
lowered_specials = set ()
283
- for special in sorted (specials , key = lambda x : x .huid ):
276
+ for special in sorted (specials , key = lambda x : x .duid ):
284
277
impl = _call_special_classmethod (overrides , special , "lower" )
285
278
if impl is not None :
286
279
f += impl .get_fragment ()
@@ -310,7 +303,7 @@ def _lower_specials(overrides, specials):
310
303
311
304
def _printspecials (overrides , specials , ns , add_data_file ):
312
305
r = ""
313
- for special in sorted (specials , key = lambda x : x .huid ):
306
+ for special in sorted (specials , key = lambda x : x .duid ):
314
307
pr = _call_special_classmethod (overrides , special , "emit_verilog" , ns , add_data_file )
315
308
if pr is None :
316
309
raise NotImplementedError ("Special " + str (special ) + " failed to implement emit_verilog" )
0 commit comments