将模块写入.bc位码文件 [英] writing module to .bc bitcode file

查看:338
本文介绍了将模块写入.bc位码文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我假设从一个模块中转储一个.bc文件是一个简单的操作,但现在,
第一次我必须从代​​码中实际执行它,因为我的生命
可以'

  static void WriteModule(const Module * M,BitstreamWriter& Stream)

http://llvm.org/docs/doxygen/html/BitcodeWriter_8cpp.html#a828cec7a8fed9d232556420efef7ae89

编写该模块,首先我需要一个BistreamWriter

  BitstreamWriter :: BitstreamWriter(SmallVectorImpl< char>& O)
code> $ b http://llvm.org/docs/doxygen/html/classllvm_1_1BitstreamWriter.html



对于BitstreamWriter,我需要一个SmallVecto rImpl。但是,接下来呢?
我应该自己写一个
文件处理程序中的SmallVectorImpl字节的内容吗?有没有这样的llvm api?我还需要一些
吗?

解决方案 lib / Bitcode / Writer / BitcodeWriter.cpp 中是静态的,这意味着它不在外面消耗(甚至不能访问它)。
$ b

同一个文件有另外一个函数,但是叫做 WriteBitcodeToFile ,带有这个接口:

  /// WriteBitcodeToFile  - 将指定的模块写入指定的输出
///流。
void llvm :: WriteBitcodeToFile(const Module * M,raw_ostream& Out);

我无法想象一个更方便的界面。头文件声明它是 ./ include / llvm / Bitcode / ReaderWriter.h ,顺便说一下。


i've assumed that dumping a .bc file from a module was a trivial operation, but now, first time i have to actually do it from code, for the life of me i can't find one missing step in the process:

static void WriteModule ( const Module *  M, BitstreamWriter &  Stream )

http://llvm.org/docs/doxygen/html/BitcodeWriter_8cpp.html#a828cec7a8fed9d232556420efef7ae89

to write that module, first i need a BistreamWriter

BitstreamWriter::BitstreamWriter (SmallVectorImpl< char > &O)

http://llvm.org/docs/doxygen/html/classllvm_1_1BitstreamWriter.html

and for a BitstreamWriter i need a SmallVectorImpl. But, what next? Should i write the content of the SmallVectorImpl byte by byte on a file handler myself? is there a llvm api for this? do i need something else?

解决方案

The WriteModule function is static within lib/Bitcode/Writer/BitcodeWriter.cpp, which means it's not there for outside consumption (you can't even access it).

The same file has another function, however, called WriteBitcodeToFile, with this interface:

/// WriteBitcodeToFile - Write the specified module to the specified output
/// stream.
void llvm::WriteBitcodeToFile(const Module *M, raw_ostream &Out);

I can't imagine a more convenient interface. The header file declaring it is ./include/llvm/Bitcode/ReaderWriter.h, by the way.

这篇关于将模块写入.bc位码文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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