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 #include "src/interpreter/bytecode-array-writer.h" | 5 #include "src/interpreter/bytecode-array-writer.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/interpreter/bytecode-label.h" | 8 #include "src/interpreter/bytecode-label.h" |
9 #include "src/interpreter/bytecode-register.h" | 9 #include "src/interpreter/bytecode-register.h" |
10 #include "src/interpreter/constant-array-builder.h" | 10 #include "src/interpreter/constant-array-builder.h" |
11 #include "src/log.h" | 11 #include "src/log.h" |
12 | 12 |
13 namespace v8 { | 13 namespace v8 { |
14 namespace internal { | 14 namespace internal { |
15 namespace interpreter { | 15 namespace interpreter { |
16 | 16 |
17 STATIC_CONST_MEMBER_DEFINITION const size_t | 17 STATIC_CONST_MEMBER_DEFINITION const size_t |
18 BytecodeArrayWriter::kMaxSizeOfPackedBytecode; | 18 BytecodeArrayWriter::kMaxSizeOfPackedBytecode; |
19 | 19 |
20 BytecodeArrayWriter::BytecodeArrayWriter( | 20 BytecodeArrayWriter::BytecodeArrayWriter( |
21 Isolate* isolate, Zone* zone, ConstantArrayBuilder* constant_array_builder, | 21 Zone* zone, ConstantArrayBuilder* constant_array_builder, |
22 SourcePositionTableBuilder::RecordingMode source_position_mode) | 22 SourcePositionTableBuilder::RecordingMode source_position_mode) |
23 : isolate_(isolate), | 23 : bytecodes_(zone), |
24 bytecodes_(zone), | |
25 max_register_count_(0), | 24 max_register_count_(0), |
26 unbound_jumps_(0), | 25 unbound_jumps_(0), |
27 source_position_table_builder_(zone, source_position_mode), | 26 source_position_table_builder_(zone, source_position_mode), |
28 constant_array_builder_(constant_array_builder) {} | 27 constant_array_builder_(constant_array_builder) {} |
29 | 28 |
30 // override | 29 // override |
31 BytecodeArrayWriter::~BytecodeArrayWriter() {} | 30 BytecodeArrayWriter::~BytecodeArrayWriter() {} |
32 | 31 |
33 // override | 32 // override |
34 Handle<BytecodeArray> BytecodeArrayWriter::ToBytecodeArray( | 33 Handle<BytecodeArray> BytecodeArrayWriter::ToBytecodeArray( |
35 int fixed_register_count, int parameter_count, | 34 Isolate* isolate, int fixed_register_count, int parameter_count, |
36 Handle<FixedArray> handler_table) { | 35 Handle<FixedArray> handler_table) { |
37 DCHECK_EQ(0, unbound_jumps_); | 36 DCHECK_EQ(0, unbound_jumps_); |
38 | 37 |
39 int bytecode_size = static_cast<int>(bytecodes()->size()); | 38 int bytecode_size = static_cast<int>(bytecodes()->size()); |
40 | 39 |
41 // All locals need a frame slot for the debugger, but may not be | 40 // All locals need a frame slot for the debugger, but may not be |
42 // present in generated code. | 41 // present in generated code. |
43 int frame_size_for_locals = fixed_register_count * kPointerSize; | 42 int frame_size_for_locals = fixed_register_count * kPointerSize; |
44 int frame_size_used = max_register_count() * kPointerSize; | 43 int frame_size_used = max_register_count() * kPointerSize; |
45 int frame_size = std::max(frame_size_for_locals, frame_size_used); | 44 int frame_size = std::max(frame_size_for_locals, frame_size_used); |
46 Handle<FixedArray> constant_pool = constant_array_builder()->ToFixedArray(); | 45 Handle<FixedArray> constant_pool = |
47 Handle<BytecodeArray> bytecode_array = isolate_->factory()->NewBytecodeArray( | 46 constant_array_builder()->ToFixedArray(isolate); |
| 47 Handle<BytecodeArray> bytecode_array = isolate->factory()->NewBytecodeArray( |
48 bytecode_size, &bytecodes()->front(), frame_size, parameter_count, | 48 bytecode_size, &bytecodes()->front(), frame_size, parameter_count, |
49 constant_pool); | 49 constant_pool); |
50 bytecode_array->set_handler_table(*handler_table); | 50 bytecode_array->set_handler_table(*handler_table); |
51 Handle<ByteArray> source_position_table = | 51 Handle<ByteArray> source_position_table = |
52 source_position_table_builder()->ToSourcePositionTable( | 52 source_position_table_builder()->ToSourcePositionTable( |
53 isolate(), Handle<AbstractCode>::cast(bytecode_array)); | 53 isolate, Handle<AbstractCode>::cast(bytecode_array)); |
54 bytecode_array->set_source_position_table(*source_position_table); | 54 bytecode_array->set_source_position_table(*source_position_table); |
55 return bytecode_array; | 55 return bytecode_array; |
56 } | 56 } |
57 | 57 |
58 // override | 58 // override |
59 void BytecodeArrayWriter::Write(BytecodeNode* node) { | 59 void BytecodeArrayWriter::Write(BytecodeNode* node) { |
60 DCHECK(!Bytecodes::IsJump(node->bytecode())); | 60 DCHECK(!Bytecodes::IsJump(node->bytecode())); |
61 UpdateSourcePositionTable(node); | 61 UpdateSourcePositionTable(node); |
62 EmitBytecode(node); | 62 EmitBytecode(node); |
63 } | 63 } |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 node->set_bytecode(node->bytecode(), k32BitJumpPlaceholder); | 383 node->set_bytecode(node->bytecode(), k32BitJumpPlaceholder); |
384 break; | 384 break; |
385 } | 385 } |
386 } | 386 } |
387 EmitBytecode(node); | 387 EmitBytecode(node); |
388 } | 388 } |
389 | 389 |
390 } // namespace interpreter | 390 } // namespace interpreter |
391 } // namespace internal | 391 } // namespace internal |
392 } // namespace v8 | 392 } // namespace v8 |
OLD | NEW |