Skip to content

Commit 8b54a8f

Browse files
author
Sean Stangl
committed
Add 'make final' to only build the last (MIR, LIR) pair.
1 parent daa1947 commit 8b54a8f

File tree

2 files changed

+48
-8
lines changed

2 files changed

+48
-8
lines changed

Makefile

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ all: gv png pdf
44
# Convenient shorthand.
55
repng: clean png
66
repdf: clean pdf
7+
refinal: clean final
8+
9+
# Only generate the final (MIR, LIR) for each function.
10+
final: /tmp/ion.json
11+
./iongraph --final $<
12+
./genpngs
713

814
gv: /tmp/ion.json
915
./iongraph $<

iongraph

+42-8
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def buildGraphsForPass(p):
204204
lir = p['lir']
205205
return (buildGraphForIR(name, mir, mir), buildGraphForIR(name, lir, mir))
206206

207-
# function obj -> output file -> (Graph OR None, Graph OR None) list
207+
# function obj -> (Graph OR None, Graph OR None) list
208208
# First entry in each tuple corresponds to MIR; second, to LIR.
209209
def buildGraphs(func):
210210
graphstup = []
@@ -213,6 +213,11 @@ def buildGraphs(func):
213213
graphstup.append(gtup)
214214
return graphstup
215215

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)]
216221

217222
# Write out a graph, constructing a nice filename.
218223
# function id -> pass id -> IR string -> Graph -> void
@@ -242,23 +247,45 @@ def parenthesize(s):
242247

243248
return s
244249

250+
def dieWithUsage():
251+
sys.stderr.write(" Usage: " + sys.argv[0] + " [--final] <JSON file>\n")
252+
sys.exit(1)
253+
245254
def main():
246255
# Operate on provided file.
247256
from sys import argv
248257

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()
252274

253-
f = open(argv[1], 'r')
275+
f = open(argFilename, 'r')
254276
s = f.read()
255277
f.close()
256278

257279
ion = json.loads(parenthesize(s))
258280

259281
for i in range(0, len(ion['functions'])):
260282
func = ion['functions'][i]
261-
gtl = buildGraphs(func)
283+
284+
gtl = []
285+
if optFinal:
286+
gtl = buildOnlyFinalPass(func)
287+
else:
288+
gtl = buildGraphs(func)
262289

263290
if len(gtl) == 0:
264291
sys.stderr.write(" function %d (%s): abort during SSA construction.\n" % (i, func['name']))
@@ -270,8 +297,15 @@ def main():
270297
mir = gt[0]
271298
lir = gt[1]
272299

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.
275309
if lir != None:
276310
outputPass(i, j, 'lir', lir)
277311
elif mir != None:

0 commit comments

Comments
 (0)