writing module to .bc bitcode file

前端 未结 2 510
遥遥无期
遥遥无期 2021-01-02 12:34

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 mis

相关标签:
2条回答
  • 2021-01-02 13:00

    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.

    0 讨论(0)
  • 2021-01-02 13:10

    I use following code :

    std::error_code EC;
    llvm::raw_fd_ostream OS("module", EC, llvm::sys::fs::F_None);
    WriteBitcodeToFile(pBiFModule, OS);
    OS.flush();
    

    and then disassemble using llvm-dis.

    0 讨论(0)
提交回复
热议问题