OLD | NEW |
(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. |
| 24 source_position_ = entry.source_position_; |
| 25 is_statement_ = entry.is_statement_; |
| 26 } |
| 27 } |
| 28 |
| 29 std::ostream& operator<<(std::ostream& os, const BytecodeSourceInfo& info) { |
| 30 if (info.is_valid()) { |
| 31 char description = info.is_statement() ? 'S' : 'E'; |
| 32 os << info.source_position() << ' ' << description << '>'; |
| 33 } |
| 34 return os; |
| 35 } |
| 36 |
| 37 BytecodeNode::BytecodeNode(Bytecode bytecode) { |
| 38 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 0); |
| 39 bytecode_ = bytecode; |
| 40 operand_scale_ = OperandScale::kSingle; |
| 41 } |
| 42 |
| 43 BytecodeNode::BytecodeNode(Bytecode bytecode, uint32_t operand0, |
| 44 OperandScale operand_scale) { |
| 45 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 1); |
| 46 bytecode_ = bytecode; |
| 47 operands_[0] = operand0; |
| 48 operand_scale_ = operand_scale; |
| 49 } |
| 50 |
| 51 BytecodeNode::BytecodeNode(Bytecode bytecode, uint32_t operand0, |
| 52 uint32_t operand1, OperandScale operand_scale) { |
| 53 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 2); |
| 54 bytecode_ = bytecode; |
| 55 operands_[0] = operand0; |
| 56 operands_[1] = operand1; |
| 57 operand_scale_ = operand_scale; |
| 58 } |
| 59 |
| 60 BytecodeNode::BytecodeNode(Bytecode bytecode, uint32_t operand0, |
| 61 uint32_t operand1, uint32_t operand2, |
| 62 OperandScale operand_scale) { |
| 63 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 3); |
| 64 bytecode_ = bytecode; |
| 65 operands_[0] = operand0; |
| 66 operands_[1] = operand1; |
| 67 operands_[2] = operand2; |
| 68 operand_scale_ = operand_scale; |
| 69 } |
| 70 |
| 71 BytecodeNode::BytecodeNode(Bytecode bytecode, uint32_t operand0, |
| 72 uint32_t operand1, uint32_t operand2, |
| 73 uint32_t operand3, OperandScale operand_scale) { |
| 74 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 4); |
| 75 bytecode_ = bytecode; |
| 76 operands_[0] = operand0; |
| 77 operands_[1] = operand1; |
| 78 operands_[2] = operand2; |
| 79 operands_[3] = operand3; |
| 80 operand_scale_ = operand_scale; |
| 81 } |
| 82 |
| 83 void BytecodeNode::set_bytecode(Bytecode bytecode) { |
| 84 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 0); |
| 85 bytecode_ = bytecode; |
| 86 operand_scale_ = OperandScale::kSingle; |
| 87 } |
| 88 |
| 89 void BytecodeNode::set_bytecode(Bytecode bytecode, uint32_t operand0, |
| 90 OperandScale operand_scale) { |
| 91 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 1); |
| 92 bytecode_ = bytecode; |
| 93 operands_[0] = operand0; |
| 94 operand_scale_ = operand_scale; |
| 95 } |
| 96 |
| 97 size_t BytecodeNode::Size() const { |
| 98 size_t size = Bytecodes::Size(bytecode_, operand_scale_); |
| 99 if (Bytecodes::OperandScaleRequiresPrefixBytecode(operand_scale_)) { |
| 100 size += 1; |
| 101 } |
| 102 return size; |
| 103 } |
| 104 |
| 105 void BytecodeNode::Print(std::ostream& os) const { |
| 106 #ifdef DEBUG |
| 107 std::ios saved_state(nullptr); |
| 108 saved_state.copyfmt(os); |
| 109 |
| 110 os << Bytecodes::ToString(bytecode_); |
| 111 if (Bytecodes::OperandScaleRequiresPrefixBytecode(operand_scale_)) { |
| 112 Bytecode scale_prefix = |
| 113 Bytecodes::OperandScaleToPrefixBytecode(operand_scale_); |
| 114 os << '.' << Bytecodes::ToString(scale_prefix); |
| 115 } |
| 116 |
| 117 for (int i = 0; i < operand_count(); ++i) { |
| 118 os << ' ' << std::setw(8) << std::setfill('0') << std::hex << operands_[i]; |
| 119 } |
| 120 os.copyfmt(saved_state); |
| 121 |
| 122 if (source_info_.is_valid()) { |
| 123 os << source_info_; |
| 124 } |
| 125 os << '\n'; |
| 126 #else |
| 127 os << static_cast<const void*>(this); |
| 128 #endif // DEBUG |
| 129 } |
| 130 |
| 131 void BytecodeNode::Clone(const BytecodeNode* const other) { |
| 132 memcpy(this, other, sizeof(*other)); |
| 133 } |
| 134 |
| 135 bool BytecodeNode::operator==(const BytecodeNode& other) const { |
| 136 if (this == &other) { |
| 137 return true; |
| 138 } else if (this->bytecode() != other.bytecode() || |
| 139 this->source_info() != other.source_info()) { |
| 140 return false; |
| 141 } else { |
| 142 for (int i = 0; i < this->operand_count(); ++i) { |
| 143 if (this->operand(i) != other.operand(i)) { |
| 144 return false; |
| 145 } |
| 146 } |
| 147 } |
| 148 return true; |
| 149 } |
| 150 |
| 151 std::ostream& operator<<(std::ostream& os, const BytecodeNode& node) { |
| 152 node.Print(os); |
| 153 return os; |
| 154 } |
| 155 |
| 156 } // namespace interpreter |
| 157 } // namespace internal |
| 158 } // namespace v8 |
OLD | NEW |