I want to unwind loops in the target program written in C at the source code level automatically (FYI, I use linux and gcc compiler). For the detailed description, let's see the following simple source code.
1: int main(){
2: int i = 0;
3: while(i<3){
4: printf("hi\n");
5: i++;
6: }
7: }
I want to convert the above source code as follows.
1: int main(){
2: int i = 0;
3: if (i<3){
4: printf("hi\n");
5: i++;
6: }
7: if (i<3){
8: printf("hi\n");
9: i++;
10: }
11: if (i<3){
12: printf("hi\n");
13: i++;
14: }
15:}
I know CBMC does unwinding loops automatically for software model checking but I am not sure the CBMC converts source code to source code for unwinding loops. I need to get a program source code where all the loops are unwinded.
I have tried to find tools or solutions for that, but I couldn't find that. Any suggestions or comments would be appreciated. Thanks!
Sorry for confusing you. I will explain details of my final goal of "loop unwinding at source code level". My final goal of unwinding loops is measuring # of test cases executing statements which are generated from loop unwinding. Refer to the following a example.
1: void ex(int i){
2: int i = 0;
3: while(i<3){
4: printf("hi\n");
5: i++;
6: }
7: }
When I convert the above source code, I want to get following source code
1: void ex(int i){
2: if (i<3){
3: printf("hi\n");
4: i++;
5: }
6: if (i<3){
7: printf("hi\n");
8: i++;
9: }
10: if (i<3){
11: printf("hi\n");
12: i++;
13: }
14:}
And from the above converted source code, I will measure # of test cases executing each statement that comes from "loop unwinding". For example, the numbers of test cases executing line #3,4 or line #7,8 or line #11,12 that were converted from line #4 and 5 in the original source code would be different from that of test cases executing line#4,5 in the original source code.
FYI, if there is a way that can achieve my final goal without loop unwinding, the way is also good! Thanks!