Home | History | Annotate | Download | only in interpreter
      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/source-position-table.h"
      9 
     10 namespace v8 {
     11 namespace internal {
     12 namespace interpreter {
     13 
     14 void 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 
     34 bool 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 
     50 std::ostream& operator<<(std::ostream& os, const BytecodeSourceInfo& info) {
     51   if (info.is_valid()) {
     52     char description = info.is_statement() ? 'S' : 'E';
     53     os << info.source_position() << ' ' << description << '>';
     54   }
     55   return os;
     56 }
     57 
     58 std::ostream& operator<<(std::ostream& os, const BytecodeNode& node) {
     59   node.Print(os);
     60   return os;
     61 }
     62 
     63 }  // namespace interpreter
     64 }  // namespace internal
     65 }  // namespace v8
     66