|
16 | 16 |
|
17 | 17 | import argparse
|
18 | 18 | import os
|
| 19 | +from subprocess import PIPE, Popen |
19 | 20 |
|
20 | 21 | from os.path import abspath, dirname, join
|
21 | 22 |
|
22 | 23 | PROGRAMS_SOURCE_DIR = dirname(abspath(__file__))
|
23 | 24 |
|
| 25 | +PROGRAMS_EXECUTABLE_DIR = join(dirname(abspath(__file__)), "executables") |
| 26 | + |
| 27 | +COREMARK_SOURCES = join(PROGRAMS_SOURCE_DIR, "coremark") |
| 28 | + |
| 29 | +clang = False |
| 30 | +emcc = False |
| 31 | +clang_path = '/opt/wasi-sdk/bin/clang' |
| 32 | +emcc_path = '/usr/lib/emscripten/emcc' |
| 33 | + |
24 | 34 | def compile_coremark():
|
| 35 | + global emcc, emcc_path, clang, clang_path |
| 36 | + |
| 37 | + if clang: |
| 38 | + if os.system(clang_path + " --version >/dev/null") != 0: |
| 39 | + print("Could not find wasi-clang for building coremark.") |
| 40 | + exit(1) |
| 41 | + |
| 42 | + proc = Popen([clang_path, |
| 43 | + '-O3', |
| 44 | + '-I'+COREMARK_SOURCES+'/posix', '-I'+COREMARK_SOURCES, |
| 45 | + '-DFLAGS_STR="-O3 -DPERFORMANCE_RUN=1"', |
| 46 | + '-Wl,--export=main', |
| 47 | + '-DITERATIONS=400000', |
| 48 | + '-DSEED_METHOD=SEED_VOLATILE', |
| 49 | + '-DPERFORMANCE_RUN=1', |
| 50 | + '-Wl,--allow-undefined', |
| 51 | + COREMARK_SOURCES + '/core_list_join.c', |
| 52 | + COREMARK_SOURCES + '/core_main.c', |
| 53 | + COREMARK_SOURCES + '/core_matrix.c', |
| 54 | + COREMARK_SOURCES + '/core_state.c', |
| 55 | + COREMARK_SOURCES + '/core_util.c', |
| 56 | + COREMARK_SOURCES + '/posix/core_portme.c', |
| 57 | + '-o'+ PROGRAMS_EXECUTABLE_DIR +'/coremark_clang.wasm' |
| 58 | + ]) |
| 59 | + |
| 60 | + out, _ = proc.communicate() |
| 61 | + |
| 62 | + if proc.returncode != 0: |
| 63 | + print("Error with clang compilation! Stopping.") |
| 64 | + exit(1) |
| 65 | + |
| 66 | + |
| 67 | + if emcc: |
| 68 | + if os.system(emcc_path + " --version >/dev/null") != 0: |
| 69 | + print("Could not find emcc for building coremark.") |
| 70 | + exit(1) |
| 71 | + |
| 72 | + proc = Popen([emcc_path, |
| 73 | + '-O3', |
| 74 | + '-I'+COREMARK_SOURCES, '-I',COREMARK_SOURCES+'/posix', |
| 75 | + '-DFLAGS_STR="-O3 -DPERFORMANCE_RUN=1"', |
| 76 | + '-Wl,--allow-undefined', |
| 77 | + '-DITERATIONS=400000', |
| 78 | + '-DSEED_METHOD=SEED_VOLATILE', |
| 79 | + '-DPERFORMANCE_RUN=1', |
| 80 | + '-Wl,--export=main', |
| 81 | + '-sWASM=1', |
| 82 | + '-sEXPORTED_FUNCTIONS=_main', |
| 83 | + '-sEXPORTED_RUNTIME_METHODS=ccal,cwrap', |
| 84 | + COREMARK_SOURCES + '/core_list_join.c', |
| 85 | + COREMARK_SOURCES + '/core_main.c', |
| 86 | + COREMARK_SOURCES + '/core_matrix.c', |
| 87 | + COREMARK_SOURCES + '/core_state.c', |
| 88 | + COREMARK_SOURCES + '/core_util.c', |
| 89 | + COREMARK_SOURCES + '/posix/core_portme.c', |
| 90 | + '-o'+ PROGRAMS_EXECUTABLE_DIR +'/coremark_emcc.wasm' |
| 91 | + ]) |
| 92 | + |
| 93 | + out, _ = proc.communicate() |
| 94 | + |
| 95 | + if proc.returncode != 0: |
| 96 | + print("Error with emscripten compilation! Stopping.") |
| 97 | + exit(1) |
| 98 | + |
25 | 99 | return
|
26 | 100 |
|
| 101 | + |
27 | 102 | def parse_args():
|
| 103 | + global emcc, emcc_path, clang, clang_path |
| 104 | + |
28 | 105 | parser = argparse.ArgumentParser()
|
29 | 106 | parser.add_argument("--all", help="compile all programs", action="store_true", default=True)
|
30 | 107 | parser.add_argument("--coremark", help="compile coremark", action="store_true")
|
31 | 108 | parser.add_argument("--summary", help="Generate summary", action="store_true", default=False)
|
| 109 | + parser.add_argument("--emcc", help="Compile with emscripten. If there is no system emcc then follow the argument with a path to the emcc executeable.", nargs="?", default="") |
| 110 | + parser.add_argument("--clang", help="Compile with clang. If there is no system emcc then follow the argument with a path to the emcc executeable.", nargs="?", default="") |
32 | 111 | args = parser.parse_args()
|
33 | 112 |
|
34 |
| - args.orig_results = args.results.copy() |
| 113 | + if args.emcc != "" and args.emcc is not None: |
| 114 | + emcc_path = args.emcc |
| 115 | + emcc = True |
| 116 | + elif args.emcc != "": |
| 117 | + emcc = True |
| 118 | + |
| 119 | + if args.clang != "" and args.clang is not None: |
| 120 | + clang_path = args.clang |
| 121 | + clang = True |
| 122 | + elif args.clang != "": |
| 123 | + clang = True |
| 124 | + |
| 125 | + if not clang and not emcc: |
| 126 | + print("Please define which compilers to use with --emcc, --clang!") |
| 127 | + exit(1) |
| 128 | + |
35 | 129 | return args
|
36 | 130 |
|
37 | 131 | def main():
|
38 | 132 | args = parse_args()
|
39 |
| - |
| 133 | + |
40 | 134 | if args.all:
|
41 | 135 | compile_coremark()
|
42 |
| - |
| 136 | + |
43 | 137 | print("All programs compiled succesfully!")
|
44 | 138 | return
|
45 | 139 |
|
|
0 commit comments