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?
What is commonly known as the LLVM bitcode file format (also, sometimes anachronistically known as bytecode) is actually two things: a bitstream container format and an encoding of LLVM IR into the container format. The bitstream format is an abstract encoding of structured data, very similar to XML in some ways.
The LLVM bytecode representation is used to store the intermediate representation on disk in compacted form. The LLVM bytecode format may change in the future, but LLVM will always be backwards compatible with older formats. This document will only describe the most current version of the bytecode format.
It is possible to execute a bc-file with lli command. However that doesn't create a stand alone executable product. Show activity on this post. There's always the option of using llc to compile to assembly from which you can generate an executable.
LLVM is a three-phase compiler that supports multiple source languages and target architectures. It uses a common intermediate representation (IR) bytecode in its optimizer. Consequently, any supported high-level programming language is trans- formed to this IR bytecode as part of the LLVM compilation process.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With