Need help with source-to-source translation

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Need help with source-to-source translation

Sumner, Brian via cfe-dev

Hi everyone,

let's consider the example:

int foo(int p) {

    if ( p)

       /* code path#1 */

        return 0;

     else    {

        /* code path#2 */

        return 1;

    }

}

1. What is the best solution to get the string representation of the expression of a return statement?

2. Because I want to perform some transformation with return statements I have to figure out if they are enclosed in a block?

The example above should be transformed in something like

int foo(int p) {

    if ( p) { /* <---- */

       /* do some processing ... */

        return 0;

     } /* <--- */

     else    {

       /* do some processing ... */

        return 1;

    }

}

Any hints or pointers are welcome.

Thanks

Marcel


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Need help with source-to-source translation

Sumner, Brian via cfe-dev
You'll probably want to take a look at libtooling:
https://clang.llvm.org/docs/LibTooling.html

On Fri, Jul 28, 2017 at 4:54 PM Marcel Schaible via cfe-dev <[hidden email]> wrote:

Hi everyone,

let's consider the example:

int foo(int p) {

    if ( p)

       /* code path#1 */

        return 0;

     else    {

        /* code path#2 */

        return 1;

    }

}

1. What is the best solution to get the string representation of the expression of a return statement?

2. Because I want to perform some transformation with return statements I have to figure out if they are enclosed in a block?

The example above should be transformed in something like

int foo(int p) {

    if ( p) { /* <---- */

       /* do some processing ... */

        return 0;

     } /* <--- */

     else    {

       /* do some processing ... */

        return 1;

    }

}

Any hints or pointers are welcome.

Thanks

Marcel

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Need help with source-to-source translation

Sumner, Brian via cfe-dev
Manuel, thanks for your help. Of course I went already through a bunch of documentation including libtooling.
My tool is performing now the basic setup and can transform some simple cases.

Do you know by chance how to retrieve the ASTContext from a ReturnStmt and a FuncDecl?

BTW: Your presentation at the EURO LLVM was very helpful!

Greetings from Munich

Marcel



Am 01.08.2017 um 12:16 schrieb Manuel Klimek:
You'll probably want to take a look at libtooling:
https://clang.llvm.org/docs/LibTooling.html

On Fri, Jul 28, 2017 at 4:54 PM Marcel Schaible via cfe-dev <[hidden email]> wrote:

Hi everyone,

let's consider the example:

int foo(int p) {

    if ( p)

       /* code path#1 */

        return 0;

     else    {

        /* code path#2 */

        return 1;

    }

}

1. What is the best solution to get the string representation of the expression of a return statement?

2. Because I want to perform some transformation with return statements I have to figure out if they are enclosed in a block?

The example above should be transformed in something like

int foo(int p) {

    if ( p) { /* <---- */

       /* do some processing ... */

        return 0;

     } /* <--- */

     else    {

       /* do some processing ... */

        return 1;

    }

}

Any hints or pointers are welcome.

Thanks

Marcel

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Need help with source-to-source translation

Sumner, Brian via cfe-dev
On Tue, Aug 1, 2017 at 12:35 PM Marcel Schaible <[hidden email]> wrote:
Manuel, thanks for your help. Of course I went already through a bunch of documentation including libtooling.
My tool is performing now the basic setup and can transform some simple cases.

Do you know by chance how to retrieve the ASTContext from a ReturnStmt and a FuncDecl?

Generally, if you use AST matchers you'll have the ASTContext in the callback. What exactly is the problem you're running into?

BTW: Your presentation at the EURO LLVM was very helpful!

Thanks! :)
 

Greetings from Munich


Marcel




Am 01.08.2017 um 12:16 schrieb Manuel Klimek:
You'll probably want to take a look at libtooling:
https://clang.llvm.org/docs/LibTooling.html

On Fri, Jul 28, 2017 at 4:54 PM Marcel Schaible via cfe-dev <[hidden email]> wrote:

Hi everyone,

let's consider the example:

int foo(int p) {

    if ( p)

       /* code path#1 */

        return 0;

     else    {

        /* code path#2 */

        return 1;

    }

}

1. What is the best solution to get the string representation of the expression of a return statement?

2. Because I want to perform some transformation with return statements I have to figure out if they are enclosed in a block?

The example above should be transformed in something like

int foo(int p) {

    if ( p) { /* <---- */

       /* do some processing ... */

        return 0;

     } /* <--- */

     else    {

       /* do some processing ... */

        return 1;

    }

}

Any hints or pointers are welcome.

Thanks

Marcel

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Need help with source-to-source translation

Sumner, Brian via cfe-dev
At the moment I am using the ASTConsumer/ASTVisitor interface. But I am planing to switch to AST matchers asap.
After scratching my head for a while I found the solution for my problem. It was just a misunderstanding of the inheritance tree.

Thanks for your help

Marcel
Am 01.08.2017 um 13:48 schrieb Manuel Klimek:
On Tue, Aug 1, 2017 at 12:35 PM Marcel Schaible <[hidden email]> wrote:
Manuel, thanks for your help. Of course I went already through a bunch of documentation including libtooling.
My tool is performing now the basic setup and can transform some simple cases.

Do you know by chance how to retrieve the ASTContext from a ReturnStmt and a FuncDecl?

Generally, if you use AST matchers you'll have the ASTContext in the callback. What exactly is the problem you're running into?

