4 <title>Pep/
8 Analysis
</title>
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">
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>
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>
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');
24 ga('create', 'UA-574578-5', 'xymus.net');
25 ga('send', 'pageview');
27 // Both Viz and Pep8 use emscripten
28 // We put aside the module of each program and bring it back before each use
33 $
("#analyze").prop('disabled', false)
37 // Show and set color of output console
38 $
("#consolePanel").removeClass("panel-success panel-warning panel-danger")
39 var analysis
= $
("#console").text();
40 if (analysis
.indexOf("Error") >= 0) {
41 $
("#consolePanel").addClass("panel-danger")
42 ga('trackEvent', 'Result', 'Error')
44 else if (analysis
.indexOf("Warning") >= 0) {
45 $
("#consolePanel").addClass("panel-warning")
46 ga('trackEvent', 'Result', 'Warning')
49 $
("#consolePanel").addClass("panel-success")
50 ga('trackEvent', 'Result', 'Success')
53 $
("#consolePanel").show()
54 $
("#analyze").prop('disabled', false)
57 function exception(ex
) {
58 console
.debug("Tool invocation failed, with:\n" + $
("#console").text() + "\n" + ex
)
59 ga('trackEvent', 'Crash', 'Analysis', $
("#console").text())
60 $
("#fatal-error").show()
61 $
("#analyze").prop('disabled', true)
64 function stdout(text
) {
65 $
("#console").append(text
+ "<br>")
70 $
("#consolePanel").hide()
72 // Clean output console
73 $
("#console").text("")
76 var input
= editor
.getValue()
79 ga('trackEvent', 'Action', 'Analyze')
81 // Invoke the full Nit program
82 if(typeof(Worker
) !== "undefined") {
84 $
("#analyze").prop('disabled', true)
85 worker
.postMessage(input
)
88 ga('trackEvent', 'Crash', 'No Webworkers', $
("#console").text())
91 run_analysis
= Module
.cwrap('pep8analysis_web___NativeString_run_analysis', null, ['string'])
101 function load(file
) {
102 // Load a sample program
103 $
.get('samples/' + file
, function(data
){
104 editor
.setValue(data
)
108 function show_graph(source
) {
110 var res
= Viz(source
, "svg", "dot")
112 $
("#graph").html(res
)
118 <nav class=
"navbar navbar-default" role=
"navigation">
119 <div class=
"container-fluid">
120 <div class=
"navbar-header">
121 <button type=
"button" class=
"navbar-toggle" data-toggle=
"collapse" data-target=
"#bs-example-navbar-collapse-1">
122 <span class=
"sr-only">Toggle navigation
</span>
123 <span class=
"icon-bar"></span>
124 <span class=
"icon-bar"></span>
125 <span class=
"icon-bar"></span>
127 <a class=
"navbar-brand">Pep/
8 Analysis
</a>
130 <div class=
"collapse navbar-collapse" id=
"bs-example-navbar-collapse-1">
131 <ul class=
"nav navbar-nav">
132 <li class=
"active"><a>Web interface
</a></li>
133 <li><a href=
"https://github.com/privat/nit/tree/master/contrib/pep8analysis/">Tool source and manual
</a></li>
135 <ul class=
"nav navbar-nav navbar-right">
136 <li><a href=
"http://nitlanguage.org/">nitlanguage.org
</a></li>
137 <li><a href=
"https://code.google.com/p/pep8-1/">Pep/
8 project
</a></li>
143 <div class=
"container-fluid">
144 <div class=
"alert alert-warning" id=
"loading">Loading the tool... This may take some time.
</div>
145 <div class=
"alert alert-danger" id=
"fatal-error" style=
"display: none;">
146 <h2>The JavaScript tool crashed
</h2>
147 <p>Please refresh the page to try again, or use Firefox. An error report has been sent to the developer
</p>
151 <div class=
"col-sm-12 col-lg-6">
152 <div class=
"panel panel-default" id=
"panelIntro">
153 <div class=
"panel-heading">Description and Usage
154 <button type=
"button" class=
"close" onClick=
"$('#panelIntro').hide()" aria-hidden=
"true">×</button>
156 <div class=
"panel-body" id=
"code-panel">
157 <p>This tools finds strange behavior in Pep/
8 programs by exploring all detectable execution paths.
</p>
158 <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>
159 <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>
163 <div class=
"panel panel-default">
164 <div class=
"panel-heading">Pep/
8 Source Code
</div>
165 <div class=
"panel-body" id=
"code-panel">
166 <textarea id=
"listing"></textarea>
168 var editor
= CodeMirror
.fromTextArea(listing
, {
172 editor
.setSize("100%", 500);
175 <div class=
"btn-group">
176 <button type=
"button" class=
"btn btn-default" id=
"analyze" onclick=
"exec();" disabled
>Analyze program
</button>
177 <button type=
"button" class=
"btn btn-default dropdown-toggle" data-toggle=
"dropdown">
178 <span class=
"glyphicon glyphicon-folder-open"></span>
180 <span class=
"caret"></span>
182 <ul class=
"dropdown-menu">
183 <li><a onclick=
"load('02-fibo.pep')">fibo.pep - clean program
</a></li>
184 <li><a onclick=
"load('06-calc-non-pur.pep');">calc-non-pur.pep - self rewriting program
</a></li>
185 <li><a onclick=
"load('types.pep');"/>types.pep - strange data manipulation
</a></li>
186 <li><a onclick=
"load('directive-in-code.pep');">directive-in-code.pep - mixed directives and instructions
</a></li>
193 <div class=
"clearfix visible-xs"></div>
194 <div class=
"col-sm-12 col-lg-6">
195 <div class=
"alert alert-warning" id=
"working" style=
"display: none;">The tool is evaluating all possible execution paths... This may take some time.
</div>
196 <div class=
"panel" id=
"consolePanel" style=
"display: none;">
197 <div class=
"panel-heading">Analysis Result
</div>
198 <div class=
"panel-body">
199 <samp id=
"console"></samp>
200 <button type=
"button" class=
"btn btn-default" onclick=
"$('#panelGraph').show();$('#panelGraphExp').show();">
201 Show control flow graph
</button>
202 <em class=
"pull-right" id=
"panelGraphExp" style=
"display: none;">The graph is at the bottom of the page...
</em>
207 <div class=
"col-sm-12 col-lg-6">
208 <div class=
"panel panel-default" id=
"panelRef">
209 <div class=
"panel-heading">Output Documentation
210 <button type=
"button" class=
"close" onClick=
"$('#panelRef').hide()" aria-hidden=
"true">×</button>
212 <div class=
"panel-body" id=
"code-panel">
213 <h4>Line and memory references
</h4>
214 <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>
215 <table class=
"table table-striped">
221 <td>Source line
5</td>
224 <td>Source line
8</td>
227 <td>Registers A, X
</td>
230 <td>Memory at address
24 (bytes)
</td>
233 <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>
237 <h4>Common errors and warnings
</h4>
239 <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>
241 <table class=
"table table-striped">
246 <td>... the CFG may be wrong
</td>
247 <td>The program structure is too complex to analyze. This happens when jumping to dynamic addresses and when using switch statements.
</td>
249 <td>unreachable instructions
</td>
250 <td>There's dead code.
</td>
252 <td>data in program flow
</td>
253 <td>The program may execute raw data. There's probably a
<code>BR
</code> missing.
</td>
255 <td>overwriting code at...
</td>
256 <td>An instruction writes over an existing instruction (probably your code).
</td>
258 <td>expected
"type" in
"address", got
"something"</td>
259 <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>
268 <div class=
"col-sm-12 col-lg-12">
269 <div class=
"panel panel-default" id=
"panelGraph" style=
"display: none;">
270 <div class=
"panel-heading">Control Flow Graph (CFG)
271 <button type=
"button" class=
"close" onClick=
"$('#panelGraph').hide()" aria-hidden=
"true">×</button>
273 <div class=
"panel-body">
274 <div id=
"graph"></div>
280 if(typeof(Worker
) !== "undefined") {
282 var worker
= new Worker("worker.js")
283 worker
.onmessage
= function(event
) {
284 if (event
.data
.type
== "ready") {
286 } else if (event
.data
.type
== "complete") {
288 } else if (event
.data
.type
== "exception") {
289 exception(event
.data
.data
)
290 } else if (event
.data
.type
== "stdout") {
291 stdout(event
.data
.data
)
292 } else if (event
.data
.type
== "show_graph") {
293 show_graph(event
.data
.data
)
295 console
.out(event
.data
)
300 $
(document
).ready(function() {
301 // Report full loading
303 $
("#analyze").prop('disabled', false)
307 'TOTAL_MEMORY': 512000000
309 importScripts("pep8analysis.js")
310 var Pep8Module
= Module
313 <script src=
"viz.js"></script>