Commit c5f87848 authored by Danylo Boiko's avatar Danylo Boiko Committed by V8 LUCI CQ

[turbolizer] Initial TS code refactoring

- basic file movement
- dependencies update
- grammar fix
- refactoring common files (from new folder 'common')

Change-Id: Ie47d565202aefe247ef6fd9e64108926e467d533
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3695385Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Commit-Queue: Danylo Boiko <danielboyko02@gmail.com>
Cr-Commit-Position: refs/heads/main@{#81050}
parent fb235844
......@@ -2276,7 +2276,7 @@ std::ostream& operator<<(std::ostream& out, const InstructionRangesAsJSON& s) {
need_comma = true;
}
out << "}";
out << ", \"blockIdtoInstructionRange\": {";
out << ", \"blockIdToInstructionRange\": {";
need_comma = false;
for (auto block : s.sequence->instruction_blocks()) {
if (need_comma) out << ", ";
......
This diff is collapsed.
{
"name": "turbolizer",
"version": "0.1.0",
"version": "0.1.1",
"description": "Visualization tool for V8 TurboFan IR graphs",
"scripts": {
"build": "rollup -c",
......@@ -13,22 +13,23 @@
"author": "The V8 team",
"license": "MIT",
"dependencies": {
"@types/d3": "^5.7.2",
"d3": "^5.7.0",
"@types/d3": "^5.16.0",
"d3": "^5.16.0",
"rollup-plugin-node-resolve": "^4.0.0",
"rollup-plugin-typescript2": "^0.20.1"
"rollup-plugin-typescript2": "^0.32.1"
},
"repository": {
"type": "git",
"url": "https://github.com/v8/v8.git"
},
"devDependencies": {
"chai": "^4.2.0",
"local-web-server": "^2.6.0",
"mocha": "^5.2.0",
"rollup": "^0.68.2",
"ts-mocha": "^2.0.0",
"tslint": "^5.12.0",
"typescript": "^3.2.2"
"@types/node": "^17.0.41",
"chai": "^4.3.6",
"local-web-server": "^5.2.1",
"mocha": "^10.0.0",
"rollup": "^2.75.6",
"ts-mocha": "^10.0.0",
"tslint": "^5.20.1",
"typescript": "^4.7.3"
}
}
......@@ -2,18 +2,16 @@
// 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';
import node from 'rollup-plugin-node-resolve';
import path from 'path';
import typescript from "rollup-plugin-typescript2";
import node from "rollup-plugin-node-resolve";
import path from "path";
const onwarn = warning => {
const warningHandler = (warning) => {
// Silence circular dependency warning for moment package
const node_modules = path.normalize('node_modules/');
if (warning.code === 'CIRCULAR_DEPENDENCY' &&
!warning.importer.indexOf(node_modules)) {
return
if (warning.code === 'CIRCULAR_DEPENDENCY' && warning.importer.indexOf(node_modules)) {
return;
}
console.warn(`(!) ${warning.message}`)
}
......@@ -27,5 +25,5 @@ export default {
format: "iife",
sourcemap: true
},
onwarn: onwarn
onwarn: warningHandler
};
......@@ -4,22 +4,22 @@
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 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 RANGES_PANE_ID = "ranges";
export const RANGES_COLLAPSE_VERT_ID = "ranges-shrink-vert";
export const RANGES_EXPAND_VERT_ID = "ranges-expand-vert";
export const RANGES_COLLAPSE_HOR_ID = "ranges-shrink-hor";
export const RANGES_EXPAND_HOR_ID = "ranges-expand-hor";
export const UNICODE_BLOCK = '&#9611;';
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 } },
......
......@@ -3,80 +3,39 @@
// found in the LICENSE file.
export function anyToString(x: any): string {
return "" + x;
return `${x}`;
}
function computeScrollTop(container, element) {
const height = container.offsetHeight;
const margin = Math.floor(height / 4);
const pos = element.offsetTop;
const currentScrollTop = container.scrollTop;
if (pos < currentScrollTop + margin) {
return Math.max(0, pos - margin);
} else if (pos > (currentScrollTop + 3 * margin)) {
return Math.max(0, pos - 3 * margin);
}
return pos;
}
export class ViewElements {
container: HTMLElement;
scrollTop: number;
constructor(container: HTMLElement) {
this.container = container;
this.scrollTop = undefined;
}
consider(element, doConsider) {
if (!doConsider) return;
const newScrollTop = computeScrollTop(this.container, element);
if (isNaN(newScrollTop)) {
console.log("NOO");
}
if (this.scrollTop === undefined) {
this.scrollTop = newScrollTop;
} else {
this.scrollTop = Math.min(this.scrollTop, newScrollTop);
}
}
apply(doApply) {
if (!doApply || this.scrollTop === undefined) return;
this.container.scrollTop = this.scrollTop;
}
}
export 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): Array<T> {
if (arr.length == 0) return arr;
arr = arr.sort(f);
const ret = [arr[0]];
const uniqueArr = [arr[0]];
for (let i = 1; i < arr.length; i++) {
if (!equal(arr[i - 1], arr[i])) {
ret.push(arr[i]);
uniqueArr.push(arr[i]);
}
}
return ret;
return uniqueArr;
}
// Partial application without binding the receiver
export function partial(f: any, ...arguments1: Array<any>) {
export function partial(func: any, ...arguments1: Array<any>) {
return function (this: any, ...arguments2: Array<any>) {
f.apply(this, [...arguments1, ...arguments2]);
func.apply(this, [...arguments1, ...arguments2]);
};
}
export function isIterable(obj: any): obj is Iterable<any> {
return obj != null && obj != undefined
&& typeof obj != 'string' && typeof obj[Symbol.iterator] === 'function';
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;
}
export function measureText(text: string) {
const textMeasure = document.getElementById('text-measure');
export function measureText(text: string): { width: number, height: number } {
const textMeasure = document.getElementById("text-measure");
if (textMeasure instanceof SVGTSpanElement) {
textMeasure.textContent = text;
return {
......@@ -88,13 +47,13 @@ export function measureText(text: string) {
}
// Interpolate between the given start and end values by a fraction of val/max.
export function interpolate(val: number, max: number, start: number, end: number) {
export function interpolate(val: number, max: number, start: number, end: number): number {
return start + (end - start) * (val / max);
}
export function createElement(tag: string, cls: string, content?: string) {
export function createElement(tag: string, cls: string, content?: string): HTMLElement {
const el = document.createElement(tag);
el.className = cls;
if (content != undefined) el.innerText = content;
if (content !== undefined) el.innerText = content;
return el;
}
// Copyright 2022 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.
export class ViewElements {
container: HTMLElement;
scrollTop: number;
constructor(container: HTMLElement) {
this.container = container;
this.scrollTop = undefined;
}
public consider(element: HTMLElement, doConsider: boolean): void {
if (!doConsider) return;
const newScrollTop = this.computeScrollTop(element);
if (isNaN(newScrollTop)) {
console.warn("New scroll top value is NaN");
}
if (this.scrollTop === undefined) {
this.scrollTop = newScrollTop;
} else {
this.scrollTop = Math.min(this.scrollTop, newScrollTop);
}
}
public apply(doApply: boolean): void {
if (!doApply || this.scrollTop === undefined) return;
this.container.scrollTop = this.scrollTop;
}
private computeScrollTop(element: HTMLElement): number {
const height = this.container.offsetHeight;
const margin = Math.floor(height / 4);
const pos = element.offsetTop;
const currentScrollTop = this.container.scrollTop;
if (pos < currentScrollTop + margin) {
return Math.max(0, pos - margin);
} else if (pos > (currentScrollTop + 3 * margin)) {
return Math.max(0, pos - 3 * margin);
}
return pos;
}
}
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import { GNode, MINIMUM_EDGE_SEPARATION, DEFAULT_NODE_BUBBLE_RADIUS } from "../src/node";
import { GNode, MINIMUM_EDGE_SEPARATION, DEFAULT_NODE_BUBBLE_RADIUS } from "./node";
import { Graph } from "./graph";
const BEZIER_CONSTANT = 0.3;
......
......@@ -2,9 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import { MAX_RANK_SENTINEL } from "../src/constants";
import { Edge } from "../src/edge";
import { GNode, MINIMUM_EDGE_SEPARATION, NODE_INPUT_WIDTH, MINIMUM_NODE_OUTPUT_APPROACH, DEFAULT_NODE_BUBBLE_RADIUS } from "../src/node";
import { MAX_RANK_SENTINEL } from "./common/constants";
import { Edge } from "./edge";
import { GNode, MINIMUM_EDGE_SEPARATION, NODE_INPUT_WIDTH, MINIMUM_NODE_OUTPUT_APPROACH, DEFAULT_NODE_BUBBLE_RADIUS } from "./node";
import { Graph } from "./graph";
const DEFAULT_NODE_ROW_SEPARATION = 150;
......
......@@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import { GraphView } from "../src/graph-view";
import { ScheduleView } from "../src/schedule-view";
import { SequenceView } from "../src/sequence-view";
import { SourceResolver } from "../src/source-resolver";
import { SelectionBroker } from "../src/selection-broker";
import { View, PhaseView } from "../src/view";
import { GraphView } from "./views/graph-view";
import { ScheduleView } from "./views/schedule-view";
import { SequenceView } from "./views/sequence-view";
import { SourceResolver } from "./source-resolver";
import { SelectionBroker } from "./selection/selection-broker";
import { View, PhaseView } from "./views/view";
import { GNode } from "./node";
const multiviewID = "multiview";
......
......@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import { Edge } from "../src/edge";
import { Edge } from "./edge";
import { NodeLabel } from "./node-label";
import { MAX_RANK_SENTINEL } from "./constants";
import { alignUp, measureText } from "./util";
import { MAX_RANK_SENTINEL } from "./common/constants";
import { alignUp, measureText } from "./common/util";
export const DEFAULT_NODE_BUBBLE_RADIUS = 12;
export const NODE_INPUT_WIDTH = 50;
......
......@@ -3,7 +3,7 @@
// found in the LICENSE file.
import * as d3 from "d3";
import * as C from "../src/constants";
import * as C from "./common/constants";
class Snapper {
resizer: Resizer;
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import { SourceResolver, sourcePositionValid } from "../src/source-resolver";
import { ClearableHandler, SelectionHandler, NodeSelectionHandler, BlockSelectionHandler, InstructionSelectionHandler, RegisterAllocationSelectionHandler } from "../src/selection-handler";
import { SourceResolver, sourcePositionValid } from "../source-resolver";
import { ClearableHandler, SelectionHandler, NodeSelectionHandler, BlockSelectionHandler, InstructionSelectionHandler, RegisterAllocationSelectionHandler } from "./selection-handler";
export class SelectionBroker {
sourceResolver: SourceResolver;
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import { GNode } from "./node";
import { GNode } from "../node";
export class MySelection {
selection: any;
......@@ -45,8 +45,8 @@ export class MySelection {
return this.selection.has(key);
}
selectedKeys() {
const result = new Set();
selectedKeys(): Set<string> {
const result = new Set<string>();
for (const i of this.selection.keys()) {
result.add(i);
}
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import { sortUnique, anyToString } from "../src/util";
import { sortUnique, anyToString } from "./common/util";
import { NodeLabel } from "./node-label";
function sourcePositionLe(a, b) {
......
// Copyright 2022 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.
export class Tabs {
private container: HTMLElement;
......
......@@ -2,15 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import { SourceResolver } from "../src/source-resolver";
import { SelectionBroker } from "../src/selection-broker";
import { DisassemblyView } from "../src/disassembly-view";
import { GraphMultiView } from "../src/graphmultiview";
import { CodeMode, CodeView } from "../src/code-view";
import { Tabs } from "../src/tabs";
import { Resizer } from "../src/resizer";
import * as C from "../src/constants";
import { InfoView } from "./info-view";
import * as C from "./common/constants";
import { SourceResolver } from "./source-resolver";
import { SelectionBroker } from "./selection/selection-broker";
import { DisassemblyView } from "./views/disassembly-view";
import { GraphMultiView } from "./graphmultiview";
import { CodeMode, CodeView } from "./views/code-view";
import { Tabs } from "./tabs";
import { Resizer } from "./resizer";
import { InfoView } from "./views/info-view";
window.onload = function () {
let multiview: GraphMultiView = null;
......
......@@ -10,12 +10,12 @@ declare global {
const PR: PR;
}
import { Source, SourceResolver, sourcePositionToStringKey } from "../src/source-resolver";
import { SelectionBroker } from "../src/selection-broker";
import { View } from "../src/view";
import { MySelection } from "../src/selection";
import { ViewElements } from "../src/util";
import { SelectionHandler } from "./selection-handler";
import { Source, SourceResolver, sourcePositionToStringKey } from "../source-resolver";
import { SelectionBroker } from "../selection/selection-broker";
import { View } from "./view";
import { MySelection } from "../selection/selection";
import { ViewElements } from "../common/view-elements";
import { SelectionHandler } from "../selection/selection-handler";
export enum CodeMode {
MAIN_SOURCE = "main function",
......
......@@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import { PROF_COLS, UNICODE_BLOCK } from "../src/constants";
import { SelectionBroker } from "../src/selection-broker";
import { TextView } from "../src/text-view";
import { MySelection } from "./selection";
import { anyToString, interpolate } from "./util";
import { InstructionSelectionHandler } from "./selection-handler";
import { PROF_COLS, UNICODE_BLOCK } from "../common/constants";
import { SelectionBroker } from "../selection/selection-broker";
import { TextView } from "./text-view";
import { MySelection } from "../selection/selection";
import { anyToString, interpolate } from "../common/util";
import { InstructionSelectionHandler } from "../selection/selection-handler";
const toolboxHTML = `<div id="disassembly-toolbox">
<form>
......
......@@ -3,17 +3,17 @@
// found in the LICENSE file.
import * as d3 from "d3";
import { layoutNodeGraph } from "../src/graph-layout";
import { GNode, nodeToStr } from "../src/node";
import { NODE_INPUT_WIDTH } from "../src/node";
import { DEFAULT_NODE_BUBBLE_RADIUS } from "../src/node";
import { Edge, edgeToStr } from "../src/edge";
import { PhaseView } from "../src/view";
import { MySelection } from "../src/selection";
import { partial } from "../src/util";
import { NodeSelectionHandler, ClearableHandler } from "./selection-handler";
import { Graph } from "./graph";
import { SelectionBroker } from "./selection-broker";
import { layoutNodeGraph } from "../graph-layout";
import { GNode, nodeToStr } from "../node";
import { NODE_INPUT_WIDTH } from "../node";
import { DEFAULT_NODE_BUBBLE_RADIUS } from "../node";
import { Edge, edgeToStr } from "../edge";
import { PhaseView } from "./view";
import { MySelection } from "../selection/selection";
import { partial } from "../common/util";
import { NodeSelectionHandler, ClearableHandler } from "../selection/selection-handler";
import { Graph } from "../graph";
import { SelectionBroker } from "../selection/selection-broker";
function nodeToStringKey(n: GNode) {
return "" + n.id;
......
......@@ -2,9 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import { createElement } from "../src/util";
import { SequenceView } from "../src/sequence-view";
import { RegisterAllocation, Range, ChildRange, Interval } from "../src/source-resolver";
import { createElement } from "../common/util";
import { SequenceView } from "./sequence-view";
import { RegisterAllocation, Range, ChildRange, Interval } from "../source-resolver";
class Constants {
// Determines how many rows each div group holds for the purposes of
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import { Schedule, SourceResolver } from "../src/source-resolver";
import { TextView } from "../src/text-view";
import { Schedule, SourceResolver } from "../source-resolver";
import { TextView } from "./text-view";
export class ScheduleView extends TextView {
schedule: Schedule;
......
......@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import { Sequence } from "../src/source-resolver";
import { createElement } from "../src/util";
import { TextView } from "../src/text-view";
import { RangeView } from "../src/range-view";
import { Sequence } from "../source-resolver";
import { createElement } from "../common/util";
import { TextView } from "./text-view";
import { RangeView } from "./range-view";
export class SequenceView extends TextView {
sequence: Sequence;
......
......@@ -2,12 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import { PhaseView } from "../src/view";
import { anyToString, ViewElements, isIterable } from "../src/util";
import { MySelection } from "../src/selection";
import { SourceResolver } from "./source-resolver";
import { SelectionBroker } from "./selection-broker";
import { NodeSelectionHandler, BlockSelectionHandler, RegisterAllocationSelectionHandler } from "./selection-handler";
import { PhaseView } from "./view";
import { anyToString, isIterable } from "../common/util";
import { MySelection } from "../selection/selection";
import { SourceResolver } from "../source-resolver";
import { SelectionBroker } from "../selection/selection-broker";
import { NodeSelectionHandler, BlockSelectionHandler, RegisterAllocationSelectionHandler } from "../selection/selection-handler";
import { ViewElements } from "../common/view-elements";
export abstract class TextView extends PhaseView {
selectionHandler: NodeSelectionHandler;
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import { GNode } from "./node";
import { GNode } from "../node";
export abstract class View {
protected container: HTMLElement;
......
......@@ -2,8 +2,8 @@
"compilerOptions": {
"outDir": "build/",
"allowJs": false,
"target": "es2018",
"module": "es2015",
"target": "es2021",
"module": "es2020",
"sourceMap": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
......@@ -11,29 +11,30 @@
"noUnusedLocals": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"lib": ["dom", "es6", "dom.iterable", "scripthost", "es2018"]
"lib": ["es2020", "es2021", "dom", "dom.iterable", "scripthost"]
},
"files": [
"src/util.ts",
"src/common/util.ts",
"src/common/constants.ts",
"src/common/view-elements.ts",
"src/selection/selection.ts",
"src/selection/selection-broker.ts",
"src/selection/selection-handler.ts",
"src/views/view.ts",
"src/views/code-view.ts",
"src/views/graph-view.ts",
"src/views/schedule-view.ts",
"src/views/disassembly-view.ts",
"src/views/text-view.ts",
"src/views/info-view.ts",
"src/node.ts",
"src/edge.ts",
"src/graph.ts",
"src/node-label.ts",
"src/source-resolver.ts",
"src/selection.ts",
"src/selection-broker.ts",
"src/selection-handler.ts",
"src/constants.ts",
"src/view.ts",
"src/text-view.ts",
"src/code-view.ts",
"src/graph-layout.ts",
"src/graph-view.ts",
"src/schedule-view.ts",
"src/disassembly-view.ts",
"src/graphmultiview.ts",
"src/turbo-visualizer.ts",
"src/resizer.ts",
"src/info-view.ts"
"src/resizer.ts"
]
}
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