From ca17c654997f3f08287f48dc197a2b88140fa824 Mon Sep 17 00:00:00 2001 From: Emma Jane Bonestell Date: Mon, 10 Jan 2022 10:50:33 -0600 Subject: [PATCH] Fixes LLVM 13/14 compatibility (#1395) Fixes LLVM 13 and LLVM 14 compatibility as of the current master branch. * LLVM 13 -- llvm::MCContext now requires the TargetTriple ; https://reviews.llvm.org/D101462 * LLVM 13 -- FPImm has been split into two functions, DFPImm retains original semantics ; https://reviews.llvm.org/D77384 * LLVM 14 -- Support/TargetRegistry.h has been moved to MC/TargetRegistry.h ; https://reviews.llvm.org/D111454 --- lib/bap_llvm/llvm_disasm.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/bap_llvm/llvm_disasm.cpp b/lib/bap_llvm/llvm_disasm.cpp index 315dc49c9..a3070163c 100644 --- a/lib/bap_llvm/llvm_disasm.cpp +++ b/lib/bap_llvm/llvm_disasm.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #if LLVM_VERSION_MAJOR >= 12 #include @@ -13,6 +12,12 @@ #endif #include +#if LLVM_VERSION_MAJOR >= 14 +#include +#else +#include +#endif + #if LLVM_VERSION_MAJOR >= 10 #include "llvm/MC/MCTargetOptions.h" #endif @@ -258,8 +263,11 @@ class llvm_disassembler : public disassembler_interface { } shared_ptr ctx +#if LLVM_VERSION_MAJOR >= 13 + (new llvm::MCContext(t, &*asm_info, &*reg_info, 0)); +#else (new llvm::MCContext(&*asm_info, &*reg_info, 0)); - +#endif if (!ctx) { if (debug_level > 0) output_error(triple, cpu, "failed to create disassembly context"); @@ -522,11 +530,19 @@ class llvm_disassembler : public disassembler_interface { op.imm_val = mcop.getImm(); return op; } +#if LLVM_VERSION_MAJOR >= 13 + if (mcop.isDFPImm()) { + op.type = bap_disasm_op_fmm; + op.fmm_val = bit_cast(mcop.getDFPImm()); + return op; + } +#else if (mcop.isFPImm()) { op.type = bap_disasm_op_fmm; op.fmm_val = mcop.getFPImm(); return op; } +#endif if (mcop.isInst()) { std::cerr << "got subinst\n"; abort();