1//===- Bitcode/Writer/DXILBitcodeWriter.cpp - DXIL Bitcode Writer ---------===//
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// Bitcode writer implementation.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_DXILWRITER_DXILBITCODEWRITER_H
14#define LLVM_DXILWRITER_DXILBITCODEWRITER_H
15
16#include "llvm/ADT/StringRef.h"
17#include "llvm/IR/ModuleSummaryIndex.h"
18#include "llvm/MC/StringTableBuilder.h"
19#include "llvm/Support/Allocator.h"
20#include "llvm/Support/MemoryBufferRef.h"
21#include <memory>
22#include <vector>
23
24namespace llvm {
25
26class BitstreamWriter;
27class Module;
28class raw_ostream;
29
30namespace dxil {
31
32class DXILDebugInfoMap;
33
34class BitcodeWriter {
35 SmallVectorImpl<char> &Buffer;
36 std::unique_ptr<BitstreamWriter> Stream;
37
38 StringTableBuilder StrtabBuilder{StringTableBuilder::RAW};
39
40 // Owns any strings created by the irsymtab writer until we create the
41 // string table.
42 BumpPtrAllocator Alloc;
43
44 void writeBlob(unsigned Block, unsigned Record, StringRef Blob);
45
46 std::vector<Module *> Mods;
47
48public:
49 /// Create a BitcodeWriter that writes to Buffer.
50 BitcodeWriter(SmallVectorImpl<char> &Buffer);
51
52 ~BitcodeWriter();
53
54 /// Write the specified module to the buffer specified at construction time.
55 void writeModule(const Module &M, const DXILDebugInfoMap &DebugInfo);
56};
57
58/// Write the specified module to the specified raw output stream.
59///
60/// For streams where it matters, the given stream should be in "binary"
61/// mode.
62void WriteDXILToFile(Module &M, raw_ostream &Out);
63
64} // namespace dxil
65
66} // namespace llvm
67
68#endif // LLVM_DXILWRITER_DXILBITCODEWRITER_H
69