Skip to content

Commit df9b7f4

Browse files
authored
Merge pull request sysprog21#487 from ChinYikMing/fix-wasm-service
Bring WebAssembly service up
2 parents 9d2af70 + aa57760 commit df9b7f4

File tree

3 files changed

+44
-36
lines changed

3 files changed

+44
-36
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-
"doom.elf",
140-
"smolnes.elf",
141-
"quake.elf",
142-
"coremark.elf",
143-
"dhrystone.elf",
144-
"pi.elf",
145-
"donut.elf",
146-
"aes.elf",
147-
"coro.elf",
148-
"fcalc.elf",
149-
"hamilton.elf",
150-
"hello.elf",
151-
"ieee754.elf",
152-
"jit-bf.elf",
153-
"maj2random.elf",
154-
"mandelbrot.elf",
155-
"nqueens.elf",
156-
"nyancat.elf",
157-
"perfcount.elf",
158-
"qrcode.elf",
159-
"readelf.elf",
160-
"richards.elf",
161-
"rvsim.elf",
162-
"scimark2.elf",
163-
"spirograph.elf",
164-
"stream.elf",
165-
];
166-
167138
var runButton = document.getElementById("runButton");
168139
runButton.addEventListener("click", runButtonClickHandler);
169140

mk/wasm.mk

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
CFLAGS_emcc ?=
2-
deps_emcc :=
2+
deps_emcc := artifact
33
ASSETS := assets
44
WEB_HTML_RESOURCES := $(ASSETS)/html
55
WEB_JS_RESOURCES := $(ASSETS)/js
66
EXPORTED_FUNCS := _main,_indirect_rv_halt
7-
8-
ifeq ("$(CC_IS_EMCC)", "1")
7+
DEMO_DIR := demo
98
WEB_FILES := $(BIN).js \
109
$(BIN).wasm \
1110
$(BIN).worker.js
11+
12+
ifeq ("$(CC_IS_EMCC)", "1")
1213
BIN := $(BIN).js
1314

1415
# TCO
@@ -28,15 +29,19 @@ CFLAGS_emcc += -sINITIAL_MEMORY=2GB \
2829
-sSTACK_SIZE=4MB \
2930
-sPTHREAD_POOL_SIZE=navigator.hardwareConcurrency \
3031
--embed-file build@/ \
32+
--embed-file build/riscv32@/riscv32 \
3133
--embed-file build/timidity@/etc/timidity \
3234
-DMEM_SIZE=0x40000000 \
3335
-DCYCLE_PER_STEP=2000000 \
3436
--pre-js $(WEB_JS_RESOURCES)/pre.js \
3537
-O3 \
3638
-w
3739

40+
$(DEMO_DIR)/elf_list.js: tools/gen-elf-list-js.py
41+
$(Q)tools/gen-elf-list-js.py > $@
42+
3843
# used to download all dependencies of elf executable and bundle into single wasm
39-
deps_emcc += $(DOOM_DATA) $(QUAKE_DATA) $(TIMIDITY_DATA)
44+
deps_emcc += $(DEMO_DIR)/elf_list.js $(DOOM_DATA) $(QUAKE_DATA) $(TIMIDITY_DATA)
4045

4146
# check browser MAJOR version if supports TCO
4247
CHROME_MAJOR :=
@@ -77,7 +82,6 @@ else
7782
endif
7883

7984
# used to serve wasm locally
80-
DEMO_DIR := demo
8185
DEMO_IP := 127.0.0.1
8286
DEMO_PORT := 8000
8387

@@ -97,7 +101,7 @@ endef
97101
STATIC_WEB_FILES := $(WEB_HTML_RESOURCES)/index.html \
98102
$(WEB_JS_RESOURCES)/coi-serviceworker.min.js
99103

100-
start-web: $(BIN) check-demo-dir-exist
104+
start-web: check-demo-dir-exist $(BIN)
101105
$(foreach T, $(WEB_FILES), $(call cp-web-file, $(T)))
102106
$(foreach T, $(STATIC_WEB_FILES), $(call cp-web-file, $(T)))
103107
$(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)