]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm/MC/MCWasmObjectWriter.h
Merge llvm, clang, lld, lldb, compiler-rt and libc++ r304460, and update
[FreeBSD/FreeBSD.git] / contrib / llvm / include / llvm / MC / MCWasmObjectWriter.h
1 //===-- llvm/MC/MCWasmObjectWriter.h - Wasm Object Writer -------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_MC_MCWASMOBJECTWRITER_H
11 #define LLVM_MC_MCWASMOBJECTWRITER_H
12
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"
17 #include <vector>
18
19 namespace llvm {
20 class MCAssembler;
21 class MCContext;
22 class MCFixup;
23 class MCFragment;
24 class MCObjectWriter;
25 class MCSectionWasm;
26 class MCSymbol;
27 class MCSymbolWasm;
28 class MCValue;
29 class raw_pwrite_stream;
30
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.
38
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) {}
44
45   void print(raw_ostream &Out) const {
46     Out << "Off=" << Offset << ", Sym=" << Symbol << ", Addend=" << Addend
47         << ", Type=" << Type << ", FixupSection=" << FixupSection;
48   }
49   void dump() const { print(errs()); }
50 };
51
52 class MCWasmObjectTargetWriter {
53   const unsigned Is64Bit : 1;
54
55 protected:
56   explicit MCWasmObjectTargetWriter(bool Is64Bit_);
57
58 public:
59   virtual ~MCWasmObjectTargetWriter() {}
60
61   virtual unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
62                                 const MCFixup &Fixup, bool IsPCRel) const = 0;
63
64   virtual bool needsRelocateWithSymbol(const MCSymbol &Sym,
65                                        unsigned Type) const;
66
67   virtual void sortRelocs(const MCAssembler &Asm,
68                           std::vector<WasmRelocationEntry> &Relocs);
69
70   /// \name Accessors
71   /// @{
72   bool is64Bit() const { return Is64Bit; }
73   /// @}
74 };
75
76 /// \brief Construct a new Wasm writer instance.
77 ///
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
84
85 #endif