Commit 1dec2864 authored by Sigurd Schneider's avatar Sigurd Schneider Committed by Commit Bot

[turbolizer] Change turbolizer to ES2015 modules

Bug: v8:7327
Change-Id: If2670e2b8e64a34f5de7855615e2288b6f2f3133
Reviewed-on: https://chromium-review.googlesource.com/1131193
Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
Reviewed-by: 's avatarGeorg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54371}
parent 80508f14
......@@ -102,3 +102,6 @@ v8.ignition_dispatches_table.json
/Default/
node_modules
tools/turbolizer/build
tools/turbolizer/.rpt2_cache
tools/turbolizer/deploy
This diff is collapsed.
......@@ -2,9 +2,8 @@
"name": "turbolizer",
"version": "0.1.0",
"description": "Visualization tool for V8 TurboFan IR graphs",
"main": "index.html",
"scripts": {
"build": "tsc",
"build": "rollup -c",
"watch": "tsc --watch",
"deploy": "./deploy.sh",
"format": "tsfmt -r"
......@@ -13,7 +12,10 @@
"license": "MIT",
"dependencies": {
"@types/d3": "^5.0.0",
"d3": "^5.4.0"
"d3": "^5.5.0",
"pegjs": "^0.10.0",
"rollup": "^0.62.0",
"rollup-plugin-typescript2": "^0.15.1"
},
"repository": {
"type": "git",
......
// Copyright 2018 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.
import typescript from 'rollup-plugin-typescript2';
export default {
entry: "src/turbo-visualizer.ts",
format: "iife",
plugins: [typescript({abortOnError:false})],
dest: "build/turbolizer.js"
};
......@@ -2,14 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
"use strict";
import {Source,SourceResolver,sourcePositionToStringKey} from "./source-resolver.js"
import {SelectionBroker} from "./selection-broker.js"
import {View} from "./view.js"
import {MySelection} from "./selection.js"
import {anyToString,ViewElements} from "./util.js"
enum CodeMode {
export enum CodeMode {
MAIN_SOURCE = "main function",
INLINED_SOURCE = "inlined function"
};
class CodeView extends View {
export class CodeView extends View {
broker: SelectionBroker;
source: Source;
sourceResolver: SourceResolver;
......
......@@ -2,25 +2,22 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
const MAX_RANK_SENTINEL = 0;
const GRAPH_MARGIN = 250;
const WIDTH = 'width';
const HEIGHT = 'height';
const VISIBILITY = 'visibility';
const SOURCE_PANE_ID = 'left';
const SOURCE_COLLAPSE_ID = 'source-shrink';
const SOURCE_EXPAND_ID = 'source-expand';
const INTERMEDIATE_PANE_ID = 'middle';
const GRAPH_PANE_ID = 'graph';
const SCHEDULE_PANE_ID = 'schedule';
const GENERATED_PANE_ID = 'right';
const DISASSEMBLY_PANE_ID = 'disassembly';
const DISASSEMBLY_COLLAPSE_ID = 'disassembly-shrink';
const DISASSEMBLY_EXPAND_ID = 'disassembly-expand';
const COLLAPSE_PANE_BUTTON_VISIBLE = 'button-input';
const COLLAPSE_PANE_BUTTON_INVISIBLE = 'button-input-invisible';
const UNICODE_BLOCK = '&#9611;';
const PROF_COLS = [
export const MAX_RANK_SENTINEL = 0;
export const GRAPH_MARGIN = 250;
export const SOURCE_PANE_ID = 'left';
export const SOURCE_COLLAPSE_ID = 'source-shrink';
export const SOURCE_EXPAND_ID = 'source-expand';
export const INTERMEDIATE_PANE_ID = 'middle';
export const GRAPH_PANE_ID = 'graph';
export const SCHEDULE_PANE_ID = 'schedule';
export const GENERATED_PANE_ID = 'right';
export const DISASSEMBLY_PANE_ID = 'disassembly';
export const DISASSEMBLY_COLLAPSE_ID = 'disassembly-shrink';
export const DISASSEMBLY_EXPAND_ID = 'disassembly-expand';
export const COLLAPSE_PANE_BUTTON_VISIBLE = 'button-input';
export const COLLAPSE_PANE_BUTTON_INVISIBLE = 'button-input-invisible';
export const UNICODE_BLOCK = '&#9611;';
export const PROF_COLS = [
{ perc: 0, col: { r: 255, g: 255, b: 255 } },
{ perc: 0.5, col: { r: 255, g: 255, b: 128 } },
{ perc: 5, col: { r: 255, g: 128, b: 0 } },
......
......@@ -2,9 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
"use strict";
import {PROF_COLS, UNICODE_BLOCK} from "./constants.js"
import {SelectionBroker} from "./selection-broker.js"
import {TextView} from "./text-view.js"
class DisassemblyView extends TextView {
export class DisassemblyView extends TextView {
SOURCE_POSITION_HEADER_REGEX: any;
addr_event_counts: any;
total_event_counts: any;
......
......@@ -2,13 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var MINIMUM_EDGE_SEPARATION = 20;
import {GNode, DEFAULT_NODE_BUBBLE_RADIUS} from "./node.js"
function isEdgeInitiallyVisible(target, index, source, type) {
export const MINIMUM_EDGE_SEPARATION = 20;
export function isEdgeInitiallyVisible(target, index, source, type) {
return type == "control" && (target.cfg || source.cfg);
}
class Edge {
export class Edge {
target: GNode;
source: GNode;
index: number;
......@@ -89,4 +91,4 @@ class Edge {
}
const edgeToStr = (e: Edge) => e.stringID();
export const edgeToStr = (e: Edge) => e.stringID();
......@@ -2,7 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var DEFAULT_NODE_ROW_SEPARATION = 130
import {MAX_RANK_SENTINEL} from "./constants.js"
import {MINIMUM_EDGE_SEPARATION} from "./edge.js"
import {NODE_INPUT_WIDTH, MINIMUM_NODE_OUTPUT_APPROACH, DEFAULT_NODE_BUBBLE_RADIUS} from "./node.js"
const DEFAULT_NODE_ROW_SEPARATION = 130
var traceLayout = false;
......@@ -246,7 +252,7 @@ function newGraphOccupation(graph) {
return occupation;
}
function layoutNodeGraph(graph) {
export function layoutNodeGraph(graph) {
// First determine the set of nodes that have no outputs. Those are the
// basis for bottom-up DFS to determine rank and node placement.
var endNodesHasNoOutputs = [];
......
......@@ -2,7 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
"use strict";
import * as d3 from "d3"
import {layoutNodeGraph} from "./graph-layout.js"
import {MAX_RANK_SENTINEL} from "./constants.js"
import {GNode, nodeToStr, isNodeInitiallyVisible} from "./node.js"
import {NODE_INPUT_WIDTH, MINIMUM_NODE_OUTPUT_APPROACH} from "./node.js"
import {DEFAULT_NODE_BUBBLE_RADIUS} from "./node.js"
import {Edge, edgeToStr} from "./edge.js"
import {View, PhaseView} from "./view.js"
import {MySelection} from "./selection.js"
import {partial, alignUp} from "./util.js"
function nodeToStringKey(n) {
return "" + n.id;
......@@ -18,7 +27,7 @@ interface GraphState {
hideDead: boolean
}
class GraphView extends View implements PhaseView {
export class GraphView extends View implements PhaseView {
divElement: d3.Selection<any, any, any, any>;
svg: d3.Selection<any, any, any, any>;
showPhaseByName: (string) => void;
......@@ -272,7 +281,7 @@ class GraphView extends View implements PhaseView {
};
measureText(text) {
const textMeasure = document.getElementById('text-measure');
const textMeasure = document.getElementById('text-measure') as SVGTSpanElement;
textMeasure.textContent = text;
return {
width: textMeasure.getBBox().width,
......@@ -304,7 +313,7 @@ class GraphView extends View implements PhaseView {
n.labelbbox = g.measureText(n.displayLabel);
n.typebbox = g.measureText(n.getDisplayType());
var innerwidth = Math.max(n.labelbbox.width, n.typebbox.width);
n.width = MoreMath.alignUp(innerwidth + NODE_INPUT_WIDTH * 2,
n.width = alignUp(innerwidth + NODE_INPUT_WIDTH * 2,
NODE_INPUT_WIDTH);
var innerheight = Math.max(n.labelbbox.height, n.typebbox.height);
n.normalheight = innerheight + 20;
......@@ -748,10 +757,10 @@ class GraphView extends View implements PhaseView {
newGs.append("rect")
.attr("rx", 10)
.attr("ry", 10)
.attr(WIDTH, function (d) {
.attr('width', function (d) {
return d.getTotalNodeWidth();
})
.attr(HEIGHT, function (d) {
.attr('height', function (d) {
return graph.getNodeHeight(d);
})
......@@ -856,7 +865,7 @@ class GraphView extends View implements PhaseView {
})
.attr("transform", function (d) { return "translate(" + d.x + "," + d.y + ")"; })
.select('rect')
.attr(HEIGHT, function (d) { return graph.getNodeHeight(d); });
.attr('height', function (d) { return graph.getNodeHeight(d); });
graph.visibleBubbles = d3.selectAll('circle');
......
......@@ -2,9 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
"use strict";
import {GraphView} from "./graph-view.js"
import {ScheduleView} from "./schedule-view.js"
import {SourceResolver} from "./source-resolver.js"
import {SelectionBroker} from "./selection-broker.js"
import {View, PhaseView} from "./view.js"
class GraphMultiView extends View {
export class GraphMultiView extends View {
sourceResolver: SourceResolver;
selectionBroker: SelectionBroker;
graph: GraphView;
......
// Copyright 2014 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.
const MoreMath = {
alignUp: (raw, multiple) => {
return Math.floor((raw + multiple - 1) / multiple) * multiple;
}
};
......@@ -2,13 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
const TYPE_HEIGHT = 25;
const DEFAULT_NODE_BUBBLE_RADIUS = 12;
const NODE_INPUT_WIDTH = 50;
import {NodeOrigin} from "./source-resolver.js"
import {MINIMUM_EDGE_SEPARATION} from "./edge.js"
export const DEFAULT_NODE_BUBBLE_RADIUS = 12;
export const NODE_INPUT_WIDTH = 50;
export const MINIMUM_NODE_OUTPUT_APPROACH = 15;
const MINIMUM_NODE_INPUT_APPROACH = 15 + 2 * DEFAULT_NODE_BUBBLE_RADIUS;
const MINIMUM_NODE_OUTPUT_APPROACH = 15;
function isNodeInitiallyVisible(node) {
export function isNodeInitiallyVisible(node) {
return node.cfg;
}
......@@ -22,7 +24,7 @@ function formatOrigin(origin) {
return "unknown origin";
}
class GNode {
export class GNode {
control: boolean;
opcode: string;
live: boolean;
......@@ -177,4 +179,4 @@ class GNode {
}
};
const nodeToStr = (n: GNode) => "N" + n.id;
export const nodeToStr = (n: GNode) => "N" + n.id;
......@@ -2,9 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
"use strict";
import {Schedule,SourceResolver} from "./source-resolver.js"
import {isIterable} from "./util.js"
import {PhaseView} from "./view.js"
import {TextView} from "./text-view.js"
class ScheduleView extends TextView implements PhaseView {
export class ScheduleView extends TextView implements PhaseView {
schedule: Schedule;
sourceResolver: SourceResolver;
......
......@@ -2,7 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
class SelectionBroker {
import {SourceResolver, sourcePositionValid} from "./source-resolver.js"
export class SelectionBroker {
sourceResolver: SourceResolver;
sourcePositionHandlers: Array<SelectionHandler>;
nodeHandlers: Array<NodeSelectionHandler>;
......
......@@ -2,7 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
class MySelection {
import {isIterable} from "./util.js"
export class MySelection {
selection: any;
stringKey: (o: any) => string;
......
......@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import {sortUnique, anyToString} from "./util.js"
function sourcePositionLe(a, b) {
if (a.inliningId == b.inliningId) {
return a.scriptOffset - b.scriptOffset;
......@@ -14,7 +16,7 @@ function sourcePositionEq(a, b) {
a.scriptOffset == b.scriptOffset;
}
function sourcePositionToStringKey(sourcePosition): string {
export function sourcePositionToStringKey(sourcePosition): string {
if (!sourcePosition) return "undefined";
if (sourcePosition.inliningId && sourcePosition.scriptOffset)
return "SP:" + sourcePosition.inliningId + ":" + sourcePosition.scriptOffset;
......@@ -23,12 +25,12 @@ function sourcePositionToStringKey(sourcePosition): string {
return "undefined";
}
function sourcePositionValid(l) {
export function sourcePositionValid(l) {
return (typeof l.scriptOffset !== undefined
&& typeof l.inliningId !== undefined) || typeof l.bytecodePosition != undefined;
}
interface SourcePosition {
export interface SourcePosition {
scriptOffset: number;
inliningId: number;
}
......@@ -38,7 +40,7 @@ interface TurboFanOrigin {
reducer: string;
}
interface NodeOrigin {
export interface NodeOrigin {
nodeId: number;
}
......@@ -52,7 +54,7 @@ type TurboFanBytecodeOrigin = BytecodePosition & TurboFanOrigin;
type AnyPosition = SourcePosition | BytecodePosition;
interface Source {
export interface Source {
sourcePositions: Array<SourcePosition>;
sourceName: string;
functionName: string;
......@@ -70,11 +72,11 @@ interface Phase {
data: any;
}
interface Schedule {
export interface Schedule {
nodes: Array<any>;
}
class SourceResolver {
export class SourceResolver {
nodePositionMap: Array<AnyPosition>;
sources: Array<Source>;
inlinings: Array<Inlining>;
......
......@@ -2,13 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
"use strict";
import {View} from "./view.js"
import {anyToString, ViewElements, isIterable} from "./util.js"
import {MySelection} from "./selection.js"
function anyToString(x: any): string {
return "" + x;
}
abstract class TextView extends View {
export abstract class TextView extends View {
selectionHandler: NodeSelectionHandler;
blockSelectionHandler: BlockSelectionHandler;
nodeSelectionHandler: NodeSelectionHandler;
......
......@@ -2,6 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import * as C from "./constants.js"
import {SourceResolver} from "./source-resolver.js"
import {SelectionBroker} from "./selection-broker.js"
import {DisassemblyView} from "./disassembly-view.js"
import {GraphMultiView} from "./graphmultiview.js"
import {CodeMode, CodeView} from "./code-view.js"
import * as d3 from "d3"
class Snapper {
resizer: Resizer;
sourceExpand: HTMLElement;
......@@ -12,10 +20,10 @@ class Snapper {
constructor(resizer: Resizer) {
const snapper = this;
snapper.resizer = resizer;
snapper.sourceExpand = document.getElementById(SOURCE_EXPAND_ID);
snapper.sourceCollapse = document.getElementById(SOURCE_COLLAPSE_ID);
snapper.disassemblyExpand = document.getElementById(DISASSEMBLY_EXPAND_ID);
snapper.disassemblyCollapse = document.getElementById(DISASSEMBLY_COLLAPSE_ID);
snapper.sourceExpand = document.getElementById(C.SOURCE_EXPAND_ID);
snapper.sourceCollapse = document.getElementById(C.SOURCE_COLLAPSE_ID);
snapper.disassemblyExpand = document.getElementById(C.DISASSEMBLY_EXPAND_ID);
snapper.disassemblyCollapse = document.getElementById(C.DISASSEMBLY_COLLAPSE_ID);
document.getElementById("source-collapse").addEventListener("click", function () {
resizer.snapper.toggleSourceExpanded();
......@@ -112,9 +120,9 @@ class Resizer {
resizer.panes_updated_callback = panes_updated_callback;
resizer.dead_width = dead_width
resizer.client_width = document.body.getBoundingClientRect().width;
resizer.left = document.getElementById(SOURCE_PANE_ID);
resizer.middle = document.getElementById(INTERMEDIATE_PANE_ID);
resizer.right = document.getElementById(GENERATED_PANE_ID);
resizer.left = document.getElementById(C.SOURCE_PANE_ID);
resizer.middle = document.getElementById(C.INTERMEDIATE_PANE_ID);
resizer.right = document.getElementById(C.GENERATED_PANE_ID);
resizer.resizer_left = d3.select('.resizer-left');
resizer.resizer_right = d3.select('.resizer-right');
resizer.sep_left = resizer.client_width / 3;
......@@ -188,7 +196,6 @@ class Resizer {
}
window.onload = function () {
"use strict";
var svg = null;
var multiview = null;
var disassemblyView = null;
......@@ -237,24 +244,24 @@ window.onload = function () {
sourceResolver.setNodePositionMap(jsonObj.nodePositions);
sourceResolver.parsePhases(jsonObj.phases);
let sourceView = new CodeView(SOURCE_PANE_ID, selectionBroker, sourceResolver, fnc, CodeMode.MAIN_SOURCE);
let sourceView = new CodeView(C.SOURCE_PANE_ID, selectionBroker, sourceResolver, fnc, CodeMode.MAIN_SOURCE);
sourceView.show(null, null);
sourceViews.push(sourceView);
sourceResolver.forEachSource((source) => {
let sourceView = new CodeView(SOURCE_PANE_ID, selectionBroker, sourceResolver, source, CodeMode.INLINED_SOURCE);
let sourceView = new CodeView(C.SOURCE_PANE_ID, selectionBroker, sourceResolver, source, CodeMode.INLINED_SOURCE);
sourceView.show(null, null);
sourceViews.push(sourceView);
});
disassemblyView = new DisassemblyView(GENERATED_PANE_ID, selectionBroker);
disassemblyView = new DisassemblyView(C.GENERATED_PANE_ID, selectionBroker);
disassemblyView.initializeCode(fnc.sourceText);
if (sourceResolver.disassemblyPhase) {
disassemblyView.initializePerfProfile(jsonObj.eventCounts);
disassemblyView.show(sourceResolver.disassemblyPhase.data, null);
}
multiview = new GraphMultiView(INTERMEDIATE_PANE_ID, selectionBroker, sourceResolver);
multiview = new GraphMultiView(C.INTERMEDIATE_PANE_ID, selectionBroker, sourceResolver);
multiview.show(jsonObj);
} catch (err) {
if (window.confirm("Error: Exception during load of TurboFan JSON file:\n" +
......
......@@ -2,7 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
"use strict";
export function anyToString(x: any): string {
return "" + x;
}
function computeScrollTop(container, element) {
const height = container.offsetHeight;
......@@ -17,7 +19,7 @@ function computeScrollTop(container, element) {
return pos;
}
class ViewElements {
export class ViewElements {
container: HTMLElement;
scrollTop: number;
......@@ -84,7 +86,7 @@ function upperBound(a, value, compare, lookup) {
}
function sortUnique<T>(arr: Array<T>, f: (a: T, b: T) => number, equal: (a: T, b: T) => boolean) {
export function sortUnique<T>(arr: Array<T>, f: (a: T, b: T) => number, equal: (a: T, b: T) => boolean) {
if (arr.length == 0) return arr;
arr = arr.sort(f);
let ret = [arr[0]];
......@@ -97,14 +99,18 @@ function sortUnique<T>(arr: Array<T>, f: (a: T, b: T) => number, equal: (a: T, b
}
// Partial application without binding the receiver
function partial(f, ...arguments1) {
export function partial(f, ...arguments1) {
return function (...arguments2) {
var arguments2 = Array.from(arguments);
f.apply(this, [...arguments1, ...arguments2]);
}
}
function isIterable(obj: any): obj is Iterable<any> {
export function isIterable(obj: any): obj is Iterable<any> {
return obj != null && obj != undefined
&& typeof obj != 'string' && typeof obj[Symbol.iterator] === 'function';
}
export function alignUp(raw:number, multiple:number):number {
return Math.floor((raw + multiple - 1) / multiple) * multiple;
}
......@@ -2,9 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
"use strict";
abstract class View {
export abstract class View {
container: HTMLElement;
divNode: HTMLElement;
abstract initializeContent(data: any, rememberedSelection: Selection): void;
......@@ -32,7 +30,7 @@ abstract class View {
}
}
interface PhaseView {
export interface PhaseView {
onresize();
searchInputAction(searchInput: HTMLInputElement, e: Event);
}
{
"compilerOptions": {
"outFile": "build/turbolizer.js",
"allowJs": true,
"outDir": "build/",
"allowJs": false,
"target": "es2017",
"sourceMap": true
"module": "es2015",
"sourceMap": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"moduleResolution": "node"
},
"files": [
"src/monkey.ts",
"src/util.ts",
"src/lang-disassembly.ts",
"src/node.ts",
......@@ -26,4 +29,4 @@
"src/graphmultiview.ts",
"src/turbo-visualizer.ts"
]
}
\ No newline at end of file
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment