mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-05 01:20:20 +00:00
Move some wasm constants and macros
This commit is contained in:
parent
63d9187343
commit
2e67bdf4d0
4 changed files with 31 additions and 29 deletions
|
@ -14,8 +14,6 @@ pub use sections::{ConstExpr, Export, ExportType, Global, GlobalType, Signature}
|
|||
use bitvec::vec::BitVec;
|
||||
use bumpalo::{collections::Vec, Bump};
|
||||
|
||||
use crate::DEBUG_SETTINGS;
|
||||
|
||||
use self::linking::{IndexRelocType, LinkingSection, RelocationSection, WasmObjectSymbol};
|
||||
use self::parse::{Parse, ParseError};
|
||||
use self::sections::{
|
||||
|
@ -25,6 +23,9 @@ use self::sections::{
|
|||
};
|
||||
use self::serialize::{SerialBuffer, Serialize};
|
||||
|
||||
pub const STACK_POINTER_GLOBAL_ID: u32 = 0;
|
||||
pub const FRAME_ALIGNMENT_BYTES: i32 = 16;
|
||||
|
||||
/// A representation of the WebAssembly binary file format
|
||||
/// https://webassembly.github.io/spec/core/binary/modules.html
|
||||
#[derive(Debug)]
|
||||
|
@ -593,3 +594,23 @@ impl<'a> WasmModule<'a> {
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// Round up to alignment_bytes (which must be a power of 2)
|
||||
#[macro_export]
|
||||
macro_rules! round_up_to_alignment {
|
||||
($unaligned: expr, $alignment_bytes: expr) => {
|
||||
if $alignment_bytes <= 1 {
|
||||
$unaligned
|
||||
} else if $alignment_bytes.count_ones() != 1 {
|
||||
internal_error!(
|
||||
"Cannot align to {} bytes. Not a power of 2.",
|
||||
$alignment_bytes
|
||||
);
|
||||
} else {
|
||||
let mut aligned = $unaligned;
|
||||
aligned += $alignment_bytes - 1; // if lower bits are non-zero, push it over the next boundary
|
||||
aligned &= !$alignment_bytes + 1; // mask with a flag that has upper bits 1, lower bits 0
|
||||
aligned
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue