2007-09-18 05:18:57 +02:00
|
|
|
//===-- BitWriter.cpp -----------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 21:36:04 +01:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-09-18 05:18:57 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm-c/BitWriter.h"
|
|
|
|
#include "llvm/Bitcode/ReaderWriter.h"
|
2009-08-23 09:49:08 +02:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2007-09-18 05:18:57 +02:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
|
|
|
|
/*===-- Operations on modules ---------------------------------------------===*/
|
|
|
|
|
|
|
|
int LLVMWriteBitcodeToFile(LLVMModuleRef M, const char *Path) {
|
2009-08-23 09:49:08 +02:00
|
|
|
std::string ErrorInfo;
|
|
|
|
raw_fd_ostream OS(Path, ErrorInfo,
|
2009-08-25 17:34:52 +02:00
|
|
|
raw_fd_ostream::F_Binary);
|
2007-09-18 05:18:57 +02:00
|
|
|
|
2009-08-23 09:49:08 +02:00
|
|
|
if (!ErrorInfo.empty())
|
2007-09-18 05:18:57 +02:00
|
|
|
return -1;
|
|
|
|
|
2009-08-23 09:49:08 +02:00
|
|
|
WriteBitcodeToFile(unwrap(M), OS);
|
2007-09-18 05:18:57 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-06-11 12:46:24 +02:00
|
|
|
#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR >= 4)
|
2007-09-18 05:18:57 +02:00
|
|
|
#include <ext/stdio_filebuf.h>
|
|
|
|
|
|
|
|
int LLVMWriteBitcodeToFileHandle(LLVMModuleRef M, int FileHandle) {
|
2009-08-23 09:49:08 +02:00
|
|
|
raw_fd_ostream OS(FileHandle, false);
|
2007-09-18 05:18:57 +02:00
|
|
|
|
2009-08-23 09:49:08 +02:00
|
|
|
WriteBitcodeToFile(unwrap(M), OS);
|
2007-09-18 05:18:57 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-06-11 12:46:24 +02:00
|
|
|
#else
|
|
|
|
|
|
|
|
int LLVMWriteBitcodeToFileHandle(LLVMModuleRef M, int FileHandle) {
|
|
|
|
return -1; // Not supported.
|
|
|
|
}
|
|
|
|
|
2007-09-18 05:18:57 +02:00
|
|
|
#endif
|