Skip to content

Commit 976909a

Browse files
committed
Add a generator for the ELF executables list
As the number of ELF executables may increase over time, manually updating the HTML ELF list becomes tedious. Therefore, an ELF list generator has been introduced. When new ELF executables are added to the build or build/riscv32 directories, the list will be generated dynamically. Close: #486
1 parent 74af7cc commit 976909a

File tree

3 files changed

+40
-32
lines changed

3 files changed

+40
-32
lines changed

assets/html/index.html

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -130,40 +130,11 @@
130130
</div>
131131
<textarea id="output" rows="8"></textarea>
132132

133+
<script src="elf_list.js"></script>
133134
<script type='text/javascript'>
134135
var statusElement = document.getElementById('status');
135136
var progressElement = document.getElementById('progress');
136137
var spinnerElement = document.getElementById('spinner');
137-
138-
var elfFiles = [
139-
"riscv32/doom",
140-
"smolnes.elf",
141-
"riscv32/quake",
142-
"riscv32/coremark",
143-
"riscv32/dhrystone",
144-
"riscv32/pi",
145-
"riscv32/donut",
146-
"riscv32/aes",
147-
"coro.elf",
148-
"riscv32/fcalc",
149-
"riscv32/hamilton",
150-
"hello.elf",
151-
"ieee754.elf",
152-
"jit-bf.elf",
153-
"riscv32/maj2random",
154-
"riscv32/mandelbrot",
155-
"riscv32/nqueens",
156-
"riscv32/nyancat",
157-
"perfcount.elf",
158-
"riscv32/qrcode",
159-
"readelf.elf",
160-
"riscv32/richards",
161-
"riscv32/rvsim",
162-
"riscv32/scimark2",
163-
"riscv32/spirograph",
164-
"riscv32/stream",
165-
];
166-
167138
var runButton = document.getElementById("runButton");
168139
runButton.addEventListener("click", runButtonClickHandler);
169140

mk/wasm.mk

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,15 @@ CFLAGS_emcc += -sINITIAL_MEMORY=2GB \
3434
-DMEM_SIZE=0x40000000 \
3535
-DCYCLE_PER_STEP=2000000 \
3636
--pre-js $(WEB_JS_RESOURCES)/pre.js \
37+
--pre-js $(DEMO_DIR)/elf_list.js \
3738
-O3 \
3839
-w
3940

41+
gen_elf_list_js:
42+
$(Q)tools/gen-elf-list-js.py > $(DEMO_DIR)/elf_list.js
43+
4044
# used to download all dependencies of elf executable and bundle into single wasm
41-
deps_emcc += $(DOOM_DATA) $(QUAKE_DATA) $(TIMIDITY_DATA)
45+
deps_emcc += gen_elf_list_js $(DOOM_DATA) $(QUAKE_DATA) $(TIMIDITY_DATA)
4246

4347
# check browser MAJOR version if supports TCO
4448
CHROME_MAJOR :=
@@ -98,7 +102,7 @@ endef
98102
STATIC_WEB_FILES := $(WEB_HTML_RESOURCES)/index.html \
99103
$(WEB_JS_RESOURCES)/coi-serviceworker.min.js
100104

101-
start-web: $(BIN) check-demo-dir-exist
105+
start-web: check-demo-dir-exist $(BIN)
102106
$(foreach T, $(WEB_FILES), $(call cp-web-file, $(T)))
103107
$(foreach T, $(STATIC_WEB_FILES), $(call cp-web-file, $(T)))
104108
$(Q)python3 -m http.server --bind $(DEMO_IP) $(DEMO_PORT) --directory $(DEMO_DIR)

tools/gen-elf-list-js.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
5+
def list_files(d):
6+
try:
7+
if d == "build":
8+
files = [f for f in os.listdir(d) if (os.path.isfile(os.path.join(d, f)) and f.endswith('.elf'))]
9+
else:
10+
parent_dir = os.path.dirname(d)
11+
files = [
12+
os.path.relpath(os.path.join(d, f), start=parent_dir)
13+
for f in os.listdir(d)
14+
if os.path.isfile(os.path.join(d, f))
15+
]
16+
return files
17+
except FileNotFoundError:
18+
print(f"Directory {directory} not found.")
19+
return []
20+
21+
elf_exec_dirs = ["build", "build/riscv32"]
22+
elf_exec_list = []
23+
24+
for d in elf_exec_dirs:
25+
files = list_files(d)
26+
elf_exec_list.extend(files)
27+
#print(elf_exec_list)
28+
29+
def gen_elf_list_js():
30+
js_code = f"const elfFiles = {elf_exec_list};\n"
31+
print(js_code)
32+
33+
gen_elf_list_js()

0 commit comments

Comments
 (0)