1 //===-- llvm/MC/MCWasmObjectWriter.h - Wasm Object Writer -------*- C++ -*-===//
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 #ifndef LLVM_MC_MCWASMOBJECTWRITER_H
10 #define LLVM_MC_MCWASMOBJECTWRITER_H
11 
12 #include "llvm/MC/MCObjectWriter.h"
13 #include <memory>
14 
15 namespace llvm {
16 
17 class MCFixup;
18 class MCSectionWasm;
19 class MCValue;
20 class raw_pwrite_stream;
21 
22 class MCWasmObjectTargetWriter : public MCObjectTargetWriter {
23   const unsigned Is64Bit : 1;
24   const unsigned IsEmscripten : 1;
25 
26 protected:
27   explicit MCWasmObjectTargetWriter(bool Is64Bit_, bool IsEmscripten);
28 
29 public:
30   virtual ~MCWasmObjectTargetWriter();
31 
getFormat()32   Triple::ObjectFormatType getFormat() const override { return Triple::Wasm; }
classof(const MCObjectTargetWriter * W)33   static bool classof(const MCObjectTargetWriter *W) {
34     return W->getFormat() == Triple::Wasm;
35   }
36 
37   virtual unsigned getRelocType(const MCValue &Target, const MCFixup &Fixup,
38                                 const MCSectionWasm &FixupSection,
39                                 bool IsLocRel) const = 0;
40 
41   /// \name Accessors
42   /// @{
is64Bit()43   bool is64Bit() const { return Is64Bit; }
isEmscripten()44   bool isEmscripten() const { return IsEmscripten; }
45   /// @}
46 };
47 
48 /// Construct a new Wasm writer instance.
49 ///
50 /// \param MOTW - The target specific Wasm writer subclass.
51 /// \param OS - The stream to write to.
52 /// \returns The constructed object writer.
53 std::unique_ptr<MCObjectWriter>
54 createWasmObjectWriter(std::unique_ptr<MCWasmObjectTargetWriter> MOTW,
55                        raw_pwrite_stream &OS);
56 
57 std::unique_ptr<MCObjectWriter>
58 createWasmDwoObjectWriter(std::unique_ptr<MCWasmObjectTargetWriter> MOTW,
59                           raw_pwrite_stream &OS, raw_pwrite_stream &DwoOS);
60 
61 } // namespace llvm
62 
63 #endif
64