Skip to content

Bring wasm service up #487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 1 addition & 30 deletions assets/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -130,40 +130,11 @@
</div>
<textarea id="output" rows="8"></textarea>

<script src="elf_list.js"></script>
<script type='text/javascript'>
var statusElement = document.getElementById('status');
var progressElement = document.getElementById('progress');
var spinnerElement = document.getElementById('spinner');

var elfFiles = [
"doom.elf",
"smolnes.elf",
"quake.elf",
"coremark.elf",
"dhrystone.elf",
"pi.elf",
"donut.elf",
"aes.elf",
"coro.elf",
"fcalc.elf",
"hamilton.elf",
"hello.elf",
"ieee754.elf",
"jit-bf.elf",
"maj2random.elf",
"mandelbrot.elf",
"nqueens.elf",
"nyancat.elf",
"perfcount.elf",
"qrcode.elf",
"readelf.elf",
"richards.elf",
"rvsim.elf",
"scimark2.elf",
"spirograph.elf",
"stream.elf",
];

var runButton = document.getElementById("runButton");
runButton.addEventListener("click", runButtonClickHandler);

Expand Down
16 changes: 10 additions & 6 deletions mk/wasm.mk
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
CFLAGS_emcc ?=
deps_emcc :=
deps_emcc := artifact
ASSETS := assets
WEB_HTML_RESOURCES := $(ASSETS)/html
WEB_JS_RESOURCES := $(ASSETS)/js
EXPORTED_FUNCS := _main,_indirect_rv_halt

ifeq ("$(CC_IS_EMCC)", "1")
DEMO_DIR := demo
WEB_FILES := $(BIN).js \
$(BIN).wasm \
$(BIN).worker.js

ifeq ("$(CC_IS_EMCC)", "1")
BIN := $(BIN).js

# TCO
Expand All @@ -28,15 +29,19 @@ CFLAGS_emcc += -sINITIAL_MEMORY=2GB \
-sSTACK_SIZE=4MB \
-sPTHREAD_POOL_SIZE=navigator.hardwareConcurrency \
--embed-file build@/ \
--embed-file build/riscv32@/riscv32 \
--embed-file build/timidity@/etc/timidity \
-DMEM_SIZE=0x40000000 \
-DCYCLE_PER_STEP=2000000 \
--pre-js $(WEB_JS_RESOURCES)/pre.js \
-O3 \
-w

$(DEMO_DIR)/elf_list.js: tools/gen-elf-list-js.py
$(Q)tools/gen-elf-list-js.py > $@

# used to download all dependencies of elf executable and bundle into single wasm
deps_emcc += $(DOOM_DATA) $(QUAKE_DATA) $(TIMIDITY_DATA)
deps_emcc += $(DEMO_DIR)/elf_list.js $(DOOM_DATA) $(QUAKE_DATA) $(TIMIDITY_DATA)

# check browser MAJOR version if supports TCO
CHROME_MAJOR :=
Expand Down Expand Up @@ -77,7 +82,6 @@ else
endif

# used to serve wasm locally
DEMO_DIR := demo
DEMO_IP := 127.0.0.1
DEMO_PORT := 8000

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

start-web: $(BIN) check-demo-dir-exist
start-web: check-demo-dir-exist $(BIN)
$(foreach T, $(WEB_FILES), $(call cp-web-file, $(T)))
$(foreach T, $(STATIC_WEB_FILES), $(call cp-web-file, $(T)))
$(Q)python3 -m http.server --bind $(DEMO_IP) $(DEMO_PORT) --directory $(DEMO_DIR)
Expand Down
33 changes: 33 additions & 0 deletions tools/gen-elf-list-js.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python3

import os

def list_files(d):
try:
if d == "build":
files = [f for f in os.listdir(d) if (os.path.isfile(os.path.join(d, f)) and f.endswith('.elf'))]
else:
parent_dir = os.path.dirname(d)
files = [
os.path.relpath(os.path.join(d, f), start=parent_dir)
for f in os.listdir(d)
if os.path.isfile(os.path.join(d, f))
]
return files
except FileNotFoundError:
print(f"Directory {directory} not found.")
return []

elf_exec_dirs = ["build", "build/riscv32"]
elf_exec_list = []

for d in elf_exec_dirs:
files = list_files(d)
elf_exec_list.extend(files)
#print(elf_exec_list)

def gen_elf_list_js():
js_code = f"const elfFiles = {elf_exec_list};\n"
print(js_code)

gen_elf_list_js()
Loading