Skip to content

Commit 1611562

Browse files
Merge pull request #347 from well-typed/c-types-prelude
Add minimal `LibC` module
2 parents 8221616 + 7f5ff69 commit 1611562

File tree

891 files changed

+59169
-68
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

891 files changed

+59169
-68
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ unversioned
44
cabal.project.local
55
.vscode/
66
*.dll
7+
macros-recognized.log

hs-bindgen-libclang/src/HsBindgen/Clang/Args.hs

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{-# LANGUAGE LambdaCase #-}
2+
13
module HsBindgen.Clang.Args (
24
ClangArgs(..)
35
, CStandard(..)
@@ -15,6 +17,9 @@ import HsBindgen.Clang.Version
1517

1618
-- | @libclang@ command line arguments
1719
--
20+
-- The default standard when one is not specified depends on the Clang version
21+
-- and has GNU extensions enabled.
22+
--
1823
-- TODO: <https://github.com/well-typed/hs-bindgen/issues/83> (also #10 and #71).
1924
-- We should support more of the command line arguments of @clang@.
2025
data ClangArgs = ClangArgs {
@@ -24,6 +29,9 @@ data ClangArgs = ClangArgs {
2429
-- | C standard
2530
, clangCStandard :: Maybe CStandard
2631

32+
-- | Enable GNU extensions when 'True'
33+
, clangEnableGnu :: Bool
34+
2735
-- | Other arguments
2836
--
2937
-- See https://clang.llvm.org/docs/ClangCommandLineReference.html
@@ -43,17 +51,18 @@ data ClangArgs = ClangArgs {
4351
-- We don't currently support @C2y@ because it requires @clang-19@ or later and
4452
-- we have no reliable way to test for that (see 'ClangVersion').
4553
data CStandard =
46-
C23
47-
| C17
48-
| C11
54+
C89
4955
| C99
50-
| C89
51-
deriving stock (Show, Eq)
56+
| C11
57+
| C17
58+
| C23
59+
deriving stock (Bounded, Enum, Eq, Ord, Show)
5260

5361
defaultClangArgs :: ClangArgs
5462
defaultClangArgs = ClangArgs {
5563
clangTarget = Nothing
5664
, clangCStandard = Nothing
65+
, clangEnableGnu = False
5766
, clangOtherArgs = []
5867
}
5968

@@ -66,28 +75,41 @@ fromClangArgs args = aux [
6675
ifGiven clangTarget $ \target ->
6776
return ["-target", target]
6877

69-
, ifGiven clangCStandard $ \cStandard ->
70-
case cStandard of
71-
C23 -> -- We can use @-std=c23@ in @clang-18@ or later, but we have no
72-
-- reliable way of testing for that.
73-
if clangVersion >= Clang9_or_10
74-
then return ["-std=c2x"]
75-
else throwError "C23 requires clang-9 or later"
76-
C17 -> if clangVersion >= Clang6
77-
then return ["-std=c17"]
78-
else throwError "C17 requires clang-6 or later"
79-
C11 -> if clangVersion == ClangOlderThan3_2
80-
then return ["-std=c1x"]
81-
else return ["-std=c11"]
82-
C99 -> return ["-std=c99"]
83-
C89 -> return ["-std=c89"]
78+
, ifGiven clangCStandard $ \case
79+
C89
80+
| clangEnableGnu -> return ["-std=gnu89"]
81+
| otherwise -> return ["-std=c89"]
82+
C99
83+
| clangEnableGnu -> return ["-std=gnu99"]
84+
| otherwise -> return ["-std=c99"]
85+
C11
86+
| clangEnableGnu -> return $
87+
if clangVersion == ClangOlderThan3_2
88+
then ["-std=gnu1x"]
89+
else ["-std=gnu11"]
90+
| otherwise -> return $
91+
if clangVersion == ClangOlderThan3_2
92+
then ["-std=c1x"]
93+
else ["-std=c11"]
94+
C17
95+
| clangVersion < Clang6 -> throwError "C17 requires clang-6 or later"
96+
| clangEnableGnu -> return ["-std=gnu17"]
97+
| otherwise -> return ["-std=c17"]
98+
-- We can use @-std=c23@ in @clang-18@ or later, but we have no reliable
99+
-- way of testing for that.
100+
C23
101+
| clangVersion < Clang9_or_10 ->
102+
throwError "C23 requires clang-9 or later"
103+
| clangEnableGnu -> return ["-std=gnu2x"]
104+
| otherwise -> return ["-std=c2x"]
84105

85106
, return clangOtherArgs
86107
]
87108
where
88109
ClangArgs{
89110
clangTarget
90111
, clangCStandard
112+
, clangEnableGnu
91113
, clangOtherArgs
92114
} = args
93115

hs-bindgen-patterns/hs-bindgen-patterns.cabal

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,25 @@ library
3636
import:
3737
lang
3838
exposed-modules:
39-
HsBindgen.Patterns
4039
HsBindgen.ConstantArray
40+
HsBindgen.Patterns
4141
HsBindgen.Patterns.FlexibleArrayMember
42+
HsBindgen.Patterns.LibC
4243
other-modules:
4344
HsBindgen.Patterns.Arithmetic
4445
HsBindgen.Patterns.Backtrace
4546
HsBindgen.Patterns.Enum.Bitfield
4647
HsBindgen.Patterns.Enum.Simple
48+
HsBindgen.Patterns.LibC.Arch
4749
hs-source-dirs:
4850
src
51+
if arch(x86_64)
52+
hs-source-dirs: src-x86_64
53+
else
54+
if arch(aarch64)
55+
hs-source-dirs: src-aarch64
56+
else
57+
buildable: False
4958
build-depends:
5059
, pretty-show >= 1.10 && < 1.11
5160
, vector ^>=0.13.2.0
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module HsBindgen.Patterns.LibC.Arch (
2+
) where
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module HsBindgen.Patterns.LibC.Arch (
2+
) where

0 commit comments

Comments
 (0)