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)
38 // Clean output console
39 $
("#console").text("")
42 var input
= editor
.getValue()
44 // Invoke the full Nit program
46 ret
= Module
['callMain']([input])
48 // Shot and set color of output console
49 $
("#consolePanel").removeClass("panel-success panel-warning panel-danger")
50 $
("#consolePanel").show()
51 var analysis
= $
("#consolePanel").text();
52 if (analysis
.indexOf("Error") >= 0)
53 $
("#consolePanel").addClass("panel-danger")
54 else if (analysis
.indexOf("Warning") >= 0)
55 $
("#consolePanel").addClass("panel-warning")
57 $
("#consolePanel").addClass("panel-success")
61 // Load a sample program
62 $
.get('samples/' + file
, function(data
){
67 function show_graph(source
) {
69 var res
= Viz(source
, "svg", "dot")
77 <nav class=
"navbar navbar-default" role=
"navigation">
78 <div class=
"container-fluid">
79 <div class=
"navbar-header">
80 <button type=
"button" class=
"navbar-toggle" data-toggle=
"collapse" data-target=
"#bs-example-navbar-collapse-1">
81 <span class=
"sr-only">Toggle navigation
</span>
82 <span class=
"icon-bar"></span>
83 <span class=
"icon-bar"></span>
84 <span class=
"icon-bar"></span>
86 <a class=
"navbar-brand">Pep/
8 Analysis
</a>
89 <div class=
"collapse navbar-collapse" id=
"bs-example-navbar-collapse-1">
90 <ul class=
"nav navbar-nav">
91 <li class=
"active"><a>Web interface
</a></li>
92 <li><a href=
"https://github.com/privat/nit/tree/master/contrib/pep8analysis/">Tool source and manual
</a></li>
94 <ul class=
"nav navbar-nav navbar-right">
95 <li><a href=
"http://nitlanguage.org/">nitlanguage.org
</a></li>
96 <li><a href=
"https://code.google.com/p/pep8-1/">Pep/
8 project
</a></li>
102 <div class=
"container-fluid">
103 <div class=
"alert alert-warning" id=
"loading">Loading the tool... This may take some time.
</div>
106 <div class=
"col-sm-12 col-lg-6">
107 <div class=
"panel panel-default" id=
"panelIntro">
108 <div class=
"panel-heading">Description and Usage
109 <button type=
"button" class=
"close" onClick=
"$('#panelIntro').hide()" aria-hidden=
"true">×</button>
111 <div class=
"panel-body" id=
"code-panel">
112 <p>This tools finds strange behavior in Pep/
8 programs by exploring all detectable execution paths.
</p>
113 <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>
114 <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>
118 <div class=
"panel panel-default">
119 <div class=
"panel-heading">Pep/
8 Source Code
</div>
120 <div class=
"panel-body" id=
"code-panel">
121 <textarea id=
"listing"></textarea>
123 var editor
= CodeMirror
.fromTextArea(listing
, {
127 editor
.setSize("100%", 500);
130 <div class=
"btn-group">
131 <button type=
"button" class=
"btn btn-default" id=
"analyze" onclick=
"exec();" disabled
>Analyze program
</button>
132 <button type=
"button" class=
"btn btn-default dropdown-toggle" data-toggle=
"dropdown">
133 <span class=
"glyphicon glyphicon-folder-open"></span>
135 <span class=
"caret"></span>
137 <ul class=
"dropdown-menu">
138 <li><a onclick=
"load('02-fibo.pep')">fibo.pep - clean program
</a></li>
139 <li><a onclick=
"load('06-calc-non-pur.pep');">calc-non-pur.pep - self rewriting program
</a></li>
140 <li><a onclick=
"load('types.pep');"/>types.pep - strange data manipulation
</a></li>
141 <li><a onclick=
"load('directive-in-code.pep');">directive-in-code.pep - mixed directives and instructions
</a></li>
148 <div class=
"clearfix visible-xs"></div>
149 <div class=
"col-sm-12 col-lg-6">
150 <div class=
"panel" id=
"consolePanel" style=
"display: none;">
151 <div class=
"panel-heading">Analysis Result
</div>
152 <div class=
"panel-body">
153 <samp id=
"console"></samp>
154 <button type=
"button" class=
"btn btn-default" onclick=
"$('#panelGraph').show();$('#panelGraphExp').show();">
155 Show control flow graph
</button>
156 <em class=
"pull-right" id=
"panelGraphExp" style=
"display: none;">The graph is at the bottom of the page...
</em>
161 <div class=
"col-sm-12 col-lg-6">
162 <div class=
"panel panel-default" id=
"panelRef">
163 <div class=
"panel-heading">Output Documentation
164 <button type=
"button" class=
"close" onClick=
"$('#panelRef').hide()" aria-hidden=
"true">×</button>
166 <div class=
"panel-body" id=
"code-panel">
167 <h4>Line and memory references
</h4>
168 <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>
169 <table class=
"table table-striped">
175 <td>Source line
5</td>
178 <td>Source line
8</td>
181 <td>Registers A, X
</td>
184 <td>Memory at address
24 (bytes)
</td>
187 <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 <h4>Common errors and warnings
</h4>
193 <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>
195 <table class=
"table table-striped">
200 <td>... the CFG may be wrong
</td>
201 <td>The program structure is too complex to analyze. This happens when jumping to dynamic addresses and when using switch statements.
</td>
203 <td>unreachable instructions
</td>
204 <td>There's dead code.
</td>
206 <td>data in program flow
</td>
207 <td>The program may execute raw data. There's probably a
<code>BR
</code> missing.
</td>
209 <td>overwriting code at...
</td>
210 <td>An instruction writes over an existing instruction (probably your code).
</td>
212 <td>expected
"type" in
"address", got
"something"</td>
213 <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>
222 <div class=
"col-sm-12 col-lg-12">
223 <div class=
"panel panel-default" id=
"panelGraph" style=
"display: none;">
224 <div class=
"panel-heading">Control Flow Graph (CFG)
225 <button type=
"button" class=
"close" onClick=
"$('#panelGraph').hide()" aria-hidden=
"true">×</button>
227 <div class=
"panel-body">
228 <div id=
"graph"></div>
235 'print': function(text
) {
236 $
("#console").append(text
+ "<br>")
238 'noInitialRun': true,
241 <script src=
"pep8analysis.js"></script>
242 <script>Pep8Module
= Module
</script>
243 <script src=
"viz.js"></script>