summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbuild.sh4
-rw-r--r--src/asm2wasm.h25
2 files changed, 27 insertions, 2 deletions
diff --git a/build.sh b/build.sh
index aefa83e77..922d27570 100755
--- a/build.sh
+++ b/build.sh
@@ -1,8 +1,8 @@
echo "building binaryen shell"
g++ -O2 -std=c++11 src/binaryen-shell.cpp src/pass.cpp src/passes/*.cpp -o bin/binaryen-shell -Isrc/ -msse2 -mfpmath=sse # use sse for math, avoid x87, necessarily for proper float rounding on 32-bit
echo "building asm2wasm"
-g++ -O2 -std=c++11 src/asm2wasm-main.cpp src/emscripten-optimizer/parser.cpp src/emscripten-optimizer/simple_ast.cpp src/emscripten-optimizer/optimizer-shared.cpp -o bin/asm2wasm
+g++ -g -std=c++11 src/asm2wasm-main.cpp src/emscripten-optimizer/parser.cpp src/emscripten-optimizer/simple_ast.cpp src/emscripten-optimizer/optimizer-shared.cpp -o bin/asm2wasm
echo "building interpreter/js"
-em++ -std=c++11 src/wasm-js.cpp src/emscripten-optimizer/parser.cpp src/emscripten-optimizer/simple_ast.cpp src/emscripten-optimizer/optimizer-shared.cpp -o bin/wasm.js -s MODULARIZE=1 -s 'EXPORT_NAME="WasmJS"' --memory-init-file 0 -Oz -s ALLOW_MEMORY_GROWTH=1 #-profiling -s DEMANGLE_SUPPORT=1 #-DWASM_JS_DEBUG -DWASM_INTERPRETER_DEBUG=2
+em++ -std=c++11 src/wasm-js.cpp src/emscripten-optimizer/parser.cpp src/emscripten-optimizer/simple_ast.cpp src/emscripten-optimizer/optimizer-shared.cpp -o bin/wasm.js -s MODULARIZE=1 -s 'EXPORT_NAME="WasmJS"' --memory-init-file 0 -Oz -s ALLOW_MEMORY_GROWTH=1 -profiling -s DEMANGLE_SUPPORT=1 -DWASM_JS_DEBUG -DWASM_INTERPRETER_DEBUG=2
cat src/js/post.js >> bin/wasm.js
diff --git a/src/asm2wasm.h b/src/asm2wasm.h
index 6a181b337..976e0afe1 100644
--- a/src/asm2wasm.h
+++ b/src/asm2wasm.h
@@ -36,6 +36,8 @@ IString GLOBAL("global"), NAN_("NaN"), INFINITY_("Infinity"),
F64_TO_INT("f64-to-int"),
GLOBAL_MATH("global.Math"),
ABS("abs"),
+ FLOOR("floor"),
+ SQRT("sqrt"),
I32_TEMP("asm2wasm_i32_temp"),
DEBUGGER("debugger");
@@ -131,6 +133,8 @@ private:
IString Math_clz32;
IString Math_fround;
IString Math_abs;
+ IString Math_floor;
+ IString Math_sqrt;
// function types. we fill in this information as we see
// uses, in the first pass
@@ -455,6 +459,14 @@ void Asm2WasmBuilder::processAsm(Ref ast) {
assert(Math_abs.isNull());
Math_abs = name;
return;
+ } else if (imported[2] == FLOOR) {
+ assert(Math_floor.isNull());
+ Math_floor = name;
+ return;
+ } else if (imported[2] == SQRT) {
+ assert(Math_sqrt.isNull());
+ Math_sqrt = name;
+ return;
}
}
std::string fullName = module[1][1]->getCString();
@@ -1121,6 +1133,19 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
abort();
}
}
+ if (name == Math_floor || name == Math_sqrt) {
+ // overloaded on type: f32 or f64
+ Expression* value = process(ast[2][0]);
+ if (value->type == f32 || value->type == f64) {
+ auto ret = allocator.alloc<Unary>();
+ ret->op = name == Math_floor ? Floor : Sqrt;
+ ret->value = value;
+ ret->type = value->type;
+ return ret;
+ } else {
+ abort();
+ }
+ }
Call* ret;
if (wasm.importsMap.find(name) != wasm.importsMap.end()) {
Ref parent = astStackHelper.getParent();