1// Copyright 2015 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 5"use strict"; 6 7class DisassemblyView extends TextView { 8 constructor(id, broker, sortedPositionList) { 9 super(id, broker, null, false); 10 this.pos_start = -1; 11 let view = this; 12 let ADDRESS_STYLE = { 13 css: 'tag', 14 location: function(text) { 15 ADDRESS_STYLE.last_address = text; 16 return undefined; 17 } 18 }; 19 let ADDRESS_LINK_STYLE = { 20 css: 'tag', 21 link: function(text) { 22 view.select(function(location) { return location.address == text; }, true, true); 23 } 24 }; 25 let UNCLASSIFIED_STYLE = { 26 css: 'com' 27 }; 28 let NUMBER_STYLE = { 29 css: 'lit' 30 }; 31 let COMMENT_STYLE = { 32 css: 'com' 33 }; 34 let POSITION_STYLE = { 35 css: 'com', 36 location: function(text) { 37 view.pos_start = Number(text); 38 } 39 }; 40 let OPCODE_STYLE = { 41 css: 'kwd', 42 location: function(text) { 43 return { 44 address: ADDRESS_STYLE.last_address 45 }; 46 } 47 }; 48 let patterns = [ 49 [ 50 [/^0x[0-9a-f]{8,16}/, ADDRESS_STYLE, 1], 51 [/^.*/, UNCLASSIFIED_STYLE, -1] 52 ], 53 [ 54 [/^\s+\d+\s+[0-9a-f]+\s+/, NUMBER_STYLE, 2], 55 [/^.*/, null, -1] 56 ], 57 [ 58 [/^\S+\s+/, OPCODE_STYLE, 3], 59 [/^\S+$/, OPCODE_STYLE, -1], 60 [/^.*/, null, -1] 61 ], 62 [ 63 [/^\s+/, null], 64 [/^[^\(;]+$/, null, -1], 65 [/^[^\(;]+/, null], 66 [/^\(/, null, 4], 67 [/^;/, COMMENT_STYLE, 5] 68 ], 69 [ 70 [/^0x[0-9a-f]{8,16}/, ADDRESS_LINK_STYLE], 71 [/^[^\)]/, null], 72 [/^\)$/, null, -1], 73 [/^\)/, null, 3] 74 ], 75 [ 76 [/^; debug\: position /, COMMENT_STYLE, 6], 77 [/^.+$/, COMMENT_STYLE, -1] 78 ], 79 [ 80 [/^\d+$/, POSITION_STYLE, -1], 81 ] 82 ]; 83 view.setPatterns(patterns); 84 } 85 86 lineLocation(li) { 87 let view = this; 88 let result = undefined; 89 for (let i = 0; i < li.children.length; ++i) { 90 let fragment = li.children[i]; 91 let location = fragment.location; 92 if (location != null) { 93 if (location.address != undefined) { 94 if (result === undefined) result = {}; 95 result.address = location.address; 96 } 97 if (view.pos_start != -1) { 98 if (result === undefined) result = {}; 99 result.pos_start = view.pos_start; 100 result.pos_end = result.pos_start + 1; 101 } 102 } 103 } 104 return result; 105 } 106} 107