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
30 $
(document
).ready(function() {
31 // Report full loading
33 $
("#analyze").prop('disabled', false)
39 // Clean output console
40 $
("#console").text("")
43 var input
= editor
.getValue()
46 ga('trackEvent', 'Action', 'Analyze')
48 // Invoke the full Nit program
51 run_analysis
= Module
.cwrap('pep8analysis_web___NativeString_run_analysis', null, ['string'])
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)
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')
67 else if (analysis
.indexOf("Warning") >= 0) {
68 $
("#consolePanel").addClass("panel-warning")
69 ga('trackEvent', 'Result', 'Warning')
72 $
("#consolePanel").addClass("panel-success")
73 ga('trackEvent', 'Result', 'Success')
76 $
("#consolePanel").show()
80 // Load a sample program
81 $
.get('samples/' + file
, function(data
){
86 function show_graph(source
) {
88 var res
= Viz(source
, "svg", "dot")
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>
105 <a class=
"navbar-brand">Pep/
8 Analysis
</a>
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>
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>
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>
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">×</button>
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>
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>
146 var editor
= CodeMirror
.fromTextArea(listing
, {
150 editor
.setSize("100%", 500);
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>
158 <span class=
"caret"></span>
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>
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>
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">×</button>
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">
199 <td>Source line
5</td>
202 <td>Source line
8</td>
205 <td>Registers A, X
</td>
208 <td>Memory at address
24 (bytes)
</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>
215 <h4>Common errors and warnings
</h4>
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>
219 <table class=
"table table-striped">
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>
227 <td>unreachable instructions
</td>
228 <td>There's dead code.
</td>
230 <td>data in program flow
</td>
231 <td>The program may execute raw data. There's probably a
<code>BR
</code> missing.
</td>
233 <td>overwriting code at...
</td>
234 <td>An instruction writes over an existing instruction (probably your code).
</td>
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>
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">×</button>
251 <div class=
"panel-body">
252 <div id=
"graph"></div>
259 'print': function(text
) {
260 $
("#console").append(text
+ "<br>")
262 'TOTAL_MEMORY': 512000000
265 <script src=
"pep8analysis.js"></script>
266 <script>Pep8Module
= Module
</script>
267 <script src=
"viz.js"></script>