mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-01 15:51:12 +00:00
Wasm: Serialize WasmModule without linking info
This commit is contained in:
parent
b8ab6af203
commit
5a39002e8b
6 changed files with 75 additions and 5 deletions
|
@ -156,6 +156,12 @@ pub struct CodeBuilder<'a> {
|
|||
relocations: Vec<'a, RelocationEntry>,
|
||||
}
|
||||
|
||||
impl<'a> Serialize for CodeBuilder<'a> {
|
||||
fn serialize<T: SerialBuffer>(&self, buffer: &mut T) {
|
||||
self.serialize_without_relocs(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::new_without_default)]
|
||||
impl<'a> CodeBuilder<'a> {
|
||||
pub fn new(arena: &'a Bump) -> Self {
|
||||
|
@ -470,6 +476,35 @@ impl<'a> CodeBuilder<'a> {
|
|||
|
||||
***********************************************************/
|
||||
|
||||
/// Serialize all byte vectors in the right order
|
||||
/// Also update relocation offsets relative to the base offset (code section body start)
|
||||
pub fn serialize_without_relocs<T: SerialBuffer>(&self, buffer: &mut T) {
|
||||
buffer.append_slice(&self.inner_length);
|
||||
buffer.append_slice(&self.preamble);
|
||||
|
||||
let mut code_pos = 0;
|
||||
let mut insert_iter = self.insertions.iter();
|
||||
loop {
|
||||
let next_insert = insert_iter.next();
|
||||
let next_pos = match next_insert {
|
||||
Some(Insertion { at, .. }) => *at,
|
||||
None => self.code.len(),
|
||||
};
|
||||
|
||||
buffer.append_slice(&self.code[code_pos..next_pos]);
|
||||
|
||||
match next_insert {
|
||||
Some(Insertion { at, start, end }) => {
|
||||
buffer.append_slice(&self.insert_bytes[*start..*end]);
|
||||
code_pos = *at;
|
||||
}
|
||||
None => {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Serialize all byte vectors in the right order
|
||||
/// Also update relocation offsets relative to the base offset (code section body start)
|
||||
pub fn serialize_with_relocs<T: SerialBuffer>(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue