[turbolizer] Reduce number of TypeScript errors
Bug: v8:7327 Notry: true Change-Id: Ia1c2164269d3d656b951d46debe42a811a6d9c89 Reviewed-on: https://chromium-review.googlesource.com/c/1386494 Reviewed-by: Georg Neis <neis@chromium.org> Commit-Queue: Sigurd Schneider <sigurds@chromium.org> Cr-Commit-Position: refs/heads/master@{#58421}
This commit is contained in:
parent
f62e8cde44
commit
f55b2d88da
@ -5,8 +5,22 @@
|
||||
import typescript from 'rollup-plugin-typescript2';
|
||||
import node from 'rollup-plugin-node-resolve';
|
||||
|
||||
import path from 'path'
|
||||
|
||||
const onwarn = 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
|
||||
}
|
||||
|
||||
console.warn(`(!) ${warning.message}`)
|
||||
}
|
||||
|
||||
export default {
|
||||
input: "src/turbo-visualizer.ts",
|
||||
plugins: [node(), typescript({abortOnError:false})],
|
||||
output: {file: "build/turbolizer.js", format: "iife", sourcemap: true}
|
||||
output: {file: "build/turbolizer.js", format: "iife", sourcemap: true},
|
||||
onwarn: onwarn
|
||||
};
|
||||
|
@ -7,6 +7,7 @@ import { SelectionBroker } from "../src/selection-broker"
|
||||
import { View } from "../src/view"
|
||||
import { MySelection } from "../src/selection"
|
||||
import { anyToString, ViewElements } from "../src/util"
|
||||
import { SelectionHandler } from "./selection-handler";
|
||||
|
||||
export enum CodeMode {
|
||||
MAIN_SOURCE = "main function",
|
||||
|
@ -8,6 +8,7 @@ import { TextView } from "../src/text-view"
|
||||
import { SourceResolver } from "./source-resolver";
|
||||
import { MySelection } from "./selection";
|
||||
import { anyToString } from "./util";
|
||||
import { InstructionSelectionHandler } from "./selection-handler";
|
||||
|
||||
export class DisassemblyView extends TextView {
|
||||
SOURCE_POSITION_HEADER_REGEX: any;
|
||||
@ -63,13 +64,6 @@ export class DisassemblyView extends TextView {
|
||||
};
|
||||
const BLOCK_HEADER_STYLE = {
|
||||
css: ['com', 'block'],
|
||||
block_id: null,
|
||||
blockId: function (text) {
|
||||
let matches = /\d+/.exec(text);
|
||||
if (!matches) return undefined;
|
||||
BLOCK_HEADER_STYLE.block_id = Number(matches[0]);
|
||||
return BLOCK_HEADER_STYLE.block_id;
|
||||
},
|
||||
associateData: function (text, fragment) {
|
||||
let matches = /\d+/.exec(text);
|
||||
if (!matches) return;
|
||||
|
@ -12,6 +12,7 @@ import { Edge, edgeToStr } from "../src/edge"
|
||||
import { View, PhaseView } from "../src/view"
|
||||
import { MySelection } from "../src/selection"
|
||||
import { partial, alignUp } from "../src/util"
|
||||
import { NodeSelectionHandler, ClearableHandler } from "./selection-handler";
|
||||
|
||||
function nodeToStringKey(n) {
|
||||
return "" + n.id;
|
||||
@ -34,7 +35,7 @@ export class GraphView extends View implements PhaseView {
|
||||
state: GraphState;
|
||||
nodes: Array<GNode>;
|
||||
edges: Array<any>;
|
||||
selectionHandler: NodeSelectionHandler;
|
||||
selectionHandler: NodeSelectionHandler&ClearableHandler;
|
||||
graphElement: d3.Selection<any, any, any, any>;
|
||||
visibleNodes: d3.Selection<any, GNode, any, any>;
|
||||
visibleEdges: d3.Selection<any, Edge, any, any>;
|
||||
@ -285,12 +286,14 @@ export class GraphView extends View implements PhaseView {
|
||||
};
|
||||
|
||||
measureText(text) {
|
||||
const textMeasure = document.getElementById('text-measure') as SVGTSpanElement;
|
||||
textMeasure.textContent = text;
|
||||
return {
|
||||
width: textMeasure.getBBox().width,
|
||||
height: textMeasure.getBBox().height,
|
||||
};
|
||||
const textMeasure = document.getElementById('text-measure');
|
||||
if (textMeasure instanceof SVGTSpanElement) {
|
||||
textMeasure.textContent = text;
|
||||
return {
|
||||
width: textMeasure.getBBox().width,
|
||||
height: textMeasure.getBBox().height,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
createGraph(data, rememberedSelection) {
|
||||
|
@ -74,7 +74,10 @@ export class GraphMultiView extends View {
|
||||
view.selectMenu.innerHTML = '';
|
||||
view.sourceResolver.forEachPhase((phase) => {
|
||||
const optionElement = document.createElement("option");
|
||||
const maxNodeId = phase.highestNodeId == 0 ? "" : ` ${phase.highestNodeId}`;
|
||||
let maxNodeId = "";
|
||||
if (phase.type == "graph" && phase.highestNodeId != 0) {
|
||||
maxNodeId = ` ${phase.highestNodeId}`;
|
||||
}
|
||||
optionElement.text = `${phase.name}${maxNodeId}`;
|
||||
view.selectMenu.add(optionElement);
|
||||
});
|
||||
|
@ -2,7 +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 { SourceResolver, sourcePositionValid } from "../src/source-resolver"
|
||||
import { ClearableHandler, SelectionHandler, NodeSelectionHandler, BlockSelectionHandler, InstructionSelectionHandler } from "../src/selection-handler"
|
||||
|
||||
export class SelectionBroker {
|
||||
sourceResolver: SourceResolver;
|
||||
@ -21,22 +22,22 @@ export class SelectionBroker {
|
||||
this.sourceResolver = sourceResolver;
|
||||
};
|
||||
|
||||
addSourcePositionHandler(handler: SelectionHandler&ClearableHandler) {
|
||||
addSourcePositionHandler(handler: SelectionHandler & ClearableHandler) {
|
||||
this.allHandlers.push(handler);
|
||||
this.sourcePositionHandlers.push(handler);
|
||||
}
|
||||
|
||||
addNodeHandler(handler: NodeSelectionHandler&ClearableHandler) {
|
||||
addNodeHandler(handler: NodeSelectionHandler & ClearableHandler) {
|
||||
this.allHandlers.push(handler);
|
||||
this.nodeHandlers.push(handler);
|
||||
}
|
||||
|
||||
addBlockHandler(handler: BlockSelectionHandler&ClearableHandler) {
|
||||
addBlockHandler(handler: BlockSelectionHandler & ClearableHandler) {
|
||||
this.allHandlers.push(handler);
|
||||
this.blockHandlers.push(handler);
|
||||
}
|
||||
|
||||
addInstructionHandler(handler: InstructionSelectionHandler&ClearableHandler) {
|
||||
addInstructionHandler(handler: InstructionSelectionHandler & ClearableHandler) {
|
||||
this.allHandlers.push(handler);
|
||||
this.instructionHandlers.push(handler);
|
||||
}
|
||||
|
@ -2,29 +2,29 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
interface ClearableHandler {
|
||||
export interface ClearableHandler {
|
||||
brokeredClear(): void;
|
||||
}
|
||||
|
||||
interface SelectionHandler {
|
||||
export interface SelectionHandler {
|
||||
clear(): void;
|
||||
select(nodeIds: any, selected: any): void;
|
||||
brokeredSourcePositionSelect(sourcePositions: any, selected: any): void;
|
||||
};
|
||||
|
||||
interface NodeSelectionHandler {
|
||||
export interface NodeSelectionHandler {
|
||||
clear(): void;
|
||||
select(nodeIds: any, selected: any): void;
|
||||
brokeredNodeSelect(nodeIds: any, selected: any): void;
|
||||
};
|
||||
|
||||
interface BlockSelectionHandler {
|
||||
export interface BlockSelectionHandler {
|
||||
clear(): void;
|
||||
select(nodeIds: any, selected: any): void;
|
||||
brokeredBlockSelect(blockIds: any, selected: any): void;
|
||||
};
|
||||
|
||||
interface InstructionSelectionHandler {
|
||||
export interface InstructionSelectionHandler {
|
||||
clear(): void;
|
||||
select(instructionIds: any, selected: any): void;
|
||||
brokeredInstructionSelect(instructionIds: any, selected: any): void;
|
||||
|
@ -61,17 +61,36 @@ export interface Source {
|
||||
sourceText: string;
|
||||
sourceId: number;
|
||||
startPosition?: number;
|
||||
backwardsCompatibility: boolean;
|
||||
}
|
||||
interface Inlining {
|
||||
inliningPosition: SourcePosition;
|
||||
sourceId: number;
|
||||
}
|
||||
interface Phase {
|
||||
type: string;
|
||||
interface OtherPhase {
|
||||
type: "disassembly"|"sequence"|"schedule";
|
||||
name: string;
|
||||
data: any;
|
||||
}
|
||||
|
||||
interface InstructionsPhase {
|
||||
type: "instructions";
|
||||
name: string;
|
||||
data: any;
|
||||
instructionOffsetToPCOffset: any;
|
||||
blockIdtoInstructionRange: any;
|
||||
nodeIdToInstructionRange: any;
|
||||
}
|
||||
|
||||
interface GraphPhase {
|
||||
type: "graph";
|
||||
name: string;
|
||||
data: any;
|
||||
highestNodeId: number;
|
||||
}
|
||||
|
||||
type Phase = GraphPhase | InstructionsPhase | OtherPhase;
|
||||
|
||||
export interface Schedule {
|
||||
nodes: Array<any>;
|
||||
}
|
||||
@ -301,7 +320,7 @@ export class SourceResolver {
|
||||
return inliningStack;
|
||||
}
|
||||
|
||||
recordOrigins(phase) {
|
||||
recordOrigins(phase:GraphPhase) {
|
||||
if (phase.type != "graph") return;
|
||||
for (const node of phase.data.nodes) {
|
||||
phase.highestNodeId = Math.max(phase.highestNodeId, node.id)
|
||||
@ -349,7 +368,7 @@ export class SourceResolver {
|
||||
if (!this.pcOffsetToInstructions.has(offset)) {
|
||||
this.pcOffsetToInstructions.set(offset, []);
|
||||
}
|
||||
this.pcOffsetToInstructions.get(offset).push(instruction);
|
||||
this.pcOffsetToInstructions.get(offset).push(Number(instruction));
|
||||
}
|
||||
this.pcOffsets = Array.from(this.pcOffsetToInstructions.keys()).sort((a, b) => b - a);
|
||||
}
|
||||
@ -417,7 +436,6 @@ export class SourceResolver {
|
||||
|
||||
parsePhases(phases) {
|
||||
for (const [phaseId, phase] of Object.entries<Phase>(phases)) {
|
||||
phase.highestNodeId = 0;
|
||||
if (phase.type == 'disassembly') {
|
||||
this.disassemblyPhase = phase;
|
||||
} else if (phase.type == 'schedule') {
|
||||
@ -437,9 +455,10 @@ export class SourceResolver {
|
||||
this.readInstructionOffsetToPCOffset(phase.instructionOffsetToPCOffset);
|
||||
}
|
||||
} else {
|
||||
this.phases.push(phase);
|
||||
this.recordOrigins(phase);
|
||||
this.phaseNames.set(phase.name, this.phases.length);
|
||||
const graphPhase: GraphPhase = Object.assign({highestNodeId: 0});
|
||||
this.phases.push(graphPhase);
|
||||
this.recordOrigins(graphPhase);
|
||||
this.phaseNames.set(graphPhase.name, this.phases.length);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -456,7 +475,7 @@ export class SourceResolver {
|
||||
return this.phaseNames.get(phaseName);
|
||||
}
|
||||
|
||||
forEachPhase(f) {
|
||||
forEachPhase(f:(value: Phase, index: number, array: Phase[]) => void) {
|
||||
this.phases.forEach(f);
|
||||
}
|
||||
|
||||
|
@ -7,11 +7,11 @@ 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 } from "./selection-handler";
|
||||
|
||||
export abstract class TextView extends View {
|
||||
selectionHandler: NodeSelectionHandler;
|
||||
blockSelectionHandler: BlockSelectionHandler;
|
||||
nodeSelectionHandler: NodeSelectionHandler;
|
||||
selection: MySelection;
|
||||
blockSelection: MySelection;
|
||||
textListNode: HTMLUListElement;
|
||||
@ -183,14 +183,6 @@ export abstract class TextView extends View {
|
||||
let view = this;
|
||||
let fragment = document.createElement("SPAN");
|
||||
|
||||
if (style.blockId != undefined) {
|
||||
const blockId = style.blockId(text);
|
||||
if (blockId != undefined) {
|
||||
fragment.blockId = blockId;
|
||||
this.addHtmlElementForBlockId(blockId, fragment);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof style.link == 'function') {
|
||||
fragment.classList.add('linkable-text');
|
||||
fragment.onmouseup = function (e) {
|
||||
@ -199,19 +191,6 @@ export abstract class TextView extends View {
|
||||
};
|
||||
}
|
||||
|
||||
if (typeof style.nodeId == 'function') {
|
||||
const nodeId = style.nodeId(text);
|
||||
if (nodeId != undefined) {
|
||||
fragment.nodeId = nodeId;
|
||||
this.addHtmlElementForNodeId(nodeId, fragment);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof style.assignBlockId === 'function') {
|
||||
fragment.blockId = style.assignBlockId();
|
||||
this.addNodeIdToBlockId(fragment.nodeId, fragment.blockId);
|
||||
}
|
||||
|
||||
if (typeof style.associateData == 'function') {
|
||||
style.associateData(text, fragment);
|
||||
}
|
||||
|
@ -226,7 +226,7 @@ window.onload = function () {
|
||||
|
||||
const jsonObj = JSON.parse(txtRes);
|
||||
|
||||
let fnc = jsonObj.function;
|
||||
let fnc = Object.assign(jsonObj.function, {backwardsCompatibility: false});
|
||||
// Backwards compatibility.
|
||||
if (typeof fnc == 'string') {
|
||||
fnc = {
|
||||
|
Loading…
Reference in New Issue
Block a user