Compile a simple function (#2)
* Implement basics. * Execute code * Add wasm2wat test cases. * abi_loc_for_arg for stack. * Assert that sp_depth is 0 at the epilogue * Do 32bit add. * Assert that RAX can be used as a scratch register * Reuse assembler. * Align stack slots.
This commit is contained in:
committed by
Dan Gohman
parent
d3bc26bc93
commit
08240761d5
34
src/tests.rs
Normal file
34
src/tests.rs
Normal file
@@ -0,0 +1,34 @@
|
||||
use super::{translate, TranslatedModule};
|
||||
use wabt;
|
||||
|
||||
fn translate_wat(wat: &str) -> TranslatedModule {
|
||||
let wasm = wabt::wat2wasm(wat).unwrap();
|
||||
let compiled = translate(&wasm).unwrap();
|
||||
compiled
|
||||
}
|
||||
|
||||
/// Execute the first function in the module.
|
||||
fn execute_wat(wat: &str, a: usize, b: usize) -> usize {
|
||||
let translated = translate_wat(wat);
|
||||
translated.execute_func(0, a, b)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn adds() {
|
||||
const CASES: &[(usize, usize, usize)] = &[
|
||||
(5, 3, 8),
|
||||
(0, 228, 228),
|
||||
(usize::max_value(), 1, 0),
|
||||
];
|
||||
|
||||
let code = r#"
|
||||
(module
|
||||
(func (param i32) (param i32) (result i32) (i32.add (get_local 0) (get_local 1)))
|
||||
)
|
||||
"#;
|
||||
for (a, b, expected) in CASES {
|
||||
assert_eq!(execute_wat(code, *a, *b), *expected);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Add a test that checks argument passing via the stack.
|
||||
Reference in New Issue
Block a user