99
1010from riscvmodel .code import decode
1111from riscvmodel .model import Model
12- from riscvmodel .variant import RV32I
12+ from riscvmodel .variant import RV32I , RV32IM , Variant
1313import pygments
1414import pygments .lexers
1515import pygments .formatters
@@ -46,9 +46,11 @@ def render(pipeline, args):
4646
4747 model = Model (RV32I ) if "e" in args .format else None
4848
49+ stages = pipeline .get_stages ()
50+
4951 header_legend = []
5052 length = 0 # need to keep track separately
51- for s in pipeline . stages :
53+ for s in stages :
5254 leg = colorama .Style .BRIGHT + \
5355 display [s ].fore + display [s ].back + \
5456 display [s ].char + colorama .Style .RESET_ALL
@@ -57,7 +59,7 @@ def render(pipeline, args):
5759 length += 2 + len (display [s ].legend )
5860 header_legend .append (leg )
5961 header_legend = " " .join (header_legend )
60- print (header_legend )
62+ args . outfile . write (header_legend )
6163
6264 col_width = {'m' : 1 , 'r' : 8 , 't' : 17 , 'p' : 16 , 'i' : 20 , 'e' : 40 }
6365
@@ -96,20 +98,20 @@ def render(pipeline, args):
9698 in_snip = False
9799 line = list ("." * args .width )
98100
99- for s in range (len (pipeline . stages )):
100- stage = pipeline . stages [s ]
101+ for s in range (len (stages )):
102+ stage = stages [s ]
101103 if stage in i and i [stage ] is not None :
102104 line [i [stage ] % args .width ] = display [stage ].fore + \
103105 display [stage ].back + display [stage ].char + \
104106 colorama .Style .RESET_ALL
105107 next = s + 1
106- if next >= len (pipeline . stages ) and "end" in i and i ["end" ] is not None :
108+ if next >= len (stages ) and "end" in i and i ["end" ] is not None :
107109 for x in range (i [stage ] + 1 , i ["end" ]+ 1 ):
108110 line [x % args .width ] = display [stage ].fore + \
109111 display [stage ].back + "=" + \
110112 colorama .Style .RESET_ALL
111113 continue
112- next = pipeline . stages [next ]
114+ next = stages [next ]
113115 if next in i and i [next ] is not None :
114116 for x in range (i [stage ] + 1 , i [next ]):
115117 line [x % args .width ] = display [stage ].fore + \
@@ -129,32 +131,34 @@ def render(pipeline, args):
129131 elif c == "r" :
130132 if "end" in i and i ["end" ]:
131133 count_retired += 1
132- elif "RE" in pipeline . stages :
134+ elif "RE" in stages :
133135 if i .RE is not None :
134136 count_retired += 1
135- elif "C" in pipeline . stages :
137+ elif "C" in stages :
136138 if i .C is not None :
137139 count_retired += 1
138140 line += "{:8}" .format (count_retired )
139141 width = 8
140142 elif c == "t" :
141- if pipeline . stages [- 1 ] in i and i [pipeline . stages [- 1 ]]:
142- line += "{:8}-{:8}" .format (i [pipeline . stages [0 ]],
143- i [pipeline . stages [- 1 ]])
143+ if stages [- 1 ] in i and i [stages [- 1 ]]:
144+ line += "{:8}-{:8}" .format (i [stages [0 ]],
145+ i [stages [- 1 ]])
144146 else :
145- line += "{:8}---------" .format (i [pipeline . stages [0 ]])
147+ line += "{:8}---------" .format (i [stages [0 ]])
146148 width = 17
147149 elif c == "p" :
148150 line += "{:016x}" .format (i .pc )
149151 width = 16
150152 elif c == "i" and i .insn :
151- insn = str (decode (int (i .insn )))
152- line += pygments .highlight (insn , pygments .lexers .GasLexer (
153- ), pygments .formatters .TerminalFormatter ()).strip ()
153+ try :
154+ insn = str (decode (int (i .insn ), Variant ("RV32IMZifencei_Zicsr" )))
155+ except :
156+ insn = str (i .insn )
157+ line += pygments .highlight (insn , pygments .lexers .GasLexer (), pygments .formatters .TerminalFormatter ()).strip ()
154158 width = len (insn )
155159 elif c == "e" :
156160 line += colorama .Style .DIM
157- insn = decode (int (i .insn ))
161+ insn = decode (int (i .insn ), Variant ( "RV32IMZifencei_Zicsr" ) )
158162 inops = insn .inopstr (model )
159163 if len (inops ) > 0 :
160164 line += "[i] " + inops
0 commit comments