| 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 | 90 |
| 91 /// Assembler buffers are used to emit binary code. They grow on demand. | 91 /// Assembler buffers are used to emit binary code. They grow on demand. |
| 92 class AssemblerBuffer { | 92 class AssemblerBuffer { |
| 93 AssemblerBuffer(const AssemblerBuffer &) = delete; | 93 AssemblerBuffer(const AssemblerBuffer &) = delete; |
| 94 AssemblerBuffer &operator=(const AssemblerBuffer &) = delete; | 94 AssemblerBuffer &operator=(const AssemblerBuffer &) = delete; |
| 95 | 95 |
| 96 public: | 96 public: |
| 97 AssemblerBuffer(Assembler &); | 97 AssemblerBuffer(Assembler &); |
| 98 ~AssemblerBuffer(); | 98 ~AssemblerBuffer(); |
| 99 | 99 |
| 100 /// Basic support for emitting, loading, and storing. | 100 /// \name Basic support for emitting, loading, and storing. |
| 101 /// @{ |
| 102 // These use memcpy instead of assignment to avoid undefined behaviour of |
| 103 // assigning to unaligned addresses. Since the size of the copy is known the |
| 104 // compiler can inline the memcpy with simple moves. |
| 101 template <typename T> void emit(T Value) { | 105 template <typename T> void emit(T Value) { |
| 102 assert(hasEnsuredCapacity()); | 106 assert(hasEnsuredCapacity()); |
| 103 *reinterpret_cast<T *>(Cursor) = Value; | 107 memcpy(reinterpret_cast<void *>(Cursor), &Value, sizeof(T)); |
| 104 Cursor += sizeof(T); | 108 Cursor += sizeof(T); |
| 105 } | 109 } |
| 106 | 110 |
| 107 template <typename T> T load(intptr_t Position) const { | 111 template <typename T> T load(intptr_t Position) const { |
| 108 assert(Position >= 0 && | 112 assert(Position >= 0 && |
| 109 Position <= (size() - static_cast<intptr_t>(sizeof(T)))); | 113 Position <= (size() - static_cast<intptr_t>(sizeof(T)))); |
| 110 return *reinterpret_cast<T *>(Contents + Position); | 114 T Value; |
| 115 memcpy(&Value, reinterpret_cast<void *>(Contents + Position), sizeof(T)); |
| 116 return Value; |
| 111 } | 117 } |
| 112 | 118 |
| 113 template <typename T> void store(intptr_t Position, T Value) { | 119 template <typename T> void store(intptr_t Position, T Value) { |
| 114 assert(Position >= 0 && | 120 assert(Position >= 0 && |
| 115 Position <= (size() - static_cast<intptr_t>(sizeof(T)))); | 121 Position <= (size() - static_cast<intptr_t>(sizeof(T)))); |
| 116 *reinterpret_cast<T *>(Contents + Position) = Value; | 122 memcpy(reinterpret_cast<void *>(Contents + Position), &Value, sizeof(T)); |
| 117 } | 123 } |
| 124 /// @{ |
| 118 | 125 |
| 119 /// Emit a fixup at the current location. | 126 /// Emit a fixup at the current location. |
| 120 void emitFixup(AssemblerFixup *Fixup) { Fixup->set_position(size()); } | 127 void emitFixup(AssemblerFixup *Fixup) { Fixup->set_position(size()); } |
| 121 | 128 |
| 122 /// Get the size of the emitted code. | 129 /// Get the size of the emitted code. |
| 123 intptr_t size() const { return Cursor - Contents; } | 130 intptr_t size() const { return Cursor - Contents; } |
| 124 uintptr_t contents() const { return Contents; } | 131 uintptr_t contents() const { return Contents; } |
| 125 | 132 |
| 126 /// To emit an instruction to the assembler buffer, the EnsureCapacity helper | 133 /// To emit an instruction to the assembler buffer, the EnsureCapacity helper |
| 127 /// must be used to guarantee that the underlying data area is big enough to | 134 /// must be used to guarantee that the underlying data area is big enough to |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 protected: | 307 protected: |
| 301 // Buffer's constructor uses the Allocator, so it needs to appear after it. | 308 // Buffer's constructor uses the Allocator, so it needs to appear after it. |
| 302 // TODO(jpp): dependencies on construction order are a nice way of shooting | 309 // TODO(jpp): dependencies on construction order are a nice way of shooting |
| 303 // yourself in the foot. Fix this. | 310 // yourself in the foot. Fix this. |
| 304 AssemblerBuffer Buffer; | 311 AssemblerBuffer Buffer; |
| 305 }; | 312 }; |
| 306 | 313 |
| 307 } // end of namespace Ice | 314 } // end of namespace Ice |
| 308 | 315 |
| 309 #endif // SUBZERO_SRC_ICEASSEMBLER_H_ | 316 #endif // SUBZERO_SRC_ICEASSEMBLER_H_ |
| OLD | NEW |