OLD | NEW |
1 //===- subzero/src/assembler.cpp - Assembler base class -------------------===// | 1 //===- subzero/src/assembler.cpp - Assembler base class -------------------===// |
2 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 2 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
3 // for details. All rights reserved. Use of this source code is governed by a | 3 // for details. All rights reserved. Use of this source code is governed by a |
4 // BSD-style license that can be found in the LICENSE file. | 4 // BSD-style license that can be found in the LICENSE file. |
5 // | 5 // |
6 // Modified by the Subzero authors. | 6 // Modified by the Subzero authors. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 // The Subzero Code Generator | 10 // The Subzero Code Generator |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 FixupI = buffer_.fixups_begin(), | 117 FixupI = buffer_.fixups_begin(), |
118 FixupE = buffer_.fixups_end(); FixupI != FixupE; ++FixupI) { | 118 FixupE = buffer_.fixups_end(); FixupI != FixupE; ++FixupI) { |
119 AssemblerFixup *NextFixup = *FixupI; | 119 AssemblerFixup *NextFixup = *FixupI; |
120 intptr_t NextFixupLoc = NextFixup->position(); | 120 intptr_t NextFixupLoc = NextFixup->position(); |
121 for (intptr_t i = CurPosition; i < NextFixupLoc; ++i) { | 121 for (intptr_t i = CurPosition; i < NextFixupLoc; ++i) { |
122 Str << "\t.byte 0x"; | 122 Str << "\t.byte 0x"; |
123 Str.write_hex(buffer_.Load<uint8_t>(i)); | 123 Str.write_hex(buffer_.Load<uint8_t>(i)); |
124 Str << "\n"; | 124 Str << "\n"; |
125 } | 125 } |
126 Str << "\t.long "; | 126 Str << "\t.long "; |
127 const ConstantRelocatable *Reloc = NextFixup->value(); | 127 NextFixup->emit(Ctx); |
128 if (Reloc->getSuppressMangling()) | |
129 Str << Reloc->getName(); | |
130 else | |
131 Str << Ctx->mangleName(Reloc->getName()); | |
132 if (Reloc->getOffset()) { | |
133 Str << " + " << Reloc->getOffset(); | |
134 } | |
135 bool IsPCRel = NextFixup->kind() == FK_PcRel_4; | 128 bool IsPCRel = NextFixup->kind() == FK_PcRel_4; |
136 if (IsPCRel) | 129 if (IsPCRel) |
137 Str << " - (. + " << FixupSize << ")"; | 130 Str << " - (. + " << FixupSize << ")"; |
138 Str << "\n"; | 131 Str << "\n"; |
139 CurPosition = NextFixupLoc + FixupSize; | 132 CurPosition = NextFixupLoc + FixupSize; |
140 assert(CurPosition <= EndPosition); | 133 assert(CurPosition <= EndPosition); |
141 } | 134 } |
142 // Handle any bytes that are not prefixed by a fixup. | 135 // Handle any bytes that are not prefixed by a fixup. |
143 for (intptr_t i = CurPosition; i < EndPosition; ++i) { | 136 for (intptr_t i = CurPosition; i < EndPosition; ++i) { |
144 Str << "\t.byte 0x"; | 137 Str << "\t.byte 0x"; |
145 Str.write_hex(buffer_.Load<uint8_t>(i)); | 138 Str.write_hex(buffer_.Load<uint8_t>(i)); |
146 Str << "\n"; | 139 Str << "\n"; |
147 } | 140 } |
148 } | 141 } |
149 | 142 |
| 143 RelocOffsetT AssemblerFixup::offset() const { |
| 144 if (const auto CR = llvm::dyn_cast<ConstantRelocatable>(value_)) |
| 145 return CR->getOffset(); |
| 146 return 0; |
| 147 } |
| 148 |
| 149 IceString AssemblerFixup::symbol(GlobalContext *Ctx) const { |
| 150 std::string Buffer; |
| 151 llvm::raw_string_ostream Str(Buffer); |
| 152 const Constant *C = value_; |
| 153 if (const auto CR = llvm::dyn_cast<ConstantRelocatable>(C)) { |
| 154 if (CR->getSuppressMangling()) |
| 155 Str << CR->getName(); |
| 156 else |
| 157 Str << Ctx->mangleName(CR->getName()); |
| 158 } else { |
| 159 assert(llvm::isa<ConstantFloat>(C) || llvm::isa<ConstantDouble>(C)); |
| 160 C->emitPoolLabel(Str); |
| 161 } |
| 162 return Str.str(); |
| 163 } |
| 164 |
| 165 void AssemblerFixup::emit(GlobalContext *Ctx) const { |
| 166 Ostream &Str = Ctx->getStrEmit(); |
| 167 Str << symbol(Ctx); |
| 168 RelocOffsetT Offset = offset(); |
| 169 if (Offset) |
| 170 Str << " + " << Offset; |
| 171 } |
| 172 |
150 } // end of namespace Ice | 173 } // end of namespace Ice |
OLD | NEW |