blob: 9f51c35ad92e2068e64e9e55046fbcc9cc41b57c [file] [log] [blame]
Gordon Henriksen8b94a142007-09-18 03:18:57 +00001//===-- BitWriter.cpp -----------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Gordon Henriksen8b94a142007-09-18 03:18:57 +00007//
8//===----------------------------------------------------------------------===//
9
10#include "llvm-c/BitWriter.h"
Gordon Henriksen8b94a142007-09-18 03:18:57 +000011#include "llvm/Bitcode/ReaderWriter.h"
Chris Lattnerb515d752009-08-23 07:49:08 +000012#include "llvm/Support/raw_ostream.h"
Gordon Henriksen8b94a142007-09-18 03:18:57 +000013using namespace llvm;
14
15
16/*===-- Operations on modules ---------------------------------------------===*/
17
18int LLVMWriteBitcodeToFile(LLVMModuleRef M, const char *Path) {
Chris Lattnerb515d752009-08-23 07:49:08 +000019 std::string ErrorInfo;
Joe Abbey170a15e2012-11-25 15:23:39 +000020 raw_fd_ostream OS(Path, ErrorInfo, raw_fd_ostream::F_Binary);
21
Chris Lattnerb515d752009-08-23 07:49:08 +000022 if (!ErrorInfo.empty())
Gordon Henriksen8b94a142007-09-18 03:18:57 +000023 return -1;
Joe Abbey170a15e2012-11-25 15:23:39 +000024
Chris Lattnerb515d752009-08-23 07:49:08 +000025 WriteBitcodeToFile(unwrap(M), OS);
Gordon Henriksen8b94a142007-09-18 03:18:57 +000026 return 0;
27}
28
Erick Tryzelaare6230502010-03-06 00:30:06 +000029int LLVMWriteBitcodeToFD(LLVMModuleRef M, int FD, int ShouldClose,
30 int Unbuffered) {
31 raw_fd_ostream OS(FD, ShouldClose, Unbuffered);
Joe Abbey170a15e2012-11-25 15:23:39 +000032
Chris Lattnerb515d752009-08-23 07:49:08 +000033 WriteBitcodeToFile(unwrap(M), OS);
Gordon Henriksen8b94a142007-09-18 03:18:57 +000034 return 0;
35}
Erick Tryzelaare6230502010-03-06 00:30:06 +000036
37int LLVMWriteBitcodeToFileHandle(LLVMModuleRef M, int FileHandle) {
38 return LLVMWriteBitcodeToFD(M, FileHandle, true, false);
39}