From 5536f3f63fcc3b312743f5d0d7597fd9e27258bc Mon Sep 17 00:00:00 2001 From: wargio Date: Sun, 28 Jul 2024 14:44:46 +0800 Subject: [PATCH] Everything is broken but is ok --- .../autosync/cpptranslator/arch_config.json | 16 ++++++-- .../cpptranslator/patches/FieldFromInstr.py | 2 +- .../cpptranslator/patches/Includes.py | 40 +++++++++++++++++++ 3 files changed, 54 insertions(+), 4 deletions(-) diff --git a/suite/auto-sync/src/autosync/cpptranslator/arch_config.json b/suite/auto-sync/src/autosync/cpptranslator/arch_config.json index 44d29ceb2f..8e3888036d 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/arch_config.json +++ b/suite/auto-sync/src/autosync/cpptranslator/arch_config.json @@ -147,12 +147,22 @@ "{LLVM_ROOT}/llvm/lib/Target/LoongArch/Disassembler/LoongArchDisassembler.cpp", "{LLVM_ROOT}/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchInstPrinter.cpp" ], - "templates_with_arg_deduction": [ - ], + "templates_with_arg_deduction": [], "manually_edited_files": [] }, "Mips": { - "files_to_translate": [], + "files_to_translate": [ + { + "in": "{LLVM_ROOT}/llvm/lib/Target/Mips/Disassembler/MipsDisassembler.cpp", + "out": "MipsDisassembler.c" + },{ + "in": "{LLVM_ROOT}/llvm/lib/Target/Mips/MCTargetDesc/MipsInstPrinter.cpp", + "out": "MipsInstPrinter.c" + },{ + "in": "{LLVM_ROOT}/llvm/lib/Target/Mips/MCTargetDesc/MipsInstPrinter.h", + "out": "MipsInstPrinter.h" + } + ], "files_for_template_search": [ "{CPP_INC_OUT_DIR}/MipsGenDisassemblerTables.inc", "{CPP_INC_OUT_DIR}/MipsGenAsmWriter.inc" diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/FieldFromInstr.py b/suite/auto-sync/src/autosync/cpptranslator/patches/FieldFromInstr.py index 8133e7b683..6f8269b048 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/FieldFromInstr.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/FieldFromInstr.py @@ -59,7 +59,7 @@ def get_patch(self, captures: [(Node, str)], src: bytes, **kwargs) -> bytes: elif inst_type in [b"uint16_t"]: inst_width = 2 else: - log.fatal(f"Type {inst_type} no handled.") + log.fatal(f"Type {inst_type} not handled.") exit(1) else: # Needs manual fix diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/Includes.py b/suite/auto-sync/src/autosync/cpptranslator/patches/Includes.py index d8bc3e1d63..a532017ea6 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/Includes.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/Includes.py @@ -64,6 +64,8 @@ def get_patch(self, captures: [(Node, str)], src: bytes, **kwargs) -> bytes: return res + get_AArch64_includes(filename) + get_general_macros() case "LoongArch": return res + get_LoongArch_includes(filename) + get_general_macros() + case "Mips": + return res + get_Mips_includes(filename) + get_general_macros() case "TEST_ARCH": return res + b"test_output" case _: @@ -294,6 +296,44 @@ def get_LoongArch_includes(filename: str) -> bytes: exit(1) +def get_Mips_includes(filename: str) -> bytes: + match filename: + case "MipsDisassembler.cpp": + return ( + b'#include "../../MCInst.h"\n' + + b'#include "../../MathExtras.h"\n' + + b'#include "../../MCInstPrinter.h"\n' + + b'#include "../../MCDisassembler.h"\n' + + b'#include "../../MCFixedLenDisassembler.h"\n' + + b'#include "../../cs_priv.h"\n' + + b'#include "../../utils.h"\n' + + b'#include "MipsDisassemblerExtension.h"\n' + + b"#define GET_SUBTARGETINFO_ENUM\n" + + b'#include "MipsGenSubtargetInfo.inc"\n\n' + + b"#define GET_INSTRINFO_ENUM\n" + + b'#include "MipsGenInstrInfo.inc"\n\n' + + b"#define GET_REGINFO_ENUM\n" + + b'#include "MipsGenRegisterInfo.inc"\n\n' + ) + case "MipsInstPrinter.cpp": + return ( + b'#include "MipsMapping.h"\n' + + b'#include "MipsInstPrinter.h"\n\n' + + b"#define GET_SUBTARGETINFO_ENUM\n" + + b'#include "MipsGenSubtargetInfo.inc"\n\n' + + b"#define GET_INSTRINFO_ENUM\n" + + b'#include "MipsGenInstrInfo.inc"\n\n' + + b"#define GET_REGINFO_ENUM\n" + + b'#include "MipsGenRegisterInfo.inc"\n\n' + ) + case "MipsInstPrinter.h": + return ( + b'#include "../../MCInstPrinter.h"\n' + b'#include "../../cs_priv.h"\n' + ) + log.fatal(f"No includes given for Mips source file: {filename}") + exit(1) + + def get_general_macros(): return ( b"#define CONCAT(a, b) CONCAT_(a, b)\n" b"#define CONCAT_(a, b) a ## _ ## b\n"