bool EmitASTBitcodeFile(const TranslationUnit* TU,
const llvm::sys::Path& Filename);
+/// EmitASTBitcodeStream - Emit a translation unit to a std::ostream.
+bool EmitASTBitcodeStream(const TranslationUnit& TU,
+ std::ostream& Stream);
+
+bool EmitASTBitcodeStream(const TranslationUnit* TU,
+ std::ostream& Stream);
+
+/// EmitASTBitcodeBuffer - Emit a translation unit to a buffer.
+bool EmitASTBitcodeBuffer(const TranslationUnit& TU,
+ std::vector<unsigned char>& Buffer);
+
+bool EmitASTBitcodeBuffer(const TranslationUnit* TU,
+ std::vector<unsigned char>& Buffer);
+
/// ReadASTBitcodeFile - Reconsitute a translation unit from a bitcode file.
TranslationUnit* ReadASTBitcodeFile(const llvm::sys::Path& Filename,
FileManager& FMgr);
+/// ReadASTBitcodeBuffer - Reconsitute a translation unit from a buffer.
+TranslationUnit* ReadASTBitcodeBuffer(llvm::MemoryBuffer& MBuffer,
+ FileManager& FMgr);
+
} // end namespace clang
return TU ? EmitASTBitcodeFile(*TU, Filename) : false;
}
-bool clang::EmitASTBitcodeFile(const TranslationUnit& TU,
- const llvm::sys::Path& Filename) {
-
- // Reserve 256K for bitstream buffer.
- std::vector<unsigned char> Buffer;
- Buffer.reserve(256*1024);
-
+bool clang::EmitASTBitcodeBuffer(const TranslationUnit* TU,
+ std::vector<unsigned char>& Buffer) {
+
+ return TU ? EmitASTBitcodeBuffer(*TU, Buffer) : false;
+}
+
+bool clang::EmitASTBitcodeStream(const TranslationUnit* TU,
+ std::ostream& Stream) {
+
+ return TU ? EmitASTBitcodeStream(*TU, Stream) : false;
+}
+
+bool clang::EmitASTBitcodeBuffer(const TranslationUnit& TU,
+ std::vector<unsigned char>& Buffer) {
// Create bitstream.
llvm::BitstreamWriter Stream(Buffer);
TU.Emit(Sezr);
}
+ return true;
+}
+
+bool clang::EmitASTBitcodeStream(const TranslationUnit& TU,
+ std::ostream& Stream) {
+
+ // Reserve 256K for bitstream buffer.
+ std::vector<unsigned char> Buffer;
+ Buffer.reserve(256*1024);
+
+ EmitASTBitcodeBuffer(TU,Buffer);
+
+ // Write the bits to disk.
+ Stream.write((char*)&Buffer.front(), Buffer.size());
+ return true;
+}
+
+bool clang::EmitASTBitcodeFile(const TranslationUnit& TU,
+ const llvm::sys::Path& Filename) {
+
+ // Reserve 256K for bitstream buffer.
+ std::vector<unsigned char> Buffer;
+ Buffer.reserve(256*1024);
+
+ EmitASTBitcodeBuffer(TU,Buffer);
+
// Write the bits to disk.
if (FILE* fp = fopen(Filename.c_str(),"wb")) {
fwrite((char*)&Buffer.front(), sizeof(char), Buffer.size(), fp);
}
TranslationUnit*
-clang::ReadASTBitcodeFile(const llvm::sys::Path& Filename, FileManager& FMgr) {
-
- // Create the memory buffer that contains the contents of the file.
- llvm::OwningPtr<llvm::MemoryBuffer>
- MBuffer(llvm::MemoryBuffer::getFile(Filename.c_str()));
-
- if (!MBuffer) {
- // FIXME: Provide diagnostic.
- return NULL;
- }
-
+clang::ReadASTBitcodeBuffer(llvm::MemoryBuffer& MBuffer, FileManager& FMgr) {
+
// Check if the file is of the proper length.
- if (MBuffer->getBufferSize() & 0x3) {
+ if (MBuffer.getBufferSize() & 0x3) {
// FIXME: Provide diagnostic: "Length should be a multiple of 4 bytes."
return NULL;
}
// Create the bitstream reader.
- unsigned char *BufPtr = (unsigned char *) MBuffer->getBufferStart();
- llvm::BitstreamReader Stream(BufPtr,BufPtr+MBuffer->getBufferSize());
+ unsigned char *BufPtr = (unsigned char *) MBuffer.getBufferStart();
+ llvm::BitstreamReader Stream(BufPtr,BufPtr+MBuffer.getBufferSize());
if (Stream.Read(8) != 'B' ||
Stream.Read(8) != 'C' ||
return TranslationUnit::Create(Dezr,FMgr);
}
+TranslationUnit*
+clang::ReadASTBitcodeFile(const llvm::sys::Path& Filename, FileManager& FMgr) {
+
+ // Create the memory buffer that contains the contents of the file.
+ llvm::OwningPtr<llvm::MemoryBuffer>
+ MBuffer(llvm::MemoryBuffer::getFile(Filename.c_str()));
+
+ if (!MBuffer) {
+ // FIXME: Provide diagnostic.
+ return NULL;
+ }
+
+ return ReadASTBitcodeBuffer(*MBuffer, FMgr);
+}
+
TranslationUnit* TranslationUnit::Create(llvm::Deserializer& Dezr,
FileManager& FMgr) {