mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-29 10:25:12 +00:00
Add support for writing LLVM IR to a specified BitstreamWriter.
Patch by Lukasz Janyst! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@61251 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -76,6 +76,9 @@ public:
|
|||||||
BlockInfoRecords.pop_back();
|
BlockInfoRecords.pop_back();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<unsigned char> &getBuffer() { return Out; }
|
||||||
|
|
||||||
//===--------------------------------------------------------------------===//
|
//===--------------------------------------------------------------------===//
|
||||||
// Basic Primitives for emitting bits to the stream.
|
// Basic Primitives for emitting bits to the stream.
|
||||||
//===--------------------------------------------------------------------===//
|
//===--------------------------------------------------------------------===//
|
||||||
|
@@ -22,6 +22,7 @@ namespace llvm {
|
|||||||
class ModuleProvider;
|
class ModuleProvider;
|
||||||
class MemoryBuffer;
|
class MemoryBuffer;
|
||||||
class ModulePass;
|
class ModulePass;
|
||||||
|
class BitstreamWriter;
|
||||||
class raw_ostream;
|
class raw_ostream;
|
||||||
|
|
||||||
/// getBitcodeModuleProvider - Read the header of the specified bitcode buffer
|
/// getBitcodeModuleProvider - Read the header of the specified bitcode buffer
|
||||||
@@ -45,6 +46,10 @@ namespace llvm {
|
|||||||
/// raw output stream.
|
/// raw output stream.
|
||||||
void WriteBitcodeToFile(const Module *M, raw_ostream &Out);
|
void WriteBitcodeToFile(const Module *M, raw_ostream &Out);
|
||||||
|
|
||||||
|
/// WriteBitcodeToStream - Write the specified module to the specified
|
||||||
|
/// raw output stream.
|
||||||
|
void WriteBitcodeToStream(const Module *M, BitstreamWriter &Stream);
|
||||||
|
|
||||||
/// CreateBitcodeWriterPass - Create and return a pass that writes the module
|
/// CreateBitcodeWriterPass - Create and return a pass that writes the module
|
||||||
/// to the specified ostream.
|
/// to the specified ostream.
|
||||||
ModulePass *CreateBitcodeWriterPass(std::ostream &Str);
|
ModulePass *CreateBitcodeWriterPass(std::ostream &Str);
|
||||||
|
@@ -1355,7 +1355,23 @@ void llvm::WriteBitcodeToFile(const Module *M, raw_ostream &Out) {
|
|||||||
BitstreamWriter Stream(Buffer);
|
BitstreamWriter Stream(Buffer);
|
||||||
|
|
||||||
Buffer.reserve(256*1024);
|
Buffer.reserve(256*1024);
|
||||||
|
|
||||||
|
WriteBitcodeToStream( M, Stream );
|
||||||
|
|
||||||
|
// If writing to stdout, set binary mode.
|
||||||
|
if (&llvm::outs() == &Out)
|
||||||
|
sys::Program::ChangeStdoutToBinary();
|
||||||
|
|
||||||
|
// Write the generated bitstream to "Out".
|
||||||
|
Out.write((char*)&Buffer.front(), Buffer.size());
|
||||||
|
|
||||||
|
// Make sure it hits disk now.
|
||||||
|
Out.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// WriteBitcodeToStream - Write the specified module to the specified output
|
||||||
|
/// stream.
|
||||||
|
void llvm::WriteBitcodeToStream(const Module *M, BitstreamWriter &Stream) {
|
||||||
// If this is darwin, emit a file header and trailer if needed.
|
// If this is darwin, emit a file header and trailer if needed.
|
||||||
bool isDarwin = M->getTargetTriple().find("-darwin") != std::string::npos;
|
bool isDarwin = M->getTargetTriple().find("-darwin") != std::string::npos;
|
||||||
if (isDarwin)
|
if (isDarwin)
|
||||||
@@ -1373,16 +1389,5 @@ void llvm::WriteBitcodeToFile(const Module *M, raw_ostream &Out) {
|
|||||||
WriteModule(M, Stream);
|
WriteModule(M, Stream);
|
||||||
|
|
||||||
if (isDarwin)
|
if (isDarwin)
|
||||||
EmitDarwinBCTrailer(Stream, Buffer.size());
|
EmitDarwinBCTrailer(Stream, Stream.getBuffer().size());
|
||||||
|
|
||||||
|
|
||||||
// If writing to stdout, set binary mode.
|
|
||||||
if (&llvm::outs() == &Out)
|
|
||||||
sys::Program::ChangeStdoutToBinary();
|
|
||||||
|
|
||||||
// Write the generated bitstream to "Out".
|
|
||||||
Out.write((char*)&Buffer.front(), Buffer.size());
|
|
||||||
|
|
||||||
// Make sure it hits disk now.
|
|
||||||
Out.flush();
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user