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_______________________________________________________________ *)
17 module MO = MetaOutput
19 module BrgO = BrgOutput
20 module BrgU = BrgUntrusted
29 let initial_status = {
30 ac = AO.initial_counters;
31 mc = MO.initial_counters;
32 brgc= BrgO.initial_counters;
33 mst = MA.initial_status
36 let count count_fun c item =
37 if !L.level > 2 then count_fun Cps.start c item else c
40 L.error BrgO.specs (L.Warn s :: msg)
44 let version_string = "Helena Checker 0.8.0 M - December 2008" in
46 let meta_file = ref None in
47 let hierarchy = ref (fun h -> h + 2) in
48 let set_summary i = L.level := i in
49 let print_version () = L.warn version_string; exit 0 in
50 let set_stage i = stage := i in
53 | Some (och, _) -> close_out och
55 let set_meta_file name =
57 let och = open_out name in
58 let frm = Format.formatter_of_out_channel och in
59 Format.pp_set_margin frm max_int;
60 meta_file := Some (och, frm)
63 if !L.level > 0 then Time.gmtime version_string;
65 L.warn (P.sprintf "Processing file: %s" name);
66 if !L.level > 0 then Time.utime_stamp "started";
67 let ich = open_in name in
68 let lexbuf = Lexing.from_channel ich in
69 let book = AutParser.book AutLexer.token lexbuf in
71 if !L.level > 0 then Time.utime_stamp "parsed";
72 let rec aux st = function
78 | Some (_, (i, u, _)) ->
79 Log.warn (P.sprintf "[%u] %s" i (U.string_of_uri u)); st
83 let st = {st with brgc = count BrgO.count_item st.brgc item} in
84 if !stage > 2 then BrgU.type_check (f st) !hierarchy item else st
89 mst = mst; mc = count MO.count_item st.mc item
91 begin match !meta_file with
93 | Some (_, frm) -> MO.pp_item Cps.start frm item
95 if !stage > 1 then MBrg.brg_of_meta (f st) item else st
98 let st = {st with ac = count AO.count_item st.ac item} in
100 if !stage > 0 then MA.meta_of_aut f st.mst item else st
104 let st = aux initial_status book in
105 if !L.level > 0 then Time.utime_stamp "processed";
106 if !L.level > 2 then AO.print_counters Cps.start st.ac;
107 if !L.level > 2 && !stage > 0 then MO.print_counters Cps.start st.mc;
108 if !L.level > 2 && !stage > 1 then BrgO.print_counters Cps.start st.brgc;
111 "Usage: helena [ -V | -Ss <number> | -m <file> ] <file> ...\n\n" ^
112 "Summary levels: 0 just errors, 1 time stamps, 2 processed file names, \
113 3 data information, 4 typing information, 5 reduction information\n\n" ^
114 "Stages: 0 parsing, 1 to intermediate, 2 to untrusted, 3 to trusted\n"
116 let help_S = "<number> Set summary level" in
117 let help_V = " Show version information" in
118 let help_m = "<file> output intermediate representation" in
119 let help_s = "<number> Set translation stage" in
121 ("-S", Arg.Int set_summary, help_S);
122 ("-V", Arg.Unit print_version, help_V);
123 ("-m", Arg.String set_meta_file, help_m);
124 ("-s", Arg.Int set_stage, help_s);
126 if !L.level > 0 then Time.utime_stamp "at exit"
127 with BrgType.TypeError msg -> brg_error "Type Error" msg