mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 22:34:45 +00:00
Wasm: Create OpaqueSection for sections that may be used in builtins but not by us
This commit is contained in:
parent
738434329e
commit
a1f737d6d8
2 changed files with 34 additions and 10 deletions
|
@ -23,7 +23,7 @@ use crate::wasm_module::linking::{
|
|||
};
|
||||
use crate::wasm_module::sections::{
|
||||
CodeSection, DataMode, DataSection, DataSegment, ExportSection, FunctionSection, GlobalSection,
|
||||
Import, ImportDesc, ImportSection, MemorySection, TypeSection, WasmModule,
|
||||
Import, ImportDesc, ImportSection, MemorySection, OpaqueSection, TypeSection, WasmModule,
|
||||
};
|
||||
use crate::wasm_module::{
|
||||
code_builder, CodeBuilder, ConstExpr, Export, ExportType, Global, GlobalType, LocalId,
|
||||
|
@ -109,14 +109,14 @@ impl<'a> WasmBackend<'a> {
|
|||
types: TypeSection::new(arena, num_procs),
|
||||
import: ImportSection::new(arena),
|
||||
function: FunctionSection::new(arena, num_procs),
|
||||
table: (),
|
||||
table: OpaqueSection::default(),
|
||||
memory: MemorySection::new(MEMORY_INIT_SIZE),
|
||||
global: GlobalSection {
|
||||
entries: bumpalo::vec![in arena; stack_pointer],
|
||||
},
|
||||
export: ExportSection { entries: exports },
|
||||
start: (),
|
||||
element: (),
|
||||
start: OpaqueSection::default(),
|
||||
element: OpaqueSection::default(),
|
||||
code: CodeSection {
|
||||
preloaded_count: 0,
|
||||
preloaded_bytes: Vec::with_capacity_in(0, arena),
|
||||
|
|
|
@ -627,20 +627,44 @@ impl SectionCounter {
|
|||
}
|
||||
}
|
||||
|
||||
/// A Wasm module section that we don't use for Roc code,
|
||||
/// but may be present in a preloaded binary
|
||||
#[derive(Debug)]
|
||||
pub struct OpaqueSection<'a> {
|
||||
bytes: &'a [u8],
|
||||
}
|
||||
|
||||
impl<'a> OpaqueSection<'a> {
|
||||
pub fn new(bytes: &'a [u8]) -> Self {
|
||||
Self { bytes }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Default for OpaqueSection<'a> {
|
||||
fn default() -> Self {
|
||||
Self { bytes: &[] }
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for OpaqueSection<'_> {
|
||||
fn serialize<T: SerialBuffer>(&self, buffer: &mut T) {
|
||||
if !self.bytes.is_empty() {
|
||||
buffer.append_slice(&self.bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct WasmModule<'a> {
|
||||
pub types: TypeSection<'a>,
|
||||
pub import: ImportSection<'a>,
|
||||
pub function: FunctionSection<'a>,
|
||||
/// Dummy placeholder for tables (used for function pointers and host references)
|
||||
pub table: (),
|
||||
pub table: OpaqueSection<'a>,
|
||||
pub memory: MemorySection,
|
||||
pub global: GlobalSection<'a>,
|
||||
pub export: ExportSection<'a>,
|
||||
/// Dummy placeholder for start function. In Roc, this would be part of the platform.
|
||||
pub start: (),
|
||||
/// Dummy placeholder for table elements. Roc does not use tables.
|
||||
pub element: (),
|
||||
pub start: OpaqueSection<'a>,
|
||||
pub element: OpaqueSection<'a>,
|
||||
pub code: CodeSection<'a>,
|
||||
pub data: DataSection<'a>,
|
||||
pub linking: LinkingSection<'a>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue