source: Deliverables/D2.2/8051/cparser/Parse.ml @ 486

Last change on this file since 486 was 486, checked in by ayache, 9 years ago

Deliverable D2.2

File size: 2.4 KB
Line 
1(* *********************************************************************)
2(*                                                                     *)
3(*              The Compcert verified compiler                         *)
4(*                                                                     *)
5(*          Xavier Leroy, INRIA Paris-Rocquencourt                     *)
6(*                                                                     *)
7(*  Copyright Institut National de Recherche en Informatique et en     *)
8(*  Automatique.  All rights reserved.  This file is distributed       *)
9(*  under the terms of the GNU General Public License as published by  *)
10(*  the Free Software Foundation, either version 2 of the License, or  *)
11(*  (at your option) any later version.  This file is also distributed *)
12(*  under the terms of the INRIA Non-Commercial License Agreement.     *)
13(*                                                                     *)
14(* *********************************************************************)
15
16(* Entry point for the library: parse, elaborate, and transform *)
17
18module CharSet = Set.Make(struct type t = char let compare = compare end)
19
20let transform_program t p =
21  let run_pass pass flag p = if CharSet.mem flag t then pass p else p in
22  Rename.program
23  (run_pass (AddCasts.program ~all:(CharSet.mem 'C' t)) 'c'
24  (run_pass StructAssign.program 'S'
25  (run_pass StructByValue.program 's'
26  (run_pass Bitfields.program 'f'
27  (run_pass (SimplExpr.program ~volatile:(CharSet.mem 'v' t)) 'e'
28  (run_pass Unblock.program 'b'
29  p))))))
30
31let parse_transformations s =
32  let t = ref CharSet.empty in
33  let set s = String.iter (fun c -> t := CharSet.add c !t) s in
34  String.iter
35    (function 'b' -> set "b"
36            | 'e' -> set "e"
37            | 'c' -> set "ec"
38            | 'C' -> set "ecC"
39            | 's' -> set "s"
40            | 'S' -> set "esS"
41            | 'v' -> set "ev"
42            | 'f' -> set "bef"
43            |  _  -> ())
44    s;
45  !t
46
47let preprocessed_file transfs name sourcefile =
48  Errors.reset();
49  let t = parse_transformations transfs in
50  let ic = open_in sourcefile in
51  let p =
52    try
53      Rename.program (transform_program t (Elab.elab_preprocessed_file name ic))
54    with Parsing.Parse_error ->
55           Errors.error "Error during parsing"; []
56       | Errors.Abort ->
57           [] in
58  close_in ic;
59  if Errors.check_errors() then None else Some p
Note: See TracBrowser for help on using the repository browser.