source: Deliverables/D2.2/8051/src/clight/clightParser.ml @ 486

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

Deliverable D2.2

File size: 823 bytes
Line 
1let process file = 
2  let tmp_file = Filename.temp_file "cparser" ".i" 
3  and prepro_opts = [] in
4
5  (* Preprocessing *)
6  Cparser.Builtins.set Cparser.GCC.builtins;
7  let rc = Sys.command
8    (Printf.sprintf "gcc -E -U__GNUC__ %s %s > %s"
9       (String.concat " " (List.map Filename.quote prepro_opts))
10       (Filename.quote file) (Filename.quote tmp_file)) in
11  if rc <> 0 then (
12    Misc.SysExt.safe_remove tmp_file; failwith "Error calling gcc."
13  );
14
15  (* C to Cil *)
16  let r = Cparser.Parse.preprocessed_file "CSf" file tmp_file in
17  Misc.SysExt.safe_remove tmp_file;
18  match r with
19    | None -> failwith "Error during C parsing."
20    | Some p ->
21      (* Cil to Clight *)
22      (match ClightFromC.convertProgram p with
23        | None -> failwith "Error during C to Clight pass."
24        | Some(pp) -> pp
25      ) 
Note: See TracBrowser for help on using the repository browser.