Bap_c_size.baseThe base class for computing sizes and aligments of C data types.
The algorithm is implemented as a class to allow a particular implementation to fine tune the calculation.
The model argument defines the default sizes for integral data types. If no suitable model is available for your architecture then use the closest model and override the specific methods to fine-tune the data model of your target.
The entry methods are bits and aligment.
For example, let's compute the size of the
struct foo {
char v1;
int v2;
char v3;
};Using the LP64 data model, in which integers are 32 bit long and char is 8 bit. The size of the structure is 12 bytes, due to the 3 bytes of padding before v2 and six bytes of trailing padding.
# let size = new C.Size.base `LP64;;
# size#bits C.Type.(structure "foo" [
"v1", basic `char;
"v2", basic `uint;
"v3", basic `char
]);;
- : C.Size.bits option = Some 96method bits : Bap_c_type.t -> bits optionreturns a size of the data type representation in bits.
For incomplete types returns None. The size is always a multitude of the data type alignment and includes the paddings necessary for preserving the alignment restrictions.
method alignment : Bap_c_type.t -> Bap.Std.sizealignment t the alignment of data type t.
The alignment of
sizeof(t);sizeof the pointer;method padding : Bap_c_type.t -> bits -> Bap.Std.size optionDEPRECATED. Use the padding function if you need to compute padding.
method array : (Bap_c_type.cvr Bap_c_type.qualifier, Bap_c_type.array)
Bap_c_type.spec ->
bits optionarray spec if array spec is complete, i.e., the number of elements is known, then returns a product of the array size and the array's element type in bits, otherwise returns None
method union : (Bap_c_type.no_qualifier, Bap_c_type.compound) Bap_c_type.spec ->
bits optionif spec is complete then returns a size in bits of the biggest element, including the padding between fields, but excludeing the trailing padding.
method structure : (Bap_c_type.no_qualifier, Bap_c_type.compound)
Bap_c_type.spec ->
bits optionif spec is complete then returns a total size of the structure, including the padding between fields, but excluding the trailing padding.
method integer : Bap_c_type.integer -> Bap.Std.sizethe size of intergral types.
method pointer : Bap.Std.addr_sizethe size of a pointer.
method enum : (string * int64 option) list -> Bap.Std.sizethe size of the enumeration.
method real : Bap_c_type.real -> [ `r32 | `r64 | `r128 ]the size of a real floating-point data type.
method complex : Bap_c_type.complex -> Bap.Std.sizethe size of a complex floating-point data type.
method floating : Bap_c_type.floating -> Bap.Std.sizethe size of a floating-point data type.
method basic : Bap_c_type.basic -> Bap.Std.sizethe size of a basic data type.
method scalar : Bap_c_type.scalar -> Bap.Std.sizethe size of a scalar data type.