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 <script type=
"text/javascript" src=
"viz.js"></script>
12 // Both Viz and Pep8 use emscripten
13 // We put aside the module of each program and bring it back before each use
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>
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>
26 // Redirect print to HTML
28 'print': function(text
) {
29 $
("#console").append(text
+ "<br>")
34 $
(document
).ready(function() {
35 // Report full loading
37 $
("#analyze").prop('disabled', false)
41 // Clean output console
42 $
("#console").text("")
45 var input
= editor
.getValue()
47 // Invoke the full Nit program
49 ret
= Module
['callMain']([input])
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")
60 $
("#consolePanel").addClass("panel-success")
64 // Load a sample program
65 $
.get('samples/' + file
, function(data
){
70 function show_graph(source
) {
72 var res
= Viz(source
, "svg", "dot")
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>
89 <a class=
"navbar-brand">Pep/
8 Analysis
</a>
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>
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>
105 <div class=
"container-fluid">
106 <div class=
"alert alert-warning" id=
"loading">Loading the tool... This may take some time.
</div>
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">×</button>
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>
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>
126 var editor
= CodeMirror
.fromTextArea(listing
, {
130 editor
.setSize("100%", 500);
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>
138 <span class=
"caret"></span>
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>
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>
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">×</button>
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">
178 <td>Source line
5</td>
181 <td>Source line
8</td>
184 <td>Registers A, X
</td>
187 <td>Memory at address
24 (bytes)
</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>
194 <h4>Common errors and warnings
</h4>
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>
198 <table class=
"table table-striped">
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>
206 <td>unreachable instructions
</td>
207 <td>There's dead code.
</td>
209 <td>data in program flow
</td>
210 <td>The program may execute raw data. There's probably a
<code>BR
</code> missing.
</td>
212 <td>overwriting code at...
</td>
213 <td>An instruction writes over an existing instruction (probably your code).
</td>
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>
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">×</button>
230 <div class=
"panel-body">
231 <div id=
"graph"></div>
236 <script src=
"pep8analysis.js"></script>
237 <script>var Pep8Module
= Module
</script>