LLVM 20.0.0git
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"
15using namespace llvm;
16
17
18/*===-- Operations on modules ---------------------------------------------===*/
19
20int LLVMWriteBitcodeToFile(LLVMModuleRef M, const char *Path) {
21 std::error_code EC;
23
24 if (EC)
25 return -1;
26
28 return 0;
29}
30
31int LLVMWriteBitcodeToFD(LLVMModuleRef M, int FD, int ShouldClose,
32 int Unbuffered) {
33 raw_fd_ostream OS(FD, ShouldClose, Unbuffered);
34
36 return 0;
37}
38
40 return LLVMWriteBitcodeToFD(M, FileHandle, true, false);
41}
42
44 std::string Data;
46
48 return wrap(MemoryBuffer::getMemBufferCopy(OS.str()).release());
49}
Module.h This file contains the declarations for the Module class.
raw_pwrite_stream & OS
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:460
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:661
int LLVMWriteBitcodeToFile(LLVMModuleRef M, const char *Path)
Writes a module to the specified path.
Definition: BitWriter.cpp:20
int LLVMWriteBitcodeToFileHandle(LLVMModuleRef M, int FileHandle)
Deprecated for LLVMWriteBitcodeToFD.
Definition: BitWriter.cpp:39
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
struct LLVMOpaqueMemoryBuffer * LLVMMemoryBufferRef
LLVM uses a polymorphic type hierarchy which C cannot represent, therefore parameters must be passed ...
Definition: Types.h:48
struct LLVMOpaqueModule * LLVMModuleRef
The top-level container for all other LLVM Intermediate Representation (IR) objects.
Definition: Types.h:61
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
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.
Attribute unwrap(LLVMAttributeRef Attr)
Definition: Attributes.h:332
LLVMAttributeRef wrap(Attribute Attr)
Definition: Attributes.h:327