OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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 document.onload = (function(d3){ |
| 6 "use strict"; |
| 7 var jsonObj; |
| 8 var sourceExpandClassList = document.getElementById(SOURCE_EXPAND_ID).classLis
t; |
| 9 var sourceCollapseClassList = document.getElementById(SOURCE_COLLAPSE_ID).clas
sList; |
| 10 var sourceExpanded = sourceCollapseClassList.contains(COLLAPSE_PANE_BUTTON_VIS
IBLE); |
| 11 var disassemblyExpandClassList = document.getElementById(DISASSEMBLY_EXPAND_ID
).classList; |
| 12 var disassemblyCollapseClassList = document.getElementById(DISASSEMBLY_COLLAPS
E_ID).classList; |
| 13 var disassemblyExpanded = disassemblyCollapseClassList.contains(COLLAPSE_PANE_
BUTTON_VISIBLE); |
| 14 var svg = null; |
| 15 var graph = null; |
| 16 var schedule = null; |
| 17 var empty = null; |
| 18 var currentPhaseView = null; |
| 19 var disassemblyView = null; |
| 20 var sourceView = null; |
| 21 var selectionBroker = null; |
| 22 |
| 23 function updatePanes() { |
| 24 if (sourceExpanded) { |
| 25 if (disassemblyExpanded) { |
| 26 d3.select("#" + SOURCE_PANE_ID).style(WIDTH, "30%"); |
| 27 d3.select("#" + INTERMEDIATE_PANE_ID).style(WIDTH, "40%"); |
| 28 d3.select("#" + GENERATED_PANE_ID).style(WIDTH, "30%"); |
| 29 } else { |
| 30 d3.select("#" + SOURCE_PANE_ID).style(WIDTH, "50%"); |
| 31 d3.select("#" + INTERMEDIATE_PANE_ID).style(WIDTH, "50%"); |
| 32 d3.select("#" + GENERATED_PANE_ID).style(WIDTH, "0%"); |
| 33 } |
| 34 } else { |
| 35 if (disassemblyExpanded) { |
| 36 d3.select("#" + SOURCE_PANE_ID).style(WIDTH, "0%"); |
| 37 d3.select("#" + INTERMEDIATE_PANE_ID).style(WIDTH, "50%"); |
| 38 d3.select("#" + GENERATED_PANE_ID).style(WIDTH, "50%"); |
| 39 } else { |
| 40 d3.select("#" + SOURCE_PANE_ID).style(WIDTH, "0%"); |
| 41 d3.select("#" + INTERMEDIATE_PANE_ID).style(WIDTH, "100%"); |
| 42 d3.select("#" + GENERATED_PANE_ID).style(WIDTH, "0%"); |
| 43 } |
| 44 } |
| 45 } |
| 46 |
| 47 function setSourceExpanded(newState) { |
| 48 sourceExpanded = newState; |
| 49 updatePanes(); |
| 50 if (newState) { |
| 51 sourceCollapseClassList.add(COLLAPSE_PANE_BUTTON_VISIBLE); |
| 52 sourceCollapseClassList.remove(COLLAPSE_PANE_BUTTON_INVISIBLE); |
| 53 sourceExpandClassList.add(COLLAPSE_PANE_BUTTON_INVISIBLE); |
| 54 sourceExpandClassList.remove(COLLAPSE_PANE_BUTTON_VISIBLE); |
| 55 } else { |
| 56 sourceCollapseClassList.add(COLLAPSE_PANE_BUTTON_INVISIBLE); |
| 57 sourceCollapseClassList.remove(COLLAPSE_PANE_BUTTON_VISIBLE); |
| 58 sourceExpandClassList.add(COLLAPSE_PANE_BUTTON_VISIBLE); |
| 59 sourceExpandClassList.remove(COLLAPSE_PANE_BUTTON_INVISIBLE); |
| 60 } |
| 61 } |
| 62 |
| 63 function setDisassemblyExpanded(newState) { |
| 64 disassemblyExpanded = newState; |
| 65 updatePanes(); |
| 66 if (newState) { |
| 67 disassemblyCollapseClassList.add(COLLAPSE_PANE_BUTTON_VISIBLE); |
| 68 disassemblyCollapseClassList.remove(COLLAPSE_PANE_BUTTON_INVISIBLE); |
| 69 disassemblyExpandClassList.add(COLLAPSE_PANE_BUTTON_INVISIBLE); |
| 70 disassemblyExpandClassList.remove(COLLAPSE_PANE_BUTTON_VISIBLE); |
| 71 } else { |
| 72 disassemblyCollapseClassList.add(COLLAPSE_PANE_BUTTON_INVISIBLE); |
| 73 disassemblyCollapseClassList.remove(COLLAPSE_PANE_BUTTON_VISIBLE); |
| 74 disassemblyExpandClassList.add(COLLAPSE_PANE_BUTTON_VISIBLE); |
| 75 disassemblyExpandClassList.remove(COLLAPSE_PANE_BUTTON_INVISIBLE); |
| 76 } |
| 77 } |
| 78 |
| 79 function hideCurrentPhase() { |
| 80 var rememberedSelection = null; |
| 81 if (currentPhaseView != null) { |
| 82 rememberedSelection = currentPhaseView.detachSelection(); |
| 83 currentPhaseView.hide(); |
| 84 currentPhaseView = null; |
| 85 } |
| 86 return rememberedSelection; |
| 87 } |
| 88 |
| 89 function displayPhaseView(view, data) { |
| 90 var rememberedSelection = hideCurrentPhase(); |
| 91 view.show(data, rememberedSelection); |
| 92 d3.select("#middle").classed("scrollable", view.isScrollable()); |
| 93 currentPhaseView = view; |
| 94 } |
| 95 |
| 96 function displayPhase(phase) { |
| 97 if (phase.type == 'graph') { |
| 98 displayPhaseView(graph, phase.data); |
| 99 } else if (phase.type == 'schedule') { |
| 100 displayPhaseView(schedule, phase.data); |
| 101 } else { |
| 102 displayPhaseView(empty, null); |
| 103 } |
| 104 } |
| 105 |
| 106 function fitPanesToParents() { |
| 107 d3.select("#left").classed("scrollable", false) |
| 108 d3.select("#right").classed("scrollable", false); |
| 109 |
| 110 graph.fitGraphViewToWindow(); |
| 111 disassemblyView.resizeToParent(); |
| 112 sourceView.resizeToParent(); |
| 113 |
| 114 d3.select("#left").classed("scrollable", true); |
| 115 d3.select("#right").classed("scrollable", true); |
| 116 } |
| 117 |
| 118 selectionBroker = new SelectionBroker(); |
| 119 |
| 120 function initializeHandlers(g) { |
| 121 d3.select("#source-expand").on("click", function(){ |
| 122 setSourceExpanded(true); |
| 123 setTimeout(function(){ |
| 124 g.fitGraphViewToWindow(); |
| 125 }, 1000); |
| 126 }); |
| 127 d3.select("#source-shrink").on("click", function(){ |
| 128 setSourceExpanded(false); |
| 129 setTimeout(function(){ |
| 130 g.fitGraphViewToWindow(); |
| 131 }, 1000); |
| 132 }); |
| 133 d3.select("#disassembly-expand").on("click", function(){ |
| 134 setDisassemblyExpanded(true); |
| 135 setTimeout(function(){ |
| 136 g.fitGraphViewToWindow(); |
| 137 }, 1000); |
| 138 }); |
| 139 d3.select("#disassembly-shrink").on("click", function(){ |
| 140 setDisassemblyExpanded(false); |
| 141 setTimeout(function(){ |
| 142 g.fitGraphViewToWindow(); |
| 143 }, 1000); |
| 144 }); |
| 145 window.onresize = function(){ |
| 146 fitPanesToParents(); |
| 147 }; |
| 148 d3.select("#hidden-file-upload").on("change", function() { |
| 149 if (window.File && window.FileReader && window.FileList) { |
| 150 var uploadFile = this.files[0]; |
| 151 var filereader = new window.FileReader(); |
| 152 var consts = Node.consts; |
| 153 filereader.onload = function(){ |
| 154 var txtRes = filereader.result; |
| 155 // If the JSON isn't properly terminated, assume compiler crashed and |
| 156 // add best-guess empty termination |
| 157 if (txtRes[txtRes.length-2] == ',') { |
| 158 txtRes += '{"name":"disassembly","type":"disassembly","data":""}]}'; |
| 159 } |
| 160 try{ |
| 161 jsonObj = JSON.parse(txtRes); |
| 162 |
| 163 sourceView.initializeCode(jsonObj.source, jsonObj.sourcePosition); |
| 164 schedule.setNodePositionMap(jsonObj.nodePositions); |
| 165 |
| 166 var selectMenu = document.getElementById('display-selector'); |
| 167 var disassemblyPhase = null; |
| 168 selectMenu.innerHTML = ''; |
| 169 for (var i = 0; i < jsonObj.phases.length; ++i) { |
| 170 var optionElement = document.createElement("option"); |
| 171 optionElement.text = jsonObj.phases[i].name; |
| 172 if (optionElement.text == 'disassembly') { |
| 173 disassemblyPhase = jsonObj.phases[i]; |
| 174 } else { |
| 175 selectMenu.add(optionElement, null); |
| 176 } |
| 177 } |
| 178 disassemblyView.setNodePositionMap(jsonObj.nodePositions); |
| 179 disassemblyView.show(disassemblyPhase.data, null); |
| 180 |
| 181 displayPhase(jsonObj.phases[0]); |
| 182 |
| 183 selectMenu.onchange = function(item) { |
| 184 displayPhase(jsonObj.phases[selectMenu.selectedIndex]); |
| 185 } |
| 186 |
| 187 fitPanesToParents(); |
| 188 } |
| 189 catch(err) { |
| 190 window.alert("Invalid TurboFan JSON file\n" + |
| 191 "error: " + err.message); |
| 192 return; |
| 193 } |
| 194 }; |
| 195 filereader.readAsText(uploadFile); |
| 196 } else { |
| 197 alert("Can't load graph"); |
| 198 } |
| 199 }); |
| 200 } |
| 201 |
| 202 sourceView = new CodeView(SOURCE_PANE_ID, PR, "", 0, selectionBroker); |
| 203 disassemblyView = new DisassemblyView(DISASSEMBLY_PANE_ID, selectionBroker); |
| 204 graph = new GraphView(d3, GRAPH_PANE_ID, [], [], selectionBroker); |
| 205 schedule = new ScheduleView(SCHEDULE_PANE_ID, selectionBroker); |
| 206 empty = new EmptyView(EMPTY_PANE_ID, selectionBroker); |
| 207 |
| 208 initializeHandlers(graph); |
| 209 |
| 210 setSourceExpanded(true); |
| 211 setDisassemblyExpanded(false); |
| 212 |
| 213 displayPhaseView(empty, null); |
| 214 fitPanesToParents(); |
| 215 })(window.d3); |
OLD | NEW |