v8/tools/turbolizer/selection-broker.js
Sigurd Schneider a97a362d86 [turbolizer] Add support for inlined functions
This CL adds support for inlined functions in Turbolizer. It is also a
refactoring of the Turbolizer code-base. Most importantly, handling of
source positions changed to exact source positions, and not code ranges.
This improves selection interoperability between different phase views.

A separate CL changes the Turbolizer JSON format to include inlining
information. This Turbolizer update, however, is intended to be backwards
compatible with the JSON format Turbolizer generated before the JSON
format change.


Bug: v8:7327
Change-Id: Ic67506a6f3a36fe98c012b1e76994972779c1fd2
Reviewed-on: https://chromium-review.googlesource.com/1032784
Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
Reviewed-by: Daniel Clifford <danno@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53213}
2018-05-16 13:43:14 +00:00

74 lines
2.1 KiB
JavaScript

// Copyright 2015 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.
class SelectionBroker {
constructor(sourceResolver) {
this.sourcePositionHandlers = [];
this.nodeHandlers = [];
this.blockHandlers = [];
this.sourceResolver = sourceResolver;
};
addSourcePositionHandler(handler) {
this.sourcePositionHandlers.push(handler);
}
addNodeHandler(handler) {
this.nodeHandlers.push(handler);
}
addBlockHandler(handler) {
this.blockHandlers.push(handler);
}
broadcastSourcePositionSelect(from, sourcePositions, selected) {
let broker = this;
sourcePositions = sourcePositions.filter((l) => {
if (typeof l.scriptOffset == 'undefined'
|| typeof l.inliningId == 'undefined') {
console.log("Warning: invalid source position");
return false;
}
return true;
});
for (var b of this.sourcePositionHandlers) {
if (b != from) b.brokeredSourcePositionSelect(sourcePositions, selected);
}
const nodes = this.sourceResolver.sourcePositionsToNodeIds(sourcePositions);
for (var b of this.nodeHandlers) {
if (b != from) b.brokeredNodeSelect(nodes, selected);
}
}
broadcastNodeSelect(from, nodes, selected) {
let broker = this;
for (var b of this.nodeHandlers) {
if (b != from) b.brokeredNodeSelect(nodes, selected);
}
const sourcePositions = this.sourceResolver.nodeIdsToSourcePositions(nodes);
for (var b of this.sourcePositionHandlers) {
if (b != from) b.brokeredSourcePositionSelect(sourcePositions, selected);
}
}
broadcastBlockSelect(from, blocks, selected) {
let broker = this;
for (var b of this.blockHandlers) {
if (b != from) b.brokeredBlockSelect(blocks, selected);
}
}
broadcastClear(from) {
this.sourcePositionHandlers.forEach(function (b) {
if (b != from) b.brokeredClear();
});
this.nodeHandlers.forEach(function (b) {
if (b != from) b.brokeredClear();
});
this.blockHandlers.forEach(function (b) {
if (b != from) b.brokeredClear();
});
}
}