diff --git a/CHANGELOG.md b/CHANGELOG.md index 7df75e32..e4d1b76a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * New yaml option: `hasm_in_src_path` * Tells splat to consider `hasm` files to be relative to `src_path` instead of `asm_path`. +* Remove some dead code. ### 0.21.3 diff --git a/src/splat/segtypes/__init__.py b/src/splat/segtypes/__init__.py index 94d7a34e..be0655b1 100644 --- a/src/splat/segtypes/__init__.py +++ b/src/splat/segtypes/__init__.py @@ -1,4 +1,3 @@ -from . import address_range as address_range from . import linker_entry as linker_entry from . import segment as segment diff --git a/src/splat/segtypes/address_range.py b/src/splat/segtypes/address_range.py deleted file mode 100644 index 0c57cc0d..00000000 --- a/src/splat/segtypes/address_range.py +++ /dev/null @@ -1,10 +0,0 @@ -from dataclasses import dataclass - - -@dataclass -class AddressRange: - start: int - end: int - - def contains(self, addr: int) -> bool: - return self.start <= addr < self.end diff --git a/src/splat/segtypes/common/code.py b/src/splat/segtypes/common/code.py index 065d822f..ec9e43da 100644 --- a/src/splat/segtypes/common/code.py +++ b/src/splat/segtypes/common/code.py @@ -39,9 +39,6 @@ def __init__( ) self.reported_file_split = False - self.jtbl_glabels_to_add: Set[int] = set() - self.jumptables: Dict[int, Tuple[int, int]] = {} - self.rodata_syms: Dict[int, List[Symbol]] = {} self.align = parse_segment_align(yaml) if self.align is None: @@ -58,27 +55,6 @@ def vram_end(self) -> Optional[int]: else: return None - def check_rodata_sym_impl(self, func_addr: int, sym: Symbol, rodata_section: Range): - if rodata_section.is_complete(): - assert rodata_section.start is not None - assert rodata_section.end is not None - - rodata_start: int = rodata_section.start - rodata_end: int = rodata_section.end - if rodata_start <= sym.vram_start < rodata_end: - if func_addr not in self.rodata_syms: - self.rodata_syms[func_addr] = [] - self.rodata_syms[func_addr].append(sym) - - # Prepare symbol for migration to the function - def check_rodata_sym(self, func_addr: int, sym: Symbol): - rodata_section = self.section_boundaries.get(".rodata") - if rodata_section is not None: - self.check_rodata_sym_impl(func_addr, sym, rodata_section) - rodata_section = self.section_boundaries.get(".rdata") - if rodata_section is not None: - self.check_rodata_sym_impl(func_addr, sym, rodata_section) - def handle_alls(self, segs: List[Segment], base_segs) -> bool: for i, elem in enumerate(segs): if elem.type.startswith("all_"): @@ -168,13 +144,10 @@ def parse_subsegments(self, segment_yaml) -> List[Segment]: OrderedDict() ) # Used to manually add "all_" types for sections not otherwise defined in the yaml - self.section_boundaries = OrderedDict( + # Stores yaml index where a section was first found + found_sections = OrderedDict( (s_name, Range()) for s_name in options.opts.section_order ) - - found_sections = OrderedDict( - (s_name, Range()) for s_name in self.section_boundaries - ) # Stores yaml index where a section was first found found_sections.pop(".text") # Mark any manually added dot types @@ -334,15 +307,6 @@ def parse_subsegments(self, segment_yaml) -> List[Segment]: if segment.special_vram_segment: self.special_vram_segment = True - for i, section in enumerate(self.section_order): - if not self.section_boundaries[section].has_start() and dotless_type( - section - ) == dotless_type(segment.type): - if i > 0: - prev_section = self.section_order[i - 1] - self.section_boundaries[prev_section].end = segment.vram_start - self.section_boundaries[section].start = segment.vram_start - segment.bss_contains_common = self.bss_contains_common ret.append(segment) @@ -399,18 +363,6 @@ def parse_subsegments(self, segment_yaml) -> List[Segment]: while check: check = self.handle_alls(ret, base_segments) - # TODO why is this necessary? - rodata_section = self.section_boundaries.get( - ".rodata" - ) or self.section_boundaries.get(".rdata") - if ( - rodata_section is not None - and rodata_section.has_start() - and not rodata_section.has_end() - ): - assert self.vram_end is not None - rodata_section.end = self.vram_end - return ret def scan(self, rom_bytes): diff --git a/src/splat/segtypes/common/codesubsegment.py b/src/splat/segtypes/common/codesubsegment.py index 2bbf8703..44d38b40 100644 --- a/src/splat/segtypes/common/codesubsegment.py +++ b/src/splat/segtypes/common/codesubsegment.py @@ -89,15 +89,6 @@ def scan_code(self, rom_bytes, is_hasm=False): self.process_insns(func) - # Process jumptable labels and pass them to spimdisasm - self.gather_jumptable_labels(rom_bytes) - for jtbl_label_vram in self.parent.jtbl_glabels_to_add: - sym = self.create_symbol( - jtbl_label_vram, True, type="jtbl_label", define=True - ) - sym.type = "jtbl_label" - symbols.add_symbol_to_spim_section(self.spim_section.get_section(), sym) - def process_insns( self, func_spim: spimdisasm.mips.symbols.SymbolFunction, @@ -112,21 +103,6 @@ def process_insns( self.get_most_parent(), func_spim.contextSym ) - # Gather symbols found by spimdisasm and create those symbols in splat's side - for referenced_vram in func_spim.instrAnalyzer.referencedVrams: - context_sym = self.spim_section.get_section().getSymbol( - referenced_vram, tryPlusOffset=False - ) - if context_sym is not None: - if context_sym.type == spimdisasm.common.SymbolSpecialType.jumptable: - self.parent.jumptables[referenced_vram] = ( - func_spim.vram, - func_spim.vramEnd, - ) - symbols.create_symbol_from_spim_symbol( - self.get_most_parent(), context_sym - ) - # Main loop for i, insn in enumerate(func_spim.instructions): if options.opts.platform == "ps2": @@ -149,13 +125,10 @@ def process_insns( sym_address, tryPlusOffset=False ) if context_sym is not None: - sym = symbols.create_symbol_from_spim_symbol( + symbols.create_symbol_from_spim_symbol( self.get_most_parent(), context_sym ) - if self.parent: - self.parent.check_rodata_sym(func_spim.vram, sym) - def print_file_boundaries(self): if not self.show_file_boundaries or not self.spim_section: return @@ -187,29 +160,6 @@ def print_file_boundaries(self): ) print(f" - [0x{self.rom_start+in_file_offset:X}, {self.type}]") - def gather_jumptable_labels(self, rom_bytes): - assert isinstance(self.rom_start, int) - assert isinstance(self.vram_start, int) - - # TODO: use the seg_symbols for this - # jumptables = [j.type == "jtbl" for j in self.seg_symbols] - for jumptable in self.parent.jumptables: - start, end = self.parent.jumptables[jumptable] - rom_offset = self.rom_start + jumptable - self.vram_start - - if rom_offset <= 0: - return - - while rom_offset: - word = rom_bytes[rom_offset : rom_offset + 4] - word_int = int.from_bytes(word, options.opts.endianness) - if word_int >= start and word_int <= end: - self.parent.jtbl_glabels_to_add.add(word_int) - else: - break - - rom_offset += 4 - def should_scan(self) -> bool: return ( options.opts.is_mode_active("code") diff --git a/src/splat/segtypes/segment.py b/src/splat/segtypes/segment.py index 3cf48243..fdc5ff6f 100644 --- a/src/splat/segtypes/segment.py +++ b/src/splat/segtypes/segment.py @@ -762,11 +762,3 @@ def create_symbol( assert ret is not None return ret - - def get_func_for_addr(self, addr) -> Optional[Symbol]: - for syms in self.seg_symbols.values(): - for sym in syms: - if sym.type == "func" and sym.contains_vram(addr): - return sym - - return None diff --git a/src/splat/util/__init__.py b/src/splat/util/__init__.py index 72992643..9e667f4b 100644 --- a/src/splat/util/__init__.py +++ b/src/splat/util/__init__.py @@ -1,7 +1,6 @@ from . import cache_handler as cache_handler from . import color as color from . import compiler as compiler -from . import floats as floats from . import gc as gc from . import log as log from . import n64 as n64 diff --git a/src/splat/util/floats.py b/src/splat/util/floats.py deleted file mode 100644 index 009725e7..00000000 --- a/src/splat/util/floats.py +++ /dev/null @@ -1,63 +0,0 @@ -import math -import struct - - -# From mips_to_c: https://github.com/matt-kempster/mips_to_c/blob/d208400cca045113dada3e16c0d59c50cdac4529/src/translate.py#L2085 -def format_f32_imm(num: int) -> str: - packed = struct.pack(">I", num & (2**32 - 1)) - value = struct.unpack(">f", packed)[0] - - if not value or value == 4294967296.0: - # Zero, negative zero, nan, or INT_MAX. - return str(value) - - # Write values smaller than 1e-7 / greater than 1e7 using scientific notation, - # and values in between using fixed point. - if abs(math.log10(abs(value))) > 6.9: - fmt_char = "e" - elif abs(value) < 1: - fmt_char = "f" - else: - fmt_char = "g" - - def fmt(prec: int) -> str: - """Format 'value' with 'prec' significant digits/decimals, in either scientific - or regular notation depending on 'fmt_char'.""" - ret = ("{:." + str(prec) + fmt_char + "}").format(value) - if fmt_char == "e": - return ret.replace("e+", "e").replace("e0", "e").replace("e-0", "e-") - if "e" in ret: - # The "g" format character can sometimes introduce scientific notation if - # formatting with too few decimals. If this happens, return an incorrect - # value to prevent the result from being used. - # - # Since the value we are formatting is within (1e-7, 1e7) in absolute - # value, it will at least be possible to format with 7 decimals, which is - # less than float precision. Thus, this annoying Python limitation won't - # lead to us outputting numbers with more precision than we really have. - return "0" - return ret - - # 20 decimals is more than enough for a float. Start there, then try to shrink it. - prec = 20 - while prec > 0: - prec -= 1 - value2 = float(fmt(prec)) - if struct.pack(">f", value2) != packed: - prec += 1 - break - - if prec == 20: - # Uh oh, even the original value didn't format correctly. Fall back to str(), - # which ought to work. - return str(value) - - ret = fmt(prec) - if "." not in ret and "e" not in ret: - ret += ".0" - return ret - - -def format_f64_imm(num: int) -> str: - (value,) = struct.unpack(">d", struct.pack(">Q", num & (2**64 - 1))) - return str(value)