Skip to content

Commit

Permalink
Everything is broken but is ok
Browse files Browse the repository at this point in the history
  • Loading branch information
wargio committed Jul 28, 2024
1 parent f8dd32c commit 5536f3f
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
16 changes: 13 additions & 3 deletions suite/auto-sync/src/autosync/cpptranslator/arch_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 40 additions & 0 deletions suite/auto-sync/src/autosync/cpptranslator/patches/Includes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 _:
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 5536f3f

Please sign in to comment.