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