2016-02-04 10:50:01 +00:00
|
|
|
// 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.
|
|
|
|
|
|
|
|
#ifndef V8_INTERPRETER_SOURCE_POSITION_TABLE_H_
|
|
|
|
#define V8_INTERPRETER_SOURCE_POSITION_TABLE_H_
|
|
|
|
|
|
|
|
#include "src/assert-scope.h"
|
2016-02-24 12:53:42 +00:00
|
|
|
#include "src/checks.h"
|
2016-02-04 10:50:01 +00:00
|
|
|
#include "src/handles.h"
|
|
|
|
#include "src/zone-containers.h"
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
class BytecodeArray;
|
2016-02-24 12:53:42 +00:00
|
|
|
class ByteArray;
|
2016-02-04 10:50:01 +00:00
|
|
|
class Isolate;
|
2016-02-24 12:53:42 +00:00
|
|
|
class Zone;
|
2016-02-04 10:50:01 +00:00
|
|
|
|
|
|
|
namespace interpreter {
|
|
|
|
|
2016-02-24 12:53:42 +00:00
|
|
|
struct PositionTableEntry {
|
|
|
|
PositionTableEntry()
|
|
|
|
: bytecode_offset(0), source_position(0), is_statement(false) {}
|
|
|
|
PositionTableEntry(int bytecode, int source, bool statement)
|
|
|
|
: bytecode_offset(bytecode),
|
|
|
|
source_position(source),
|
|
|
|
is_statement(statement) {}
|
|
|
|
|
|
|
|
int bytecode_offset;
|
|
|
|
int source_position;
|
|
|
|
bool is_statement;
|
|
|
|
};
|
|
|
|
|
2016-02-04 10:50:01 +00:00
|
|
|
class SourcePositionTableBuilder {
|
|
|
|
public:
|
|
|
|
explicit SourcePositionTableBuilder(Isolate* isolate, Zone* zone)
|
2016-02-24 12:53:42 +00:00
|
|
|
: isolate_(isolate), bytes_(zone), previous_() {}
|
2016-02-04 10:50:01 +00:00
|
|
|
|
2016-02-05 13:29:03 +00:00
|
|
|
void AddStatementPosition(size_t bytecode_offset, int source_position);
|
|
|
|
void AddExpressionPosition(size_t bytecode_offset, int source_position);
|
2016-02-24 12:53:42 +00:00
|
|
|
Handle<ByteArray> ToSourcePositionTable();
|
2016-02-04 10:50:01 +00:00
|
|
|
|
|
|
|
private:
|
2016-02-24 12:53:42 +00:00
|
|
|
void AddEntry(const PositionTableEntry& entry);
|
2016-02-04 10:50:01 +00:00
|
|
|
|
|
|
|
Isolate* isolate_;
|
2016-02-24 12:53:42 +00:00
|
|
|
ZoneVector<byte> bytes_;
|
|
|
|
PositionTableEntry previous_;
|
|
|
|
|
|
|
|
#ifdef ENABLE_SLOW_DCHECKS
|
|
|
|
std::vector<PositionTableEntry> raw_entries_;
|
|
|
|
#endif
|
2016-02-04 10:50:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class SourcePositionTableIterator {
|
|
|
|
public:
|
2016-02-24 12:53:42 +00:00
|
|
|
explicit SourcePositionTableIterator(ByteArray* byte_array);
|
2016-02-04 10:50:01 +00:00
|
|
|
|
|
|
|
void Advance();
|
|
|
|
|
|
|
|
int bytecode_offset() const {
|
|
|
|
DCHECK(!done());
|
2016-02-24 12:53:42 +00:00
|
|
|
return current_.bytecode_offset;
|
2016-02-04 10:50:01 +00:00
|
|
|
}
|
|
|
|
int source_position() const {
|
|
|
|
DCHECK(!done());
|
2016-02-24 12:53:42 +00:00
|
|
|
return current_.source_position;
|
2016-02-04 10:50:01 +00:00
|
|
|
}
|
|
|
|
bool is_statement() const {
|
|
|
|
DCHECK(!done());
|
2016-02-24 12:53:42 +00:00
|
|
|
return current_.is_statement;
|
2016-02-04 10:50:01 +00:00
|
|
|
}
|
2016-02-24 12:53:42 +00:00
|
|
|
bool done() const { return index_ == kDone; }
|
2016-02-04 10:50:01 +00:00
|
|
|
|
|
|
|
private:
|
2016-02-24 12:53:42 +00:00
|
|
|
static const int kDone = -1;
|
|
|
|
|
|
|
|
ByteArray* table_;
|
2016-02-04 10:50:01 +00:00
|
|
|
int index_;
|
2016-02-24 12:53:42 +00:00
|
|
|
PositionTableEntry current_;
|
2016-02-04 10:50:01 +00:00
|
|
|
DisallowHeapAllocation no_gc;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace interpreter
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
|
|
|
|
|
|
|
#endif // V8_INTERPRETER_SOURCE_POSITION_TABLE_H_
|