-
Notifications
You must be signed in to change notification settings - Fork 21
Add C11 generic support #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 46 commits
203f283
d9a7510
0067d37
a7cf7e4
ddd59c1
76e9c83
005a453
e58de49
50c02c9
041c7cf
962dc8a
5f1b78e
c2f6339
7cdf8ad
0b162ca
9a17ba2
9473315
19238f0
06a878c
b4bd664
2add3ca
a6ef80d
897aba2
5e9a2f6
e67879d
46c6a0a
dd8f2f2
919c0f8
66b5e81
f703a1c
afafead
e84b98b
8fc4cc4
0177bfd
8d5204a
ba391a8
b13180b
2be7157
79a4579
1983c12
39d8442
ce4f4f7
46e4f05
7a7e1e4
3dfa002
6674fd1
544dbfc
7606d26
e47e4ad
f70e708
a0a1a94
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1275,8 +1275,8 @@ let charType = TInt(IChar, []) | |
| let boolType = TInt(IBool, []) | ||
|
|
||
| let charPtrType = TPtr(charType,[]) | ||
| let charConstPtrType = TPtr(TInt(IChar, [Attr("const", [])]),[]) | ||
| let stringLiteralType = ref charPtrType | ||
| let charConstPtrType = TPtr(TInt(IChar, [Attr("const", []); Attr("pconst", [])]),[]) | ||
| let stringLiteralType = charPtrType | ||
michael-schwarz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| let voidPtrType = TPtr(voidType, []) | ||
| let intPtrType = TPtr(intType, []) | ||
|
|
@@ -1527,6 +1527,18 @@ let rec typeAttrs = function | |
| | TFun (_, _, _, a) -> a | ||
| | TBuiltin_va_list a -> a | ||
|
|
||
| (** [typeAttrs], which doesn't add inner attributes. *) | ||
| let typeAttrsOuter = function | ||
| | TVoid a -> a | ||
| | TInt (_, a) -> a | ||
| | TFloat (_, a) -> a | ||
| | TNamed (_, a) -> a | ||
| | TPtr (_, a) -> a | ||
| | TArray (_, _, a) -> a | ||
| | TComp (_, a) -> a | ||
| | TEnum (_, a) -> a | ||
| | TFun (_, _, _, a) -> a | ||
| | TBuiltin_va_list a -> a | ||
|
|
||
| let setTypeAttrs t a = | ||
| match t with | ||
|
|
@@ -1578,6 +1590,19 @@ let typeRemoveAttributes (anl: string list) t = | |
| | TNamed (t, a) -> TNamed (t, drop a) | ||
| | TBuiltin_va_list a -> TBuiltin_va_list (drop a) | ||
|
|
||
| (** Partition attributes into type qualifiers and non type qualifiers. *) | ||
| let partitionQualifierAttributes al = | ||
| List.partition (function | ||
| | Attr (("const" | "volatile" | "restrict"), []) -> true | ||
| | _ -> false | ||
| ) al | ||
|
|
||
| (** Remove top-level type qualifiers from type. *) | ||
| let removeOuterQualifierAttributes t = | ||
| let a = typeAttrsOuter t in | ||
| let (_, a') = partitionQualifierAttributes a in | ||
| setTypeAttrs t a' | ||
|
|
||
| let unrollType (t: typ) : typ = | ||
| let rec withAttrs (al: attributes) (t: typ) : typ = | ||
| match t with | ||
|
|
@@ -1930,7 +1955,7 @@ let rec typeOf (e: exp) : typ = | |
| (* The type of a string is a pointer to characters ! The only case when | ||
| * you would want it to be an array is as an argument to sizeof, but we | ||
| * have SizeOfStr for that *) | ||
| | Const(CStr s) -> !stringLiteralType | ||
| | Const(CStr s) -> stringLiteralType | ||
|
|
||
| | Const(CWStr s) -> TPtr(!wcharType,[]) | ||
|
|
||
|
|
@@ -2164,11 +2189,7 @@ let rec getInteger (e:exp) : cilint option = | |
| let mkInt ik n = Some (fst (truncateCilint ik n)) in | ||
| match unrollType t, getInteger e with | ||
| | TInt (ik, _), Some n -> mkInt ik n | ||
| | TPtr _, Some n -> begin | ||
| match !upointType with | ||
| TInt (ik, _) -> mkInt ik n | ||
| | _ -> raise (Failure "pointer size unknown") | ||
| end | ||
| (* "integer constant expressions" may not cast to ptr *) | ||
michael-schwarz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| | TEnum (ei, _), Some n -> mkInt ei.ekind n | ||
| | TFloat _, v -> v | ||
| | _, _ -> None | ||
|
|
@@ -2800,9 +2821,12 @@ let isArrayType t = | |
|
|
||
| (** 6.3.2.3 subsection 3 | ||
| * An integer constant expr with value 0, or such an expr cast to void *, is called a null pointer constant. *) | ||
| let isNullPtrConstant = function | ||
| | CastE(TPtr(TVoid _,_), e) -> isZero @@ constFold true e | ||
| | e -> isZero @@ constFold true e | ||
| let isNullPtrConstant e = | ||
| let rec isNullPtrConstant = function | ||
| | CastE (TPtr (TVoid [], []), e) -> isNullPtrConstant e (* no qualifiers allowed on void or ptr *) | ||
| | e -> isZero e | ||
| in | ||
| isNullPtrConstant (constFold true e) | ||
|
|
||
| let rec isConstant = function | ||
| | Const _ -> true | ||
|
|
@@ -2965,7 +2989,7 @@ let initGccBuiltins () : unit = | |
| let ulongLongType = TInt(IULongLong, []) in | ||
| let floatType = TFloat(FFloat, []) in | ||
| let longDoubleType = TFloat (FLongDouble, []) in | ||
| let voidConstPtrType = TPtr(TVoid [Attr ("const", [])], []) in | ||
| let voidConstPtrType = TPtr(TVoid [Attr ("const", []); Attr ("pconst", [])], []) in | ||
| let sizeType = !typeOfSizeOf in | ||
| let v4sfType = TFloat (FFloat,[Attr("__vector_size__", [AInt 16])]) in | ||
|
|
||
|
|
@@ -4404,7 +4428,7 @@ class defaultCilPrinterClass : cilPrinter = object (self) | |
|
|
||
| | TArray (elemt, lo, a) -> | ||
| (* ignore the const attribute for arrays *) | ||
| let a' = dropAttributes [ "const" ] a in | ||
| let a' = dropAttributes [ "pconst" ] a in | ||
michael-schwarz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| let name' = | ||
| if a' == [] then name else | ||
| if nameOpt == None then printAttributes a' else | ||
|
|
@@ -4472,7 +4496,8 @@ class defaultCilPrinterClass : cilPrinter = object (self) | |
| method pAttr (Attr(an, args): attribute) : doc * bool = | ||
| (* Recognize and take care of some known cases *) | ||
| match an, args with | ||
| "const", [] -> text "const", false | ||
| "const", [] -> nil, false (* don't print const directly, because of split local declarations *) | ||
| | "pconst", [] -> text "const", false (* pconst means print const *) | ||
| (* Put the aconst inside the attribute list *) | ||
| | "complex", [] when !c99Mode -> text "_Complex", false | ||
| | "complex", [] when not !msvcMode -> text "__complex__", false | ||
|
|
@@ -5044,7 +5069,7 @@ let makeVarinfo global name ?init typ = | |
| { vname = name; | ||
| vid = newVID (); | ||
| vglob = global; | ||
| vtype = if global then typ else typeRemoveAttributes ["const"] typ; | ||
| vtype = if global then typ else typeRemoveAttributes ["pconst"] typ; | ||
michael-schwarz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| vdecl = lu; | ||
| vinit = {init=init}; | ||
| vinline = false; | ||
|
|
@@ -7000,11 +7025,6 @@ let initCIL () = | |
| Some machine -> M.theMachine := machine | ||
| | None -> M.theMachine := if !msvcMode then M.msvc else M.gcc | ||
| end; | ||
| (* Pick type for string literals *) | ||
| stringLiteralType := if !M.theMachine.M.const_string_literals then | ||
| charConstPtrType | ||
| else | ||
| charPtrType; | ||
|
Comment on lines
-6715
to
-6719
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is removing this necessary?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, looks like this is an MSVC thing, which we will no longer support anyway.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it was actually supposed to be a GCC thing, but it didn't even match the typing behavior of GCC: #48 (comment). |
||
| (* Find the right ikind given the size *) | ||
| let findIkindSz (unsigned: bool) (sz: int) : ikind = | ||
| try | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.