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
This commit is contained in:
Chris Lattner
2009-08-23 07:49:08 +00:00
parent a81d29b391
commit b515d75856
9 changed files with 80 additions and 128 deletions

View File

@ -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);
std::string ErrorInfo;
raw_fd_ostream OS(Path, ErrorInfo,
raw_fd_ostream::F_Force|raw_fd_ostream::F_Binary);
if (!OS.fail())
WriteBitcodeToFile(unwrap(M), OS);
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;
}