Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(598)

Side by Side Diff: src/interpreter/bytecode-pipeline.cc

Issue 1947403002: [interpreter] Introduce bytecode generation pipeline. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Incorporate comments on patch set 6. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "src/interpreter/bytecode-pipeline.h"
6
7 #include <iomanip>
8 #include "src/interpreter/source-position-table.h"
9
10 namespace v8 {
11 namespace internal {
12 namespace interpreter {
13
14 void BytecodeSourceInfo::Update(const BytecodeSourceInfo& entry) {
15 DCHECK(entry.is_valid());
16 if (!is_valid() || (entry.is_statement() && !is_statement()) ||
17 (entry.is_statement() && is_statement() &&
18 entry.source_position() > source_position())) {
19 // Position is updated if there is no existing position. Or the
20 // incoming position is a statement and the current position is an
21 // expression. Or we already have a statement and incoming
22 // statement is later. This last piece is needed for the first
23 // statement in a function.
rmcilroy 2016/05/12 12:15:13 I'm not sure what "This last piece is needed for t
oth 2016/05/12 14:59:53 Comment updated. IIRC there may be multiple statem
24 source_position_ = entry.source_position_;
25 is_statement_ = entry.is_statement_;
26 }
27 }
28
29 BytecodeNode::BytecodeNode(Bytecode bytecode) {
30 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 0);
31 bytecode_ = bytecode;
32 operand_scale_ = OperandScale::kSingle;
33 }
34
35 BytecodeNode::BytecodeNode(Bytecode bytecode, uint32_t operand0,
36 OperandScale operand_scale) {
37 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 1);
38 bytecode_ = bytecode;
39 operands_[0] = operand0;
40 operand_scale_ = operand_scale;
41 }
42
43 BytecodeNode::BytecodeNode(Bytecode bytecode, uint32_t operand0,
44 uint32_t operand1, OperandScale operand_scale) {
45 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 2);
46 bytecode_ = bytecode;
47 operands_[0] = operand0;
48 operands_[1] = operand1;
49 operand_scale_ = operand_scale;
50 }
51
52 BytecodeNode::BytecodeNode(Bytecode bytecode, uint32_t operand0,
53 uint32_t operand1, uint32_t operand2,
54 OperandScale operand_scale) {
55 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 3);
56 bytecode_ = bytecode;
57 operands_[0] = operand0;
58 operands_[1] = operand1;
59 operands_[2] = operand2;
60 operand_scale_ = operand_scale;
61 }
62
63 BytecodeNode::BytecodeNode(Bytecode bytecode, uint32_t operand0,
64 uint32_t operand1, uint32_t operand2,
65 uint32_t operand3, OperandScale operand_scale) {
66 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 4);
67 bytecode_ = bytecode;
68 operands_[0] = operand0;
69 operands_[1] = operand1;
70 operands_[2] = operand2;
71 operands_[3] = operand3;
72 operand_scale_ = operand_scale;
73 }
74
75 void BytecodeNode::set_bytecode(Bytecode bytecode) {
76 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 0);
77 bytecode_ = bytecode;
78 operand_scale_ = OperandScale::kSingle;
79 }
80
81 void BytecodeNode::set_bytecode(Bytecode bytecode, uint32_t operand0,
82 OperandScale operand_scale) {
83 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 1);
84 bytecode_ = bytecode;
85 operands_[0] = operand0;
86 operand_scale_ = operand_scale;
87 }
88
89 size_t BytecodeNode::Size() const {
90 size_t size = Bytecodes::Size(bytecode_, operand_scale_);
91 if (Bytecodes::OperandScaleRequiresPrefixBytecode(operand_scale_)) {
92 size += 1;
93 }
94 return size;
95 }
96
97 void BytecodeNode::Print(std::ostream& os) {
98 #ifdef DEBUG
99 std::ios saved_state(nullptr);
100 saved_state.copyfmt(os);
101
102 os << Bytecodes::ToString(bytecode_);
103 if (Bytecodes::OperandScaleRequiresPrefixBytecode(operand_scale_)) {
104 Bytecode scale_prefix =
105 Bytecodes::OperandScaleToPrefixBytecode(operand_scale_);
106 os << '.' << Bytecodes::ToString(scale_prefix);
107 }
108
109 for (int i = 0; i < operand_count(); ++i) {
110 os << ' ' << std::setw(8) << std::setfill('0') << std::hex << operands_[i];
111 }
112 os.copyfmt(saved_state);
113
114 if (source_info_.is_valid()) {
115 char type = source_info_.is_statement() ? 'S' : 'E';
116 os << ' ' << type << '@' << source_info_.source_position();
117 }
118 os << '\n';
119 #endif // DEBUG
120 }
121
122 } // namespace interpreter
123 } // namespace internal
124 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698