<div dir="ltr">That's my use case, it's different than the OP, probably.<div><br></div><div>In my case, I want to generate a first pass, with a JIT (the code is generated from another description), but the generated code could be changed by the user in a subsequent pass.</div><div>Modifying directly the AST is not an option, try generating equations with thousands of parameters that are solved in real time. Just no way someone can write them efficiently in IR (that's why you have the AST to IR generator!).</div><div><br></div><div>I don't understand your last paragraph. If clang-format can cleanup rewrites, why can't it reformat code from the AST? If the AST printer writes any kind of code, why couldn't clang-format reformat it?</div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">Le mar. 10 juil. 2018 à 22:41, David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hmm, not sure I follow.<br><br>Did the user write this source code? Are they going to want to change it later? Does it make sense for them to see the edits you're suggesting, or are those edits really compiler optimizations/transformations? If they're more the latter, then perhaps caching the LLVM IR (with these optimizations/transformations applied) rather than modifying the source would be more suitable.<br><br>Easier to generate correctly formatted code from the AST? Not really - the AST printing doesn't have any particularly nuanced formatted printing. That's what clang-format is for (it was specifically built for doing code rewrites based on ASTs - where the rewrite is expressed as a textual change to the original source (not an AST modification) & that change is applied, then clang-format is used to tidy it up).</div><br><div class="gmail_quote"><div dir="ltr">On Tue, Jul 10, 2018 at 2:11 PM Matthieu Brucher <<a href="mailto:matthieu.brucher@gmail.com" target="_blank">matthieu.brucher@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">It's odd though, because generating code on the fly would be easier on the AST than on the IR tree, if the goal is JIT and also saving the code at the same time.<div>It's probably also easier also to generate properly formatted code?</div><div><br></div><div>Regards,</div><div><br></div><div>Matthieu</div></div><br><div class="gmail_quote"><div dir="ltr">Le mar. 10 juil. 2018 à 16:21, David Blaikie via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">It's generally considered that the AST invariants are too subtle/complex to use AST modification and AST->source conversion reliably. Refactoring/source code modification is generally encouraged to be done via textual edits generated from source location information in the AST.<br><br><div class="gmail_quote"><div dir="ltr">On Mon, Jul 9, 2018 at 8:36 PM Ridwan Shariffdeen via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-family:garamond,serif;font-size:small">Hi,</div><div class="gmail_default" style="font-family:garamond,serif;font-size:small"><br></div><div class="gmail_default" style="font-family:garamond,serif;font-size:small">I am trying to build a tool which can insert new AST nodes to a AST tree obtained from a source code and generate the modified source code. For example add an if condition to a given location. <br><br>I have seen examples on ReWriter which can insert text, but I want to insert a proper AST node and generate the source code from the modified AST. </div><div class="gmail_default" style="font-family:garamond,serif;font-size:small"><br></div><div class="gmail_default" style="font-family:garamond,serif;font-size:small">For this purpose, I think I should be using ASTWriter and not ReWriter. Is there any documentation I can refer on how to implement this?</div><div class="gmail_default" style="font-family:garamond,serif;font-size:small"><br></div><div class="gmail_default" style="font-family:garamond,serif;font-size:small">Any help in this regard is highly appreciated. </div><div class="gmail_default" style="font-family:garamond,serif;font-size:small"><br></div><div class="gmail_default" style="font-family:garamond,serif;font-size:small">Thanks!</div><div class="gmail_default" style="font-family:garamond,serif;font-size:small">Ridwan</div></div>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div></div>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="m_5750601677052724679m_-4642569081504176905gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>Quantitative analyst, Ph.D.<br>Blog: <a href="http://blog.audio-tk.com/" target="_blank">http://blog.audio-tk.com/</a><br>LinkedIn: <a href="http://www.linkedin.com/in/matthieubrucher" target="_blank">http://www.linkedin.com/in/matthieubrucher</a></div></div></div></div></div>
</blockquote></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>Quantitative analyst, Ph.D.<br>Blog: <a href="http://blog.audio-tk.com/" target="_blank">http://blog.audio-tk.com/</a><br>LinkedIn: <a href="http://www.linkedin.com/in/matthieubrucher" target="_blank">http://www.linkedin.com/in/matthieubrucher</a></div></div></div></div></div>