swtv-kaist / cs458-spring24

7 stars 0 forks source link

[HW4] Total number of branches and ID #9

Closed Mysigyeong closed 6 months ago

Mysigyeong commented 6 months ago
$ ./PrintBranches example-kcov.c
function: f2
        If      ID: 0   Line: 4         Col: 2          Filename: ./example-kcov.h
function: f1
        If      ID: 1   Line: 19                Col: 2          Filename: example-kcov.c
function: main
        If      ID: 2   Line: 30                Col: 2          Filename: example-kcov.c
        If      ID: 3   Line: 32                Col: 9          Filename: example-kcov.c
        For     ID: 4   Line: 39                Col: 2          Filename: example-kcov.c
        While   ID: 5   Line: 44                Col: 2          Filename: example-kcov.c
        Do      ID: 6   Line: 49                Col: 2          Filename: example-kcov.c
        Case    ID: 7   Line: 51                Col: 4          Filename: example-kcov.c
        Case    ID: 8   Line: 54                Col: 4          Filename: example-kcov.c
        ?:      ID: 9   Line: 55                Col: 9          Filename: example-kcov.c
        Default ID: 10  Line: 58                Col: 4          Filename: example-kcov.c
        If      ID: 11  Line: 63                Col: 2          Filename: example-kcov.c
        ?:      ID: 12  Line: 63                Col: 7          Filename: example-kcov.c
        ImpDef. ID: 13  Line: 67                Col: 2          Filename: example-kcov.c
        Case    ID: 14  Line: 68                Col: 3          Filename: example-kcov.c
        Case    ID: 15  Line: 71                Col: 3          Filename: example-kcov.c
        Do      ID: 16  Line: 76                Col: 2          Filename: example-kcov.c
        If      ID: 17  Line: 76                Col: 2          Filename: example-kcov.c
Total number of branches: 30

I'd like to know how the total number of branches is 30. I also would like to know if the ID values are just manually given by the programmer not llvm internal logic. Thank you.

3-24 commented 6 months ago
  1. The branch count is determined by the number of outgoing edges for nodes with more than two outgoing edges in CFG. For instance, if-else statement has if branch and else branch, so the branch count is 2. In this way, you can get the total number of branches of example-kcov.c.
  2. ID is given by the programmer, and the order of ID should follow the order of the line number.