1 //===-- BitWriter.cpp -----------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm-c/BitWriter.h"
11 #include "llvm/CHelpers.h"
12 #include "llvm/Bitcode/ReaderWriter.h"
18 /*===-- Operations on modules ---------------------------------------------===*/
20 int LLVMWriteBitcodeToFile(LLVMModuleRef M, const char *Path) {
21 std::ofstream OS(Path);
24 WriteBitcodeToFile(unwrap(M), OS);
33 #include <ext/stdio_filebuf.h>
35 // FIXME: Control this with configure? Provide some portable abstraction in
36 // libSystem? As is, the user will just get a linker error if they use this on
37 // non-GCC. Some C++ stdlibs even have ofstream::ofstream(int fd).
38 int LLVMWriteBitcodeToFileHandle(LLVMModuleRef M, int FileHandle) {
39 __gnu_cxx::stdio_filebuf<char> Buffer(FileHandle, std::ios_base::out);
40 std::ostream OS(&Buffer);
43 WriteBitcodeToFile(unwrap(M), OS);