diff options
author | Bernhard Schommer <bernhardschommer@gmail.com> | 2015-09-16 19:43:35 +0200 |
---|---|---|
committer | Bernhard Schommer <bernhardschommer@gmail.com> | 2015-09-16 19:43:35 +0200 |
commit | 98cddc7ba45b34fbd71d9a80c27a8e5ec6b311b0 (patch) | |
tree | 5a39f62c4e1526dd9e047f74efca164c59504f95 /cparser/Cutil.ml | |
parent | 3344bcf59acb1ae8d43a0d15acb4b824689e706d (diff) | |
download | compcert-98cddc7ba45b34fbd71d9a80c27a8e5ec6b311b0.tar.gz compcert-98cddc7ba45b34fbd71d9a80c27a8e5ec6b311b0.zip |
Move more functionality in the new interface.
Added functions to add more information to the debuging interface,
like the struct layout with offsets, bitifiled layout and removed
the no longer needed mapping from stamp to atom.
Diffstat (limited to 'cparser/Cutil.ml')
-rw-r--r-- | cparser/Cutil.ml | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/cparser/Cutil.ml b/cparser/Cutil.ml index a3c05c34..90bbfe5a 100644 --- a/cparser/Cutil.ml +++ b/cparser/Cutil.ml @@ -427,7 +427,6 @@ let sizeof_union env members = We lay out fields consecutively, inserting padding to preserve their alignment. Not done here but in composite_info_decl: rounding size to alignment. *) - let sizeof_struct env members = let rec sizeof_rec ofs = function | [] -> @@ -449,6 +448,26 @@ let sizeof_struct env members = end in sizeof_rec 0 members +(* Simplified version to compute offsets on structs without bitfields *) +let struct_layout env members = + let rec struct_layout_rec mem ofs = function + | [] -> + mem + | [ { fld_typ = TArray(_, None, _) } as m ] -> + (* C99: ty[] allowed as last field *) + begin match alignof env m.fld_typ with + | Some a -> ( m.fld_name,align ofs a)::mem + | None -> [] + end + | m :: rem -> + match alignof env m.fld_typ, sizeof env m.fld_typ with + | Some a, Some s -> + let offset = align ofs a in + struct_layout_rec ((m.fld_name,offset)::mem) (offset + s) rem + | _, _ -> [] + in struct_layout_rec [] 0 members + + (* Determine whether a type is incomplete *) let incomplete_type env t = |