BTW: Your presentation at the EURO LLVM was very helpful!

Thanks! :)
 

Greetings from Munich


Marcel




Am 01.08.2017 um 12:16 schrieb Manuel Klimek:
You'll probably want to take a look at libtooling:
https://clang.llvm.org/docs/LibTooling.html

On Fri, Jul 28, 2017 at 4:54 PM Marcel Schaible via cfe-dev <[hidden email]> wrote:

Hi everyone,

let's consider the example:

int foo(int p) {

    if ( p)

       /* code path#1 */

        return 0;

     else    {

        /* code path#2 */

        return 1;

    }

}

1. What is the best solution to get the string representation of the expression of a return statement?

2. Because I want to perform some transformation with return statements I have to figure out if they are enclosed in a block?

The example above should be transformed in something like

int foo(int p) {

    if ( p) { /* <---- */

       /* do some processing ... */

        return 0;

     } /* <--- */

     else    {

       /* do some processing ... */

        return 1;

    }

}

Any hints or pointers are welcome.

Thanks

Marcel

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev



_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Need help with source-to-source translation

Sumner, Brian via cfe-dev
If you need a starting template for AST matchers, https://github.com/firolino/clang-tool might be useful for you.

2017-08-01 15:44 GMT+02:00 Marcel Schaible via cfe-dev <[hidden email]>:
At the moment I am using the ASTConsumer/ASTVisitor interface. But I am planing to switch to AST matchers asap.
After scratching my head for a while I found the solution for my problem. It was just a misunderstanding of the inheritance tree.

Thanks for your help

Marcel

Am 01.08.2017 um 13:48 schrieb Manuel Klimek:
On Tue, Aug 1, 2017 at 12:35 PM Marcel Schaible <[hidden email]> wrote:
Manuel, thanks for your help. Of course I went already through a bunch of documentation including libtooling.
My tool is performing now the basic setup and can transform some simple cases.

Do you know by chance how to retrieve the ASTContext from a ReturnStmt and a FuncDecl?

Generally, if you use AST matchers you'll have the ASTContext in the callback. What exactly is the problem you're running into?

BTW: Your presentation at the EURO LLVM was very helpful!

Thanks! :)
 

Greetings from Munich


Marcel




Am 01.08.2017 um 12:16 schrieb Manuel Klimek:
You'll probably want to take a look at libtooling:
https://clang.llvm.org/docs/LibTooling.html

On Fri, Jul 28, 2017 at 4:54 PM Marcel Schaible via cfe-dev <[hidden email]> wrote:

Hi everyone,

let's consider the example:

int foo(int p) {

    if ( p)

       /* code path#1 */

        return 0;

     else    {

        /* code path#2 */

        return 1;

    }

}

1. What is the best solution to get the string representation of the expression of a return statement?

2. Because I want to perform some transformation with return statements I have to figure out if they are enclosed in a block?

The example above should be transformed in something like

int foo(int p) {

    if ( p) { /* <---- */

       /* do some processing ... */

        return 0;

     } /* <--- */

     else    {

       /* do some processing ... */

        return 1;

    }

}

Any hints or pointers are welcome.

Thanks

Marcel

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev



_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev



_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Need help with source-to-source translation

Sumner, Brian via cfe-dev

Looks promising. Thanks Marcel


Am 01.08.2017 um 16:51 schrieb Firat Kasmis:
If you need a starting template for AST matchers, https://github.com/firolino/clang-tool might be useful for you.

2017-08-01 15:44 GMT+02:00 Marcel Schaible via cfe-dev <[hidden email]>:
At the moment I am using the ASTConsumer/ASTVisitor interface. But I am planing to switch to AST matchers asap.
After scratching my head for a while I found the solution for my problem. It was just a misunderstanding of the inheritance tree.

Thanks for your help

Marcel

Am 01.08.2017 um 13:48 schrieb Manuel Klimek:
On Tue, Aug 1, 2017 at 12:35 PM Marcel Schaible <[hidden email]> wrote:
Manuel, thanks for your help. Of course I went already through a bunch of documentation including libtooling.
My tool is performing now the basic setup and can transform some simple cases.

Do you know by chance how to retrieve the ASTContext from a ReturnStmt and a FuncDecl?

Generally, if you use AST matchers you'll have the ASTContext in the callback. What exactly is the problem you're running into?

BTW: Your presentation at the EURO LLVM was very helpful!

Thanks! :)
 

Greetings from Munich


Marcel




Am 01.08.2017 um 12:16 schrieb Manuel Klimek:
You'll probably want to take a look at libtooling:
https://clang.llvm.org/docs/LibTooling.html

On Fri, Jul 28, 2017 at 4:54 PM Marcel Schaible via cfe-dev <[hidden email]> wrote:

Hi everyone,

let's consider the example:

int foo(int p) {

    if ( p)

       /* code path#1 */

        return 0;

     else    {

        /* code path#2 */

        return 1;

    }

}

1. What is the best solution to get the string representation of the expression of a return statement?

2. Because I want to perform some transformation with return statements I have to figure out if they are enclosed in a block?

The example above should be transformed in something like

int foo(int p) {

    if ( p) { /* <---- */

       /* do some processing ... */

        return 0;

     } /* <--- */

     else    {

       /* do some processing ... */

        return 1;

    }

}

Any hints or pointers are welcome.

Thanks

Marcel

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev



_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev




_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Loading...