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