1// Copyright 2019 the V8 project authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5function formatOrigin(origin) { 6 if (origin.nodeId) { 7 return `#${origin.nodeId} in phase ${origin.phase}/${origin.reducer}`; 8 } 9 if (origin.bytecodePosition) { 10 return `Bytecode line ${origin.bytecodePosition} in phase ${origin.phase}/${origin.reducer}`; 11 } 12 return "unknown origin"; 13} 14 15export class NodeLabel { 16 id: number; 17 label: string; 18 title: string; 19 live: boolean; 20 properties: string; 21 sourcePosition: any; 22 origin: any; 23 opcode: string; 24 control: boolean; 25 opinfo: string; 26 type: string; 27 inplaceUpdatePhase: string; 28 29 constructor(id: number, label: string, title: string, live: boolean, properties: string, sourcePosition: any, origin: any, opcode: string, control: boolean, opinfo: string, type: string) { 30 this.id = id; 31 this.label = label; 32 this.title = title; 33 this.live = live; 34 this.properties = properties; 35 this.sourcePosition = sourcePosition; 36 this.origin = origin; 37 this.opcode = opcode; 38 this.control = control; 39 this.opinfo = opinfo; 40 this.type = type; 41 this.inplaceUpdatePhase = null; 42 } 43 44 equals(that?: NodeLabel) { 45 if (!that) return false; 46 if (this.id != that.id) return false; 47 if (this.label != that.label) return false; 48 if (this.title != that.title) return false; 49 if (this.live != that.live) return false; 50 if (this.properties != that.properties) return false; 51 if (this.opcode != that.opcode) return false; 52 if (this.control != that.control) return false; 53 if (this.opinfo != that.opinfo) return false; 54 if (this.type != that.type) return false; 55 return true; 56 } 57 58 getTitle() { 59 let propsString = ""; 60 if (this.properties === "") { 61 propsString = "no properties"; 62 } else { 63 propsString = "[" + this.properties + "]"; 64 } 65 let title = this.title + "\n" + propsString + "\n" + this.opinfo; 66 if (this.origin) { 67 title += `\nOrigin: ${formatOrigin(this.origin)}`; 68 } 69 if (this.inplaceUpdatePhase) { 70 title += `\nInplace update in phase: ${this.inplaceUpdatePhase}`; 71 } 72 return title; 73 } 74 75 getDisplayLabel() { 76 const result = `${this.id}: ${this.label}`; 77 if (result.length > 40) { 78 return `${this.id}: ${this.opcode}`; 79 } 80 return result; 81 } 82 83 setInplaceUpdatePhase(name: string): any { 84 this.inplaceUpdatePhase = name; 85 } 86} 87