Takashiidobe wrote:

> > 👋 since I wrote the issue. I've been working on translating C to rust, 
> > primarily with clang ir. I ran into some code in the wild that had the 
> > pattern from the linked issue, and shrunk it down to what I linked there.
> > My assumption was that constness should be preserved (clang-ast properly 
> > preserves it) and that it should be the same for clang-ir side since it's 
> > useful information if you want to look at the clang ir itself.
> > If not I'm also fine to close the issue, since I do have a way around it 
> > (transmute/fetch from the ast), and since it does cause some maintenance 
> > burden I can understand not wanting to support this use case.
> 
> That's an interesting use case. I don't think we want to preserve all the 
> information in the AST. We also would like to break any dependencies on the 
> AST, since that means the CIR can't be effectively written to disk without 
> also writing the entire AST.
> 
> Why wouldn't you perform your translation directly from the AST?

I started out using the AST but i found CIR easier to use so I swapped over. 
CIR (currently) does most of what I want since it adds metadata for alignment, 
types, handles widths, doesn't have a lot of include soup, and is much more 
compact to read. 

There's pros and cons, and I still do have to rely on the AST (for comments, 
macros, unsupported functionality), and I don't expect CIR to help with that 
part, but it's fairly rare and I assume as more work is done the NYIs/bugs will 
disappear. I was able to get translation done up to C23 features without much 
need for the AST.

For the comment about dropping direct AST support, I don't need most of the 
AST, the reason why I'm using CIR is because it drops most of the AST and does 
post processing. For my use case the IR would be too low level, the AST is too 
high-level, and CIR does most of the postprocessing I want so I figured I'd 
piggyback on that work instead of doing it myself. 

https://github.com/llvm/llvm-project/pull/218114
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to