![]() |
|||
|
|
This project will collect information about the basic blocks in a FORTRAN program, comment the FORTRAN code to show where the basic blocks begin, and print a summary of the basic blocks for each program unit. See Rules to Define Basic Block Boundaries below for hints.
mini_polaris -f sw test.f > test.listIn this example, test.f is a FORTRAN program which you want to compile.
We save the output to the file test.list which may be examined for correctness. The file sw contains your own copy of the switchfile in your work directory. (see Switches.)
list2src < test.list > test.P.fThe .P.f ending indicates the file potentially contains parallelization directives, which is not relevant for this assignment, but which is important to the purpose of the Polaris compiler.
The output FORTRAN program produced by this project should include comments before the first statement in each basic block identifying that basic block (see comment example.) Additionally, you should provide a method to summarize the basic blocks for each program unit (see summary example.) A summary should contain the number of basic blocks, and for each basic block, what is the first statement and last statement, and the successor(s) and predecessor(s) (which will be other basic blocks.) And finally, you should provide the option of printing out the current subprogram just after you have found the basic blocks, either in normal FORTRAN or a detailed listing of the abstract syntax tree (see AST exmple.)
So, if you use a different switchfile which has p_bbsummary set to 0, then the summary routine will not be called. If you set basic_blocks to 0, then none of the routines will be called (it doesn't make sense to print the summary if you have not found the basic blocks.)
List<BasicBlock> * find_basic_blocks(ProgramUnit & pgm);Note that this requires you use the class BasicBlock and that it is derived from type Listable, in order to be able to use it as part of a List. Several hints are provided for this assignment to get you started. The function find_basic_blocks() should return NULL if the type of program unit represented by pgm is not a program, subroutine, or function. (Hint : look at cvdl/base/ProgramUnit.h for the various types allowed and how to find out what type pgm is.)
void summarize_basic_blocks(ProgramUnit &pgm,
List<BasicBlock> * bbl,
ostream &o);
You will probably need to use the class WorkStack to accomplish the function find_basic_blocks(). (see WorkStack example.)
Or on linux, the file cvdl/bblock/Makefile includes the lines :
CPPSRCS = bblock.cc # add your other .cc files here
CPPHDRS = bblock.h BasicBlock.h # add your other .h files hereIf you create other source files, you should add them to these two lines so they will be compiled and linked into the final program.
It is highly recommended that you implement these functions one step at a time, compiling and testing your latest addition to verify that your additions are correct. Be sure to follow the hints on print format and naming of basic blocks so that your output is identical to the examples (see Examples.)
If you have not compiled out mini_polaris yet, change to your work directory and run make, i.e.
cd ~/minipolaris
make
If you make some changes and want to recompile, just type make at the bblock directory. Or, if you want to do it from the top-level makefile, you should do (suppose you are at the bblock directory)
rm libbblock_pkg.so.1
cd ~/minipolaris
make
cd ~/minipolaris/cvdl/bblock
rm *.o libbblock_pkg.so.1Then
cd ..
tar cf - bblock | gzip > project1B_UIN.tar.gz
gzcat proj-bblock.tar.gz | tar tvf - # this will list the files for verification
is the same as:
IF (Exp) THEN
Stat
ENDIF
So the original IF line will be the END of a BB (because it has a Goto) and the ENDIF line is the START of BB (because is a target of a Goto). Stat is the beginning of a BB.
IF (!E) GOTO 001
Stat
IMPLIED GOTO 001
001 CONTINUE
DO I=1,10is the same as:
Stat
ENDDO
I=1So the original DO line START a BB (target of goto) and also END (because of the GOTO). The ENDDO line START a BB (target).
001 IF (I .GT. 10) GOTO 002
Stat
I=I+1
GOTO 001
002 CONTINUE
When the function find_basic_blocks() is called, Polaris will have already scanned the input program and represented it as an AST. So, it is unnecessary to examine the type of statement because the successors and predecessors by statement are already available. You can also find out the next and previous statement lexicographically (i.e. the line before and the line after in the original program.) This makes it very easy to determine if a statement jumps to any other statement except the next line (one of the requirements for the end of a basic block) or if it has more than one possible successor/predecessor statement.
Parasol Home | Research | People | General info | Seminars | Resources Parasol Lab, 301 Harvey R. Bright Bldg, 3112 TAMU, College Station, TX 77843-3112 Contact Webmaster Phone 979.458.0722 Fax 979.458.0718
Department of Computer Science and Engineering | Dwight Look College of Engineering | Texas A&M University Privacy statement: Computer Science and Engineering Engineering TAMU |