Project

General

Profile

Download (6.6 KB) Statistics
| Branch: | Tag: | Revision:
1
(* 
2
TODO:
3

    
4
- export du tube sur la tete de boucle:
5
  - par exemple un tube par dimension en 2d: temps x valeur
6
  - en sage ? en gnuplot? en tikz?
7
  - deux facon de visualiser le partitionnement
8
    - si on choisi un tube 2d, par exemple la variable x, on doit pouvoir visualiser le split du tube en fonction d'une variable booleenne. Par exemple on choisi b1 et on voit deux couleurs sur le tube de x. Ou on se restreint a b1 true ou b1 false 
9
    - on doit aussi pouvoir afficher globalement pour une variable booleen le split. On choisi par exemple b1 de facon gloable et tous les tubes sont raffines en b1 true / b1 false / b1 both / b1 split enfin pour avoir deux plots separes.
10

    
11
   - par exemple un csv
12
   nb_temps, x_min, x_max, y_min, y_max, b1_true_x_min, b1_true_x_max, b1_true_y_min, b1_true_y_max, ....
13

    
14

    
15
  - 
16
- export de l'ast en latex avec des instructions tikz puis ensuite l'affichage des elements abstraits a chaque point de programme pour les articles. On peut desactiver ou activer les domaines grace aux options
17

    
18
*)
19

    
20

    
21
let pp_var fmt ((n,t),ctx) =
22
  (* Tiny.Ast.Var.pp_ fmt v *)
23
  match ctx with
24
  | None ->
25
    Format.fprintf fmt "%s" n  
26
  | Some ((bv, _),b) ->
27
     Format.fprintf fmt "%s __ %s = %b" n bv b  
28

    
29
  
30
let pp_bound fmt b = Tiny.Scalar.pp fmt b 
31

    
32
module type S =
33
  sig
34
    module Results: Tiny.Analyze.Results
35
    val list: (int * Results.Dom.t) list
36
    val bounds:  ((Tiny.Ast.Var.t * (Tiny.Ast.Var.t * bool) option) * (Tiny.Scalar.t * Tiny.Scalar.t)) list
37
  end
38
  
39
let process env ast results =
40
  let module Results = (val results: Tiny.Analyze.Results) in
41
  let module Dom = Results.Dom in
42
  let module PrintResults = Tiny.PrintResults.Make (Dom) in
43
  let m = Results.results in
44
  
45
  let while_loc = Tiny.Ast.get_main_while_loc ast in
46
  let list = PrintResults.get_unrolled_info m while_loc in
47
  let join =
48
    match list with
49
    | [] -> Dom.bottom env
50
    | (_,hd)::tl -> List.fold_left (fun accu (_,e) -> Dom.join accu e) hd tl
51
  in
52
  let bounds = Dom.to_bounds join in
53
  let module M = struct
54
      module Results = Results
55
      module PrintResults = PrintResults
56
      let list = list
57
      let bounds = bounds
58
    end
59
  in
60
  (module M: S)
61
  (*                 
62
let build f_header f_content env ast results =
63
  let module Results = (val results: Tiny.Analyze.Results) in
64
  let module Dom = Results.Dom in
65
  let module PrintResults = Tiny.PrintResults.Make (Dom) in
66
  let m = Results.results in
67
  
68
  let while_loc = Tiny.Ast.get_main_while_loc ast in
69
  let list = PrintResults.get_unrolled_info m while_loc in
70
  let join =
71
    match list with
72
    | [] -> Dom.bottom env
73
    | (_,hd)::tl -> List.fold_left (fun accu (_,e) -> Dom.join accu e) hd tl
74
  in
75
  let bounds = Dom.to_bounds join in
76
  f_header bounds;
77
  f_content list
78
  *)
79

    
80
let pp_bounds fmt bounds =
81
  List.iter (fun ((v,ctx) as x, (min, max)) ->
82
      
83
      Format.fprintf fmt
84
        "%a in %a,%a@."
85
        pp_var x
86
        pp_bound min
87
        pp_bound max)
88
    bounds
89
  
90
let pp env ast results fmt =
91
  let m = process env ast results in
92
  let module M = (val m: S) in
93
  pp_bounds fmt  M.bounds;
94
  Format.fprintf fmt "Tube: %i@." (List.length M.list);
95
  List.iter (fun (idx, elem) ->
96
      Format.fprintf fmt "%i -> %a@." idx M.Results.Dom.fprint elem) M.list
97

    
98
let export env ast results fmt =
99
  let m = process env ast results in
