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 /// This file declares generic fixup types. | 11 /// This file 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 class Assembler; | |
Jim Stichnoth
2015/10/27 21:41:21
Is this forward declaration needed? It's already
Karl
2015/10/27 22:16:41
Done.
| |
23 | |
22 /// Each target and container format has a different namespace of relocations. | 24 /// Each target and container format has a different namespace of relocations. |
23 /// This holds the specific target+container format's relocation number. | 25 /// This holds the specific target+container format's relocation number. |
24 using FixupKind = uint32_t; | 26 using FixupKind = uint32_t; |
25 | 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 struct AssemblerFixup { | 30 struct 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 intptr_t position() const { return position_; } | 36 intptr_t position() const { return position_; } |
35 void set_position(intptr_t Position) { position_ = Position; } | 37 void set_position(intptr_t Position) { position_ = Position; } |
36 | 38 |
37 FixupKind kind() const { return kind_; } | 39 FixupKind kind() const { return kind_; } |
38 void set_kind(FixupKind Kind) { kind_ = Kind; } | 40 void set_kind(FixupKind Kind) { kind_ = Kind; } |
39 | 41 |
40 RelocOffsetT offset() const; | 42 RelocOffsetT offset() const; |
41 IceString symbol(const GlobalContext *Ctx) const; | 43 IceString symbol(const GlobalContext *Ctx) const; |
42 | 44 |
43 static const Constant *NullSymbol; | 45 static const Constant *NullSymbol; |
44 bool isNullSymbol() const { return value_ == NullSymbol; } | 46 bool isNullSymbol() const { return value_ == NullSymbol; } |
45 | 47 |
46 void set_value(const Constant *Value) { value_ = Value; } | 48 void set_value(const Constant *Value) { value_ = Value; } |
47 | 49 |
48 /// Emits fixup, then returns the number of bytes to skip. | 50 /// Emits fixup, then returns the number of bytes to skip. |
49 virtual size_t emit(GlobalContext *Ctx, RelocOffsetT OverrideOffset, | 51 virtual size_t emit(GlobalContext *Ctx, const Assembler &Asm) const; |
50 bool IsPCRel) const; | |
51 | 52 |
52 private: | 53 private: |
53 intptr_t position_ = 0; | 54 intptr_t position_ = 0; |
54 FixupKind kind_ = 0; | 55 FixupKind kind_ = 0; |
55 const Constant *value_ = nullptr; | 56 const Constant *value_ = nullptr; |
56 }; | 57 }; |
57 | 58 |
58 /// Extends a fixup to be textual. That is, it emits text instead of a sequence | 59 /// Extends a fixup to be textual. That is, it emits text instead of a sequence |
59 /// of bytes. This class is used as a fallback for unimplemented emitIAS | 60 /// of bytes. This class is used as a fallback for unimplemented emitIAS |
60 /// methods, allowing them to generate compilable assembly code. | 61 /// methods, allowing them to generate compilable assembly code. |
61 class AssemblerTextFixup : public AssemblerFixup { | 62 class AssemblerTextFixup : public AssemblerFixup { |
62 AssemblerTextFixup() = delete; | 63 AssemblerTextFixup() = delete; |
63 AssemblerTextFixup(const AssemblerTextFixup &) = delete; | 64 AssemblerTextFixup(const AssemblerTextFixup &) = delete; |
64 AssemblerTextFixup &operator=(const AssemblerTextFixup &) = delete; | 65 AssemblerTextFixup &operator=(const AssemblerTextFixup &) = delete; |
65 | 66 |
66 public: | 67 public: |
67 AssemblerTextFixup(const std::string &Message, size_t NumBytes) | 68 AssemblerTextFixup(const std::string &Message, size_t NumBytes) |
68 : AssemblerFixup(), Message(Message), NumBytes(NumBytes) {} | 69 : AssemblerFixup(), Message(Message), NumBytes(NumBytes) {} |
69 ~AssemblerTextFixup() = default; | 70 ~AssemblerTextFixup() = default; |
70 virtual size_t emit(GlobalContext *Ctx, RelocOffsetT OverrideOffset, | 71 size_t emit(GlobalContext *Ctx, const Assembler &Asm) const override; |
71 bool isPcRel) const; | |
72 | 72 |
73 private: | 73 private: |
74 const std::string Message; | 74 const std::string Message; |
75 const size_t NumBytes; | 75 const size_t NumBytes; |
76 }; | 76 }; |
77 | 77 |
78 using FixupList = std::vector<AssemblerFixup>; | 78 using FixupList = std::vector<AssemblerFixup>; |
79 using FixupRefList = std::vector<AssemblerFixup *>; | 79 using FixupRefList = std::vector<AssemblerFixup *>; |
80 | 80 |
81 } // end of namespace Ice | 81 } // end of namespace Ice |
82 | 82 |
83 #endif // SUBZERO_SRC_ICEFIXUPS_H | 83 #endif // SUBZERO_SRC_ICEFIXUPS_H |
OLD | NEW |