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 AP = AutProcess
22 module MO = MetaOutput
23 module ML = MetaLibrary
26 module BrgO = BrgOutput
27 module BrgR = BrgReduction
28 module BrgU = BrgUntrusted
30 module BagO = BagOutput
32 module BagU = BagUntrusted
43 let initial_status cover = {
44 ac = AO.initial_counters;
45 mc = MO.initial_counters;
46 brgc = BrgO.initial_counters;
47 bagc = BagO.initial_counters;
48 mst = MA.initial_status ~cover ();
49 ast = AP.initial_status
52 let count count_fun c entity =
53 if !L.level > 2 then count_fun C.start c entity else c
55 let flush () = L.flush 0; L.flush_err ()
58 L.error BagO.specs (L.Warn s :: L.Loc :: msg); flush ()
61 L.error BrgR.specs (L.Warn s :: L.Loc :: msg); flush ()
63 let process_entity f st =
64 let f ast = f {st with ast = ast} in
65 AP.process_entity f st.ast
67 (* kernel related ***********************************************************)
69 type kernel = Brg | Bag
71 type kernel_entity = BrgEntity of Brg.entity
72 | BagEntity of Bag.entity
76 let print_counters st = match !kernel with
77 | Brg -> BrgO.print_counters C.start st.brgc
78 | Bag -> BagO.print_counters C.start st.bagc
80 let kernel_of_meta f st entity = match !kernel with
82 let f entity = f st (BrgEntity entity) in
83 MBrg.brg_of_meta f entity
85 let f entity = f st (BagEntity entity) in
86 MBag.bag_of_meta f entity
88 let count_entity st = function
89 | BrgEntity entity -> {st with brgc = count BrgO.count_entity st.brgc entity}
90 | BagEntity entity -> {st with bagc = count BagO.count_entity st.bagc entity}
92 let export_entity si g = function
93 | BrgEntity entity -> G.old_export_entity BrgO.export_entry si g entity
96 let type_check f st si g k =
97 let brg_err msg = brg_error "Type Error" msg; failwith "Interrupted" in
100 | Some (i, u, _) -> f st (Some (i, u))
103 | BrgEntity entity -> BrgU.type_check brg_err f ~si g entity
104 | BagEntity entity -> BagU.type_check f ~si g entity
106 (****************************************************************************)
110 let version_string = "Helena 0.8.1 M - September 2009" in
112 let moch = ref None in
113 let meta = ref false in
114 let progress = ref false in
115 let process = ref false in
116 let use_cover = ref true in
117 let si = ref false in
118 let cc = ref false in
119 let export = ref false in
120 let graph = ref (H.graph_of_string C.err C.start "Z2") in
121 let set_hierarchy s =
122 let err () = L.warn (P.sprintf "Unknown type hierarchy: %s" s) in
123 let f g = graph := g in
124 H.graph_of_string err f s
126 let set_kernel = function
127 | "brg" -> kernel := Brg
128 | "bag" -> kernel := Bag
129 | s -> L.warn (P.sprintf "Unknown kernel version: %s" s)
131 let set_summary i = L.level := i in
132 let print_version () = L.warn (version_string ^ "\n"); exit 0 in
133 let set_stage i = stage := i in
134 let set_meta_file name =
135 let f och = moch := Some och in
140 | Some och -> ML.close_out C.start och
143 if !L.level > 0 then T.gmtime version_string;
145 L.warn (P.sprintf "Processing file: %s" name);
146 if !L.level > 0 then T.utime_stamp "started";
147 let base_name = Filename.chop_extension (Filename.basename name) in
148 if !meta then set_meta_file base_name;
149 let ich = open_in name in
150 let lexbuf = Lexing.from_channel ich in
151 let book = AutParser.book AutLexer.token lexbuf in
153 if !L.level > 0 then T.utime_stamp "parsed";
154 let rec aux st = function
162 L.warn (P.sprintf "[%u] %s" i (U.string_of_uri u));
167 let st = count_entity st entity in
168 if !export then export_entity !si !graph entity;
169 if !stage > 2 then type_check f st !si !graph entity else st
172 let f st mst entity =
174 mst = mst; mc = count MO.count_entity st.mc entity
176 begin match !moch with
178 | Some och -> ML.write_entity C.start och entity
180 if !stage > 1 then kernel_of_meta f st entity else st
183 let st = {st with ac = count AO.count_entity st.ac entity} in
186 if !stage > 0 then MA.meta_of_aut (f st) st.mst entity else st
190 if !process then process_entity f st entity else f st entity
192 O.clear_reductions ();
193 let cover = if !use_cover then base_name else "" in
194 let st = aux (initial_status cover) book in
195 if !L.level > 0 then T.utime_stamp "processed";
196 if !L.level > 2 then AO.print_counters C.start st.ac;
197 if !L.level > 2 && !process then AO.print_process_counters C.start st.ast;
198 if !L.level > 2 && !stage > 0 then MO.print_counters C.start st.mc;
199 if !L.level > 2 && !stage > 1 then print_counters st;
200 if !L.level > 2 && !stage > 1 then O.print_reductions ()
204 if !L.level > 0 then T.utime_stamp "at exit";
208 "Usage: helena [ -Vcijmpux | -Ss <number> | -hk <string> ] <file> ...\n\n" ^
209 "Summary levels: 0 just errors (default), 1 time stamps, 2 processed file names, \
210 3 data information, 4 typing information, 5 reduction information\n\n" ^
211 "Stages: 0 parsing, 1 to intermediate, 2 to untrusted, 3 to trusted (default)\n"
213 let help_S = "<number> set summary level (see above)" in
214 let help_V = " show version information" in
216 let help_c = " output conversion constraints" in
217 let help_h = "<string> set type hierarchy (default: Z2)" in
218 let help_i = " show local references by index" in
219 let help_j = " show URI of processed kernel objects" in
220 let help_k = "<string> set kernel version (default: brg)" in
221 let help_m = " output intermediate representation (HAL)" in
222 let help_p = " preprocess Automath source" in
223 let help_r = " disable initial segment of URI hierarchy" in
224 let help_s = "<number> set translation stage (see above)" in
225 let help_u = " activate sort inclusion" in
226 let help_x = " export kernel objects (XML)" in
227 L.box 0; L.box_err ();
228 H.set_sorts ignore ["Set"; "Prop"] 0;
231 ("-S", Arg.Int set_summary, help_S);
232 ("-V", Arg.Unit print_version, help_V);
233 ("-c", Arg.Set cc, help_c);
234 ("-h", Arg.String set_hierarchy, help_h);
235 ("-i", Arg.Set O.indexes, help_i);
236 ("-j", Arg.Set progress, help_j);
237 ("-k", Arg.String set_kernel, help_k);
238 ("-m", Arg.Set meta, help_m);
239 ("-p", Arg.Set process, help_p);
240 ("-r", Arg.Clear use_cover, help_r);
241 ("-s", Arg.Int set_stage, help_s);
242 ("-u", Arg.Set si, help_u);
243 ("-x", Arg.Set export, help_x)
245 with BagT.TypeError msg -> bag_error "Type Error" msg