summaryrefslogtreecommitdiff
path: root/src/wasm-builder.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/wasm-builder.h')
-rw-r--r--src/wasm-builder.h22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/wasm-builder.h b/src/wasm-builder.h
index 04e0aa4de..42d3dfe47 100644
--- a/src/wasm-builder.h
+++ b/src/wasm-builder.h
@@ -17,7 +17,8 @@
#ifndef wasm_wasm_builder_h
#define wasm_wasm_builder_h
-#include <wasm.h>
+#include "wasm.h"
+#include "ast/manipulation.h"
namespace wasm {
@@ -379,6 +380,25 @@ public:
std::swap(iff->ifTrue, iff->ifFalse);
iff->condition = makeUnary(EqZInt32, iff->condition);
}
+
+ // returns a replacement with the precise same type, and with
+ // minimal contents. as a replacement, this may reuse the
+ // input node
+ template<typename T>
+ Expression* replaceWithIdenticalType(T* curr) {
+ Literal value;
+ // TODO: reuse node conditionally when possible for literals
+ switch (curr->type) {
+ case i32: value = Literal(int32_t(0)); break;
+ case i64: value = Literal(int64_t(0)); break;
+ case f32: value = Literal(float(0)); break;
+ case f64: value = Literal(double(0)); break;
+ case none: return ExpressionManipulator::nop(curr);
+ case unreachable: return ExpressionManipulator::convert<T, Unreachable>(curr);
+ }
+ return makeConst(value);
+ }
+
};
} // namespace wasm