xref: /freebsd-src/contrib/llvm-project/llvm/include/llvm/MC/MCWasmObjectWriter.h (revision fe6060f10f634930ff71b7c50291ddc610da2475)
10b57cec5SDimitry Andric //===-- llvm/MC/MCWasmObjectWriter.h - Wasm Object Writer -------*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric 
90b57cec5SDimitry Andric #ifndef LLVM_MC_MCWASMOBJECTWRITER_H
100b57cec5SDimitry Andric #define LLVM_MC_MCWASMOBJECTWRITER_H
110b57cec5SDimitry Andric 
120b57cec5SDimitry Andric #include "llvm/MC/MCObjectWriter.h"
130b57cec5SDimitry Andric #include <memory>
140b57cec5SDimitry Andric 
150b57cec5SDimitry Andric namespace llvm {
160b57cec5SDimitry Andric 
170b57cec5SDimitry Andric class MCFixup;
18*fe6060f1SDimitry Andric class MCSectionWasm;
190b57cec5SDimitry Andric class MCValue;
200b57cec5SDimitry Andric class raw_pwrite_stream;
210b57cec5SDimitry Andric 
220b57cec5SDimitry Andric class MCWasmObjectTargetWriter : public MCObjectTargetWriter {
230b57cec5SDimitry Andric   const unsigned Is64Bit : 1;
248bcb0991SDimitry Andric   const unsigned IsEmscripten : 1;
250b57cec5SDimitry Andric 
260b57cec5SDimitry Andric protected:
278bcb0991SDimitry Andric   explicit MCWasmObjectTargetWriter(bool Is64Bit_, bool IsEmscripten);
280b57cec5SDimitry Andric 
290b57cec5SDimitry Andric public:
300b57cec5SDimitry Andric   virtual ~MCWasmObjectTargetWriter();
310b57cec5SDimitry Andric 
getFormat()325ffd83dbSDimitry Andric   Triple::ObjectFormatType getFormat() const override { return Triple::Wasm; }
classof(const MCObjectTargetWriter * W)330b57cec5SDimitry Andric   static bool classof(const MCObjectTargetWriter *W) {
340b57cec5SDimitry Andric     return W->getFormat() == Triple::Wasm;
350b57cec5SDimitry Andric   }
360b57cec5SDimitry Andric 
37*fe6060f1SDimitry Andric   virtual unsigned getRelocType(const MCValue &Target, const MCFixup &Fixup,
38*fe6060f1SDimitry Andric                                 const MCSectionWasm &FixupSection,
39*fe6060f1SDimitry Andric                                 bool IsLocRel) const = 0;
400b57cec5SDimitry Andric 
410b57cec5SDimitry Andric   /// \name Accessors
420b57cec5SDimitry Andric   /// @{
is64Bit()430b57cec5SDimitry Andric   bool is64Bit() const { return Is64Bit; }
isEmscripten()448bcb0991SDimitry Andric   bool isEmscripten() const { return IsEmscripten; }
450b57cec5SDimitry Andric   /// @}
460b57cec5SDimitry Andric };
470b57cec5SDimitry Andric 
480b57cec5SDimitry Andric /// Construct a new Wasm writer instance.
490b57cec5SDimitry Andric ///
500b57cec5SDimitry Andric /// \param MOTW - The target specific Wasm writer subclass.
510b57cec5SDimitry Andric /// \param OS - The stream to write to.
520b57cec5SDimitry Andric /// \returns The constructed object writer.
530b57cec5SDimitry Andric std::unique_ptr<MCObjectWriter>
540b57cec5SDimitry Andric createWasmObjectWriter(std::unique_ptr<MCWasmObjectTargetWriter> MOTW,
550b57cec5SDimitry Andric                        raw_pwrite_stream &OS);
560b57cec5SDimitry Andric 
57e8d8bef9SDimitry Andric std::unique_ptr<MCObjectWriter>
58e8d8bef9SDimitry Andric createWasmDwoObjectWriter(std::unique_ptr<MCWasmObjectTargetWriter> MOTW,
59e8d8bef9SDimitry Andric                           raw_pwrite_stream &OS, raw_pwrite_stream &DwoOS);
60e8d8bef9SDimitry Andric 
610b57cec5SDimitry Andric } // namespace llvm
620b57cec5SDimitry Andric 
630b57cec5SDimitry Andric #endif
64