blob: 6c9f7b3276fdaa883c6413c26d697ade7075d1a9 [file] [log] [blame]
Gordon Henriksen76a03742007-09-18 03:18:57 +00001//===-- BitWriter.cpp -----------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-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 Henriksen76a03742007-09-18 03:18:57 +00007//
8//===----------------------------------------------------------------------===//
9
10#include "llvm-c/BitWriter.h"
Gordon Henriksen76a03742007-09-18 03:18:57 +000011#include "llvm/Bitcode/ReaderWriter.h"
Filip Pizlodec20e42013-05-01 20:59:00 +000012#include "llvm/IR/Module.h"
Benjamin Kramerd59664f2014-04-29 23:26:49 +000013#include "llvm/Support/FileSystem.h"
Chris Lattner69733952009-08-23 07:49:08 +000014#include "llvm/Support/raw_ostream.h"
Gordon Henriksen76a03742007-09-18 03:18:57 +000015using namespace llvm;
16
17
18/*===-- Operations on modules ---------------------------------------------===*/
19
20int LLVMWriteBitcodeToFile(LLVMModuleRef M, const char *Path) {
Rafael Espindola3fd1e992014-08-25 18:16:47 +000021 std::error_code EC;
22 raw_fd_ostream OS(Path, EC, sys::fs::F_None);
Joe Abbey2ad8df22012-11-25 15:23:39 +000023
Rafael Espindola3fd1e992014-08-25 18:16:47 +000024 if (EC)
Gordon Henriksen76a03742007-09-18 03:18:57 +000025 return -1;
Joe Abbey2ad8df22012-11-25 15:23:39 +000026
Chris Lattner69733952009-08-23 07:49:08 +000027 WriteBitcodeToFile(unwrap(M), OS);
Gordon Henriksen76a03742007-09-18 03:18:57 +000028 return 0;
29}
30
Erick Tryzelaar381268e2010-03-06 00:30:06 +000031int LLVMWriteBitcodeToFD(LLVMModuleRef M, int FD, int ShouldClose,
32 int Unbuffered) {
33 raw_fd_ostream OS(FD, ShouldClose, Unbuffered);
Joe Abbey2ad8df22012-11-25 15:23:39 +000034
Chris Lattner69733952009-08-23 07:49:08 +000035 WriteBitcodeToFile(unwrap(M), OS);
Gordon Henriksen76a03742007-09-18 03:18:57 +000036 return 0;
37}
Erick Tryzelaar381268e2010-03-06 00:30:06 +000038
39int LLVMWriteBitcodeToFileHandle(LLVMModuleRef M, int FileHandle) {
40 return LLVMWriteBitcodeToFD(M, FileHandle, true, false);
41}