update all indirect references to native strings
[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
20 var _gaq = _gaq || [];
21 _gaq.push(['_setAccount', 'UA-574578-5']);
22 _gaq.push(['_trackPageview']);
23
24 (function() {
25 var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
26 ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
27 var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
28 })();
29
30 // Both Viz and Pep8 use emscripten
31 // We put aside the module of each program and bring it back before each use
32 var VizModule = null
33
34 function ready() {
35 $("#loading").hide()
36 $("#analyze").prop('disabled', false)
37 }
38
39 function complete() {
40 // Show and set color of output console
41 $("#consolePanel").removeClass("panel-success panel-warning panel-danger")
42 var analysis = $("#console").text();
43 if (analysis.indexOf("Error") >= 0) {
44 $("#consolePanel").addClass("panel-danger")
45 _gaq.push(['_trackEvent', 'Result', 'Error'])
46 }
47 else if (analysis.indexOf("Warning") >= 0) {
48 $("#consolePanel").addClass("panel-warning")
49 _gaq.push(['_trackEvent', 'Result', 'Warning'])
50 }
51 else {
52 $("#consolePanel").addClass("panel-success")
53 _gaq.push(['_trackEvent', 'Result', 'Success'])
54 }
55 $("#working").hide()
56 $("#consolePanel").show()
57 $("#analyze").prop('disabled', false)
58 }
59
60 function exception(ex) {
61 console.debug("Tool invocation failed, with:\n" + $("#console").text() + "\n" + ex )
62 _gaq.push(['_trackEvent', 'Bug', 'Analysis', $("#console").text()])
63 $("#fatal-error").show()
64 $("#analyze").prop('disabled', true)
65 }
66
67 function stdout(text) {
68 $("#console").append(text + "<br>")
69 }
70
71 function exec() {
72 $("#working").show()
73 $("#consolePanel").hide()
74
75 // Clean output console
76 $("#console").text("")
77
78 // Get code
79 var input = editor.getValue()
80
81 // Update GA stats
82 _gaq.push(['_trackEvent', 'Action', 'Analyze'])
83
84 // Invoke the full Nit program
85 if(typeof(Worker) !== "undefined") {
86 // Async version
87 $("#analyze").prop('disabled', true)
88 worker.postMessage(input)
89 } else {
90 // Sync version
91 _gaq.push(['_trackEvent', 'Bug', 'No Webworkers', $("#console").text()])
92 Module = Pep8Module
93 try {
94 run_analysis = Module.cwrap('pep8analysis_web___CString_run_analysis', null, ['string'])
95 run_analysis(input)
96
97 complete()
98 } catch(e) {
99 exception(e)
100 }
101 }
102 }
103
104 function load(file) {
105 // Load a sample program
106 $.get('samples/' + file, function(data){
107 editor.setValue(data)
108 })
109 }
110
111 function show_graph(source) {
112 Module = VizModule
113 var res = Viz(source, "svg", "dot")
114 VizModule = Module
115 $("#graph").html(res)
116 }
117 </script>
118 </head>
119 <body>
120
121 <nav class="navbar navbar-default" role="navigation">
122 <div class="container-fluid">
123 <div class="navbar-header">
124 <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
125 <span class="sr-only">Toggle navigation</span>
126 <span class="icon-bar"></span>
127 <span class="icon-bar"></span>
128 <span class="icon-bar"></span>
129 </button>
130 <a class="navbar-brand" href="http://xymus.net/">Xymus.net</a>
131 </div>
132
133 <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
134 <ul class="nav navbar-nav">
135 <li><a href="http://xymus.net/ens/">Enseignement</a></li>
136 <li><a href="http://xymus.net/opportunity/"><img height="22px" src="/static/opportunity-small-fr.png"></a></li>
137 <li><a href="http://xymus.net/tnitter/"><img height="22px" src="/static/tnitter-small.png"></a></li>
138 <li class="active"><a href="http://xymus.net/pep8/">Pep/8 Analysis</a></li>
139 <li><a href="http://xymus.net/benitlux/">Benitlux</a></li>
140 </ul>
141
142 <ul class="nav navbar-nav pull-right">
143 <li><a href="https://github.com/nitlang/nit/tree/master/contrib/pep8analysis/">Source and manual</a></li>
144 <li><a href="https://code.google.com/p/pep8-1/">Pep/8 project</a></li>
145 </ul>
146 </div>
147 </div>
148 </nav>
149
150 <div class="container-fluid">
151 <div class="alert alert-warning" id="loading">Loading the tool... This may take some time.</div>
152 <div class="alert alert-danger" id="fatal-error" style="display: none;">
153 <h2>The JavaScript tool crashed</h2>
154 <p>Please refresh the page to try again, or use Firefox. An error report has been sent to the developer</p>
155 </div>
156
157 <div class="row">
158 <div class="col-sm-12 col-lg-6">
159 <div class="panel panel-default" id="panelIntro">
160 <div class="panel-heading">Description and Usage
161 <button type="button" class="close" onClick="$('#panelIntro').hide()" aria-hidden="true">&times;</button>
162 </div>
163 <div class="panel-body" id="code-panel">
164 <p>This tools finds strange behavior in Pep/8 programs by exploring all detectable execution paths.</p>
165 <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>
166 <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>
167 </div>
168 </div>
169
170 <div class="panel panel-default">
171 <div class="panel-heading">Pep/8 Source Code</div>
172 <div class="panel-body" id="code-panel">
173 <textarea id="listing"></textarea>
174 <script>
175 var editor = CodeMirror.fromTextArea(listing, {
176 lineNumbers: true,
177 mode: "z80"
178 });
179 editor.setSize("100%", 500);
180 </script>
181
182 <div class="btn-group">
183 <button type="button" class="btn btn-default" id="analyze" onclick="exec();" disabled>Analyze program</button>
184 <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
185 <span class="glyphicon glyphicon-folder-open"></span>
186 Load sample program
187 <span class="caret"></span>
188 </button>
189 <ul class="dropdown-menu">
190 <li><a onclick="load('02-fibo.pep')">fibo.pep - clean program </a></li>
191 <li><a onclick="load('06-calc-non-pur.pep');">calc-non-pur.pep - self rewriting program </a></li>
192 <li><a onclick="load('types.pep');"/>types.pep - strange data manipulation </a></li>
193 <li><a onclick="load('directive-in-code.pep');">directive-in-code.pep - mixed directives and instructions</a></li>
194 </ul>
195 </div>
196 </div>
197 </div>
198 </div>
199
200 <div class="clearfix visible-xs"></div>
201 <div class="col-sm-12 col-lg-6">
202 <div class="alert alert-warning" id="working" style="display: none;">The tool is evaluating all possible execution paths... This may take some time.</div>
203 <div class="panel" id="consolePanel" style="display: none;">
204 <div class="panel-heading">Analysis Result</div>
205 <div class="panel-body">
206 <samp id="console"></samp>
207 <button type="button" class="btn btn-default" onclick="$('#panelGraph').show();$('#panelGraphExp').show();">
208 Show control flow graph</button>
209 <em class="pull-right" id="panelGraphExp" style="display: none;">The graph is at the bottom of the page...</em>
210 </div>
211 </div>
212 </div>
213
214 <div class="col-sm-12 col-lg-6">
215 <div class="panel panel-default" id="panelRef">
216 <div class="panel-heading">Output Documentation
217 <button type="button" class="close" onClick="$('#panelRef').hide()" aria-hidden="true">&times;</button>
218 </div>
219 <div class="panel-body" id="code-panel">
220 <h4>Line and memory references</h4>
221 <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>
222 <table class="table table-striped">
223 <tr>
224 <th>Shorthand</th>
225 <th>Description</th>
226 </tr><tr>
227 <td>web:5</td>
228 <td>Source line 5</td>
229 </tr><tr>
230 <td>L8</td>
231 <td>Source line 8</td>
232 </tr><tr>
233 <td>rA, rX</td>
234 <td>Registers A, X</td>
235 </tr><tr>
236 <td>m24</td>
237 <td>Memory at address 24 (bytes)</td>
238 </tr><tr>
239 <td>instr@m24</td>
240 <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>
241 </tr>
242 </table>
243
244 <h4>Common errors and warnings</h4>
245
246 <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>
247
248 <table class="table table-striped">
249 <tr>
250 <th>Error</th>
251 <th>Meaning</th>
252 </tr><tr>
253 <td>... the CFG may be wrong</td>
254 <td>The program structure is too complex to analyze. This happens when jumping to dynamic addresses and when using switch statements.</td>
255 </tr><tr>
256 <td>unreachable instructions</td>
257 <td>There's dead code.</td>
258 </tr><tr>
259 <td>data in program flow</td>
260 <td>The program may execute raw data. There's probably a <code>BR</code> missing.</td>
261 </tr><tr>
262 <td>overwriting code at...</td>
263 <td>An instruction writes over an existing instruction (probably your code).</td>
264 </tr><tr>
265 <td>expected "type" in "address", got "something"</td>
266 <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>
267 </td>
268 </tr>
269 </table>
270 </div>
271 </div>
272 </div>
273 </div>
274
275 <div class="col-sm-12 col-lg-12">
276 <div class="panel panel-default" id="panelGraph" style="display: none;">
277 <div class="panel-heading">Control Flow Graph (CFG)
278 <button type="button" class="close" onClick="$('#panelGraph').hide()" aria-hidden="true">&times;</button>
279 </div>
280 <div class="panel-body">
281 <div id="graph"></div>
282 </div>
283 </div>
284 </div>
285
286 <script>
287 if(typeof(Worker) !== "undefined") {
288 // Async version
289 var worker = new Worker("worker.js")
290 worker.onmessage = function(event) {
291 if (event.data.type == "ready") {
292 ready()
293 } else if (event.data.type == "complete") {
294 complete()
295 } else if (event.data.type == "exception") {
296 exception(event.data.data)
297 } else if (event.data.type == "stdout") {
298 stdout(event.data.data)
299 } else if (event.data.type == "show_graph") {
300 show_graph(event.data.data)
301 } else {
302 console.out(event.data)
303 }
304 }
305 } else {
306 // Synced version
307 $(document).ready(function() {
308 // Report full loading
309 $("#loading").hide()
310 $("#analyze").prop('disabled', false)
311 });
312 var Module = {
313 'print': stdout,
314 'TOTAL_MEMORY': 512000000
315 }
316 importScripts("pep8analysis.js")
317 var Pep8Module = Module
318 }
319 </script>
320 <script src="viz.js"></script>
321 </div>
322
323 </body>
324 </html>