| OLD | NEW |
| 1 //===- subzero/src/IceFixups.h - Assembler fixup kinds ----------*- C++ -*-===// | 1 //===- subzero/src/IceFixups.h - Assembler fixup kinds ----------*- C++ -*-===// |
| 2 // | 2 // |
| 3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
| 4 // | 4 // |
| 5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 /// | 9 /// |
| 10 /// \file | 10 /// \file |
| 11 /// \brief Declares generic fixup types. | 11 /// \brief Declares generic fixup types. |
| 12 /// | 12 /// |
| 13 //===----------------------------------------------------------------------===// | 13 //===----------------------------------------------------------------------===// |
| 14 | 14 |
| 15 #ifndef SUBZERO_SRC_ICEFIXUPS_H | 15 #ifndef SUBZERO_SRC_ICEFIXUPS_H |
| 16 #define SUBZERO_SRC_ICEFIXUPS_H | 16 #define SUBZERO_SRC_ICEFIXUPS_H |
| 17 | 17 |
| 18 #include "IceDefs.h" | 18 #include "IceDefs.h" |
| 19 | 19 |
| 20 namespace Ice { | 20 namespace Ice { |
| 21 | 21 |
| 22 /// Each target and container format has a different namespace of relocations. | 22 /// Each target and container format has a different namespace of relocations. |
| 23 /// This holds the specific target+container format's relocation number. | 23 /// This holds the specific target+container format's relocation number. |
| 24 using FixupKind = uint32_t; | 24 using FixupKind = uint32_t; |
| 25 | 25 |
| 26 struct ELFSym; |
| 27 |
| 26 /// Assembler fixups are positions in generated code/data that hold relocation | 28 /// Assembler fixups are positions in generated code/data that hold relocation |
| 27 /// information that needs to be processed before finalizing the code/data. | 29 /// information that needs to be processed before finalizing the code/data. |
| 28 class AssemblerFixup { | 30 class AssemblerFixup { |
| 29 AssemblerFixup &operator=(const AssemblerFixup &) = delete; | 31 AssemblerFixup &operator=(const AssemblerFixup &) = delete; |
| 30 | 32 |
| 31 public: | 33 public: |
| 32 AssemblerFixup() = default; | 34 AssemblerFixup() = default; |
| 33 AssemblerFixup(const AssemblerFixup &) = default; | 35 AssemblerFixup(const AssemblerFixup &) = default; |
| 34 virtual ~AssemblerFixup() = default; | 36 virtual ~AssemblerFixup() = default; |
| 35 intptr_t position() const { | 37 intptr_t position() const { return position_; } |
| 36 assert(position_was_set_); | 38 void set_position(intptr_t Position) { position_ = Position; } |
| 37 return position_; | |
| 38 } | |
| 39 void set_position(intptr_t Position) { | |
| 40 position_ = Position; | |
| 41 position_was_set_ = true; | |
| 42 } | |
| 43 | 39 |
| 44 FixupKind kind() const { return kind_; } | 40 FixupKind kind() const { return kind_; } |
| 45 void set_kind(FixupKind Kind) { kind_ = Kind; } | 41 void set_kind(FixupKind Kind) { kind_ = Kind; } |
| 46 | 42 |
| 47 RelocOffsetT offset() const; | 43 RelocOffsetT offset() const; |
| 48 IceString symbol(const Assembler *Asm) const; | 44 IceString symbol() const; |
| 49 | 45 |
| 50 static const Constant *NullSymbol; | 46 static const Constant *NullSymbol; |
| 51 bool isNullSymbol() const { return value_ == NullSymbol; } | 47 bool isNullSymbol() const { return ConstValue == NullSymbol; } |
| 52 | 48 |
| 53 static constexpr AssemblerFixup *NoFixup = nullptr; | 49 static constexpr AssemblerFixup *NoFixup = nullptr; |
| 54 | 50 |
| 55 void set_value(const Constant *Value) { value_ = Value; } | 51 bool valueIsSymbol() const { return ValueIsSymbol; } |
| 52 void set_value(const Constant *Value) { |
| 53 ValueIsSymbol = false; |
| 54 ConstValue = Value; |
| 55 } |
| 56 void set_value(const ELFSym *Value) { |
| 57 ValueIsSymbol = true; |
| 58 SymbolValue = Value; |
| 59 } |
| 60 const ELFSym *getSymbolValue() const { |
| 61 assert(ValueIsSymbol); |
| 62 return SymbolValue; |
| 63 } |
| 56 | 64 |
| 57 void set_addend(RelocOffsetT Addend) { addend_ = Addend; } | 65 void set_addend(RelocOffsetT Addend) { addend_ = Addend; } |
| 58 RelocOffsetT get_addend() const { return addend_; } | 66 RelocOffsetT get_addend() const { return addend_; } |
| 59 | 67 |
| 60 /// Emits fixup, then returns the number of bytes to skip. | 68 /// Emits fixup, then returns the number of bytes to skip. |
| 61 virtual size_t emit(GlobalContext *Ctx, const Assembler &Asm) const; | 69 virtual size_t emit(GlobalContext *Ctx, const Assembler &Asm) const; |
| 62 | 70 |
| 63 /// Emits offset() (little endian) in position_. If your fixup requires | 71 /// Emits offset() (little endian) in position_. If your fixup requires |
| 64 /// something smarter, you must create your own fixup type. | 72 /// something smarter, you must create your own fixup type. |
| 65 virtual void emitOffset(Assembler *Asm) const; | 73 virtual void emitOffset(Assembler *Asm) const; |
| 66 | 74 |
| 67 private: | 75 private: |
| 68 bool position_was_set_ = false; | |
| 69 intptr_t position_ = 0; | 76 intptr_t position_ = 0; |
| 70 FixupKind kind_ = 0; | 77 FixupKind kind_ = 0; |
| 71 const Constant *value_ = nullptr; | |
| 72 // An offset addend to the fixup offset (as returned by offset()), in case the | 78 // An offset addend to the fixup offset (as returned by offset()), in case the |
| 73 // assembler needs to adjust it. | 79 // assembler needs to adjust it. |
| 74 RelocOffsetT addend_ = 0; | 80 RelocOffsetT addend_ = 0; |
| 81 |
| 82 // Tagged union that holds either a Constant or ELFSym pointer, depending on |
| 83 // the ValueIsSymbol tag. |
| 84 bool ValueIsSymbol = false; |
| 85 union { |
| 86 const Constant *ConstValue; |
| 87 const ELFSym *SymbolValue; |
| 88 }; |
| 75 }; | 89 }; |
| 76 | 90 |
| 77 /// Extends a fixup to be textual. That is, it emits text instead of a sequence | 91 /// Extends a fixup to be textual. That is, it emits text instead of a sequence |
| 78 /// of bytes. This class is used as a fallback for unimplemented emitIAS | 92 /// of bytes. This class is used as a fallback for unimplemented emitIAS |
| 79 /// methods, allowing them to generate compilable assembly code. | 93 /// methods, allowing them to generate compilable assembly code. |
| 80 class AssemblerTextFixup : public AssemblerFixup { | 94 class AssemblerTextFixup : public AssemblerFixup { |
| 81 AssemblerTextFixup() = delete; | 95 AssemblerTextFixup() = delete; |
| 82 AssemblerTextFixup(const AssemblerTextFixup &) = delete; | 96 AssemblerTextFixup(const AssemblerTextFixup &) = delete; |
| 83 AssemblerTextFixup &operator=(const AssemblerTextFixup &) = delete; | 97 AssemblerTextFixup &operator=(const AssemblerTextFixup &) = delete; |
| 84 | 98 |
| 85 public: | 99 public: |
| 86 AssemblerTextFixup(const std::string &Message, size_t NumBytes) | 100 AssemblerTextFixup(const std::string &Message, size_t NumBytes) |
| 87 : AssemblerFixup(), Message(Message), NumBytes(NumBytes) {} | 101 : AssemblerFixup(), Message(Message), NumBytes(NumBytes) {} |
| 88 ~AssemblerTextFixup() = default; | 102 ~AssemblerTextFixup() = default; |
| 89 size_t emit(GlobalContext *Ctx, const Assembler &Asm) const override; | 103 size_t emit(GlobalContext *Ctx, const Assembler &Asm) const override; |
| 90 | 104 |
| 91 private: | 105 private: |
| 92 const std::string Message; | 106 const std::string Message; |
| 93 const size_t NumBytes; | 107 const size_t NumBytes; |
| 94 }; | 108 }; |
| 95 | 109 |
| 96 using FixupList = std::vector<AssemblerFixup>; | 110 using FixupList = std::vector<AssemblerFixup>; |
| 97 using FixupRefList = std::vector<AssemblerFixup *>; | 111 using FixupRefList = std::vector<AssemblerFixup *>; |
| 98 | 112 |
| 99 } // end of namespace Ice | 113 } // end of namespace Ice |
| 100 | 114 |
| 101 #endif // SUBZERO_SRC_ICEFIXUPS_H | 115 #endif // SUBZERO_SRC_ICEFIXUPS_H |
| OLD | NEW |