From 88eb7be90cfa48808f2416e427498a97b1d71faa Mon Sep 17 00:00:00 2001 From: Julgodis <> Date: Tue, 30 Mar 2021 01:29:50 +0200 Subject: [PATCH] removed double references and fixed float generation --- tools/libdol2asm/data/base.py | 5 ++++- tools/libdol2asm/exporter/cpp_exporter.py | 18 ++++++++++++++++++ tools/libdol2asm/generate_symbols.py | 8 ++++++-- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/tools/libdol2asm/data/base.py b/tools/libdol2asm/data/base.py index 3b3b8c029c3..72d922af087 100644 --- a/tools/libdol2asm/data/base.py +++ b/tools/libdol2asm/data/base.py @@ -54,6 +54,9 @@ class ArbitraryData(Symbol): exporter, builder: AsyncBuilder, c_export: bool = False): + if not c_export: + return + if self.is_static: if not self.force_section and not self.require_forward_reference: return @@ -64,7 +67,7 @@ class ArbitraryData(Symbol): await self.export_extern(builder) name = self.identifier.label - if not c_export and self.demangled_name: + if self.demangled_name: name = self.demangled_name.to_str(specialize_templates=False, without_template=False) diff --git a/tools/libdol2asm/exporter/cpp_exporter.py b/tools/libdol2asm/exporter/cpp_exporter.py index ef732130042..ced0573a74e 100644 --- a/tools/libdol2asm/exporter/cpp_exporter.py +++ b/tools/libdol2asm/exporter/cpp_exporter.py @@ -52,6 +52,15 @@ class CPPExporter: await builder.write("") break + for symbol in section.symbols: + if symbol.identifier.label == "__init_cpp_exceptions_reference": + continue + if symbol.identifier.label == "_ctors": + continue + await self.export_symbol_header(builder, symbol) + await symbol.export_declaration(self, builder) + await builder.write("") + async def export_section_dtors(self, builder: AsyncBuilder, section: Section): await builder.write("#pragma section \".dtors$10\"") for symbol in section.symbols: @@ -69,6 +78,15 @@ class CPPExporter: await builder.write("") break + for symbol in section.symbols: + if symbol.identifier.label == "__destroy_global_chain_reference": + continue + if symbol.identifier.label == "__fini_cpp_exceptions_reference": + continue + await self.export_symbol_header(builder, symbol) + await symbol.export_declaration(self, builder) + await builder.write("") + async def export_declarations(self, builder: AsyncBuilder, tu: TranslationUnit, diff --git a/tools/libdol2asm/generate_symbols.py b/tools/libdol2asm/generate_symbols.py index fc76d1ff237..e04dd975c51 100644 --- a/tools/libdol2asm/generate_symbols.py +++ b/tools/libdol2asm/generate_symbols.py @@ -156,7 +156,9 @@ def value_initialized_symbol(section: Section, # Metrowerks is very smart... if you initialize a float with 0.0f, the storage will be moved to the one of the .bss sections. # Generated literals will always be (for floats and doubles) in the .sdata2 section. Thus, if we are a literal, we cannot # use the value 0.0f. - if padding_values and len(values) > 0 and not (len(values) == 1 and values[0][0] == 0): + is_zero = (len(values) == 1 and values[0][0] == 0) + is_zero_and_no_padding = is_zero and len(padding_values) == 0 + if len(values) > 0 and not is_zero_and_no_padding: return [FloatingPoint.create_f32(identifier, symbol.addr, values, padding_values)] if isinstance(symbol.access, DoubleLoadAccess): @@ -165,7 +167,9 @@ def value_initialized_symbol(section: Section, padding_values = FloatingPoint.f64_from(padding_data) # Same comments as for the float case. - if padding_values and len(values) > 0 and not (len(values) == 1 and values[0][0] == 0): + is_zero = (len(values) == 1 and values[0][0] == 0) + is_zero_and_no_padding = is_zero and len(padding_values) == 0 + if len(values) > 0 and not is_zero_and_no_padding: return [FloatingPoint.create_f64(identifier, symbol.addr, values, padding_values)] if symbol.size == 4 and len(padding_data) % 4 == 0: