From 021acb960b51fc845e41caaed1042743b2a4085f Mon Sep 17 00:00:00 2001 From: Dennis Ranke Date: Mon, 8 Nov 2021 09:21:02 +0100 Subject: [PATCH] add support for data and start section in uw8-tool --- uw8-tool/src/pack.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/uw8-tool/src/pack.rs b/uw8-tool/src/pack.rs index 16fbbd7..c0af851 100644 --- a/uw8-tool/src/pack.rs +++ b/uw8-tool/src/pack.rs @@ -106,7 +106,9 @@ struct ParsedModule<'a> { globals: Option>, functions: Section>, exports: Section>, + start_section: Option, function_bodies: Vec>, + data_section: Option>, } impl<'a> ParsedModule<'a> { @@ -118,7 +120,9 @@ impl<'a> ParsedModule<'a> { let mut global_section = None; let mut function_section = None; let mut export_section = None; + let mut start_section = None; let mut function_bodies = Vec::new(); + let mut data_section = None; let mut offset = 0; @@ -152,6 +156,12 @@ impl<'a> ParsedModule<'a> { Payload::ExportSection(reader) => { export_section = Some(Section::new(range, read_export_section(reader)?)); } + Payload::StartSection { func, .. } => { + start_section = Some(func); + } + Payload::DataSection(_) => { + data_section = Some(Section::new(range, ())); + } Payload::CodeSectionStart { .. } => (), Payload::CodeSectionEntry(body) => function_bodies.push(body), Payload::CustomSection { .. } => (), @@ -169,7 +179,9 @@ impl<'a> ParsedModule<'a> { globals: global_section, functions: function_section.ok_or_else(|| anyhow!("No function section found"))?, exports: export_section.ok_or_else(|| anyhow!("No export section found"))?, + start_section, function_bodies, + data_section, }) } @@ -378,9 +390,16 @@ impl<'a> ParsedModule<'a> { for (name, fnc) in my_exports { export_section.export(&name, enc::Export::Function(fnc)); } + module.section(&export_section); } } + if let Some(start_function) = self.start_section { + module.section(&enc::StartSection { + function_index: start_function, + }); + } + { let mut code_section = enc::CodeSection::new(); @@ -396,6 +415,10 @@ impl<'a> ParsedModule<'a> { module.section(&code_section); } + if let Some(ref data_section) = self.data_section { + copy_section(&mut module, &self.data[data_section.range.clone()])?; + } + Ok(module.finish()) } } @@ -544,7 +567,7 @@ fn read_export_section(reader: ExportSectionReader) -> Result ExternalKind::Function => { function_exports.push((export.field.to_string(), export.index)); } - _ => bail!("Only function exports supported, found {:?}", export.kind), + _ => (), // just ignore all other kinds since MicroW8 doesn't expect any exports other than functions } } Ok(function_exports)