LLVM  9.0.0svn
BitWriter.cpp
Go to the documentation of this file.
1 //===-- BitWriter.cpp -----------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "llvm-c/BitWriter.h"
11 #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);
49 }
int LLVMWriteBitcodeToFileHandle(LLVMModuleRef M, int FileHandle)
Deprecated for LLVMWriteBitcodeToFD.
Definition: BitWriter.cpp:39
This class represents lattice values for constants.
Definition: AllocatorList.h:23
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:20
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:203
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
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:498
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:198
A raw_ostream that writes to a file descriptor.
Definition: raw_ostream.h:365
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:482