From ed1c7b1b5134790b0d3c4480a7c255f4e98d5f25 Mon Sep 17 00:00:00 2001 From: NikVolf Date: Tue, 22 Jan 2019 14:42:57 +0300 Subject: [PATCH] better exports --- src/graph.rs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/graph.rs b/src/graph.rs index 51fb4ff..dcfc32e 100644 --- a/src/graph.rs +++ b/src/graph.rs @@ -58,13 +58,18 @@ struct ElementSegment { data: Vec, } -enum Export { +enum ExportLocal { Func(EntryRef), Global(EntryRef), Table(EntryRef), Memory(EntryRef), } +struct Export { + name: String, + local: ExportLocal, +} + #[derive(Default)] struct Module { types: RefList, @@ -157,20 +162,22 @@ impl Module { }, elements::Section::Export(export_section) => { for e in export_section.entries() { - match e.internal() { + let local = match e.internal() { &elements::Internal::Function(func_idx) => { - res.exports.push(Export::Func(res.funcs.clone_ref(func_idx as usize))); + ExportLocal::Func(res.funcs.clone_ref(func_idx as usize)) }, &elements::Internal::Global(global_idx) => { - res.exports.push(Export::Global(res.globals.clone_ref(global_idx as usize))); + ExportLocal::Global(res.globals.clone_ref(global_idx as usize)) }, &elements::Internal::Memory(mem_idx) => { - res.exports.push(Export::Memory(res.memory.clone_ref(mem_idx as usize))); + ExportLocal::Memory(res.memory.clone_ref(mem_idx as usize)) }, &elements::Internal::Table(table_idx) => { - res.exports.push(Export::Table(res.tables.clone_ref(table_idx as usize))); + ExportLocal::Table(res.tables.clone_ref(table_idx as usize)) }, - } + }; + + res.exports.push(Export { local: local, name: e.field().to_owned() }) } }, _ => continue,