Skip to content

Commit b0ef83c

Browse files
axicchfast
andcommitted
cmake: add the two patches from our wasm3 fork (extapi, portable)
Co-authored-by: Paweł Bylica <[email protected]>
1 parent 37e7482 commit b0ef83c

File tree

4 files changed

+119
-0
lines changed

4 files changed

+119
-0
lines changed

cmake/ProjectWasm3.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ ExternalProject_Add(wasm3
2020
BINARY_DIR ${binary_dir}
2121
URL https://github.com/wasm3/wasm3/archive/v0.4.7.tar.gz
2222
URL_HASH SHA256=11e863a643f605d62a5276e342abb01a65d33d138d01ea0070622a3f78fa1bd5
23+
PATCH_COMMAND ${CMAKE_CURRENT_LIST_DIR}/apply_patches.sh
2324
CMAKE_ARGS
2425
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
2526
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}

cmake/apply_patches.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env sh
2+
3+
patches_dir=$(dirname $0)
4+
5+
for patch_file in $patches_dir/*.patch; do
6+
echo $(basename $patch_file)
7+
8+
# Use git-apply to patch files.
9+
# The --git-dir forces the tool to work in "outside of git repo" mode.
10+
git --git-dir=. apply -v $patch_file
11+
exit_code=$?
12+
13+
# Exit code 1 is ignored as this happens when trying apply patches to already
14+
# patched source code.
15+
test $exit_code -le 1 || exit $exit_code
16+
done

cmake/wasm3_01_extapi.patch

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
diff --git a/source/m3_env.c b/source/m3_env.c
2+
index 40ccf9b..bad855f 100644
3+
--- a/source/m3_env.c
4+
+++ b/source/m3_env.c
5+
@@ -810,6 +810,58 @@ _ ((M3Result) Call (i_function->compiled, (m3stack_t) stack, runtime->memo
6+
_catch: return result;
7+
}
8+
9+
+M3Result m3_CallProper (IM3Function i_function, uint32_t i_argc, const uint64_t* i_argv, unsigned *o_hasRet, uint64_t* o_ret)
10+
+{
11+
+ M3Result result = m3Err_none;
12+
+
13+
+ if (i_function->compiled)
14+
+ {
15+
+ IM3Module module = i_function->module;
16+
+
17+
+ IM3Runtime runtime = module->runtime;
18+
+ // FIXME: support wasi?
19+
+
20+
+ IM3FuncType ftype = i_function->funcType;
21+
+
22+
+ if (i_argc != ftype->numArgs) {
23+
+ _throw("arguments count mismatch");
24+
+ }
25+
+
26+
+ // args are always 64-bit aligned
27+
+ u64 * stack = (u64 *) runtime->stack;
28+
+
29+
+ for (u32 i = 0; i < ftype->numArgs; ++i)
30+
+ {
31+
+ stack[i] = i_argv[i];
32+
+
33+
+ switch (ftype->argTypes[i]) {
34+
+ case c_m3Type_i32:
35+
+ case c_m3Type_f32:
36+
+ case c_m3Type_i64:
37+
+ case c_m3Type_f64: break;
38+
+ default: _throw("unknown argument type");
39+
+ }
40+
+ }
41+
+
42+
+ m3StackCheckInit();
43+
+_ ((M3Result) Call (i_function->compiled, (m3stack_t) stack, runtime->memory.mallocated, d_m3OpDefaultArgs));
44+
+
45+
+ *o_hasRet = 1;
46+
+ switch (ftype->returnType) {
47+
+ case c_m3Type_none: *o_hasRet = 0; break;
48+
+ case c_m3Type_i32: *o_ret = (uint64_t)(stack[0] & 0xffffffff); break;
49+
+ case c_m3Type_i64: *o_ret = (uint64_t)stack[0]; break;
50+
+ // FIXME: not sure what happens with f32
51+
+ case c_m3Type_f32: *o_ret = (uint64_t)(f32)stack[0]; break;
52+
+ case c_m3Type_f64: *o_ret = (uint64_t)stack[0]; break;
53+
+ default: _throw("unknown return type");
54+
+ }
55+
+ }
56+
+ else _throw (m3Err_missingCompiledCode);
57+
+
58+
+ _catch: return result;
59+
+}
60+
+
61+
#if 0
62+
M3Result m3_CallMain (IM3Function i_function, uint32_t i_argc, const char * const * i_argv)
63+
{
64+
diff --git a/source/wasm3.h b/source/wasm3.h
65+
index 0c2b7ef..ebba7f4 100644
66+
--- a/source/wasm3.h
67+
+++ b/source/wasm3.h
68+
@@ -217,6 +217,8 @@ d_m3ErrorConst (trapStackOverflow, "[trap] stack overflow")
69+
M3Result m3_Call (IM3Function i_function);
70+
M3Result m3_CallWithArgs (IM3Function i_function, uint32_t i_argc, const char * const * i_argv);
71+
72+
+ M3Result m3_CallProper (IM3Function i_function, uint32_t i_argc, const uint64_t* i_argv, unsigned *o_hasRet, uint64_t* o_ret);
73+
+
74+
// IM3Functions are valid during the lifetime of the originating runtime
75+
76+
void m3_GetErrorInfo (IM3Runtime i_runtime, M3ErrorInfo* info);

cmake/wasm3_02_portable.patch

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
diff --git a/CMakeLists.txt b/CMakeLists.txt
2+
index 1b263e5..aea4253 100755
3+
--- a/CMakeLists.txt
4+
+++ b/CMakeLists.txt
5+
@@ -1,5 +1,7 @@
6+
cmake_minimum_required(VERSION 3.11)
7+
8+
+set(BUILD_PORTABLE "Build without machine specific optimisations" OFF)
9+
+
10+
set(BUILD_WASI "uvwasi" CACHE STRING "WASI implementation")
11+
set_property(CACHE BUILD_WASI PROPERTY STRINGS none simple uvwasi metawasi)
12+
13+
@@ -149,7 +151,12 @@ else()
14+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=shadow")
15+
endif()
16+
17+
- set(CMAKE_C_FLAGS_RELEASE "-O3 -march=native -Wfatal-errors -fomit-frame-pointer -fno-stack-check -fno-stack-protector") #-fno-inline
18+
+ set(CMAKE_C_FLAGS_RELEASE "-O3 -Wfatal-errors -fomit-frame-pointer -fno-stack-check -fno-stack-protector") #-fno-inline
19+
+
20+
+ if(NOT BUILD_PORTABLE)
21+
+ set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -march=native")
22+
+ endif()
23+
+
24+
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "-O0")
25+
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "-O3")
26+

0 commit comments

Comments
 (0)