summaryrefslogtreecommitdiff
path: root/tools/libdol2asm/data/function
diff options
context:
space:
mode:
authorJulgodis <>2021-04-10 07:02:38 +0200
committerJulgodis <>2021-04-10 07:02:38 +0200
commit0ad6ebe7b499ad3efffad93e2e7eb1033bcb6598 (patch)
treea40631b0654c4d310ebff2360e2a4ef32437a2b5 /tools/libdol2asm/data/function
parent2661db6aaa98a5bbd17691cb438ef64752dbcdf4 (diff)
moved strings + decompile simple store functions
Diffstat (limited to 'tools/libdol2asm/data/function')
-rw-r--r--tools/libdol2asm/data/function/__init__.py2
-rw-r--r--tools/libdol2asm/data/function/base.py15
-rw-r--r--tools/libdol2asm/data/function/ret.py9
-rw-r--r--tools/libdol2asm/data/function/sinit.py2
-rw-r--r--tools/libdol2asm/data/function/small_asm.py20
-rw-r--r--tools/libdol2asm/data/function/store.py55
6 files changed, 96 insertions, 7 deletions
diff --git a/tools/libdol2asm/data/function/__init__.py b/tools/libdol2asm/data/function/__init__.py
index c390847b02..baf3d16d9d 100644
--- a/tools/libdol2asm/data/function/__init__.py
+++ b/tools/libdol2asm/data/function/__init__.py
@@ -3,3 +3,5 @@ from .base import *
from .asm import *
from .ret import *
from .sinit import *
+from .store import *
+from .small_asm import *
diff --git a/tools/libdol2asm/data/function/base.py b/tools/libdol2asm/data/function/base.py
index 0eda461881..9985e0966e 100644
--- a/tools/libdol2asm/data/function/base.py
+++ b/tools/libdol2asm/data/function/base.py
@@ -132,12 +132,19 @@ class Function(Symbol):
for line in lines:
await builder.write(line)
- arg_type = ""
+ arg_type = []
if forward:
- arg_type = ", ".join([x.type(specialize_templates=True) for x in self.argument_types])
+ arg_type = [x.type(specialize_templates=True) for x in self.argument_types]
else:
- arg_type = ", ".join([x.decl(f"param_{i}",specialize_templates=True) for i, x in zip(
- range(len(self.argument_types)), self.argument_types)])
+ arg_type = [
+ x.decl(f"param_{i}",specialize_templates=True)
+ for i, x in enumerate(self.argument_types)
+ ]
+
+ if self.demangled_name and self.demangled_name.require_specialization:
+ arg_type = [f"void* _this", *arg_type]
+
+ arg_type = ", ".join(arg_type)
if self._section == ".init":
await builder.write_nonewline(f"SECTION_INIT ")
diff --git a/tools/libdol2asm/data/function/ret.py b/tools/libdol2asm/data/function/ret.py
index aed96c2315..c9ae3b8d1d 100644
--- a/tools/libdol2asm/data/function/ret.py
+++ b/tools/libdol2asm/data/function/ret.py
@@ -29,6 +29,8 @@ class CustomReturnFunction(ReturnFunction):
class SymbolReturnFunction(ReturnFunction):
symbol_addr: int = 0
load_or_reference: bool = True
+ load_type: Type = None
+ cast_type: Type = None
def gather_references(self, context, valid_range):
self.references = set([ self.symbol_addr ])
@@ -37,8 +39,11 @@ class SymbolReturnFunction(ReturnFunction):
symbol = symbol_table[-1, self.symbol_addr]
assert symbol
name = symbol.cpp_reference(self, self.symbol_addr)
- type = PointerType(self.return_type)
+ load_type = PointerType(self.load_type)
dereference = ""
+ cast = ""
if self.load_or_reference:
dereference = "*"
- return f"{dereference}({type.type()})({name})"
+ if self.cast_type:
+ cast = f"({self.cast_type.type()})"
+ return f"{cast}{dereference}({load_type.type()})({name})"
diff --git a/tools/libdol2asm/data/function/sinit.py b/tools/libdol2asm/data/function/sinit.py
index 02ebcd8f94..ba6aafc174 100644
--- a/tools/libdol2asm/data/function/sinit.py
+++ b/tools/libdol2asm/data/function/sinit.py
@@ -20,7 +20,7 @@ class SInitFunction(ASMFunction):
await builder.write("#pragma push")
await builder.write("#pragma force_active on")
- await builder.write(f"SECTION_CTORS void* const _ctors_{self.addr:08X} = (void*){self.label};")
+ await builder.write(f"REGISTER_CTORS(0x{self.addr:08X}, {self.label});")
await builder.write("#pragma pop")
await builder.write("")
diff --git a/tools/libdol2asm/data/function/small_asm.py b/tools/libdol2asm/data/function/small_asm.py
new file mode 100644
index 0000000000..f45d0c3b91
--- /dev/null
+++ b/tools/libdol2asm/data/function/small_asm.py
@@ -0,0 +1,20 @@
+
+from dataclasses import dataclass, field
+from typing import List
+
+from ...builder import AsyncBuilder
+from .base import *
+
+@dataclass(eq=False)
+class SmallASMFunction(Function):
+ asm: bool = True
+ insts: List[str] = field(default_factory=list)
+
+ async def export_function_body(self, exporter, builder: AsyncBuilder):
+ await builder.write(f" {{")
+ await builder.write(f"\t// clang-format off")
+ await builder.write(f"\tnofralloc")
+ for inst in self.insts:
+ await builder.write(f"\t{inst}")
+ await builder.write(f"\t// clang-format on")
+ await builder.write(f"}}") \ No newline at end of file
diff --git a/tools/libdol2asm/data/function/store.py b/tools/libdol2asm/data/function/store.py
new file mode 100644
index 0000000000..48116e6edc
--- /dev/null
+++ b/tools/libdol2asm/data/function/store.py
@@ -0,0 +1,55 @@
+
+
+from dataclasses import dataclass, field
+from capstone import *
+from capstone.ppc import *
+
+from ...builder import AsyncBuilder
+from ...types import *
+from .base import *
+
+
+@dataclass(eq=False)
+class StoreFunction(Function):
+ async def export_store(self, exporter, builder):
+ assert False
+
+ async def export_function_body(self, exporter, builder: AsyncBuilder):
+ await builder.write(f" {{")
+ await self.export_store(exporter, builder)
+ await builder.write(f"}}")
+
+
+@dataclass(eq=False)
+class Store_R3_OffsetRX_Function(StoreFunction):
+ dst: int = 0
+ dst_offset: int = 0
+ src: int = 0
+ store_type: Type = None
+
+ def calculate_params(self):
+ params = {}
+
+ gr = PPC_REG_R3
+ if self.has_class:
+ if self.demangled_name and self.demangled_name.require_specialization:
+ params[gr] = "_this"
+ else:
+ params[gr] = "this"
+ gr += 1
+
+ for i, arg in enumerate(self.argument_types):
+ params[gr] = f"param_{i}"
+ gr += 1
+
+ return params
+
+ async def export_store(self, exporter, builder):
+ params = self.calculate_params()
+ dst = params[self.dst]
+ src = params[self.src]
+ if self.dst_offset > 0:
+ dst = f"(((u8*){params[self.dst]})+{self.dst_offset}) /* {params[self.dst]}->field_0x{self.dst_offset:x} */"
+
+ pointer_type = PointerType(self.store_type)
+ await builder.write(f"\t*({pointer_type.type()}){dst} = ({self.store_type.type()})({src});")