Skip to content

Commit 91d8213

Browse files
committed
small changes
Signed-off-by: Shaw Summa <[email protected]>
1 parent 0a8b8a6 commit 91d8213

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1600
-17994
lines changed

.clang-format

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
Language: Cpp
33
BasedOnStyle: Google
44
IndentWidth: 4
5-
ColumnLimit: 0
5+
ColumnLimit: 0

.gitignore

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,12 @@
1-
.DS_Store
2-
.vscode/*
3-
bin/*
4-
err.txt
5-
install
6-
miniwasm
7-
miniwasm.exe
8-
out.*
9-
test/bench/results.json
10-
test/core/*
11-
test/*.wasm
12-
*.core
13-
*.exe
14-
*.exp
15-
*.gcda
16-
*.ilk
17-
*.lib
18-
*.o
19-
*.pdb
20-
*.tmp
21-
*.wasm
22-
*.wat
23-
*.profdata
24-
spec
1+
*
2+
!test
3+
!src
4+
!res
5+
!.github
6+
!.clang-format
7+
!.gitignore
8+
!bench.py
9+
!LICENSE
10+
!makefile
11+
!README.md
12+
!results.txt

bench.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
emccflags = ['-msimd128']
3434
emccflags = []
3535
if len(engines) == 0:
36-
engines = ['wasm3', os.path.join(cur, 'bin/miniwasm')]
36+
engines = ['wasm3', os.path.join(cur, 'build/opt/bin/miniwasm')]
3737
engines.extend(['wasmer', 'wasmtime'])
3838

3939
if len(args.test) == 0:

main/miniwasm.c

Lines changed: 135 additions & 129 deletions
Large diffs are not rendered by default.

main/wasm2wasm.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include "../src/ast.h"
2-
#include "../src/interp/interp.h"
32
#include "../src/read_bin.h"
43
#include "../src/write_bin.h"
54

main/wat2wasm.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include "../src/ast.h"
2-
#include "../src/interp/interp.h"
32
#include "../src/read_wat.h"
43
#include "../src/write_bin.h"
54

makefile

Lines changed: 48 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,89 @@
11

2-
PYTHON ?= python3
3-
OPT ?= -O2
2+
MODE ?= opt
43

5-
INSTALL ?= install
4+
BUILD_DIR = ./build/$(MODE)/
5+
BIN_DIR = $(BUILD_DIR)bin/
6+
OBJ_DIR = $(BUILD_DIR)obj/
7+
TEST_DIR = $(BUILD_DIR)test/
68

7-
EMCC ?= emcc
9+
PYTHON ?= python3
810

911
PROG_SRCS := main/wat2wat.c main/wasm2wat.c main/wat2wasm.c main/wasm2wasm.c main/miniwasm.c main/raywasm.c main/runtime/rlruntime.c
10-
PROG_OBJS := $(PROG_SRCS:%.c=%.o)
12+
PROG_OBJS := $(PROG_SRCS:%.c=$(OBJ_DIR)%.o)
1113

12-
WEB49_SRCS := src/lib.c src/read_bin.c src/read_wat.c src/write_wat.c src/write_bin.c src/io.c src/tables.c src/interp/interp.c src/opt/tree.c src/opt/tee.c src/ast.c src/api/wasi.c
13-
WEB49_OBJS := $(WEB49_SRCS:%.c=%.o)
14+
WEB49_SRCS := src/lib.c src/read_bin.c src/read_wat.c src/write_wat.c src/write_bin.c src/io.c src/tables.c src/interp/interp.c src/opt/tree.c src/opt/tee.c src/ast.c src/wasi/wasi.c
15+
WEB49_OBJS := $(WEB49_SRCS:%.c=$(OBJ_DIR)%.o)
1416

1517
OBJS := $(WEB49_OBJS)
1618

17-
UNAME_S_CMD != uname -s
18-
19-
UNAME_S ?= $(UNAME_S_CMD)
20-
21-
RGLFW_M_OR_C_Windows = c
22-
RGLFW_M_OR_C_FreeBSD = c
23-
RGLFW_M_OR_C_Linux = c
24-
RGLFW_M_OR_C_Darwin = m
25-
2619
TEST_PREFIX = test/core
2720

2821
TEST_FILES != find $(TEST_PREFIX) -name '*.wast'
2922
TEST_OUTPUTS = $(TEST_FILES:%.wast=%.txt)
3023

31-
default: all
24+
# modes
25+
FLAGS_san = -g3 -ggdb -fsanitize=address,undefined
26+
FLAGS_debug = -g3 -ggdb
3227

33-
all: bins
28+
CLAGS_opt = -O3
29+
LDFLAGS_opt = -flto
3430

35-
# install web49
31+
CFLAGS += $(CFLAGS_$(MODE)) $(FLAGS_$(MODE))
32+
LDFLAGS += $(LDFLAGS_$(MODE)) $(FLAGS_$(MODE))
3633

37-
install: bins
38-
cp bin/miniwasm $(INSTALL)
39-
chmod $(INSTALL)/miniwasm
34+
default: all
4035

41-
# tests
36+
all: bins test
4237

43-
test: results.txt
38+
# tests
4439

45-
results.txt: $(TEST_OUTPUTS)
46-
@cat /dev/null $(TEST_OUTPUTS) | sort > results.txt
40+
TESTS != find test -type f -name '*.wast'
41+
TEST_LOGS = $(TESTS:%.wast=$(TEST_DIR)log/%.log)
42+
TEST_RESULT = $(TEST_DIR)result
4743

48-
$(TEST_OUTPUTS): bin/miniwasm $(@:%.txt=%.wast) | $(TEST_PREFIX)
49-
@./bin/miniwasm $(@:%.txt=%.wast) 2>$(@:%.txt=%.log); \
50-
if test $$? -eq 0; \
51-
then mv $(@:%.txt=%.log) $(@:%.txt=%.pass.log) && echo "PASS $(@:$(TEST_PREFIX)/%.txt=%)" > $(@); \
52-
else mv $(@:%.txt=%.log) $(@:%.txt=%.fail.log) && echo "FAIL $(@:$(TEST_PREFIX)/%.txt=%)" > $(@); \
53-
fi
44+
test: $(TEST_RESULT)
5445

55-
# test/wasi:
56-
# test -d wasi-testsuite || git clone https://github.com/WebAssembly/wasi-testsuite spec --depth 1
57-
# rm -fr test/wasi
46+
$(TEST_RESULT): $(TEST_LOGS)
47+
@echo -n > $(TEST_RESULT).pass
48+
@echo -n > $(TEST_RESULT).fail
49+
@sort -u $(TEST_RESULT).pass -o $(TEST_RESULT).pass
50+
@sort -u $(TEST_RESULT).fail -o $(TEST_RESULT).fail
51+
@cat $(TEST_RESULT).pass > $(TEST_RESULT)
52+
@echo >> $(TEST_RESULT)
53+
@cat $(TEST_RESULT).fail >> $(TEST_RESULT)
54+
@rm $(TEST_RESULT).pass $(TEST_RESULT).fail
5855

59-
test/core:
60-
test -d spec || git clone https://github.com/WebAssembly/spec/ spec --depth 1
61-
rm -fr test/core
62-
cp -r spec/test/core test/core
63-
rm -r test/core/simd/meta
56+
$(TEST_DIR)log/%.log: %.wast $(BIN_DIR)miniwasm
57+
@mkdir -p $(dir $(@))
58+
@echo $(BIN_DIR)miniwasm $(<); if $(BIN_DIR)miniwasm $(<) 2>$(@); then echo pass $(<) >> $(TEST_RESULT).pass; else echo fail $(<) >> $(TEST_RESULT).fail; fi
6459

6560
# bin
6661

67-
bins: bin/wasm2wat bin/wat2wasm bin/wasm2wasm bin/wat2wat bin/miniwasm
68-
69-
bin/miniwasm: main/miniwasm.o $(OBJS)
70-
@mkdir -p bin
71-
$(CC) $(OPT) main/miniwasm.o $(OBJS) -o $(@) -lm $(LDFLAGS)
62+
MAINS != find main -type f -name '*.c'
63+
MAIN_BINS = $(MAINS:main/%.c=$(BIN_DIR)%)
7264

73-
bin/wat2wasm: main/wat2wasm.o $(OBJS)
74-
@mkdir -p bin
75-
$(CC) $(OPT) main/wat2wasm.o $(OBJS) -o $(@) -lm $(LDFLAGS)
65+
bins: $(MAIN_BINS)
7666

77-
bin/wasm2wat: main/wasm2wat.o $(OBJS)
78-
@mkdir -p bin
79-
$(CC) $(OPT) main/wasm2wat.o $(OBJS) -o $(@) -lm $(LDFLAGS)
67+
$(BIN_DIR)%: $(OBJ_DIR)main/%.o $(OBJS)
68+
@mkdir -p $(dir $(@))
69+
$(CC) $(^) -o $(@) -lm $(LDFLAGS)
8070

81-
bin/wasm2wasm: main/wasm2wasm.o $(OBJS)
82-
@mkdir -p bin
83-
$(CC) $(OPT) main/wasm2wasm.o $(OBJS) -o $(@) -lm $(LDFLAGS)
71+
# intermediate files
8472

85-
bin/wat2wat: main/wat2wat.o $(OBJS)
86-
@mkdir -p bin
87-
$(CC) $(OPT) main/wat2wat.o $(OBJS) -o $(@) -lm $(LDFLAGS)
73+
$(OBJ_DIR)%.o: %.c
74+
@mkdir -p $(dir $(@))
75+
$(CC) -c $(OPT) $(<) -o $(@) $(CFLAGS)
8876

8977
# util
9078

79+
.PHONY: format
9180
format: .dummy
9281
find src main -name '*.c' | xargs -I FILENAME clang-format -style=file -i FILENAME
9382
find src main -name '*.h' | xargs -I FILENAME clang-format -style=file -i FILENAME
9483
find src main -name '*.inc' | xargs -I FILENAME clang-format -style=file -i FILENAME
9584

85+
.PHONY: clean
9686
clean: .dummy
97-
find src main -name '*.o' | xargs rm
98-
find bin -type f | xargs rm
99-
find test/core -name '*.txt' | xargs rm
100-
find test/core -name '*.log' | xargs rm
101-
102-
# intermediate files
103-
104-
$(PROG_OBJS) $(WEB49_OBJS): $(@:%.o=%.c)
105-
$(CC) -c $(OPT) $(@:%.o=%.c) -o $(@) $(CFLAGS)
106-
107-
# dummy
87+
rm -rf build
10888

10989
.dummy:

results.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ FAIL custom
99
FAIL data
1010
FAIL elem
1111
FAIL exports
12+
FAIL f64_cmp
1213
FAIL float_exprs
1314
FAIL float_literals
1415
FAIL float_memory
@@ -90,14 +91,14 @@ FAIL simd/simd_store8_lane
9091
FAIL stack
9192
FAIL start
9293
FAIL table
93-
FAIL table-sub
9494
FAIL table_copy
9595
FAIL table_fill
9696
FAIL table_get
9797
FAIL table_grow
9898
FAIL table_init
9999
FAIL table_set
100100
FAIL table_size
101+
FAIL table-sub
101102
FAIL token
102103
FAIL tokens
103104
FAIL unreached-invalid
@@ -118,7 +119,6 @@ PASS f32_bitwise
118119
PASS f32_cmp
119120
PASS f64
120121
PASS f64_bitwise
121-
PASS f64_cmp
122122
PASS fac
123123
PASS float_misc
124124
PASS forward

src/ast.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ void web49_free_module(web49_module_t mod) {
1717
web49_section_t section = mod.sections[i];
1818
switch (section.header.id) {
1919
case WEB49_SECTION_ID_CUSTOM: {
20-
web49_section_custom_t cur = section.custom_section;
20+
web49_section_custom_t cur = section.section.custom;
2121
web49_free(cur.name);
2222
web49_free(cur.payload);
2323
break;
2424
}
2525
case WEB49_SECTION_ID_TYPE: {
26-
web49_section_type_t cur = section.type_section;
26+
web49_section_type_t cur = section.section.type;
2727
for (size_t j = 0; j < cur.num_entries; j++) {
2828
web49_section_type_entry_t ent = cur.entries[j];
2929
web49_free(ent.params);
@@ -33,7 +33,7 @@ void web49_free_module(web49_module_t mod) {
3333
break;
3434
}
3535
case WEB49_SECTION_ID_IMPORT: {
36-
web49_section_import_t cur = section.import_section;
36+
web49_section_import_t cur = section.section.import;
3737
for (size_t j = 0; j < cur.num_entries; j++) {
3838
web49_section_import_entry_t ent = cur.entries[j];
3939
web49_free(ent.module_str);
@@ -43,22 +43,22 @@ void web49_free_module(web49_module_t mod) {
4343
break;
4444
}
4545
case WEB49_SECTION_ID_FUNCTION: {
46-
web49_section_function_t cur = section.function_section;
46+
web49_section_function_t cur = section.section.function;
4747
web49_free(cur.entries);
4848
break;
4949
}
5050
case WEB49_SECTION_ID_TABLE: {
51-
web49_section_table_t cur = section.table_section;
51+
web49_section_table_t cur = section.section.table;
5252
web49_free(cur.entries);
5353
break;
5454
}
5555
case WEB49_SECTION_ID_MEMORY: {
56-
web49_section_memory_t cur = section.memory_section;
56+
web49_section_memory_t cur = section.section.memory;
5757
web49_free(cur.entries);
5858
break;
5959
}
6060
case WEB49_SECTION_ID_GLOBAL: {
61-
web49_section_global_t cur = section.global_section;
61+
web49_section_global_t cur = section.section.global;
6262
for (size_t j = 0; j < cur.num_entries; j++) {
6363
web49_section_global_entry_t ent = cur.entries[j];
6464
web49_free_instr(ent.init_expr);
@@ -67,7 +67,7 @@ void web49_free_module(web49_module_t mod) {
6767
break;
6868
}
6969
case WEB49_SECTION_ID_EXPORT: {
70-
web49_section_export_t cur = section.export_section;
70+
web49_section_export_t cur = section.section.export;
7171
for (size_t j = 0; j < cur.num_entries; j++) {
7272
web49_section_export_entry_t ent = cur.entries[j];
7373
web49_free(ent.field_str);
@@ -79,7 +79,7 @@ void web49_free_module(web49_module_t mod) {
7979
break;
8080
}
8181
case WEB49_SECTION_ID_ELEMENT: {
82-
web49_section_element_t cur = section.element_section;
82+
web49_section_element_t cur = section.section.element;
8383
for (size_t j = 0; j < cur.num_entries; j++) {
8484
web49_section_element_entry_t ent = cur.entries[j];
8585
web49_free(ent.elems);
@@ -88,7 +88,7 @@ void web49_free_module(web49_module_t mod) {
8888
break;
8989
}
9090
case WEB49_SECTION_ID_CODE: {
91-
web49_section_code_t cur = section.code_section;
91+
web49_section_code_t cur = section.section.code;
9292
for (size_t j = 0; j < cur.num_entries; j++) {
9393
web49_section_code_entry_t ent = cur.entries[j];
9494
for (size_t k = 0; k < ent.num_instrs; k++) {
@@ -101,7 +101,7 @@ void web49_free_module(web49_module_t mod) {
101101
break;
102102
}
103103
case WEB49_SECTION_ID_DATA: {
104-
web49_section_data_t cur = section.data_section;
104+
web49_section_data_t cur = section.section.data;
105105
for (size_t j = 0; j < cur.num_entries; j++) {
106106
web49_free(cur.entries[j].data);
107107
}
@@ -204,7 +204,7 @@ web49_section_t web49_module_get_section(web49_module_t mod, web49_section_id_t
204204
uint32_t web49_module_num_func_imports(web49_module_t mod) {
205205
for (size_t i = 0; i < mod.num_sections; i++) {
206206
if (mod.sections[i].header.id == WEB49_SECTION_ID_IMPORT) {
207-
web49_section_import_t *pimport = &mod.sections[i].import_section;
207+
web49_section_import_t *pimport = &mod.sections[i].section.import;
208208
if (pimport->num_func_imports == 0) {
209209
pimport->num_func_imports = 1;
210210
for (size_t j = 0; j < pimport->num_entries; j++) {

0 commit comments

Comments
 (0)