3 from __future__
import print_function
5 class TimingScriptGenerator
:
6 """Used to generate a bash script which will invoke the toy and time it"""
7 def __init__(self
, scriptname
, outputname
):
8 self
.shfile
= open(scriptname
, 'w')
9 self
.timeFile
= outputname
10 self
.shfile
.write("echo \"\" > %s\n" % self
.timeFile
)
12 def writeTimingCall(self
, irname
, callname
):
13 """Echo some comments and invoke both versions of toy"""
16 rootname
= irname
[:irname
.rfind('.')]
17 self
.shfile
.write("echo \"%s: Calls %s\" >> %s\n" % (callname
, irname
, self
.timeFile
))
18 self
.shfile
.write("echo \"\" >> %s\n" % self
.timeFile
)
19 self
.shfile
.write("echo \"With MCJIT\" >> %s\n" % self
.timeFile
)
20 self
.shfile
.write("/usr/bin/time -f \"Command %C\\n\\tuser time: %U s\\n\\tsytem time: %S s\\n\\tmax set: %M kb\"")
21 self
.shfile
.write(" -o %s -a " % self
.timeFile
)
22 self
.shfile
.write("./toy-mcjit -use-object-cache -input-IR=%s < %s > %s-mcjit.out 2> %s-mcjit.err\n" % (irname
, callname
, rootname
, rootname
))
23 self
.shfile
.write("echo \"\" >> %s\n" % self
.timeFile
)
24 self
.shfile
.write("echo \"With MCJIT again\" >> %s\n" % self
.timeFile
)
25 self
.shfile
.write("/usr/bin/time -f \"Command %C\\n\\tuser time: %U s\\n\\tsytem time: %S s\\n\\tmax set: %M kb\"")
26 self
.shfile
.write(" -o %s -a " % self
.timeFile
)
27 self
.shfile
.write("./toy-mcjit -use-object-cache -input-IR=%s < %s > %s-mcjit.out 2> %s-mcjit.err\n" % (irname
, callname
, rootname
, rootname
))
28 self
.shfile
.write("echo \"\" >> %s\n" % self
.timeFile
)
29 self
.shfile
.write("echo \"With JIT\" >> %s\n" % self
.timeFile
)
30 self
.shfile
.write("/usr/bin/time -f \"Command %C\\n\\tuser time: %U s\\n\\tsytem time: %S s\\n\\tmax set: %M kb\"")
31 self
.shfile
.write(" -o %s -a " % self
.timeFile
)
32 self
.shfile
.write("./toy-jit -input-IR=%s < %s > %s-mcjit.out 2> %s-mcjit.err\n" % (irname
, callname
, rootname
, rootname
))
33 self
.shfile
.write("echo \"\" >> %s\n" % self
.timeFile
)
34 self
.shfile
.write("echo \"\" >> %s\n" % self
.timeFile
)
36 class LibScriptGenerator
:
37 """Used to generate a bash script which will convert Kaleidoscope files to IR"""
38 def __init__(self
, filename
):
39 self
.shfile
= open(filename
, 'w')
41 def writeLibGenCall(self
, libname
, irname
):
42 self
.shfile
.write("./toy-ir-gen < %s 2> %s\n" % (libname
, irname
))
44 def splitScript(inputname
, libGenScript
, timingScript
):
45 rootname
= inputname
[:-2]
46 libname
= rootname
+ "-lib.k"
47 irname
= rootname
+ "-lib.ir"
48 callname
= rootname
+ "-call.k"
49 infile
= open(inputname
, "r")
50 libfile
= open(libname
, "w")
51 callfile
= open(callname
, "w")
52 print("Splitting %s into %s and %s" % (inputname
, callname
, libname
))
54 if not line
.startswith("#"):
55 if line
.startswith("print"):
59 libGenScript
.writeLibGenCall(libname
, irname
)
60 timingScript
.writeTimingCall(irname
, callname
)
62 # Execution begins here
63 libGenScript
= LibScriptGenerator("make-libs.sh")
64 timingScript
= TimingScriptGenerator("time-lib.sh", "lib-timing.txt")
66 script_list
= ["test-5000-3-50-50.k", "test-5000-10-100-10.k", "test-5000-10-5-10.k", "test-5000-10-1-0.k",
67 "test-1000-3-10-50.k", "test-1000-10-100-10.k", "test-1000-10-5-10.k", "test-1000-10-1-0.k",
68 "test-200-3-2-50.k", "test-200-10-40-10.k", "test-200-10-2-10.k", "test-200-10-1-0.k"]
70 for script
in script_list
:
71 splitScript(script
, libGenScript
, timingScript
)