54
54
}
55
55
56
56
.stats {
57
- font-size: 60%;
57
+ font-size: 60%;
58
58
}
59
59
60
60
table {
@@ -97,6 +97,26 @@ td.collapsed div {
97
97
text-align: right;
98
98
}
99
99
100
+ code, pre, .lines {
101
+ font-family: Menlo, monospace;
102
+ font-size: 12px;
103
+ }
104
+
105
+ .lines {
106
+ float: left;
107
+ overflow: hidden;
108
+ text-align: right;
109
+ }
110
+
111
+ .lines div {
112
+ padding-right: 10px;
113
+ color: gray;
114
+ }
115
+
116
+ div.line-number {
117
+ font-size: 12px;
118
+ }
119
+
100
120
td.ssa-prog {
101
121
width: 600px;
102
122
word-wrap: break-word;
@@ -158,10 +178,14 @@ dd.ssa-prog {
158
178
}
159
179
160
180
.line-number {
161
- font-style: italic;
162
181
font-size: 11px;
163
182
}
164
183
184
+ .no-line-number {
185
+ font-size: 11px;
186
+ color: gray;
187
+ }
188
+
165
189
.highlight-aquamarine { background-color: aquamarine; }
166
190
.highlight-coral { background-color: coral; }
167
191
.highlight-lightpink { background-color: lightpink; }
@@ -235,7 +259,7 @@ for (var i = 0; i < outlines.length; i++) {
235
259
236
260
window.onload = function() {
237
261
var ssaElemClicked = function(elem, event, selections, selected) {
238
- event.stopPropagation()
262
+ event.stopPropagation();
239
263
240
264
// TODO: pushState with updated state and read it on page load,
241
265
// so that state can survive across reloads
@@ -288,11 +312,11 @@ window.onload = function() {
288
312
289
313
var ssaValueClicked = function(event) {
290
314
ssaElemClicked(this, event, highlights, highlighted);
291
- }
315
+ };
292
316
293
317
var ssaBlockClicked = function(event) {
294
318
ssaElemClicked(this, event, outlines, outlined);
295
- }
319
+ };
296
320
297
321
var ssavalues = document.getElementsByClassName("ssa-value");
298
322
for (var i = 0; i < ssavalues.length; i++) {
@@ -311,64 +335,68 @@ window.onload = function() {
311
335
for (var i = 0; i < ssablocks.length; i++) {
312
336
ssablocks[i].addEventListener('click', ssaBlockClicked);
313
337
}
314
- var expandedDefault = [
338
+
339
+ var lines = document.getElementsByClassName("line-number");
340
+ for (var i = 0; i < lines.length; i++) {
341
+ lines[i].addEventListener('click', ssaValueClicked);
342
+ }
343
+
344
+ // Contains phase names which are expanded by default. Other columns are collapsed.
345
+ var expandedDefault = [
315
346
"start",
316
347
"deadcode",
317
348
"opt",
318
349
"lower",
319
350
"late deadcode",
320
351
"regalloc",
321
352
"genssa",
322
- ]
323
- function isExpDefault(id) {
324
- for (var i = 0; i < expandedDefault.length; i++) {
325
- if (id.startsWith(expandedDefault[i])) {
326
- return true;
327
- }
328
- }
329
- return false;
330
- }
353
+ ];
354
+
331
355
function toggler(phase) {
332
356
return function() {
333
357
toggle_cell(phase+'-col');
334
358
toggle_cell(phase+'-exp');
335
359
};
336
360
}
361
+
337
362
function toggle_cell(id) {
338
- var e = document.getElementById(id);
339
- if(e.style.display == 'table-cell')
340
- e.style.display = 'none';
341
- else
342
- e.style.display = 'table-cell';
363
+ var e = document.getElementById(id);
364
+ if (e.style.display == 'table-cell') {
365
+ e.style.display = 'none';
366
+ } else {
367
+ e.style.display = 'table-cell';
368
+ }
343
369
}
344
370
371
+ // Go through all columns and collapse needed phases.
345
372
var td = document.getElementsByTagName("td");
346
373
for (var i = 0; i < td.length; i++) {
347
374
var id = td[i].id;
348
- var def = isExpDefault(id);
349
375
var phase = id.substr(0, id.length-4);
376
+ var show = expandedDefault.indexOf(phase) !== -1
350
377
if (id.endsWith("-exp")) {
351
378
var h2 = td[i].getElementsByTagName("h2");
352
379
if (h2 && h2[0]) {
353
380
h2[0].addEventListener('click', toggler(phase));
354
381
}
355
382
} else {
356
- td[i].addEventListener('click', toggler(phase));
383
+ td[i].addEventListener('click', toggler(phase));
357
384
}
358
- if (id.endsWith("-col") && def || id.endsWith("-exp") && !def ) {
359
- td[i].style.display = 'none';
360
- continue
385
+ if (id.endsWith("-col") && show || id.endsWith("-exp") && !show ) {
386
+ td[i].style.display = 'none';
387
+ continue;
361
388
}
362
389
td[i].style.display = 'table-cell';
363
390
}
364
391
};
365
392
366
393
function toggle_visibility(id) {
367
- var e = document.getElementById(id);
368
- if(e.style.display == 'block')
369
- e.style.display = 'none';
370
- else
371
- e.style.display = 'block';
394
+ var e = document.getElementById(id);
395
+ if (e.style.display == 'block') {
396
+ e.style.display = 'none';
397
+ } else {
398
+ e.style.display = 'block';
399
+ }
372
400
}
373
401
</script>
374
402
@@ -414,6 +442,7 @@ func (w *HTMLWriter) Close() {
414
442
}
415
443
416
444
// WriteFunc writes f in a column headed by title.
445
+ // phase is used for collapsing columns and should be unique across the table.
417
446
func (w * HTMLWriter ) WriteFunc (phase , title string , f * Func ) {
418
447
if w == nil {
419
448
return // avoid generating HTML just to discard it
@@ -422,6 +451,27 @@ func (w *HTMLWriter) WriteFunc(phase, title string, f *Func) {
422
451
// TODO: Add visual representation of f's CFG.
423
452
}
424
453
454
+ // WriteSources writes lines as source code in a column headed by title.
455
+ // phase is used for collapsing columns and should be unique across the table.
456
+ func (w * HTMLWriter ) WriteSources (phase , title string , firstLineno uint , lines []string ) {
457
+ if w == nil {
458
+ return // avoid generating HTML just to discard it
459
+ }
460
+ var buf bytes.Buffer
461
+ fmt .Fprint (& buf , "<div class=\" lines\" style=\" width: 8%\" >" )
462
+ for i , _ := range lines {
463
+ ln := int (firstLineno ) + i
464
+ fmt .Fprintf (& buf , "<div class=\" l%v line-number\" >%v</div>" , ln , ln )
465
+ }
466
+ fmt .Fprint (& buf , "</div><div style=\" width: 92%\" ><pre>" )
467
+ for i , l := range lines {
468
+ ln := int (firstLineno ) + i
469
+ fmt .Fprintf (& buf , "<div class=\" l%v line-number\" >%v</div>" , ln , html .EscapeString (l ))
470
+ }
471
+ fmt .Fprint (& buf , "</pre></div>" )
472
+ w .WriteColumn (phase , title , "" , buf .String ())
473
+ }
474
+
425
475
// WriteColumn writes raw HTML in a column headed by title.
426
476
// It is intended for pre- and post-compilation log output.
427
477
func (w * HTMLWriter ) WriteColumn (phase , title , class , html string ) {
@@ -470,9 +520,9 @@ func (v *Value) LongHTML() string {
470
520
// maybe we could replace some of that with formatting.
471
521
s := fmt .Sprintf ("<span class=\" %s ssa-long-value\" >" , v .String ())
472
522
473
- linenumber := "<span class=\" line-number\" >(?)</span>"
523
+ linenumber := "<span class=\" no- line-number\" >(?)</span>"
474
524
if v .Pos .IsKnown () {
475
- linenumber = fmt .Sprintf ("<span class=\" line-number\" >(%s)</span>" , v .Pos .LineNumberHTML ())
525
+ linenumber = fmt .Sprintf ("<span class=\" l%v line-number\" >(%s)</span>" , v . Pos . LineNumber () , v .Pos .LineNumberHTML ())
476
526
}
477
527
478
528
s += fmt .Sprintf ("%s %s = %s" , v .HTML (), linenumber , v .Op .String ())
@@ -536,7 +586,7 @@ func (b *Block) LongHTML() string {
536
586
if b .Pos .IsKnown () {
537
587
// TODO does not begin to deal with the full complexity of line numbers.
538
588
// Maybe we want a string/slice instead, of outer-inner when inlining.
539
- s += fmt .Sprintf (" (line %s)" , b .Pos .LineNumberHTML ())
589
+ s += fmt .Sprintf (" <span class= \" l%v line-number \" >(%s)</span>" , b . Pos . LineNumber () , b .Pos .LineNumberHTML ())
540
590
}
541
591
return s
542
592
}
0 commit comments