summaryrefslogtreecommitdiff
path: root/deps/v8/tools/turbolizer/schedule-view.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/tools/turbolizer/schedule-view.js')
-rw-r--r--deps/v8/tools/turbolizer/schedule-view.js253
1 files changed, 144 insertions, 109 deletions
diff --git a/deps/v8/tools/turbolizer/schedule-view.js b/deps/v8/tools/turbolizer/schedule-view.js
index ef4789211d..0864fceea7 100644
--- a/deps/v8/tools/turbolizer/schedule-view.js
+++ b/deps/v8/tools/turbolizer/schedule-view.js
@@ -5,124 +5,159 @@
"use strict";
class ScheduleView extends TextView {
- constructor(id, broker) {
- super(id, broker, null, false);
- let view = this;
- let BLOCK_STYLE = {
- css: 'tag'
- };
- const BLOCK_HEADER_STYLE = {
- css: 'com',
- block_id: -1,
- location: function(text) {
- let matches = /\d+/.exec(text);
- if (!matches) return undefined;
- BLOCK_HEADER_STYLE.block_id = Number(matches[0]);
- return {
- block_id: BLOCK_HEADER_STYLE.block_id
- };
- },
- };
- const BLOCK_LINK_STYLE = {
- css: 'tag',
- link: function(text) {
- let id = Number(text.substr(1));
- view.select(function(location) { return location.block_id == id; }, true, true);
- }
- };
- const ID_STYLE = {
- css: 'tag',
- location: function(text) {
- let matches = /\d+/.exec(text);
- return {
- node_id: Number(matches[0]),
- block_id: BLOCK_HEADER_STYLE.block_id
- };
- },
- };
- const ID_LINK_STYLE = {
- css: 'tag',
- link: function(text) {
- let id = Number(text);
- view.select(function(location) { return location.node_id == id; }, true, true);
+
+ createViewElement() {
+ const pane = document.createElement('div');
+ pane.setAttribute('id', "schedule");
+ pane.innerHTML =
+ `<pre id='schedule-text-pre' class='prettyprint prettyprinted'>
+ <ul id='schedule-list' class='nolinenums noindent'>
+ </ul>
+ </pre>`;
+ return pane;
+ }
+
+ constructor(parentId, broker) {
+ super(parentId, broker, null, false);
+ }
+
+ attachSelection(s) {
+ const view = this;
+ if (!(s instanceof Set)) return;
+ view.selectionHandler.clear();
+ view.blockSelectionHandler.clear();
+ view.sourcePositionSelectionHandler.clear();
+ const selected = new Array();
+ for (const key of s) selected.push(key);
+ view.selectionHandler.select(selected, true);
+ }
+
+ createElementFromString(htmlString) {
+ var div = document.createElement('div');
+ div.innerHTML = htmlString.trim();
+ return div.firstChild;
+ }
+
+
+ elementForBlock(block) {
+ const view = this;
+ function createElement(tag, cls, content) {
+ const el = document.createElement(tag);
+ if (isIterable(cls)) {
+ for (const c of cls) el.classList.add(c);
+ } else {
+ el.classList.add(cls);
}
- };
- const NODE_STYLE = { css: 'kwd' };
- const GOTO_STYLE = { css: 'kwd',
- goto_id: -2,
- location: function(text) {
- return {
- node_id: GOTO_STYLE.goto_id--,
- block_id: BLOCK_HEADER_STYLE.block_id
- };
+ if (content != undefined) el.innerHTML = content;
+ return el;
+ }
+
+ function mkNodeLinkHandler(nodeId) {
+ return function (e) {
+ e.stopPropagation();
+ if (!e.shiftKey) {
+ view.selectionHandler.clear();
+ }
+ view.selectionHandler.select([nodeId], true);
+ };
+ }
+
+ function createElementForNode(node) {
+ const nodeEl = createElement("div", "node");
+ const node_id = createElement("div", ["node-id", "tag", "clickable"], node.id);
+ node_id.onclick = mkNodeLinkHandler(node.id);
+ view.addHtmlElementForNodeId(node.id, node_id);
+ nodeEl.appendChild(node_id);
+ const node_label = createElement("div", "node-label", node.label);
+ nodeEl.appendChild(node_label);
+ if (node.inputs.length > 0) {
+ const node_parameters = createElement("div", ["parameter-list", "comma-sep-list"]);
+ for (const param of node.inputs) {
+ const paramEl = createElement("div", ["parameter", "tag", "clickable"], param);
+ node_parameters.appendChild(paramEl);
+ paramEl.onclick = mkNodeLinkHandler(param);
+ view.addHtmlElementForNodeId(param, paramEl);
+ }
+ nodeEl.appendChild(node_parameters);
}
+ return nodeEl;
}
- const ARROW_STYLE = { css: 'kwd' };
- let patterns = [
- [
- [/^--- BLOCK B\d+/, BLOCK_HEADER_STYLE, 1],
- [/^\s+\d+: /, ID_STYLE, 2],
- [/^\s+Goto/, GOTO_STYLE, 6],
- [/^.*/, null, -1]
- ],
- [
- [/^ +/, null],
- [/^\(deferred\)/, BLOCK_HEADER_STYLE],
- [/^B\d+/, BLOCK_LINK_STYLE],
- [/^<-/, ARROW_STYLE],
- [/^->/, ARROW_STYLE],
- [/^,/, null],
- [/^---/, BLOCK_HEADER_STYLE, -1]
- ],
- // Parse opcode including []
- [
- [/^[A-Za-z0-9_]+(\[.*\])?$/, NODE_STYLE, -1],
- [/^[A-Za-z0-9_]+(\[(\[.*?\]|.)*?\])?/, NODE_STYLE, 3]
- ],
- // Parse optional parameters
- [
- [/^ /, null, 4],
- [/^\(/, null],
- [/^\d+/, ID_LINK_STYLE],
- [/^, /, null],
- [/^\)$/, null, -1],
- [/^\)/, null, 4],
- ],
- [
- [/^ -> /, ARROW_STYLE, 5],
- [/^.*/, null, -1]
- ],
- [
- [/^B\d+$/, BLOCK_LINK_STYLE, -1],
- [/^B\d+/, BLOCK_LINK_STYLE],
- [/^, /, null]
- ],
- [
- [/^ -> /, ARROW_STYLE],
- [/^B\d+$/, BLOCK_LINK_STYLE, -1]
- ]
- ];
- this.setPatterns(patterns);
+
+ function mkBlockLinkHandler(blockId) {
+ return function (e) {
+ e.stopPropagation();
+ if (!e.shiftKey) {
+ view.blockSelectionHandler.clear();
+ }
+ view.blockSelectionHandler.select(["" + blockId], true);
+ };
+ }
+
+ const schedule_block = createElement("div", "schedule-block");
+ const block_id = createElement("div", ["block-id", "com", "clickable"], block.id);
+ block_id.onclick = mkBlockLinkHandler(block.id);
+ schedule_block.appendChild(block_id);
+ const block_pred = createElement("div", ["predecessor-list", "block-list", "comma-sep-list"]);
+ for (const pred of block.pred) {
+ const predEl = createElement("div", ["block-id", "com", "clickable"], pred);
+ predEl.onclick = mkBlockLinkHandler(pred);
+ block_pred.appendChild(predEl);
+ }
+ if (block.pred.length) schedule_block.appendChild(block_pred);
+ const nodes = createElement("div", "nodes");
+ for (const node of block.nodes) {
+ nodes.appendChild(createElementForNode(node, block.id));
+ }
+ schedule_block.appendChild(nodes);
+ const block_succ = createElement("div", ["successor-list", "block-list", "comma-sep-list"]);
+ for (const succ of block.succ) {
+ const succEl = createElement("div", ["block-id", "com", "clickable"], succ);
+ succEl.onclick = mkBlockLinkHandler(succ);
+ block_succ.appendChild(succEl);
+ }
+ if (block.succ.length) schedule_block.appendChild(block_succ);
+ this.addHtmlElementForBlockId(block.id, schedule_block);
+ return schedule_block;
}
- initializeContent(data, rememberedSelection) {
- super.initializeContent(data, rememberedSelection);
- var graph = this;
- var locations = [];
- for (var id of rememberedSelection) {
- locations.push({ node_id : id });
+ addBlocks(blocks) {
+ for (const block of blocks) {
+ const blockEl = this.elementForBlock(block);
+ this.divNode.appendChild(blockEl);
}
- this.selectLocations(locations, true, true);
+ }
+
+ initializeContent(data, rememberedSelection) {
+ this.clearText();
+ this.schedule = data.schedule
+ this.addBlocks(data.schedule.blocks);
+ this.attachSelection(rememberedSelection);
}
detachSelection() {
- var selection = this.selection.detachSelection();
- var s = new Set();
- for (var i of selection) {
- if (i.location.node_id != undefined && i.location.node_id > 0) {
- s.add(i.location.node_id);
+ this.blockSelection.clear();
+ this.sourcePositionSelection.clear();
+ return this.selection.detachSelection();
+ }
+
+ lineString(node) {
+ return `${node.id}: ${node.label}(${node.inputs.join(", ")})`
+ }
+
+ searchInputAction(view, searchBar) {
+ d3.event.stopPropagation();
+ this.selectionHandler.clear();
+ const query = searchBar.value;
+ if (query.length == 0) return;
+ const select = [];
+ window.sessionStorage.setItem("lastSearch", query);
+ const reg = new RegExp(query);
+ for (const node of this.schedule.nodes) {
+ if (node === undefined) continue;
+ if (reg.exec(this.lineString(node)) != null) {
+ select.push(node.id)
}
- };
- return s;
+ }
+ this.selectionHandler.select(select, true);
}
}