1 | open Extracted.Errors |
---|
2 | open ClightPrinter |
---|
3 | |
---|
4 | let string_of_pos n = string_of_int (Extracted.Glue.int_of_matitapos n) |
---|
5 | |
---|
6 | let string_of_intensional_event = |
---|
7 | function |
---|
8 | Extracted.StructuredTraces.IEVcost cl -> |
---|
9 | "COST(k_" ^ string_of_pos cl ^") " |
---|
10 | | Extracted.StructuredTraces.IEVcall id -> |
---|
11 | "CALL(fun_" ^ string_of_pos id ^ ") " |
---|
12 | | Extracted.StructuredTraces.IEVtailcall _ -> assert false |
---|
13 | | Extracted.StructuredTraces.IEVret id -> |
---|
14 | "RET(fun_" ^ string_of_pos id ^ ") " |
---|
15 | ;; |
---|
16 | |
---|
17 | let string_of_pass = |
---|
18 | function |
---|
19 | | Extracted.Compiler.Clight_pass -> "Clight_pass" |
---|
20 | | Extracted.Compiler.Clight_switch_removed_pass -> "Clight_switch_removed_pass" |
---|
21 | | Extracted.Compiler.Clight_label_pass -> "Clight_label_pass" |
---|
22 | | Extracted.Compiler.Clight_simplified_pass -> "Clight_simplified_pass" |
---|
23 | | Extracted.Compiler.Cminor_pass -> "Cminor_pass" |
---|
24 | | Extracted.Compiler.Rtlabs_pass -> "Rtlabs_pass" |
---|
25 | | Extracted.Compiler.Rtl_separate_pass -> "Rtl_separate_pass" |
---|
26 | | Extracted.Compiler.Rtl_uniq_pass -> "Rtl_uniq_pass" |
---|
27 | | Extracted.Compiler.Ertl_pass -> "Ertl_pass" |
---|
28 | | Extracted.Compiler.Ertlptr_pass -> "Ertlptr_pass" |
---|
29 | | Extracted.Compiler.Ltl_pass -> "Ltl_pass" |
---|
30 | | Extracted.Compiler.Lin_pass -> "Lin_pass" |
---|
31 | ;; |
---|
32 | |
---|
33 | let argv1 = Sys.argv.(1) in |
---|
34 | let do_print,filename = |
---|
35 | if argv1 = "-exec" then |
---|
36 | true,Sys.argv.(2) |
---|
37 | else |
---|
38 | false,argv1 in |
---|
39 | let cl = ClightParser.process filename in |
---|
40 | let observe = |
---|
41 | if do_print then |
---|
42 | let rec infinity = Extracted.Nat.S infinity in |
---|
43 | (fun pass prog -> |
---|
44 | if pass = Extracted.Compiler.Ltl_pass then |
---|
45 | print_string (BackendPrinter.print_LTL_program (fst (Obj.magic prog))); |
---|
46 | Extracted.Semantics.run_and_print pass prog infinity |
---|
47 | (fun p -> print_endline ("\n" ^ string_of_pass p ^ ":"); Extracted.Types.It) |
---|
48 | (fun evn -> print_string (string_of_intensional_event evn); Extracted.Types.It) |
---|
49 | (fun msg -> print_endline (Error.errormsg msg); Extracted.Types.It) |
---|
50 | (fun n-> print_endline (string_of_int (Extracted.Glue.int_of_bitvector n)); Extracted.Types.It)) |
---|
51 | else (fun _ _ -> Extracted.Types.It) |
---|
52 | in |
---|
53 | let output = |
---|
54 | match Extracted.Compiler.compile observe cl with |
---|
55 | | OK o -> o |
---|
56 | | Error m -> failwith (Error.errormsg m) |
---|
57 | in |
---|
58 | let labelled = output.Extracted.Compiler.c_labelled_clight in |
---|
59 | let l_costmap = output.Extracted.Compiler.c_clight_cost_map in |
---|
60 | let s_costmap = output.Extracted.Compiler.c_stack_cost in |
---|
61 | let style = |
---|
62 | match try Sys.argv.(2) with _ -> "instrumented" with |
---|
63 | | "plain" -> Cost_plain |
---|
64 | | "numbered" -> Cost_numbered (l_costmap,s_costmap) |
---|
65 | | "instrumented" -> Cost_instrumented (l_costmap,s_costmap) |
---|
66 | | x -> failwith ("I have no idea what " ^ x ^ " means") |
---|
67 | in |
---|
68 | print_endline (ClightPrinter.print_program style labelled); |
---|
69 | print_newline (); |
---|
70 | print_endline (ASMPrinter.print_program (Extracted.ASM.oc (Extracted.Compiler.c_labelled_object_code output))); |
---|
71 | |
---|