Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions scripts/wasm2js.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ var asmLibraryArg = {
console.log('get_f64 ' + [loc, index, value]);
return value;
},
get_anyref: function(loc, index, value) {
console.log('get_anyref ' + [loc, index, value]);
return value;
},
get_exnref: function(loc, index, value) {
console.log('get_exnref ' + [loc, index, value]);
return value;
},
set_i32: function(loc, index, value) {
console.log('set_i32 ' + [loc, index, value]);
return value;
Expand All @@ -147,6 +155,14 @@ var asmLibraryArg = {
console.log('set_f64 ' + [loc, index, value]);
return value;
},
set_anyref: function(loc, index, value) {
console.log('set_anyref ' + [loc, index, value]);
return value;
},
set_exnref: function(loc, index, value) {
console.log('set_exnref ' + [loc, index, value]);
return value;
},
load_ptr: function(loc, bytes, offset, ptr) {
console.log('load_ptr ' + [loc, bytes, offset, ptr]);
return ptr;
Expand Down
20 changes: 16 additions & 4 deletions src/passes/InstrumentLocals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,15 @@ Name get_i32("get_i32");
Name get_i64("get_i64");
Name get_f32("get_f32");
Name get_f64("get_f64");
Name get_anyref("get_anyref");
Name get_exnref("get_exnref");

Name set_i32("set_i32");
Name set_i64("set_i64");
Name set_f32("set_f32");
Name set_f64("set_f64");
Name set_anyref("set_anyref");
Name set_exnref("set_exnref");

struct InstrumentLocals : public WalkerPass<PostWalker<InstrumentLocals>> {
void visitLocalGet(LocalGet* curr) {
Expand All @@ -82,9 +86,11 @@ struct InstrumentLocals : public WalkerPass<PostWalker<InstrumentLocals>> {
case v128:
assert(false && "v128 not implemented yet");
case anyref:
assert(false && "anyref not implemented yet");
import = get_anyref;
break;
case exnref:
assert(false && "exnref not implemented yet");
import = get_exnref;
break;
case none:
WASM_UNREACHABLE();
case unreachable:
Expand Down Expand Up @@ -116,9 +122,11 @@ struct InstrumentLocals : public WalkerPass<PostWalker<InstrumentLocals>> {
case v128:
assert(false && "v128 not implemented yet");
case anyref:
assert(false && "anyref not implemented yet");
import = set_anyref;
break;
case exnref:
assert(false && "exnref not implemented yet");
import = set_exnref;
break;
case unreachable:
return; // nothing to do here
case none:
Expand All @@ -137,10 +145,14 @@ struct InstrumentLocals : public WalkerPass<PostWalker<InstrumentLocals>> {
addImport(curr, get_i64, "jiij");
addImport(curr, get_f32, "fiif");
addImport(curr, get_f64, "diid");
addImport(curr, get_anyref, "aiia");
addImport(curr, get_exnref, "eiie");
addImport(curr, set_i32, "iiii");
addImport(curr, set_i64, "jiij");
addImport(curr, set_f32, "fiif");
addImport(curr, set_f64, "diid");
addImport(curr, set_anyref, "aiia");
addImport(curr, set_exnref, "eiie");
}

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,27 @@
(type $FUNCSIG$jiij (func (param i32 i32 i64) (result i64)))
(type $FUNCSIG$fiif (func (param i32 i32 f32) (result f32)))
(type $FUNCSIG$diid (func (param i32 i32 f64) (result f64)))
(type $FUNCSIG$aiia (func (param i32 i32 anyref) (result anyref)))
(type $FUNCSIG$eiie (func (param i32 i32 exnref) (result exnref)))
(import "env" "get_i32" (func $get_i32 (param i32 i32 i32) (result i32)))
(import "env" "get_i64" (func $get_i64 (param i32 i32 i64) (result i64)))
(import "env" "get_f32" (func $get_f32 (param i32 i32 f32) (result f32)))
(import "env" "get_f64" (func $get_f64 (param i32 i32 f64) (result f64)))
(import "env" "get_anyref" (func $get_anyref (param i32 i32 anyref) (result anyref)))
(import "env" "get_exnref" (func $get_exnref (param i32 i32 exnref) (result exnref)))
(import "env" "set_i32" (func $set_i32 (param i32 i32 i32) (result i32)))
(import "env" "set_i64" (func $set_i64 (param i32 i32 i64) (result i64)))
(import "env" "set_f32" (func $set_f32 (param i32 i32 f32) (result f32)))
(import "env" "set_f64" (func $set_f64 (param i32 i32 f64) (result f64)))
(func $A (; 8 ;) (type $FUNCSIG$v)
(import "env" "set_anyref" (func $set_anyref (param i32 i32 anyref) (result anyref)))
(import "env" "set_exnref" (func $set_exnref (param i32 i32 exnref) (result exnref)))
(func $A (; 12 ;) (type $FUNCSIG$v)
(local $x i32)
(local $y i64)
(local $z f32)
(local $w f64)
(local $a anyref)
(local $e exnref)
(drop
(call $get_i32
(i32.const 0)
Expand All @@ -42,8 +50,22 @@
)
)
(drop
(call $get_i32
(call $get_anyref
(i32.const 3)
(i32.const 4)
(local.get $a)
)
)
(drop
(call $get_exnref
(i32.const 4)
(i32.const 5)
(local.get $e)
)
)
(drop
(call $get_i32
(i32.const 5)
(i32.const 0)
(local.get $x)
)
Expand All @@ -53,21 +75,35 @@
)
(drop
(call $get_f32
(i32.const 4)
(i32.const 6)
(i32.const 2)
(local.get $z)
)
)
(drop
(call $get_f64
(i32.const 5)
(i32.const 7)
(i32.const 3)
(local.get $w)
)
)
(drop
(call $get_anyref
(i32.const 8)
(i32.const 4)
(local.get $a)
)
)
(drop
(call $get_exnref
(i32.const 9)
(i32.const 5)
(local.get $e)
)
)
(local.set $x
(call $set_i32
(i32.const 6)
(i32.const 10)
(i32.const 0)
(i32.const 1)
)
Expand All @@ -77,21 +113,35 @@
)
(local.set $z
(call $set_f32
(i32.const 7)
(i32.const 11)
(i32.const 2)
(f32.const 3.2100000381469727)
)
)
(local.set $w
(call $set_f64
(i32.const 8)
(i32.const 12)
(i32.const 3)
(f64.const 4.321)
)
)
(local.set $a
(call $set_anyref
(i32.const 13)
(i32.const 4)
(anyref.pop)
)
)
(local.set $e
(call $set_exnref
(i32.const 14)
(i32.const 5)
(exnref.pop)
)
)
(local.set $x
(call $set_i32
(i32.const 9)
(i32.const 15)
(i32.const 0)
(i32.const 11)
)
Expand All @@ -101,17 +151,31 @@
)
(local.set $z
(call $set_f32
(i32.const 10)
(i32.const 16)
(i32.const 2)
(f32.const 33.209999084472656)
)
)
(local.set $w
(call $set_f64
(i32.const 11)
(i32.const 17)
(i32.const 3)
(f64.const 44.321)
)
)
(local.set $a
(call $set_anyref
(i32.const 18)
(i32.const 4)
(anyref.pop)
)
)
(local.set $e
(call $set_exnref
(i32.const 19)
(i32.const 5)
(exnref.pop)
)
)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,36 @@
(local $y i64)
(local $z f32)
(local $w f64)
(local $a anyref)
(local $e exnref)

(drop (local.get $x))
(drop (local.get $y))
(drop (local.get $z))
(drop (local.get $w))
(drop (local.get $a))
(drop (local.get $e))

(drop (local.get $x))
(drop (local.get $y))
(drop (local.get $z))
(drop (local.get $w))
(drop (local.get $a))
(drop (local.get $e))

(local.set $x (i32.const 1))
(local.set $y (i64.const 2))
(local.set $z (f32.const 3.21))
(local.set $w (f64.const 4.321))
(local.set $a (anyref.pop))
(local.set $e (exnref.pop))

(local.set $x (i32.const 11))
(local.set $y (i64.const 22))
(local.set $z (f32.const 33.21))
(local.set $w (f64.const 44.321))
(local.set $a (anyref.pop))
(local.set $e (exnref.pop))
)
)