Commit 191906d1 authored by xleroy's avatar xleroy
Browse files

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
parent a9578873
......@@ -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'
......
......@@ -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
......
......@@ -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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment