summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2015-12-12 10:37:08 -0500
committerAlon Zakai <alonzakai@gmail.com>2015-12-12 10:37:08 -0500
commit082b484ed36bbab55e22898bd268ba961df2f213 (patch)
tree139c8a282dd7f77522f75b9ae2180738b64c095a
parentefbc76812555d28241ae7fc7687a0ae4e588006a (diff)
downloadbinaryen-082b484ed36bbab55e22898bd268ba961df2f213.tar.gz
binaryen-082b484ed36bbab55e22898bd268ba961df2f213.tar.bz2
binaryen-082b484ed36bbab55e22898bd268ba961df2f213.zip
many more ops in s2wasm
-rwxr-xr-xauto_update_tests.py2
-rwxr-xr-xcheck.py2
-rw-r--r--src/s2wasm.h50
-rw-r--r--test/dot_s/conv.wast292
4 files changed, 340 insertions, 6 deletions
diff --git a/auto_update_tests.py b/auto_update_tests.py
index 55fba2044..b51be1b8b 100755
--- a/auto_update_tests.py
+++ b/auto_update_tests.py
@@ -32,7 +32,7 @@ for t in sorted(os.listdir('test')):
open(t, 'w').write(actual)
-for s in ['minimal.s', 'basics.s', 'call.s', 'cfg-stackify.s', 'comparisons_f32.s', 'comparisons_f64.s', 'comparisons_i32.s', 'comparisons_i64.s']:
+for s in ['minimal.s', 'basics.s', 'call.s', 'cfg-stackify.s', 'comparisons_f32.s', 'comparisons_f64.s', 'comparisons_i32.s', 'comparisons_i64.s', 'conv.s']:
print '..', s
wasm = s.replace('.s', '.wast')
full = os.path.join('test', 'dot_s', s)
diff --git a/check.py b/check.py
index ac0acc315..6908966a3 100755
--- a/check.py
+++ b/check.py
@@ -214,7 +214,7 @@ for t in spec_tests:
print '\n[ checking .s testcases... ]\n'
-for s in ['minimal.s', 'basics.s', 'call.s', 'cfg-stackify.s', 'comparisons_f32.s', 'comparisons_f64.s', 'comparisons_i32.s', 'comparisons_i64.s']:
+for s in ['minimal.s', 'basics.s', 'call.s', 'cfg-stackify.s', 'comparisons_f32.s', 'comparisons_f64.s', 'comparisons_i32.s', 'comparisons_i64.s', 'conv.s']:
print '..', s
wasm = s.replace('.s', '.wast')
full = os.path.join('test', 'dot_s', s)
diff --git a/src/s2wasm.h b/src/s2wasm.h
index c85e50e10..ed8d3e0e3 100644
--- a/src/s2wasm.h
+++ b/src/s2wasm.h
@@ -307,6 +307,15 @@ private:
assert(curr->type == type);
setOutput(curr, assign);
};
+ auto makeUnary = [&](UnaryOp op, WasmType type) {
+ Name assign = getAssign();
+ skipComma();
+ auto curr = allocator.alloc<Unary>();
+ curr->op = op;
+ curr->value = getInput();
+ curr->type = type;
+ setOutput(curr, assign);
+ };
auto makeLoad = [&](WasmType type) {
Name assign = getAssign();
skipComma();
@@ -384,11 +393,23 @@ private:
// constant
setOutput(parseConst(getStr(), type, allocator), assign);
}
- } else abort_on("type.c");
+ } else if (match("convert_s/i32")) makeUnary(UnaryOp::ConvertSInt32, type);
+ else if (match("convert_u/i32")) makeUnary(UnaryOp::ConvertUInt32, type);
+ else if (match("convert_s/i64")) makeUnary(UnaryOp::ConvertSInt64, type);
+ else if (match("convert_u/i64")) makeUnary(UnaryOp::ConvertUInt64, type);
+ else abort_on("type.c");
+ break;
+ }
+ case 'd': {
+ if (match("demote/f64")) makeUnary(UnaryOp::DemoteFloat64, type);
+ else abort_on("type.g");
break;
}
case 'e': {
if (match("eq")) makeBinary(BinaryOp::Eq, i32);
+ else if (match("extend_s/i32")) makeUnary(UnaryOp::ExtendSInt32, type);
+ else if (match("extend_u/i32")) makeUnary(UnaryOp::ExtendUInt32, type);
+ else abort_on("type.e");
break;
}
case 'g': {
@@ -424,26 +445,47 @@ private:
}
case 'o': {
if (match("or")) makeBinary(BinaryOp::Or, type);
- else abort_on("type.n");
+ else abort_on("type.o");
+ break;
+ }
+ case 'p': {
+ if (match("promote/f32")) makeUnary(UnaryOp::PromoteFloat32, type);
+ else abort_on("type.p");
break;
}
case 'r': {
if (match("rem_s")) makeBinary(BinaryOp::RemS, type);
else if (match("rem_u")) makeBinary(BinaryOp::RemU, type);
- else abort_on("type.n");
+ else if (match("reinterpret/i32") || match("reinterpret/i64")) makeUnary(UnaryOp::ReinterpretInt, type);
+ else if (match("reinterpret/f32") || match("reinterpret/f64")) makeUnary(UnaryOp::ReinterpretFloat, type);
+ else abort_on("type.r");
break;
}
case 's': {
if (match("shr_s")) makeBinary(BinaryOp::ShrS, type);
else if (match("shr_u")) makeBinary(BinaryOp::ShrU, type);
+ else if (match("shl")) makeBinary(BinaryOp::Shl, type);
else if (match("sub")) makeBinary(BinaryOp::Sub, type);
else if (match("store")) makeStore(type);
else abort_on("type.s");
break;
}
+ case 't': {
+ if (match("trunc_s/f32")) makeUnary(UnaryOp::TruncSFloat32, type);
+ else if (match("trunc_u/f32")) makeUnary(UnaryOp::TruncUFloat32, type);
+ else if (match("trunc_s/f64")) makeUnary(UnaryOp::TruncSFloat64, type);
+ else if (match("trunc_u/f64")) makeUnary(UnaryOp::TruncUFloat64, type);
+ else abort_on("type.t");
+ break;
+ }
+ case 'w': {
+ if (match("wrap/i64")) makeUnary(UnaryOp::WrapInt64, type);
+ else abort_on("type.w");
+ break;
+ }
case 'x': {
if (match("or")) makeBinary(BinaryOp::Xor, type);
- else abort_on("type.n");
+ else abort_on("type.x");
break;
}
default: abort_on("type.?");
diff --git a/test/dot_s/conv.wast b/test/dot_s/conv.wast
new file mode 100644
index 000000000..c93954b4d
--- /dev/null
+++ b/test/dot_s/conv.wast
@@ -0,0 +1,292 @@
+(module
+ (memory 0 4294967295)
+ (func $i32_wrap_i64 (param $$0 i64) (result i32)
+ (block $fake_return_waka123
+ (block
+ (br $fake_return_waka123
+ (i32.wrap/i64
+ (get_local $$0)
+ )
+ )
+ )
+ )
+ )
+ (func $i64_extend_s_i32 (param $$0 i32) (result i64)
+ (block $fake_return_waka123
+ (block
+ (br $fake_return_waka123
+ (i64.extend_s/i32
+ (get_local $$0)
+ )
+ )
+ )
+ )
+ )
+ (func $i64_extend_u_i32 (param $$0 i32) (result i64)
+ (block $fake_return_waka123
+ (block
+ (br $fake_return_waka123
+ (i64.extend_u/i32
+ (get_local $$0)
+ )
+ )
+ )
+ )
+ )
+ (func $i32_trunc_s_f32 (param $$0 f32) (result i32)
+ (block $fake_return_waka123
+ (block
+ (br $fake_return_waka123
+ (i32.trunc_s/f32
+ (get_local $$0)
+ )
+ )
+ )
+ )
+ )
+ (func $i32_trunc_u_f32 (param $$0 f32) (result i32)
+ (block $fake_return_waka123
+ (block
+ (br $fake_return_waka123
+ (i32.trunc_u/f32
+ (get_local $$0)
+ )
+ )
+ )
+ )
+ )
+ (func $i32_trunc_s_f64 (param $$0 f64) (result i32)
+ (block $fake_return_waka123
+ (block
+ (br $fake_return_waka123
+ (i32.trunc_s/f64
+ (get_local $$0)
+ )
+ )
+ )
+ )
+ )
+ (func $i32_trunc_u_f64 (param $$0 f64) (result i32)
+ (block $fake_return_waka123
+ (block
+ (br $fake_return_waka123
+ (i32.trunc_u/f64
+ (get_local $$0)
+ )
+ )
+ )
+ )
+ )
+ (func $i64_trunc_s_f32 (param $$0 f32) (result i64)
+ (block $fake_return_waka123
+ (block
+ (br $fake_return_waka123
+ (i64.trunc_s/f32
+ (get_local $$0)
+ )
+ )
+ )
+ )
+ )
+ (func $i64_trunc_u_f32 (param $$0 f32) (result i64)
+ (block $fake_return_waka123
+ (block
+ (br $fake_return_waka123
+ (i64.trunc_u/f32
+ (get_local $$0)
+ )
+ )
+ )
+ )
+ )
+ (func $i64_trunc_s_f64 (param $$0 f64) (result i64)
+ (block $fake_return_waka123
+ (block
+ (br $fake_return_waka123
+ (i64.trunc_s/f64
+ (get_local $$0)
+ )
+ )
+ )
+ )
+ )
+ (func $i64_trunc_u_f64 (param $$0 f64) (result i64)
+ (block $fake_return_waka123
+ (block
+ (br $fake_return_waka123
+ (i64.trunc_u/f64
+ (get_local $$0)
+ )
+ )
+ )
+ )
+ )
+ (func $f32_convert_s_i32 (param $$0 i32) (result f32)
+ (block $fake_return_waka123
+ (block
+ (br $fake_return_waka123
+ (f32.convert_s/i32
+ (get_local $$0)
+ )
+ )
+ )
+ )
+ )
+ (func $f32_convert_u_i32 (param $$0 i32) (result f32)
+ (block $fake_return_waka123
+ (block
+ (br $fake_return_waka123
+ (f32.convert_u/i32
+ (get_local $$0)
+ )
+ )
+ )
+ )
+ )
+ (func $f64_convert_s_i32 (param $$0 i32) (result f64)
+ (block $fake_return_waka123
+ (block
+ (br $fake_return_waka123
+ (f64.convert_s/i32
+ (get_local $$0)
+ )
+ )
+ )
+ )
+ )
+ (func $f64_convert_u_i32 (param $$0 i32) (result f64)
+ (block $fake_return_waka123
+ (block
+ (br $fake_return_waka123
+ (f64.convert_u/i32
+ (get_local $$0)
+ )
+ )
+ )
+ )
+ )
+ (func $f32_convert_s_i64 (param $$0 i64) (result f32)
+ (block $fake_return_waka123
+ (block
+ (br $fake_return_waka123
+ (f32.convert_s/i64
+ (get_local $$0)
+ )
+ )
+ )
+ )
+ )
+ (func $f32_convert_u_i64 (param $$0 i64) (result f32)
+ (block $fake_return_waka123
+ (block
+ (br $fake_return_waka123
+ (f32.convert_u/i64
+ (get_local $$0)
+ )
+ )
+ )
+ )
+ )
+ (func $f64_convert_s_i64 (param $$0 i64) (result f64)
+ (block $fake_return_waka123
+ (block
+ (br $fake_return_waka123
+ (f64.convert_s/i64
+ (get_local $$0)
+ )
+ )
+ )
+ )
+ )
+ (func $f64_convert_u_i64 (param $$0 i64) (result f64)
+ (block $fake_return_waka123
+ (block
+ (br $fake_return_waka123
+ (f64.convert_u/i64
+ (get_local $$0)
+ )
+ )
+ )
+ )
+ )
+ (func $f64_promote_f32 (param $$0 f32) (result f64)
+ (block $fake_return_waka123
+ (block
+ (br $fake_return_waka123
+ (f64.promote/f32
+ (get_local $$0)
+ )
+ )
+ )
+ )
+ )
+ (func $f32_demote_f64 (param $$0 f64) (result f32)
+ (block $fake_return_waka123
+ (block
+ (br $fake_return_waka123
+ (f32.demote/f64
+ (get_local $$0)
+ )
+ )
+ )
+ )
+ )
+ (func $anyext (param $$0 i32) (result i64)
+ (block $fake_return_waka123
+ (block
+ (br $fake_return_waka123
+ (i64.shl
+ (i64.extend_u/i32
+ (get_local $$0)
+ )
+ (i64.const 32)
+ )
+ )
+ )
+ )
+ )
+ (func $bitcast_i32_to_float (param $$0 i32) (result f32)
+ (block $fake_return_waka123
+ (block
+ (br $fake_return_waka123
+ (f32.reinterpreti32
+ (get_local $$0)
+ )
+ )
+ )
+ )
+ )
+ (func $bitcast_float_to_i32 (param $$0 f32) (result i32)
+ (block $fake_return_waka123
+ (block
+ (br $fake_return_waka123
+ (i32.reinterpret/f32
+ (get_local $$0)
+ )
+ )
+ )
+ )
+ )
+ (func $bitcast_i64_to_double (param $$0 i64) (result f64)
+ (block $fake_return_waka123
+ (block
+ (br $fake_return_waka123
+ (f64.reinterpreti64
+ (get_local $$0)
+ )
+ )
+ )
+ )
+ )
+ (func $bitcast_double_to_i64 (param $$0 f64) (result i64)
+ (block $fake_return_waka123
+ (block
+ (br $fake_return_waka123
+ (i64.reinterpret/f64
+ (get_local $$0)
+ )
+ )
+ )
+ )
+ )
+)