Link integer emit and runtime

This commit is contained in:
Rerumu
2022-05-21 02:50:11 -04:00
parent aea1df4e90
commit 3fa4fa5d83
4 changed files with 45 additions and 3 deletions
+15 -1
View File
@@ -66,6 +66,20 @@ impl Driver for MemoryGrow {
}
}
fn write_i64(number: i64, w: &mut dyn Write) -> Result<()> {
match number {
0 => write!(w, "num_K_ZERO "),
1 => write!(w, "num_K_ONE "),
_ => {
let list = number.to_ne_bytes();
let a = u32::from_ne_bytes(list[0..4].try_into().unwrap());
let b = u32::from_ne_bytes(list[4..8].try_into().unwrap());
write!(w, "num_from_u32({a}, {b}) ")
}
}
}
fn write_f32(number: f32, w: &mut dyn Write) -> Result<()> {
let sign = if number.is_sign_negative() { "-" } else { "" };
@@ -94,7 +108,7 @@ impl Driver for Value {
fn write(&self, _: &mut Manager, w: &mut dyn Write) -> Result<()> {
match self {
Self::I32(i) => write!(w, "{i} "),
Self::I64(i) => write!(w, "{i} "),
Self::I64(i) => write_i64(*i, w),
Self::F32(f) => write_f32(*f, w),
Self::F64(f) => write_f64(*f, w),
}
+7 -1
View File
@@ -3,6 +3,7 @@ use std::{
ops::Range,
};
use parity_wasm::elements::ValueType;
use wasm_ast::node::{
Backward, Br, BrIf, BrTable, Call, CallIndirect, Else, Forward, If, Intermediate, Memorize,
Return, SetGlobal, SetLocal, Statement, StoreAt,
@@ -262,13 +263,18 @@ fn write_variable_list(ir: &Intermediate, w: &mut dyn Write) -> Result<()> {
for data in &ir.local_data {
let range = total..total + usize::try_from(data.count()).unwrap();
let zero = if data.value_type() == ValueType::I64 {
"num_K_ZERO "
} else {
"0 "
};
total = range.end;
write!(w, "local ")?;
write_ascending("loc", range.clone(), w)?;
write!(w, " = ")?;
write_separated(range, |_, w| w.write_all(b"0"), w)?;
write_separated(range, |_, w| w.write_all(zero.as_bytes()), w)?;
write!(w, " ")?;
}