let bits_sizeof ty =
let rec rec_size ?(top_size=false) ty =
match unrollType ty with
| TPtr _ ->
if is_reference_type ty && not top_size then
rec_size (pointed_type ty) * (reference_size ty)
else
Int64.of_int (bitsSizeOf ty)
| TArray _ -> assert false
| TFun _ -> unsupported "Function pointer type %a not allowed" !Ast_printer.d_type ty
| TNamed _ -> assert false
| TComp(compinfo,_,_) ->
let size_from_field fi =
match
fi.foffset_in_bits, fi.fsize_in_bits, fi.fpadding_in_bits
with
| Some off, Some siz, Some padd ->
Int64.of_int off + Int64.of_int siz + Int64.of_int padd
| _ -> assert false
in
if compinfo.cstruct then
match List.rev compinfo.cfields with
| [] -> 0L
| fi :: _ -> size_from_field fi
else
List.fold_left max 0L (List.map size_from_field compinfo.cfields)
| TEnum _ | TVoid _ | TInt _ | TFloat _ | TBuiltin_va_list _ ->
Int64.of_int (bitsSizeOf ty)
in
rec_size ~top_size:true ty