]> matita.cs.unibo.it Git - helm.git/blob - helm/software/lambda-delta/toplevel/top.ml
bb6dcd8433a5536377c26e41a64d82f9f4dafafd
[helm.git] / helm / software / lambda-delta / toplevel / top.ml
1 (* Copyright (C) 2000, HELM Team.
2  * 
3  * This file is part of HELM, an Hypertextual, Electronic
4  * Library of Mathematics, developed at the Computer Science
5  * Department, University of Bologna, Italy.
6  * 
7  * HELM is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  * 
12  * HELM is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with HELM; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://cs.unibo.it/helm/.
24  *)
25
26 module AO = AutOutput
27 module MA = MetaAut
28 module MO = MetaOutput
29
30 let main =
31    let version_string = "Helena Checker 0.8.0 M - November 2008" in
32    let summary = ref 0 in
33    let stage = ref 1 in
34    let meta_file = ref None in
35    let set_summary i = summary := i in
36    let print_version () = print_endline version_string; exit 0 in
37    let set_stage i = stage := i in
38    let close = function
39       | None          -> ()
40       | Some (och, _) -> close_out och
41    in
42    let set_meta_file name =
43       close !meta_file;
44       let och = open_out name in
45       let frm = Format.formatter_of_out_channel och in
46       Format.pp_set_margin frm max_int;
47       meta_file := Some (och, frm)
48    in
49    let read_file name =
50       if !summary > 0 then Time.gmtime version_string;      
51       if !summary > 1 then
52          Printf.printf "Processing file: %s\n" name; flush stdout;
53       if !summary > 0 then Time.utime_stamp "started";
54       let ich = open_in name in
55       let lexbuf = Lexing.from_channel ich in
56       let book = AutParser.book AutLexer.token lexbuf in
57       close_in ich;
58       if !summary > 0 then Time.utime_stamp "parsed";
59       let rec aux ac mc st = function
60          | []         -> ac, mc, st
61          | item :: tl -> 
62             let ac = if !summary > 2 then AO.count_item Cps.id ac item else ac in
63             let f st item = 
64                let mc = if !summary > 2 then MO.count_item Cps.id mc item else mc in
65                begin match !meta_file with
66                   | None          -> ()
67                   | Some (_, frm) -> MO.pp_item Cps.id frm item
68                end;
69                st, mc
70             in
71             let st, mc = if !stage > 0 then MA.meta_of_aut f st item else st, mc in
72             aux ac mc st tl
73       in 
74       let ac, mc, _st = 
75          aux AO.initial_counters MO.initial_counters MA.initial_status book
76       in
77       if !summary > 0 then Time.utime_stamp "processed";
78       if !summary > 2 then AO.print_counters Cps.id ac;
79       if !summary > 2 && !stage > 0 then MO.print_counters Cps.id mc;
80    in
81    let help = "Usage: helena [ -V | -Ss <number> | -m <file> ] <file> ..." in
82    let help_S = "<number>  Set summary level" in
83    let help_V = " Show version information" in   
84    let help_m = "<file>  output intermediate representation" in
85    let help_s = "<number>  Set translation stage" in
86    Arg.parse [
87       ("-S", Arg.Int set_summary, help_S);
88       ("-V", Arg.Unit print_version, help_V);
89       ("-m", Arg.String set_meta_file, help_m); 
90       ("-s", Arg.Int set_stage, help_s);
91    ] read_file help;
92    if !summary > 0 then Time.utime_stamp "at exit"