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