pep8analysis: report fatal crash of the tool
[nit.git] / contrib / pep8analysis / www / index.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>Pep/8 Analysis</title>
5
6 <meta charset="utf-8">
7 <meta http-equiv="X-UA-Compatible" content="IE=edge">
8 <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
9
10 <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
11 <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
12 <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
13
14 <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/codemirror/4.2.0/codemirror.css">
15 <script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/4.2.0/codemirror.min.js"></script>
16 <script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/4.2.0/mode/z80/z80.js"></script>
17
18 <script>
19 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
20 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
21 m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
22 })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
23
24 ga('create', 'UA-574578-5', 'xymus.net');
25 ga('send', 'pageview');
26
27 // Both Viz and Pep8 use emscripten
28 // We put aside the module of each program and bring it back before each use
29 var VizModule = null
30 $(document).ready(function() {
31 // Report full loading
32 $("#loading").hide()
33 $("#analyze").prop('disabled', false)
34
35 });
36
37 function exec() {
38 $("#working").show()
39 // Clean output console
40 $("#console").text("")
41
42 // Get code
43 var input = editor.getValue()
44
45 // Update GA stats
46 ga('trackEvent', 'Action', 'Analyze')
47
48 // Invoke the full Nit program
49 Module = Pep8Module
50 try {
51 ret = Module['callMain']([input])
52 } catch(e) {
53 console.debug("Tool invocation failed, with:\n" + $("#console").text() + "\n" + e )
54 ga('trackEvent', 'Crash', 'Analysis', $("#console").text())
55 $("#fatal-error").show()
56 $("#analyze").prop('disabled', true)
57 }
58
59 // Show and set color of output console
60 $("#consolePanel").removeClass("panel-success panel-warning panel-danger")
61 var analysis = $("#console").text();
62 if (analysis.indexOf("Error") >= 0) {
63 $("#consolePanel").addClass("panel-danger")
64 ga('trackEvent', 'Result', 'Error')
65 }
66 else if (analysis.indexOf("Warning") >= 0) {
67 $("#consolePanel").addClass("panel-warning")
68 ga('trackEvent', 'Result', 'Warning')
69 }
70 else {
71 $("#consolePanel").addClass("panel-success")
72 ga('trackEvent', 'Result', 'Success')
73 }
74 $("#working").hide()
75 $("#consolePanel").show()
76 }
77
78 function load(file) {
79 // Load a sample program
80 $.get('samples/' + file, function(data){
81 editor.setValue(data)
82 })
83 }
84
85 function show_graph(source) {
86 Module = VizModule
87 var res = Viz(source, "svg", "dot")
88 VizModule = Module
89 $("#graph").html(res)
90 }
91 </script>
92 </head>
93 <body>
94
95 <nav class="navbar navbar-default" role="navigation">
96 <div class="container-fluid">
97 <div class="navbar-header">
98 <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
99 <span class="sr-only">Toggle navigation</span>
100 <span class="icon-bar"></span>
101 <span class="icon-bar"></span>
102 <span class="icon-bar"></span>
103 </button>
104 <a class="navbar-brand">Pep/8 Analysis</a>
105 </div>
106
107 <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
108 <ul class="nav navbar-nav">
109 <li class="active"><a>Web interface</a></li>
110 <li><a href="https://github.com/privat/nit/tree/master/contrib/pep8analysis/">Tool source and manual</a></li>
111 </ul>
112 <ul class="nav navbar-nav navbar-right">
113 <li><a href="http://nitlanguage.org/">nitlanguage.org</a></li>
114 <li><a href="https://code.google.com/p/pep8-1/">Pep/8 project</a></li>
115 </ul>
116 </div>
117 </div>
118 </nav>
119
120 <div class="container-fluid">
121 <div class="alert alert-warning" id="loading">Loading the tool... This may take some time.</div>
122 <div class="alert alert-danger" id="fatal-error" style="display: none;">
123 <h2>The JavaScript tool crashed</h2>
124 <p>Please refresh the page to try again, or use Firefox. An error report has been sent to the developer</p>
125 </div>
126
127 <div class="row">
128 <div class="col-sm-12 col-lg-6">
129 <div class="panel panel-default" id="panelIntro">
130 <div class="panel-heading">Description and Usage
131 <button type="button" class="close" onClick="$('#panelIntro').hide()" aria-hidden="true">&times;</button>
132 </div>
133 <div class="panel-body" id="code-panel">
134 <p>This tools finds strange behavior in Pep/8 programs by exploring all detectable execution paths.</p>
135 <p>Upon analyzing a program, this tool reports dead code blocks and data within the execution path. It also detects wrongful use of data such as accessing uninitialized memory, printing a word and reading code.</p>
136 <p><strong>To use:</strong> copy-paste your code in the source code block and launch the analysis using the <em>Analyze program</em> button.</p>
137 </div>
138 </div>
139
140 <div class="panel panel-default">
141 <div class="panel-heading">Pep/8 Source Code</div>
142 <div class="panel-body" id="code-panel">
143 <textarea id="listing"></textarea>
144 <script>
145 var editor = CodeMirror.fromTextArea(listing, {
146 lineNumbers: true,
147 mode: "z80"
148 });
149 editor.setSize("100%", 500);
150 </script>
151
152 <div class="btn-group">
153 <button type="button" class="btn btn-default" id="analyze" onclick="exec();" disabled>Analyze program</button>
154 <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
155 <span class="glyphicon glyphicon-folder-open"></span>
156 Load sample program
157 <span class="caret"></span>
158 </button>
159 <ul class="dropdown-menu">
160 <li><a onclick="load('02-fibo.pep')">fibo.pep - clean program </a></li>
161 <li><a onclick="load('06-calc-non-pur.pep');">calc-non-pur.pep - self rewriting program </a></li>
162 <li><a onclick="load('types.pep');"/>types.pep - strange data manipulation </a></li>
163 <li><a onclick="load('directive-in-code.pep');">directive-in-code.pep - mixed directives and instructions</a></li>
164 </ul>
165 </div>
166 </div>
167 </div>
168 </div>
169
170 <div class="clearfix visible-xs"></div>
171 <div class="col-sm-12 col-lg-6">
172 <div class="alert alert-warning" id="working" style="display: none;">The tool is evaluating all possible execution paths... This may take some time.</div>
173 <div class="panel" id="consolePanel" style="display: none;">
174 <div class="panel-heading">Analysis Result</div>
175 <div class="panel-body">
176 <samp id="console"></samp>
177 <button type="button" class="btn btn-default" onclick="$('#panelGraph').show();$('#panelGraphExp').show();">
178 Show control flow graph</button>
179 <em class="pull-right" id="panelGraphExp" style="display: none;">The graph is at the bottom of the page...</em>
180 </div>
181 </div>
182 </div>
183
184 <div class="col-sm-12 col-lg-6">
185 <div class="panel panel-default" id="panelRef">
186 <div class="panel-heading">Output Documentation
187 <button type="button" class="close" onClick="$('#panelRef').hide()" aria-hidden="true">&times;</button>
188 </div>
189 <div class="panel-body" id="code-panel">
190 <h4>Line and memory references</h4>
191 <p>Shorthand are used in the error messages, some refer directly to the line numbers others to the address in the memory of the running program.</p>
192 <table class="table table-striped">
193 <tr>
194 <th>Shorthand</th>
195 <th>Description</th>
196 </tr><tr>
197 <td>web:5</td>
198 <td>Source line 5</td>
199 </tr><tr>
200 <td>L8</td>
201 <td>Source line 8</td>
202 </tr><tr>
203 <td>rA, rX</td>
204 <td>Registers A, X</td>
205 </tr><tr>
206 <td>m24</td>
207 <td>Memory at address 24 (bytes)</td>
208 </tr><tr>
209 <td>instr@m24</td>
210 <td>Intruction at address 24 (bytes). Usually, this would be the (24/4+1=) 7th instruction, if there is no data blocks. And the 7th line if there is no data blocks or comments.</td>
211 </tr>
212 </table>
213
214 <h4>Common errors and warnings</h4>
215
216 <p>Note that the tool reports <em>possible</em> errors and strange behaviors. For an advanced or expert user, it may raise errors on correct code.</p>
217
218 <table class="table table-striped">
219 <tr>
220 <th>Error</th>
221 <th>Meaning</th>
222 </tr><tr>
223 <td>... the CFG may be wrong</td>
224 <td>The program structure is too complex to analyze. This happens when jumping to dynamic addresses and when using switch statements.</td>
225 </tr><tr>
226 <td>unreachable instructions</td>
227 <td>There's dead code.</td>
228 </tr><tr>
229 <td>data in program flow</td>
230 <td>The program may execute raw data. There's probably a <code>BR</code> missing.</td>
231 </tr><tr>
232 <td>overwriting code at...</td>
233 <td>An instruction writes over an existing instruction (probably your code).</td>
234 </tr><tr>
235 <td>expected "type" in "address", got "something"</td>
236 <td>An instruction uses data with an unexepected type. It may be a <code>CHARO</code> using something other than a char. Or a copy of uninitialized data over an initialized word.<br>
237 </td>
238 </tr>
239 </table>
240 </div>
241 </div>
242 </div>
243 </div>
244
245 <div class="col-sm-12 col-lg-12">
246 <div class="panel panel-default" id="panelGraph" style="display: none;">
247 <div class="panel-heading">Control Flow Graph (CFG)
248 <button type="button" class="close" onClick="$('#panelGraph').hide()" aria-hidden="true">&times;</button>
249 </div>
250 <div class="panel-body">
251 <div id="graph"></div>
252 </div>
253 </div>
254 </div>
255
256 <script>
257 var Module = {
258 'print': function(text) {
259 $("#console").append(text + "<br>")
260 },
261 'noInitialRun': true,
262 'TOTAL_MEMORY': 512000000
263 }
264 </script>
265 <script src="pep8analysis.js"></script>
266 <script>Pep8Module = Module</script>
267 <script src="viz.js"></script>
268 </div>
269
270 </body>
271 </html>