-
Notifications
You must be signed in to change notification settings - Fork 0
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
Generate external bindings during translation #480
Comments
External bindings configuration should be generated from the The current pipeline can be seen in #498 (comment). If we add the graph TD
Clang-- parseCHeader -->C
C-- genHsDecls -->Hs
Hs-- genSHsDecls --> SHs
subgraph Preprocessor
PPIO["`source
(IO)`"]
PPPure["`source
(pure)`"]
HsModule-- genPP -->PPIO
HsModule-- genPPString -->PPPure
end
SHs-- genModule -->HsModule
subgraph Template Haskell
DecsQ
Exts[Set TH.Extension]
end
SHs-- genTH --> DecsQ
SHs-- genExtensions --> Exts
Dump["`dump
(IO)`"]
C-- dumpCHeader -->Dump
Hs-- genExtBindings -->ExtBindings
Tests["`tests
(IO)`"]
Hs-- genTests -->Tests
Any opinions? My vote is to go ahead and add |
Our external bindings design includes the Haskell package name. It is not actually used anywhere, though we may use it in the future, and it is probably useful information for users. We do not yet have this information (when using the The current plan is to add a new Example usage:
That example demonstrates how it would work now. Improvements include: After we implement support for getting information from a
Notes:
|
Consider the case of creating bindings with multiple modules for C headers First translate
Then translate
Those commands create separate external bindings configurations for each module, which need to be merged to create an external bindings configuration for the package. Note that this is already implemented in function Related discussion: #75 (comment) |
@edsko and I discussed this yesterday. We decided to go ahead and move development commands to a separate CLI, as @phadej suggested. Main CLI With that change, FWIW, I like the new public API much better! |
Test
There is an issue. Type typedef struct S5 {
char a;
int b;
} S5; In this case, we translate to a single Haskell type - cname: struct S5
headers:
- simple_structs.h
identifier: S5
module: Acme.SimpleStructs
package: acme This is correct, but we also need to generate the following: - cname: S5
headers:
- simple_structs.h
identifier: S5
module: Acme.SimpleStructs
package: acme
|
Nope, the information is not included in the structDeclPath = DeclPathStruct (DeclNameTag (CName "S5")) DeclPathTop My initial understanding was correct. |
In the processing of We need to be able to distinguish the case when a DeclPathStruct
(DeclNameTag "foo")
(DeclPathStruct (DeclNameTypedef "foo") DeclPathTop) The two uses of An alternative way to do this is to add a constructor: -- | Structure/union/enum tag and typedef name are the same
DeclNameBoth CName Thoughts? |
I am using trace debugging to try to understand the exact order of processing as we fold the Clang AST. I am currently considering the following declaration, in // struct with typedef
typedef struct S2 {
char a;
int b;
float c;
} S2_t; As noted in a comment, a Consider this line in the code that processes the use <-
processTypeDeclRec
(DeclPathStruct (DeclNameTypedef tag) DeclPathTop)
extBindings
unit
Nothing
ty'
The Since a type may have any number of One way to resolve the issue is to add aliases to the C AST. Note that aliases should be separate from the canonical Alternatively, we could change |
@TravisCardwell you overcomplicate the matter. AFAIK (if it's not please tell),
and
generate the same In particular, I made sure that
and
work the same. This was in length discussed in #306 |
Yes, the generated Haskell looks good. I am working on generating the external bindings. For this example, we can already generate external bindings without issue because each I am running into trouble when the typedef struct S5 {
char a;
int b;
} S5; In this case, we only translate to a single Haskell type. We need to generate bindings for both My idea for resolving this is to add alias information to the C AST. If we assume that the case where the Are there any other (perhaps not-yet-implemented) cases where there are more than one C name spelling that map to the same translated Haskell type? |
typedef struct S5 {
char a;
int b;
} S5; is the same as typedef struct {
char a;
int b;
} S5; We don't differentiate these (partly because That's also discussed in #306 |
We should support generation of external bindings configuration for a module during translation. This is only relevant to the preprocessor mode. We can add an option to the CLI
preprocessor
command to enable this as well as specify the output file path.The text was updated successfully, but these errors were encountered: