Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Side by Side Diff: tools/turbolizer/disassembly-view.js

Issue 2133663002: [turbolizer] Improve code comments in disassembly (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: [turbolizer] Improve code comments in disassembly Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/turbolizer/code-view.js ('k') | tools/turbolizer/text-view.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 "use strict"; 5 "use strict";
6 6
7 class DisassemblyView extends TextView { 7 class DisassemblyView extends TextView {
8 constructor(id, broker, sortedPositionList) { 8 constructor(id, broker, sortedPositionList) {
9 super(id, broker, null, false); 9 super(id, broker, null, false);
10 this.pos_start = -1; 10 this.pos_start = -1;
11 this.pos_lines = null;
11 let view = this; 12 let view = this;
12 let ADDRESS_STYLE = { 13 let ADDRESS_STYLE = {
13 css: 'tag', 14 css: 'tag',
14 location: function(text) { 15 location: function(text) {
15 ADDRESS_STYLE.last_address = text; 16 ADDRESS_STYLE.last_address = text;
16 return undefined; 17 return undefined;
17 } 18 }
18 }; 19 };
19 let ADDRESS_LINK_STYLE = { 20 let ADDRESS_LINK_STYLE = {
20 css: 'tag', 21 css: 'tag',
(...skipping 17 matching lines...) Expand all
38 } 39 }
39 }; 40 };
40 let OPCODE_STYLE = { 41 let OPCODE_STYLE = {
41 css: 'kwd', 42 css: 'kwd',
42 location: function(text) { 43 location: function(text) {
43 return { 44 return {
44 address: ADDRESS_STYLE.last_address 45 address: ADDRESS_STYLE.last_address
45 }; 46 };
46 } 47 }
47 }; 48 };
49 const BLOCK_HEADER_STYLE = {
50 css: 'com',
51 block_id: -1,
52 location: function(text) {
53 let matches = /\d+/.exec(text);
54 if (!matches) return undefined;
55 BLOCK_HEADER_STYLE.block_id = Number(matches[0]);
56 return {
57 block_id: BLOCK_HEADER_STYLE.block_id
58 };
59 },
60 };
61 const SOURCE_POSITION_HEADER_STYLE = {
62 css: 'com',
63 location: function(text) {
64 let matches = /(\d+):(\d+)/.exec(text);
65 if (!matches) return undefined;
66 let li = Number(matches[1]);
67 if (view.pos_lines === null) return undefined;
68 let pos = view.pos_lines[li-1] + Number(matches[2]);
69 return {
70 pos_start: pos,
71 pos_end: pos + 1
72 };
73 },
74 };
75 view.SOURCE_POSITION_HEADER_REGEX = /^(\s*-- .+:)(\d+:\d+)( --)/;
48 let patterns = [ 76 let patterns = [
49 [ 77 [
50 [/^0x[0-9a-f]{8,16}/, ADDRESS_STYLE, 1], 78 [/^0x[0-9a-f]{8,16}/, ADDRESS_STYLE, 1],
79 [view.SOURCE_POSITION_HEADER_REGEX, SOURCE_POSITION_HEADER_STYLE, -1],
80 [/^\s+-- B\d+ start.*/, BLOCK_HEADER_STYLE, -1],
51 [/^.*/, UNCLASSIFIED_STYLE, -1] 81 [/^.*/, UNCLASSIFIED_STYLE, -1]
52 ], 82 ],
53 [ 83 [
54 [/^\s+\d+\s+[0-9a-f]+\s+/, NUMBER_STYLE, 2], 84 [/^\s+\d+\s+[0-9a-f]+\s+/, NUMBER_STYLE, 2],
55 [/^.*/, null, -1] 85 [/^.*/, null, -1]
56 ], 86 ],
57 [ 87 [
58 [/^\S+\s+/, OPCODE_STYLE, 3], 88 [/^\S+\s+/, OPCODE_STYLE, 3],
59 [/^\S+$/, OPCODE_STYLE, -1], 89 [/^\S+$/, OPCODE_STYLE, -1],
60 [/^.*/, null, -1] 90 [/^.*/, null, -1]
(...skipping 22 matching lines...) Expand all
83 view.setPatterns(patterns); 113 view.setPatterns(patterns);
84 } 114 }
85 115
86 lineLocation(li) { 116 lineLocation(li) {
87 let view = this; 117 let view = this;
88 let result = undefined; 118 let result = undefined;
89 for (let i = 0; i < li.children.length; ++i) { 119 for (let i = 0; i < li.children.length; ++i) {
90 let fragment = li.children[i]; 120 let fragment = li.children[i];
91 let location = fragment.location; 121 let location = fragment.location;
92 if (location != null) { 122 if (location != null) {
123 if (location.block_id != undefined) {
124 if (result === undefined) result = {};
125 result.block_id = location.block_id;
126 }
93 if (location.address != undefined) { 127 if (location.address != undefined) {
94 if (result === undefined) result = {}; 128 if (result === undefined) result = {};
95 result.address = location.address; 129 result.address = location.address;
96 } 130 }
97 if (view.pos_start != -1) { 131 if (location.pos_start != undefined && location.pos_end != undefined) {
132 if (result === undefined) result = {};
133 result.pos_start = location.pos_start;
134 result.pos_end = location.pos_end;
135 }
136 else if (view.pos_start != -1) {
98 if (result === undefined) result = {}; 137 if (result === undefined) result = {};
99 result.pos_start = view.pos_start; 138 result.pos_start = view.pos_start;
100 result.pos_end = result.pos_start + 1; 139 result.pos_end = result.pos_start + 1;
101 } 140 }
102 } 141 }
103 } 142 }
104 return result; 143 return result;
105 } 144 }
145
146 initializeCode(sourceText, sourcePosition) {
147 let view = this;
148 view.pos_lines = new Array();
149 // Comment lines for line 0 include sourcePosition already, only need to
150 // add sourcePosition for lines > 0.
151 view.pos_lines[0] = sourcePosition;
152 if (sourceText != "") {
153 let base = sourcePosition;
154 let current = 0;
155 let source_lines = sourceText.split("\n");
156 for (i=1; i < source_lines.length; i++) {
157 // Add 1 for newline character that is split off.
158 current += source_lines[i-1].length + 1;
159 view.pos_lines[i] = base + current;
160 }
161 }
162 }
163
164 processLine(line) {
165 let view = this;
166 let func = function(match, p1, p2, p3) {
167 let nums = p2.split(":");
168 let li = Number(nums[0]);
169 let pos = Number(nums[1]);
170 if(li === 0)
171 pos -= view.pos_lines[0];
172 li++;
173 return p1 + li + ":" + pos + p3;
174 };
175 line = line.replace(view.SOURCE_POSITION_HEADER_REGEX, func);
176 let fragments = super.processLine(line);
177 return fragments;
178 }
106 } 179 }
OLDNEW
« no previous file with comments | « tools/turbolizer/code-view.js ('k') | tools/turbolizer/text-view.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698