blob: 985208c40fdbf4a8c65cadbcbc7222375be53266 [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"
Filip Pizlo40be1e82013-05-01 20:59:00 +000012#include "llvm/IR/Module.h"
Chris Lattnerb515d752009-08-23 07:49:08 +000013#include "llvm/Support/raw_ostream.h"
Gordon Henriksen8b94a142007-09-18 03:18:57 +000014using namespace llvm;
15
16
17/*===-- Operations on modules ---------------------------------------------===*/
18
19int LLVMWriteBitcodeToFile(LLVMModuleRef M, const char *Path) {
Chris Lattnerb515d752009-08-23 07:49:08 +000020 std::string ErrorInfo;
Joe Abbey170a15e2012-11-25 15:23:39 +000021 raw_fd_ostream OS(Path, ErrorInfo, raw_fd_ostream::F_Binary);
22
Chris Lattnerb515d752009-08-23 07:49:08 +000023 if (!ErrorInfo.empty())
Gordon Henriksen8b94a142007-09-18 03:18:57 +000024 return -1;
Joe Abbey170a15e2012-11-25 15:23:39 +000025
Chris Lattnerb515d752009-08-23 07:49:08 +000026 WriteBitcodeToFile(unwrap(M), OS);
Gordon Henriksen8b94a142007-09-18 03:18:57 +000027 return 0;
28}
29
Erick Tryzelaare6230502010-03-06 00:30:06 +000030int LLVMWriteBitcodeToFD(LLVMModuleRef M, int FD, int ShouldClose,
31 int Unbuffered) {
32 raw_fd_ostream OS(FD, ShouldClose, Unbuffered);
Joe Abbey170a15e2012-11-25 15:23:39 +000033
Chris Lattnerb515d752009-08-23 07:49:08 +000034 WriteBitcodeToFile(unwrap(M), OS);
Gordon Henriksen8b94a142007-09-18 03:18:57 +000035 return 0;
36}
Erick Tryzelaare6230502010-03-06 00:30:06 +000037
38int LLVMWriteBitcodeToFileHandle(LLVMModuleRef M, int FileHandle) {
39 return LLVMWriteBitcodeToFD(M, FileHandle, true, false);
40}