100
  let module M = (val m: S) in
101
  List.iter (fun (x, (min, max)) ->
102
      Format.fprintf fmt
103
        "%a in %a,%a@."
104
        pp_var x
105
        pp_bound min
106
        pp_bound max)
107
    M.bounds;
108
  Format.fprintf fmt "Tube: %i@." (List.length M.list);
109
  List.iter (fun (idx, elem) ->
110
      Format.fprintf fmt
111
        "%i -> %a@."
112
        idx
113
        pp_bounds (M.Results.Dom.to_bounds elem)
114
    ) M.list
115

    
116
let export_to_wide_csv  env ast results fmt =
117
  let m = process env ast results in
118
  let module M = (val m: S) in
119
  let bounds = List.map (fun (idx, elem) -> idx, M.Results.Dom.to_bounds elem) M.list in
120
  (* Gather all variable ids *)
121
  let module VarIdSet = Set.Make (
122
                         struct
123
                           type t = Tiny.Ast.Var.t * (Tiny.Ast.Var.t * bool) option
124
                           let compare = compare
125
                         end)
126
  in
127
  let var_ids = List.fold_left (
128
                    fun accu (_, bounds) ->
129
                    List.fold_left (fun accu (vctx, _) -> VarIdSet.add vctx accu) accu bounds
130
                  ) VarIdSet.empty bounds
131
  in
132
  let ordered_list = VarIdSet.elements var_ids in
133
  Format.fprintf fmt "timestep,%a@."
134
    (Utils.fprintf_list ~sep:","
135
       (fun fmt ((n,_),ctx) ->
136
         let pp fmt =
137
           match ctx with
138
             None ->
139
              Format.fprintf fmt "%s" n
140
           | Some ((bn,_),b) ->
141
              Format.fprintf fmt "%s_//%s_eq_%b" n bn b
142
         in
143
         Format.fprintf fmt "%t_min,%t_max" pp pp
144
    ))
145
    ordered_list;
146
  Format.fprintf fmt "%a@."
147
    (Utils.fprintf_list ~sep:"@."
148
    (fun fmt (idx, bounds_idx) ->
149
      Format.fprintf fmt "@[<h 0>%i, %a@]"
150
        idx
151
        (Utils.fprintf_list ~sep:", "
152
           (fun fmt (min_, max_) ->
153
             let pp_bound fmt b = match b with
154
               | None -> Format.fprintf fmt ","
155
               | Some b -> Tiny.Scalar.pp fmt b
156
             in
157
             Format.fprintf fmt "%a, %a" pp_bound min_ pp_bound max_))
158
        (List.map (fun v -> if List.mem_assoc v bounds_idx then
159
                              let min_, max_ = List.assoc v bounds_idx in
160
                              Some min_, Some max_
161
                            else
162
                              None, None
163
           ) ordered_list)
164
    ))
165
    bounds;
166
  ()
167

    
168

    
169
let export_to_csv  env ast results fmt =
170
  let m = process env ast results in
171
  let module M = (val m: S) in
172
  let bounds = List.map (fun (idx, elem) ->
173
                   idx,
174
                   try M.Results.Dom.to_bounds elem with Tiny.Relational.BotEnv -> Format.eprintf "Issues exporting env %a to bounds: bottom!@." M.Results.Dom.fprint elem; assert false
175
                 ) M.list
176
  in
177
  (* Gather all variable ids *)
178
  let pp_vctx fmt ((n,t), ctx ) =
179
    match ctx with
180
    | None -> Format.fprintf fmt "%s,%a,," n (Tiny.Ast.pp_base_type) t
181
    | Some ((bname,_ (* type should be bool *) ), bval) ->
182
        Format.fprintf fmt "%s,%a,%s,%b" n (Tiny.Ast.pp_base_type) t bname bval
183
  in
184
  let pp_bound fmt (min_, max_) =
185
    Format.fprintf fmt "%a,%a" Tiny.Scalar.pp min_ Tiny.Scalar.pp max_
186
  in
187
  Format.fprintf fmt "timestep,varid,type,boolpart,boolval,min,max@.";
188
  Utils.fprintf_list ~sep:"@." (
189
      fun fmt (idx, idx_bounds) ->
190
      Utils.fprintf_list ~sep:"@." (fun fmt (vctx, vctx_bound) ->
191
          Format.fprintf fmt "%i,%a,%a" idx pp_vctx vctx pp_bound vctx_bound
192
        ) fmt idx_bounds
193
    ) fmt bounds
194

    
195
  
(1-1/3)