blob: 00da632bbcc61e4f772bc4446ae99a476ad11789 [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===-- llvm/MC/MCWasmObjectWriter.h - Wasm Object Writer -------*- C++ -*-===//
2//
Andrew Walbran16937d02019-10-22 13:54:20 +01003// 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
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01006//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_MC_MCWASMOBJECTWRITER_H
10#define LLVM_MC_MCWASMOBJECTWRITER_H
11
Andrew Scullcdfcccc2018-10-05 20:58:37 +010012#include "llvm/MC/MCObjectWriter.h"
13#include <memory>
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010014
15namespace llvm {
16
17class MCFixup;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010018class MCValue;
19class raw_pwrite_stream;
20
Andrew Scullcdfcccc2018-10-05 20:58:37 +010021class MCWasmObjectTargetWriter : public MCObjectTargetWriter {
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010022 const unsigned Is64Bit : 1;
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020023 const unsigned IsEmscripten : 1;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010024
25protected:
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020026 explicit MCWasmObjectTargetWriter(bool Is64Bit_, bool IsEmscripten);
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010027
28public:
29 virtual ~MCWasmObjectTargetWriter();
30
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020031 Triple::ObjectFormatType getFormat() const override { return Triple::Wasm; }
Andrew Scullcdfcccc2018-10-05 20:58:37 +010032 static bool classof(const MCObjectTargetWriter *W) {
33 return W->getFormat() == Triple::Wasm;
34 }
35
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010036 virtual unsigned getRelocType(const MCValue &Target,
37 const MCFixup &Fixup) const = 0;
38
39 /// \name Accessors
40 /// @{
41 bool is64Bit() const { return Is64Bit; }
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020042 bool isEmscripten() const { return IsEmscripten; }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010043 /// @}
44};
45
Andrew Scullcdfcccc2018-10-05 20:58:37 +010046/// Construct a new Wasm writer instance.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010047///
48/// \param MOTW - The target specific Wasm writer subclass.
49/// \param OS - The stream to write to.
50/// \returns The constructed object writer.
51std::unique_ptr<MCObjectWriter>
52createWasmObjectWriter(std::unique_ptr<MCWasmObjectTargetWriter> MOTW,
53 raw_pwrite_stream &OS);
54
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020055std::unique_ptr<MCObjectWriter>
56createWasmDwoObjectWriter(std::unique_ptr<MCWasmObjectTargetWriter> MOTW,
57 raw_pwrite_stream &OS, raw_pwrite_stream &DwoOS);
58
Andrew Scull0372a572018-11-16 15:47:06 +000059} // namespace llvm
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010060
61#endif