From ce87aed628c77cd3740cb0d11cb034f351edd91c Mon Sep 17 00:00:00 2001 From: em-eight Date: Thu, 22 Feb 2024 17:03:09 +0200 Subject: [PATCH] Generate only .c/.cpp in --regen_asm --- mkwutil/gen_asm.py | 19 +++++-------------- mkwutil/gen_asm/source.c.j2 | 4 ++-- mkwutil/gen_asm/source.h.j2 | 17 ----------------- mkwutil/gen_asm/source_decls.j2 | 4 ++++ 4 files changed, 11 insertions(+), 33 deletions(-) delete mode 100644 mkwutil/gen_asm/source.h.j2 diff --git a/mkwutil/gen_asm.py b/mkwutil/gen_asm.py index 44a8a537d..65a6b9982 100644 --- a/mkwutil/gen_asm.py +++ b/mkwutil/gen_asm.py @@ -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. @@ -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, @@ -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): @@ -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"), ) @@ -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"), ) diff --git a/mkwutil/gen_asm/source.c.j2 b/mkwutil/gen_asm/source.c.j2 index 56977a1b9..ffe112a10 100644 --- a/mkwutil/gen_asm/source.c.j2 +++ b/mkwutil/gen_asm/source.c.j2 @@ -1,5 +1,5 @@ -#include "{{ header }}" - +#include +#include {% include 'source_decls.j2' %} // .rodata diff --git a/mkwutil/gen_asm/source.h.j2 b/mkwutil/gen_asm/source.h.j2 deleted file mode 100644 index d95ee7136..000000000 --- a/mkwutil/gen_asm/source.h.j2 +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include - -#include - -#ifdef __cplusplus -extern "C" { -#endif -{% for function in functions %} -// PAL: {{ function.addr | addr }}..{{ (function.addr+function.size) | addr }} -UNKNOWN_FUNCTION({{ function.name }}); -{%- endfor %} - -#ifdef __cplusplus -} -#endif diff --git a/mkwutil/gen_asm/source_decls.j2 b/mkwutil/gen_asm/source_decls.j2 index feea87080..f192ad91e 100644 --- a/mkwutil/gen_asm/source_decls.j2 +++ b/mkwutil/gen_asm/source_decls.j2 @@ -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 %}