Project

General

Profile

Download (5.06 KB) Statistics
| Branch: | Tag: | Revision:
1

    
2
let active = ref false
3
let tiny_debug = ref false
4
let tiny_help = ref false
5
let descending = ref 1
6
let unrolling = ref 0
7

    
8

    
9
              
10
let quiet () = Tiny.Report.verbosity := 0
11
             
12
let print_tiny_help () =
13
  let open Format in
14
  Format.eprintf "@[Tiny verifier plugin produces a simple imperative code \
15
          output for the provided main node, inlining all calls. This \
16
          code can then be analyzed using tiny analyzer options.@]";
17
  Format.eprintf "@.@?";
18
  flush stdout
19

    
20
  
21
let tiny_run ~basename prog machines =
22
  if !tiny_help then (
23
    let _ = print_tiny_help () in
24
    exit 0
25
  );
26
  let node_name =
27
    match !Options.main_node with
28
    | "" -> (
29
      Format.eprintf "Tiny verifier requires a main node.@.";
30
      Format.eprintf "@[<v 2>Available ones are:@ %a@]@.@?"
31
        (Utils.fprintf_list ~sep:"@ "
32
           (fun fmt m ->
33
             Format.fprintf fmt "%s" m.Machine_code_types.mname.node_id
34
           )
35
        )
36
        machines; 
37
      exit 1
38
    )
39
    | s -> ( (* should have been addessed before *)
40
      match Machine_code_common.get_machine_opt machines s with
41
      | None -> begin
42
          Global.main_node := s;
43
          Format.eprintf "Code generation error: %a@." Error.pp_error_msg Error.Main_not_found;
44
          raise (Error.Error (Location.dummy_loc, Error.Main_not_found))
45
        end
46
      | Some _ -> s
47
    )
48
  in
49
  let m = Machine_code_common.get_machine machines node_name in
50
  let env = (* We add each variables of the node the Tiny env *)
51
    Tiny_utils.machine_to_env m in
52
  let nd = m.mname in
53
  (* Building preamble with some bounds on inputs *)
54
  (* TODO: deal woth contracts, asserts, ... *)
55
  let bounds_inputs = [] in
56
  let ast = Tiny_utils.machine_to_ast bounds_inputs m in
57
  let mems = m.mmemory in
58
  
59
   Format.printf "%a@." Tiny.Ast.fprint_stm ast; 
60

    
61
   let dom =
62
     let open Tiny.Load_domains in
63
     prepare_domains (List.map get_domain !domains)
64
   in
65
   let results = Tiny.Analyze.analyze dom !descending !unrolling env ast in
66
   let module Results = (val results: Tiny.Analyze.Results) in
67
   let module Dom = Results.Dom in
68
   let module PrintResults = Tiny.PrintResults.Make (Dom) in
69
   let m = Results.results in
70
   (* if !Tiny.Report.verbosity > 1 then *)
71
   PrintResults.print m ast None (* no !output_file *);
72
        (* else PrintResults.print_invariants m ast !output_file *)
73

    
74
   ()
75
  
76
  
77
module Verifier =
78
  (struct
79
    include VerifierType.Default
80
    let name = "tiny"
81
    let options =
82
      [
83
        "-debug", Arg.Set tiny_debug, "tiny debug";
84
        ("-abstract-domain", Arg.String Tiny.Load_domains.decl_domain,
85
         "<domain>  Use abstract domain <domain> " ^ Tiny.Domains.available_domains_str);
86
        (* ("-a", Arg.String Tiny.Load_domains.decl_domain,
87
         *  "<domain>  Use abstract domain <domain> " ^ Tiny.Domains.available_domains_str); *)
88
        ("-param", Arg.String Tiny.Load_domains.set_param,
89
         "<p>  Send <p> to the abstract domain, syntax <dom>:<p> can be used \
90
          to target the (sub)domain <dom>");
91
        (* ("-p", Arg.String Tiny.Load_domains.set_param,
92
         *  "<p>  Send <p> to the abstract domain, syntax <dom>:<p> can be used \
93
         *   to target the (sub)domain <dom>"); *)
94
        ("-help-domain", Arg.String Tiny.Load_domains.help_domain,
95
         "<domain>  Print params of <domain>");
96
        (* ("-h", Arg.String Tiny.Load_domains.help_domain, "<domain>  Print params of <domain>"); *)
97
        (* ("--compile", Arg.Set compile_mode, " Compilation mode: compile to C");
98
      ("-c", Arg.Set compile_mode,             " Compilation mode: compile to C");*)
99
        
100
        ("-quiet", Arg.Unit quiet, " Quiet mode");
101
        (* ("-q", Arg.Unit quiet, " Quiet mode"); *)
102
        ("-verbose", Arg.Set_int Tiny.Report.verbosity,
103
         "<n>  Verbosity level (default is 1)");
104
        (* ("-v", Arg.Set_int Tiny.Report.verbosity, "<n>  Verbosity level (default is 1)"); *)
105
  (*      ("--output", Arg.String set_output_file,
106
         "<filename> Output results to file <filename> (default is \
107
          standard ouput)");
108
        ("-o", Arg.String set_output_file,
109
         "<filename>  Output results to file <filename> (default is standard ouput)");
110
   *)
111
        ("-descending", Arg.Set_int descending,
112
         "<n>  Perform <n> descending iterations after fixpoint of a loop \
113
          is reached (default is 1)");
114
        (* ("-d", Arg.Set_int descending,
115
         *  "<n>  Perform <n> descending iterations after fixpoint of a loop \
116
         * is reached (default is 1)"); *)
117
      ("-unrolling", Arg.Set_int unrolling,
118
       "<n>  Unroll loops <n> times before computing fixpoint (default is 0)");
119
      (* (\* ("-u", Arg.Set_int unrolling,
120
       *  *  "<n>  Unroll loops <n> times before computing fixpoint (default is 0)"); *\) *)
121
       "-help", Arg.Set tiny_help, "tiny help and usage";
122
        
123
      
124
      ]
125
      
126
    let activate () =
127
      active := true;
128
      (* Options.global_inline := true;
129
       * Options.optimization := 0;
130
       * Options.const_unfold := true; *)
131
      ()
132
      
133
    let is_active () = !active
134
    let run = tiny_run
135
            
136
            
137
  end: VerifierType.S)
138
    
(2-2/2)