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