pep8analysis: Web interface launches only the analysis (not the full main)
[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 run_analysis = Module.cwrap('pep8analysis_web___NativeString_run_analysis', null, ['string'])
52 run_analysis(input)
53 } catch(e) {
54 console.debug("Tool invocation failed, with:\n" + $("#console").text() + "\n" + e )
55 ga('trackEvent', 'Crash', 'Analysis', $("#console").text())
56 $("#fatal-error").show()
57 $("#analyze").prop('disabled', true)
58 }
59
60 // Show and set color of output console
61 $("#consolePanel").removeClass("panel-success panel-warning panel-danger")
62 var analysis = $("#console").text();
63 if (analysis.indexOf("Error") >= 0) {
64 $("#consolePanel").addClass("panel-danger")
65 ga('trackEvent', 'Result', 'Error')
66 }
67 else if (analysis.indexOf("Warning") >= 0) {
68 $("#consolePanel").addClass("panel-warning")
69 ga('trackEvent', 'Result', 'Warning')
70 }
71 else {
72 $("#consolePanel").addClass("panel-success")
73 ga('trackEvent', 'Result', 'Success')
74 }
75 $("#working").hide()
76 $("#consolePanel").show()
77 }
78
79 function load(file) {
80 // Load a sample program
81 $.get('samples/' + file, function(data){
82 editor.setValue(data)
83 })
84 }
85
86 function show_graph(source) {
87 Module = VizModule
88 var res = Viz(source, "svg", "dot")
89 VizModule = Module
90 $("#graph").html(res)
91 }
92 </script>
93 </head>
94 <body>
95
96 <nav class="navbar navbar-default" role="navigation">
97 <div class="container-fluid">
98 <div class="navbar-header">
99 <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
100 <span class="sr-only">Toggle navigation</span>
101 <span class="icon-bar"></span>
102 <span class="icon-bar"></span>
103 <span class="icon-bar"></span>
104 </button>
105 <a class="navbar-brand">Pep/8 Analysis</a>
106 </div>
107
108 <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
109 <ul class="nav navbar-nav">
110 <li class="active"><a>Web interface</a></li>
111 <li><a href="https://github.com/privat/nit/tree/master/contrib/pep8analysis/">Tool source and manual</a></li>
112 </ul>
113 <ul class="nav navbar-nav navbar-right">
114 <li><a href="http://nitlanguage.org/">nitlanguage.org</a></li>
115 <li><a href="https://code.google.com/p/pep8-1/">Pep/8 project</a></li>
116 </ul>
117 </div>
118 </div>
119 </nav>
120
121 <div class="container-fluid">
122 <div class="alert alert-warning" id="loading">Loading the tool... This may take some time.</div>
123 <div class="alert alert-danger" id="fatal-error" style="display: none;">
124 <h2>The JavaScript tool crashed</h2>
125 <p>Please refresh the page to try again, or use Firefox. An error report has been sent to the developer</p>
126 </div>
127
128 <div class="row">
129 <div class="col-sm-12 col-lg-6">
130 <div class="panel panel-default" id="panelIntro">
131 <div class="panel-heading">Description and Usage
132 <button type="button" class="close" onClick="$('#panelIntro').hide()" aria-hidden="true">&times;</button>
133 </div>
134 <div class="panel-body" id="code-panel">
135 <p>This tools finds strange behavior in Pep/8 programs by exploring all detectable execution paths.</p>
136 <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>
137 <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>
138 </div>
139 </div>
140
141 <div class="panel panel-default">
142 <div class="panel-heading">Pep/8 Source Code</div>
143 <div class="panel-body" id="code-panel">
144 <textarea id="listing"></textarea>
145 <script>
146 var editor = CodeMirror.fromTextArea(listing, {
147 lineNumbers: true,
148 mode: "z80"
149 });
150 editor.setSize("100%", 500);
151 </script>
152
153 <div class="btn-group">
154 <button type="button" class="btn btn-default" id="analyze" onclick="exec();" disabled>Analyze program</button>
155 <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
156 <span class="glyphicon glyphicon-folder-open"></span>
157 Load sample program
158 <span class="caret"></span>
159 </button>
160 <ul class="dropdown-menu">
161 <li><a onclick="load('02-fibo.pep')">fibo.pep - clean program </a></li>
162 <li><a onclick="load('06-calc-non-pur.pep');">calc-non-pur.pep - self rewriting program </a></li>
163 <li><a onclick="load('types.pep');"/>types.pep - strange data manipulation </a></li>
164 <li><a onclick="load('directive-in-code.pep');">directive-in-code.pep - mixed directives and instructions</a></li>
165 </ul>
166 </div>
167 </div>
168 </div>
169 </div>
170
171 <div class="clearfix visible-xs"></div>
172 <div class="col-sm-12 col-lg-6">
173 <div class="alert alert-warning" id="working" style="display: none;">The tool is evaluating all possible execution paths... This may take some time.</div>
174 <div class="panel" id="consolePanel" style="display: none;">
175 <div class="panel-heading">Analysis Result</div>
176 <div class="panel-body">
177 <samp id="console"></samp>
178 <button type="button" class="btn btn-default" onclick="$('#panelGraph').show();$('#panelGraphExp').show();">
179 Show control flow graph</button>
180 <em class="pull-right" id="panelGraphExp" style="display: none;">The graph is at the bottom of the page...</em>
181 </div>
182 </div>
183 </div>
184
185 <div class="col-sm-12 col-lg-6">
186 <div class="panel panel-default" id="panelRef">
187 <div class="panel-heading">Output Documentation
188 <button type="button" class="close" onClick="$('#panelRef').hide()" aria-hidden="true">&times;</button>
189 </div>
190 <div class="panel-body" id="code-panel">
191 <h4>Line and memory references</h4>
192 <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>
193 <table class="table table-striped">
194 <tr>
195 <th>Shorthand</th>
196 <th>Description</th>
197 </tr><tr>
198 <td>web:5</td>
199 <td>Source line 5</td>
200 </tr><tr>
201 <td>L8</td>
202 <td>Source line 8</td>
203 </tr><tr>
204 <td>rA, rX</td>
205 <td>Registers A, X</td>
206 </tr><tr>
207 <td>m24</td>
208 <td>Memory at address 24 (bytes)</td>
209 </tr><tr>
210 <td>instr@m24</td>
211 <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>
212 </tr>
213 </table>
214
215 <h4>Common errors and warnings</h4>
216
217 <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>
218
219 <table class="table table-striped">
220 <tr>
221 <th>Error</th>
222 <th>Meaning</th>
223 </tr><tr>
224 <td>... the CFG may be wrong</td>
225 <td>The program structure is too complex to analyze. This happens when jumping to dynamic addresses and when using switch statements.</td>
226 </tr><tr>
227 <td>unreachable instructions</td>
228 <td>There's dead code.</td>
229 </tr><tr>
230 <td>data in program flow</td>
231 <td>The program may execute raw data. There's probably a <code>BR</code> missing.</td>
232 </tr><tr>
233 <td>overwriting code at...</td>
234 <td>An instruction writes over an existing instruction (probably your code).</td>
235 </tr><tr>
236 <td>expected "type" in "address", got "something"</td>
237 <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>
238 </td>
239 </tr>
240 </table>
241 </div>
242 </div>
243 </div>
244 </div>
245
246 <div class="col-sm-12 col-lg-12">
247 <div class="panel panel-default" id="panelGraph" style="display: none;">
248 <div class="panel-heading">Control Flow Graph (CFG)
249 <button type="button" class="close" onClick="$('#panelGraph').hide()" aria-hidden="true">&times;</button>
250 </div>
251 <div class="panel-body">
252 <div id="graph"></div>
253 </div>
254 </div>
255 </div>
256
257 <script>
258 var Module = {
259 'print': function(text) {
260 $("#console").append(text + "<br>")
261 },
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>