LLVM API Documentation

BitWriter.cpp
Go to the documentation of this file.
00001 //===-- BitWriter.cpp -----------------------------------------------------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 
00010 #include "llvm-c/BitWriter.h"
00011 #include "llvm/Bitcode/ReaderWriter.h"
00012 #include "llvm/IR/Module.h"
00013 #include "llvm/Support/FileSystem.h"
00014 #include "llvm/Support/raw_ostream.h"
00015 using namespace llvm;
00016 
00017 
00018 /*===-- Operations on modules ---------------------------------------------===*/
00019 
00020 int LLVMWriteBitcodeToFile(LLVMModuleRef M, const char *Path) {
00021   std::error_code EC;
00022   raw_fd_ostream OS(Path, EC, sys::fs::F_None);
00023 
00024   if (EC)
00025     return -1;
00026 
00027   WriteBitcodeToFile(unwrap(M), OS);
00028   return 0;
00029 }
00030 
00031 int LLVMWriteBitcodeToFD(LLVMModuleRef M, int FD, int ShouldClose,
00032                          int Unbuffered) {
00033   raw_fd_ostream OS(FD, ShouldClose, Unbuffered);
00034 
00035   WriteBitcodeToFile(unwrap(M), OS);
00036   return 0;
00037 }
00038 
00039 int LLVMWriteBitcodeToFileHandle(LLVMModuleRef M, int FileHandle) {
00040   return LLVMWriteBitcodeToFD(M, FileHandle, true, false);
00041 }