Index: src/interpreter/source-position-table.cc |
diff --git a/src/interpreter/source-position-table.cc b/src/interpreter/source-position-table.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c2a3cc24f61a4997ec7dcfc20289411a19978eae |
--- /dev/null |
+++ b/src/interpreter/source-position-table.cc |
@@ -0,0 +1,67 @@ |
+// Copyright 2016 the V8 project authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "src/interpreter/source-position-table.h" |
+ |
+#include "src/assembler.h" |
+#include "src/objects-inl.h" |
+#include "src/objects.h" |
+ |
+namespace v8 { |
+namespace internal { |
+namespace interpreter { |
+ |
+Handle<FixedArray> SourcePositionTableBuilder::ToFixedArray() { |
+ int length = entries_.size(); |
+ Handle<FixedArray> table = |
+ isolate_->factory()->NewFixedArray(length * 2, TENURED); |
+ for (int i = 0; i < length; i++) { |
+ table->set(i * 2, Smi::FromInt(entries_[i].bytecode_offset)); |
+ table->set(i * 2 + 1, Smi::FromInt(entries_[i].source_position_and_type)); |
+ } |
+ return table; |
+} |
+ |
+SourcePositionTableIterator::SourcePositionTableIterator( |
+ BytecodeArray* bytecode_array) |
+ : table_(bytecode_array->source_position_table()), |
+ index_(0), |
+ is_statement_(false), |
+ bytecode_offset_(RelocInfo::kNoPosition), |
+ source_position_(RelocInfo::kNoPosition) { |
+ DCHECK(table_->length() % 2 == 0); |
+} |
+ |
+bool SourcePositionTableIterator::Next() { |
+ if (index_ < table_->length()) { |
+ int new_bytecode_offset = Smi::cast(table_->get(index_))->value(); |
+ // Bytecode offsets are in ascending order. |
+ DCHECK_LT(bytecode_offset_, new_bytecode_offset); |
+ bytecode_offset_ = new_bytecode_offset; |
+ uint32_t source_position_and_type = |
+ static_cast<uint32_t>(Smi::cast(table_->get(index_ + 1))->value()); |
+ is_statement_ = IsStatementField::decode(source_position_and_type); |
+ source_position_ = SourcePositionField::decode(source_position_and_type); |
+ index_ += 2; |
+ return true; |
+ } |
+ is_statement_ = false; |
+ bytecode_offset_ = RelocInfo::kNoPosition; |
+ source_position_ = RelocInfo::kNoPosition; |
+ return false; |
+} |
+ |
+int SourcePositionTableIterator::PositionFromBytecodeOffset( |
+ BytecodeArray* bytecode_array, int bytecode_offset) { |
+ SourcePositionTableIterator iterator(bytecode_array); |
+ int last_position = 0; |
+ while (iterator.Next() && iterator.bytecode_offset() <= bytecode_offset) { |
+ last_position = iterator.source_position(); |
+ } |
+ return last_position; |
+} |
+ |
+} // namespace interpreter |
+} // namespace internal |
+} // namespace v8 |