Project

General

Profile

Download (6.71 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.Bounds.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, bounds) ->
82
      
83
      Format.fprintf fmt
84
        "%a in %a@."
85
        pp_var x
86
        Tiny.Bounds.pp bounds)
87
    bounds
88
  
89
let pp env ast results fmt =
90
  let m = process env ast results in
91
  let module M = (val m: S) in
92
  pp_bounds fmt  M.bounds;
93
  Format.fprintf fmt "Tube: %i@." (List.length M.list);
94
  List.iter (fun (idx, elem) ->
95
      Format.fprintf fmt "%i -> %a@." idx M.Results.Dom.fprint elem) M.list
96

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

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

    
170

    
171
let export_to_csv  env ast results fmt =
172
  let m = process env ast results in
173
  let module M = (val m: S) in
174
  let bounds = List.map (fun (idx, elem) ->
175
                   idx,
176
                   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
177
                 ) M.list
178
  in
179
  (* Gather all variable ids *)
180
  let pp_vctx fmt ((n,t), ctx ) =
181
    match ctx with
182
    | None -> Format.fprintf fmt "%s,%a,," n (Tiny.Ast.pp_base_type) t
183
    | Some ((bname,_ (* type should be bool *) ), bval) ->
184
        Format.fprintf fmt "%s,%a,%s,%b" n (Tiny.Ast.pp_base_type) t bname bval
185
  in
186
  Format.fprintf fmt "timestep,varid,type,boolpart,boolval,min,max@.";
187
  Utils.fprintf_list ~sep:"@." (
188
      fun fmt (idx, idx_bounds) ->
189
      Utils.fprintf_list ~sep:"@." (fun fmt (vctx, vctx_bound) ->
190
          Format.fprintf fmt "%i,%a,%a" idx pp_vctx vctx Tiny.Bounds.pp vctx_bound
191
        ) fmt idx_bounds
192
    ) fmt bounds
193

    
194
  
(1-1/3)