Skip to content

Commit

Permalink
Fixes for LLVM 17 (as well as LLVM 16)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmourad01 committed Feb 15, 2024
1 parent 511b64c commit dca1b82
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
18 changes: 16 additions & 2 deletions lib/bap_llvm/llvm_disasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,22 @@

#include <cstring>
#include <cstdint>
#include <limits>
#include <typeinfo>
#include <iostream>
#if LLVM_VERSION_MAJOR >= 16
#include <optional>
#endif

#include "disasm.hpp"
#include "llvm_disasm.h"

#include <llvm/MC/MCDisassembler/MCDisassembler.h>

#include <llvm/ADT/ArrayRef.h>
#if LLVM_VERSION_MAJOR >= 17
#include <llvm/TargetParser/Triple.h>
#else
#include <llvm/ADT/Triple.h>
#endif
#include <llvm/ADT/Twine.h>

template <typename T>
Expand Down Expand Up @@ -464,7 +469,12 @@ class llvm_disassembler : public disassembler_interface {
} else if (p == is_true) {
return true;
} else {
#if LLVM_VERSION_MAJOR >= 16
// MCInstrDesc needs to know its own address to access some implicit tables.
auto &d = ins_info->get(current.code);
#else
auto d = ins_info->get(current.code);
#endif
if (p == may_affect_control_flow) {
return d.mayAffectControlFlow(mcinst, *reg_info);
} else if (auto check = fun_of_pred(p)) {
Expand Down Expand Up @@ -652,7 +662,11 @@ struct create_llvm_disassembler : disasm_factory {

static void parse_environment_options(const char *prog_name, const char *env_var) {
#if LLVM_VERSION_MAJOR >= 12
#if LLVM_VERSION_MAJOR >= 16
std::optional<std::string> env_value = llvm::sys::Process::GetEnv(llvm::StringRef(env_var));
#else
llvm::Optional<std::string> env_value = llvm::sys::Process::GetEnv(llvm::StringRef(env_var));
#endif
if (!env_value)
return;

Expand Down
4 changes: 4 additions & 0 deletions lib/bap_llvm/llvm_loader_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
#include <iomanip>
#include <iostream>

#if LLVM_VERSION_MAJOR >= 17
#include <llvm/TargetParser/Triple.h>
#else
#include <llvm/ADT/Triple.h>
#endif

#include "llvm_error_or.hpp"

Expand Down
5 changes: 5 additions & 0 deletions lib/bap_llvm/llvm_primitives.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#include <iostream>

#include <llvm/Config/llvm-config.h>
#if LLVM_VERSION_MAJOR >= 17
#include <llvm/TargetParser/Triple.h>
#else
#include <llvm/ADT/Triple.h>
#endif

#include "llvm_primitives.hpp"

Expand Down

0 comments on commit dca1b82

Please sign in to comment.