From 15cb01b1811e325157da3c5af2513e8dc8c7a18b Mon Sep 17 00:00:00 2001 From: Thomas Lamb Date: Mon, 16 Mar 2026 12:27:17 -0400 Subject: [PATCH 1/2] Set language linkage to "C" when compiling C++ --- mwccgap/constants.py | 12 ++++++++++++ mwccgap/preprocessor.py | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/mwccgap/constants.py b/mwccgap/constants.py index f16b31e..c5b2994 100644 --- a/mwccgap/constants.py +++ b/mwccgap/constants.py @@ -16,3 +16,15 @@ LOCAL_SUFFIX = ", local" IGNORED_RELOCATIONS = (".rel.pdr",) + +BEFORE_PREPROCESSED_LINES = """ +#ifdef __cplusplus +extern "C" { +#endif +""".splitlines() + +AFTER_PREPROCESSED_LINES = """ +#ifdef __cplusplus +} +#endif +""".splitlines() diff --git a/mwccgap/preprocessor.py b/mwccgap/preprocessor.py index a758330..88a6340 100644 --- a/mwccgap/preprocessor.py +++ b/mwccgap/preprocessor.py @@ -16,6 +16,8 @@ INCLUDE_RODATA_REGEX, BLOCK_COMMENT_REGEX, LOCAL_SUFFIX, + BEFORE_PREPROCESSED_LINES, + AFTER_PREPROCESSED_LINES, ) @@ -231,7 +233,9 @@ def preprocess_c_file( raise Exception(f"Failed to preprocess {asm_file}: {e}") from None asm_files.append((asm_file, len(rodata_entries))) + out_lines += BEFORE_PREPROCESSED_LINES out_lines += new_lines + out_lines += AFTER_PREPROCESSED_LINES else: out_lines.append(line) From a3de95c824339150cd3e386776b7c8fdcba79c77 Mon Sep 17 00:00:00 2001 From: Thomas Lamb Date: Mon, 16 Mar 2026 15:04:03 -0400 Subject: [PATCH 2/2] Refactor preprocessor guard statements --- mwccgap/constants.py | 12 ------------ mwccgap/preprocessor.py | 19 +++++++++++++++---- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/mwccgap/constants.py b/mwccgap/constants.py index c5b2994..f16b31e 100644 --- a/mwccgap/constants.py +++ b/mwccgap/constants.py @@ -16,15 +16,3 @@ LOCAL_SUFFIX = ", local" IGNORED_RELOCATIONS = (".rel.pdr",) - -BEFORE_PREPROCESSED_LINES = """ -#ifdef __cplusplus -extern "C" { -#endif -""".splitlines() - -AFTER_PREPROCESSED_LINES = """ -#ifdef __cplusplus -} -#endif -""".splitlines() diff --git a/mwccgap/preprocessor.py b/mwccgap/preprocessor.py index 88a6340..597dd53 100644 --- a/mwccgap/preprocessor.py +++ b/mwccgap/preprocessor.py @@ -16,11 +16,22 @@ INCLUDE_RODATA_REGEX, BLOCK_COMMENT_REGEX, LOCAL_SUFFIX, - BEFORE_PREPROCESSED_LINES, - AFTER_PREPROCESSED_LINES, ) +C_MACRO_START = """ +#ifdef __cplusplus +extern "C" { +#endif +""".splitlines() + +C_MACRO_END = """ +#ifdef __cplusplus +} +#endif +""".splitlines() + + @dataclass class Symbol: name: str @@ -233,9 +244,9 @@ def preprocess_c_file( raise Exception(f"Failed to preprocess {asm_file}: {e}") from None asm_files.append((asm_file, len(rodata_entries))) - out_lines += BEFORE_PREPROCESSED_LINES + out_lines += C_MACRO_START out_lines += new_lines - out_lines += AFTER_PREPROCESSED_LINES + out_lines += C_MACRO_END else: out_lines.append(line)