Skip to content

Commit

Permalink
Fixes LLVM 13/14 compatibility (#1395)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
EmmaJaneBonestell authored Jan 10, 2022
1 parent 257df8d commit ca17c65
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions lib/bap_llvm/llvm_disasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@
#include <llvm/MC/MCRegisterInfo.h>
#include <llvm/Support/DataTypes.h>
#include <llvm/Support/FormattedStream.h>
#include <llvm/Support/TargetRegistry.h>
#include <llvm/Support/CommandLine.h>
#if LLVM_VERSION_MAJOR >= 12
#include <llvm/Support/Process.h>
#include <llvm/Support/StringSaver.h>
#endif
#include <llvm-c/Target.h>

#if LLVM_VERSION_MAJOR >= 14
#include <llvm/MC/TargetRegistry.h>
#else
#include <llvm/Support/TargetRegistry.h>
#endif

#if LLVM_VERSION_MAJOR >= 10
#include "llvm/MC/MCTargetOptions.h"
#endif
Expand Down Expand Up @@ -258,8 +263,11 @@ class llvm_disassembler : public disassembler_interface {
}

shared_ptr<llvm::MCContext> 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");
Expand Down Expand Up @@ -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<double>(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();
Expand Down

0 comments on commit ca17c65

Please sign in to comment.