LLVM  3.7.0
BitWriter.cpp
Go to the documentation of this file.
1 //===-- BitWriter.cpp -----------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "llvm-c/BitWriter.h"
12 #include "llvm/IR/Module.h"
15 using namespace llvm;
16 
17 
18 /*===-- Operations on modules ---------------------------------------------===*/
19 
20 int LLVMWriteBitcodeToFile(LLVMModuleRef M, const char *Path) {
21  std::error_code EC;
22  raw_fd_ostream OS(Path, EC, sys::fs::F_None);
23 
24  if (EC)
25  return -1;
26 
27  WriteBitcodeToFile(unwrap(M), OS);
28  return 0;
29 }
30 
31 int LLVMWriteBitcodeToFD(LLVMModuleRef M, int FD, int ShouldClose,
32  int Unbuffered) {
33  raw_fd_ostream OS(FD, ShouldClose, Unbuffered);
34 
35  WriteBitcodeToFile(unwrap(M), OS);
36  return 0;
37 }
38 
40  return LLVMWriteBitcodeToFD(M, FileHandle, true, false);
41 }
42 
44  std::string Data;
45  raw_string_ostream OS(Data);
46 
47  WriteBitcodeToFile(unwrap(M), OS);
48  return wrap(MemoryBuffer::getMemBufferCopy(OS.str()).release());
49 }
int LLVMWriteBitcodeToFileHandle(LLVMModuleRef M, int FileHandle)
Deprecated for LLVMWriteBitcodeToFD.
Definition: BitWriter.cpp:39
int LLVMWriteBitcodeToFile(LLVMModuleRef M, const char *Path)
Writes a module to the specified path.
Definition: BitWriter.cpp:20
struct LLVMOpaqueMemoryBuffer * LLVMMemoryBufferRef
Used to pass regions of memory through LLVM interfaces.
Definition: Support.h:36
LLVMMemoryBufferRef LLVMWriteBitcodeToMemoryBuffer(LLVMModuleRef M)
Writes a module to a new memory buffer and returns it.
Definition: BitWriter.cpp:43
int LLVMWriteBitcodeToFD(LLVMModuleRef M, int FD, int ShouldClose, int Unbuffered)
Writes a module to an open file descriptor.
Definition: BitWriter.cpp:31
LLVMTargetDataRef wrap(const DataLayout *P)
Definition: DataLayout.h:469
DataLayout * unwrap(LLVMTargetDataRef P)
Definition: DataLayout.h:465
void WriteBitcodeToFile(const Module *M, raw_ostream &Out, bool ShouldPreserveUseListOrder=false)
Write the specified module to the specified raw output stream.
std::string & str()
Flushes the stream contents to the target string and returns the string's reference.
Definition: raw_ostream.h:480
Module.h This file contains the declarations for the Module class.
static std::unique_ptr< MemoryBuffer > getMemBufferCopy(StringRef InputData, const Twine &BufferName="")
Open the specified memory range as a MemoryBuffer, copying the contents and taking ownership of it...
A raw_ostream that writes to a file descriptor.
Definition: raw_ostream.h:345
struct LLVMOpaqueModule * LLVMModuleRef
The top-level container for all other LLVM Intermediate Representation (IR) objects.
Definition: Core.h:78
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:465