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

Remove some dead code #330

Merged
merged 3 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion src/splat/segtypes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from . import address_range as address_range
from . import linker_entry as linker_entry
from . import segment as segment

Expand Down
10 changes: 0 additions & 10 deletions src/splat/segtypes/address_range.py

This file was deleted.

52 changes: 2 additions & 50 deletions src/splat/segtypes/common/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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_"):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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):
Expand Down
52 changes: 1 addition & 51 deletions src/splat/segtypes/common/codesubsegment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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":
Expand All @@ -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
Expand Down Expand Up @@ -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")
Expand Down
8 changes: 0 additions & 8 deletions src/splat/segtypes/segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion src/splat/util/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
63 changes: 0 additions & 63 deletions src/splat/util/floats.py

This file was deleted.