1 //===-- llvm/MC/MCWasmObjectWriter.h - Wasm Object Writer -------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_MC_MCWASMOBJECTWRITER_H
11 #define LLVM_MC_MCWASMOBJECTWRITER_H
13 #include "llvm/ADT/Triple.h"
14 #include "llvm/MC/MCValue.h"
15 #include "llvm/Support/DataTypes.h"
16 #include "llvm/Support/raw_ostream.h"
29 class raw_pwrite_stream;
31 // Information about a single relocation.
32 struct WasmRelocationEntry {
33 uint64_t Offset; // Where is the relocation.
34 const MCSymbolWasm *Symbol; // The symbol to relocate with.
35 int64_t Addend; // A value to add to the symbol.
36 unsigned Type; // The type of the relocation.
37 MCSectionWasm *FixupSection;// The section the relocation is targeting.
39 WasmRelocationEntry(uint64_t Offset, const MCSymbolWasm *Symbol,
40 int64_t Addend, unsigned Type,
41 MCSectionWasm *FixupSection)
42 : Offset(Offset), Symbol(Symbol), Addend(Addend), Type(Type),
43 FixupSection(FixupSection) {}
45 void print(raw_ostream &Out) const {
46 Out << "Off=" << Offset << ", Sym=" << Symbol << ", Addend=" << Addend
47 << ", Type=" << Type << ", FixupSection=" << FixupSection;
49 void dump() const { print(errs()); }
52 class MCWasmObjectTargetWriter {
53 const unsigned Is64Bit : 1;
56 explicit MCWasmObjectTargetWriter(bool Is64Bit_);
59 virtual ~MCWasmObjectTargetWriter() {}
61 virtual unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
62 const MCFixup &Fixup, bool IsPCRel) const = 0;
64 virtual bool needsRelocateWithSymbol(const MCSymbol &Sym,
67 virtual void sortRelocs(const MCAssembler &Asm,
68 std::vector<WasmRelocationEntry> &Relocs);
72 bool is64Bit() const { return Is64Bit; }
76 /// \brief Construct a new Wasm writer instance.
78 /// \param MOTW - The target specific Wasm writer subclass.
79 /// \param OS - The stream to write to.
80 /// \returns The constructed object writer.
81 MCObjectWriter *createWasmObjectWriter(MCWasmObjectTargetWriter *MOTW,
82 raw_pwrite_stream &OS);
83 } // End llvm namespace