Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:15

0001 //===-- llvm/MC/MCSPIRVObjectWriter.h - SPIR-V Object Writer -----*- C++ *-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_MC_MCSPIRVOBJECTWRITER_H
0010 #define LLVM_MC_MCSPIRVOBJECTWRITER_H
0011 
0012 #include "llvm/MC/MCObjectWriter.h"
0013 #include "llvm/MC/MCValue.h"
0014 #include "llvm/Support/EndianStream.h"
0015 #include "llvm/Support/raw_ostream.h"
0016 #include <memory>
0017 
0018 namespace llvm {
0019 
0020 class MCSPIRVObjectTargetWriter : public MCObjectTargetWriter {
0021 protected:
0022   explicit MCSPIRVObjectTargetWriter() {}
0023 
0024 public:
0025   Triple::ObjectFormatType getFormat() const override { return Triple::SPIRV; }
0026   static bool classof(const MCObjectTargetWriter *W) {
0027     return W->getFormat() == Triple::SPIRV;
0028   }
0029 };
0030 
0031 class SPIRVObjectWriter final : public MCObjectWriter {
0032   support::endian::Writer W;
0033   std::unique_ptr<MCSPIRVObjectTargetWriter> TargetObjectWriter;
0034 
0035   struct VersionInfoType {
0036     unsigned Major = 0;
0037     unsigned Minor = 0;
0038     unsigned Bound = 0;
0039   } VersionInfo;
0040 
0041 public:
0042   SPIRVObjectWriter(std::unique_ptr<MCSPIRVObjectTargetWriter> MOTW,
0043                     raw_pwrite_stream &OS)
0044       : W(OS, llvm::endianness::little), TargetObjectWriter(std::move(MOTW)) {}
0045 
0046   void setBuildVersion(unsigned Major, unsigned Minor, unsigned Bound);
0047 
0048 private:
0049   void recordRelocation(MCAssembler &Asm, const MCFragment *Fragment,
0050                         const MCFixup &Fixup, MCValue Target,
0051                         uint64_t &FixedValue) override {}
0052 
0053   uint64_t writeObject(MCAssembler &Asm) override;
0054   void writeHeader(const MCAssembler &Asm);
0055 };
0056 
0057 /// Construct a new SPIR-V writer instance.
0058 ///
0059 /// \param MOTW - The target specific SPIR-V writer subclass.
0060 /// \param OS - The stream to write to.
0061 /// \returns The constructed object writer.
0062 std::unique_ptr<MCObjectWriter>
0063 createSPIRVObjectWriter(std::unique_ptr<MCSPIRVObjectTargetWriter> MOTW,
0064                         raw_pwrite_stream &OS);
0065 
0066 } // namespace llvm
0067 
0068 #endif