eliminate some wrappers.

llvm-svn: 67904
This commit is contained in:
Chris Lattner 2009-03-28 03:53:02 +00:00
parent f7d9e2ba1c
commit 96c339a661
4 changed files with 40 additions and 71 deletions

View File

@ -61,27 +61,10 @@ public:
iterator end() const { return Context->getTranslationUnitDecl()->decls_end(); }
};
/// EmitASTBitcodeFile - Emit a translation unit to a bitcode file.
bool EmitASTBitcodeFile(const TranslationUnit& TU,
const llvm::sys::Path& Filename);
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);
/// ReadASTBitcodeBuffer - Reconsitute a translation unit from a buffer.
TranslationUnit* ReadASTBitcodeBuffer(llvm::MemoryBuffer& MBuffer,
FileManager& FMgr);

View File

@ -39,24 +39,6 @@ TranslationUnit::~TranslationUnit() {
}
}
bool clang::EmitASTBitcodeFile(const TranslationUnit* TU,
const llvm::sys::Path& Filename) {
return TU ? EmitASTBitcodeFile(*TU, Filename) : false;
}
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.
@ -82,39 +64,6 @@ bool clang::EmitASTBitcodeBuffer(const TranslationUnit& TU,
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);
fclose(fp);
return true;
}
return false;
}
TranslationUnit*
clang::ReadASTBitcodeBuffer(llvm::MemoryBuffer& MBuffer, FileManager& FMgr) {

View File

@ -977,7 +977,18 @@ public:
virtual void HandleTranslationUnit(TranslationUnit& TU) {
if (Diags.hasErrorOccurred())
return;
EmitASTBitcodeFile(&TU, FName);
// 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(FName.c_str(),"wb")) {
fwrite((char*)&Buffer.front(), sizeof(char), Buffer.size(), fp);
fclose(fp);
}
}
};
@ -1016,7 +1027,19 @@ public:
sprintf(&buf[0], "%s-%llX.ast", FE->getName(),
(unsigned long long) FE->getInode());
FName.appendComponent(&buf[0]);
EmitASTBitcodeFile(&TU, FName);
// 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(FName.c_str(),"wb")) {
fwrite((char*)&Buffer.front(), sizeof(char), Buffer.size(), fp);
fclose(fp);
}
// Now emit the sources.

View File

@ -74,7 +74,21 @@ bool SerializationTest::Serialize(llvm::sys::Path& Filename,
}
// Serialize the translation unit.
return EmitASTBitcodeFile(TU,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);
fclose(fp);
return true;
}
return false;
}
bool SerializationTest::Deserialize(llvm::sys::Path& Filename,