Skip to content

Commit 17c0392

Browse files
committed
Fix for aarch64-darwin
See visq/language-c#89
1 parent 4786ce0 commit 17c0392

File tree

2 files changed

+150
-0
lines changed

2 files changed

+150
-0
lines changed

modules/configuration-nix.nix

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,8 @@ in {
7777
++ pkgs.lib.optional (__elem config.compiler.nix-name [
7878
"ghc810420210212"
7979
]) (from "1.7.0.0" ../patches/ghcide-1.7-plutus-ghc.patch);
80+
81+
packages.language-c.patches = [
82+
(fromUntil "0.9.1" "0.9.2" ../patches/languge-c-int128.patch)
83+
];
8084
}

patches/languge-c-int128.patch

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
diff --git a/src/Language/C/Parser/Lexer.x b/src/Language/C/Parser/Lexer.x
2+
index 6f6592b..3a0d79d 100644
3+
--- a/src/Language/C/Parser/Lexer.x
4+
+++ b/src/Language/C/Parser/Lexer.x
5+
@@ -284,7 +284,7 @@ alignof _Alignof __alignof alignof __alignof__,
6+
asm @__,
7+
atomic _Atomic,
8+
auto, break, bool _Bool,
9+
-case, char, const @__, continue,
10+
+case, char, const @__, const __constant, continue,
11+
complex _Complex __complex__
12+
default, do, double,
13+
else, enum, extern,
14+
@@ -293,6 +293,8 @@ generic _Generic,
15+
goto,
16+
if, inline @__, int,
17+
int128 __int128,
18+
+int128 __int128_t,
19+
+UInt128 __uint128_t,
20+
long,
21+
noreturn _Noreturn,
22+
nullable _Nullable __nullable,
23+
@@ -324,7 +326,7 @@ label __label__
24+
(CTokGnuC GnuCTyCompat) __builtin_types_compatible_p
25+
(flip CTokClangC ClangBuiltinConvertVector) __builtin_convertvector
26+
-}
27+
--- Tokens: _Alignas _Alignof __alignof alignof __alignof__ __asm asm __asm__ _Atomic auto break _Bool case char __const const __const__ continue _Complex __complex__ default do double else enum extern float for _Generic goto if __inline inline __inline__ int __int128 long _Noreturn _Nullable __nullable _Nonnull __nonnull register __restrict restrict __restrict__ return short __signed signed __signed__ sizeof static _Static_assert struct switch typedef __typeof typeof __typeof__ __thread _Thread_local union unsigned void __volatile volatile __volatile__ while __label__ _Float32 _Float32x _Float64 _Float64x _Float128 __float128 _Float128x __attribute __attribute__ __extension__ __real __real__ __imag __imag__ __builtin_va_arg __builtin_offsetof __builtin_types_compatible_p __builtin_convertvector
28+
+-- Tokens: _Alignas _Alignof __alignof alignof __alignof__ __asm asm __asm__ _Atomic auto break _Bool case char __const const __const__ __constant continue _Complex __complex__ default do double else enum extern float for _Generic goto if __inline inline __inline__ int __int128 __int128_t __uint128_t long _Noreturn _Nullable __nullable _Nonnull __nonnull register __restrict restrict __restrict__ return short __signed signed __signed__ sizeof static _Static_assert struct switch typedef __typeof typeof __typeof__ __thread _Thread_local union unsigned void __volatile volatile __volatile__ while __label__ _Float32 _Float32x _Float64 _Float64x _Float128 __float128 _Float128x __attribute __attribute__ __extension__ __real __real__ __imag __imag__ __builtin_va_arg __builtin_offsetof __builtin_types_compatible_p __builtin_convertvector
29+
idkwtok ('_' : 'A' : 'l' : 'i' : 'g' : 'n' : 'a' : 's' : []) = tok 8 CTokAlignas
30+
idkwtok ('_' : 'A' : 'l' : 'i' : 'g' : 'n' : 'o' : 'f' : []) = tok 8 CTokAlignof
31+
idkwtok ('_' : 'A' : 't' : 'o' : 'm' : 'i' : 'c' : []) = tok 7 CTokAtomic
32+
@@ -377,6 +379,7 @@ idkwtok ('i' : 'n' : 'l' : 'i' : 'n' : 'e' : []) = tok 6 CTokInline
33+
idkwtok ('_' : '_' : 'i' : 'n' : 'l' : 'i' : 'n' : 'e' : '_' : '_' : []) = tok 10 CTokInline
34+
idkwtok ('i' : 'n' : 't' : []) = tok 3 CTokInt
35+
idkwtok ('_' : '_' : 'i' : 'n' : 't' : '1' : '2' : '8' : []) = tok 8 CTokInt128
36+
+idkwtok ('_' : '_' : 'i' : 'n' : 't' : '1' : '2' : '8' : '_' : 't' : []) = tok 10 CTokInt128
37+
idkwtok ('_' : '_' : 'l' : 'a' : 'b' : 'e' : 'l' : '_' : '_' : []) = tok 9 CTokLabel
38+
idkwtok ('l' : 'o' : 'n' : 'g' : []) = tok 4 CTokLong
39+
idkwtok ('_' : '_' : 'n' : 'o' : 'n' : 'n' : 'u' : 'l' : 'l' : []) = tok 9 CTokNonnull
40+
@@ -401,6 +404,7 @@ idkwtok ('t' : 'y' : 'p' : 'e' : 'd' : 'e' : 'f' : []) = tok 7 CTokTypedef
41+
idkwtok ('_' : '_' : 't' : 'y' : 'p' : 'e' : 'o' : 'f' : []) = tok 8 CTokTypeof
42+
idkwtok ('t' : 'y' : 'p' : 'e' : 'o' : 'f' : []) = tok 6 CTokTypeof
43+
idkwtok ('_' : '_' : 't' : 'y' : 'p' : 'e' : 'o' : 'f' : '_' : '_' : []) = tok 10 CTokTypeof
44+
+idkwtok ('_' : '_' : 'u' : 'i' : 'n' : 't' : '1' : '2' : '8' : '_' : 't' : []) = tok 11 CTokUInt128
45+
idkwtok ('u' : 'n' : 'i' : 'o' : 'n' : []) = tok 5 CTokUnion
46+
idkwtok ('u' : 'n' : 's' : 'i' : 'g' : 'n' : 'e' : 'd' : []) = tok 8 CTokUnsigned
47+
idkwtok ('v' : 'o' : 'i' : 'd' : []) = tok 4 CTokVoid
48+
diff --git a/src/Language/C/Parser/Parser.y b/src/Language/C/Parser/Parser.y
49+
index fb494dc..d976c23 100644
50+
--- a/src/Language/C/Parser/Parser.y
51+
+++ b/src/Language/C/Parser/Parser.y
52+
@@ -215,6 +215,8 @@ if { CTokIf _ }
53+
inline { CTokInline _ }
54+
int { CTokInt _ }
55+
"__int128" { CTokInt128 _ }
56+
+"__int128_t" { CTokInt128 _ }
57+
+"__uint128_t" { CTokUInt128 _ }
58+
long { CTokLong _ }
59+
"__label__" { CTokLabel _ }
60+
"_Noreturn" { CTokNoreturn _ }
61+
@@ -892,6 +894,7 @@ basic_type_name
62+
| "_Bool" {% withNodeInfo $1 $ CBoolType }
63+
| "_Complex" {% withNodeInfo $1 $ CComplexType }
64+
| "__int128" {% withNodeInfo $1 $ CInt128Type }
65+
+ | "__uint128_t" {% withNodeInfo $1 $ CUInt128Type }
66+
| "_Float32" {% withNodeInfo $1 $ (CFloatNType 32 False) }
67+
| "_Float32x" {% withNodeInfo $1 $ (CFloatNType 32 True) }
68+
| "_Float64" {% withNodeInfo $1 $ (CFloatNType 64 False) }
69+
diff --git a/src/Language/C/Parser/Tokens.hs b/src/Language/C/Parser/Tokens.hs
70+
index 66b77a9..fabde66 100644
71+
--- a/src/Language/C/Parser/Tokens.hs
72+
+++ b/src/Language/C/Parser/Tokens.hs
73+
@@ -101,7 +101,8 @@ data CToken = CTokLParen !PosLength -- `('
74+
-- (or `__inline',
75+
-- `__inline__')
76+
| CTokInt !PosLength -- `int'
77+
- | CTokInt128 !PosLength -- `__int128`
78+
+ | CTokInt128 !PosLength -- `__int128' (or `__int128_t')
79+
+ | CTokUInt128 !PosLength -- `__uint128_t'
80+
| CTokLong !PosLength -- `long'
81+
| CTokLabel !PosLength -- `__label__
82+
| CTokNoreturn !PosLength -- `_Noreturn'
83+
@@ -237,6 +238,7 @@ posLenOfTok (CTokGeneric pos ) = pos
84+
posLenOfTok (CTokGoto pos ) = pos
85+
posLenOfTok (CTokInt pos ) = pos
86+
posLenOfTok (CTokInt128 pos ) = pos
87+
+posLenOfTok (CTokUInt128 pos ) = pos
88+
posLenOfTok (CTokInline pos ) = pos
89+
posLenOfTok (CTokIf pos ) = pos
90+
posLenOfTok (CTokLong pos ) = pos
91+
@@ -352,6 +354,7 @@ instance Show CToken where
92+
showsPrec _ (CTokInline _ ) = showString "inline"
93+
showsPrec _ (CTokInt _ ) = showString "int"
94+
showsPrec _ (CTokInt128 _ ) = showString "__int128"
95+
+ showsPrec _ (CTokUInt128 _ ) = showString "__uint128_t"
96+
showsPrec _ (CTokLong _ ) = showString "long"
97+
showsPrec _ (CTokLabel _ ) = showString "__label__"
98+
showsPrec _ (CTokNoreturn _ ) = showString "_Noreturn"
99+
diff --git a/src/Language/C/Pretty.hs b/src/Language/C/Pretty.hs
100+
index 1db99ed..55bfcfb 100644
101+
--- a/src/Language/C/Pretty.hs
102+
+++ b/src/Language/C/Pretty.hs
103+
@@ -256,6 +256,7 @@ instance Pretty CTypeSpec where
104+
pretty (CBoolType _) = text "_Bool"
105+
pretty (CComplexType _) = text "_Complex"
106+
pretty (CInt128Type _) = text "__int128"
107+
+ pretty (CUInt128Type _) = text "__uint128_t"
108+
pretty (CSUType union _) = pretty union
109+
pretty (CEnumType enum _) = pretty enum
110+
pretty (CTypeDef ident _) = identP ident
111+
diff --git a/src/Language/C/Syntax/AST.hs b/src/Language/C/Syntax/AST.hs
112+
index 2bdc642..c58d822 100644
113+
--- a/src/Language/C/Syntax/AST.hs
114+
+++ b/src/Language/C/Syntax/AST.hs
115+
@@ -468,6 +468,7 @@ data CTypeSpecifier a
116+
| CBoolType a
117+
| CComplexType a
118+
| CInt128Type a
119+
+ | CUInt128Type a
120+
| CFloatNType Int Bool a -- ^ IEC 60227: width (32,64,128), extended flag
121+
| CSUType (CStructureUnion a) a -- ^ Struct or Union specifier
122+
| CEnumType (CEnumeration a) a -- ^ Enumeration specifier
123+
@@ -1096,6 +1097,7 @@ instance CNode t1 => CNode (CTypeSpecifier t1) where
124+
nodeInfo (CBoolType d) = nodeInfo d
125+
nodeInfo (CComplexType d) = nodeInfo d
126+
nodeInfo (CInt128Type d) = nodeInfo d
127+
+ nodeInfo (CUInt128Type d) = nodeInfo d
128+
nodeInfo (CSUType _ n) = nodeInfo n
129+
nodeInfo (CEnumType _ n) = nodeInfo n
130+
nodeInfo (CTypeDef _ n) = nodeInfo n
131+
@@ -1119,6 +1121,7 @@ instance Functor CTypeSpecifier where
132+
fmap _f (CBoolType a1) = CBoolType (_f a1)
133+
fmap _f (CComplexType a1) = CComplexType (_f a1)
134+
fmap _f (CInt128Type a1) = CInt128Type (_f a1)
135+
+ fmap _f (CUInt128Type a1) = CUInt128Type (_f a1)
136+
fmap _f (CSUType a1 a2) = CSUType (fmap _f a1) (_f a2)
137+
fmap _f (CEnumType a1 a2) = CEnumType (fmap _f a1) (_f a2)
138+
fmap _f (CTypeDef a1 a2) = CTypeDef a1 (_f a2)
139+
@@ -1140,6 +1143,7 @@ instance Annotated CTypeSpecifier where
140+
annotation (CBoolType n) = n
141+
annotation (CComplexType n) = n
142+
annotation (CInt128Type n) = n
143+
+ annotation (CUInt128Type n) = n
144+
annotation (CSUType _ n) = n
145+
annotation (CEnumType _ n) = n
146+
annotation (CTypeDef _ n) = n

0 commit comments

Comments
 (0)