Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial implementation of module linking #26

Merged
merged 7 commits into from
Jun 18, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix custom section annotations
  • Loading branch information
alexcrichton committed Jun 18, 2020
commit 96cfce9d0125df8def7c9b342e2a1ef77c79b851
53 changes: 31 additions & 22 deletions crates/wast/src/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,30 +81,39 @@ fn encode_fields(
_ => false,
})
.peekable();
while let Some(field) = items.next() {
macro_rules! list {
($code:expr, $name:ident) => {
list!($code, $name, $name, |f| f)
};
($code:expr, $field:ident, $custom:ident, |$f:ident| $e:expr) => {
if let ModuleField::$field($f) = field {
let mut list = vec![$e];
while let Some(ModuleField::$field($f)) = items.peek() {
list.push($e);
items.next();

// A special path is used for now to handle non-module-linking modules to
// work around WebAssembly/annotations#11
if aliases.len() == 0 && modules.len() == 0 && instances.len() == 0 {
e.section_list(1, Type, &types);
e.section_list(2, Import, &imports);
} else {
while let Some(field) = items.next() {
macro_rules! list {
($code:expr, $name:ident) => {
list!($code, $name, $name, |f| f)
};
($code:expr, $field:ident, $custom:ident, |$f:ident| $e:expr) => {
if let ModuleField::$field($f) = field {
let mut list = vec![$e];
while let Some(ModuleField::$field($f)) = items.peek() {
list.push($e);
items.next();
}
e.section_list($code, $custom, &list);
}
e.section_list($code, $custom, &list);
}
};
};
}
list!(1, Type);
list!(2, Import);
list!(100, NestedModule, Module, |m| match &m.kind {
NestedModuleKind::Inline { ty, .. } =>
ty.as_ref().expect("type should be filled in"),
_ => panic!("only inline modules should be present now"),
});
list!(101, Instance);
list!(102, Alias);
}
list!(1, Type);
list!(2, Import);
list!(100, NestedModule, Module, |m| match &m.kind {
NestedModuleKind::Inline { ty, .. } => ty.as_ref().expect("type should be filled in"),
_ => panic!("only inline modules should be present now"),
});
list!(101, Instance);
list!(102, Alias);
}

let functys = funcs.iter().map(|f| &f.ty).collect::<Vec<_>>();
Expand Down