wasm: generate code for ZigCC wrapper function

This commit is contained in:
Brian Carroll 2022-03-26 08:21:08 +00:00
parent 973d6dc41f
commit ff9bbfab63
4 changed files with 193 additions and 6 deletions

View file

@ -70,7 +70,7 @@ impl std::fmt::Debug for VmBlock<'_> {
/// Rust representation matches Wasm encoding.
/// It's an error to specify alignment higher than the "natural" alignment of the instruction
#[repr(u8)]
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, PartialEq, PartialOrd)]
pub enum Align {
Bytes1 = 0,
Bytes2 = 1,
@ -78,6 +78,23 @@ pub enum Align {
Bytes8 = 3,
}
impl Align {
/// Calculate the largest possible alignment for a load/store at a given stack frame offset
/// Assumes the stack frame is aligned to at least 8 bytes
pub fn from_stack_offset(max_align: Align, offset: u32) -> Align {
if (max_align == Align::Bytes8) && (offset & 7 == 0) {
return Align::Bytes8;
}
if (max_align >= Align::Bytes4) && (offset & 3 == 0) {
return Align::Bytes4;
}
if (max_align >= Align::Bytes2) && (offset & 1 == 0) {
return Align::Bytes2;
}
return Align::Bytes1;
}
}
impl From<u32> for Align {
fn from(x: u32) -> Align {
match x {