[cfe-dev] Serializing conflicting replacements

Manuel Klimek via cfe-dev cfe-dev at lists.llvm.org
Thu Sep 28 01:10:31 PDT 2017


On Wed, Sep 27, 2017 at 8:06 PM Roman Popov via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> Hi all,
> I need to write a tool that will convert stackful coroutine to stackless.
> One of the required refactorings is inlining all functions that call yield
> into a coroutine body.
>
> Here is an example of required refactoring:
>
> Input source code:
>
> void foo() { /*foo*/ yield(); }
>
> void bar() { /*bar*/  foo(); }
>
> void coroutine_body() {
>   bar();
> }
>
> Expected output code from tool:
>
> void coroutine_body() {
>    /*bar*/
>    /*foo*/
>    yield();
> }
>
>
> So when I run the tool it will create two conflicting replacements:
>
>    - inline foo into bar
>    - inline bar into coroutine_body
>
>
> Is it possible to apply them one after another using current Clang
> libraries?  Or it is not supported out-of-the-box and I should better run
> tool N times to inline all functions one-by-one without generating
> conflicting replacements?
>

We do have Replacements::merge(), but the merged replacements need to be
relative to the new code after applying the original replacements, so
that's not fully helping.
I think running the tool multiple times is probably simplest, but it's also
possible to build up the dependency chain of your replacements yourself,
and then creating one large replacement in the end from the dep tree.


>
> Thanks,
> Roman
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170928/f5a2689b/attachment.html>


More information about the cfe-dev mailing list