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 "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
9 #include "src/interpreter/bytecode-array-writer.h" | 9 #include "src/interpreter/bytecode-array-writer.h" |
10 #include "src/interpreter/bytecode-register-allocator.h" | 10 #include "src/interpreter/bytecode-register-allocator.h" |
11 #include "src/interpreter/bytecode-register.h" | 11 #include "src/interpreter/bytecode-register.h" |
12 #include "src/interpreter/bytecodes.h" | 12 #include "src/interpreter/bytecodes.h" |
13 #include "src/interpreter/constant-array-builder.h" | 13 #include "src/interpreter/constant-array-builder.h" |
14 #include "src/interpreter/handler-table-builder.h" | 14 #include "src/interpreter/handler-table-builder.h" |
15 #include "src/zone/zone-containers.h" | 15 #include "src/zone/zone-containers.h" |
16 | 16 |
17 namespace v8 { | 17 namespace v8 { |
18 namespace internal { | 18 namespace internal { |
19 | 19 |
20 class Isolate; | 20 class Isolate; |
21 | 21 |
22 namespace interpreter { | 22 namespace interpreter { |
23 | 23 |
24 class BytecodeLabel; | 24 class BytecodeLabel; |
25 class BytecodeNode; | 25 class BytecodeNode; |
26 class BytecodePipelineStage; | 26 class BytecodePipelineStage; |
27 class BytecodeRegisterOptimizer; | |
27 class Register; | 28 class Register; |
28 | 29 |
29 class BytecodeArrayBuilder final : public ZoneObject { | 30 class BytecodeArrayBuilder final : public ZoneObject { |
30 public: | 31 public: |
31 BytecodeArrayBuilder( | 32 BytecodeArrayBuilder( |
32 Isolate* isolate, Zone* zone, int parameter_count, int context_count, | 33 Isolate* isolate, Zone* zone, int parameter_count, int context_count, |
33 int locals_count, FunctionLiteral* literal = nullptr, | 34 int locals_count, FunctionLiteral* literal = nullptr, |
34 SourcePositionTableBuilder::RecordingMode source_position_mode = | 35 SourcePositionTableBuilder::RecordingMode source_position_mode = |
35 SourcePositionTableBuilder::RECORD_SOURCE_POSITIONS); | 36 SourcePositionTableBuilder::RECORD_SOURCE_POSITIONS); |
36 | 37 |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
310 } | 311 } |
311 } | 312 } |
312 | 313 |
313 void SetExpressionAsStatementPosition(Expression* expr) { | 314 void SetExpressionAsStatementPosition(Expression* expr) { |
314 if (expr->position() == kNoSourcePosition) return; | 315 if (expr->position() == kNoSourcePosition) return; |
315 latest_source_info_.MakeStatementPosition(expr->position()); | 316 latest_source_info_.MakeStatementPosition(expr->position()); |
316 } | 317 } |
317 | 318 |
318 bool RequiresImplicitReturn() const { return !return_seen_in_block_; } | 319 bool RequiresImplicitReturn() const { return !return_seen_in_block_; } |
319 | 320 |
321 // Returns the raw operand value for the given register or register list. | |
322 uint32_t GetInputRegisterOperand(Register reg); | |
323 uint32_t GetOutputRegisterOperand(Register reg); | |
324 uint32_t GetInputRegisterListOperand(RegisterList reg_list); | |
325 uint32_t GetOutputRegisterListOperand(RegisterList reg_list); | |
326 | |
327 // Used internally to prepare for emitting a given bytecode. | |
Leszek Swirski
2016/10/06 10:35:17
If this is used internally, should it be private?
rmcilroy
2016/10/06 17:14:43
Done.
| |
328 void PrepareToOutputBytecode(Bytecode bytecode); | |
329 | |
320 // Accessors | 330 // Accessors |
321 BytecodeRegisterAllocator* register_allocator() { | 331 BytecodeRegisterAllocator* register_allocator() { |
322 return ®ister_allocator_; | 332 return ®ister_allocator_; |
323 } | 333 } |
324 const BytecodeRegisterAllocator* register_allocator() const { | 334 const BytecodeRegisterAllocator* register_allocator() const { |
325 return ®ister_allocator_; | 335 return ®ister_allocator_; |
326 } | 336 } |
327 Zone* zone() const { return zone_; } | 337 Zone* zone() const { return zone_; } |
328 | 338 |
329 private: | 339 private: |
330 friend class BytecodeRegisterAllocator; | 340 friend class BytecodeRegisterAllocator; |
331 | 341 |
332 INLINE(void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1, | 342 // Returns the current source position for the given |bytecode|. |
333 uint32_t operand2, uint32_t operand3)); | 343 INLINE(BytecodeSourceInfo CurrentSourcePosition(Bytecode bytecode)); |
334 INLINE(void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1, | |
335 uint32_t operand2)); | |
336 INLINE(void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1)); | |
337 INLINE(void Output(Bytecode bytecode, uint32_t operand0)); | |
338 INLINE(void Output(Bytecode bytecode)); | |
339 | 344 |
340 INLINE(void OutputJump(Bytecode bytecode, BytecodeLabel* label)); | 345 #define DECLARE_BYTECODE_OUTPUT(Name, ...) \ |
341 INLINE(void OutputJump(Bytecode bytecode, uint32_t operand0, | 346 template <typename... Operands> \ |
342 BytecodeLabel* label)); | 347 INLINE(void Output##Name(Operands... operands)); \ |
348 template <typename... Operands> \ | |
349 INLINE(void Output##Name(BytecodeLabel* label, Operands... operands)); | |
350 BYTECODE_LIST(DECLARE_BYTECODE_OUTPUT) | |
351 #undef DECLARE_OPERAND_TYPE_INFO | |
343 | 352 |
344 bool RegisterIsValid(Register reg) const; | 353 bool RegisterIsValid(Register reg) const; |
345 bool OperandsAreValid(Bytecode bytecode, int operand_count, | 354 bool RegisterListIsValid(RegisterList reg_list) const; |
346 uint32_t operand0 = 0, uint32_t operand1 = 0, | |
347 uint32_t operand2 = 0, uint32_t operand3 = 0) const; | |
348 | |
349 static uint32_t RegisterOperand(Register reg) { | |
350 return static_cast<uint32_t>(reg.ToOperand()); | |
351 } | |
352 | |
353 static uint32_t SignedOperand(int value) { | |
354 return static_cast<uint32_t>(value); | |
355 } | |
356 | |
357 static uint32_t UnsignedOperand(int value) { | |
358 DCHECK_GE(value, 0); | |
359 return static_cast<uint32_t>(value); | |
360 } | |
361 | |
362 static uint32_t UnsignedOperand(size_t value) { | |
363 DCHECK_LE(value, kMaxUInt32); | |
364 return static_cast<uint32_t>(value); | |
365 } | |
366 | 355 |
367 // Set position for return. | 356 // Set position for return. |
368 void SetReturnPosition(); | 357 void SetReturnPosition(); |
369 | 358 |
370 // Gets a constant pool entry for the |object|. | 359 // Gets a constant pool entry for the |object|. |
371 size_t GetConstantPoolEntry(Handle<Object> object); | 360 size_t GetConstantPoolEntry(Handle<Object> object); |
372 | 361 |
373 // Not implemented as the illegal bytecode is used inside internally | 362 // Not implemented as the illegal bytecode is used inside internally |
374 // to indicate a bytecode field is not valid or an error has occured | 363 // to indicate a bytecode field is not valid or an error has occured |
375 // during bytecode generation. | 364 // during bytecode generation. |
(...skipping 20 matching lines...) Expand all Loading... | |
396 ConstantArrayBuilder constant_array_builder_; | 385 ConstantArrayBuilder constant_array_builder_; |
397 HandlerTableBuilder handler_table_builder_; | 386 HandlerTableBuilder handler_table_builder_; |
398 bool return_seen_in_block_; | 387 bool return_seen_in_block_; |
399 int parameter_count_; | 388 int parameter_count_; |
400 int local_register_count_; | 389 int local_register_count_; |
401 int context_register_count_; | 390 int context_register_count_; |
402 int return_position_; | 391 int return_position_; |
403 BytecodeRegisterAllocator register_allocator_; | 392 BytecodeRegisterAllocator register_allocator_; |
404 BytecodeArrayWriter bytecode_array_writer_; | 393 BytecodeArrayWriter bytecode_array_writer_; |
405 BytecodePipelineStage* pipeline_; | 394 BytecodePipelineStage* pipeline_; |
395 BytecodeRegisterOptimizer* register_optimizer_; | |
406 BytecodeSourceInfo latest_source_info_; | 396 BytecodeSourceInfo latest_source_info_; |
407 | 397 |
408 static int const kNoFeedbackSlot = 0; | 398 static int const kNoFeedbackSlot = 0; |
409 | 399 |
410 DISALLOW_COPY_AND_ASSIGN(BytecodeArrayBuilder); | 400 DISALLOW_COPY_AND_ASSIGN(BytecodeArrayBuilder); |
411 }; | 401 }; |
412 | 402 |
413 } // namespace interpreter | 403 } // namespace interpreter |
414 } // namespace internal | 404 } // namespace internal |
415 } // namespace v8 | 405 } // namespace v8 |
416 | 406 |
417 #endif // V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ | 407 #endif // V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ |
OLD | NEW |