Skip to content

Instantly share code, notes, and snippets.

@steveklabnik
Created October 29, 2017 20:42
Embed
What would you like to do?
Module {
type_section: Some(
TypeSection(
[
FuncType {
params: [],
return_types: [
I32
]
}
]
)
),
function_section: Some(
FunctionSection(
[
Type(
0
)
]
)
),
table_section: Some(
TableSection(
[
Table {
elmtype: Anyfunc,
limit: Limit {
min: 0,
max: None
}
}
]
)
),
memory_section: Some(
MemorySection(
[
Mem(
Limit {
min: 0,
max: Some(
1
)
}
)
]
)
),
global_section: None,
export_section: Some(
ExportSection(
[
Export {
name: "memory",
description: ExportDescription(
Mem(
0
)
)
},
Export {
name: "main",
description: ExportDescription(
Func(
0
)
)
}
]
)
),
code_section: Some(
CodeSection(
[
Code {
locals: [],
instructions: [
I32Const(
0
)
]
}
]
)
)
}
(module
(table 0 anyfunc)
(memory $0 1)
(export "memory" (memory $0))
(export "main" (func $main))
(func $main (result i32)
(i32.const 0)
)
)
@binji
Copy link

binji commented Oct 31, 2017

(responding to your comment on #WebAssembly irc)

hey all; I have a basic question, if anyone's around. https://gist.github.com/steveklabnik/a3f2357a5bf8d5f4dd4374b4a3fa60ed <- this has a sexpr-based wasm file, and the output of a parser i wrote. in the sexpr format, it's clear how functions are defined: the name, return type, body. but in the binary format, the export points to the function section, and the function section contains indexes to the type section. but how does the code section relate to the function/type sections?

Yeah, it's not super clear from the spec doc, but basically a given function uses the same index into the function section and the code section. It basically splits the func into two parts where type is defined in the function section and locals and body are defined in the code section.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment