File: split-lib.py

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,998,520 kB
  • sloc: cpp: 6,951,680; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,009; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,167; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (106 lines) | stat: -rw-r--r-- 3,911 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env python3

from __future__ import print_function


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!")