| 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 /// Assembler fixups are positions in generated code/data that hold relocation | 26 /// Assembler fixups are positions in generated code/data that hold relocation |
| 27 /// information that needs to be processed before finalizing the code/data. | 27 /// information that needs to be processed before finalizing the code/data. |
| 28 struct AssemblerFixup { | 28 class AssemblerFixup { |
| 29 AssemblerFixup &operator=(const AssemblerFixup &) = delete; | 29 AssemblerFixup &operator=(const AssemblerFixup &) = delete; |
| 30 | 30 |
| 31 public: | 31 public: |
| 32 AssemblerFixup() = default; | 32 AssemblerFixup() = default; |
| 33 AssemblerFixup(const AssemblerFixup &) = default; | 33 AssemblerFixup(const AssemblerFixup &) = default; |
| 34 intptr_t position() const { | 34 intptr_t position() const { |
| 35 assert(position_was_set_); | 35 assert(position_was_set_); |
| 36 return position_; | 36 return position_; |
| 37 } | 37 } |
| 38 void set_position(intptr_t Position) { | 38 void set_position(intptr_t Position) { |
| 39 position_ = Position; | 39 position_ = Position; |
| 40 position_was_set_ = true; | 40 position_was_set_ = true; |
| 41 } | 41 } |
| 42 | 42 |
| 43 FixupKind kind() const { return kind_; } | 43 FixupKind kind() const { return kind_; } |
| 44 void set_kind(FixupKind Kind) { kind_ = Kind; } | 44 void set_kind(FixupKind Kind) { kind_ = Kind; } |
| 45 | 45 |
| 46 RelocOffsetT offset() const; | 46 RelocOffsetT offset() const; |
| 47 IceString symbol(const GlobalContext *Ctx, const Assembler *Asm) const; | 47 IceString symbol(const GlobalContext *Ctx, const Assembler *Asm) const; |
| 48 | 48 |
| 49 static const Constant *NullSymbol; | 49 static const Constant *NullSymbol; |
| 50 bool isNullSymbol() const { return value_ == NullSymbol; } | 50 bool isNullSymbol() const { return value_ == NullSymbol; } |
| 51 | 51 |
| 52 static constexpr AssemblerFixup *NoFixup = nullptr; | 52 static constexpr AssemblerFixup *NoFixup = nullptr; |
| 53 | 53 |
| 54 void set_value(const Constant *Value) { value_ = Value; } | 54 void set_value(const Constant *Value) { value_ = Value; } |
| 55 | 55 |
| 56 void set_addend(RelocOffsetT Addend) { addend_ = Addend; } |
| 57 |
| 56 /// Emits fixup, then returns the number of bytes to skip. | 58 /// Emits fixup, then returns the number of bytes to skip. |
| 57 virtual size_t emit(GlobalContext *Ctx, const Assembler &Asm) const; | 59 virtual size_t emit(GlobalContext *Ctx, const Assembler &Asm) const; |
| 58 | 60 |
| 59 private: | 61 private: |
| 60 bool position_was_set_ = false; | 62 bool position_was_set_ = false; |
| 61 intptr_t position_ = 0; | 63 intptr_t position_ = 0; |
| 62 FixupKind kind_ = 0; | 64 FixupKind kind_ = 0; |
| 63 const Constant *value_ = nullptr; | 65 const Constant *value_ = nullptr; |
| 66 // An offset addend to the fixup offset (as returned by offset()), in case the |
| 67 // assembler needs to adjust it. |
| 68 RelocOffsetT addend_ = 0; |
| 64 }; | 69 }; |
| 65 | 70 |
| 66 /// Extends a fixup to be textual. That is, it emits text instead of a sequence | 71 /// Extends a fixup to be textual. That is, it emits text instead of a sequence |
| 67 /// of bytes. This class is used as a fallback for unimplemented emitIAS | 72 /// of bytes. This class is used as a fallback for unimplemented emitIAS |
| 68 /// methods, allowing them to generate compilable assembly code. | 73 /// methods, allowing them to generate compilable assembly code. |
| 69 class AssemblerTextFixup : public AssemblerFixup { | 74 class AssemblerTextFixup : public AssemblerFixup { |
| 70 AssemblerTextFixup() = delete; | 75 AssemblerTextFixup() = delete; |
| 71 AssemblerTextFixup(const AssemblerTextFixup &) = delete; | 76 AssemblerTextFixup(const AssemblerTextFixup &) = delete; |
| 72 AssemblerTextFixup &operator=(const AssemblerTextFixup &) = delete; | 77 AssemblerTextFixup &operator=(const AssemblerTextFixup &) = delete; |
| 73 | 78 |
| 74 public: | 79 public: |
| 75 AssemblerTextFixup(const std::string &Message, size_t NumBytes) | 80 AssemblerTextFixup(const std::string &Message, size_t NumBytes) |
| 76 : AssemblerFixup(), Message(Message), NumBytes(NumBytes) {} | 81 : AssemblerFixup(), Message(Message), NumBytes(NumBytes) {} |
| 77 ~AssemblerTextFixup() = default; | 82 ~AssemblerTextFixup() = default; |
| 78 size_t emit(GlobalContext *Ctx, const Assembler &Asm) const override; | 83 size_t emit(GlobalContext *Ctx, const Assembler &Asm) const override; |
| 79 | 84 |
| 80 private: | 85 private: |
| 81 const std::string Message; | 86 const std::string Message; |
| 82 const size_t NumBytes; | 87 const size_t NumBytes; |
| 83 }; | 88 }; |
| 84 | 89 |
| 85 using FixupList = std::vector<AssemblerFixup>; | 90 using FixupList = std::vector<AssemblerFixup>; |
| 86 using FixupRefList = std::vector<AssemblerFixup *>; | 91 using FixupRefList = std::vector<AssemblerFixup *>; |
| 87 | 92 |
| 88 } // end of namespace Ice | 93 } // end of namespace Ice |
| 89 | 94 |
| 90 #endif // SUBZERO_SRC_ICEFIXUPS_H | 95 #endif // SUBZERO_SRC_ICEFIXUPS_H |
| OLD | NEW |