mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 06:44:46 +00:00
wasm: Create a global for __stack_pointer
This commit is contained in:
parent
78cae6c3b3
commit
73f0a7c96c
3 changed files with 21 additions and 1 deletions
|
@ -86,6 +86,14 @@ impl<'a> WasmBackend<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
module.global.append(Global {
|
||||
ty: GlobalType {
|
||||
value_type: ValueType::I32,
|
||||
is_mutable: true,
|
||||
},
|
||||
init: ConstExpr::I32(1234), // TODO: come up with a value!
|
||||
});
|
||||
|
||||
module.export.exports = app_exports;
|
||||
module.code.code_builders.reserve(proc_lookup.len());
|
||||
|
||||
|
|
|
@ -105,6 +105,7 @@ impl<'a> WasmModule<'a> {
|
|||
let function = FunctionSection::parse(arena, bytes, &mut cursor)?;
|
||||
let table = TableSection::parse((), bytes, &mut cursor)?;
|
||||
let memory = MemorySection::parse(arena, bytes, &mut cursor)?;
|
||||
let global_start = cursor;
|
||||
let global = GlobalSection::parse(arena, bytes, &mut cursor)?;
|
||||
let export = ExportSection::parse(arena, bytes, &mut cursor)?;
|
||||
let start = OpaqueSection::parse((arena, SectionId::Start), bytes, &mut cursor)?;
|
||||
|
@ -127,6 +128,13 @@ impl<'a> WasmModule<'a> {
|
|||
let reloc_data = RelocationSection::parse((arena, "reloc.DATA"), bytes, &mut cursor)?;
|
||||
let names = NameSection::parse(arena, bytes, &mut cursor)?;
|
||||
|
||||
if global.count != 0 {
|
||||
return Err(ParseError {
|
||||
offset: global_start,
|
||||
message: format!("All globals in a relocatable Wasm module should be imported, but found {} internally defined", global.count),
|
||||
});
|
||||
}
|
||||
|
||||
Ok(WasmModule {
|
||||
types,
|
||||
import,
|
||||
|
|
|
@ -385,14 +385,15 @@ impl<'a> ImportSection<'a> {
|
|||
|
||||
impl<'a> Parse<&'a Bump> for ImportSection<'a> {
|
||||
fn parse(arena: &'a Bump, module_bytes: &[u8], cursor: &mut usize) -> Result<Self, ParseError> {
|
||||
let start = *cursor;
|
||||
let (count, range) = parse_section(Self::ID, module_bytes, cursor)?;
|
||||
let mut bytes = Vec::with_capacity_in(range.len() * 2, arena);
|
||||
let mut fn_signatures = Vec::with_capacity_in(range.len() / 8, arena);
|
||||
|
||||
let end = range.end;
|
||||
bytes.extend_from_slice(&module_bytes[range]);
|
||||
|
||||
while *cursor < end {
|
||||
let import_start = *cursor;
|
||||
String::skip_bytes(module_bytes, cursor)?; // import namespace
|
||||
String::skip_bytes(module_bytes, cursor)?; // import name
|
||||
|
||||
|
@ -403,6 +404,7 @@ impl<'a> Parse<&'a Bump> for ImportSection<'a> {
|
|||
ImportTypeId::Func => {
|
||||
let sig = u32::parse((), module_bytes, cursor)?;
|
||||
fn_signatures.push(sig);
|
||||
bytes.extend_from_slice(&module_bytes[import_start..*cursor]);
|
||||
}
|
||||
ImportTypeId::Table => {
|
||||
TableType::skip_bytes(module_bytes, cursor)?;
|
||||
|
@ -416,6 +418,8 @@ impl<'a> Parse<&'a Bump> for ImportSection<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
dbg!(bytes.len(), end - start);
|
||||
|
||||
Ok(ImportSection {
|
||||
count,
|
||||
fn_signatures,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue