summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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
4 files changed, 25 insertions, 2 deletions
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