Changeset 1291 for Deliverables/D2.2/8051-indexed-labels-branch/src/clight
- Timestamp:
- Oct 5, 2011, 10:20:41 AM (9 years ago)
- Location:
- Deliverables/D2.2/8051-indexed-labels-branch
- Files:
-
- 6 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
Deliverables/D2.2/8051-indexed-labels-branch/src/clight/clight.mli
r818 r1291 113 113 | Eorbool of expr*expr (**r sequential or ([||]) *) 114 114 | Esizeof of ctype (**r size of a type *) 115 | Efield of expr*ident 115 | Efield of expr*ident (**r access to a member of a struct or union *) 116 116 117 117 (** The following constructors are used by the annotation process only. *) 118 118 119 | Ecost of CostLabel.t *expr (**r cost label. *)119 | Ecost of CostLabel.t * expr (**r cost label. *) 120 120 | Ecall of ident * expr * expr 121 121 -
Deliverables/D2.2/8051-indexed-labels-branch/src/clight/clightAnnotator.ml
r818 r1291 25 25 Label.Set.union user_labels1 user_labels2) 26 26 27 let empty_triple = (StringTools.Set.empty, CostLabel.Set.empty, Label.Set.empty) 27 let empty_triple = 28 (StringTools.Set.empty, CostLabel.Set.empty, Label.Set.empty) 28 29 29 30 let name_singleton id = 30 31 (StringTools.Set.singleton id, CostLabel.Set.empty, Label.Set.empty) 31 32 32 let cost_label_singleton cost_lbl =33 (StringTools.Set.empty, CostLabel.Set.singleton cost_lbl, Label.Set.empty)33 let cost_label_singleton lbl = 34 (StringTools.Set.empty, CostLabel.Set.singleton lbl, Label.Set.empty) 34 35 35 36 let label_singleton lbl = … … 77 78 (StringTools.Set.union vars names, cost_labels, user_labels) 78 79 | Clight.External (id, _, _) -> 79 (StringTools.Set.singleton id, CostLabel.Set.empty, Label.Set.empty) in 80 (StringTools.Set.singleton id, CostLabel.Set.empty, 81 Label.Set.empty) in 80 82 let fun_idents (id, f_def) = 81 83 let (names, cost_labels, user_labels) = def_idents f_def in … … 93 95 let all_labels p = 94 96 let (_, cost_labels, user_labels) = prog_idents p in 95 let all = 96 CostLabel.Set.fold (fun lbl lbls -> StringTools.Set.add lbl lbls) 97 cost_labels StringTools.Set.empty in 98 Label.Set.fold (fun lbl lbls -> StringTools.Set.add lbl lbls) user_labels all 97 let f lbl = StringTools.Set.add (CostLabel.string_of_cost_label lbl) in 98 let all = CostLabel.Set.fold f cost_labels StringTools.Set.empty in 99 Label.Set.fold StringTools.Set.add user_labels all 99 100 100 101 let all_idents p = 101 102 let (names, cost_labels, user_labels) = prog_idents p in 103 let f lbl = StringTools.Set.add (CostLabel.string_of_cost_label lbl) in 104 let cost_labels = CostLabel.Set.fold f cost_labels StringTools.Set.empty in 102 105 let to_string_set fold set = 103 106 fold (fun lbl idents -> StringTools.Set.add lbl idents) set 104 107 StringTools.Set.empty in 105 let cost_labels = to_string_set CostLabel.Set.fold cost_labels in106 108 let user_labels = to_string_set Label.Set.fold user_labels in 107 109 StringTools.Set.union names (StringTools.Set.union cost_labels user_labels) -
Deliverables/D2.2/8051-indexed-labels-branch/src/clight/clightAnnotator.mli
r818 r1291 6 6 Then, each cost label in the program is replaced by an increment of the cost 7 7 variable, following the mapping [cost_map]. The function also returns the 8 name of the cost variable and the name of the cost increment function. *) 9 8 name of the cost variable and the name of the cost increment function. 9 10 TODO: int to expressions *) 10 11 val instrument : Clight.program -> int CostLabel.Map.t -> 11 12 Clight.program * string * string -
Deliverables/D2.2/8051-indexed-labels-branch/src/clight/clightInterpret.ml
r818 r1291 104 104 | Esizeof ty -> "sizeof(" ^ (string_of_ctype ty) ^ ")" 105 105 | Efield (e, field) -> "(" ^ (string_of_expr e) ^ ")." ^ field 106 | Ecost (cost_lbl, e) -> "/* " ^ cost_lbl ^ " */ " ^ (string_of_expr e) 106 | Ecost (cost_lbl, e) -> 107 let cost_lbl = CostLabel.string_of_cost_label cost_lbl in 108 "/* " ^ cost_lbl ^ " */ " ^ (string_of_expr e) 107 109 | Ecall (f, arg, e) -> 108 110 "(" ^ f ^ "(" ^ (string_of_expr arg) ^ "), " ^ (string_of_expr e) ^ ")" … … 129 131 | Slabel (lbl, _) -> "label " ^ lbl 130 132 | Sgoto lbl -> "goto " ^ lbl 131 | Scost (lbl, _) -> "cost " ^ lbl 133 | Scost (lbl, _) -> 134 let lbl = CostLabel.string_of_cost_label lbl in 135 "cost " ^ lbl 132 136 133 137 let string_of_local_env lenv = -
Deliverables/D2.2/8051-indexed-labels-branch/src/clight/clightLabelling.ml
r818 r1291 6 6 7 7 8 (* Add a cost label in front of a statement . *)8 (* Add a cost label in front of a statement with the current indexing. *) 9 9 10 let add_starting_cost_label cost_universe stmt =11 Clight.Scost (CostLabel. Gen.freshcost_universe, stmt)10 let add_starting_cost_label indexing cost_universe stmt = 11 Clight.Scost (CostLabel.fresh indexing cost_universe, stmt) 12 12 13 13 (* Add a cost label at the end of a statement. *) 14 14 15 let add_ending_cost_label cost_universe stmt = 16 Clight.Ssequence (stmt, add_starting_cost_label cost_universe Clight.Sskip) 15 let add_ending_cost_label indexing cost_universe stmt = 16 let lbld_skip = add_starting_cost_label indexing cost_universe Clight.Sskip in 17 Clight.Ssequence (stmt, lbld_skip) 17 18 18 19 … … 24 25 25 26 26 let add_cost_label_e cost_universe e =27 Expr (Ecost (CostLabel. Gen.freshcost_universe, e), typeof e)27 let add_cost_label_e indexing cost_universe e = 28 Expr (Ecost (CostLabel.fresh indexing cost_universe, e), typeof e) 28 29 29 30 30 31 (* Add cost labels to an expression. *) 31 32 32 let rec add_cost_labels_e cost_universe = function33 | Expr (exp,cty) -> Expr (add_cost_labels_expr cost_universe exp,cty)33 let rec add_cost_labels_e ind cost_universe = function 34 | Expr (exp,cty) -> Expr (add_cost_labels_expr ind cost_universe exp,cty) 34 35 35 and add_cost_labels_expr cost_universe exp = match exp with36 and add_cost_labels_expr ind cost_universe exp = match exp with 36 37 | Econst_int _ | Econst_float _ | Evar _ | Esizeof _ -> exp 37 | Ederef e -> Ederef (add_cost_labels_e cost_universe e)38 | Eaddrof e -> Eaddrof (add_cost_labels_e cost_universe e)39 | Eunop (op,e) -> Eunop (op,(add_cost_labels_e cost_universe e))38 | Ederef e -> Ederef (add_cost_labels_e ind cost_universe e) 39 | Eaddrof e -> Eaddrof (add_cost_labels_e ind cost_universe e) 40 | Eunop (op,e) -> Eunop (op,(add_cost_labels_e ind cost_universe e)) 40 41 | Ebinop (op,e1,e2) -> 41 42 Ebinop (op, 42 add_cost_labels_e cost_universe e1,43 add_cost_labels_e cost_universe e2)44 | Ecast (t,e) -> Ecast (t, add_cost_labels_e cost_universe e)43 add_cost_labels_e ind cost_universe e1, 44 add_cost_labels_e ind cost_universe e2) 45 | Ecast (t,e) -> Ecast (t, add_cost_labels_e ind cost_universe e) 45 46 | Eandbool (e1,e2) -> 46 let e1' = add_cost_labels_e cost_universe e1 in47 let e2' = add_cost_labels_e cost_universe e2 in48 let b1 = add_cost_label_e cost_universe (const_int 1) in49 let b2 = add_cost_label_e cost_universe (const_int 0) in47 let e1' = add_cost_labels_e ind cost_universe e1 in 48 let e2' = add_cost_labels_e ind cost_universe e2 in 49 let b1 = add_cost_label_e ind cost_universe (const_int 1) in 50 let b2 = add_cost_label_e ind cost_universe (const_int 0) in 50 51 let e2' = Expr (Econdition (e2', b1, b2), int_type) in 51 let e2' = add_cost_label_e cost_universe e2' in52 let e3' = add_cost_label_e cost_universe (const_int 0) in52 let e2' = add_cost_label_e ind cost_universe e2' in 53 let e3' = add_cost_label_e ind cost_universe (const_int 0) in 53 54 Econdition (e1', e2', e3') 54 55 | Eorbool (e1,e2) -> 55 let e1' = add_cost_labels_e cost_universe e1 in56 let e2' = add_cost_label_e cost_universe (const_int 1) in57 let e3' = add_cost_labels_e cost_universe e2 in58 let b1 = add_cost_label_e cost_universe (const_int 1) in59 let b2 = add_cost_label_e cost_universe (const_int 0) in56 let e1' = add_cost_labels_e ind cost_universe e1 in 57 let e2' = add_cost_label_e ind cost_universe (const_int 1) in 58 let e3' = add_cost_labels_e ind cost_universe e2 in 59 let b1 = add_cost_label_e ind cost_universe (const_int 1) in 60 let b2 = add_cost_label_e ind cost_universe (const_int 0) in 60 61 let e3' = Expr (Econdition (e3', b1, b2), int_type) in 61 let e3' = add_cost_label_e cost_universe e3' in62 let e3' = add_cost_label_e ind cost_universe e3' in 62 63 Econdition (e1', e2', e3') 63 | Efield (e,id) -> Efield (add_cost_labels_e cost_universe e,id)64 | Efield (e,id) -> Efield (add_cost_labels_e ind cost_universe e,id) 64 65 | Econdition (e1,e2,e3) -> 65 let e1' = add_cost_labels_e cost_universe e1 in66 let e2' = add_cost_labels_e cost_universe e2 in67 let e2' = add_cost_label_e cost_universe e2' in68 let e3' = add_cost_labels_e cost_universe e3 in69 let e3' = add_cost_label_e cost_universe e3' in66 let e1' = add_cost_labels_e ind cost_universe e1 in 67 let e2' = add_cost_labels_e ind cost_universe e2 in 68 let e2' = add_cost_label_e ind cost_universe e2' in 69 let e3' = add_cost_labels_e ind cost_universe e3 in 70 let e3' = add_cost_label_e ind cost_universe e3' in 70 71 Econdition (e1', e2', e3') 71 72 | Ecost (_,_) | Ecall _ -> assert false (* Should not happen *) 72 73 73 let add_cost_labels_opt cost_universe = function 74 | None -> None 75 | Some e -> Some (add_cost_labels_e cost_universe e) 74 let add_cost_labels_opt ind cost_universe = 75 Option.map (add_cost_labels_e ind cost_universe) 76 76 77 let add_cost_labels_lst cost_universe l =78 List.map (add_cost_labels_e cost_universe) l77 let add_cost_labels_lst ind cost_universe l = 78 List.map (add_cost_labels_e ind cost_universe) l 79 79 80 80 81 81 (* Add cost labels to a statement. *) 82 82 83 let rec add_cost_labels_st cost_universe = function83 let rec add_cost_labels_st ind cost_universe = function 84 84 | Sskip -> Sskip 85 85 | Sassign (e1,e2) -> 86 Sassign (add_cost_labels_e cost_universe e1,87 add_cost_labels_e cost_universe e2)86 Sassign (add_cost_labels_e ind cost_universe e1, 87 add_cost_labels_e ind cost_universe e2) 88 88 | Scall (e1,e2,lst) -> 89 Scall (add_cost_labels_opt cost_universe e1,90 add_cost_labels_e cost_universe e2,91 add_cost_labels_lst cost_universe lst)89 Scall (add_cost_labels_opt ind cost_universe e1, 90 add_cost_labels_e ind cost_universe e2, 91 add_cost_labels_lst ind cost_universe lst) 92 92 | Ssequence (s1,s2) -> 93 Ssequence (add_cost_labels_st cost_universe s1,94 add_cost_labels_st cost_universe s2)93 Ssequence (add_cost_labels_st ind cost_universe s1, 94 add_cost_labels_st ind cost_universe s2) 95 95 | Sifthenelse (e,s1,s2) -> 96 let s1' = add_cost_labels_st cost_universe s1 in97 let s1' = add_starting_cost_label cost_universe s1' in98 let s2' = add_cost_labels_st cost_universe s2 in99 let s2' = add_starting_cost_label cost_universe s2' in100 Sifthenelse (add_cost_labels_e cost_universe e, s1', s2')96 let s1' = add_cost_labels_st ind cost_universe s1 in 97 let s1' = add_starting_cost_label ind cost_universe s1' in 98 let s2' = add_cost_labels_st ind cost_universe s2 in 99 let s2' = add_starting_cost_label ind cost_universe s2' in 100 Sifthenelse (add_cost_labels_e ind cost_universe e, s1', s2') 101 101 | Swhile (e,s) -> 102 let s' = add_cost_labels_st cost_universe s in103 let s' = add_starting_cost_label cost_universe s' in104 add_ending_cost_label cost_universe105 (Swhile (add_cost_labels_e cost_universe e, s'))102 let s' = add_cost_labels_st ind cost_universe s in 103 let s' = add_starting_cost_label ind cost_universe s' in 104 add_ending_cost_label ind cost_universe 105 (Swhile (add_cost_labels_e ind cost_universe e, s')) 106 106 | Sdowhile (e,s) -> 107 let s1 = add_cost_labels_st cost_universe s in108 let s2 = add_cost_labels_st cost_universe s in109 let s2' = add_starting_cost_label cost_universe s2 in110 add_ending_cost_label cost_universe111 (Ssequence (s1, Swhile (add_cost_labels_e cost_universe e, s2')))107 let s1 = add_cost_labels_st ind cost_universe s in 108 let s2 = add_cost_labels_st ind cost_universe s in 109 let s2' = add_starting_cost_label ind cost_universe s2 in 110 add_ending_cost_label ind cost_universe 111 (Ssequence (s1, Swhile (add_cost_labels_e ind cost_universe e, s2'))) 112 112 | Sfor (s1,e,s2,s3) -> 113 let s1' = add_cost_labels_st cost_universe s1 in114 let s2' = add_cost_labels_st cost_universe s2 in115 let s3' = add_cost_labels_st cost_universe s3 in116 let s3' = add_starting_cost_label cost_universe s3' in117 add_ending_cost_label cost_universe118 (Sfor (s1', add_cost_labels_e cost_universe e, s2', s3'))119 | Sreturn e -> Sreturn (add_cost_labels_opt cost_universe e)113 let s1' = add_cost_labels_st ind cost_universe s1 in 114 let s2' = add_cost_labels_st ind cost_universe s2 in 115 let s3' = add_cost_labels_st ind cost_universe s3 in 116 let s3' = add_starting_cost_label ind cost_universe s3' in 117 add_ending_cost_label ind cost_universe 118 (Sfor (s1', add_cost_labels_e ind cost_universe e, s2', s3')) 119 | Sreturn e -> Sreturn (add_cost_labels_opt ind cost_universe e) 120 120 | Sswitch (e,ls) -> 121 Sswitch (add_cost_labels_e cost_universe e,122 add_cost_labels_ls cost_universe ls)121 Sswitch (add_cost_labels_e ind cost_universe e, 122 add_cost_labels_ls ind cost_universe ls) 123 123 | Slabel (lbl,s) -> 124 let s' = add_cost_labels_st cost_universe s in125 let s' = add_starting_cost_label cost_universe s' in124 let s' = add_cost_labels_st ind cost_universe s in 125 let s' = add_starting_cost_label ind cost_universe s' in 126 126 Slabel (lbl,s') 127 127 | Scost (_,_) -> assert false 128 128 | _ as stmt -> stmt 129 129 130 and add_cost_labels_ls cost_universe = function130 and add_cost_labels_ls ind cost_universe = function 131 131 | LSdefault s -> 132 let s' = add_cost_labels_st cost_universe s in133 let s' = add_starting_cost_label cost_universe s' in132 let s' = add_cost_labels_st ind cost_universe s in 133 let s' = add_starting_cost_label ind cost_universe s' in 134 134 LSdefault s' 135 135 | LScase (i,s,ls) -> 136 let s' = add_cost_labels_st cost_universe s in137 let s' = add_starting_cost_label cost_universe s' in138 LScase (i, s', add_cost_labels_ls cost_universe ls)136 let s' = add_cost_labels_st ind cost_universe s in 137 let s' = add_starting_cost_label ind cost_universe s' in 138 LScase (i, s', add_cost_labels_ls ind cost_universe ls) 139 139 140 140 141 141 (* Add cost labels to a function. *) 142 142 143 let add_cost_labels_f cost_universe = function143 let add_cost_labels_f ind cost_universe = function 144 144 | (id,Internal fd) -> (id,Internal { 145 145 fn_return = fd.fn_return ; 146 146 fn_params = fd.fn_params ; 147 147 fn_vars = fd.fn_vars ; 148 fn_body = add_starting_cost_label cost_universe149 (add_cost_labels_st cost_universe fd.fn_body)148 fn_body = add_starting_cost_label ind cost_universe 149 (add_cost_labels_st ind cost_universe fd.fn_body) 150 150 }) 151 151 | (id,External (a,b,c)) -> (id,External (a,b,c)) … … 157 157 let add_cost_labels p = 158 158 let labs = ClightAnnotator.all_labels p in 159 let labs = StringTools.Set.fold CostLabel.Set.add labs CostLabel.Set.empty in 160 let cost_prefix = CostLabel.Gen.fresh_prefix labs "_cost" in 161 let cost_universe = CostLabel.Gen.new_universe cost_prefix in 159 let add = CostLabel.Atom.Set.add in 160 let empty = CostLabel.Atom.Set.empty in 161 let labs = StringTools.Set.fold add labs empty in 162 let cost_prefix = CostLabel.Atom.Gen.fresh_prefix labs "_cost" in 163 let cost_universe = CostLabel.Atom.Gen.new_universe cost_prefix in 164 let ind = CostLabel.Indexing.empty in 162 165 { 163 prog_funct = List.map (add_cost_labels_f cost_universe) p.prog_funct;166 prog_funct = List.map (add_cost_labels_f ind cost_universe) p.prog_funct; 164 167 prog_main = p.prog_main; 165 168 prog_vars = p.prog_vars -
Deliverables/D2.2/8051-indexed-labels-branch/src/clight/clightPrinter.ml
r818 r1291 196 196 | Efield(e1, id) -> 197 197 fprintf p "%a.%s" print_expr_prec (level, e1) id 198 | Ecost (lbl,e1) -> 199 fprintf p "(/* %s */ %a)" lbl print_expr e1 200 | Ecall (f, arg, e) -> 198 | Ecost(lbl, e1) -> 199 (* printing label uglily even if in comment for consistence *) 200 let lbl = CostLabel.string_of_cost_label lbl in 201 fprintf p "(/* %s */ %a)" lbl print_expr e1 202 | Ecall(f, arg, e) -> 201 203 fprintf p "(%s(%a), %a)" f print_expr arg print_expr e 202 204 … … 272 274 fprintf p "goto %s;" lbl 273 275 | Scost (lbl,s1) -> 276 let lbl = CostLabel.string_of_cost_label lbl in 274 277 fprintf p "%s:@ %a" lbl print_stmt s1 275 278
Note: See TracChangeset
for help on using the changeset viewer.