How to slice the source code?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to slice the source code?

liuml07
Hi all,

I'm doing the program slicing [1] in LLVM. Now I implemented the Weiser's algorithm [2] in a simple way by writing a plugin to analyze the IR. My final goal is to slice the source code, thus I recorded all the lines of source code to be sliced. The last step is to delete the lines which are not in the program slice. However, I met a problem when deleting the source code directly:

To make it clear, I gave an example following, in which the following lines (underline decoration) can be deleted. We can see that the line 4 should also be deleted, but it's not.
1   for (int i = 0; i < BUFSIZE; i++) {
2      for (int j = 0; j < np; j++)
3         buf[i] = ((rank + j) % np);
4  }

I got the LoC info from meta-data of the IR which can be deleted. However, there is no according IR in the first place, which represents the line 4 (whose functionality is to end a block). I'm not familiar with clang and its AST. A friend told me to parse the code using python to find the matching "}" (or END in Fortran) and delete them. I'd like to know if there is an LLVM way to do this.

Any idea?

Thank you!

Mingliang LIU (刘明亮 in Chinese)

PACMAN Group,  Dept. of Computer Science & Technology
Tsinghua University, Beijing 100084, China
Email: [hidden email]

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: How to slice the source code?

Jonas Wagner
Hi,

maybe you can have a look at the CReduce project: http://embed.cs.utah.edu/creduce/

This project implements many source-to-source transformations of C programs, e.g. removing functions, changing variable names, deleting branches in if-statements, etc. Some of these are purely based on the source code, other use the Clang frontend.

Hope this helps,
Jonas


On Sun, Mar 17, 2013 at 7:25 PM, Mingliang LIU <[hidden email]> wrote:
Hi all,

I'm doing the program slicing [1] in LLVM. Now I implemented the Weiser's algorithm [2] in a simple way by writing a plugin to analyze the IR. My final goal is to slice the source code, thus I recorded all the lines of source code to be sliced. The last step is to delete the lines which are not in the program slice. However, I met a problem when deleting the source code directly:

To make it clear, I gave an example following, in which the following lines (underline decoration) can be deleted. We can see that the line 4 should also be deleted, but it's not.
1   for (int i = 0; i < BUFSIZE; i++) {
2      for (int j = 0; j < np; j++)
3         buf[i] = ((rank + j) % np);
4  }

I got the LoC info from meta-data of the IR which can be deleted. However, there is no according IR in the first place, which represents the line 4 (whose functionality is to end a block). I'm not familiar with clang and its AST. A friend told me to parse the code using python to find the matching "}" (or END in Fortran) and delete them. I'd like to know if there is an LLVM way to do this.

Any idea?

Thank you!

Mingliang LIU (刘明亮 in Chinese)

PACMAN Group,  Dept. of Computer Science & Technology
Tsinghua University, Beijing 100084, China
Email: [hidden email]

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev



_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: How to slice the source code?

liuml07
It will definitely help me a lot.

Thank you.


On Tue, Mar 26, 2013 at 3:43 PM, Jonas Wagner <[hidden email]> wrote:
Hi,

maybe you can have a look at the CReduce project: http://embed.cs.utah.edu/creduce/

This project implements many source-to-source transformations of C programs, e.g. removing functions, changing variable names, deleting branches in if-statements, etc. Some of these are purely based on the source code, other use the Clang frontend.

Hope this helps,
Jonas


On Sun, Mar 17, 2013 at 7:25 PM, Mingliang LIU <[hidden email]> wrote:
Hi all,

I'm doing the program slicing [1] in LLVM. Now I implemented the Weiser's algorithm [2] in a simple way by writing a plugin to analyze the IR. My final goal is to slice the source code, thus I recorded all the lines of source code to be sliced. The last step is to delete the lines which are not in the program slice. However, I met a problem when deleting the source code directly:

To make it clear, I gave an example following, in which the following lines (underline decoration) can be deleted. We can see that the line 4 should also be deleted, but it's not.
1   for (int i = 0; i < BUFSIZE; i++) {
2      for (int j = 0; j < np; j++)
3         buf[i] = ((rank + j) % np);
4  }

I got the LoC info from meta-data of the IR which can be deleted. However, there is no according IR in the first place, which represents the line 4 (whose functionality is to end a block). I'm not familiar with clang and its AST. A friend told me to parse the code using python to find the matching "}" (or END in Fortran) and delete them. I'd like to know if there is an LLVM way to do this.

Any idea?

Thank you!

Mingliang LIU (刘明亮 in Chinese)

PACMAN Group,  Dept. of Computer Science & Technology
Tsinghua University, Beijing 100084, China
Email: [hidden email]

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev





--
Mingliang LIU (刘明亮 in Chinese)

PACMAN Group,  Dept. of Computer Science & Technology
Tsinghua University, Beijing 100084, China
Email: [hidden email]

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev