Mercurial > hg > CbC > CbC_llvm
diff examples/Kaleidoscope/MCJIT/cached/split-lib.py @ 0:95c75e76d11b LLVM3.4
LLVM 3.4
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 12 Dec 2013 13:56:28 +0900 |
parents | |
children | c2174574ed3a |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/Kaleidoscope/MCJIT/cached/split-lib.py Thu Dec 12 13:56:28 2013 +0900 @@ -0,0 +1,70 @@ +#!/usr/bin/env python + +class TimingScriptGenerator: + """Used to generate a bash script which will invoke the toy and time it""" + def __init__(self, scriptname, outputname): + self.shfile = open(scriptname, 'w') + self.timeFile = outputname + self.shfile.write("echo \"\" > %s\n" % self.timeFile) + + def writeTimingCall(self, irname, callname): + """Echo some comments and invoke both versions of toy""" + rootname = irname + if '.' in irname: + rootname = irname[:irname.rfind('.')] + self.shfile.write("echo \"%s: Calls %s\" >> %s\n" % (callname, irname, self.timeFile)) + self.shfile.write("echo \"\" >> %s\n" % self.timeFile) + self.shfile.write("echo \"With MCJIT\" >> %s\n" % self.timeFile) + self.shfile.write("/usr/bin/time -f \"Command %C\\n\\tuser time: %U s\\n\\tsytem time: %S s\\n\\tmax set: %M kb\"") + self.shfile.write(" -o %s -a " % self.timeFile) + self.shfile.write("./toy-mcjit -use-object-cache -input-IR=%s < %s > %s-mcjit.out 2> %s-mcjit.err\n" % (irname, callname, rootname, rootname)) + self.shfile.write("echo \"\" >> %s\n" % self.timeFile) + self.shfile.write("echo \"With MCJIT again\" >> %s\n" % self.timeFile) + self.shfile.write("/usr/bin/time -f \"Command %C\\n\\tuser time: %U s\\n\\tsytem time: %S s\\n\\tmax set: %M kb\"") + self.shfile.write(" -o %s -a " % self.timeFile) + self.shfile.write("./toy-mcjit -use-object-cache -input-IR=%s < %s > %s-mcjit.out 2> %s-mcjit.err\n" % (irname, callname, rootname, rootname)) + self.shfile.write("echo \"\" >> %s\n" % self.timeFile) + self.shfile.write("echo \"With JIT\" >> %s\n" % self.timeFile) + self.shfile.write("/usr/bin/time -f \"Command %C\\n\\tuser time: %U s\\n\\tsytem time: %S s\\n\\tmax set: %M kb\"") + self.shfile.write(" -o %s -a " % self.timeFile) + self.shfile.write("./toy-jit -input-IR=%s < %s > %s-mcjit.out 2> %s-mcjit.err\n" % (irname, callname, rootname, rootname)) + self.shfile.write("echo \"\" >> %s\n" % self.timeFile) + self.shfile.write("echo \"\" >> %s\n" % self.timeFile) + +class LibScriptGenerator: + """Used to generate a bash script which will convert Kaleidoscope files to IR""" + def __init__(self, filename): + self.shfile = open(filename, 'w') + + def writeLibGenCall(self, libname, irname): + self.shfile.write("./toy-ir-gen < %s 2> %s\n" % (libname, irname)) + +def splitScript(inputname, libGenScript, timingScript): + rootname = inputname[:-2] + libname = rootname + "-lib.k" + irname = rootname + "-lib.ir" + callname = rootname + "-call.k" + infile = open(inputname, "r") + libfile = open(libname, "w") + callfile = open(callname, "w") + print "Splitting %s into %s and %s" % (inputname, callname, libname) + for line in infile: + if not line.startswith("#"): + if line.startswith("print"): + callfile.write(line) + else: + libfile.write(line) + libGenScript.writeLibGenCall(libname, irname) + timingScript.writeTimingCall(irname, callname) + +# Execution begins here +libGenScript = LibScriptGenerator("make-libs.sh") +timingScript = TimingScriptGenerator("time-lib.sh", "lib-timing.txt") + +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", + "test-1000-3-10-50.k", "test-1000-10-100-10.k", "test-1000-10-5-10.k", "test-1000-10-1-0.k", + "test-200-3-2-50.k", "test-200-10-40-10.k", "test-200-10-2-10.k", "test-200-10-1-0.k"] + +for script in script_list: + splitScript(script, libGenScript, timingScript) +print "All done!"