7 #if LLVM_VERSION_LESS_EQUAL(3, 9) 8 #include <llvm/Bitcode/ReaderWriter.h> 10 #include <llvm/Bitcode/BitcodeReader.h> 13 #include <llvm/IR/Module.h> 14 #include <llvm/Support/MemoryBuffer.h> 20 template <
typename MemBuffType>
21 Result parseBitcodeMemBuff(MemBuffType buff, llvm::LLVMContext& ctx,
22 std::unique_ptr<llvm::Module>* toFill) {
23 assert(toFill !=
nullptr &&
"Cannot pass a null toFill pointer to parseBitcodeMemBuff");
29 std::vector<std::string> errorMsgs;
31 #if LLVM_VERSION_AT_LEAST(4, 0) 32 auto E = errorOrMod.takeError();
34 llvm::handleAllErrors(std::move(E), [&errorMsgs](llvm::ErrorInfoBase& err) {
35 errorMsgs.push_back(err.message());
39 res.addEntry(
"EUKN",
"Failed to parse generated bitcode.", {{
"Error Messages", errorMsgs}});
44 #if LLVM_VERSION_LESS_EQUAL(3, 6) 45 std::unique_ptr<llvm::Module>
57 std::unique_ptr<llvm::Module>* toFill) {
61 auto bcFileBufferOrError = llvm::MemoryBuffer::getFile(file.string());
62 if (!bcFileBufferOrError) {
63 res.
addEntry(
"EUKN",
"Failed to load LLVM module from disk", {{
"File", file.string()}});
67 return parseBitcodeMemBuff(bcFileBufferOrError
69 #
if LLVM_VERSION_AT_LEAST(3, 6)
77 Result parseBitcodeString(
const std::string& bitcode, llvm::LLVMContext& ctx,
78 std::unique_ptr<llvm::Module>* toFill) {
79 return parseBitcodeMemBuff(
80 #
if LLVM_VERSION_LESS_EQUAL(3, 5)
81 llvm::MemoryBuffer::getMemBufferCopy
85 (bitcode,
"generated.bc"),
Result parseBitcodeFile(const boost::filesystem::path &file, llvm::LLVMContext &ctx, std::unique_ptr< llvm::Module > *toFill)
Parse a bitcode file.
void addEntry(const char *ec, const char *overview, nlohmann::json data)
Add a entry to the result, either a warning or an error.
Defines the Result class and related functions.
The namespace where chigraph lives.
The result object, used for identifiying errors with good diagnostics.