summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt8
-rw-r--r--include/wabt/c-writer.h3
-rw-r--r--src/c-writer.cc11
-rw-r--r--src/prebuilt/wasm2c_header_top.cc7
-rw-r--r--src/template/wasm2c.top.h4
-rw-r--r--src/tools/wasm2c.cc5
-rwxr-xr-xtest/run-spec-wasm2c.py8
-rw-r--r--test/spec-wasm2c-prefix.c1
-rw-r--r--test/wasm2c/add.txt6
-rw-r--r--test/wasm2c/check-imports.txt6
-rw-r--r--test/wasm2c/export-names.txt6
-rw-r--r--test/wasm2c/hello.txt6
-rw-r--r--test/wasm2c/minimal.txt6
-rw-r--r--wasm2c/README.md7
-rw-r--r--wasm2c/examples/callback/Makefile2
-rw-r--r--wasm2c/examples/fac/Makefile2
-rw-r--r--wasm2c/examples/fac/fac.c6
-rw-r--r--wasm2c/examples/fac/fac.h4
-rw-r--r--wasm2c/examples/rot13/Makefile2
-rw-r--r--wasm2c/wasm-rt-exceptions-impl.c68
-rw-r--r--wasm2c/wasm-rt-exceptions.h69
-rw-r--r--wasm2c/wasm-rt-impl.c53
-rw-r--r--wasm2c/wasm-rt-impl.h13
-rw-r--r--wasm2c/wasm-rt.h86
24 files changed, 249 insertions, 140 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a8dd9452..b9531a01 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -415,7 +415,9 @@ if (WABT_INSTALL_RULES)
)
endif ()
-add_library(wasm-rt-impl STATIC wasm2c/wasm-rt-impl.c wasm2c/wasm-rt-impl.h)
+set(WASM_RT_FILES "wasm2c/wasm-rt-impl.h" "wasm2c/wasm-rt-impl.c" "wasm2c/wasm-rt-exceptions-impl.c")
+
+add_library(wasm-rt-impl STATIC ${WASM_RT_FILES})
add_library(wabt::wasm-rt-impl ALIAS wasm-rt-impl)
if (WABT_BIG_ENDIAN)
target_compile_definitions(wasm-rt-impl PUBLIC WABT_BIG_ENDIAN=1)
@@ -429,12 +431,12 @@ if (WABT_INSTALL_RULES)
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
install(
- FILES "wasm2c/wasm-rt.h"
+ FILES "wasm2c/wasm-rt.h" "wasm2c/wasm-rt-exceptions.h"
TYPE INCLUDE
COMPONENT wabt-development
)
install(
- FILES "wasm2c/wasm-rt-impl.h" "wasm2c/wasm-rt-impl.c"
+ FILES ${WASM_RT_FILES}
DESTINATION "${CMAKE_INSTALL_DATADIR}/wabt/wasm2c"
COMPONENT wabt-development
)
diff --git a/include/wabt/c-writer.h b/include/wabt/c-writer.h
index a1731a7f..7d9ff6ad 100644
--- a/include/wabt/c-writer.h
+++ b/include/wabt/c-writer.h
@@ -19,6 +19,7 @@
#include <functional>
#include "wabt/common.h"
+#include "wabt/feature.h"
#include "wabt/ir.h"
namespace wabt {
@@ -28,6 +29,8 @@ class Stream;
struct WriteCOptions {
std::string_view module_name;
+ /* Set of wasm features enabled for wasm2c */
+ Features* features;
/*
* name_to_output_file_index takes const iterators to begin and end of a list
* of all functions in the module, number of imported functions, and number of
diff --git a/src/c-writer.cc b/src/c-writer.cc
index 994f6111..798f85f9 100644
--- a/src/c-writer.cc
+++ b/src/c-writer.cc
@@ -368,6 +368,7 @@ class CWriter {
const std::string&);
void WriteCallIndirectFuncDeclaration(const FuncDeclaration&,
const std::string&);
+ void WriteFeatureMacros();
void WriteModuleInstance();
void WriteGlobals();
void WriteGlobal(const Global&, const std::string&);
@@ -1789,6 +1790,15 @@ void CWriter::WriteCallIndirectFuncDeclaration(const FuncDeclaration& decl,
Write(")");
}
+void CWriter::WriteFeatureMacros() {
+ if (options_.features->exceptions_enabled()) {
+ Write("#define WASM_RT_ENABLE_EXCEPTION_HANDLING", Newline(), Newline());
+ }
+ if (options_.features->simd_enabled()) {
+ Write("#define WASM_RT_ENABLE_SIMD", Newline(), Newline());
+ }
+}
+
void CWriter::WriteModuleInstance() {
BeginInstance();
WriteGlobals();
@@ -5122,6 +5132,7 @@ void CWriter::WriteCHeader() {
Write("#ifndef ", guard, Newline());
Write("#define ", guard, Newline());
Write(Newline());
+ WriteFeatureMacros();
Write(s_header_top);
Write(Newline());
WriteModuleInstance();
diff --git a/src/prebuilt/wasm2c_header_top.cc b/src/prebuilt/wasm2c_header_top.cc
index daf1eecf..d36aaf0c 100644
--- a/src/prebuilt/wasm2c_header_top.cc
+++ b/src/prebuilt/wasm2c_header_top.cc
@@ -4,6 +4,13 @@ R"w2c_template(
#include "wasm-rt.h"
)w2c_template"
R"w2c_template(
+#if defined(WASM_RT_ENABLE_EXCEPTION_HANDLING)
+)w2c_template"
+R"w2c_template(#include "wasm-rt-exceptions.h"
+)w2c_template"
+R"w2c_template(#endif
+)w2c_template"
+R"w2c_template(
#if defined(WASM_RT_ENABLE_SIMD)
)w2c_template"
R"w2c_template(#include "simde/wasm/simd128.h"
diff --git a/src/template/wasm2c.top.h b/src/template/wasm2c.top.h
index 4f4141b8..2610a956 100644
--- a/src/template/wasm2c.top.h
+++ b/src/template/wasm2c.top.h
@@ -2,6 +2,10 @@
#include "wasm-rt.h"
+#if defined(WASM_RT_ENABLE_EXCEPTION_HANDLING)
+#include "wasm-rt-exceptions.h"
+#endif
+
#if defined(WASM_RT_ENABLE_SIMD)
#include "simde/wasm/simd128.h"
#endif
diff --git a/src/tools/wasm2c.cc b/src/tools/wasm2c.cc
index 4f2ce452..83e5114a 100644
--- a/src/tools/wasm2c.cc
+++ b/src/tools/wasm2c.cc
@@ -60,7 +60,7 @@ examples:
static const std::string supported_features[] = {
"multi-memory", "multi-value", "sign-extension", "saturating-float-to-int",
- "exceptions", "memory64", "extended-const"};
+ "exceptions", "memory64", "extended-const", "simd"};
static bool IsFeatureSupported(const std::string& feature) {
return std::find(std::begin(supported_features), std::end(supported_features),
@@ -100,12 +100,13 @@ static void ParseOptions(int argc, char** argv) {
ConvertBackslashToSlash(&s_infile);
});
parser.Parse(argc, argv);
+ s_write_c_options.features = &s_features;
bool any_non_supported_feature = false;
#define WABT_FEATURE(variable, flag, default_, help) \
any_non_supported_feature |= \
(s_features.variable##_enabled() != default_) && \
- !IsFeatureSupported(flag);
+ s_features.variable##_enabled() && !IsFeatureSupported(flag);
#include "wabt/feature.def"
#undef WABT_FEATURE
diff --git a/test/run-spec-wasm2c.py b/test/run-spec-wasm2c.py
index 7bb73b43..d604f653 100755
--- a/test/run-spec-wasm2c.py
+++ b/test/run-spec-wasm2c.py
@@ -452,15 +452,13 @@ def Compile(cc, c_filename, out_dir, *cflags):
o_filename = utils.ChangeDir(utils.ChangeExt(c_filename, ext), out_dir)
args = list(cflags)
if IS_WINDOWS:
- args += ['/nologo', '/DWASM_RT_ENABLE_SIMD',
- '/MDd', '/c', c_filename, '/Fo' + o_filename]
+ args += ['/nologo', '/MDd', '/c', c_filename, '/Fo' + o_filename]
else:
# See "Compiling the wasm2c output" section of wasm2c/README.md
# When compiling with -O2, GCC and clang require '-fno-optimize-sibling-calls'
# and '-frounding-math' to maintain conformance with the spec tests
# (GCC also requires '-fsignaling-nans')
args += ['-c', c_filename, '-o', o_filename, '-O2',
- '-DWASM_RT_ENABLE_SIMD',
'-Wall', '-Werror', '-Wno-unused',
'-Wno-ignored-optimization-argument',
'-Wno-tautological-constant-out-of-range-compare',
@@ -622,6 +620,10 @@ def main(args):
wasm_rt_impl_c = os.path.join(options.wasmrt_dir, 'wasm-rt-impl.c')
o_filenames.append(Compile(cc, wasm_rt_impl_c, out_dir, *cflags))
+ # Compile wasm-rt-exceptions.
+ wasm_rt_exceptions_c = os.path.join(options.wasmrt_dir, 'wasm-rt-exceptions-impl.c')
+ o_filenames.append(Compile(cc, wasm_rt_exceptions_c, out_dir, *cflags))
+
# Compile and link -main test run entry point
o_filenames.append(Compile(cc, main_filename, out_dir, *cflags))
if IS_WINDOWS:
diff --git a/test/spec-wasm2c-prefix.c b/test/spec-wasm2c-prefix.c
index c82a882d..b2f5d103 100644
--- a/test/spec-wasm2c-prefix.c
+++ b/test/spec-wasm2c-prefix.c
@@ -11,6 +11,7 @@
#include "wasm-rt.h"
#include "wasm-rt-impl.h"
+#include "wasm-rt-exceptions.h"
static int g_tests_run;
static int g_tests_passed;
diff --git a/test/wasm2c/add.txt b/test/wasm2c/add.txt
index e84befab..a5a7197d 100644
--- a/test/wasm2c/add.txt
+++ b/test/wasm2c/add.txt
@@ -8,10 +8,16 @@
#ifndef WASM_H_GENERATED_
#define WASM_H_GENERATED_
+#define WASM_RT_ENABLE_SIMD
+
#include <stdint.h>
#include "wasm-rt.h"
+#if defined(WASM_RT_ENABLE_EXCEPTION_HANDLING)
+#include "wasm-rt-exceptions.h"
+#endif
+
#if defined(WASM_RT_ENABLE_SIMD)
#include "simde/wasm/simd128.h"
#endif
diff --git a/test/wasm2c/check-imports.txt b/test/wasm2c/check-imports.txt
index cdfca122..73f59b22 100644
--- a/test/wasm2c/check-imports.txt
+++ b/test/wasm2c/check-imports.txt
@@ -21,10 +21,16 @@
#ifndef WASM_H_GENERATED_
#define WASM_H_GENERATED_
+#define WASM_RT_ENABLE_SIMD
+
#include <stdint.h>
#include "wasm-rt.h"
+#if defined(WASM_RT_ENABLE_EXCEPTION_HANDLING)
+#include "wasm-rt-exceptions.h"
+#endif
+
#if defined(WASM_RT_ENABLE_SIMD)
#include "simde/wasm/simd128.h"
#endif
diff --git a/test/wasm2c/export-names.txt b/test/wasm2c/export-names.txt
index e24984b3..09cae5b1 100644
--- a/test/wasm2c/export-names.txt
+++ b/test/wasm2c/export-names.txt
@@ -11,10 +11,16 @@
#ifndef WASM_H_GENERATED_
#define WASM_H_GENERATED_
+#define WASM_RT_ENABLE_SIMD
+
#include <stdint.h>
#include "wasm-rt.h"
+#if defined(WASM_RT_ENABLE_EXCEPTION_HANDLING)
+#include "wasm-rt-exceptions.h"
+#endif
+
#if defined(WASM_RT_ENABLE_SIMD)
#include "simde/wasm/simd128.h"
#endif
diff --git a/test/wasm2c/hello.txt b/test/wasm2c/hello.txt
index 418916ca..ea3bf426 100644
--- a/test/wasm2c/hello.txt
+++ b/test/wasm2c/hello.txt
@@ -26,10 +26,16 @@
#ifndef WASM_H_GENERATED_
#define WASM_H_GENERATED_
+#define WASM_RT_ENABLE_SIMD
+
#include <stdint.h>
#include "wasm-rt.h"
+#if defined(WASM_RT_ENABLE_EXCEPTION_HANDLING)
+#include "wasm-rt-exceptions.h"
+#endif
+
#if defined(WASM_RT_ENABLE_SIMD)
#include "simde/wasm/simd128.h"
#endif
diff --git a/test/wasm2c/minimal.txt b/test/wasm2c/minimal.txt
index d4efc0d5..669b3d8e 100644
--- a/test/wasm2c/minimal.txt
+++ b/test/wasm2c/minimal.txt
@@ -5,10 +5,16 @@
#ifndef WASM_H_GENERATED_
#define WASM_H_GENERATED_
+#define WASM_RT_ENABLE_SIMD
+
#include <stdint.h>
#include "wasm-rt.h"
+#if defined(WASM_RT_ENABLE_EXCEPTION_HANDLING)
+#include "wasm-rt-exceptions.h"
+#endif
+
#if defined(WASM_RT_ENABLE_SIMD)
#include "simde/wasm/simd128.h"
#endif
diff --git a/wasm2c/README.md b/wasm2c/README.md
index 68fdb11a..5271e892 100644
--- a/wasm2c/README.md
+++ b/wasm2c/README.md
@@ -341,8 +341,9 @@ exhaustion.
### Runtime support for exception handling
-Several additional symbols must be defined if wasm2c is being run with
-support for exceptions (`--enable-exceptions`):
+Several additional symbols must be defined if wasm2c is being run with support
+for exceptions (`--enable-exceptions`). These are defined in
+`wasm-rt-exceptions.h`. These symbols are:
```c
void wasm_rt_load_exception(const char* tag, uint32_t size, const void* values);
@@ -357,7 +358,7 @@ wasm_rt_try(target)
```
A C implementation of these functions is also available in
-[`wasm-rt-impl.h`](wasm-rt-impl.h) and [`wasm-rt-impl.c`](wasm-rt-impl.c).
+[`wasm-rt-exceptions-impl.c`](wasm-rt-exceptions-impl.c).
`wasm_rt_load_exception` sets the active exception to a given tag, size, and contents.
diff --git a/wasm2c/examples/callback/Makefile b/wasm2c/examples/callback/Makefile
index c226ff31..ece54c34 100644
--- a/wasm2c/examples/callback/Makefile
+++ b/wasm2c/examples/callback/Makefile
@@ -14,6 +14,6 @@ callback.wasm: callback.wat ../../../bin/wat2wasm
../../../bin/wat2wasm --debug-names $< -o $@
callback.c: callback.wasm ../../../bin/wasm2c
- ../../../bin/wasm2c $< -o $@
+ ../../../bin/wasm2c $< -o $@ --disable-simd
.PHONY: all clean
diff --git a/wasm2c/examples/fac/Makefile b/wasm2c/examples/fac/Makefile
index a5179a71..623fcfc3 100644
--- a/wasm2c/examples/fac/Makefile
+++ b/wasm2c/examples/fac/Makefile
@@ -12,6 +12,6 @@ fac.wasm: fac.wat ../../../bin/wat2wasm
../../../bin/wat2wasm $< -o $@
fac.c: fac.wasm ../../../bin/wasm2c
- ../../../bin/wasm2c $< -o $@
+ ../../../bin/wasm2c $< -o $@ --disable-simd
.PHONY: all clean
diff --git a/wasm2c/examples/fac/fac.c b/wasm2c/examples/fac/fac.c
index 970abbe1..683c5d80 100644
--- a/wasm2c/examples/fac/fac.c
+++ b/wasm2c/examples/fac/fac.c
@@ -4,10 +4,14 @@
#include <stdarg.h>
#include <stddef.h>
#include <string.h>
-#if defined(_MSC_VER)
+#if defined(__MINGW32__)
+#include <malloc.h>
+#elif defined(_MSC_VER)
#include <intrin.h>
#include <malloc.h>
#define alloca _alloca
+#elif defined(__FreeBSD__) || defined(__OpenBSD__)
+#include <stdlib.h>
#else
#include <alloca.h>
#endif
diff --git a/wasm2c/examples/fac/fac.h b/wasm2c/examples/fac/fac.h
index 5450fe42..f85dc5a9 100644
--- a/wasm2c/examples/fac/fac.h
+++ b/wasm2c/examples/fac/fac.h
@@ -6,6 +6,10 @@
#include "wasm-rt.h"
+#if defined(WASM_RT_ENABLE_EXCEPTION_HANDLING)
+#include "wasm-rt-exceptions.h"
+#endif
+
#if defined(WASM_RT_ENABLE_SIMD)
#include "simde/wasm/simd128.h"
#endif
diff --git a/wasm2c/examples/rot13/Makefile b/wasm2c/examples/rot13/Makefile
index b957c19f..4461af7c 100644
--- a/wasm2c/examples/rot13/Makefile
+++ b/wasm2c/examples/rot13/Makefile
@@ -14,6 +14,6 @@ rot13.wasm: rot13.wat ../../../bin/wat2wasm
../../../bin/wat2wasm $< -o $@
rot13.c: rot13.wasm ../../../bin/wasm2c
- ../../../bin/wasm2c $< -o $@
+ ../../../bin/wasm2c $< -o $@ --disable-simd
.PHONY: all clean
diff --git a/wasm2c/wasm-rt-exceptions-impl.c b/wasm2c/wasm-rt-exceptions-impl.c
new file mode 100644
index 00000000..8eee492e
--- /dev/null
+++ b/wasm2c/wasm-rt-exceptions-impl.c
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2018 WebAssembly Community Group participants
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "wasm-rt.h"
+
+#include "wasm-rt-exceptions.h"
+
+#include <string.h>
+
+#define MAX_EXCEPTION_SIZE 256
+
+static WASM_RT_THREAD_LOCAL wasm_rt_tag_t g_active_exception_tag;
+static WASM_RT_THREAD_LOCAL uint8_t g_active_exception[MAX_EXCEPTION_SIZE];
+static WASM_RT_THREAD_LOCAL uint32_t g_active_exception_size;
+
+static WASM_RT_THREAD_LOCAL wasm_rt_jmp_buf* g_unwind_target;
+
+void wasm_rt_load_exception(const wasm_rt_tag_t tag,
+ uint32_t size,
+ const void* values) {
+ if (size > MAX_EXCEPTION_SIZE) {
+ wasm_rt_trap(WASM_RT_TRAP_EXHAUSTION);
+ }
+
+ g_active_exception_tag = tag;
+ g_active_exception_size = size;
+
+ if (size) {
+ memcpy(g_active_exception, values, size);
+ }
+}
+
+WASM_RT_NO_RETURN void wasm_rt_throw(void) {
+ WASM_RT_LONGJMP(*g_unwind_target, WASM_RT_TRAP_UNCAUGHT_EXCEPTION);
+}
+
+WASM_RT_UNWIND_TARGET* wasm_rt_get_unwind_target(void) {
+ return g_unwind_target;
+}
+
+void wasm_rt_set_unwind_target(WASM_RT_UNWIND_TARGET* target) {
+ g_unwind_target = target;
+}
+
+wasm_rt_tag_t wasm_rt_exception_tag(void) {
+ return g_active_exception_tag;
+}
+
+uint32_t wasm_rt_exception_size(void) {
+ return g_active_exception_size;
+}
+
+void* wasm_rt_exception(void) {
+ return g_active_exception;
+}
diff --git a/wasm2c/wasm-rt-exceptions.h b/wasm2c/wasm-rt-exceptions.h
new file mode 100644
index 00000000..7ccba2f7
--- /dev/null
+++ b/wasm2c/wasm-rt-exceptions.h
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2018 WebAssembly Community Group participants
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef WASM_RT_EXCEPTIONS_H_
+#define WASM_RT_EXCEPTIONS_H_
+
+#include "wasm-rt.h"
+
+/**
+ * A tag is represented as an arbitrary pointer.
+ */
+typedef const void* wasm_rt_tag_t;
+
+/**
+ * Set the active exception to given tag, size, and contents.
+ */
+void wasm_rt_load_exception(const wasm_rt_tag_t tag,
+ uint32_t size,
+ const void* values);
+
+/**
+ * Throw the active exception.
+ */
+WASM_RT_NO_RETURN void wasm_rt_throw(void);
+
+/**
+ * The type of an unwind target if an exception is thrown and caught.
+ */
+#define WASM_RT_UNWIND_TARGET wasm_rt_jmp_buf
+
+/**
+ * Get the current unwind target if an exception is thrown.
+ */
+WASM_RT_UNWIND_TARGET* wasm_rt_get_unwind_target(void);
+
+/**
+ * Set the unwind target if an exception is thrown.
+ */
+void wasm_rt_set_unwind_target(WASM_RT_UNWIND_TARGET* target);
+
+/**
+ * Tag of the active exception.
+ */
+wasm_rt_tag_t wasm_rt_exception_tag(void);
+
+/**
+ * Size of the active exception.
+ */
+uint32_t wasm_rt_exception_size(void);
+
+/**
+ * Contents of the active exception.
+ */
+void* wasm_rt_exception(void);
+
+#endif
diff --git a/wasm2c/wasm-rt-impl.c b/wasm2c/wasm-rt-impl.c
index 788fe1d7..db4458ae 100644
--- a/wasm2c/wasm-rt-impl.c
+++ b/wasm2c/wasm-rt-impl.c
@@ -36,13 +36,7 @@
#include <sys/mman.h>
#endif
-#if _MSC_VER
-#include <malloc.h>
-#define alloca _alloca
-#endif
-
#define PAGE_SIZE 65536
-#define MAX_EXCEPTION_SIZE 256
#if WASM_RT_INSTALL_SIGNAL_HANDLER
static bool g_signal_handler_installed = false;
@@ -60,12 +54,6 @@ WASM_RT_THREAD_LOCAL uint32_t wasm_rt_saved_call_stack_depth;
WASM_RT_THREAD_LOCAL wasm_rt_jmp_buf g_wasm_rt_jmp_buf;
-static WASM_RT_THREAD_LOCAL wasm_rt_tag_t g_active_exception_tag;
-static WASM_RT_THREAD_LOCAL uint8_t g_active_exception[MAX_EXCEPTION_SIZE];
-static WASM_RT_THREAD_LOCAL uint32_t g_active_exception_size;
-
-static WASM_RT_THREAD_LOCAL wasm_rt_jmp_buf* g_unwind_target;
-
#ifdef WASM_RT_TRAP_HANDLER
extern void WASM_RT_TRAP_HANDLER(wasm_rt_trap_t code);
#endif
@@ -88,45 +76,6 @@ void wasm_rt_trap(wasm_rt_trap_t code) {
#endif
}
-void wasm_rt_load_exception(const wasm_rt_tag_t tag,
- uint32_t size,
- const void* values) {
- if (size > MAX_EXCEPTION_SIZE) {
- wasm_rt_trap(WASM_RT_TRAP_EXHAUSTION);
- }
-
- g_active_exception_tag = tag;
- g_active_exception_size = size;
-
- if (size) {
- memcpy(g_active_exception, values, size);
- }
-}
-
-WASM_RT_NO_RETURN void wasm_rt_throw(void) {
- WASM_RT_LONGJMP(*g_unwind_target, WASM_RT_TRAP_UNCAUGHT_EXCEPTION);
-}
-
-WASM_RT_UNWIND_TARGET* wasm_rt_get_unwind_target(void) {
- return g_unwind_target;
-}
-
-void wasm_rt_set_unwind_target(WASM_RT_UNWIND_TARGET* target) {
- g_unwind_target = target;
-}
-
-wasm_rt_tag_t wasm_rt_exception_tag(void) {
- return g_active_exception_tag;
-}
-
-uint32_t wasm_rt_exception_size(void) {
- return g_active_exception_size;
-}
-
-void* wasm_rt_exception(void) {
- return g_active_exception;
-}
-
#ifdef _WIN32
static void* os_mmap(size_t size) {
void* ret = VirtualAlloc(NULL, size, MEM_RESERVE, PAGE_NOACCESS);
@@ -399,7 +348,7 @@ uint64_t wasm_rt_grow_memory(wasm_rt_memory_t* memory, uint64_t delta) {
void wasm_rt_free_memory(wasm_rt_memory_t* memory) {
#if WASM_RT_USE_MMAP
const uint64_t mmap_size = get_allocation_size_for_mmap(memory);
- os_munmap(memory->data, mmap_size); // ignore error
+ os_munmap(memory->data, mmap_size); // ignore error
#else
free(memory->data);
#endif
diff --git a/wasm2c/wasm-rt-impl.h b/wasm2c/wasm-rt-impl.h
index 088619f4..c7d7fdbf 100644
--- a/wasm2c/wasm-rt-impl.h
+++ b/wasm2c/wasm-rt-impl.h
@@ -30,19 +30,6 @@ extern "C" {
/** A setjmp buffer used for handling traps. */
extern WASM_RT_THREAD_LOCAL wasm_rt_jmp_buf g_wasm_rt_jmp_buf;
-#if WASM_RT_INSTALL_SIGNAL_HANDLER && !defined(_WIN32)
-#define WASM_RT_LONGJMP_UNCHECKED(buf, val) siglongjmp(buf, val)
-#else
-#define WASM_RT_LONGJMP_UNCHECKED(buf, val) longjmp(buf, val)
-#endif
-
-#define WASM_RT_LONGJMP(buf, val) \
- /* Abort on failure as this may be called in the trap handler */ \
- if (!((buf).initialized)) \
- abort(); \
- (buf).initialized = false; \
- WASM_RT_LONGJMP_UNCHECKED((buf).buffer, val)
-
#if WASM_RT_USE_STACK_DEPTH_COUNT
/** Saved call stack depth that will be restored in case a trap occurs. */
extern WASM_RT_THREAD_LOCAL uint32_t wasm_rt_saved_call_stack_depth;
diff --git a/wasm2c/wasm-rt.h b/wasm2c/wasm-rt.h
index 03f78834..9fd12dee 100644
--- a/wasm2c/wasm-rt.h
+++ b/wasm2c/wasm-rt.h
@@ -318,37 +318,7 @@ bool wasm_rt_is_initialized(void);
void wasm_rt_free(void);
/**
- * Stop execution immediately and jump back to the call to `wasm_rt_impl_try`.
- * The result of `wasm_rt_impl_try` will be the provided trap reason.
- *
- * This is typically called by the generated code, and not the embedder.
- */
-WASM_RT_NO_RETURN void wasm_rt_trap(wasm_rt_trap_t);
-
-/**
- * Return a human readable error string based on a trap type.
- */
-const char* wasm_rt_strerror(wasm_rt_trap_t trap);
-
-/**
- * A tag is represented as an arbitrary pointer.
- */
-typedef const void* wasm_rt_tag_t;
-
-/**
- * Set the active exception to given tag, size, and contents.
- */
-void wasm_rt_load_exception(const wasm_rt_tag_t tag,
- uint32_t size,
- const void* values);
-
-/**
- * Throw the active exception.
- */
-WASM_RT_NO_RETURN void wasm_rt_throw(void);
-
-/**
- * A hardened jmp_buf that allows us to checks if it is initialized before use
+ * A hardened jmp_buf that allows checking for initialization before use
*/
typedef struct {
/* Is the jmp buf intialized? */
@@ -357,44 +327,40 @@ typedef struct {
jmp_buf buffer;
} wasm_rt_jmp_buf;
-/**
- * The type of an unwind target if an exception is thrown and caught.
- */
-#define WASM_RT_UNWIND_TARGET wasm_rt_jmp_buf
+#if WASM_RT_INSTALL_SIGNAL_HANDLER && !defined(_WIN32)
+#define WASM_RT_SETJMP_SETBUF(buf) sigsetjmp(buf, 1)
+#else
+#define WASM_RT_SETJMP_SETBUF(buf) setjmp(buf)
+#endif
-/**
- * Get the current unwind target if an exception is thrown.
- */
-WASM_RT_UNWIND_TARGET* wasm_rt_get_unwind_target(void);
+#define WASM_RT_SETJMP(buf) \
+ ((buf).initialized = true, WASM_RT_SETJMP_SETBUF((buf).buffer))
-/**
- * Set the unwind target if an exception is thrown.
- */
-void wasm_rt_set_unwind_target(WASM_RT_UNWIND_TARGET* target);
+#if WASM_RT_INSTALL_SIGNAL_HANDLER && !defined(_WIN32)
+#define WASM_RT_LONGJMP_UNCHECKED(buf, val) siglongjmp(buf, val)
+#else
+#define WASM_RT_LONGJMP_UNCHECKED(buf, val) longjmp(buf, val)
+#endif
-/**
- * Tag of the active exception.
- */
-wasm_rt_tag_t wasm_rt_exception_tag(void);
+#define WASM_RT_LONGJMP(buf, val) \
+ /* Abort on failure as this may be called in the trap handler */ \
+ if (!((buf).initialized)) \
+ abort(); \
+ (buf).initialized = false; \
+ WASM_RT_LONGJMP_UNCHECKED((buf).buffer, val)
/**
- * Size of the active exception.
+ * Stop execution immediately and jump back to the call to `wasm_rt_impl_try`.
+ * The result of `wasm_rt_impl_try` will be the provided trap reason.
+ *
+ * This is typically called by the generated code, and not the embedder.
*/
-uint32_t wasm_rt_exception_size(void);
+WASM_RT_NO_RETURN void wasm_rt_trap(wasm_rt_trap_t);
/**
- * Contents of the active exception.
+ * Return a human readable error string based on a trap type.
*/
-void* wasm_rt_exception(void);
-
-#if WASM_RT_INSTALL_SIGNAL_HANDLER && !defined(_WIN32)
-#define WASM_RT_SETJMP_SETBUF(buf) sigsetjmp(buf, 1)
-#else
-#define WASM_RT_SETJMP_SETBUF(buf) setjmp(buf)
-#endif
-
-#define WASM_RT_SETJMP(buf) \
- ((buf).initialized = true, WASM_RT_SETJMP_SETBUF((buf).buffer))
+const char* wasm_rt_strerror(wasm_rt_trap_t trap);
#define wasm_rt_try(target) WASM_RT_SETJMP(target)