Skip to content

Commit bfbedec

Browse files
committed
WIP: Update coremark build scirpt
Signed-off-by: Ádám László Kulcsár <[email protected]>
1 parent 0f40ad3 commit bfbedec

File tree

1 file changed

+97
-3
lines changed

1 file changed

+97
-3
lines changed

test/programs/build_programs.py

Lines changed: 97 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,124 @@
1616

1717
import argparse
1818
import os
19+
from subprocess import PIPE, Popen
1920

2021
from os.path import abspath, dirname, join
2122

2223
PROGRAMS_SOURCE_DIR = dirname(abspath(__file__))
2324

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+
2434
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+
2599
return
26100

101+
27102
def parse_args():
103+
global emcc, emcc_path, clang, clang_path
104+
28105
parser = argparse.ArgumentParser()
29106
parser.add_argument("--all", help="compile all programs", action="store_true", default=True)
30107
parser.add_argument("--coremark", help="compile coremark", action="store_true")
31108
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="")
32111
args = parser.parse_args()
33112

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+
35129
return args
36130

37131
def main():
38132
args = parse_args()
39-
133+
40134
if args.all:
41135
compile_coremark()
42-
136+
43137
print("All programs compiled succesfully!")
44138
return
45139

0 commit comments

Comments
 (0)