mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 06:44:46 +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::{
|
use crate::wasm_module::sections::{
|
||||||
CodeSection, DataMode, DataSection, DataSegment, ExportSection, FunctionSection, GlobalSection,
|
CodeSection, DataMode, DataSection, DataSegment, ExportSection, FunctionSection, GlobalSection,
|
||||||
Import, ImportDesc, ImportSection, MemorySection, TypeSection, WasmModule,
|
Import, ImportDesc, ImportSection, MemorySection, OpaqueSection, TypeSection, WasmModule,
|
||||||
};
|
};
|
||||||
use crate::wasm_module::{
|
use crate::wasm_module::{
|
||||||
code_builder, CodeBuilder, ConstExpr, Export, ExportType, Global, GlobalType, LocalId,
|
code_builder, CodeBuilder, ConstExpr, Export, ExportType, Global, GlobalType, LocalId,
|
||||||
|
@ -109,14 +109,14 @@ impl<'a> WasmBackend<'a> {
|
||||||
types: TypeSection::new(arena, num_procs),
|
types: TypeSection::new(arena, num_procs),
|
||||||
import: ImportSection::new(arena),
|
import: ImportSection::new(arena),
|
||||||
function: FunctionSection::new(arena, num_procs),
|
function: FunctionSection::new(arena, num_procs),
|
||||||
table: (),
|
table: OpaqueSection::default(),
|
||||||
memory: MemorySection::new(MEMORY_INIT_SIZE),
|
memory: MemorySection::new(MEMORY_INIT_SIZE),
|
||||||
global: GlobalSection {
|
global: GlobalSection {
|
||||||
entries: bumpalo::vec![in arena; stack_pointer],
|
entries: bumpalo::vec![in arena; stack_pointer],
|
||||||
},
|
},
|
||||||
export: ExportSection { entries: exports },
|
export: ExportSection { entries: exports },
|
||||||
start: (),
|
start: OpaqueSection::default(),
|
||||||
element: (),
|
element: OpaqueSection::default(),
|
||||||
code: CodeSection {
|
code: CodeSection {
|
||||||
preloaded_count: 0,
|
preloaded_count: 0,
|
||||||
preloaded_bytes: Vec::with_capacity_in(0, arena),
|
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)]
|
#[derive(Debug)]
|
||||||
pub struct WasmModule<'a> {
|
pub struct WasmModule<'a> {
|
||||||
pub types: TypeSection<'a>,
|
pub types: TypeSection<'a>,
|
||||||
pub import: ImportSection<'a>,
|
pub import: ImportSection<'a>,
|
||||||
pub function: FunctionSection<'a>,
|
pub function: FunctionSection<'a>,
|
||||||
/// Dummy placeholder for tables (used for function pointers and host references)
|
pub table: OpaqueSection<'a>,
|
||||||
pub table: (),
|
|
||||||
pub memory: MemorySection,
|
pub memory: MemorySection,
|
||||||
pub global: GlobalSection<'a>,
|
pub global: GlobalSection<'a>,
|
||||||
pub export: ExportSection<'a>,
|
pub export: ExportSection<'a>,
|
||||||
/// Dummy placeholder for start function. In Roc, this would be part of the platform.
|
pub start: OpaqueSection<'a>,
|
||||||
pub start: (),
|
pub element: OpaqueSection<'a>,
|
||||||
/// Dummy placeholder for table elements. Roc does not use tables.
|
|
||||||
pub element: (),
|
|
||||||
pub code: CodeSection<'a>,
|
pub code: CodeSection<'a>,
|
||||||
pub data: DataSection<'a>,
|
pub data: DataSection<'a>,
|
||||||
pub linking: LinkingSection<'a>,
|
pub linking: LinkingSection<'a>,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue