2 ||M|| This file is part of HELM, an Hypertextual, Electronic
3 ||A|| Library of Mathematics, developed at the Computer Science
4 ||T|| Department, University of Bologna, Italy.
6 ||T|| HELM is free software; you can redistribute it and/or
7 ||A|| modify it under the terms of the GNU General Public License
8 \ / version 2 or (at your option) any later version.
9 \ / This software is distributed as is, NO WARRANTY.
10 V_______________________________________________________________ *)
19 module MO = MetaOutput
21 module BrgO = BrgOutput
22 module BrgU = BrgUntrusted
31 let initial_status = {
32 ac = AO.initial_counters;
33 mc = MO.initial_counters;
34 brgc= BrgO.initial_counters;
35 mst = MA.initial_status
38 let count count_fun c item =
39 if !L.level > 2 then count_fun C.start c item else c
42 L.error BrgO.specs (L.Warn s :: msg)
46 let version_string = "Helena Checker 0.8.0 M - December 2008" in
48 let meta_file = ref None in
51 | Some g -> H.graph := g
52 | None -> L.warn (P.sprintf "Unknown type hierarchy: %s" s)
56 let set_summary i = L.level := i in
57 let print_version () = L.warn version_string; exit 0 in
58 let set_stage i = stage := i in
61 | Some (och, _) -> close_out och
63 let set_meta_file name =
65 let och = open_out name in
66 let frm = Format.formatter_of_out_channel och in
67 Format.pp_set_margin frm max_int;
68 meta_file := Some (och, frm)
71 if !L.level > 0 then Time.gmtime version_string;
73 L.warn (P.sprintf "Processing file: %s" name);
74 if !L.level > 0 then Time.utime_stamp "started";
75 let ich = open_in name in
76 let lexbuf = Lexing.from_channel ich in
77 let book = AutParser.book AutLexer.token lexbuf in
79 if !L.level > 0 then Time.utime_stamp "parsed";
80 let rec aux st = function
86 | Some (_, (i, u, _)) ->
87 Log.warn (P.sprintf "[%u] %s" i (U.string_of_uri u)); st
91 let st = {st with brgc = count BrgO.count_item st.brgc item} in
92 if !stage > 2 then BrgU.type_check (f st) !H.graph item else st
97 mst = mst; mc = count MO.count_item st.mc item
99 begin match !meta_file with
101 | Some (_, frm) -> MO.pp_item C.start frm item
103 if !stage > 1 then MBrg.brg_of_meta (f st) item else st
106 let st = {st with ac = count AO.count_item st.ac item} in
108 if !stage > 0 then MA.meta_of_aut f st.mst item else st
112 let st = aux initial_status book in
113 if !L.level > 0 then Time.utime_stamp "processed";
114 if !L.level > 2 then AO.print_counters C.start st.ac;
115 if !L.level > 2 && !stage > 0 then MO.print_counters C.start st.mc;
116 if !L.level > 2 && !stage > 1 then BrgO.print_counters C.start st.brgc;
119 "Usage: helena [ -V | -Ss <number> | -m <file> | -h <string> ] <file> ...\n\n" ^
120 "Summary levels: 0 just errors, 1 time stamps, 2 processed file names, \
121 3 data information, 4 typing information, 5 reduction information\n\n" ^
122 "Stages: 0 parsing, 1 to intermediate, 2 to untrusted, 3 to trusted\n"
124 let help_S = "<number> Set summary level" in
125 let help_V = " Show version information" in
126 let help_h = "<string> set type hierarchy" in
127 let help_m = "<file> output intermediate representation" in
128 let help_s = "<number> Set translation stage" in
129 H.set_new_sorts ignore ["Set"; "Prop"];
131 ("-S", Arg.Int set_summary, help_S);
132 ("-V", Arg.Unit print_version, help_V);
133 ("-h", Arg.String set_hierarchy, help_h);
134 ("-m", Arg.String set_meta_file, help_m);
135 ("-s", Arg.Int set_stage, help_s);
137 if !L.level > 0 then Time.utime_stamp "at exit"
138 with BrgType.TypeError msg -> brg_error "Type Error" msg