 Timestamp:
 Jan 19, 2011, 6:23:27 PM (9 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

Deliverables/D2.3/8051memoryspacesbranch/cparser/Bitfields.ml
r453 r460 119 119 bf.bf_pos in 120 120 (* Give the mask an hexadecimal string representation, nicer to read *) 121 {edesc = EConst(CInt(m, IUInt, sprintf "0x%LXU" m)); etyp = TInt(IUInt, []) }121 {edesc = EConst(CInt(m, IUInt, sprintf "0x%LXU" m)); etyp = TInt(IUInt, []); espace = Code} (* XXX are consts always Code? *) 122 122 123 123 (* Extract the value of a bitfield *) … … 141 141 let e1 = 142 142 {edesc = EBinop(Oshl, carrier, left_shift_count bf, TInt(IUInt, [])); 143 etyp = carrier.etyp } in143 etyp = carrier.etyp; espace = Any} in 144 144 let ty = TInt((if bf.bf_signed then IInt else IUInt), []) in 145 145 let e2 = 146 {edesc = ECast(ty, e1); etyp = ty } in146 {edesc = ECast(ty, e1); etyp = ty; espace = Any} in 147 147 {edesc = EBinop(Oshr, e2, right_shift_count bf, e2.etyp); 148 etyp = e2.etyp }148 etyp = e2.etyp; espace = Any} 149 149 150 150 (* Assign a bitfield within a carrier *) … … 162 162 let bitfield_assign bf carrier newval = 163 163 let msk = insertion_mask bf in 164 let notmsk = {edesc = EUnop(Onot, msk); etyp = msk.etyp } in164 let notmsk = {edesc = EUnop(Onot, msk); etyp = msk.etyp; espace = Any} in 165 165 let newval_shifted = 166 166 {edesc = EBinop(Oshl, newval, intconst (Int64.of_int bf.bf_pos) IUInt, 167 167 TInt(IUInt,[])); 168 etyp = TInt(IUInt,[])} in 168 etyp = TInt(IUInt,[]); 169 espace = Any} in 169 170 let newval_masked = 170 171 {edesc = EBinop(Oand, newval_shifted, msk, TInt(IUInt,[])); 171 etyp = TInt(IUInt,[])} 172 etyp = TInt(IUInt,[]); 173 espace = Any} 172 174 and oldval_masked = 173 175 {edesc = EBinop(Oand, carrier, notmsk, TInt(IUInt,[])); 174 etyp = TInt(IUInt,[]) } in176 etyp = TInt(IUInt,[]); espace = Any} in 175 177 {edesc = EBinop(Oor, oldval_masked, newval_masked, TInt(IUInt,[])); 176 etyp = TInt(IUInt,[]) }178 etyp = TInt(IUInt,[]); espace = Any} 177 179 178 180 (* Expressions *) … … 189 191 let is_bitfield_access_ptr ty fieldname = 190 192 match unroll env ty with 191  TPtr( ty', _) > is_bitfield_access ty' fieldname193  TPtr(_, ty', _) > is_bitfield_access ty' fieldname 192 194  _ > None in 193 195 … … 202 204 begin match is_bitfield_access e1.etyp fieldname with 203 205  None > 204 {edesc = EUnop(Odot fieldname, e1'); etyp = e.etyp }206 {edesc = EUnop(Odot fieldname, e1'); etyp = e.etyp; espace = e1'.espace} 205 207  Some bf > 206 208 bitfield_extract bf 207 209 {edesc = EUnop(Odot bf.bf_carrier, e1'); 208 etyp = bf.bf_carrier_typ} 210 etyp = bf.bf_carrier_typ; 211 espace = e1'.espace} 209 212 end 210 213 … … 213 216 begin match is_bitfield_access_ptr e1.etyp fieldname with 214 217  None > 215 {edesc = EUnop(Oarrow fieldname, e1'); etyp = e.etyp }218 {edesc = EUnop(Oarrow fieldname, e1'); etyp = e.etyp; espace = Any} 216 219  Some bf > 217 220 bitfield_extract bf 218 221 {edesc = EUnop(Oarrow bf.bf_carrier, e1'); 219 etyp = bf.bf_carrier_typ }222 etyp = bf.bf_carrier_typ; espace = Any} 220 223 end 221 224 222 225  EUnop(op, e1) > 223 226 (* Note: simplified expr, so no ++/ *) 224 {edesc = EUnop(op, texp e1); etyp = e.etyp }227 {edesc = EUnop(op, texp e1); etyp = e.etyp; espace = e.espace} 225 228 226 229  EBinop(Oassign, e1, e2, ty) > … … 232 235 {edesc = EBinop(Oassign, 233 236 {edesc = EUnop(Odot fieldname, lhs); 234 etyp = e1.etyp },237 etyp = e1.etyp; espace = lhs.espace}, 235 238 rhs, ty); 236 etyp = e.etyp} 239 etyp = e.etyp; 240 espace = e.espace} 237 241  Some bf > 238 242 let carrier = 239 243 {edesc = EUnop(Odot bf.bf_carrier, lhs); 240 etyp = bf.bf_carrier_typ} in 244 etyp = bf.bf_carrier_typ; 245 espace = lhs.espace} in 241 246 {edesc = EBinop(Oassign, carrier, 242 247 bitfield_assign bf carrier rhs, 243 248 carrier.etyp); 244 etyp = carrier.etyp} 249 etyp = carrier.etyp; 250 espace = lhs.espace} 245 251 end 246 252  EUnop(Oarrow fieldname, e11) > … … 250 256 {edesc = EBinop(Oassign, 251 257 {edesc = EUnop(Oarrow fieldname, lhs); 252 etyp = e1.etyp}, 258 etyp = e1.etyp; 259 espace = e1.espace}, 253 260 rhs, ty); 254 etyp = e.etyp} 261 etyp = e.etyp; 262 espace = e.espace} 255 263  Some bf > 256 264 let carrier = 257 265 {edesc = EUnop(Oarrow bf.bf_carrier, lhs); 258 etyp = bf.bf_carrier_typ} in 266 etyp = bf.bf_carrier_typ; 267 espace = Any} in 259 268 {edesc = EBinop(Oassign, carrier, 260 269 bitfield_assign bf carrier rhs, 261 270 carrier.etyp); 262 etyp = carrier.etyp} 271 etyp = carrier.etyp; 272 espace = Any} 263 273 end 264 274  _ > 265 {edesc = EBinop(Oassign, texp e1, texp e2, e1.etyp); etyp = e1.etyp }275 {edesc = EBinop(Oassign, texp e1, texp e2, e1.etyp); etyp = e1.etyp; espace = e1.espace} 266 276 end 267 277 268 278  EBinop(op, e1, e2, ty) > 269 279 (* Note: simplified expr assumed, so no assignop *) 270 {edesc = EBinop(op, texp e1, texp e2, ty); etyp = e.etyp }280 {edesc = EBinop(op, texp e1, texp e2, ty); etyp = e.etyp; espace = e.espace} 271 281  EConditional(e1, e2, e3) > 272 {edesc = EConditional(texp e1, texp e2, texp e3); etyp = e.etyp }282 {edesc = EConditional(texp e1, texp e2, texp e3); etyp = e.etyp; espace = e.espace} 273 283  ECast(ty, e1) > 274 {edesc = ECast(ty, texp e1); etyp = e.etyp }284 {edesc = ECast(ty, texp e1); etyp = e.etyp; espace = e.espace} 275 285  ECall(e1, el) > 276 {edesc = ECall(texp e1, List.map texp el); etyp = e.etyp }286 {edesc = ECall(texp e1, List.map texp el); etyp = e.etyp; espace = e.espace} 277 287 278 288 in texp e … … 326 336 let e_mask = 327 337 {edesc = EConst(CInt(m, IUInt, sprintf "0x%LXU" m)); 328 etyp = TInt(IUInt, [])} in 338 etyp = TInt(IUInt, []); 339 espace = Any} in 329 340 let e_and = 330 341 {edesc = EBinop(Oand, e, e_mask, TInt(IUInt,[])); 331 etyp = TInt(IUInt,[])} in 342 etyp = TInt(IUInt,[]); 343 espace = Any} in 332 344 {edesc = EBinop(Oshl, e_and, intconst (Int64.of_int bf.bf_pos) IInt, 333 345 TInt(IUInt, [])); 334 etyp = TInt(IUInt, [])} 346 etyp = TInt(IUInt, []); 347 espace = Any} 335 348  _ > assert false 336 349 … … 355 368  e1 :: el > 356 369 {edesc = EBinop(Oor, e1, or_expr_list el, TInt(IUInt,[])); 357 etyp = TInt(IUInt,[])} 370 etyp = TInt(IUInt,[]); 371 espace = Any} 358 372 359 373 let rec transf_struct_init id fld_init_list = … … 368 382 fld_bitfield = None}, 369 383 Init_single {edesc = ECast(bf.bf_carrier_typ, or_expr_list el); 370 etyp = bf.bf_carrier_typ}) 384 etyp = bf.bf_carrier_typ; 385 espace = Any}) 371 386 :: transf_struct_init id rem' 372 387 with Not_found >
Note: See TracChangeset
for help on using the changeset viewer.