@@ -23,7 +23,7 @@ class ImplementationLimit(Exception):
2323})
2424
2525
26- def signed (value ):
26+ def _signed (value ):
2727 if isinstance (value , str ):
2828 return False
2929 elif isinstance (value , int ):
@@ -34,7 +34,7 @@ def signed(value):
3434 assert False , "Invalid constant {!r}" .format (value )
3535
3636
37- def const (value ):
37+ def _const (value ):
3838 if isinstance (value , str ):
3939 return "\" {}\" " .format (value .translate (_escape_map ))
4040 elif isinstance (value , int ):
@@ -44,7 +44,7 @@ def const(value):
4444 # This code path is only used for Instances, where Verilog-like behavior is desirable.
4545 # Verilog ensures that integers with unspecified width are 32 bits wide or more.
4646 width = max (32 , bits_for (value ))
47- return const (ast .Const (value , width ))
47+ return _const (ast .Const (value , width ))
4848 elif isinstance (value , ast .Const ):
4949 value_twos_compl = value .value & ((1 << value .width ) - 1 )
5050 return "{}'{:0{}b}" .format (value .width , value_twos_compl , value .width )
@@ -98,7 +98,7 @@ def _append(self, *args, **kwargs):
9898class _AttrBuilder :
9999 def _attribute (self , name , value , * , indent = 0 ):
100100 self ._append ("{}attribute \\ {} {}\n " ,
101- " " * indent , name , const (value ))
101+ " " * indent , name , _const (value ))
102102
103103 def _attributes (self , attrs , * , src = None , ** kwargs ):
104104 for name , value in attrs .items ():
@@ -166,12 +166,12 @@ def cell(self, kind, name=None, params={}, ports={}, attrs={}, src=""):
166166 if isinstance (value , float ):
167167 self ._append (" parameter real \\ {} \" {!r}\" \n " ,
168168 param , value )
169- elif signed (value ):
169+ elif _signed (value ):
170170 self ._append (" parameter signed \\ {} {}\n " ,
171- param , const (value ))
171+ param , _const (value ))
172172 else :
173173 self ._append (" parameter \\ {} {}\n " ,
174- param , const (value ))
174+ param , _const (value ))
175175 for port , wire in ports .items ():
176176 self ._append (" connect {} {}\n " , port , wire )
177177 self ._append (" end\n " )
@@ -270,18 +270,14 @@ def update(self, lhs, rhs):
270270 self ._append (" update {} {}\n " , lhs , rhs )
271271
272272
273- def src (src_loc ):
273+ def _src (src_loc ):
274274 if src_loc is None :
275275 return None
276276 file , line = src_loc
277277 return "{}:{}" .format (file , line )
278278
279279
280- def srcs (src_locs ):
281- return "|" .join (sorted (filter (lambda x : x , map (src , src_locs ))))
282-
283-
284- class LegalizeValue (Exception ):
280+ class _LegalizeValue (Exception ):
285281 def __init__ (self , value , branches , src_loc ):
286282 self .value = value
287283 self .branches = list (branches )
@@ -335,10 +331,10 @@ def resolve(self, signal, prefix=None):
335331
336332 wire_curr = self .rtlil .wire (width = signal .width , name = wire_name ,
337333 port_id = port_id , port_kind = port_kind ,
338- attrs = attrs , src = src (signal .src_loc ))
334+ attrs = attrs , src = _src (signal .src_loc ))
339335 if signal in self .driven and self .driven [signal ]:
340336 wire_next = self .rtlil .wire (width = signal .width , name = wire_curr + "$next" ,
341- src = src (signal .src_loc ))
337+ src = _src (signal .src_loc ))
342338 else :
343339 wire_next = None
344340 self .wires [signal ] = (wire_curr , wire_next )
@@ -419,7 +415,7 @@ def on_ArrayProxy(self, value):
419415 else :
420416 max_index = 1 << len (value .index )
421417 max_elem = len (value .elems )
422- raise LegalizeValue (value .index , range (min (max_index , max_elem )), value .src_loc )
418+ raise _LegalizeValue (value .index , range (min (max_index , max_elem )), value .src_loc )
423419
424420
425421class _RHSValueCompiler (_ValueCompiler ):
@@ -454,19 +450,19 @@ def on_value(self, value):
454450 return super ().on_value (self .s .expand (value ))
455451
456452 def on_Const (self , value ):
457- return const (value )
453+ return _const (value )
458454
459455 def on_AnyConst (self , value ):
460456 if value in self .s .anys :
461457 return self .s .anys [value ]
462458
463459 res_bits , res_sign = value .shape ()
464- res = self .s .rtlil .wire (width = res_bits , src = src (value .src_loc ))
460+ res = self .s .rtlil .wire (width = res_bits , src = _src (value .src_loc ))
465461 self .s .rtlil .cell ("$anyconst" , ports = {
466462 "\\ Y" : res ,
467463 }, params = {
468464 "WIDTH" : res_bits ,
469- }, src = src (value .src_loc ))
465+ }, src = _src (value .src_loc ))
470466 self .s .anys [value ] = res
471467 return res
472468
@@ -475,12 +471,12 @@ def on_AnySeq(self, value):
475471 return self .s .anys [value ]
476472
477473 res_bits , res_sign = value .shape ()
478- res = self .s .rtlil .wire (width = res_bits , src = src (value .src_loc ))
474+ res = self .s .rtlil .wire (width = res_bits , src = _src (value .src_loc ))
479475 self .s .rtlil .cell ("$anyseq" , ports = {
480476 "\\ Y" : res ,
481477 }, params = {
482478 "WIDTH" : res_bits ,
483- }, src = src (value .src_loc ))
479+ }, src = _src (value .src_loc ))
484480 self .s .anys [value ] = res
485481 return res
486482
@@ -496,15 +492,15 @@ def on_Operator_unary(self, value):
496492
497493 arg_bits , arg_sign = arg .shape ()
498494 res_bits , res_sign = value .shape ()
499- res = self .s .rtlil .wire (width = res_bits , src = src (value .src_loc ))
495+ res = self .s .rtlil .wire (width = res_bits , src = _src (value .src_loc ))
500496 self .s .rtlil .cell (self .operator_map [(1 , value .operator )], ports = {
501497 "\\ A" : self (arg ),
502498 "\\ Y" : res ,
503499 }, params = {
504500 "A_SIGNED" : arg_sign ,
505501 "A_WIDTH" : arg_bits ,
506502 "Y_WIDTH" : res_bits ,
507- }, src = src (value .src_loc ))
503+ }, src = _src (value .src_loc ))
508504 return res
509505
510506 def match_shape (self , value , new_bits , new_sign ):
@@ -515,15 +511,15 @@ def match_shape(self, value, new_bits, new_sign):
515511 if new_bits <= value_bits :
516512 return self (ast .Slice (value , 0 , new_bits ))
517513
518- res = self .s .rtlil .wire (width = new_bits , src = src (value .src_loc ))
514+ res = self .s .rtlil .wire (width = new_bits , src = _src (value .src_loc ))
519515 self .s .rtlil .cell ("$pos" , ports = {
520516 "\\ A" : self (value ),
521517 "\\ Y" : res ,
522518 }, params = {
523519 "A_SIGNED" : value_sign ,
524520 "A_WIDTH" : value_bits ,
525521 "Y_WIDTH" : new_bits ,
526- }, src = src (value .src_loc ))
522+ }, src = _src (value .src_loc ))
527523 return res
528524
529525 def on_Operator_binary (self , value ):
@@ -539,7 +535,7 @@ def on_Operator_binary(self, value):
539535 lhs_wire = self .match_shape (lhs , lhs_bits , lhs_sign )
540536 rhs_wire = self .match_shape (rhs , rhs_bits , rhs_sign )
541537 res_bits , res_sign = value .shape ()
542- res = self .s .rtlil .wire (width = res_bits , src = src (value .src_loc ))
538+ res = self .s .rtlil .wire (width = res_bits , src = _src (value .src_loc ))
543539 self .s .rtlil .cell (self .operator_map [(2 , value .operator )], ports = {
544540 "\\ A" : lhs_wire ,
545541 "\\ B" : rhs_wire ,
@@ -550,19 +546,19 @@ def on_Operator_binary(self, value):
550546 "B_SIGNED" : rhs_sign ,
551547 "B_WIDTH" : rhs_bits ,
552548 "Y_WIDTH" : res_bits ,
553- }, src = src (value .src_loc ))
549+ }, src = _src (value .src_loc ))
554550 if value .operator in ("//" , "%" ):
555551 # RTLIL leaves division by zero undefined, but we require it to return zero.
556552 divmod_res = res
557- res = self .s .rtlil .wire (width = res_bits , src = src (value .src_loc ))
553+ res = self .s .rtlil .wire (width = res_bits , src = _src (value .src_loc ))
558554 self .s .rtlil .cell ("$mux" , ports = {
559555 "\\ A" : divmod_res ,
560556 "\\ B" : self (ast .Const (0 , ast .Shape (res_bits , res_sign ))),
561557 "\\ S" : self (rhs == 0 ),
562558 "\\ Y" : res ,
563559 }, params = {
564560 "WIDTH" : res_bits
565- }, src = src (value .src_loc ))
561+ }, src = _src (value .src_loc ))
566562 return res
567563
568564 def on_Operator_mux (self , value ):
@@ -573,15 +569,15 @@ def on_Operator_mux(self, value):
573569 val1_bits = val0_bits = res_bits = max (val1_bits , val0_bits , res_bits )
574570 val1_wire = self .match_shape (val1 , val1_bits , val1_sign )
575571 val0_wire = self .match_shape (val0 , val0_bits , val0_sign )
576- res = self .s .rtlil .wire (width = res_bits , src = src (value .src_loc ))
572+ res = self .s .rtlil .wire (width = res_bits , src = _src (value .src_loc ))
577573 self .s .rtlil .cell ("$mux" , ports = {
578574 "\\ A" : val0_wire ,
579575 "\\ B" : val1_wire ,
580576 "\\ S" : self (sel ),
581577 "\\ Y" : res ,
582578 }, params = {
583579 "WIDTH" : res_bits
584- }, src = src (value .src_loc ))
580+ }, src = _src (value .src_loc ))
585581 return res
586582
587583 def on_Operator (self , value ):
@@ -599,7 +595,7 @@ def _prepare_value_for_Slice(self, value):
599595 if isinstance (value , (ast .Signal , ast .Slice , ast .Cat )):
600596 sigspec = self (value )
601597 else :
602- sigspec = self .s .rtlil .wire (len (value ), src = src (value .src_loc ))
598+ sigspec = self .s .rtlil .wire (len (value ), src = _src (value .src_loc ))
603599 self .s .rtlil .connect (sigspec , self (value ))
604600 return sigspec
605601
@@ -610,7 +606,7 @@ def on_Part(self, value):
610606 lhs_bits , lhs_sign = lhs .shape ()
611607 rhs_bits , rhs_sign = rhs .shape ()
612608 res_bits , res_sign = value .shape ()
613- res = self .s .rtlil .wire (width = res_bits , src = src (value .src_loc ))
609+ res = self .s .rtlil .wire (width = res_bits , src = _src (value .src_loc ))
614610 # Note: Verilog's x[o+:w] construct produces a $shiftx cell, not a $shift cell.
615611 # However, nMigen's semantics defines the out-of-range bits to be zero, so it is correct
616612 # to use a $shift cell here instead, even though it produces less idiomatic Verilog.
@@ -624,7 +620,7 @@ def on_Part(self, value):
624620 "B_SIGNED" : rhs_sign ,
625621 "B_WIDTH" : rhs_bits ,
626622 "Y_WIDTH" : res_bits ,
627- }, src = src (value .src_loc ))
623+ }, src = _src (value .src_loc ))
628624 return res
629625
630626 def on_Repl (self , value ):
@@ -681,9 +677,9 @@ def on_Part(self, value):
681677 # is large (e.g. 32-bit wide), trying to naively legalize it is likely to exhaust
682678 # system resources.
683679 max_branches = len (value .value ) // value .stride + 1
684- raise LegalizeValue (value .offset ,
685- range (1 << len (value .offset ))[:max_branches ],
686- value .src_loc )
680+ raise _LegalizeValue (value .offset ,
681+ range (1 << len (value .offset ))[:max_branches ],
682+ value .src_loc )
687683
688684 def on_Repl (self , value ):
689685 raise TypeError # :nocov:
@@ -743,7 +739,7 @@ def on_property(self, stmt):
743739 self .state .rtlil .cell ("$" + stmt ._kind , ports = {
744740 "\\ A" : check_wire ,
745741 "\\ EN" : en_wire ,
746- }, src = src (stmt .src_loc ))
742+ }, src = _src (stmt .src_loc ))
747743
748744 on_Assert = on_property
749745 on_Assume = on_property
@@ -764,11 +760,11 @@ def on_Switch(self, stmt):
764760 # don't cache anything in that case.
765761 test_sigspec = self .rhs_compiler (stmt .test )
766762
767- with self ._case .switch (test_sigspec , src = src (stmt .src_loc )) as switch :
763+ with self ._case .switch (test_sigspec , src = _src (stmt .src_loc )) as switch :
768764 for values , stmts in stmt .cases .items ():
769765 case_attrs = {}
770766 if values in stmt .case_src_locs :
771- case_attrs ["src" ] = src (stmt .case_src_locs [values ])
767+ case_attrs ["src" ] = _src (stmt .case_src_locs [values ])
772768 if isinstance (stmt .test , ast .Signal ) and stmt .test .decoder :
773769 decoded_values = []
774770 for value in values :
@@ -785,9 +781,9 @@ def on_Switch(self, stmt):
785781 def on_statement (self , stmt ):
786782 try :
787783 super ().on_statement (stmt )
788- except LegalizeValue as legalize :
784+ except _LegalizeValue as legalize :
789785 with self ._case .switch (self .rhs_compiler (legalize .value ),
790- src = src (legalize .src_loc )) as switch :
786+ src = _src (legalize .src_loc )) as switch :
791787 shape = legalize .value .shape ()
792788 tests = ["{:0{}b}" .format (v , shape .width ) for v in legalize .branches ]
793789 if tests :
0 commit comments