因此,在解决问题之后,它终于让我对问题进行了简单的破解我需要提醒您注意这个解决方案适用于 LLVM5.0 的问题,所以我不知道它是否适用于其他版本。
-first: 我已经从 AsmWriter.cpp 文件中复制了llvm::LLVMContext::dump 的定义,您可以在以下位置找到各种llvm::Dump 方法的定义这个文件的总结尾我已经复制了它们以备将来使用我将写入我使用过的 LLVMDump.cpp 的内容
LLVMDump.cpp
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/IR/AssemblyAnnotationWriter.h"
#include "llvm/IR/CFG.h"
#include "llvm/IR/CallingConv.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/IRPrintingPasses.h"
#include "llvm/IR/InlineAsm.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/ModuleSlotTracker.h"
#include "llvm/IR/Operator.h"
#include "llvm/IR/Statepoint.h"
#include "llvm/IR/TypeFinder.h"
#include "llvm/IR/UseListOrder.h"
#include "llvm/IR/ValueSymbolTable.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/BinaryFormat/Dwarf.h"
#include <algorithm>
#include <cctype>
using namespace llvm;
LLVM_DUMP_METHOD
void Value::dump() const { print(dbgs(), /*IsForDebug=*/true); dbgs() << '\n'; }
// Type::dump - allow easy printing of Types from the debugger.
LLVM_DUMP_METHOD
void Type::dump() const { print(dbgs(), /*IsForDebug=*/true); dbgs() << '\n'; }
// Module::dump() - Allow printing of Modules from the debugger.
LLVM_DUMP_METHOD
void Module::dump() const {
print(dbgs(), nullptr,
/*ShouldPreserveUseListOrder=*/false, /*IsForDebug=*/true);
}
// \brief Allow printing of Comdats from the debugger.
LLVM_DUMP_METHOD
void Comdat::dump() const { print(dbgs(), /*IsForDebug=*/true); }
// NamedMDNode::dump() - Allow printing of NamedMDNodes from the debugger.
LLVM_DUMP_METHOD
void NamedMDNode::dump() const { print(dbgs(), /*IsForDebug=*/true); }
LLVM_DUMP_METHOD
void Metadata::dump() const { dump(nullptr); }
LLVM_DUMP_METHOD
void Metadata::dump(const Module *M) const {
print(dbgs(), M, /*IsForDebug=*/true);
dbgs() << '\n';
}
请注意,我已将旧的包含目录 #include "llvm/Support/Dwarf.h" 更改为 #include "llvm/BinaryFormat/Dwarf.h"
-second:我已将 LLVMDUmp.cpp 编译为静态库,以便稍后在需要时链接它。
如果您不知道如何在 mac 上创建静态链接库,因为 -static 标志不适用于 mac 上的 clang 或 gcc
clang++ -std=c++1z -O3 -c LLVMDump.cpp -o LLVMDump.o
然后用于创建静态链接库
ar -rv libLLVMDump.a LLVMDump.o
现在只需将 libLLVMDump.a 移动到您计算机上的 lib 目录中,以便在需要时使用它(如果您不知道应该从 llvm 安装中设置 lib 目录的位置)使用llvm配置
llvm-config --lib-dir
它会显示你应该把你的 llvm/lib 目录放在哪里。
测试:
如果需要,您可以使用问题中的代码
clang++ -O3 -Wall -std=c++1z -L /path/lib -lLLVMCore -lLLVMBinaryFormat -lLLVMSupport -lLLVMDemangle -lLLVMDump llvmtest.cpp
请注意我们刚刚创建的最后的 LLVMDump。
我希望对任何人都有帮助,祝编码愉快?。