3 from __future__
import print_function
6 class TimingScriptGenerator
:
7 """Used to generate a bash script which will invoke the toy and time it"""
9 def __init__(self
, scriptname
, outputname
):
10 self
.shfile
= open(scriptname
, "w")
11 self
.timeFile
= outputname
12 self
.shfile
.write('echo "" > %s\n' % self
.timeFile
)
14 def writeTimingCall(self
, irname
, callname
):
15 """Echo some comments and invoke both versions of toy"""
18 rootname
= irname
[: irname
.rfind(".")]
20 'echo "%s: Calls %s" >> %s\n' % (callname
, irname
, self
.timeFile
)
22 self
.shfile
.write('echo "" >> %s\n' % self
.timeFile
)
23 self
.shfile
.write('echo "With MCJIT" >> %s\n' % self
.timeFile
)
25 '/usr/bin/time -f "Command %C\\n\\tuser time: %U s\\n\\tsytem time: %S s\\n\\tmax set: %M kb"'
27 self
.shfile
.write(" -o %s -a " % self
.timeFile
)
29 "./toy-mcjit -use-object-cache -input-IR=%s < %s > %s-mcjit.out 2> %s-mcjit.err\n"
30 % (irname
, callname
, rootname
, rootname
)
32 self
.shfile
.write('echo "" >> %s\n' % self
.timeFile
)
33 self
.shfile
.write('echo "With MCJIT again" >> %s\n' % self
.timeFile
)
35 '/usr/bin/time -f "Command %C\\n\\tuser time: %U s\\n\\tsytem time: %S s\\n\\tmax set: %M kb"'
37 self
.shfile
.write(" -o %s -a " % self
.timeFile
)
39 "./toy-mcjit -use-object-cache -input-IR=%s < %s > %s-mcjit.out 2> %s-mcjit.err\n"
40 % (irname
, callname
, rootname
, rootname
)
42 self
.shfile
.write('echo "" >> %s\n' % self
.timeFile
)
43 self
.shfile
.write('echo "With JIT" >> %s\n' % self
.timeFile
)
45 '/usr/bin/time -f "Command %C\\n\\tuser time: %U s\\n\\tsytem time: %S s\\n\\tmax set: %M kb"'
47 self
.shfile
.write(" -o %s -a " % self
.timeFile
)
49 "./toy-jit -input-IR=%s < %s > %s-mcjit.out 2> %s-mcjit.err\n"
50 % (irname
, callname
, rootname
, rootname
)
52 self
.shfile
.write('echo "" >> %s\n' % self
.timeFile
)
53 self
.shfile
.write('echo "" >> %s\n' % self
.timeFile
)
56 class LibScriptGenerator
:
57 """Used to generate a bash script which will convert Kaleidoscope files to IR"""
59 def __init__(self
, filename
):
60 self
.shfile
= open(filename
, "w")
62 def writeLibGenCall(self
, libname
, irname
):
63 self
.shfile
.write("./toy-ir-gen < %s 2> %s\n" % (libname
, irname
))
66 def splitScript(inputname
, libGenScript
, timingScript
):
67 rootname
= inputname
[:-2]
68 libname
= rootname
+ "-lib.k"
69 irname
= rootname
+ "-lib.ir"
70 callname
= rootname
+ "-call.k"
71 infile
= open(inputname
, "r")
72 libfile
= open(libname
, "w")
73 callfile
= open(callname
, "w")
74 print("Splitting %s into %s and %s" % (inputname
, callname
, libname
))
76 if not line
.startswith("#"):
77 if line
.startswith("print"):
81 libGenScript
.writeLibGenCall(libname
, irname
)
82 timingScript
.writeTimingCall(irname
, callname
)
85 # Execution begins here
86 libGenScript
= LibScriptGenerator("make-libs.sh")
87 timingScript
= TimingScriptGenerator("time-lib.sh", "lib-timing.txt")
90 "test-5000-3-50-50.k",
91 "test-5000-10-100-10.k",
92 "test-5000-10-5-10.k",
94 "test-1000-3-10-50.k",
95 "test-1000-10-100-10.k",
96 "test-1000-10-5-10.k",
99 "test-200-10-40-10.k",
100 "test-200-10-2-10.k",
104 for script
in script_list
:
105 splitScript(script
, libGenScript
, timingScript
)