Linemarkers can be added to PSyclone's output to store the information where in the tree a statement is. Linemarkers have the format (https://gcc.gnu.org/onlinedocs/gcc-3.0.2/cpp_9.html):
Linenum can only be an 8-byte integer, but we can modify the filename freely. I'am atm experimenting with the following format:
# 121 "stdout.f90:0.6" 1
if (a == b) then
# 123 "stdout.f90:0.6.1.0"
a = 2 * a + SQRT(a / b) + (i - j) / (d(i) - d(j) * d(i + 1))
The dotted numbers after the ':' indicate the index positions in the tree. E.g. this line is first (0) child of the FileContainer; 7th statement (6) ... which is an if-statement. So 0.6.0 is the if-condition, 0.6.1 is the if-body (and 0.6.2 the else-body). Then 0.6.1.0 is therefore the first statement of the if-body).
Creating a stack trace with gfortran, we get:
#3 0x5885d9a5f23a in test_prog
at /home/joerg/work/psyclone/bughunt/stdout.f90:0.6.1.0:123
#4 0x5885d9a5f315 in main
at /home/joerg/work/psyclone/bughunt/stdout.f90:0.8:125
Similarly for ifort:
a.out 00000000004042BF MAIN__ 123 stdout.f90:0.6.1.0
So the information is preserved (though it needs compiler-specific reading of the stack trace of course).
This can be useful in case we want to develop a tool that can analyse stack traces: instead of trying to map line numbers to PSyIR nodes, we can extract the exact node using the information at the end of the file name.
It needs to be confirmed that the same format works for other compilers as well.
The approach here would be to extend the Fortran back to optionally add these line number directives.
Linemarkers can be added to PSyclone's output to store the information where in the tree a statement is. Linemarkers have the format (https://gcc.gnu.org/onlinedocs/gcc-3.0.2/cpp_9.html):
Linenum can only be an 8-byte integer, but we can modify the filename freely. I'am atm experimenting with the following format:
The dotted numbers after the ':' indicate the index positions in the tree. E.g. this line is first (0) child of the FileContainer; 7th statement (6) ... which is an if-statement. So 0.6.0 is the if-condition, 0.6.1 is the if-body (and 0.6.2 the else-body). Then 0.6.1.0 is therefore the first statement of the if-body).
Creating a stack trace with gfortran, we get:
Similarly for ifort:
So the information is preserved (though it needs compiler-specific reading of the stack trace of course).
This can be useful in case we want to develop a tool that can analyse stack traces: instead of trying to map line numbers to PSyIR nodes, we can extract the exact node using the information at the end of the file name.
It needs to be confirmed that the same format works for other compilers as well.
The approach here would be to extend the Fortran back to optionally add these line number directives.