Chromium Code Reviews| 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 /// Basic support for emitting, loading, and storing. |
| 101 template <typename T> void emit(T Value) { | 101 template <typename T> void emit(T Value) { |
| 102 assert(hasEnsuredCapacity()); | 102 assert(hasEnsuredCapacity()); |
| 103 *reinterpret_cast<T *>(Cursor) = Value; | 103 memcpy(reinterpret_cast<void *>(Cursor), &Value, sizeof(T)); |
|
Jim Stichnoth
2015/09/04 21:32:48
Have you checked the effect of this patch on assem
ascull
2015/09/05 00:00:48
The binary produces is the same before and after t
Jim Stichnoth
2015/09/05 01:03:22
OK, thanks for checking.
| |
| 104 Cursor += sizeof(T); | 104 Cursor += sizeof(T); |
| 105 } | 105 } |
| 106 | 106 |
| 107 template <typename T> T load(intptr_t Position) const { | 107 template <typename T> T load(intptr_t Position) const { |
| 108 assert(Position >= 0 && | 108 assert(Position >= 0 && |
| 109 Position <= (size() - static_cast<intptr_t>(sizeof(T)))); | 109 Position <= (size() - static_cast<intptr_t>(sizeof(T)))); |
| 110 return *reinterpret_cast<T *>(Contents + Position); | 110 T Value; |
| 111 memcpy(&Value, reinterpret_cast<void *>(Contents + Position), sizeof(T)); | |
| 112 return Value; | |
| 111 } | 113 } |
| 112 | 114 |
| 113 template <typename T> void store(intptr_t Position, T Value) { | 115 template <typename T> void store(intptr_t Position, T Value) { |
| 114 assert(Position >= 0 && | 116 assert(Position >= 0 && |
| 115 Position <= (size() - static_cast<intptr_t>(sizeof(T)))); | 117 Position <= (size() - static_cast<intptr_t>(sizeof(T)))); |
| 116 *reinterpret_cast<T *>(Contents + Position) = Value; | 118 memcpy(reinterpret_cast<void *>(Contents + Position), &Value, sizeof(T)); |
| 117 } | 119 } |
| 118 | 120 |
| 119 /// Emit a fixup at the current location. | 121 /// Emit a fixup at the current location. |
| 120 void emitFixup(AssemblerFixup *Fixup) { Fixup->set_position(size()); } | 122 void emitFixup(AssemblerFixup *Fixup) { Fixup->set_position(size()); } |
| 121 | 123 |
| 122 /// Get the size of the emitted code. | 124 /// Get the size of the emitted code. |
| 123 intptr_t size() const { return Cursor - Contents; } | 125 intptr_t size() const { return Cursor - Contents; } |
| 124 uintptr_t contents() const { return Contents; } | 126 uintptr_t contents() const { return Contents; } |
| 125 | 127 |
| 126 /// To emit an instruction to the assembler buffer, the EnsureCapacity helper | 128 /// To emit an instruction to the assembler buffer, the EnsureCapacity helper |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 300 protected: | 302 protected: |
| 301 // Buffer's constructor uses the Allocator, so it needs to appear after it. | 303 // 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 | 304 // TODO(jpp): dependencies on construction order are a nice way of shooting |
| 303 // yourself in the foot. Fix this. | 305 // yourself in the foot. Fix this. |
| 304 AssemblerBuffer Buffer; | 306 AssemblerBuffer Buffer; |
| 305 }; | 307 }; |
| 306 | 308 |
| 307 } // end of namespace Ice | 309 } // end of namespace Ice |
| 308 | 310 |
| 309 #endif // SUBZERO_SRC_ICEASSEMBLER_H_ | 311 #endif // SUBZERO_SRC_ICEASSEMBLER_H_ |
| OLD | NEW |