mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-29 00:21:34 +00:00
Test 'tee_local' and 'set_global' in more operators
Based on this commit from the WebAssembly spec tests: c90bc9686f
This commit is contained in:
@ -167,6 +167,15 @@
|
|||||||
(func (export "as-set_local-value") (result i32)
|
(func (export "as-set_local-value") (result i32)
|
||||||
(local i32) (set_local 0 (block (result i32) (i32.const 1))) (get_local 0)
|
(local i32) (set_local 0 (block (result i32) (i32.const 1))) (get_local 0)
|
||||||
)
|
)
|
||||||
|
(func (export "as-tee_local-value") (result i32)
|
||||||
|
(local i32) (tee_local 0 (block (result i32) (i32.const 1)))
|
||||||
|
)
|
||||||
|
(global $a (mut i32) (i32.const 10))
|
||||||
|
(func (export "as-set_global-value") (result i32)
|
||||||
|
(set_global $a (block (result i32) (i32.const 1)))
|
||||||
|
(get_global $a)
|
||||||
|
)
|
||||||
|
|
||||||
(func (export "as-load-operand") (result i32)
|
(func (export "as-load-operand") (result i32)
|
||||||
(i32.load (block (result i32) (i32.const 1)))
|
(i32.load (block (result i32) (i32.const 1)))
|
||||||
)
|
)
|
||||||
@ -277,6 +286,8 @@
|
|||||||
(assert_return (invoke "as-drop-operand"))
|
(assert_return (invoke "as-drop-operand"))
|
||||||
(assert_return (invoke "as-br-value") (i32.const 1))
|
(assert_return (invoke "as-br-value") (i32.const 1))
|
||||||
(assert_return (invoke "as-set_local-value") (i32.const 1))
|
(assert_return (invoke "as-set_local-value") (i32.const 1))
|
||||||
|
(assert_return (invoke "as-tee_local-value") (i32.const 1))
|
||||||
|
(assert_return (invoke "as-set_global-value") (i32.const 1))
|
||||||
(assert_return (invoke "as-load-operand") (i32.const 1))
|
(assert_return (invoke "as-load-operand") (i32.const 1))
|
||||||
|
|
||||||
(assert_return (invoke "as-unary-operand") (i32.const 0))
|
(assert_return (invoke "as-unary-operand") (i32.const 0))
|
||||||
|
@ -181,6 +181,13 @@
|
|||||||
(func (export "as-set_local-value") (result i32) (local f32)
|
(func (export "as-set_local-value") (result i32) (local f32)
|
||||||
(block (result i32) (set_local 0 (br 0 (i32.const 17))) (i32.const -1))
|
(block (result i32) (set_local 0 (br 0 (i32.const 17))) (i32.const -1))
|
||||||
)
|
)
|
||||||
|
(func (export "as-tee_local-value") (result i32) (local i32)
|
||||||
|
(block (result i32) (tee_local 0 (br 0 (i32.const 1))))
|
||||||
|
)
|
||||||
|
(global $a (mut i32) (i32.const 10))
|
||||||
|
(func (export "as-set_global-value") (result i32)
|
||||||
|
(block (result i32) (set_global $a (br 0 (i32.const 1))))
|
||||||
|
)
|
||||||
|
|
||||||
(memory 1)
|
(memory 1)
|
||||||
(func (export "as-load-address") (result f32)
|
(func (export "as-load-address") (result f32)
|
||||||
@ -377,6 +384,8 @@
|
|||||||
(assert_return (invoke "as-call_indirect-last") (i32.const 23))
|
(assert_return (invoke "as-call_indirect-last") (i32.const 23))
|
||||||
|
|
||||||
(assert_return (invoke "as-set_local-value") (i32.const 17))
|
(assert_return (invoke "as-set_local-value") (i32.const 17))
|
||||||
|
(assert_return (invoke "as-tee_local-value") (i32.const 1))
|
||||||
|
(assert_return (invoke "as-set_global-value") (i32.const 1))
|
||||||
|
|
||||||
(assert_return (invoke "as-load-address") (f32.const 1.7))
|
(assert_return (invoke "as-load-address") (f32.const 1.7))
|
||||||
(assert_return (invoke "as-loadN-address") (i64.const 30))
|
(assert_return (invoke "as-loadN-address") (i64.const 30))
|
||||||
|
@ -205,6 +205,19 @@
|
|||||||
(i32.const -1)
|
(i32.const -1)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
(func (export "as-tee_local-value") (param i32) (result i32)
|
||||||
|
(block (result i32)
|
||||||
|
(tee_local 0 (br_if 0 (i32.const 1) (get_local 0)))
|
||||||
|
(return (i32.const -1))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(global $a (mut i32) (i32.const 10))
|
||||||
|
(func (export "as-set_global-value") (param i32) (result i32)
|
||||||
|
(block (result i32)
|
||||||
|
(set_global $a (br_if 0 (i32.const 1) (get_local 0)))
|
||||||
|
(return (i32.const -1))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
(func (export "as-unary-operand") (result f64)
|
(func (export "as-unary-operand") (result f64)
|
||||||
(block (result f64) (f64.neg (br_if 0 (f64.const 1.0) (i32.const 1))))
|
(block (result f64) (f64.neg (br_if 0 (f64.const 1.0) (i32.const 1))))
|
||||||
@ -391,6 +404,12 @@
|
|||||||
(assert_return (invoke "as-set_local-value" (i32.const 0)) (i32.const -1))
|
(assert_return (invoke "as-set_local-value" (i32.const 0)) (i32.const -1))
|
||||||
(assert_return (invoke "as-set_local-value" (i32.const 1)) (i32.const 17))
|
(assert_return (invoke "as-set_local-value" (i32.const 1)) (i32.const 17))
|
||||||
|
|
||||||
|
(assert_return (invoke "as-tee_local-value" (i32.const 0)) (i32.const -1))
|
||||||
|
(assert_return (invoke "as-tee_local-value" (i32.const 1)) (i32.const 1))
|
||||||
|
|
||||||
|
(assert_return (invoke "as-set_global-value" (i32.const 0)) (i32.const -1))
|
||||||
|
(assert_return (invoke "as-set_global-value" (i32.const 1)) (i32.const 1))
|
||||||
|
|
||||||
(assert_return (invoke "as-unary-operand") (f64.const 1.0))
|
(assert_return (invoke "as-unary-operand") (f64.const 1.0))
|
||||||
(assert_return (invoke "as-binary-left") (i32.const 1))
|
(assert_return (invoke "as-binary-left") (i32.const 1))
|
||||||
(assert_return (invoke "as-binary-right") (i32.const 1))
|
(assert_return (invoke "as-binary-right") (i32.const 1))
|
||||||
|
@ -1027,6 +1027,20 @@
|
|||||||
(i32.const -1)
|
(i32.const -1)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
(func (export "as-tee_local-value") (result i32)
|
||||||
|
(local i32)
|
||||||
|
(block (result i32)
|
||||||
|
(set_local 0 (br_table 0 (i32.const 1) (i32.const 1)))
|
||||||
|
(i32.const -1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(global $a (mut i32) (i32.const 10))
|
||||||
|
(func (export "as-set_global-value") (result i32)
|
||||||
|
(block (result i32)
|
||||||
|
(set_global $a (br_table 0 (i32.const 1) (i32.const 1)))
|
||||||
|
(i32.const -1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
(memory 1)
|
(memory 1)
|
||||||
(func (export "as-load-address") (result f32)
|
(func (export "as-load-address") (result f32)
|
||||||
@ -1342,6 +1356,8 @@
|
|||||||
(assert_return (invoke "as-call_indirect-func") (i32.const 23))
|
(assert_return (invoke "as-call_indirect-func") (i32.const 23))
|
||||||
|
|
||||||
(assert_return (invoke "as-set_local-value") (i32.const 17))
|
(assert_return (invoke "as-set_local-value") (i32.const 17))
|
||||||
|
(assert_return (invoke "as-tee_local-value") (i32.const 1))
|
||||||
|
(assert_return (invoke "as-set_global-value") (i32.const 1))
|
||||||
|
|
||||||
(assert_return (invoke "as-load-address") (f32.const 1.7))
|
(assert_return (invoke "as-load-address") (f32.const 1.7))
|
||||||
(assert_return (invoke "as-loadN-address") (i64.const 30))
|
(assert_return (invoke "as-loadN-address") (i64.const 30))
|
||||||
@ -1512,4 +1528,3 @@
|
|||||||
))
|
))
|
||||||
"unknown label"
|
"unknown label"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -106,6 +106,97 @@
|
|||||||
|
|
||||||
(func $mutual-runaway1 (export "mutual-runaway") (call $mutual-runaway2))
|
(func $mutual-runaway1 (export "mutual-runaway") (call $mutual-runaway2))
|
||||||
(func $mutual-runaway2 (call $mutual-runaway1))
|
(func $mutual-runaway2 (call $mutual-runaway1))
|
||||||
|
|
||||||
|
;; As parameter of control constructs and instructions
|
||||||
|
|
||||||
|
(memory 1)
|
||||||
|
|
||||||
|
(func (export "as-select-first") (result i32)
|
||||||
|
(select (call $const-i32) (i32.const 2) (i32.const 3))
|
||||||
|
)
|
||||||
|
(func (export "as-select-mid") (result i32)
|
||||||
|
(select (i32.const 2) (call $const-i32) (i32.const 3))
|
||||||
|
)
|
||||||
|
(func (export "as-select-last") (result i32)
|
||||||
|
(select (i32.const 2) (i32.const 3) (call $const-i32))
|
||||||
|
)
|
||||||
|
|
||||||
|
(func (export "as-if-condition") (result i32)
|
||||||
|
(if (result i32) (call $const-i32) (then (i32.const 1)) (else (i32.const 2)))
|
||||||
|
)
|
||||||
|
|
||||||
|
(func (export "as-br_if-first") (result i32)
|
||||||
|
(block (result i32) (br_if 0 (call $const-i32) (i32.const 2)))
|
||||||
|
)
|
||||||
|
(func (export "as-br_if-last") (result i32)
|
||||||
|
(block (result i32) (br_if 0 (i32.const 2) (call $const-i32)))
|
||||||
|
)
|
||||||
|
|
||||||
|
(func (export "as-br_table-first") (result i32)
|
||||||
|
(block (result i32) (call $const-i32) (i32.const 2) (br_table 0 0))
|
||||||
|
)
|
||||||
|
(func (export "as-br_table-last") (result i32)
|
||||||
|
(block (result i32) (i32.const 2) (call $const-i32) (br_table 0 0))
|
||||||
|
)
|
||||||
|
|
||||||
|
(func $func (param i32 i32) (result i32) (get_local 0))
|
||||||
|
(type $check (func (param i32 i32) (result i32)))
|
||||||
|
(table anyfunc (elem $func))
|
||||||
|
(func (export "as-call_indirect-first") (result i32)
|
||||||
|
(block (result i32)
|
||||||
|
(call_indirect (type $check)
|
||||||
|
(call $const-i32) (i32.const 2) (i32.const 0)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(func (export "as-call_indirect-mid") (result i32)
|
||||||
|
(block (result i32)
|
||||||
|
(call_indirect (type $check)
|
||||||
|
(i32.const 2) (call $const-i32) (i32.const 0)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(func (export "as-call_indirect-last") (result i32)
|
||||||
|
(block (result i32)
|
||||||
|
(call_indirect (type $check)
|
||||||
|
(i32.const 1) (i32.const 2) (call $const-i32)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
(func (export "as-store-first")
|
||||||
|
(call $const-i32) (i32.const 1) (i32.store)
|
||||||
|
)
|
||||||
|
(func (export "as-store-last")
|
||||||
|
(i32.const 10) (call $const-i32) (i32.store)
|
||||||
|
)
|
||||||
|
|
||||||
|
(func (export "as-memory.grow-value") (result i32)
|
||||||
|
(memory.grow (call $const-i32))
|
||||||
|
)
|
||||||
|
(func (export "as-return-value") (result i32)
|
||||||
|
(call $const-i32) (return)
|
||||||
|
)
|
||||||
|
(func (export "as-drop-operand")
|
||||||
|
(call $const-i32) (drop)
|
||||||
|
)
|
||||||
|
(func (export "as-br-value") (result i32)
|
||||||
|
(block (result i32) (br 0 (call $const-i32)))
|
||||||
|
)
|
||||||
|
(func (export "as-set_local-value") (result i32)
|
||||||
|
(local i32) (set_local 0 (call $const-i32)) (get_local 0)
|
||||||
|
)
|
||||||
|
(func (export "as-tee_local-value") (result i32)
|
||||||
|
(local i32) (tee_local 0 (call $const-i32))
|
||||||
|
)
|
||||||
|
(global $a (mut i32) (i32.const 10))
|
||||||
|
(func (export "as-set_global-value") (result i32)
|
||||||
|
(set_global $a (call $const-i32))
|
||||||
|
(get_global $a)
|
||||||
|
)
|
||||||
|
(func (export "as-load-operand") (result i32)
|
||||||
|
(i32.load (call $const-i32))
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
(assert_return (invoke "type-i32") (i32.const 0x132))
|
(assert_return (invoke "type-i32") (i32.const 0x132))
|
||||||
@ -153,6 +244,33 @@
|
|||||||
(assert_exhaustion (invoke "runaway") "call stack exhausted")
|
(assert_exhaustion (invoke "runaway") "call stack exhausted")
|
||||||
(assert_exhaustion (invoke "mutual-runaway") "call stack exhausted")
|
(assert_exhaustion (invoke "mutual-runaway") "call stack exhausted")
|
||||||
|
|
||||||
|
(assert_return (invoke "as-select-first") (i32.const 0x132))
|
||||||
|
(assert_return (invoke "as-select-mid") (i32.const 2))
|
||||||
|
(assert_return (invoke "as-select-last") (i32.const 2))
|
||||||
|
|
||||||
|
(assert_return (invoke "as-if-condition") (i32.const 1))
|
||||||
|
|
||||||
|
(assert_return (invoke "as-br_if-first") (i32.const 0x132))
|
||||||
|
(assert_return (invoke "as-br_if-last") (i32.const 2))
|
||||||
|
|
||||||
|
(assert_return (invoke "as-br_table-first") (i32.const 0x132))
|
||||||
|
(assert_return (invoke "as-br_table-last") (i32.const 2))
|
||||||
|
|
||||||
|
(assert_return (invoke "as-call_indirect-first") (i32.const 0x132))
|
||||||
|
(assert_return (invoke "as-call_indirect-mid") (i32.const 2))
|
||||||
|
(assert_trap (invoke "as-call_indirect-last") "undefined element")
|
||||||
|
|
||||||
|
(assert_return (invoke "as-store-first"))
|
||||||
|
(assert_return (invoke "as-store-last"))
|
||||||
|
|
||||||
|
;; (assert_return (invoke "as-memory.grow-value") (i32.const 1))
|
||||||
|
(assert_return (invoke "as-return-value") (i32.const 0x132))
|
||||||
|
(assert_return (invoke "as-drop-operand"))
|
||||||
|
(assert_return (invoke "as-br-value") (i32.const 0x132))
|
||||||
|
(assert_return (invoke "as-set_local-value") (i32.const 0x132))
|
||||||
|
(assert_return (invoke "as-tee_local-value") (i32.const 0x132))
|
||||||
|
(assert_return (invoke "as-set_global-value") (i32.const 0x132))
|
||||||
|
(assert_return (invoke "as-load-operand") (i32.const 1))
|
||||||
|
|
||||||
;; Invalid typing
|
;; Invalid typing
|
||||||
|
|
||||||
|
@ -371,6 +371,15 @@
|
|||||||
(func (export "as-set_local-value") (result f64)
|
(func (export "as-set_local-value") (result f64)
|
||||||
(local f64) (set_local 0 (call_indirect (type $over-f64) (f64.const 1) (i32.const 7))) (get_local 0)
|
(local f64) (set_local 0 (call_indirect (type $over-f64) (f64.const 1) (i32.const 7))) (get_local 0)
|
||||||
)
|
)
|
||||||
|
(func (export "as-tee_local-value") (result f64)
|
||||||
|
(local f64) (tee_local 0 (call_indirect (type $over-f64) (f64.const 1) (i32.const 7)))
|
||||||
|
)
|
||||||
|
(global $a (mut f64) (f64.const 10.0))
|
||||||
|
(func (export "as-set_global-value") (result f64)
|
||||||
|
(set_global $a (call_indirect (type $over-f64) (f64.const 1.0) (i32.const 7)))
|
||||||
|
(get_global $a)
|
||||||
|
)
|
||||||
|
|
||||||
(func (export "as-load-operand") (result i32)
|
(func (export "as-load-operand") (result i32)
|
||||||
(i32.load (call_indirect (type $out-i32) (i32.const 0)))
|
(i32.load (call_indirect (type $out-i32) (i32.const 0)))
|
||||||
)
|
)
|
||||||
@ -508,6 +517,8 @@
|
|||||||
(assert_return (invoke "as-drop-operand"))
|
(assert_return (invoke "as-drop-operand"))
|
||||||
(assert_return (invoke "as-br-value") (f32.const 1))
|
(assert_return (invoke "as-br-value") (f32.const 1))
|
||||||
(assert_return (invoke "as-set_local-value") (f64.const 1))
|
(assert_return (invoke "as-set_local-value") (f64.const 1))
|
||||||
|
(assert_return (invoke "as-tee_local-value") (f64.const 1))
|
||||||
|
(assert_return (invoke "as-set_global-value") (f64.const 1.0))
|
||||||
(assert_return (invoke "as-load-operand") (i32.const 1))
|
(assert_return (invoke "as-load-operand") (i32.const 1))
|
||||||
|
|
||||||
;; Invalid syntax
|
;; Invalid syntax
|
||||||
|
@ -1,8 +1,14 @@
|
|||||||
use crate::webassembly::{ImportObject, VmCtx};
|
use crate::webassembly::{ImportObject, VmCtx};
|
||||||
use libc::putchar;
|
use libc::putchar;
|
||||||
|
|
||||||
|
fn printf(format: i32, values: i32, context: &VmCtx) -> i32 {
|
||||||
|
println!("PRINTF {:?} {:?}", format, values);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn generate_libc_env<'a, 'b>() -> ImportObject<&'a str, &'b str> {
|
pub fn generate_libc_env<'a, 'b>() -> ImportObject<&'a str, &'b str> {
|
||||||
let mut import_object = ImportObject::new();
|
let mut import_object = ImportObject::new();
|
||||||
|
import_object.set("env", "printf", printf as *const u8);
|
||||||
import_object.set("env", "putchar", putchar as *const u8);
|
import_object.set("env", "putchar", putchar as *const u8);
|
||||||
import_object
|
import_object
|
||||||
}
|
}
|
||||||
@ -30,4 +36,20 @@ mod tests {
|
|||||||
let context = instance.generate_context();
|
let context = instance.generate_context();
|
||||||
main(&context);
|
main(&context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// #[test]
|
||||||
|
// fn test_printf() {
|
||||||
|
// let wasm_bytes = include_wast2wasm_bytes!("tests/printf.wast");
|
||||||
|
// let import_object = generate_libc_env();
|
||||||
|
// let result_object = instantiate(wasm_bytes, import_object).expect("Not compiled properly");
|
||||||
|
// let module = result_object.module;
|
||||||
|
// let mut instance = result_object.instance;
|
||||||
|
// let func_index = match module.info.exports.get("main") {
|
||||||
|
// Some(&Export::Function(index)) => index,
|
||||||
|
// _ => panic!("Function not found"),
|
||||||
|
// };
|
||||||
|
// let main: fn(&VmCtx) = get_instance_function!(instance, func_index);
|
||||||
|
// let context = instance.generate_context();
|
||||||
|
// main(&context);
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -15,7 +15,7 @@ const MAX_PAGES: u32 = 65536;
|
|||||||
/// This linear memory has a stable base address and at the same time allows
|
/// This linear memory has a stable base address and at the same time allows
|
||||||
/// for dynamical growing.
|
/// for dynamical growing.
|
||||||
pub struct LinearMemory {
|
pub struct LinearMemory {
|
||||||
mmap: MmapMut,
|
pub mmap: MmapMut,
|
||||||
// The initial size of the WebAssembly Memory, in units of
|
// The initial size of the WebAssembly Memory, in units of
|
||||||
// WebAssembly pages.
|
// WebAssembly pages.
|
||||||
current: u32,
|
current: u32,
|
||||||
|
Reference in New Issue
Block a user