Browse Source

Add i32 literals support.

pull/397/head
Sergey Pepyakin 6 years ago
committed by Dan Gohman
parent
commit
38590cbcb9
  1. 10
      src/backend.rs
  2. 3
      src/function_body.rs
  3. 14
      src/tests.rs

10
src/backend.rs

@ -261,7 +261,7 @@ pub fn get_local_i32(ctx: &mut Context, local_idx: u32) {
push_i32(ctx, gpr);
}
pub fn store_i32(ctx: &mut Context, local_idx: u32) {
pub fn set_local_i32(ctx: &mut Context, local_idx: u32) {
let gpr = pop_i32(ctx);
let offset = sp_relative_offset(ctx, local_idx);
dynasm!(ctx.asm
@ -270,6 +270,14 @@ pub fn store_i32(ctx: &mut Context, local_idx: u32) {
ctx.regs.release_scratch_gpr(gpr);
}
pub fn literal_i32(ctx: &mut Context, imm: i32) {
let gpr = ctx.regs.take_scratch_gpr();
dynasm!(ctx.asm
; mov Rd(gpr), imm
);
push_i32(ctx, gpr);
}
pub fn relop_eq_i32(ctx: &mut Context) {
let right = pop_i32(ctx);
let left = pop_i32(ctx);

3
src/function_body.rs

@ -217,6 +217,9 @@ pub fn translate(
Operator::GetLocal { local_index } => {
get_local_i32(&mut ctx, local_index);
}
Operator::I32Const { value } => {
literal_i32(&mut ctx, value);
}
Operator::Call { function_index } => {
let callee_ty = translation_ctx.func_type(function_index);
assert!(callee_ty.returns.len() == 0, "is not supported");

14
src/tests.rs

@ -129,4 +129,18 @@ fn function_call() {
assert_eq!(execute_wat(code, 2, 0), 2);
}
#[test]
fn literals() {
let code = r#"
(module
(func (param i32) (param i32) (result i32)
(i32.const 228)
)
)
"#;
assert_eq!(execute_wat(code, 0, 0), 228);
}
// TODO: Add a test that checks argument passing via the stack.

Loading…
Cancel
Save