opnsense-src/lib/Bitcode/Writer/BitWriter.cpp

47 lines
1.2 KiB
C++
Raw Normal View History

2009-06-02 13:52:33 -04:00
//===-- BitWriter.cpp -----------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm-c/BitWriter.h"
#include "llvm/Bitcode/ReaderWriter.h"
2009-10-14 13:57:32 -04:00
#include "llvm/Support/raw_ostream.h"
2009-06-02 13:52:33 -04:00
using namespace llvm;
/*===-- Operations on modules ---------------------------------------------===*/
int LLVMWriteBitcodeToFile(LLVMModuleRef M, const char *Path) {
2009-10-14 13:57:32 -04:00
std::string ErrorInfo;
raw_fd_ostream OS(Path, ErrorInfo,
raw_fd_ostream::F_Binary);
2009-06-02 13:52:33 -04:00
2009-10-14 13:57:32 -04:00
if (!ErrorInfo.empty())
2009-06-02 13:52:33 -04:00
return -1;
2009-10-14 13:57:32 -04:00
WriteBitcodeToFile(unwrap(M), OS);
2009-06-02 13:52:33 -04:00
return 0;
}
#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR >= 4)
#include <ext/stdio_filebuf.h>
int LLVMWriteBitcodeToFileHandle(LLVMModuleRef M, int FileHandle) {
2009-10-14 13:57:32 -04:00
raw_fd_ostream OS(FileHandle, false);
2009-06-02 13:52:33 -04:00
2009-10-14 13:57:32 -04:00
WriteBitcodeToFile(unwrap(M), OS);
2009-06-02 13:52:33 -04:00
return 0;
}
#else
int LLVMWriteBitcodeToFileHandle(LLVMModuleRef M, int FileHandle) {
return -1; // Not supported.
}
#endif