Skip to content

Commit

Permalink
Generate only .c/.cpp in --regen_asm
Browse files Browse the repository at this point in the history
  • Loading branch information
em-eight authored and riidefi committed Feb 25, 2024
1 parent d10e500 commit ce87aed
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 33 deletions.
19 changes: 5 additions & 14 deletions mkwutil/gen_asm.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,10 @@ def dump_section(self):
class CAsmGenerator:
"""Generates C files with assembly functions."""

def __init__(self, disaser, _slices, symbols, out_h, out_c, cpp_mode):
def __init__(self, disaser, _slices, symbols, out_c, cpp_mode):
self.disaser = disaser
self.slices = _slices
self.symbols = symbols
self.out_h = out_h
self.out_c = out_c
self.cpp_mode = cpp_mode
# The list of seen extern declarations.
Expand Down Expand Up @@ -258,7 +257,6 @@ def dump_source(self):
# Write out to C file.
template = jinja_env.get_template("source.c.j2")
template.stream(
header=Path(self.out_h.name).name,
cpp=self.cpp_mode,
functions=functions,
rodata=rodata,
Expand All @@ -267,9 +265,6 @@ def dump_source(self):
extern_functions=list({"name": a[1], "addr": a[0]} for a in self.extern_functions),
extern_data=list({"name": a[1], "addr": a[0]} for a in self.extern_data),
).dump(self.out_c)
# Write out to H file.
template = jinja_env.get_template("source.h.j2")
template.stream(functions=functions).dump(self.out_h)


def disassemble_function(self, fn_start_vma):
Expand Down Expand Up @@ -498,15 +493,13 @@ def __slice_dest_c(self, _slice):

def __gen_c(self, c_source_name: str, _slices: list[Slice]):
c_path = Path(c_source_name)
h_path = c_path.with_suffix(".h" if str(c_path).endswith(".c") else ".hpp")
if not (c_path.exists() or h_path.exists()):
if not c_path.exists():
c_path.parent.mkdir(parents=True, exist_ok=True)
with open(h_path, "w") as h_file, open(c_path, "w") as c_file:
with open(c_path, "w") as c_file:
gen = CAsmGenerator(
self.disaser,
_slices,
self.symbols,
h_file,
c_file,
not str(c_path).endswith(".c"),
)
Expand Down Expand Up @@ -631,15 +624,13 @@ def __slice_dest_c(self, _slice):

def __gen_c(self, c_source_name: str, _slices: list[Slice]):
c_path = Path(c_source_name)
h_path = c_path.with_suffix(".h" if str(c_path).endswith(".c") else ".hpp")
if not (c_path.exists() or h_path.exists()):
if not c_path.exists():
c_path.parent.mkdir(parents=True, exist_ok=True)
with open(h_path, "w") as h_file, open(c_path, "w") as c_file:
with open(c_path, "w") as c_file:
gen = CAsmGenerator(
self.disaser,
_slices,
self.symbols,
h_file,
c_file,
not str(c_path).endswith(".c"),
)
Expand Down
4 changes: 2 additions & 2 deletions mkwutil/gen_asm/source.c.j2
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "{{ header }}"

#include <rk_types.h>
#include <decomp.h>
{% include 'source_decls.j2' %}

// .rodata
Expand Down
17 changes: 0 additions & 17 deletions mkwutil/gen_asm/source.h.j2

This file was deleted.

4 changes: 4 additions & 0 deletions mkwutil/gen_asm/source_decls.j2
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
{% if cpp %}
extern "C" {
{% endif %}
{% for function in functions %}
// PAL: {{ function.addr | addr }}..{{ (function.addr+function.size) | addr }}
UNKNOWN_FUNCTION({{ function.name }});
{%- endfor %}
{% if extern_functions | length > 0 -%}
// Extern function references.
{%- for function in extern_functions %}
Expand Down

0 comments on commit ce87aed

Please sign in to comment.