@@ -204,7 +204,7 @@ def buildGraphsForPass(p):
204
204
lir = p ['lir' ]
205
205
return (buildGraphForIR (name , mir , mir ), buildGraphForIR (name , lir , mir ))
206
206
207
- # function obj -> output file -> (Graph OR None, Graph OR None) list
207
+ # function obj -> (Graph OR None, Graph OR None) list
208
208
# First entry in each tuple corresponds to MIR; second, to LIR.
209
209
def buildGraphs (func ):
210
210
graphstup = []
@@ -213,6 +213,11 @@ def buildGraphs(func):
213
213
graphstup .append (gtup )
214
214
return graphstup
215
215
216
+ # function obj -> (Graph OR None, Graph OR None) list
217
+ # Only builds the final pass.
218
+ def buildOnlyFinalPass (func ):
219
+ p = func ['passes' ][- 1 ]
220
+ return [buildGraphsForPass (p )]
216
221
217
222
# Write out a graph, constructing a nice filename.
218
223
# function id -> pass id -> IR string -> Graph -> void
@@ -242,23 +247,45 @@ def parenthesize(s):
242
247
243
248
return s
244
249
250
+ def dieWithUsage ():
251
+ sys .stderr .write (" Usage: " + sys .argv [0 ] + " [--final] <JSON file>\n " )
252
+ sys .exit (1 )
253
+
245
254
def main ():
246
255
# Operate on provided file.
247
256
from sys import argv
248
257
249
- if len (argv ) != 2 or argv [1 ] == '--help' or argv [1 ] == '-h' :
250
- sys .stderr .write (" Usage: " + sys .argv [0 ] + " <JSON file>\n " )
251
- sys .exit (1 )
258
+ argFilename = ''
259
+ optFinal = False
260
+
261
+
262
+ if len (argv ) < 2 or argv [1 ] == '--help' or argv [1 ] == '-h' :
263
+ dieWithUsage ()
264
+
265
+ if len (argv ) == 2 :
266
+ argFilename = argv [1 ]
267
+ elif len (argv ) == 3 :
268
+ if argv [1 ] != '--final' :
269
+ dieWithUsage ()
270
+ argFilename = argv [2 ]
271
+ optFinal = True
272
+ else :
273
+ dieWithUsage ()
252
274
253
- f = open (argv [ 1 ] , 'r' )
275
+ f = open (argFilename , 'r' )
254
276
s = f .read ()
255
277
f .close ()
256
278
257
279
ion = json .loads (parenthesize (s ))
258
280
259
281
for i in range (0 , len (ion ['functions' ])):
260
282
func = ion ['functions' ][i ]
261
- gtl = buildGraphs (func )
283
+
284
+ gtl = []
285
+ if optFinal :
286
+ gtl = buildOnlyFinalPass (func )
287
+ else :
288
+ gtl = buildGraphs (func )
262
289
263
290
if len (gtl ) == 0 :
264
291
sys .stderr .write (" function %d (%s): abort during SSA construction.\n " % (i , func ['name' ]))
@@ -270,8 +297,15 @@ def main():
270
297
mir = gt [0 ]
271
298
lir = gt [1 ]
272
299
273
- # Only output one of (MIR, LIR). Prefer LIR.
274
- # This is just to avoid spam; change if you care about it.
300
+ # If only the final pass is requested, output both MIR and LIR.
301
+ if optFinal :
302
+ if lir != None :
303
+ outputPass (i , j , 'lir' , lir )
304
+ if mir != None :
305
+ outputPass (i , j , 'mir' , mir )
306
+ continue
307
+
308
+ # Normally, only output one of (MIR, LIR), preferring LIR.
275
309
if lir != None :
276
310
outputPass (i , j , 'lir' , lir )
277
311
elif mir != None :
0 commit comments