@@ -441,8 +441,8 @@ def emit_cell_wires(self):
441
441
continue # Instances use one wire per output, not per cell.
442
442
elif isinstance (cell , (_nir .PriorityMatch , _nir .Matches )):
443
443
continue # Inlined into assignment lists.
444
- elif isinstance (cell , (_nir .SyncProperty , _nir .AsyncProperty , _nir .Memory ,
445
- _nir .SyncWritePort )):
444
+ elif isinstance (cell , (_nir .SyncPrint , _nir .AsyncPrint , _nir .SyncProperty ,
445
+ _nir .AsyncProperty , _nir . Memory , _nir . SyncWritePort )):
446
446
continue # No outputs.
447
447
elif isinstance (cell , _nir .AssignmentList ):
448
448
width = len (cell .default )
@@ -859,37 +859,68 @@ def emit_read_port(self, cell_idx, cell):
859
859
})
860
860
self .builder .cell (f"$memrd_v2" , ports = ports , params = params , src = _src (cell .src_loc ))
861
861
862
- def emit_property (self , cell_idx , cell ):
863
- if isinstance (cell , _nir .AsyncProperty ):
864
- ports = {
865
- "A" : self .sigspec (cell .test ),
866
- "EN" : self .sigspec (cell .en ),
867
- }
868
- if isinstance (cell , _nir .SyncProperty ):
869
- test = self .builder .wire (1 , attrs = {"init" : _ast .Const (0 , 1 )})
870
- en = self .builder .wire (1 , attrs = {"init" : _ast .Const (0 , 1 )})
871
- for (d , q ) in [
872
- (cell .test , test ),
873
- (cell .en , en ),
874
- ]:
875
- ports = {
876
- "D" : self .sigspec (d ),
877
- "Q" : q ,
878
- "CLK" : self .sigspec (cell .clk ),
879
- }
880
- params = {
881
- "WIDTH" : 1 ,
882
- "CLK_POLARITY" : {
883
- "pos" : True ,
884
- "neg" : False ,
885
- }[cell .clk_edge ],
886
- }
887
- self .builder .cell (f"$dff" , ports = ports , params = params , src = _src (cell .src_loc ))
888
- ports = {
889
- "A" : test ,
890
- "EN" : en ,
891
- }
892
- self .builder .cell (f"${ cell .kind } " , name = cell .name , ports = ports , src = _src (cell .src_loc ))
862
+ def emit_print (self , cell_idx , cell ):
863
+ args = []
864
+ format = []
865
+ if cell .format is not None :
866
+ for chunk in cell .format .chunks :
867
+ if isinstance (chunk , str ):
868
+ format .append (chunk )
869
+ else :
870
+ args += chunk .value
871
+ spec = _ast .Format ._parse_format_spec (chunk .format_spec )
872
+ type = spec ["type" ]
873
+ if type is None :
874
+ type = "d"
875
+ if type == "x" or type == "X" :
876
+ # TODO(yosys): "H" type
877
+ type = "h"
878
+ if type == "s" :
879
+ # TODO(yosys): support for single unicode character?
880
+ type = "c"
881
+ width = spec ["width" ]
882
+ align = spec ["align" ]
883
+ if align is None :
884
+ align = ">" if type != "c" else "<"
885
+ if align == "=" :
886
+ # TODO(yosys): "=" alignment
887
+ align = ">"
888
+ fill = spec ["fill" ]
889
+ if fill not in (" " , "0" ):
890
+ # TODO(yosys): arbitrary fill
891
+ fill = " "
892
+ # TODO(yosys): support for options, grouping
893
+ sign = spec ["sign" ]
894
+ if sign != "+" :
895
+ # TODO(yosys): support " " sign
896
+ sign = ""
897
+ signed = "s" if chunk .signed else "u"
898
+ format .append (f"{{{ len (chunk .value )} :{ align } { fill } { width or '' } { type } { sign } { signed } }}" )
899
+ ports = {
900
+ "EN" : self .sigspec (cell .en ),
901
+ "ARGS" : self .sigspec (_nir .Value (args )),
902
+ }
903
+ params = {
904
+ "FORMAT" : "" .join (format ),
905
+ "ARGS_WIDTH" : len (args ),
906
+ "PRIORITY" : - cell_idx ,
907
+ }
908
+ if isinstance (cell , (_nir .AsyncPrint , _nir .AsyncProperty )):
909
+ ports ["TRG" ] = self .sigspec (_nir .Value ())
910
+ params ["TRG_ENABLE" ] = False
911
+ params ["TRG_WIDTH" ] = 0
912
+ params ["TRG_POLARITY" ] = 0
913
+ if isinstance (cell , (_nir .SyncPrint , _nir .SyncProperty )):
914
+ ports ["TRG" ] = self .sigspec (cell .clk )
915
+ params ["TRG_ENABLE" ] = True
916
+ params ["TRG_WIDTH" ] = 1
917
+ params ["TRG_POLARITY" ] = cell .clk_edge == "pos"
918
+ if isinstance (cell , (_nir .AsyncPrint , _nir .SyncPrint )):
919
+ self .builder .cell (f"$print" , params = params , ports = ports , src = _src (cell .src_loc ))
920
+ if isinstance (cell , (_nir .AsyncProperty , _nir .SyncProperty )):
921
+ params ["FLAVOR" ] = cell .kind
922
+ ports ["A" ] = self .sigspec (cell .test )
923
+ self .builder .cell (f"$check" , params = params , ports = ports , src = _src (cell .src_loc ))
893
924
894
925
def emit_any_value (self , cell_idx , cell ):
895
926
self .builder .cell (f"${ cell .kind } " , ports = {
@@ -939,8 +970,8 @@ def emit_cells(self):
939
970
self .emit_write_port (cell_idx , cell )
940
971
elif isinstance (cell , (_nir .AsyncReadPort , _nir .SyncReadPort )):
941
972
self .emit_read_port (cell_idx , cell )
942
- elif isinstance (cell , (_nir .AsyncProperty , _nir .SyncProperty )):
943
- self .emit_property (cell_idx , cell )
973
+ elif isinstance (cell , (_nir .AsyncPrint , _nir . SyncPrint , _nir . AsyncProperty , _nir .SyncProperty )):
974
+ self .emit_print (cell_idx , cell )
944
975
elif isinstance (cell , _nir .AnyValue ):
945
976
self .emit_any_value (cell_idx , cell )
946
977
elif isinstance (cell , _nir .Initial ):
0 commit comments