Skip to content

This is a POC of a simple source-to-source transformation using Clang Lib.

Notifications You must be signed in to change notification settings

cleversonledur/clang_examples

Repository files navigation

Clang Lib Source to Source Transformation Example

This is a simple example of source-to-source transformation.

The objective here was to use an auxiliar struct to pass variables to a function. Then, this tries to perform the following transformation:

Original Code:

void func(int &a, char &c){
        a=10;
        c='C';
}
int main(){
        int a;
        char c;
        func(a,c);
        std::cout << "a Value: " << a << c << std::endl;
}

Transformed Code:

typedef struct{
        int a;
        char c;
}data_t;

void func(int &a, char &c){
        a=10;
        c='C';
}

int main(){
        int a;
        char c;
        if(a=0)
                c='f';
        else
                c='t';
        
        data_t *d = new data_t[1];
        d->a=a;
        d->c=c;
        func(d->a, d->c);
        std::cout << "a Value: " << d->a << d->c << std::endl;
}

About

This is a POC of a simple source-to-source transformation using Clang Lib.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published