summaryrefslogtreecommitdiff
path: root/cparser
diff options
context:
space:
mode:
authorGravatar xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e>2011-03-10 10:12:34 +0000
committerGravatar xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e>2011-03-10 10:12:34 +0000
commit191906d10aa084bc6077ef3f6503fd2dacac67a1 (patch)
treefd2feb5af279c9d2b8e0a31607d713a1d877c439 /cparser
parenta9578873a5bdf14c47650cc3dd9d21e3bcef2370 (diff)
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
Diffstat (limited to 'cparser')
-rw-r--r--cparser/Bitfields.ml15
-rw-r--r--cparser/Machine.ml24
-rw-r--r--cparser/Machine.mli11
3 files changed, 39 insertions, 11 deletions
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