Changeset 1099 for Deliverables/D2.2/8051/src/clight/clightCasts.ml
 Timestamp:
 Aug 3, 2011, 4:17:41 PM (10 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

Deliverables/D2.2/8051/src/clight/clightCasts.ml
r818 r1099 24 24  _ > Clight.I32 25 25 26 let cmp_intsize cmp size1 size2 = 27 cmp (int_of_intsize size1) (int_of_intsize size2) 28 29 let max_intsize size1 size2 = 30 if (int_of_intsize size1) < (int_of_intsize size2) then size2 else size1 31 32 let intsize_union size1 size2 = 33 intsize_of_int ((int_of_intsize size1) + (int_of_intsize size2)) 26 let op_intsize_no_cast op size1 size2 = 27 op (int_of_intsize size1) (int_of_intsize size2) 28 29 let cmp_intsize cmp size1 size2 = op_intsize_no_cast cmp size1 size2 30 31 let op_intsize op size1 size2 = 32 intsize_of_int (op_intsize_no_cast op size1 size2) 33 34 let max_intsize size1 size2 = op_intsize max size1 size2 35 36 let intsize_union size1 size2 = op_intsize (+) size1 size2 34 37 35 38 let pow2 = MiscPottier.pow 2 … … 62 65 Clight.Tint (size, sign) 63 66 64 65 let type_of_expr (Clight.Expr (_, t)) = t 67 let le_int_type size1 sign1 size2 sign2 = match sign1, sign2 with 68  AST.Unsigned, AST.Signed > cmp_intsize (<) size1 size2 69  AST.Signed, AST.Unsigned > false 70  _ > cmp_intsize (<=) size1 size2 66 71 67 72 let int_type_union t1 t2 = … … 75 80 Clight.Tint (size, sign) 76 81 82 83 (* C types *) 84 85 let type_of_expr (Clight.Expr (_, t)) = t 86 77 87 let cast_if_needed t (Clight.Expr (ed, t') as e) = match t, ed with 78 88  _ when t = t' > e … … 82 92  _ > Clight.Expr (Clight.Ecast (t, e), t) 83 93 84 let rec simplify_binop t binop 85 (Clight.Expr (ed1, t1) as e1) 86 (Clight.Expr (ed2, t2) as e2) = 87 let e1' = simplify_expr e1 in 88 let e2' = simplify_expr e2 in 89 let make_int i t = Clight.Expr (Clight.Econst_int i, t) in 90 91 let (e1', e2', t') = match t1, t2, ed1, ed2 with 92 93  Clight.Tint _, Clight.Tint _, 94 Clight.Econst_int i1, Clight.Econst_int i2 > 95 let t1' = smallest_int_type i1 in 96 let t2' = smallest_int_type i2 in 97 let t' = int_type_union t1' t2' in 98 (make_int i1 t', make_int i2 t', t') 99 100  Clight.Tint _, Clight.Tint _, _, Clight.Econst_int i2 > 101 let t' = type_of_expr e1' in 102 let e2' = make_int i2 t' in 103 (e1', e2', t') 104 105  Clight.Tint _, Clight.Tint _, Clight.Econst_int i1, _ > 106 let t' = type_of_expr e2' in 107 let e1' = make_int i1 t' in 108 (e1', e2', t') 109 110  Clight.Tint _, Clight.Tint _, _, _ > 111 let t' = int_type_union (type_of_expr e1') (type_of_expr e2') in 112 (cast_if_needed t' e1', cast_if_needed t' e2', t') 113 114  _ > (e1', e2', t) 115 116 in 117 118 Clight.Expr (Clight.Ebinop (binop, e1', e2'), t') 119 120 and simplify_bool_op f_bool t e1 e2 = 94 let le_ctype t1 t2 = match t1, t2 with 95  Clight.Tint (size1, sign1), Clight.Tint (size2, sign2) > 96 le_int_type size1 sign1 size2 sign2 97  _ > t1 = t2 98 99 100 (* Simplification *) 101 102 let rec simplify_bool_op f_bool t e1 e2 = 121 103 let (e1', e2', t') = simplify_and_same_type t e1 e2 in 122 104 Clight.Expr (f_bool e1' e2', t') … … 136 118  Clight.Evar _ > e 137 119 138  Clight.Esizeof _ > Clight.Expr (ed, Clight.Tint (Clight.I8, AST.Unsigned)) 120  Clight.Esizeof _ > 121 let intsize = intsize_of_int (Driver.TargetArch.int_size * 8) in 122 Clight.Expr (ed, Clight.Tint (intsize, AST.Unsigned)) 139 123 140 124  Clight.Econst_float _ > error_float () … … 148 132 Clight.Expr (Clight.Eaddrof e', t) 149 133 150  Clight.Eunop (unop, e) > 151 let e' = simplify_expr e in 152 Clight.Expr (Clight.Eunop (unop, e'), type_of_expr e') 153 154  Clight.Ebinop (binop, e1, e2) > 155 simplify_binop t binop e1 e2 156 157  Clight.Ecast (Clight.Tint (Clight.I32, AST.Signed), e) > simplify_expr e 134  Clight.Eunop _ > e 135 136  Clight.Ebinop _ > e 137 138 (* [(t1) unop ((t2) e)], when [e] simplified has type [t1] and [t1] <= [t2], 139 is simplified to [unop e] *) 140  Clight.Ecast 141 (t1, 142 Clight.Expr 143 (Clight.Eunop (unop, Clight.Expr (Clight.Ecast (_, e'), _)), t2)) 144 when le_ctype t1 t2 > 145 let e' = simplify_expr e' in 146 let t' = type_of_expr e' in 147 if t' = t1 then Clight.Expr (Clight.Eunop (unop, e'), t') else e 148 149 (* [(t) ((t') e1 binop (t') e2)], when [e1] and [e2] simplified have type [t] 150 and [t] <= [t'], is simplified to [e] *) 151  Clight.Ecast 152 (t, 153 Clight.Expr 154 (Clight.Ebinop 155 (binop, 156 Clight.Expr (Clight.Ecast (_, e1), _), 157 Clight.Expr (Clight.Ecast (_, e2), _)), 158 t')) 159 when le_ctype t t' > 160 let e1 = simplify_expr e1 in 161 let t1 = type_of_expr e1 in 162 let e2 = simplify_expr e2 in 163 let t2 = type_of_expr e2 in 164 if t1 = t && t2 = t then Clight.Expr (Clight.Ebinop (binop, e1, e2), t) 165 else e 158 166 159 167  Clight.Ecast (t', e) >
Note: See TracChangeset
for help on using the changeset viewer.