OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ | 5 #ifndef V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ |
6 #define V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ | 6 #define V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ |
7 | 7 |
8 #include <vector> | |
9 | |
10 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
11 #include "src/identity-map.h" | |
12 #include "src/interpreter/bytecodes.h" | 9 #include "src/interpreter/bytecodes.h" |
13 #include "src/zone.h" | 10 #include "src/interpreter/constant-array-builder.h" |
14 #include "src/zone-containers.h" | 11 #include "src/zone-containers.h" |
15 | 12 |
16 namespace v8 { | 13 namespace v8 { |
17 namespace internal { | 14 namespace internal { |
18 | 15 |
19 class Isolate; | 16 class Isolate; |
20 | 17 |
21 namespace interpreter { | 18 namespace interpreter { |
22 | 19 |
23 class BytecodeLabel; | 20 class BytecodeLabel; |
| 21 class ConstantArrayBuilder; |
24 class Register; | 22 class Register; |
25 | 23 |
26 // TODO(rmcilroy): Unify this with CreateArgumentsParameters::Type in Turbofan | 24 // TODO(rmcilroy): Unify this with CreateArgumentsParameters::Type in Turbofan |
27 // when rest parameters implementation has settled down. | 25 // when rest parameters implementation has settled down. |
28 enum class CreateArgumentsType { kMappedArguments, kUnmappedArguments }; | 26 enum class CreateArgumentsType { kMappedArguments, kUnmappedArguments }; |
29 | 27 |
30 class BytecodeArrayBuilder final { | 28 class BytecodeArrayBuilder final { |
31 public: | 29 public: |
32 BytecodeArrayBuilder(Isolate* isolate, Zone* zone); | 30 BytecodeArrayBuilder(Isolate* isolate, Zone* zone); |
33 ~BytecodeArrayBuilder(); | 31 ~BytecodeArrayBuilder(); |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 Register cache_array, Register index); | 218 Register cache_array, Register index); |
221 BytecodeArrayBuilder& ForInStep(Register index); | 219 BytecodeArrayBuilder& ForInStep(Register index); |
222 | 220 |
223 // Accessors | 221 // Accessors |
224 Zone* zone() const { return zone_; } | 222 Zone* zone() const { return zone_; } |
225 | 223 |
226 private: | 224 private: |
227 ZoneVector<uint8_t>* bytecodes() { return &bytecodes_; } | 225 ZoneVector<uint8_t>* bytecodes() { return &bytecodes_; } |
228 const ZoneVector<uint8_t>* bytecodes() const { return &bytecodes_; } | 226 const ZoneVector<uint8_t>* bytecodes() const { return &bytecodes_; } |
229 Isolate* isolate() const { return isolate_; } | 227 Isolate* isolate() const { return isolate_; } |
| 228 ConstantArrayBuilder* constant_array_builder() { |
| 229 return &constant_array_builder_; |
| 230 } |
| 231 const ConstantArrayBuilder* constant_array_builder() const { |
| 232 return &constant_array_builder_; |
| 233 } |
230 | 234 |
231 static Bytecode BytecodeForBinaryOperation(Token::Value op); | 235 static Bytecode BytecodeForBinaryOperation(Token::Value op); |
232 static Bytecode BytecodeForCountOperation(Token::Value op); | 236 static Bytecode BytecodeForCountOperation(Token::Value op); |
233 static Bytecode BytecodeForCompareOperation(Token::Value op); | 237 static Bytecode BytecodeForCompareOperation(Token::Value op); |
234 static Bytecode BytecodeForWideOperands(Bytecode bytecode); | 238 static Bytecode BytecodeForWideOperands(Bytecode bytecode); |
235 static Bytecode BytecodeForLoadIC(LanguageMode language_mode); | 239 static Bytecode BytecodeForLoadIC(LanguageMode language_mode); |
236 static Bytecode BytecodeForKeyedLoadIC(LanguageMode language_mode); | 240 static Bytecode BytecodeForKeyedLoadIC(LanguageMode language_mode); |
237 static Bytecode BytecodeForStoreIC(LanguageMode language_mode); | 241 static Bytecode BytecodeForStoreIC(LanguageMode language_mode); |
238 static Bytecode BytecodeForKeyedStoreIC(LanguageMode language_mode); | 242 static Bytecode BytecodeForKeyedStoreIC(LanguageMode language_mode); |
239 static Bytecode BytecodeForLoadGlobal(LanguageMode language_mode, | 243 static Bytecode BytecodeForLoadGlobal(LanguageMode language_mode, |
240 TypeofMode typeof_mode); | 244 TypeofMode typeof_mode); |
241 static Bytecode BytecodeForStoreGlobal(LanguageMode language_mode); | 245 static Bytecode BytecodeForStoreGlobal(LanguageMode language_mode); |
242 static Bytecode BytecodeForStoreLookupSlot(LanguageMode language_mode); | 246 static Bytecode BytecodeForStoreLookupSlot(LanguageMode language_mode); |
243 static Bytecode BytecodeForCreateArguments(CreateArgumentsType type); | 247 static Bytecode BytecodeForCreateArguments(CreateArgumentsType type); |
244 static Bytecode BytecodeForDelete(LanguageMode language_mode); | 248 static Bytecode BytecodeForDelete(LanguageMode language_mode); |
245 | 249 |
246 static bool FitsInIdx8Operand(int value); | 250 static bool FitsInIdx8Operand(int value); |
247 static bool FitsInIdx8Operand(size_t value); | 251 static bool FitsInIdx8Operand(size_t value); |
248 static bool FitsInImm8Operand(int value); | 252 static bool FitsInImm8Operand(int value); |
249 static bool FitsInIdx16Operand(int value); | 253 static bool FitsInIdx16Operand(int value); |
250 static bool FitsInIdx16Operand(size_t value); | 254 static bool FitsInIdx16Operand(size_t value); |
251 | 255 |
252 static Bytecode GetJumpWithConstantOperand(Bytecode jump_with_smi8_operand); | 256 static Bytecode GetJumpWithConstantOperand(Bytecode jump_smi8_operand); |
253 static Bytecode GetJumpWithToBoolean(Bytecode jump); | 257 static Bytecode GetJumpWithConstantWideOperand(Bytecode jump_smi8_operand); |
| 258 static Bytecode GetJumpWithToBoolean(Bytecode jump_smi8_operand); |
254 | 259 |
255 template <size_t N> | 260 template <size_t N> |
256 INLINE(void Output(Bytecode bytecode, uint32_t(&oprands)[N])); | 261 INLINE(void Output(Bytecode bytecode, uint32_t(&oprands)[N])); |
257 void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1, | 262 void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1, |
258 uint32_t operand2, uint32_t operand3); | 263 uint32_t operand2, uint32_t operand3); |
259 void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1, | 264 void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1, |
260 uint32_t operand2); | 265 uint32_t operand2); |
261 void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1); | 266 void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1); |
262 void Output(Bytecode bytecode, uint32_t operand0); | 267 void Output(Bytecode bytecode, uint32_t operand0); |
263 void Output(Bytecode bytecode); | 268 void Output(Bytecode bytecode); |
264 | 269 |
265 BytecodeArrayBuilder& OutputJump(Bytecode jump_bytecode, | 270 BytecodeArrayBuilder& OutputJump(Bytecode jump_bytecode, |
266 BytecodeLabel* label); | 271 BytecodeLabel* label); |
267 void PatchJump(const ZoneVector<uint8_t>::iterator& jump_target, | 272 void PatchJump(const ZoneVector<uint8_t>::iterator& jump_target, |
268 ZoneVector<uint8_t>::iterator jump_location); | 273 const ZoneVector<uint8_t>::iterator& jump_location); |
269 | 274 |
270 void LeaveBasicBlock(); | 275 void LeaveBasicBlock(); |
271 void EnsureReturn(); | 276 void EnsureReturn(); |
272 | 277 |
273 bool OperandIsValid(Bytecode bytecode, int operand_index, | 278 bool OperandIsValid(Bytecode bytecode, int operand_index, |
274 uint32_t operand_value) const; | 279 uint32_t operand_value) const; |
275 bool LastBytecodeInSameBlock() const; | 280 bool LastBytecodeInSameBlock() const; |
276 | 281 |
277 bool NeedToBooleanCast(); | 282 bool NeedToBooleanCast(); |
278 bool IsRegisterInAccumulator(Register reg); | 283 bool IsRegisterInAccumulator(Register reg); |
279 | 284 |
| 285 // Temporary register management. |
280 int BorrowTemporaryRegister(); | 286 int BorrowTemporaryRegister(); |
281 int BorrowTemporaryRegisterNotInRange(int start_index, int end_index); | 287 int BorrowTemporaryRegisterNotInRange(int start_index, int end_index); |
282 int AllocateAndBorrowTemporaryRegister(); | 288 int AllocateAndBorrowTemporaryRegister(); |
283 void ReturnTemporaryRegister(int reg_index); | 289 void ReturnTemporaryRegister(int reg_index); |
284 int PrepareForConsecutiveTemporaryRegisters(size_t count); | 290 int PrepareForConsecutiveTemporaryRegisters(size_t count); |
285 void BorrowConsecutiveTemporaryRegister(int reg_index); | 291 void BorrowConsecutiveTemporaryRegister(int reg_index); |
286 bool TemporaryRegisterIsLive(Register reg) const; | 292 bool TemporaryRegisterIsLive(Register reg) const; |
287 | 293 |
288 Register first_temporary_register() const; | 294 Register first_temporary_register() const; |
289 Register last_temporary_register() const; | 295 Register last_temporary_register() const; |
290 | 296 |
291 Isolate* isolate_; | 297 Isolate* isolate_; |
292 Zone* zone_; | 298 Zone* zone_; |
293 ZoneVector<uint8_t> bytecodes_; | 299 ZoneVector<uint8_t> bytecodes_; |
294 bool bytecode_generated_; | 300 bool bytecode_generated_; |
| 301 ConstantArrayBuilder constant_array_builder_; |
295 size_t last_block_end_; | 302 size_t last_block_end_; |
296 size_t last_bytecode_start_; | 303 size_t last_bytecode_start_; |
297 bool exit_seen_in_block_; | 304 bool exit_seen_in_block_; |
298 int unbound_jumps_; | 305 int unbound_jumps_; |
299 | 306 |
300 IdentityMap<size_t> constants_map_; | |
301 ZoneVector<Handle<Object>> constants_; | |
302 | |
303 int parameter_count_; | 307 int parameter_count_; |
304 int local_register_count_; | 308 int local_register_count_; |
305 int context_register_count_; | 309 int context_register_count_; |
306 int temporary_register_count_; | 310 int temporary_register_count_; |
307 | |
308 ZoneSet<int> free_temporaries_; | 311 ZoneSet<int> free_temporaries_; |
309 | 312 |
310 class PreviousBytecodeHelper; | 313 class PreviousBytecodeHelper; |
311 friend class TemporaryRegisterScope; | 314 friend class TemporaryRegisterScope; |
312 DISALLOW_COPY_AND_ASSIGN(BytecodeArrayBuilder); | 315 DISALLOW_COPY_AND_ASSIGN(BytecodeArrayBuilder); |
313 }; | 316 }; |
314 | 317 |
315 | 318 |
316 // A label representing a branch target in a bytecode array. When a | 319 // A label representing a branch target in a bytecode array. When a |
317 // label is bound, it represents a known position in the bytecode | 320 // label is bound, it represents a known position in the bytecode |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 | 387 |
385 DISALLOW_COPY_AND_ASSIGN(TemporaryRegisterScope); | 388 DISALLOW_COPY_AND_ASSIGN(TemporaryRegisterScope); |
386 }; | 389 }; |
387 | 390 |
388 | 391 |
389 } // namespace interpreter | 392 } // namespace interpreter |
390 } // namespace internal | 393 } // namespace internal |
391 } // namespace v8 | 394 } // namespace v8 |
392 | 395 |
393 #endif // V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ | 396 #endif // V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ |
OLD | NEW |