<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Nov 30, 2016, at 12:38 PM, John McCall <<a href="mailto:rjmccall@apple.com" class="">rjmccall@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><blockquote type="cite" class=""><div class="">On Nov 30, 2016, at 11:54 AM, Mehdi Amini <<a href="mailto:mehdi.amini@apple.com" class="">mehdi.amini@apple.com</a>> wrote:</div><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><blockquote type="cite" class=""><div class="">On Nov 30, 2016, at 11:49 AM, Gianluca Stivan <<a href="mailto:me@yawnt.com" class="">me@yawnt.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Oh, that's actually even better than what I was thinking (and would precisely result in my desired outcome)<div class=""><br class=""></div><div class="">In the talk someone asks if there are any plans to implement an example to showcase the technique using Kaleidoscope. Was that ever published, by any chance?</div></div></div></blockquote><div class=""><br class=""></div><div class="">I don’t know, but in the meantime Swift has been released open-source. So there might be something to get from there.</div><div class=""><br class=""></div><div class="">CC Jordan and John (this is about your talk "Skip the FFI" <a href="http://llvm.org/devmtg/2014-10/#talk18" class="">http://llvm.org/devmtg/<wbr class="">2014-10/#talk18</a> )</div></div></div></div></blockquote><div class=""><br class=""></div>Swift is using information from Clang's IRGen library to lower to the C ABI, but that process is still more manual than I'd like; it'd be nice if there were a library capable of doing all the work to translate the arguments and generate the call.</div></div></div></blockquote><div><br class=""></div><div>FYI, I believe we discussed having a GSOC to start this here: <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-October/106579.html" class="">http://lists.llvm.org/pipermail/llvm-dev/2016-October/106579.html</a></div><div><br class=""></div><div>— </div><div>Mehdi</div><div><br class=""></div><div><br class=""></div><div><br class=""></div><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""></div><div class=""><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><br class=""></div><div class="">Thank you so much for the link!<br class=""></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">2016-11-30 16:39 GMT+00:00 Mehdi Amini <span dir="ltr" class=""><<a href="mailto:mehdi.amini@apple.com" target="_blank" class="">mehdi.amini@apple.com</a>></span>:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><br class=""><div class=""><span class=""><blockquote type="cite" class=""><div class="">On Nov 30, 2016, at 6:20 AM, Alex L via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank" class="">cfe-dev@lists.llvm.org</a>> wrote:</div><br class="m_1389824818702278916Apple-interchange-newline"><div class=""><div dir="ltr" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><div class="gmail_extra"><br class="m_1389824818702278916Apple-interchange-newline"><br class=""><div class="gmail_quote">On 30 November 2016 at 13:51, Gianluca Stivan<span class="m_1389824818702278916Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:me@yawnt.com" target="_blank" class="">me@yawnt.com</a>></span><span class="m_1389824818702278916Apple-converted-space"> </span>wrote:<br class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr" class="">@mats Yeah, you're right, an LLVM Pass seems to be the correct approach here, however Alex is bringing up a fair point<div class=""><br class=""></div><div class="">@Alex </div><div class=""><br class=""></div><div class="">I was just checking by compiling the header files for libgit2 (in my clang fork) and you seem to be correct, there are some cases where informations are lost. Take the following example:</div><div class=""><br class=""></div><div class="">------------------------------<wbr class="">-------------------</div><div class="">struct xyz { int x; int y; int z; } xyz;</div><div class=""><br class=""></div><div class="">struct xyz fill(int x, int y, int z);<br class=""></div><div class=""><br class=""></div><div class="">void pointer(struct xyz* d);<br class=""></div><div class=""><div class="">------------------------------<wbr class="">-------------------<br class=""></div><div class=""><br class=""></div><div class="">I do have correct informations for `pointer` (LLVM returns `declare void @pointer(%<a href="http://struct.xyz/" target="_blank" class="">struct.xyz</a>*)`), but not for `fill` (LLVM returns `declare { i64, i32 } @fill(i32, i32, i32)`). I suppose there's no way to get those informations back as AST -> IR is a lossy transformation.</div><div class=""><br class=""></div><div class="">If I had some way to link the generated `declare` back to the function AST node, that would obviously help in generating my frontend stub. But even so, I would still need to follow the function's signature to get the parameters' type definition, and so on. I'm beginning to wonder if it's just more sane to use libclang, after all.</div></div></div></blockquote><div class=""><br class=""></div><div class="">Yeah, the lowering to the IR by clang is lossy, and AFAIK there's no way to go in the reverse direction. Maybe the debug information could allow you to reverse the layout? In any case I think that's doing this reverse approach isn't worth it if you can use clang directly.</div><div class=""><br class=""></div><div class="">Btw, there has been discussion recently about making a separate library that handles this transformation process:<span class="m_1389824818702278916Apple-converted-space"> </span><a href="http://lists.llvm.org/pipermail/llvm-dev/2016-October/106660.html" target="_blank" class="">http://lists.llvm.<wbr class="">org/pipermail/llvm-dev/2016-<wbr class="">October/106660.html</a>. </div></div></div></div></div></blockquote><div class=""><br class=""></div></span><div class="">See also: <a href="http://llvm.org/devmtg/2014-10/#talk18" target="_blank" class="">http://llvm.org/devmtg/<wbr class="">2014-10/#talk18</a></div><div class=""><br class=""></div><div class="">— </div><span class="HOEnZb"><font color="#888888" class=""><div class="">Mehdi</div></font></span><div class=""><div class="h5"><div class=""><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr" class=""><div class=""><div class=""><br class=""></div><div class=""><br class=""></div></div></div><div class="m_1389824818702278916gmail-HOEnZb"><div class="m_1389824818702278916gmail-h5"><div class="gmail_extra"><br class=""><div class="gmail_quote">2016-11-30 12:12 GMT+00:00 Alex L<span class="m_1389824818702278916Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:arphaman@gmail.com" target="_blank" class="">arphaman@gmail.com</a>></span>:<br class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr" class=""><br class=""><div class="gmail_extra"><br class=""><div class="gmail_quote"><span class="">On 30 November 2016 at 11:32, Gianluca Stivan<span class="m_1389824818702278916Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:me@yawnt.com" target="_blank" class="">me@yawnt.com</a>></span><span class="m_1389824818702278916Apple-converted-space"> </span>wrote:<br class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr" class="">True,<div class=""><br class=""></div><div class="">I was toying with the idea of having a separate step in the pipeline that plugs in after AST is turned into a Module[*] which generates frontend code.</div><div class="">But to do so, I would have to have forward declarations be actually emitted, hence my proposal. Otherwise I'd just be iterating over an empty set of instructions :)</div><div class="">My theory is that LLVM IR at that point is going to be way more straightforward (just basic types, structs and `declare @..`s) to deal with.</div><div class="">Could this approach make sense? <br class=""></div></div></blockquote><div class=""><br class=""></div></span><div class="">I see, so are you thinking about basically looking at the LLVM IR with the C function declarations and generating the calls based on the IR declarations yourself instead or relying on clang? I suppose that could work, but I'm not 100% sure that it will be correct in all cases. How will your front-end deal with functions that take and return C aggregate types?</div><span class=""><div class=""> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr" class=""><div class=""></div><div class=""><br class=""></div><div class="">Cheers,</div><div class=""><br class=""></div><div class="">-yawnt</div><div class=""><br class=""></div><div class="">[*] a Clang plugin? Can they be run over Modules, that is LLVM IR, instead of AST?</div><div class=""><br class=""></div></div><div class="m_1389824818702278916gmail-m_1511894068863561271m_-8273706179846248178HOEnZb"><div class="m_1389824818702278916gmail-m_1511894068863561271m_-8273706179846248178h5"><div class="gmail_extra"><br class=""><div class="gmail_quote">2016-11-30 10:59 GMT+00:00 Alex L<span class="m_1389824818702278916Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:arphaman@gmail.com" target="_blank" class="">arphaman@gmail.com</a>></span>:<br class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr" class=""><br class=""><div class="gmail_extra"><br class=""><div class="gmail_quote"><span class="">On 30 November 2016 at 09:12, Gianluca Stivan via cfe-dev<span class="m_1389824818702278916Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank" class="">cfe-dev@lists.llvm.<wbr class="">org</a>></span><span class="m_1389824818702278916Apple-converted-space"> </span>wrote:<br class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr" class="">Hi everyone,<div class=""><br class=""></div><div class="">I was playing around with the LLVM toolchain and it occurred to me that, should I decide to target LLVM IR, it would be neat to have Clang generate declarations from C header files for easier FFI. Someone seems to have had my same idea [1] [2]. This is kind of the opposite of what other projects have gone for, where they use libclang to parse header files to achieve the same result [3].</div></div></blockquote><div class=""><br class=""></div></span><div class="">Sounds like an interesting idea. I how one question though, if you're generating only the C function declarations in LLVM IR, how will your frontend that targets LLVM IR call these declarations? Maybe I'm misunderstanding something, but I don't see how can you generate the calls to these functions without getting clang involved.</div><div class=""><br class=""></div><div class="">Cheers,</div><div class="">Alex</div><div class=""> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class=""><div dir="ltr" class=""><div class=""><br class=""></div><div class="">Now, forward declaration generation is doable by patching CodeGenModule.cpp (I kinda have a PoC working locally, except it generates *all* the forward declarations, instead of just the ones from the header files I care about)</div><div class=""><br class=""></div><div class="">Is this something that you guys would be interested in merging into Clang through a flag? Or what would the proper way to do this be? </div><div class="">I saw there's a `-femit-all-decls`, but it doesn't really emit all declarations.</div><div class=""><br class=""></div><div class=""><div class="">Apologies if this is a dumb idea, kinda new to the whole Clang thing :)!</div></div><div class=""><br class=""></div><div class="">Cheers,</div><div class=""><br class=""></div><div class="">-yawnt</div><div class=""><br class=""></div><div class="">[1]<span class="m_1389824818702278916Apple-converted-space"> </span><a href="http://stackoverflow.com/questions/24728901/clang-compiling-a-c-header-to-llvm-ir-bitcode" target="_blank" class="">http://stackoverflow.com/<wbr class="">questions/24728901/clang-<wbr class="">compiling-a-c-header-to-llvm-<wbr class="">ir-bitcode</a></div><div class="">[2] <a href="http://stackoverflow.com/questions/14032496/how-can-i-code-generate-unused-declarations-with-clang?noredirect=1&lq=1" target="_blank" class="">http://stackoverflow.com/q<wbr class="">uestions/14032496/how-can-i-co<wbr class="">de-generate-unused-declaration<wbr class="">s-with-clang?noredirect=1&lq=1</a></div><div class="">[3] <a href="https://github.com/tjfontaine/node-ffi-generate" target="_blank" class="">https://github.com/tjfonta<wbr class="">ine/node-ffi-generate</a></div></div><br class=""></span>______________________________<wbr class="">_________________<br class="">cfe-dev mailing list<br class=""><a href="mailto:cfe-dev@lists.llvm.org" target="_blank" class="">cfe-dev@lists.llvm.org</a><br class=""><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/cgi-bin/<wbr class="">mailman/listinfo/cfe-dev</a><br class=""><br class=""></blockquote></div><br class=""></div></div></blockquote></div><br class=""></div></div></div></blockquote></span></div><br class=""></div></div></blockquote></div><br class=""></div></div></div></blockquote></div><br class=""></div></div><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important" class="">______________________________<wbr class="">_________________</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important" class="">cfe-dev mailing list</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important" class=""><a href="mailto:cfe-dev@lists.llvm.org" target="_blank" class="">cfe-dev@lists.llvm.org</a></span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important" class=""><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" target="_blank" class="">http://lists.llvm.org/cgi-bin/<wbr class="">mailman/listinfo/cfe-dev</a></span></div></blockquote></div></div></div><br class=""></div></blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></div></div></blockquote></div><br class=""></div></div></blockquote></div><br class=""></body></html>