Polaris: inoutact_test.cc Source File

inoutact_test.cc

Go to the documentation of this file.
00001 ///
00002 ///
00003 #include <assert.h>
00004 
00005 #include "../ProgramUnit.h"
00006 #include "../Statement/CallStmt.h"
00007 #include "../Symbol/SubroutineSymbol.h"
00008 #include "../BinStrIter.h"
00009 #include "../debug.h"
00010 
00011 #include "../p-assert.h"
00012 #include "../p-setjmp.h"
00013 
00014 void
00015 process(char *fname1)
00016 {
00017     int             status;
00018     BinStr         bin;
00019 
00020     P_ASSERT_HANDLER(0);
00021 
00022 ///    dbx_statement_cloning_debug_level = 1000;
00023 
00024     bin = new BinStr;
00025     bin.read(fname1);
00026 
00027     ProgramUnit     pgm1("PGM1", bin);
00028 
00029     if (pgm1.structures_OK()) {
00030     cout << "The structures are OK" << endl;
00031     }
00032     
00033 ///    pgm1->display_debug(cout);
00034 
00035     {
00036     Iterator<Statement> iter = pgm1.stmts().stmts_of_type(ASSIGNMENT_STMT);
00037     if (iter.valid()) {
00038         
00039         cout << endl << "Working on the following statement:" << endl;
00040         cout << iter.current();
00041 
00042         Expression *id1 = new_variable("RRQTSY",
00043                        make_type(INTEGER_TYPE, 4),
00044                        pgm1);
00045         Expression *id2 = new_variable("EQZPXT",
00046                        make_type(INTEGER_TYPE, 4),
00047                        pgm1);
00048         Expression *e = add(constant(1), add(id2, sub(id1, constant(1))));
00049         Expression *old = iter.current().rhs().clone();
00050         
00051         iter.current().rhs(e);
00052 
00053         cout << endl << "Result of changing RHS:" << endl;
00054         cout << iter.current();
00055 
00056         iter.current().rhs(old);
00057 
00058         cout << endl << "Result of changing RHS back:" << endl;
00059         cout << iter.current();
00060 
00061         Expression *id3 = id("EQZPXT", pgm1);
00062     
00063         iter.current().lhs(id3);
00064 
00065         cout << endl << "Result of changing LHS:" << endl;
00066         cout << iter.current();
00067 
00068         iter.current().lhs(
00069         array_reference (new_array_variable ("YYQBBD",
00070                              make_type(INTEGER_TYPE,
00071                                    4),
00072                              pgm1,
00073                              colon(constant(1),
00074                                constant(100)),
00075                              colon(constant(1),
00076                                constant(100))),
00077                  comma(constant(1),
00078                        constant(1))));
00079 
00080         cout << endl << "Result of changing LHS again:" << endl;
00081         cout << iter.current();
00082 
00083         Expression *newfun = new_intrinsic ("AMAX",
00084                         make_type( REAL_TYPE,
00085                                4),
00086                         pgm1);
00087         Expression *e2 = add(constant(2),
00088                  intrinsic_call (newfun,
00089                          comma(array_reference(id("YYQBBD",
00090                                       pgm1),
00091                                        comma(id("EQZPXT",
00092                                         pgm1),
00093                                          id("RRQTSY",
00094                                         pgm1))),
00095                                id("EQZPXT",pgm1))));
00096         iter.current().rhs(e2);
00097     
00098         cout << endl << "Result of changing RHS again:" << endl;
00099         cout << iter.current();
00100 
00101         Expression *newfun2 = new_function ("SLUDGE",
00102                         make_type( REAL_TYPE,
00103                                4),
00104                         pgm1);
00105         Expression *e3 = add(constant(2),
00106                  function_call (newfun2,
00107                         comma(array_reference(id("YYQBBD",
00108                                      pgm1),
00109                                       comma(id("EQZPXT",
00110                                            pgm1),
00111                                         id("RRQTSY",
00112                                            pgm1))),
00113                               id("EQZPXT",pgm1))));
00114         iter.current().rhs(e3);
00115     
00116         cout << endl << "Result of changing RHS again:" << endl;
00117         cout << iter.current();
00118     }
00119     }
00120 
00121     {
00122     for(Iterator<Statement> iter = pgm1.stmts().stmts_of_type(READ_STMT,
00123                                   WRITE_STMT,
00124                                   PRINT_STMT);
00125         iter.valid();
00126         iter++) {
00127 
00128         cout << endl << "Working on the following statement:" << endl;
00129         cout << iter.current();
00130 
00131         iter.current().build_refs();
00132 
00133         cout << endl << "After rebuilding the sets:" << endl;
00134         cout << iter.current();
00135     }
00136     }
00137 
00138     {
00139     for(Iterator<Statement> iter = pgm1.stmts().stmts_of_type(ASSIGN_STMT);
00140         iter.valid();
00141         iter++) {
00142 
00143         cout << endl << "Working on the following statement:" << endl;
00144         cout << iter.current();
00145 
00146         iter.current().build_refs();
00147 
00148         cout << endl << "After rebuilding the sets:" << endl;
00149         cout << iter.current();
00150     }
00151     }
00152 
00153     {
00154     for(Iterator<Statement> iter = pgm1.stmts().stmts_of_type(COMPUTED_GOTO_STMT);
00155         iter.valid();
00156         iter++) {
00157 
00158         cout << endl << "Working on the following statement:" << endl;
00159         cout << iter.current();
00160 
00161         iter.current().build_refs();
00162 
00163         cout << endl << "After rebuilding the sets:" << endl;
00164         cout << iter.current();
00165     }
00166     }
00167 
00168     {
00169     for(Iterator<Statement> iter = pgm1.stmts().stmts_of_type(REWIND_STMT,
00170                                   BACKSPACE_STMT,
00171                                   ENDFILE_STMT,
00172                                   INQUIRE_STMT);
00173         iter.valid();
00174         iter++) {
00175 
00176         cout << endl << "Working on the following statement:" << endl;
00177         cout << iter.current();
00178 
00179         iter.current().build_refs();
00180 
00181         cout << endl << "After rebuilding the sets:" << endl;
00182         cout << iter.current();
00183     }
00184     }
00185 
00186     {
00187     for(Iterator<Statement> iter = pgm1.stmts().stmts_of_type(ARITHMETIC_IF_STMT);
00188         iter.valid();
00189         iter++) {
00190 
00191         cout << endl << "Working on the following statement:" << endl;
00192         cout << iter.current();
00193 
00194         iter.current().build_refs();
00195 
00196         cout << endl << "After rebuilding the sets:" << endl;
00197         cout << iter.current();
00198     }
00199     }
00200 
00201     {
00202     for(Iterator<Statement> iter = pgm1.stmts().stmts_of_type(ALLOCATE_STMT,
00203                                   DEALLOCATE_STMT,
00204                                   NULLIFY_STMT);
00205         iter.valid();
00206         iter++) {
00207 
00208         cout << endl << "Working on the following statement:" << endl;
00209         cout << iter.current();
00210 
00211         iter.current().build_refs();
00212 
00213         cout << endl << "After rebuilding the sets:" << endl;
00214         cout << iter.current();
00215     }
00216     }
00217     
00218     {
00219     for(Iterator<Statement> iter = pgm1.stmts().stmts_of_type(IF_STMT,
00220                                   ELSEIF_STMT);
00221         iter.valid();
00222         iter++) {
00223 
00224         cout << endl << "Working on the following statement:" << endl;
00225         cout << iter.current();
00226 
00227         iter.current().build_refs();
00228 
00229         cout << endl << "After rebuilding the sets:" << endl;
00230         cout << iter.current();
00231     }
00232     }
00233     
00234     {
00235     for(Iterator<Statement> iter = pgm1.stmts().stmts_of_type(DO_STMT);
00236         iter.valid();
00237         iter++) {
00238 
00239         cout << endl << "Working on the following statement:" << endl;
00240         cout << iter.current();
00241 
00242         iter.current().build_refs();
00243 
00244         cout << endl << "After rebuilding the sets:" << endl;
00245         cout << iter.current();
00246     }
00247     }
00248     {
00249     for(Iterator<Statement> iter = pgm1.stmts().stmts_of_type(ASSIGNED_GOTO_STMT);
00250         iter.valid();
00251         iter++) {
00252 
00253         cout << endl << "Working on the following statement:" << endl;
00254         cout << iter.current();
00255 
00256         iter.current().build_refs();
00257 
00258         cout << endl << "After rebuilding the sets:" << endl;
00259         cout << iter.current();
00260     }
00261     }
00262 
00263     {
00264     for(Iterator<Statement> iter = pgm1.stmts().stmts_of_type(OPEN_STMT,
00265                                   CLOSE_STMT);
00266         iter.valid();
00267         iter++) {
00268 
00269         cout << endl << "Working on the following statement:" << endl;
00270         cout << iter.current();
00271 
00272         iter.current().build_refs();
00273 
00274         cout << endl << "After rebuilding the sets:" << endl;
00275         cout << iter.current();
00276     }
00277     }
00278 
00279     {
00280     Statement *call_init =
00281         new CallStmt(pgm1.stmts().new_tag(),
00282              new SubroutineSymbol("SUBX",
00283                           IS_EXTERNAL,
00284                           NOT_INTRINSIC,
00285                           NOT_FORMAL),
00286              comma(array_reference(id("YYQBBD",
00287                           pgm1),
00288                            comma(id("EQZPXT",
00289                             pgm1),
00290                              id("RRQTSY",
00291                             pgm1))),
00292                    id("EQZPXT",pgm1)));
00293     
00294     Iterator<Statement> entries = pgm1.stmts().iterate_entry_points();
00295     if (entries.valid()) {
00296         pgm1.stmts().ins_after(call_init, &(entries.current()));
00297     }
00298 
00299     cout << endl << "After adding a CALL statement:" << endl;
00300     cout << *call_init;
00301 
00302     }
00303 
00304     if (pgm1.structures_OK()) {
00305     cout << "The structures are OK" << endl;
00306     }
00307 }
00308 
00309 int  
00310 main(int argc, char *argv[])
00311 {
00312     assert(argc >= 1);
00313     
00314     process(argv[1]);
00315 
00316     return 0;
00317 }
00318 
 © 1995-2005 University of Illinois, Urbana-Champaign. All rights reserved.  Fri Mar 25 23:05:55 2005