-
Notifications
You must be signed in to change notification settings - Fork 757
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
C API #427
C API #427
Conversation
|
||
typedef uint32_t BinaryenType; | ||
|
||
BinaryenType BinaryenNone(void); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems strange to not just use an enumeration here. Is this to prevent API breakage if the type values change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also for changes, but the main reason is that compilers using the C API might not want to use a C header. For example, Rust is not written in C, so it can't execute the C header to get those enum values. Instead it links with C libraries and calls methods on them using the C ABI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another option is a C++11 enum class with an explicit type:
enum class Color : uint32_t
{
Red, Green, Blue
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That still doesn't help the Rust use case, though? Or did I misunderstand you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might make the C++ use case a little nicer while not harming the rust use case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Yeah, I agree that might be nicer. There is the gcc bug mentioned in another comment on this PR, though, which worries me.
Looks pretty good. Have you thought about how you'd manipulate the AST after it has been created? Also, personally I'd suggest something shorter than |
No, I haven't thought much about manipulation yet. Hopefully most compilers won't need it? Probably that's too optimistic ;) About the prefix, how about "Bin"? Or any other ideas? |
Well, if you imagine the users of the API are just producers than yeah, probably not needed. I was imagining users who will want to read a binary module and then do stuff with it.
How about |
|
But I like the shortening, Probably too short, but maybe,
Definitely the kind of pun I like, but probably too much for a C API ;) |
Or maybe |
I like |
Yeah, maybe the choice is Meanwhile I added a kitchen-sink test of the api, which found a few bugs that are now fixed. |
Ok, let's merge this. We can change the name later if there are opinions about it. |
This adds a C API and a test which shows an example of using it. I've never been much of an API designer, apologies for what you're about to see.
The API is generally similar to LLVM's API which is probably the most popular compiler API. However, as we have structured control flow and statements=expressions etc., this API follows that. As a follow-up, though, I intend to add a basic-block oriented API on top of this, which should be more familiar for compilers (and then using relooping internally we can generate structured control flow as needed).
The "hello world" example and its output are the last two files in the diff.