LLVM  8.0.1
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"
16 using namespace llvm;
17 
18 
19 /*===-- Operations on modules ---------------------------------------------===*/
20 
21 int LLVMWriteBitcodeToFile(LLVMModuleRef M, const char *Path) {
22  std::error_code EC;
23  raw_fd_ostream OS(Path, EC, sys::fs::F_None);
24 
25  if (EC)
26  return -1;
27 
28  WriteBitcodeToFile(*unwrap(M), OS);
29  return 0;
30 }
31 
32 int LLVMWriteBitcodeToFD(LLVMModuleRef M, int FD, int ShouldClose,
33  int Unbuffered) {
34  raw_fd_ostream OS(FD, ShouldClose, Unbuffered);
35 
36  WriteBitcodeToFile(*unwrap(M), OS);
37  return 0;
38 }
39 
41  return LLVMWriteBitcodeToFD(M, FileHandle, true, false);
42 }
43 
45  std::string Data;
46  raw_string_ostream OS(Data);
47 
48  WriteBitcodeToFile(*unwrap(M), OS);
50 }
int LLVMWriteBitcodeToFileHandle(LLVMModuleRef M, int FileHandle)
Deprecated for LLVMWriteBitcodeToFD.
Definition: BitWriter.cpp:40
This class represents lattice values for constants.
Definition: AllocatorList.h:24
struct LLVMOpaqueModule * LLVMModuleRef
The top-level container for all other LLVM Intermediate Representation (IR) objects.
Definition: Types.h:62
int LLVMWriteBitcodeToFile(LLVMModuleRef M, const char *Path)
Writes a module to the specified path.
Definition: BitWriter.cpp:21
struct LLVMOpaqueMemoryBuffer * LLVMMemoryBufferRef
LLVM uses a polymorphic type hierarchy which C cannot represent, therefore parameters must be passed ...
Definition: Types.h:49
Attribute unwrap(LLVMAttributeRef Attr)
Definition: Attributes.h:195
LLVMMemoryBufferRef LLVMWriteBitcodeToMemoryBuffer(LLVMModuleRef M)
Writes a module to a new memory buffer and returns it.
Definition: BitWriter.cpp:44
int LLVMWriteBitcodeToFD(LLVMModuleRef M, int FD, int ShouldClose, int Unbuffered)
Writes a module to an open file descriptor.
Definition: BitWriter.cpp:32
void WriteBitcodeToFile(const Module &M, raw_ostream &Out, bool ShouldPreserveUseListOrder=false, const ModuleSummaryIndex *Index=nullptr, bool GenerateHash=false, ModuleHash *ModHash=nullptr)
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:499
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...
LLVMAttributeRef wrap(Attribute Attr)
Definition: Attributes.h:190
A raw_ostream that writes to a file descriptor.
Definition: raw_ostream.h:366
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:483