Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: src/interpreter/source-position-table.cc

Issue 1682853004: [interpreter, debugger] implement bytecode break location iterator. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix build Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/interpreter/source-position-table.h ('k') | src/objects-inl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/interpreter/source-position-table.h" 5 #include "src/interpreter/source-position-table.h"
6 6
7 #include "src/assembler.h" 7 #include "src/assembler.h"
8 #include "src/objects-inl.h" 8 #include "src/objects-inl.h"
9 #include "src/objects.h" 9 #include "src/objects.h"
10 10
11 namespace v8 { 11 namespace v8 {
12 namespace internal { 12 namespace internal {
13 namespace interpreter { 13 namespace interpreter {
14 14
15 class IsStatementField : public BitField<bool, 0, 1> {}; 15 class IsStatementField : public BitField<bool, 0, 1> {};
16 class SourcePositionField : public BitField<int, 1, 30> {}; 16 class SourcePositionField : public BitField<int, 1, 30> {};
17 17
18 void SourcePositionTableBuilder::AddStatementPosition(size_t bytecode_offset, 18 void SourcePositionTableBuilder::AddStatementPosition(size_t bytecode_offset,
19 int source_position) { 19 int source_position) {
20 int offset = static_cast<int>(bytecode_offset); 20 int offset = static_cast<int>(bytecode_offset);
21 AssertMonotonic(offset); 21 // If a position has already been assigned to this bytecode offset,
22 // do not reassign a new statement position.
23 if (CodeOffsetHasPosition(offset)) return;
22 uint32_t encoded = IsStatementField::encode(true) | 24 uint32_t encoded = IsStatementField::encode(true) |
23 SourcePositionField::encode(source_position); 25 SourcePositionField::encode(source_position);
24 entries_.push_back({offset, encoded}); 26 entries_.push_back({offset, encoded});
25 } 27 }
26 28
27 void SourcePositionTableBuilder::AddExpressionPosition(size_t bytecode_offset, 29 void SourcePositionTableBuilder::AddExpressionPosition(size_t bytecode_offset,
28 int source_position) { 30 int source_position) {
29 int offset = static_cast<int>(bytecode_offset); 31 int offset = static_cast<int>(bytecode_offset);
30 AssertMonotonic(offset); 32 // If a position has already been assigned to this bytecode offset,
33 // do not reassign a new statement position.
34 if (CodeOffsetHasPosition(offset)) return;
31 uint32_t encoded = IsStatementField::encode(false) | 35 uint32_t encoded = IsStatementField::encode(false) |
32 SourcePositionField::encode(source_position); 36 SourcePositionField::encode(source_position);
33 entries_.push_back({offset, encoded}); 37 entries_.push_back({offset, encoded});
34 } 38 }
35 39
36 void SourcePositionTableBuilder::RevertPosition(size_t bytecode_offset) { 40 void SourcePositionTableBuilder::RevertPosition(size_t bytecode_offset) {
37 int offset = static_cast<int>(bytecode_offset); 41 int offset = static_cast<int>(bytecode_offset);
38 // If we already added a source position table entry, but the bytecode array 42 // If we already added a source position table entry, but the bytecode array
39 // builder ended up not outputting a bytecode for the corresponding bytecode 43 // builder ended up not outputting a bytecode for the corresponding bytecode
40 // offset, we have to remove that entry. 44 // offset, we have to remove that entry.
41 if (entries_.size() > 0 && entries_.back().bytecode_offset == offset) { 45 if (CodeOffsetHasPosition(offset)) entries_.pop_back();
42 entries_.pop_back();
43 }
44 } 46 }
45 47
46 Handle<FixedArray> SourcePositionTableBuilder::ToFixedArray() { 48 Handle<FixedArray> SourcePositionTableBuilder::ToFixedArray() {
47 int length = static_cast<int>(entries_.size()); 49 int length = static_cast<int>(entries_.size());
48 Handle<FixedArray> table = 50 Handle<FixedArray> table =
49 isolate_->factory()->NewFixedArray(length * 2, TENURED); 51 isolate_->factory()->NewFixedArray(length * 2, TENURED);
50 for (int i = 0; i < length; i++) { 52 for (int i = 0; i < length; i++) {
51 table->set(i * 2, Smi::FromInt(entries_[i].bytecode_offset)); 53 table->set(i * 2, Smi::FromInt(entries_[i].bytecode_offset));
52 table->set(i * 2 + 1, Smi::FromInt(entries_[i].source_position_and_type)); 54 table->set(i * 2 + 1, Smi::FromInt(entries_[i].source_position_and_type));
53 } 55 }
(...skipping 19 matching lines...) Expand all
73 static_cast<uint32_t>(Smi::cast(table_->get(index_ + 1))->value()); 75 static_cast<uint32_t>(Smi::cast(table_->get(index_ + 1))->value());
74 is_statement_ = IsStatementField::decode(source_position_and_type); 76 is_statement_ = IsStatementField::decode(source_position_and_type);
75 source_position_ = SourcePositionField::decode(source_position_and_type); 77 source_position_ = SourcePositionField::decode(source_position_and_type);
76 } 78 }
77 index_ += 2; 79 index_ += 2;
78 } 80 }
79 81
80 } // namespace interpreter 82 } // namespace interpreter
81 } // namespace internal 83 } // namespace internal
82 } // namespace v8 84 } // namespace v8
OLDNEW
« no previous file with comments | « src/interpreter/source-position-table.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698