| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/globals.h" // NOLINT | 5 #include "vm/globals.h" // NOLINT |
| 6 #if defined(TARGET_ARCH_DBC) | 6 #if defined(TARGET_ARCH_DBC) |
| 7 | 7 |
| 8 #include "vm/assembler.h" | 8 #include "vm/assembler.h" |
| 9 #include "vm/cpu.h" | 9 #include "vm/cpu.h" |
| 10 #include "vm/longjump.h" | 10 #include "vm/longjump.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 *reinterpret_cast<int32_t*>(data) = Bytecode::kTrap; | 24 *reinterpret_cast<int32_t*>(data) = Bytecode::kTrap; |
| 25 data += sizeof(int32_t); | 25 data += sizeof(int32_t); |
| 26 } | 26 } |
| 27 } | 27 } |
| 28 | 28 |
| 29 #define DEFINE_EMIT(Name, Signature, Fmt0, Fmt1, Fmt2) \ | 29 #define DEFINE_EMIT(Name, Signature, Fmt0, Fmt1, Fmt2) \ |
| 30 void Assembler::Name(PARAMS_##Signature) { \ | 30 void Assembler::Name(PARAMS_##Signature) { \ |
| 31 Emit(Bytecode::FENCODE_##Signature(Bytecode::k##Name ENCODE_##Signature)); \ | 31 Emit(Bytecode::FENCODE_##Signature(Bytecode::k##Name ENCODE_##Signature)); \ |
| 32 } | 32 } |
| 33 | 33 |
| 34 | |
| 35 #define PARAMS_0 | 34 #define PARAMS_0 |
| 36 #define PARAMS_A_D uintptr_t ra, uintptr_t rd | 35 #define PARAMS_A_D uintptr_t ra, uintptr_t rd |
| 37 #define PARAMS_D uintptr_t rd | 36 #define PARAMS_D uintptr_t rd |
| 38 #define PARAMS_A_B_C uintptr_t ra, uintptr_t rb, uintptr_t rc | 37 #define PARAMS_A_B_C uintptr_t ra, uintptr_t rb, uintptr_t rc |
| 39 #define PARAMS_A uintptr_t ra | 38 #define PARAMS_A uintptr_t ra |
| 40 #define PARAMS_T intptr_t x | 39 #define PARAMS_T intptr_t x |
| 41 #define PARAMS_A_X uintptr_t ra, intptr_t x | 40 #define PARAMS_A_X uintptr_t ra, intptr_t x |
| 42 #define PARAMS_X intptr_t x | 41 #define PARAMS_X intptr_t x |
| 43 | 42 |
| 44 #define ENCODE_0 | 43 #define ENCODE_0 |
| 45 #define ENCODE_A_D , ra, rd | 44 #define ENCODE_A_D , ra, rd |
| 46 #define ENCODE_D , 0, rd | 45 #define ENCODE_D , 0, rd |
| 47 #define ENCODE_A_B_C , ra, rb, rc | 46 #define ENCODE_A_B_C , ra, rb, rc |
| 48 #define ENCODE_A , ra, 0 | 47 #define ENCODE_A , ra, 0 |
| 49 #define ENCODE_T , x | 48 #define ENCODE_T , x |
| 50 #define ENCODE_A_X , ra, x | 49 #define ENCODE_A_X , ra, x |
| 51 #define ENCODE_X , 0, x | 50 #define ENCODE_X , 0, x |
| 52 | 51 |
| 53 #define FENCODE_0 Encode | 52 #define FENCODE_0 Encode |
| 54 #define FENCODE_A_D Encode | 53 #define FENCODE_A_D Encode |
| 55 #define FENCODE_D Encode | 54 #define FENCODE_D Encode |
| 56 #define FENCODE_A_B_C Encode | 55 #define FENCODE_A_B_C Encode |
| 57 #define FENCODE_A Encode | 56 #define FENCODE_A Encode |
| 58 #define FENCODE_T EncodeSigned | 57 #define FENCODE_T EncodeSigned |
| 59 #define FENCODE_A_X EncodeSigned | 58 #define FENCODE_A_X EncodeSigned |
| 60 #define FENCODE_X EncodeSigned | 59 #define FENCODE_X EncodeSigned |
| 61 | 60 |
| 62 | |
| 63 BYTECODES_LIST(DEFINE_EMIT) | 61 BYTECODES_LIST(DEFINE_EMIT) |
| 64 | 62 |
| 65 | |
| 66 #undef DEFINE_EMIT | 63 #undef DEFINE_EMIT |
| 67 | 64 |
| 68 | |
| 69 void Assembler::Emit(int32_t value) { | 65 void Assembler::Emit(int32_t value) { |
| 70 AssemblerBuffer::EnsureCapacity ensured(&buffer_); | 66 AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 71 buffer_.Emit<int32_t>(value); | 67 buffer_.Emit<int32_t>(value); |
| 72 } | 68 } |
| 73 | 69 |
| 74 | |
| 75 const char* Assembler::RegisterName(Register reg) { | 70 const char* Assembler::RegisterName(Register reg) { |
| 76 return Thread::Current()->zone()->PrintToString("R%d", reg); | 71 return Thread::Current()->zone()->PrintToString("R%d", reg); |
| 77 } | 72 } |
| 78 | 73 |
| 79 | |
| 80 static int32_t EncodeJump(int32_t relative_pc) { | 74 static int32_t EncodeJump(int32_t relative_pc) { |
| 81 return Bytecode::kJump | (relative_pc << 8); | 75 return Bytecode::kJump | (relative_pc << 8); |
| 82 } | 76 } |
| 83 | 77 |
| 84 | |
| 85 static int32_t OffsetToPC(int32_t offset) { | 78 static int32_t OffsetToPC(int32_t offset) { |
| 86 return offset >> 2; | 79 return offset >> 2; |
| 87 } | 80 } |
| 88 | 81 |
| 89 | |
| 90 void Assembler::Jump(Label* label) { | 82 void Assembler::Jump(Label* label) { |
| 91 if (label->IsBound()) { | 83 if (label->IsBound()) { |
| 92 Emit(EncodeJump(OffsetToPC(label->Position() - buffer_.Size()))); | 84 Emit(EncodeJump(OffsetToPC(label->Position() - buffer_.Size()))); |
| 93 } else { | 85 } else { |
| 94 const intptr_t position = buffer_.Size(); | 86 const intptr_t position = buffer_.Size(); |
| 95 Emit(label->position_); | 87 Emit(label->position_); |
| 96 label->LinkTo(position); | 88 label->LinkTo(position); |
| 97 } | 89 } |
| 98 } | 90 } |
| 99 | 91 |
| 100 | |
| 101 void Assembler::Bind(Label* label) { | 92 void Assembler::Bind(Label* label) { |
| 102 ASSERT(!label->IsBound()); | 93 ASSERT(!label->IsBound()); |
| 103 ASSERT(!label->IsBound()); | 94 ASSERT(!label->IsBound()); |
| 104 intptr_t bound_pc = buffer_.Size(); | 95 intptr_t bound_pc = buffer_.Size(); |
| 105 while (label->IsLinked()) { | 96 while (label->IsLinked()) { |
| 106 const int32_t position = label->Position(); | 97 const int32_t position = label->Position(); |
| 107 const int32_t next_position = buffer_.Load<int32_t>(position); | 98 const int32_t next_position = buffer_.Load<int32_t>(position); |
| 108 buffer_.Store<int32_t>(position, | 99 buffer_.Store<int32_t>(position, |
| 109 EncodeJump(OffsetToPC(bound_pc - position))); | 100 EncodeJump(OffsetToPC(bound_pc - position))); |
| 110 label->position_ = next_position; | 101 label->position_ = next_position; |
| 111 } | 102 } |
| 112 label->BindTo(bound_pc); | 103 label->BindTo(bound_pc); |
| 113 } | 104 } |
| 114 | 105 |
| 115 | |
| 116 void Assembler::Stop(const char* message) { | 106 void Assembler::Stop(const char* message) { |
| 117 // TODO(vegorov) support passing a message to the bytecode. | 107 // TODO(vegorov) support passing a message to the bytecode. |
| 118 Emit(Bytecode::kTrap); | 108 Emit(Bytecode::kTrap); |
| 119 } | 109 } |
| 120 | 110 |
| 121 | |
| 122 void Assembler::PushConstant(const Object& obj) { | 111 void Assembler::PushConstant(const Object& obj) { |
| 123 PushConstant(AddConstant(obj)); | 112 PushConstant(AddConstant(obj)); |
| 124 } | 113 } |
| 125 | 114 |
| 126 | |
| 127 void Assembler::LoadConstant(uintptr_t ra, const Object& obj) { | 115 void Assembler::LoadConstant(uintptr_t ra, const Object& obj) { |
| 128 LoadConstant(ra, AddConstant(obj)); | 116 LoadConstant(ra, AddConstant(obj)); |
| 129 } | 117 } |
| 130 | 118 |
| 131 | |
| 132 intptr_t Assembler::AddConstant(const Object& obj) { | 119 intptr_t Assembler::AddConstant(const Object& obj) { |
| 133 return object_pool_wrapper().FindObject(Object::ZoneHandle(obj.raw())); | 120 return object_pool_wrapper().FindObject(Object::ZoneHandle(obj.raw())); |
| 134 } | 121 } |
| 135 | 122 |
| 136 | |
| 137 } // namespace dart | 123 } // namespace dart |
| 138 | 124 |
| 139 #endif // defined TARGET_ARCH_DBC | 125 #endif // defined TARGET_ARCH_DBC |
| OLD | NEW |