source: driver/compiler.ml @ 2787

Last change on this file since 2787 was 2787, checked in by campbell, 8 years ago

Output stack costs in driver.

File size: 1.8 KB
Line 
1open Extracted.Errors
2open ClightPrinter
3
4let rec run g s =
5  (match Extracted.RTLabs_semantics.rTLabs_is_final s with
6  | Extracted.Types.None ->
7    (match Extracted.RTLabs_semantics.eval_statement g s with
8    | Extracted.IOMonad.Value x -> run g (Extracted.Types.snd x)
9    | Extracted.IOMonad.Wrong m -> failwith (Error.errormsg m)
10    | _ -> failwith "oh dear")
11  | Extracted.Types.Some r -> r)
12
13let convBool = function
14| Extracted.Bool.True -> true
15| Extracted.Bool.False -> false
16
17let bv_to_int v =
18  let rec aux i v =
19    match v with
20    | Extracted.Vector.VEmpty -> i
21    | Extracted.Vector.VCons (_,b,t) -> aux (2*i + (if convBool b then 1 else 0)) t
22  in aux 0 v
23;;
24
25let cl = ClightParser.process Sys.argv.(1) in
26let OK output = Extracted.Compiler.compile cl in
27let labelled = output.Extracted.Compiler.c_labelled_clight in
28let l_costmap = output.Extracted.Compiler.c_clight_cost_map in
29let s_costmap = output.Extracted.Compiler.c_stack_cost in
30let style =
31  match try Sys.argv.(2) with _ -> "instrumented" with
32  | "plain" -> Cost_plain
33  | "numbered" -> Cost_numbered (l_costmap,s_costmap)
34  | "instrumented" -> Cost_instrumented (l_costmap,s_costmap)
35  | x -> failwith ("I have no idea what " ^ x ^ " means")
36in
37print_endline (ClightPrinter.print_program style labelled);
38print_newline ();
39print_endline (ASMPrinter.print_program (Extracted.ASM.oc (Extracted.Compiler.c_labelled_object_code output)));
40(*
41let OK mid = Extracted.Compiler.front_end cl in
42let rtlabs = Extracted.Types.snd mid in
43let g = Extracted.RTLabs_semantics.make_global0 rtlabs in
44let OK s0 = Extracted.RTLabs_semantics.make_initial_state0 rtlabs in
45let r = run g s0 in
46exit (bv_to_int r)
47
48val compile :
49  Csyntax.clight_program -> ((object_code, costlabel_map1) Types.prod,
50  (Csyntax.clight_program, Label.clight_cost_map) Types.dPair) Types.prod
51  Errors.res
52*)
Note: See TracBrowser for help on using the repository browser.