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 <map> 22 #include <memory> 23 #include <string> 24 #include <vector> 25 26 namespace llvm { 27 28 class BitstreamWriter; 29 class Module; 30 class raw_ostream; 31 32 namespace dxil { 33 34 class 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 48 public: 49 /// Create a BitcodeWriter that writes to Buffer. 50 BitcodeWriter(SmallVectorImpl<char> &Buffer, raw_fd_stream *FS = nullptr); 51 52 ~BitcodeWriter(); 53 54 /// Write the specified module to the buffer specified at construction time. 55 void writeModule(const Module &M); 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. 62 void WriteDXILToFile(const Module &M, raw_ostream &Out); 63 64 } // namespace dxil 65 66 } // namespace llvm 67 68 #endif // LLVM_DXILWRITER_DXILBITCODEWRITER_H 69