summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-08-23 07:49:08 +0000
committerChris Lattner <sabre@nondot.org>2009-08-23 07:49:08 +0000
commitb515d75856f58a8b3b71d782eb00916d686329ad (patch)
treef44504088f40b4ba59e2583c25ea523e8c15ae82 /lib
parenta81d29b3916c2eb87a17f800f3759ce21a4a96fd (diff)
downloadllvm-b515d75856f58a8b3b71d782eb00916d686329ad.tar.gz
llvm-b515d75856f58a8b3b71d782eb00916d686329ad.tar.bz2
llvm-b515d75856f58a8b3b71d782eb00916d686329ad.tar.xz
eliminate the std::ostream forms of the bitcode writing APIs.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79840 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Bitcode/Reader/Deserialize.cpp14
-rw-r--r--lib/Bitcode/Writer/BitWriter.cpp28
-rw-r--r--lib/Bitcode/Writer/BitcodeWriter.cpp11
-rw-r--r--lib/Bitcode/Writer/BitcodeWriterPass.cpp21
4 files changed, 16 insertions, 58 deletions
diff --git a/lib/Bitcode/Reader/Deserialize.cpp b/lib/Bitcode/Reader/Deserialize.cpp
index 06da6ce727..67607efae0 100644
--- a/lib/Bitcode/Reader/Deserialize.cpp
+++ b/lib/Bitcode/Reader/Deserialize.cpp
@@ -12,11 +12,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/Bitcode/Deserialize.h"
-
-#ifdef DEBUG_BACKPATCH
-#include "llvm/Support/Streams.h"
-#endif
-
+#include "llvm/Support/raw_ostream.h"
using namespace llvm;
Deserializer::Deserializer(BitstreamReader& stream)
@@ -357,7 +353,7 @@ void Deserializer::RegisterPtr(const SerializedPtrID& PtrId,
assert (!HasFinalPtr(E) && "Pointer already registered.");
#ifdef DEBUG_BACKPATCH
- llvm::cerr << "RegisterPtr: " << PtrId << " => " << Ptr << "\n";
+ errs() << "RegisterPtr: " << PtrId << " => " << Ptr << "\n";
#endif
SetPtr(E,Ptr);
@@ -377,8 +373,8 @@ void Deserializer::ReadUIntPtr(uintptr_t& PtrRef,
PtrRef = GetFinalPtr(E);
#ifdef DEBUG_BACKPATCH
- llvm::cerr << "ReadUintPtr: " << PtrId
- << " <-- " << (void*) GetFinalPtr(E) << '\n';
+ errs() << "ReadUintPtr: " << PtrId
+ << " <-- " << (void*) GetFinalPtr(E) << '\n';
#endif
}
else {
@@ -386,7 +382,7 @@ void Deserializer::ReadUIntPtr(uintptr_t& PtrRef,
"Client forbids backpatching for this pointer.");
#ifdef DEBUG_BACKPATCH
- llvm::cerr << "ReadUintPtr: " << PtrId << " (NO PTR YET)\n";
+ errs() << "ReadUintPtr: " << PtrId << " (NO PTR YET)\n";
#endif
// Register backpatch. Check the freelist for a BPNode.
diff --git a/lib/Bitcode/Writer/BitWriter.cpp b/lib/Bitcode/Writer/BitWriter.cpp
index 8834964b04..32a740569f 100644
--- a/lib/Bitcode/Writer/BitWriter.cpp
+++ b/lib/Bitcode/Writer/BitWriter.cpp
@@ -9,43 +9,31 @@
#include "llvm-c/BitWriter.h"
#include "llvm/Bitcode/ReaderWriter.h"
-#include <fstream>
-
+#include "llvm/Support/raw_ostream.h"
using namespace llvm;
/*===-- Operations on modules ---------------------------------------------===*/
int LLVMWriteBitcodeToFile(LLVMModuleRef M, const char *Path) {
- std::ofstream OS(Path, std::ios_base::out|std::ios::trunc|std::ios::binary);
-
- if (!OS.fail())
- WriteBitcodeToFile(unwrap(M), OS);
+ std::string ErrorInfo;
+ raw_fd_ostream OS(Path, ErrorInfo,
+ raw_fd_ostream::F_Force|raw_fd_ostream::F_Binary);
- if (OS.fail())
+ if (!ErrorInfo.empty())
return -1;
+ WriteBitcodeToFile(unwrap(M), OS);
return 0;
}
#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR >= 4)
#include <ext/stdio_filebuf.h>
-// FIXME: Control this with configure? Provide some portable abstraction in
-// libSystem? As is, the user will just get a linker error if they use this on
-// non-GCC. Some C++ stdlibs even have ofstream::ofstream(int fd).
int LLVMWriteBitcodeToFileHandle(LLVMModuleRef M, int FileHandle) {
- __gnu_cxx::stdio_filebuf<char> Buffer(FileHandle, std::ios_base::out |
- std::ios::trunc |
- std::ios::binary);
- std::ostream OS(&Buffer);
-
- if (!OS.fail())
- WriteBitcodeToFile(unwrap(M), OS);
-
- if (OS.fail())
- return -1;
+ raw_fd_ostream OS(FileHandle, false);
+ WriteBitcodeToFile(unwrap(M), OS);
return 0;
}
diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp
index 6a14cb3bbd..9cb5758576 100644
--- a/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -26,7 +26,6 @@
#include "llvm/ValueSymbolTable.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MathExtras.h"
-#include "llvm/Support/Streams.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/System/Program.h"
using namespace llvm;
@@ -1468,16 +1467,6 @@ static void EmitDarwinBCTrailer(BitstreamWriter &Stream, unsigned BufferSize) {
/// WriteBitcodeToFile - Write the specified module to the specified output
/// stream.
-void llvm::WriteBitcodeToFile(const Module *M, std::ostream &Out) {
- raw_os_ostream RawOut(Out);
- // If writing to stdout, set binary mode.
- if (llvm::cout == Out)
- sys::Program::ChangeStdoutToBinary();
- WriteBitcodeToFile(M, RawOut);
-}
-
-/// WriteBitcodeToFile - Write the specified module to the specified output
-/// stream.
void llvm::WriteBitcodeToFile(const Module *M, raw_ostream &Out) {
std::vector<unsigned char> Buffer;
BitstreamWriter Stream(Buffer);
diff --git a/lib/Bitcode/Writer/BitcodeWriterPass.cpp b/lib/Bitcode/Writer/BitcodeWriterPass.cpp
index 209cf0980d..3a0d3ce0be 100644
--- a/lib/Bitcode/Writer/BitcodeWriterPass.cpp
+++ b/lib/Bitcode/Writer/BitcodeWriterPass.cpp
@@ -17,24 +17,16 @@ using namespace llvm;
namespace {
class WriteBitcodePass : public ModulePass {
- // FIXME: Kill off std::ostream
- std::ostream *Out;
- raw_ostream *RawOut; // raw_ostream to print on
+ raw_ostream &OS; // raw_ostream to print on
public:
static char ID; // Pass identification, replacement for typeid
- explicit WriteBitcodePass(std::ostream &o)
- : ModulePass(&ID), Out(&o), RawOut(0) {}
explicit WriteBitcodePass(raw_ostream &o)
- : ModulePass(&ID), Out(0), RawOut(&o) {}
+ : ModulePass(&ID), OS(o) {}
const char *getPassName() const { return "Bitcode Writer"; }
bool runOnModule(Module &M) {
- if (Out) {
- WriteBitcodeToFile(&M, *Out);
- } else {
- WriteBitcodeToFile(&M, *RawOut);
- }
+ WriteBitcodeToFile(&M, OS);
return false;
}
};
@@ -42,13 +34,6 @@ namespace {
char WriteBitcodePass::ID = 0;
-/// CreateBitcodeWriterPass - Create and return a pass that writes the module
-/// to the specified ostream.
-ModulePass *llvm::CreateBitcodeWriterPass(std::ostream &Str) {
- return new WriteBitcodePass(Str);
-}
-
-
/// createBitcodeWriterPass - Create and return a pass that writes the module
/// to the specified ostream.
ModulePass *llvm::createBitcodeWriterPass(raw_ostream &Str) {