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 |
11 // | 11 // |
12 // This file is distributed under the University of Illinois Open Source | 12 // This file is distributed under the University of Illinois Open Source |
13 // License. See LICENSE.TXT for details. | 13 // License. See LICENSE.TXT for details. |
14 // | 14 // |
15 //===----------------------------------------------------------------------===// | 15 //===----------------------------------------------------------------------===// |
16 // | 16 // |
17 // This file implements the Assembler class. | 17 // This file implements the Assembler class. |
18 // | 18 // |
19 //===----------------------------------------------------------------------===// | 19 //===----------------------------------------------------------------------===// |
20 | 20 |
21 #include "assembler.h" | 21 #include "assembler.h" |
| 22 #include "IceGlobalContext.h" |
22 #include "IceMemoryRegion.h" | 23 #include "IceMemoryRegion.h" |
| 24 #include "IceOperand.h" |
23 | 25 |
24 namespace Ice { | 26 namespace Ice { |
25 | 27 |
26 static uintptr_t NewContents(Assembler &assembler, intptr_t capacity) { | 28 static uintptr_t NewContents(Assembler &assembler, intptr_t capacity) { |
27 uintptr_t result = assembler.AllocateBytes(capacity); | 29 uintptr_t result = assembler.AllocateBytes(capacity); |
28 return result; | 30 return result; |
29 } | 31 } |
30 | 32 |
31 #ifndef NDEBUG | 33 #ifndef NDEBUG |
32 AssemblerBuffer::EnsureCapacity::EnsureCapacity(AssemblerBuffer *buffer) { | 34 AssemblerBuffer::EnsureCapacity::EnsureCapacity(AssemblerBuffer *buffer) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 fixups_processed_ = false; | 69 fixups_processed_ = false; |
68 #endif // !NDEBUG | 70 #endif // !NDEBUG |
69 | 71 |
70 // Verify internal state. | 72 // Verify internal state. |
71 assert(Capacity() == kInitialBufferCapacity); | 73 assert(Capacity() == kInitialBufferCapacity); |
72 assert(Size() == 0); | 74 assert(Size() == 0); |
73 } | 75 } |
74 | 76 |
75 AssemblerBuffer::~AssemblerBuffer() {} | 77 AssemblerBuffer::~AssemblerBuffer() {} |
76 | 78 |
77 // Returns the latest fixup at or after the given position, or nullptr if | |
78 // there is none. Assumes fixups were added in increasing order. | |
79 AssemblerFixup *AssemblerBuffer::GetLatestFixup(intptr_t position) const { | |
80 AssemblerFixup *latest_fixup = nullptr; | |
81 for (auto I = fixups_.rbegin(), E = fixups_.rend(); I != E; ++I) { | |
82 if ((*I)->position() < position) | |
83 return latest_fixup; | |
84 latest_fixup = *I; | |
85 } | |
86 return latest_fixup; | |
87 } | |
88 | |
89 void AssemblerBuffer::ProcessFixups(const MemoryRegion ®ion) { | 79 void AssemblerBuffer::ProcessFixups(const MemoryRegion ®ion) { |
90 for (SizeT I = 0; I < fixups_.size(); ++I) { | 80 for (SizeT I = 0; I < fixups_.size(); ++I) { |
91 AssemblerFixup *fixup = fixups_[I]; | 81 AssemblerFixup *fixup = fixups_[I]; |
92 fixup->Process(region, fixup->position()); | 82 fixup->Process(region, fixup->position()); |
93 } | 83 } |
94 } | 84 } |
95 | 85 |
96 void AssemblerBuffer::FinalizeInstructions(const MemoryRegion &instructions) { | 86 void AssemblerBuffer::FinalizeInstructions(const MemoryRegion &instructions) { |
97 // Copy the instructions from the buffer. | 87 // Copy the instructions from the buffer. |
98 MemoryRegion from(reinterpret_cast<void *>(contents()), Size()); | 88 MemoryRegion from(reinterpret_cast<void *>(contents()), Size()); |
(...skipping 27 matching lines...) Expand all Loading... |
126 | 116 |
127 // Update the cursor and recompute the limit. | 117 // Update the cursor and recompute the limit. |
128 cursor_ += delta; | 118 cursor_ += delta; |
129 limit_ = ComputeLimit(new_contents, new_capacity); | 119 limit_ = ComputeLimit(new_contents, new_capacity); |
130 | 120 |
131 // Verify internal state. | 121 // Verify internal state. |
132 assert(Capacity() == new_capacity); | 122 assert(Capacity() == new_capacity); |
133 assert(Size() == old_size); | 123 assert(Size() == old_size); |
134 } | 124 } |
135 | 125 |
| 126 void Assembler::emitIASBytes(GlobalContext *Ctx) const { |
| 127 Ostream &Str = Ctx->getStrEmit(); |
| 128 intptr_t EndPosition = buffer_.Size(); |
| 129 intptr_t CurPosition = 0; |
| 130 const intptr_t FixupSize = 4; |
| 131 for (AssemblerBuffer::FixupList::const_iterator |
| 132 FixupI = buffer_.fixups_begin(), |
| 133 FixupE = buffer_.fixups_end(); FixupI != FixupE; ++FixupI) { |
| 134 AssemblerFixup *NextFixup = *FixupI; |
| 135 intptr_t NextFixupLoc = NextFixup->position(); |
| 136 for (intptr_t i = CurPosition; i < NextFixupLoc; ++i) { |
| 137 Str << "\t.byte 0x"; |
| 138 Str.write_hex(buffer_.Load<uint8_t>(i)); |
| 139 Str << "\n"; |
| 140 } |
| 141 Str << "\t.long "; |
| 142 const ConstantRelocatable *Reloc = NextFixup->value(); |
| 143 if (Reloc->getSuppressMangling()) |
| 144 Str << Reloc->getName(); |
| 145 else |
| 146 Str << Ctx->mangleName(Reloc->getName()); |
| 147 if (Reloc->getOffset()) { |
| 148 Str << " + " << Reloc->getOffset(); |
| 149 } |
| 150 bool IsPCRel = NextFixup->kind() == FK_PcRel_4; |
| 151 if (IsPCRel) |
| 152 Str << " - (. + " << FixupSize << ")"; |
| 153 Str << "\n"; |
| 154 CurPosition = NextFixupLoc + FixupSize; |
| 155 assert(CurPosition <= EndPosition); |
| 156 } |
| 157 // Handle any bytes that are not prefixed by a fixup. |
| 158 for (intptr_t i = CurPosition; i < EndPosition; ++i) { |
| 159 Str << "\t.byte 0x"; |
| 160 Str.write_hex(buffer_.Load<uint8_t>(i)); |
| 161 Str << "\n"; |
| 162 } |
| 163 } |
| 164 |
136 } // end of namespace Ice | 165 } // end of namespace Ice |
OLD | NEW |