forked from flurischt/interproc-trunk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterprocweb.ml
More file actions
415 lines (384 loc) · 11.6 KB
/
Copy pathinterprocweb.ml
File metadata and controls
415 lines (384 loc) · 11.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
(** CGI-Interface for the interproc analyzer *)
(* This file is part of the Interproc analyzer, released under GPL license.
Please read the COPYING file packaged in the distribution.
Copyright (C) Mathias Argoud, Gaël Lalire, Bertrand Jeannet 2007.
*)
open Html
open Http
open Cgi
open Sscookie
open Date
type option =
| Rational
| Floating
(* you will need to change the following address *)
module Link = struct
let (url:string) =
Html.link
"http://pop-art.inrialpes.fr/interproc/interprocweb.cgi"
"interprocweb"
let (urlf:string) =
Html.link
"http://pop-art.inrialpes.fr/interproc/interprocwebf.cgi"
"interprocwebf"
let (apron:string) =
Html.link
"http://apron.cri.ensmp.fr/library/"
"APRON Abstract Domain Library"
let (fixpoint:string) =
Html.link
"http://pop-art.inrialpes.fr/people/bjeannet/bjeannet-forge/fixpoint/index.html"
"Fixpoint Solver Library"
let (interproc:string) =
Html.link
"http://pop-art.inrialpes.fr/people/bjeannet/bjeannet-forge/interproc/index.html"
"Interproc"
let (simple_syntax:string) =
Html.link
"http://pop-art.inrialpes.fr/people/bjeannet/bjeannet-forge/interproc/manual_syntax.html"
"``Simple'' language syntax"
let (program_examples:string) =
Print.sprintf "%s %s %s %s %s %s %s %s"
(Html.link
"interproc_examples/incr.txt" "incr")
(Html.link
"interproc_examples/ackerman.txt" "ackerman")
(Html.link
"interproc_examples/fact.txt" "fact")
(Html.link
"interproc_examples/numerical.txt" "numerical")
(Html.link
"interproc_examples/numerical2.txt" "numerical2")
(Html.link
"interproc_examples/maccarthy91.txt" "maccarthy91")
(Html.link
"interproc_examples/heapsort.txt" "heapsort")
(Html.link
"interproc_examples/symmetricalstairs.txt" "symmetricalstairs")
let (ocamlhtml:string) =
Html.link
"http://www.eleves.ens.fr/home/mine/ocamlhtml/"
"OCamlHtml library"
end
(* ********************************************************************** *)
(* analyze *)
(* ********************************************************************** *)
let myescape_html s =
let buf = Buffer.create 16 in
let i = ref 0 in
while !i < String.length s do
if s.[!i]='<' then begin
if (String.sub s (!i+1) 11)="span style=" then begin
let index_end = String.index_from s (!i + 12) '>' in
Buffer.add_string buf
(String.sub s !i (index_end + 1 - !i));
i := index_end + 1;
end
else if (String.sub s (!i+1) 6)="/span>" then begin
Buffer.add_string buf "</span>";
i := !i + 7;
end
else begin
Buffer.add_string buf "<";
incr i;
end
end
else begin
if s.[!i]='>' then Buffer.add_string buf ">"
else if s.[!i]='&' then Buffer.add_string buf "&"
else if s.[!i]='"' then Buffer.add_string buf """
else Buffer.add_char buf s.[!i]
;
incr i;
end;
done;
Buffer.contents buf
let analyze (progtext:string) =
let d = Date.get_date ()
and e = Date.get_date ()
in
Date.add_minutes e 15;
Html.h1 "Analysis Result";
Html.p ("Run "^Link.url^" or "^Link.urlf^" ?");
let buffer = Buffer.create (String.length progtext) in
let (output:Format.formatter) = Format.formatter_of_buffer buffer in
begin try
Option.displaytags := Option.htmltags;
(* Parsing the program *)
let lexbuf = Lexing.from_string progtext in
let prog = Frontend.parse_lexbuf output lexbuf in
(* Computing solution *)
Frontend.analyze_and_display output prog;
()
with
| Exit -> ()
| Failure s ->
Html.h2 "Source";
Html.pre progtext;
Html.p (Html.escape_html s)
end;
Html.h2 "Result";
print_string "<pre>\r\n";
print_string (myescape_html (Buffer.contents buffer));
Buffer.clear buffer;
print_string "</pre>\r\n";
Html.h2 "Source";
Html.pre progtext;
Html.p ("Run "^Link.url^" or "^Link.urlf^" ?");
()
(* ********************************************************************** *)
(* frontpage *)
(* ********************************************************************** *)
let frontpage ~(opt:option) =
Html.h1 (match opt with
| Rational -> "The Interproc Analyzer"
| Floating -> "The Interprocf Analyzer"
);
Html.p
(Printf.sprintf "\
This is a web interface to the %s analyzer connected \
to the %s and the %s, whose goal is to demonstrate the features \
of the APRON library and, to a less extent, of the Analyzer fixpoint engine, \
in the static analysis field.<br><br> \
There are two compiled versions: %s, \
in which all the abstract domains use underlying multiprecision \
integer/rational numbers, and %s, \
in which box and octagon domains use underlying floating-point \
numbers in safe way.<br><br>This is the <b>%s</b> version"
Link.interproc
Link.apron
Link.fixpoint
Link.url
Link.urlf
(match opt with
| Rational -> "Interproc"
| Floating -> "Interprocf"
)
);
Html.form_begin ~meth:Multipart
(match opt with
| Rational -> "http://pop-art.inrialpes.fr/interproc/interprocweb.cgi";
| Floating -> "http://pop-art.inrialpes.fr/interproc/interprocwebf.cgi")
;
Html.h2 "Arguments";
Html.p ("\
Please type a program, upload a file from your hard-drive, \
or choose one the provided examples:"
);
Html.form_file ~maxlength:32768 "file";
Html.br ();
Html.form_menu "example"
[
Option (None,"none", "user-supplied", true);
Option (None,"interproc_examples/incr.txt", "Incr", false);
Option (None,"interproc_examples/ackerman.txt", "Ackerman", false);
Option (None,"interproc_examples/fact.txt", "Factorial", false);
Option (None,"interproc_examples/maccarthy91.txt", "Mac Carthy 91", false);
Option (None,"interproc_examples/heapsort.txt", "Heap Sort", false);
Option (None,"interproc_examples/symmetricalstairs.txt", "Symmetrical Stairs", false);
Option (None,"interproc_examples/numerical.txt", "Numerical example", false);
Option (None,"interproc_examples/numerical2.txt", "Numerical example 2", false);
];
Html.br ();
Html.form_textarea ~default:"/* type your program here ! */" "text" 15 60;
Html.br ();
print_string "Numerical Abstract Domain: ";
Html.form_menu "abstraction"
[
Option (None, "none", "Choose an Abstract Domain:", false);
Option (None, "box", "box", false);
Option (None, "boxpolicy", "box with policy iteration", false);
Option (None, "octagon", "octagon", false);
Option (None, "polka", "convex polyhedra (polka)", true);
Option (None, "ppl", "convex polyhedra (PPL)", false);
Option (None, "polkastrict", "strict convex polyhedra (polka)", false);
Option (None, "pplstrict", "strict convex polyhedra (PPL)", false);
Option (None, "polkaeq", "linear equalities (polka)", false);
Option (None, "pplgrid", "linear congruences (PPL)", false);
Option (None, "polkagrid", "convex polyhedra + linear congruences", false);
];
print_string "<br>Kind of Analysis: ";
Html.form_text
~size:6
~maxlength:6
~default:"f"
"analysis"
;
print_string "(sequence of forward and/or backward analysis)";
print_string "<br><br>Iterations/Widening options:<br>";
Html.form_checkbox
~checked:false
"guided"
;
print_string "guided iterations ";
Html.form_text
~size:2
~maxlength:2
~default:"1"
"widening_start"
;
print_string " widening delay ";
Html.form_text
~size:2
~maxlength:2
~default:"2"
"descending"
;
print_string " descending steps<br>";
Html.form_text
~size:2
~maxlength:2
~default:"0"
"debug"
;
print_string " debugging level (0 to 6)<br>";
print_string "\
<p>\n\
Hit the OK button to proceed: ";
Html.form_submit ~label:"OK !" ();
Html.form_reset ~label:"Reset" ();
Html.form_end ();
Html.h2 Link.simple_syntax;
Html.p (Print.sprintf "Here are some program examples: %s" Link.program_examples);
Html.h2 "Results";
Html.p ~style:"note" "\
In order not to flood our web-server, analysis computation time is \
limited to 1min in this demonstration. Also note that result files are \
temporary files stored on our server that have a very short life-time."
;
Html.p "The analysis computes an invariant at each program point.";
Html.h2 "Informations";
Html.p (Print.sprintf "\
The %s is freely available. It is written in C, with a OCaml binding. \
The %s analyzer and the %s are freely available, \
and are written in OCaml."
Link.interproc
Link.apron
Link.fixpoint);
Html.p
(Print.sprintf "\
This CGI-WEB interface is written in OCaml using the %s, \
freely available"
Link.ocamlhtml);
()
(* ********************************************************************** *)
(* main *)
(* ********************************************************************** *)
let mainpage ~(opt:option) =
try
let args = Cgi.get_cgi_args () in
(*
Format.bprintf Format.stdbuf
"%a"
(Print.list
(fun fmt (str1,ostr2) ->
Format.fprintf fmt "(%s,%s)"
str1
(begin match ostr2 with
| None -> "None"
| Some s -> "Some "^s
end)
))
args
;
print_string "<pre>\r\n";
print_string (myescape_html (Format.flush_str_formatter ()));
print_string "</pre>\r\n";
*)
let (text,args) = match args with
| ("file",Some "")::
("filecontent",Some "")::
("example",Some "none")::
("text",Some text)::
args
->
(text,args)
| ("file",_)::
("filecontent",Some text)::
("example",Some "none")::
("text",_)::
args
->
(text,args)
| ("file",_)::
("filecontent",_)::
("example",Some filename)::
("text",_ )::
args
->
let file = open_in filename in
let buffer = Buffer.create 1024 in
begin
try
while true do
let line = input_line file in
Buffer.add_string buffer line;
Buffer.add_string buffer "\r\n";
done
with
| End_of_file -> close_in file
end;
let text = Buffer.contents buffer in
(text,args)
| _ -> raise Exit
in
Option.iteration_guided := false;
List.iter
(begin function
| ("abstraction",Some name) ->
Option.domain := List.assoc name Option.assocnamedomain;
| ("analysis", Some text) ->
Option.analysis := [];
String.iter
(begin fun chr ->
match chr with
| 'f' ->
Option.analysis := Option.Forward :: !Option.analysis
| 'b' ->
Option.analysis := Option.Backward :: !Option.analysis
| _ ->
raise (Arg.Bad ("Wrong argument `"^text^"'; option `-analysis' expects only 'f' or 'b' characters in its argument string"))
end)
text;
Option.analysis := List.rev !Option.analysis;
if !Option.analysis=[] then
Option.analysis := [Option.Forward]
;
| ("guided",Some "on") ->
Option.iteration_guided := true
| ("widening_start",Some text) ->
Option.widening_start := int_of_string text;
| ("descending",Some text) ->
Option.widening_descend := int_of_string text;
| ("debug",Some text) ->
Option.debug := int_of_string text;
| _ -> ()
end)
args
;
analyze text
with Exit ->
frontpage ~opt
let main ~(opt:option) =
Cgi.set_timeout 15;
Sscookie.clean_cookies
(match opt with
| Rational -> "interprochtml";
| Floating -> "interprocfhtml"
);
Http.http_header ();
Html.html_begin
~lang:"en"
~author:"Antoine Miné and Bertrand Jeannet"
~desc:"\
CGI interface to the Interproc static analyzer, \
illustrating the use of the APRON Abstract Domain Library"
"Interproc Analyzer"
;
mainpage ~opt;
Html.html_end
~author:"Bertrand Jeannet"
~email:"bjeannet@NOSPAM inrialpes.fr"
()
;
()