1// Copyright 2017 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-node.h"
6
7#include <iomanip>
8#include "src/codegen/source-position-table.h"
9
10namespace v8 {
11namespace internal {
12namespace interpreter {
13
14void BytecodeNode::Print(std::ostream& os) const {
15#ifdef DEBUG
16  std::ios saved_state(nullptr);
17  saved_state.copyfmt(os);
18  os << Bytecodes::ToString(bytecode_);
19
20  for (int i = 0; i < operand_count(); ++i) {
21    os << ' ' << std::setw(8) << std::setfill('0') << std::hex << operands_[i];
22  }
23  os.copyfmt(saved_state);
24
25  if (source_info_.is_valid()) {
26    os << ' ' << source_info_;
27  }
28  os << '\n';
29#else
30  os << static_cast<const void*>(this);
31#endif  // DEBUG
32}
33
34bool BytecodeNode::operator==(const BytecodeNode& other) const {
35  if (this == &other) {
36    return true;
37  } else if (this->bytecode() != other.bytecode() ||
38             this->source_info() != other.source_info()) {
39    return false;
40  } else {
41    for (int i = 0; i < this->operand_count(); ++i) {
42      if (this->operand(i) != other.operand(i)) {
43        return false;
44      }
45    }
46  }
47  return true;
48}
49
50std::ostream& operator<<(std::ostream& os, const BytecodeNode& node) {
51  node.Print(os);
52  return os;
53}
54
55}  // namespace interpreter
56}  // namespace internal
57}  // namespace v8
58