OLD | NEW |
1 //===- subzero/src/IceAssembler.h - Integrated assembler --------*- C++ -*-===// | 1 //===- subzero/src/IceAssembler.h - Integrated assembler --------*- C++ -*-===// |
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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 | 230 |
231 void extendCapacity(); | 231 void extendCapacity(); |
232 }; | 232 }; |
233 | 233 |
234 class Assembler { | 234 class Assembler { |
235 Assembler() = delete; | 235 Assembler() = delete; |
236 Assembler(const Assembler &) = delete; | 236 Assembler(const Assembler &) = delete; |
237 Assembler &operator=(const Assembler &) = delete; | 237 Assembler &operator=(const Assembler &) = delete; |
238 | 238 |
239 public: | 239 public: |
| 240 using InternalRelocationList = |
| 241 std::vector<std::pair<const IceString, const SizeT>>; |
| 242 |
240 enum AssemblerKind { | 243 enum AssemblerKind { |
241 Asm_ARM32, | 244 Asm_ARM32, |
242 Asm_MIPS32, | 245 Asm_MIPS32, |
243 Asm_X8632, | 246 Asm_X8632, |
244 Asm_X8664, | 247 Asm_X8664, |
245 }; | 248 }; |
246 | 249 |
247 virtual ~Assembler() = default; | 250 virtual ~Assembler() = default; |
248 | 251 |
249 /// Allocate a chunk of bytes using the per-Assembler allocator. | 252 /// Allocate a chunk of bytes using the per-Assembler allocator. |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 const IceString &getFunctionName() { return FunctionName; } | 319 const IceString &getFunctionName() { return FunctionName; } |
317 void setFunctionName(const IceString &NewName) { FunctionName = NewName; } | 320 void setFunctionName(const IceString &NewName) { FunctionName = NewName; } |
318 intptr_t getBufferSize() const { return Buffer.size(); } | 321 intptr_t getBufferSize() const { return Buffer.size(); } |
319 /// Roll back to a (smaller) size. | 322 /// Roll back to a (smaller) size. |
320 void setBufferSize(intptr_t NewSize) { Buffer.setSize(NewSize); } | 323 void setBufferSize(intptr_t NewSize) { Buffer.setSize(NewSize); } |
321 void setPreliminary(bool Value) { Preliminary = Value; } | 324 void setPreliminary(bool Value) { Preliminary = Value; } |
322 bool getPreliminary() const { return Preliminary; } | 325 bool getPreliminary() const { return Preliminary; } |
323 | 326 |
324 AssemblerKind getKind() const { return Kind; } | 327 AssemblerKind getKind() const { return Kind; } |
325 | 328 |
| 329 void addRelocationAtCurrentPosition(const IceString &RelocName) { |
| 330 if (!getPreliminary()) { |
| 331 InternalRelocs.emplace_back(RelocName, getBufferSize()); |
| 332 } |
| 333 } |
| 334 |
| 335 const InternalRelocationList &getInternalRelocations() const { |
| 336 return InternalRelocs; |
| 337 } |
| 338 |
326 protected: | 339 protected: |
327 explicit Assembler(AssemblerKind Kind) | 340 explicit Assembler(AssemblerKind Kind) |
328 : Kind(Kind), Allocator(), Buffer(*this) {} | 341 : Kind(Kind), Allocator(), Buffer(*this) {} |
329 | 342 |
330 private: | 343 private: |
331 const AssemblerKind Kind; | 344 const AssemblerKind Kind; |
| 345 InternalRelocationList InternalRelocs; |
332 | 346 |
333 ArenaAllocator<32 * 1024> Allocator; | 347 ArenaAllocator<32 * 1024> Allocator; |
334 /// FunctionName and IsInternal are transferred from the original Cfg object, | 348 /// FunctionName and IsInternal are transferred from the original Cfg object, |
335 /// since the Cfg object may be deleted by the time the assembler buffer is | 349 /// since the Cfg object may be deleted by the time the assembler buffer is |
336 /// emitted. | 350 /// emitted. |
337 IceString FunctionName = ""; | 351 IceString FunctionName = ""; |
338 bool IsInternal = false; | 352 bool IsInternal = false; |
339 /// Preliminary indicates whether a preliminary pass is being made for | 353 /// Preliminary indicates whether a preliminary pass is being made for |
340 /// calculating bundle padding (Preliminary=true), versus the final pass where | 354 /// calculating bundle padding (Preliminary=true), versus the final pass where |
341 /// all changes to label bindings, label links, and relocation fixups are | 355 /// all changes to label bindings, label links, and relocation fixups are |
342 /// fully committed (Preliminary=false). | 356 /// fully committed (Preliminary=false). |
343 bool Preliminary = false; | 357 bool Preliminary = false; |
344 | 358 |
345 /// Installs a created fixup, after it has been allocated. | 359 /// Installs a created fixup, after it has been allocated. |
346 void installFixup(AssemblerFixup *F) { Buffer.installFixup(F); } | 360 void installFixup(AssemblerFixup *F) { Buffer.installFixup(F); } |
347 | 361 |
348 protected: | 362 protected: |
349 // Buffer's constructor uses the Allocator, so it needs to appear after it. | 363 // Buffer's constructor uses the Allocator, so it needs to appear after it. |
350 // TODO(jpp): dependencies on construction order are a nice way of shooting | 364 // TODO(jpp): dependencies on construction order are a nice way of shooting |
351 // yourself in the foot. Fix this. | 365 // yourself in the foot. Fix this. |
352 AssemblerBuffer Buffer; | 366 AssemblerBuffer Buffer; |
353 }; | 367 }; |
354 | 368 |
355 } // end of namespace Ice | 369 } // end of namespace Ice |
356 | 370 |
357 #endif // SUBZERO_SRC_ICEASSEMBLER_H_ | 371 #endif // SUBZERO_SRC_ICEASSEMBLER_H_ |
OLD | NEW |