From 191906d10aa084bc6077ef3f6503fd2dacac67a1 Mon Sep 17 00:00:00 2001 From: xleroy Date: Thu, 10 Mar 2011 10:12:34 +0000 Subject: Bitfields: MSB-to-LSB in addition to LSB-to-MSB git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@1600 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e --- cparser/Bitfields.ml | 15 +++++++++++---- cparser/Machine.ml | 24 +++++++++++++++++++----- cparser/Machine.mli | 11 +++++++++-- 3 files changed, 39 insertions(+), 11 deletions(-) (limited to 'cparser') diff --git a/cparser/Bitfields.ml b/cparser/Bitfields.ml index 9452a4f..472b6a4 100644 --- a/cparser/Bitfields.ml +++ b/cparser/Bitfields.ml @@ -94,15 +94,22 @@ let rec transf_members env id count = function else begin (* Create integer field of sufficient size for this bitfield group *) let carrier = sprintf "__bf%d" count in - let carrier_typ = TInt(unsigned_ikind_for_carrier nbits, []) in + let carrier_ikind = unsigned_ikind_for_carrier nbits in + let carrier_typ = TInt(carrier_ikind, []) in + (* Enter each field with its bit position, size, signedness *) List.iter (fun (name, pos, sz, signed, signed2) -> - if name <> "" then + if name <> "" then begin + let pos' = + if !config.bitfields_msb_first + then sizeof_ikind carrier_ikind * 8 - pos - sz + else pos in Hashtbl.add bitfield_table (id, name) {bf_carrier = carrier; bf_carrier_typ = carrier_typ; - bf_pos = pos; bf_size = sz; - bf_signed = signed; bf_signed_res = signed2}) + bf_pos = pos'; bf_size = sz; + bf_signed = signed; bf_signed_res = signed2} + end) bitfields; { fld_name = carrier; fld_typ = carrier_typ; fld_bitfield = None} :: transf_members env id (count + 1) ml' diff --git a/cparser/Machine.ml b/cparser/Machine.ml index 21b3daa..ffff5fb 100644 --- a/cparser/Machine.ml +++ b/cparser/Machine.ml @@ -39,7 +39,8 @@ type t = { alignof_double: int; alignof_longdouble: int; alignof_void: int option; - alignof_fun: int option + alignof_fun: int option; + bitfields_msb_first: bool } let ilp32ll64 = { @@ -66,7 +67,8 @@ let ilp32ll64 = { alignof_double = 8; alignof_longdouble = 16; alignof_void = None; - alignof_fun = None + alignof_fun = None; + bitfields_msb_first = false } let i32lpll64 = { @@ -93,7 +95,8 @@ let i32lpll64 = { alignof_double = 8; alignof_longdouble = 16; alignof_void = None; - alignof_fun = None + alignof_fun = None; + bitfields_msb_first = false } let il32pll64 = { @@ -120,15 +123,26 @@ let il32pll64 = { alignof_double = 8; alignof_longdouble = 16; alignof_void = None; - alignof_fun = None + alignof_fun = None; + bitfields_msb_first = false } -let make_char_signed c = {c with char_signed = true} +(* Canned configurations for some ABIs *) + +let x86_32 = { ilp32ll64 with char_signed = true } +let x86_64 = { i32lpll64 with char_signed = true } +let win64 = { il32pll64 with char_signed = true } +let ppc_32_bigendian = { ilp32ll64 with bitfields_msb_first = true } +let arm_littleendian = ilp32ll64 + +(* Add GCC extensions re: sizeof and alignof *) let gcc_extensions c = { c with sizeof_void = Some 1; sizeof_fun = Some 1; alignof_void = Some 1; alignof_fun = Some 1 } +(* Default configuration *) + let config = ref (match Sys.word_size with | 32 -> ilp32ll64 diff --git a/cparser/Machine.mli b/cparser/Machine.mli index bd3f357..f1d3567 100644 --- a/cparser/Machine.mli +++ b/cparser/Machine.mli @@ -39,13 +39,20 @@ type t = { alignof_double: int; alignof_longdouble: int; alignof_void: int option; - alignof_fun: int option + alignof_fun: int option; + bitfields_msb_first: bool + } val ilp32ll64 : t val i32lpll64 : t val il32pll64 : t -val make_char_signed : t -> t +val x86_32 : t +val x86_64 : t +val win64 : t +val ppc_32_bigendian : t +val arm_littleendian : t + val gcc_extensions : t -> t val config : t ref -- cgit v1.2.3