-
Notifications
You must be signed in to change notification settings - Fork 707
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
Possible alternative to rust-cexpr #1762
Comments
That looks nice. It would probably depend on how much bloat does it bring in compared to cexpr, but probably could be an opt-in feature otherwise if needed. I think the biggest issues we have with macros are a bit more intrinsic to macros, like "we don't know if a name refers to a named constant because that's only really known at the time of expansion". Also note that we only use cexpr for preprocessing so we don't really need or want full compilation. We use libclang for that. I think the biggest use-case that's missing from cexpr (apart from maybe trying to understand some types, but that's another of the "can't really know until expansion" bits, which seem hard to solve because there may not be any expansion at all) is the "invoking a functional macro with a constant argument". That seems like it could be reasonably handled. Can you elaborate on how bindgen would use your compiler, and which enhancements or regressions can we expect from that? |
Yes, that's the major complaint I've had. I can feature-gate all the codegen, but the fewest dependencies I have right now still have a dependency on
Ok, if you use
Hmm that sounds interesting ... I could try expanding object macros and seeing if they form a valid expression and giving you back that type. It won't work all the time but it might work more than it does now? For function macros I could try setting all the arguments to
That's handled now, yes.
Sure thing. I'd expect bindgen to use rcc to expand C macros into Rust AdvantagesI listed most of the advantages above but I can go into more detail:
Regressions
I'm not sure how you currently pass expressions to cexpr, but note that if you want rcc to handle backslashes before newlines you might have to pass in multiple lines of C source code. If clang handles this it won't be an issue. Things that won't change
In general |
Well bindgen depends on syn / quote as well so that in particular is not a massive issue. cranelift would be though :) What we do is here: Line 700 in f686751
i.e., we pass the already-tokenized clang input to cexpr. That function has a single caller. We keep the already-parsed macros here: rust-bindgen/src/ir/context.rs Line 355 in d65100e
We're technically running the preprocessor with clang already, so a third option would be to somehow add / expose the same "try to expand this now" capability to libclang. But using |
Ok great! Yes cranelift is definitely optional, that shouldn't be an issue. Here's an idea for what
It's a little different since my The Note that this is all psuedocode because most of the API you'd need isn't currently public, I can change that in the next release of rcc. Let me know if there's anything else you're looking for! |
I was working on this a little bit and ran on a problem that I'm not sure the right way to solve. In For context, locations are used for providing highlighting for errors in the C code (really they should be called |
Clang tokens do have locations though they may not be exposed right now. Should be straight-forward to expose it (cursors already expose a location) see the docs for |
I am inferring from saltwater@ Consequently I am closing the issue. |
FWIW, I still think this is useful - would be willing to work on it some more if I could have some hope reviews would take less than 3 months between each look ... |
I noticed that you commented on jethrogb/rust-cexpr#23 that you depend on cexpr and don't want it to be unmaintained. As another alternative, I'm currently working on a C compiler in Rust which doesn't have any C dependencies on LLVM. It handles
It does not currently support cross-compiling, but it will soon™.
Let me know if you're interested! I don't currently have the exact API cexpr exposes (
preprocessor_expr
or something like that), but I could add it without much trouble.The text was updated successfully, but these errors were encountered: