| OLD | NEW | 
| (Empty) |  | 
 |   1 // Copyright 2016 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/source-position-table.h" | 
 |   6  | 
 |   7 #include "src/assembler.h" | 
 |   8 #include "src/objects-inl.h" | 
 |   9 #include "src/objects.h" | 
 |  10  | 
 |  11 namespace v8 { | 
 |  12 namespace internal { | 
 |  13 namespace interpreter { | 
 |  14  | 
 |  15 class IsStatementField : public BitField<bool, 0, 1> {}; | 
 |  16 class SourcePositionField : public BitField<int, 1, 30> {}; | 
 |  17  | 
 |  18 void SourcePositionTableBuilder::AddStatementPosition(int bytecode_offset, | 
 |  19                                                       int source_position) { | 
 |  20   AssertMonotonic(bytecode_offset); | 
 |  21   uint32_t encoded = IsStatementField::encode(true) | | 
 |  22                      SourcePositionField::encode(source_position); | 
 |  23   entries_.push_back({bytecode_offset, encoded}); | 
 |  24 } | 
 |  25  | 
 |  26 void SourcePositionTableBuilder::AddExpressionPosition(int bytecode_offset, | 
 |  27                                                        int source_position) { | 
 |  28   AssertMonotonic(bytecode_offset); | 
 |  29   uint32_t encoded = IsStatementField::encode(false) | | 
 |  30                      SourcePositionField::encode(source_position); | 
 |  31   entries_.push_back({bytecode_offset, encoded}); | 
 |  32 } | 
 |  33  | 
 |  34 Handle<FixedArray> SourcePositionTableBuilder::ToFixedArray() { | 
 |  35   int length = static_cast<int>(entries_.size()); | 
 |  36   Handle<FixedArray> table = | 
 |  37       isolate_->factory()->NewFixedArray(length * 2, TENURED); | 
 |  38   for (int i = 0; i < length; i++) { | 
 |  39     table->set(i * 2, Smi::FromInt(entries_[i].bytecode_offset)); | 
 |  40     table->set(i * 2 + 1, Smi::FromInt(entries_[i].source_position_and_type)); | 
 |  41   } | 
 |  42   return table; | 
 |  43 } | 
 |  44  | 
 |  45 SourcePositionTableIterator::SourcePositionTableIterator( | 
 |  46     BytecodeArray* bytecode_array) | 
 |  47     : table_(bytecode_array->source_position_table()), | 
 |  48       index_(0), | 
 |  49       length_(table_->length()) { | 
 |  50   DCHECK(table_->length() % 2 == 0); | 
 |  51   Advance(); | 
 |  52 } | 
 |  53  | 
 |  54 void SourcePositionTableIterator::Advance() { | 
 |  55   if (index_ < length_) { | 
 |  56     int new_bytecode_offset = Smi::cast(table_->get(index_))->value(); | 
 |  57     // Bytecode offsets are in ascending order. | 
 |  58     DCHECK(bytecode_offset_ < new_bytecode_offset || index_ == 0); | 
 |  59     bytecode_offset_ = new_bytecode_offset; | 
 |  60     uint32_t source_position_and_type = | 
 |  61         static_cast<uint32_t>(Smi::cast(table_->get(index_ + 1))->value()); | 
 |  62     is_statement_ = IsStatementField::decode(source_position_and_type); | 
 |  63     source_position_ = SourcePositionField::decode(source_position_and_type); | 
 |  64   } | 
 |  65   index_ += 2; | 
 |  66 } | 
 |  67  | 
 |  68 int SourcePositionTableIterator::PositionFromBytecodeOffset( | 
 |  69     BytecodeArray* bytecode_array, int bytecode_offset) { | 
 |  70   int last_position = 0; | 
 |  71   for (SourcePositionTableIterator iterator(bytecode_array); | 
 |  72        !iterator.done() && iterator.bytecode_offset() <= bytecode_offset; | 
 |  73        iterator.Advance()) { | 
 |  74     last_position = iterator.source_position(); | 
 |  75   } | 
 |  76   return last_position; | 
 |  77 } | 
 |  78  | 
 |  79 }  // namespace interpreter | 
 |  80 }  // namespace internal | 
 |  81 }  // namespace v8 | 
| OLD | NEW |