Improve constant expression generation
This commit is contained in:
parent
16ce3eca98
commit
7f0158ef00
@ -51,18 +51,23 @@ fn gen_nil_array(name: &str, len: usize, w: &mut dyn Write) -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn gen_expression(code: &[Instruction], w: &mut dyn Write) -> Result<()> {
|
pub fn gen_expression(code: &[Instruction], w: &mut dyn Write) -> Result<()> {
|
||||||
assert!(code.len() == 2);
|
// FIXME: Badly generated WASM will produce the wrong constant.
|
||||||
|
for inst in code {
|
||||||
|
let result = match *inst {
|
||||||
|
Instruction::I32Const(v) => write!(w, "{} ", v),
|
||||||
|
Instruction::I64Const(v) => write!(w, "{} ", v),
|
||||||
|
Instruction::F32Const(v) => write!(w, "{} ", f32::from_bits(v)),
|
||||||
|
Instruction::F64Const(v) => write!(w, "{} ", f64::from_bits(v)),
|
||||||
|
Instruction::GetGlobal(i) => write!(w, "GLOBAL_LIST[{}].value ", i),
|
||||||
|
_ => {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let inst = code.first().unwrap();
|
return result;
|
||||||
|
|
||||||
match *inst {
|
|
||||||
Instruction::I32Const(v) => write!(w, "{} ", v),
|
|
||||||
Instruction::I64Const(v) => write!(w, "{} ", v),
|
|
||||||
Instruction::F32Const(v) => write!(w, "{} ", f32::from_bits(v)),
|
|
||||||
Instruction::F64Const(v) => write!(w, "{} ", f64::from_bits(v)),
|
|
||||||
Instruction::GetGlobal(i) => write!(w, "GLOBAL_LIST[{}].value ", i),
|
|
||||||
_ => unreachable!(),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unreachable!();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Module<'a> {
|
pub struct Module<'a> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user