从LLVM :: ModuleRef中提取LLVM :: Module [英] Extracting LLVM::Module from LLVM::ModuleRef

查看:446
本文介绍了从LLVM :: ModuleRef中提取LLVM :: Module的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建简单的位码读取器(而不是专用过程,以便能够更轻松地进行调试),并且在提取模块时遇到了一些问题.这是main内部的内容:

I'm trying to build a simple bitcode reader (rather than a dedicated pass, in order to be able to debug more easily) and I have some problems extracting the module. Here's what I have inside main:

LLVMModuleRef module;    
char *message = nullptr;
LLVMMemoryBufferRef memoryBuffer;

LLVMCreateMemoryBufferWithContentsOfFile(
    argv[1],
    &memoryBuffer,
    &message);

LLVMParseBitcode2(memoryBuffer,&module);

// for (auto func:module->getFunctionList())
{
    /* ... */
}

如何从LLVMModuleRef中提取模块?当然,我在这里错过了一些琐碎的事情.

How can I extract Module from LLVMModuleRef? Surely I'm missing something trivial here.

推荐答案

为什么要混合使用C和C ++ API?

Why are you mixing C and C++ APIs?

如果您想使用llvm::Module,我假设您使用C ++进行编码,因此只需使用C ++ API来解析位代码即可:

If you want to work with llvm::Module, I assume you are coding in C++, so just use C++ API to parse the bitcode:

    #include "llvm/IRReader/IRReader.h"

    SMDiagnostic Err;
    LLVMContext ctx;
    unique_ptr<Module> M = parseIRFile(path, Err, ctx);

    if (!M) {
        Err.print("Error loading bitcode", errs());
    }

这篇关于从LLVM :: ModuleRef中提取LLVM :: Module的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