00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 static char USMID[] = "\n@(#)5.0_pl/sources/ir.c 5.6 10/05/99 14:45:20\n";
00042
00043 # include <stdarg.h>
00044
00045 # include "defines.h"
00046
00047 # include "host.m"
00048 # include "host.h"
00049 # include "target.m"
00050 # include "target.h"
00051
00052 # include "globals.m"
00053 # include "tokens.m"
00054 # include "sytb.m"
00055 # include "s_globals.m"
00056 # include "debug.m"
00057
00058 # include "globals.h"
00059 # include "tokens.h"
00060 # include "sytb.h"
00061 # include "s_globals.h"
00062
00063
00064
00065
00066
00067
00068 static boolean compare_il(int, int, int, int);
00069 static boolean compare_ir(int, int);
00070 static boolean il_is_symbolic_constant(int);
00071 static boolean ir_is_symbolic_constant(int);
00072
00073 static int label_copy_al_idx = NULL_IDX;
00074 static boolean gen_lbl_copy = FALSE;
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094 void gen_sh(sh_position_type position,
00095 stmt_type_type stmt_type,
00096 int line_num,
00097 int col_num,
00098 boolean err_flag,
00099 boolean labeled,
00100 boolean compiler_gen)
00101 #ifdef KEY
00102 {
00103 int sh_idx = gen_sh_at(position, stmt_type, line_num, col_num, err_flag,
00104 labeled, compiler_gen, curr_stmt_sh_idx);
00105 if (position == After) {
00106 curr_stmt_sh_idx = sh_idx;
00107 }
00108 }
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118 int gen_sh_at(sh_position_type position,
00119 stmt_type_type stmt_type,
00120 int line_num,
00121 int col_num,
00122 boolean err_flag,
00123 boolean labeled,
00124 boolean compiler_gen,
00125 int insertion_idx)
00126 {
00127 int next_idx;
00128 int prev_idx;
00129 int sh_idx;
00130
00131
00132 TRACE (Func_Entry, "gen_sh_at", NULL);
00133
00134 # ifdef _DEBUG
00135 if (defer_stmt_expansion) {
00136 PRINTMSG(line_num, 626, Internal, col_num,
00137 "no defer_stmt_expansion", "gen_sh_at");
00138 }
00139
00140 if (insertion_idx == NULL_IDX) {
00141 PRINTMSG(line_num, 626, Internal, col_num,
00142 "valid insertion_idx", "gen_sh_at");
00143 }
00144 # endif
00145
00146 sh_idx = ntr_sh_tbl();
00147 SH_STMT_TYPE(sh_idx) = stmt_type;
00148 SH_GLB_LINE(sh_idx) = line_num;
00149 SH_ERR_FLG(sh_idx) = err_flag;
00150 SH_COL_NUM(sh_idx) = col_num;
00151 SH_LABELED(sh_idx) = labeled;
00152 SH_COMPILER_GEN(sh_idx) = compiler_gen;
00153
00154 if (stmt_type == Construct_Def) {
00155 SH_P2_SKIP_ME(sh_idx) = TRUE;
00156 }
00157
00158 if (position == Before) {
00159 SH_NEXT_IDX(sh_idx) = insertion_idx;
00160
00161 if (insertion_idx == SCP_FIRST_SH_IDX(curr_scp_idx)) {
00162 SCP_FIRST_SH_IDX(curr_scp_idx) = sh_idx;
00163 }
00164 else {
00165 prev_idx = SH_PREV_IDX(insertion_idx);
00166
00167 if (prev_idx != NULL_IDX) {
00168 SH_PREV_IDX(sh_idx) = prev_idx;
00169 SH_NEXT_IDX(prev_idx) = sh_idx;
00170 }
00171 }
00172
00173 SH_PREV_IDX(insertion_idx) = sh_idx;
00174 }
00175 else {
00176 SH_PREV_IDX(sh_idx) = insertion_idx;
00177 next_idx = SH_NEXT_IDX(insertion_idx);
00178
00179 if (next_idx != NULL_IDX) {
00180 SH_NEXT_IDX(sh_idx) = next_idx;
00181 SH_PREV_IDX(next_idx) = sh_idx;
00182 }
00183
00184 SH_NEXT_IDX(insertion_idx) = sh_idx;
00185 }
00186
00187 TRACE (Func_Exit, "gen_sh", NULL);
00188
00189 return sh_idx;
00190
00191 }
00192 #else
00193 {
00194 int next_idx;
00195 int prev_idx;
00196 int sh_idx;
00197
00198
00199 TRACE (Func_Entry, "gen_sh", NULL);
00200
00201 # ifdef _DEBUG
00202 if (defer_stmt_expansion) {
00203 PRINTMSG(line_num, 626, Internal, col_num,
00204 "no defer_stmt_expansion", "gen_sh");
00205 }
00206
00207 if (curr_stmt_sh_idx == NULL_IDX) {
00208 PRINTMSG(line_num, 626, Internal, col_num,
00209 "valid curr_stmt_sh_idx", "gen_sh");
00210 }
00211 # endif
00212
00213 sh_idx = ntr_sh_tbl();
00214 SH_STMT_TYPE(sh_idx) = stmt_type;
00215 SH_GLB_LINE(sh_idx) = line_num;
00216 SH_ERR_FLG(sh_idx) = err_flag;
00217 SH_COL_NUM(sh_idx) = col_num;
00218 SH_LABELED(sh_idx) = labeled;
00219 SH_COMPILER_GEN(sh_idx) = compiler_gen;
00220
00221 if (stmt_type == Construct_Def) {
00222 SH_P2_SKIP_ME(sh_idx) = TRUE;
00223 }
00224
00225 if (position == Before) {
00226 SH_NEXT_IDX(sh_idx) = curr_stmt_sh_idx;
00227
00228 if (curr_stmt_sh_idx == SCP_FIRST_SH_IDX(curr_scp_idx)) {
00229 SCP_FIRST_SH_IDX(curr_scp_idx) = sh_idx;
00230 }
00231 else {
00232 prev_idx = SH_PREV_IDX(curr_stmt_sh_idx);
00233
00234 if (prev_idx != NULL_IDX) {
00235 SH_PREV_IDX(sh_idx) = prev_idx;
00236 SH_NEXT_IDX(prev_idx) = sh_idx;
00237 }
00238 }
00239
00240 SH_PREV_IDX(curr_stmt_sh_idx) = sh_idx;
00241 }
00242 else {
00243 SH_PREV_IDX(sh_idx) = curr_stmt_sh_idx;
00244 next_idx = SH_NEXT_IDX(curr_stmt_sh_idx);
00245
00246 if (next_idx != NULL_IDX) {
00247 SH_NEXT_IDX(sh_idx) = next_idx;
00248 SH_PREV_IDX(next_idx) = sh_idx;
00249 }
00250
00251 SH_NEXT_IDX(curr_stmt_sh_idx) = sh_idx;
00252 curr_stmt_sh_idx = sh_idx;
00253 }
00254
00255 TRACE (Func_Exit, "gen_sh", NULL);
00256
00257 return;
00258
00259 }
00260 #endif
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279 void gen_gl_sh(sh_position_type position,
00280 stmt_type_type stmt_type,
00281 int line_num,
00282 int col_num,
00283 boolean err_flag,
00284 boolean labeled,
00285 boolean compiler_gen)
00286
00287 {
00288 int next_idx;
00289 int prev_idx;
00290 int sh_idx;
00291
00292
00293 TRACE (Func_Entry, "gen_gl_sh", NULL);
00294
00295 sh_idx = ntr_gl_sh_tbl();
00296 GL_SH_STMT_TYPE(sh_idx) = stmt_type;
00297 GL_SH_GLB_LINE(sh_idx) = line_num;
00298 GL_SH_ERR_FLG(sh_idx) = err_flag;
00299 GL_SH_COL_NUM(sh_idx) = col_num;
00300 GL_SH_LABELED(sh_idx) = labeled;
00301 GL_SH_COMPILER_GEN(sh_idx) = compiler_gen;
00302
00303 if (stmt_type == Construct_Def) {
00304 GL_SH_P2_SKIP_ME(sh_idx) = TRUE;
00305 }
00306
00307 if (curr_gl_stmt_sh_idx == NULL_IDX) {
00308
00309 if (global_stmt_sh_idx == NULL_IDX) {
00310 global_stmt_sh_idx = sh_idx;
00311 }
00312 curr_gl_stmt_sh_idx = sh_idx;
00313 }
00314 else if (position == Before) {
00315
00316 GL_SH_NEXT_IDX(sh_idx) = curr_gl_stmt_sh_idx;
00317
00318 if (curr_gl_stmt_sh_idx == global_stmt_sh_idx) {
00319 global_stmt_sh_idx = sh_idx;
00320 }
00321 else {
00322 prev_idx = GL_SH_PREV_IDX(curr_gl_stmt_sh_idx);
00323
00324 if (prev_idx != NULL_IDX) {
00325 GL_SH_PREV_IDX(sh_idx) = prev_idx;
00326 GL_SH_NEXT_IDX(prev_idx) = sh_idx;
00327 }
00328 }
00329
00330 GL_SH_PREV_IDX(curr_gl_stmt_sh_idx) = sh_idx;
00331 }
00332 else {
00333 GL_SH_PREV_IDX(sh_idx) = curr_gl_stmt_sh_idx;
00334 next_idx = GL_SH_NEXT_IDX(curr_gl_stmt_sh_idx);
00335
00336 if (next_idx != NULL_IDX) {
00337 GL_SH_NEXT_IDX(sh_idx) = next_idx;
00338 GL_SH_PREV_IDX(next_idx) = sh_idx;
00339 }
00340
00341 GL_SH_NEXT_IDX(curr_gl_stmt_sh_idx) = sh_idx;
00342 curr_gl_stmt_sh_idx = sh_idx;
00343 }
00344
00345 TRACE (Func_Exit, "gen_gl_sh", NULL);
00346
00347 return;
00348
00349 }
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371 static boolean compare_ir(int ir_idx1,
00372 int ir_idx2)
00373 {
00374 boolean matched;
00375 int type1;
00376 int type2;
00377
00378 TRACE (Func_Entry, "compare_ir", NULL);
00379
00380
00381
00382
00383
00384
00385 type1 = IR_TYPE_IDX(ir_idx1);
00386 type2 = IR_TYPE_IDX(ir_idx2);
00387
00388 if (IR_OPR(ir_idx1) == IR_OPR(ir_idx2) && type1 == type2 &&
00389 IR_FLD_L(ir_idx1) == IR_FLD_L(ir_idx2) &&
00390 IR_FLD_R(ir_idx1) == IR_FLD_R(ir_idx2)) {
00391
00392
00393
00394
00395
00396
00397
00398 if (IR_IDX_L(ir_idx1) == IR_IDX_L(ir_idx2)) {
00399 matched = TRUE;
00400 }
00401 else if (IR_FLD_L(ir_idx1) == IR_Tbl_Idx) {
00402 matched = compare_ir(IR_IDX_L(ir_idx1), IR_IDX_L(ir_idx2));
00403 }
00404 else if (IR_FLD_L(ir_idx1) == IL_Tbl_Idx) {
00405 matched = compare_il(IR_IDX_L(ir_idx1), IR_IDX_L(ir_idx2),
00406 IR_LIST_CNT_L(ir_idx1), IR_LIST_CNT_L(ir_idx2));
00407 }
00408 else {
00409 matched = FALSE;
00410 }
00411
00412 if (matched) {
00413
00414 if (IR_IDX_R(ir_idx1) == IR_IDX_R(ir_idx2)) {
00415 matched = TRUE;
00416 }
00417 else if (IR_FLD_R(ir_idx1) == IR_Tbl_Idx) {
00418 matched = compare_ir(IR_IDX_R(ir_idx1), IR_IDX_R(ir_idx2));
00419 }
00420 else if (IR_FLD_R(ir_idx1) == IL_Tbl_Idx) {
00421 matched = compare_il(IR_IDX_R(ir_idx1), IR_IDX_R(ir_idx2),
00422 IR_LIST_CNT_R(ir_idx1),IR_LIST_CNT_R(ir_idx2));
00423 }
00424 else {
00425 matched = FALSE;
00426 }
00427 }
00428 }
00429 else {
00430 matched = FALSE;
00431 }
00432
00433 TRACE (Func_Exit, "compare_ir", NULL);
00434
00435 return(matched);
00436
00437 }
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461 static boolean compare_il(int il_idx1,
00462 int il_idx2,
00463 int list_cnt1,
00464 int list_cnt2)
00465 {
00466 boolean matched;
00467
00468
00469 TRACE (Func_Entry, "compare_il", NULL);
00470
00471 if (list_cnt1 != list_cnt2) {
00472 matched = FALSE;
00473 }
00474 else {
00475
00476 do {
00477 if (IL_FLD(il_idx1) == IL_FLD(il_idx2)) {
00478
00479
00480
00481
00482
00483 if (IL_IDX(il_idx1) == IL_IDX(il_idx2)) {
00484 matched = TRUE;
00485 }
00486 else if (IL_FLD(il_idx1) == IR_Tbl_Idx) {
00487 matched = compare_ir(IL_IDX(il_idx1), IL_IDX(il_idx2));
00488 }
00489 else if (IL_FLD(il_idx1) == IL_Tbl_Idx) {
00490 matched = compare_il(IL_IDX(il_idx1), IL_IDX(il_idx2),
00491 IL_LIST_CNT(il_idx1), IL_LIST_CNT(il_idx2));
00492 }
00493 else {
00494 matched = FALSE;
00495 }
00496 }
00497 else {
00498 matched = FALSE;
00499 }
00500
00501 il_idx1 = IL_NEXT_LIST_IDX(il_idx1);
00502 il_idx2 = IL_NEXT_LIST_IDX(il_idx2);
00503
00504
00505
00506
00507 } while (matched && il_idx1 != NULL_IDX);
00508 }
00509
00510 TRACE (Func_Exit, "compare_il", NULL);
00511
00512 return(matched);
00513
00514 }
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531 void free_ir_stream(int ir_idx)
00532 {
00533 TRACE (Func_Entry, "free_ir_stream", NULL);
00534
00535 if (IR_FLD_L(ir_idx) == IR_Tbl_Idx) {
00536 free_ir_stream(IR_IDX_L(ir_idx));
00537 }
00538 else if (IR_FLD_L(ir_idx) == IL_Tbl_Idx) {
00539 free_ir_list(IR_IDX_L(ir_idx));
00540 }
00541
00542 if (IR_FLD_R(ir_idx) == IR_Tbl_Idx) {
00543 free_ir_stream(IR_IDX_R(ir_idx));
00544 }
00545 else if (IR_FLD_R(ir_idx) == IL_Tbl_Idx) {
00546 free_ir_list(IR_IDX_R(ir_idx));
00547 }
00548
00549 FREE_IR_NODE(ir_idx);
00550
00551 TRACE (Func_Exit, "free_ir_stream", NULL);
00552
00553 return;
00554
00555 }
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572 void free_ir_list(int il_idx)
00573 {
00574 int next_il;
00575
00576
00577 TRACE (Func_Entry, "free_ir_list", NULL);
00578
00579 while (il_idx != NULL_IDX) {
00580
00581 if (IL_FLD(il_idx) == IR_Tbl_Idx) {
00582 free_ir_stream(IL_IDX(il_idx));
00583 }
00584 else if (IL_FLD(il_idx) == IL_Tbl_Idx) {
00585 free_ir_list(IL_IDX(il_idx));
00586 }
00587
00588 next_il = IL_NEXT_LIST_IDX(il_idx);
00589 FREE_IR_LIST_NODE(il_idx);
00590 il_idx = next_il;
00591 }
00592
00593 TRACE (Func_Exit, "free_ir_list", NULL);
00594
00595 return;
00596
00597 }
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616 void copy_subtree(opnd_type *old_opnd,
00617 opnd_type *new_opnd)
00618
00619 {
00620 int idx;
00621 int list_idx;
00622 int list2_idx;
00623 int new_root = NULL_IDX;
00624 opnd_type opnd_o;
00625 opnd_type opnd_n;
00626
00627
00628 TRACE (Func_Entry, "copy_subtree", NULL);
00629
00630 COPY_OPND((*new_opnd), (*old_opnd));
00631 idx = OPND_IDX((*old_opnd));
00632
00633 if (idx) {
00634
00635 switch(OPND_FLD((*old_opnd))) {
00636
00637 case NO_Tbl_Idx :
00638 break;
00639
00640 case IR_Tbl_Idx :
00641
00642 if (IR_OPR(idx) == Stmt_Expansion_Opr) {
00643
00644
00645 COPY_OPND(opnd_o, IR_OPND_L(idx));
00646 copy_subtree(&opnd_o, &opnd_n);
00647 COPY_OPND((*new_opnd), opnd_n);
00648 }
00649 else {
00650 NTR_IR_TBL(new_root);
00651
00652 COPY_TBL_NTRY(ir_tbl, new_root, idx);
00653 OPND_IDX((*new_opnd)) = new_root;
00654
00655 COPY_OPND(opnd_o, IR_OPND_L(idx));
00656 copy_subtree(&opnd_o, &opnd_n);
00657 COPY_OPND(IR_OPND_L(new_root), opnd_n);
00658
00659 COPY_OPND(opnd_o, IR_OPND_R(idx));
00660 copy_subtree(&opnd_o, &opnd_n);
00661 COPY_OPND(IR_OPND_R(new_root), opnd_n);
00662 }
00663 break;
00664
00665 case AT_Tbl_Idx :
00666
00667 if (gen_lbl_copy &&
00668 AT_OBJ_CLASS(idx) == Label &&
00669 ATL_CLASS(idx) == Lbl_Internal) {
00670
00671 if (ATL_NEW_LBL_IDX(idx) == NULL_IDX) {
00672
00673 ATL_NEW_LBL_IDX(idx) = gen_internal_lbl(AT_DEF_LINE(idx));
00674
00675 NTR_ATTR_LIST_TBL(list_idx);
00676 AL_ATTR_IDX(list_idx) = idx;
00677
00678 AL_NEXT_IDX(list_idx) = label_copy_al_idx;
00679
00680 label_copy_al_idx = list_idx;
00681 }
00682
00683 OPND_IDX((*new_opnd)) = ATL_NEW_LBL_IDX(idx);
00684 }
00685 break;
00686
00687 case CN_Tbl_Idx :
00688 break;
00689
00690 case SH_Tbl_Idx :
00691
00692 new_root = ntr_sh_tbl();
00693
00694 COPY_TBL_NTRY(sh_tbl, new_root, idx);
00695
00696 OPND_FLD(opnd_o) = IR_Tbl_Idx;
00697 OPND_IDX(opnd_o) = SH_IR_IDX(idx);
00698 copy_subtree(&opnd_o, &opnd_n);
00699 SH_IR_IDX(new_root) = OPND_IDX(opnd_n);
00700 OPND_IDX((*new_opnd)) = new_root;
00701 break;
00702
00703 case IL_Tbl_Idx :
00704
00705 NTR_IR_LIST_TBL(new_root);
00706
00707 COPY_TBL_NTRY(ir_list_tbl, new_root, idx);
00708 OPND_IDX((*new_opnd)) = new_root;
00709
00710 COPY_OPND(opnd_o, IL_OPND(idx));
00711 copy_subtree(&opnd_o, &opnd_n);
00712 COPY_OPND(IL_OPND(new_root), opnd_n);
00713
00714 list2_idx = new_root;
00715
00716 idx = IL_NEXT_LIST_IDX(idx);
00717
00718 while (idx != NULL_IDX) {
00719 NTR_IR_LIST_TBL(list_idx);
00720
00721 COPY_TBL_NTRY(ir_list_tbl, list_idx, idx);
00722
00723 if (! IL_ARG_DESC_VARIANT(idx)) {
00724 IL_PREV_LIST_IDX(list_idx) = list2_idx;
00725 }
00726
00727 IL_NEXT_LIST_IDX(list2_idx) = list_idx;
00728 list2_idx = list_idx;
00729
00730 COPY_OPND(opnd_o, IL_OPND(idx));
00731 copy_subtree(&opnd_o, &opnd_n);
00732 COPY_OPND(IL_OPND(list_idx), opnd_n);
00733
00734 idx = IL_NEXT_LIST_IDX(idx);
00735 }
00736 break;
00737 }
00738 }
00739
00740 TRACE (Func_Exit, "copy_subtree", NULL);
00741
00742 return;
00743
00744 }
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762
00763 int copy_to_gl_subtree(int idx,
00764 fld_type fld)
00765
00766 {
00767 int new_idx;
00768 int list_idx;
00769 int list2_idx;
00770 int name_idx;
00771 int new_root = NULL_IDX;
00772
00773
00774 TRACE (Func_Entry, "copy_to_gl_subtree", NULL);
00775
00776 if (idx != NULL_IDX) {
00777
00778 switch(fld) {
00779
00780 case NO_Tbl_Idx :
00781 break;
00782
00783 case IR_Tbl_Idx :
00784
00785 NTR_GL_IR_TBL(new_root);
00786
00787 COPY_GL_TBL_NTRY(global_ir_tbl, ir_tbl, new_root, idx);
00788
00789 new_idx = copy_to_gl_subtree(IR_IDX_L(idx), IR_FLD_L(idx));
00790 GL_IR_IDX_L(new_root) = new_idx;
00791
00792 new_idx = copy_to_gl_subtree(IR_IDX_R(idx), IR_FLD_R(idx));
00793 GL_IR_IDX_R(new_root) = new_idx;
00794
00795 break;
00796
00797 case AT_Tbl_Idx :
00798
00799 if (srch_global_name_tbl(AT_OBJ_NAME_PTR(idx),
00800 AT_NAME_LEN(idx),
00801 &name_idx)) {
00802 }
00803 else {
00804 ntr_global_name_tbl(idx, NULL_IDX, name_idx);
00805 }
00806
00807 new_root = GN_ATTR_IDX(name_idx);
00808 break;
00809
00810 case CN_Tbl_Idx :
00811
00812
00813
00814
00815
00816 # ifdef _DEBUG
00817 if (TYP_TYPE(CN_TYPE_IDX(idx)) != Integer) {
00818 PRINTMSG(stmt_start_line, 626, Internal, stmt_start_col,
00819 "Integer constant", "copy_to_gl_subtree");
00820 }
00821 # endif
00822
00823 new_root = CN_INT_TO_C(idx);
00824 break;
00825
00826 case SH_Tbl_Idx :
00827
00828 new_root = ntr_gl_sh_tbl();
00829
00830 COPY_GL_TBL_NTRY(global_sh_tbl, sh_tbl, new_root, idx);
00831
00832 new_idx = copy_to_gl_subtree(SH_IR_IDX(idx), IR_Tbl_Idx);
00833 GL_SH_IR_IDX(new_root) = new_idx;
00834 break;
00835
00836 case IL_Tbl_Idx :
00837
00838 NTR_GL_IR_LIST_TBL(new_root);
00839
00840 COPY_GL_TBL_NTRY(global_ir_list_tbl, ir_list_tbl, new_root, idx);
00841
00842 new_idx = copy_to_gl_subtree(IL_IDX(idx), IL_FLD(idx));
00843 GL_IL_IDX(new_root) = new_idx;
00844 list2_idx = new_root;
00845
00846 idx = IL_NEXT_LIST_IDX(idx);
00847
00848 while (idx != NULL_IDX) {
00849 NTR_GL_IR_LIST_TBL(list_idx);
00850
00851 COPY_GL_TBL_NTRY(global_ir_list_tbl, ir_list_tbl, list_idx, idx);
00852
00853 if (! IL_ARG_DESC_VARIANT(idx)) {
00854 GL_IL_PREV_LIST_IDX(list_idx) = list2_idx;
00855 }
00856
00857 GL_IL_NEXT_LIST_IDX(list2_idx) = list_idx;
00858 list2_idx = list_idx;
00859
00860 new_idx = copy_to_gl_subtree(IL_IDX(idx), IL_FLD(idx));
00861 GL_IL_IDX(list_idx) = new_idx;
00862 idx = IL_NEXT_LIST_IDX(idx);
00863 }
00864 break;
00865 }
00866 }
00867
00868 TRACE (Func_Exit, "copy_to_gl_subtree", NULL);
00869
00870 return(new_root);
00871
00872 }
00873
00874
00875
00876
00877
00878
00879
00880
00881
00882
00883
00884
00885
00886
00887
00888
00889
00890
00891 int copy_from_gl_subtree(int idx,
00892 fld_type fld)
00893
00894 {
00895 int new_idx;
00896 int list_idx;
00897 int list2_idx;
00898 int name_idx;
00899 int new_root = NULL_IDX;
00900 long_type the_constant;
00901
00902
00903 TRACE (Func_Entry, "copy_from_gl_subtree", NULL);
00904
00905 if (idx != NULL_IDX) {
00906
00907 switch(fld) {
00908
00909 case NO_Tbl_Idx :
00910 break;
00911
00912 case IR_Tbl_Idx :
00913
00914 NTR_IR_TBL(new_root);
00915
00916 COPY_GL_TBL_NTRY(ir_tbl, global_ir_tbl, new_root, idx);
00917
00918 new_idx = copy_from_gl_subtree(GL_IR_IDX_L(idx), GL_IR_FLD_L(idx));
00919 IR_IDX_L(new_root) = new_idx;
00920
00921 new_idx = copy_from_gl_subtree(GL_IR_IDX_R(idx), GL_IR_FLD_R(idx));
00922 IR_IDX_R(new_root) = new_idx;
00923
00924 break;
00925
00926 case AT_Tbl_Idx :
00927
00928 new_root = srch_sym_tbl(GA_OBJ_NAME_PTR(idx),
00929 GA_NAME_LEN(idx),
00930 &name_idx);
00931
00932
00933 break;
00934
00935 case CN_Tbl_Idx :
00936
00937
00938
00939
00940
00941
00942
00943 the_constant = idx;
00944 new_root = ntr_const_tbl(CG_INTEGER_DEFAULT_TYPE,
00945 FALSE,
00946 &the_constant);
00947
00948 break;
00949
00950 case SH_Tbl_Idx :
00951
00952 new_root = ntr_sh_tbl();
00953
00954 COPY_GL_TBL_NTRY(sh_tbl, global_sh_tbl, new_root, idx);
00955
00956 new_idx = copy_from_gl_subtree(GL_SH_IR_IDX(idx), IR_Tbl_Idx);
00957 SH_IR_IDX(new_root) = new_idx;
00958
00959 SH_COMPILER_GEN(new_root) = TRUE;
00960 break;
00961
00962 case IL_Tbl_Idx :
00963
00964 NTR_IR_LIST_TBL(new_root);
00965
00966 COPY_GL_TBL_NTRY(ir_list_tbl, global_ir_list_tbl, new_root, idx);
00967
00968 new_idx = copy_from_gl_subtree(GL_IL_IDX(idx), GL_IL_FLD(idx));
00969 IL_IDX(new_root) = new_idx;
00970 list2_idx = new_root;
00971
00972 idx = GL_IL_NEXT_LIST_IDX(idx);
00973
00974 while (idx != NULL_IDX) {
00975 NTR_IR_LIST_TBL(list_idx);
00976
00977 COPY_GL_TBL_NTRY(ir_list_tbl, global_ir_list_tbl, list_idx, idx);
00978
00979 if (! GL_IL_ARG_DESC_VARIANT(idx)) {
00980 IL_PREV_LIST_IDX(list_idx) = list2_idx;
00981 }
00982
00983 IL_NEXT_LIST_IDX(list2_idx) = list_idx;
00984 list2_idx = list_idx;
00985
00986 new_idx = copy_from_gl_subtree(GL_IL_IDX(idx), GL_IL_FLD(idx));
00987 IL_IDX(list_idx) = new_idx;
00988 idx = GL_IL_NEXT_LIST_IDX(idx);
00989 }
00990 break;
00991 }
00992 }
00993
00994 TRACE (Func_Exit, "copy_from_gl_subtree", NULL);
00995
00996 return(new_root);
00997
00998 }
00999
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009
01010
01011
01012
01013
01014
01015
01016
01017
01018 void insert_sh_chain_after_entries(int head_idx,
01019 int tail_idx)
01020
01021 {
01022 int entry_idx;
01023 int entry_sh_idx;
01024 int idx;
01025 int next_sh_idx;
01026 int new_end_sh_idx;
01027 int new_start_sh_idx;
01028
01029
01030 TRACE (Func_Entry, "insert_sh_chain_after_entries", NULL);
01031
01032 SH_NEXT_IDX(tail_idx) = SH_NEXT_IDX(SCP_FIRST_SH_IDX(curr_scp_idx));
01033 SH_PREV_IDX(head_idx) = SCP_FIRST_SH_IDX(curr_scp_idx);
01034 SH_NEXT_IDX(SCP_FIRST_SH_IDX(curr_scp_idx)) = head_idx;
01035 SH_PREV_IDX(SH_NEXT_IDX(tail_idx)) = tail_idx;
01036
01037 idx = SCP_ENTRY_IDX(curr_scp_idx);
01038
01039 while (idx != NULL_IDX) {
01040
01041
01042 entry_idx = AL_ATTR_IDX(idx);
01043
01044 entry_sh_idx = ATP_FIRST_SH_IDX(entry_idx);
01045 next_sh_idx = SH_NEXT_IDX(entry_sh_idx);
01046
01047 copy_entry_exit_sh_list(head_idx,
01048 tail_idx,
01049 &new_start_sh_idx,
01050 &new_end_sh_idx);
01051
01052 SH_NEXT_IDX(entry_sh_idx) = new_start_sh_idx;
01053 SH_PREV_IDX(new_start_sh_idx) = entry_sh_idx;
01054
01055 SH_PREV_IDX(next_sh_idx) = new_end_sh_idx;
01056 SH_NEXT_IDX(new_end_sh_idx) = next_sh_idx;
01057
01058 idx = AL_NEXT_IDX(idx);
01059 }
01060
01061
01062 TRACE (Func_Exit, "insert_sh_chain_after_entries", NULL);
01063
01064 return;
01065
01066 }
01067
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077
01078
01079
01080
01081
01082
01083
01084 void insert_sh_chain(int start_idx,
01085 int end_idx,
01086 sh_position_type position)
01087
01088 {
01089
01090
01091 TRACE (Func_Entry, "insert_sh_chain", NULL);
01092
01093 if (position == Before) {
01094 if (SH_PREV_IDX(curr_stmt_sh_idx) != NULL_IDX) {
01095 SH_NEXT_IDX(SH_PREV_IDX(curr_stmt_sh_idx)) = start_idx;
01096 }
01097 SH_PREV_IDX(start_idx) = SH_PREV_IDX(curr_stmt_sh_idx);
01098
01099 SH_PREV_IDX(curr_stmt_sh_idx) = end_idx;
01100 SH_NEXT_IDX(end_idx) = curr_stmt_sh_idx;
01101 }
01102 else {
01103 SH_PREV_IDX(start_idx) = curr_stmt_sh_idx;
01104 SH_NEXT_IDX(end_idx) = SH_NEXT_IDX(curr_stmt_sh_idx);
01105 if (SH_NEXT_IDX(curr_stmt_sh_idx) != NULL_IDX) {
01106 SH_PREV_IDX(SH_NEXT_IDX(curr_stmt_sh_idx)) = end_idx;
01107 }
01108 SH_NEXT_IDX(curr_stmt_sh_idx) = start_idx;
01109 }
01110
01111 TRACE (Func_Exit, "insert_sh_chain", NULL);
01112
01113 return;
01114
01115 }
01116
01117
01118
01119
01120
01121
01122
01123
01124
01125
01126
01127
01128
01129
01130
01131
01132
01133
01134
01135
01136
01137
01138 boolean compare_opnds(opnd_type *opnd1,
01139 opnd_type *opnd2)
01140 {
01141 boolean matched;
01142
01143 TRACE (Func_Entry, "compare_opnds", NULL);
01144
01145 if (OPND_FLD((*opnd1)) != OPND_FLD((*opnd2))) {
01146 matched = FALSE;
01147 }
01148 else {
01149
01150 switch (OPND_FLD((*opnd1))) {
01151
01152 case IR_Tbl_Idx:
01153 matched = compare_ir(OPND_IDX((*opnd1)), OPND_IDX((*opnd2)));
01154 break;
01155
01156 case IL_Tbl_Idx:
01157 matched = compare_il(OPND_IDX((*opnd1)),
01158 OPND_IDX((*opnd2)),
01159 OPND_LIST_CNT((*opnd1)),
01160 OPND_LIST_CNT((*opnd2)));
01161 break;
01162
01163 default:
01164 matched = OPND_IDX((*opnd1)) == OPND_IDX((*opnd2));
01165 break;
01166 }
01167 }
01168
01169 TRACE (Func_Exit, "compare_opnds", NULL);
01170
01171 return(matched);
01172
01173 }
01174
01175
01176
01177
01178
01179
01180
01181
01182
01183
01184
01185
01186
01187
01188
01189
01190
01191
01192
01193 void insert_sh_chain_before(int sh_idx)
01194
01195 {
01196 int start_idx;
01197 int end_idx;
01198
01199 TRACE (Func_Entry, "insert_sh_chain_before", NULL);
01200
01201 start_idx = sh_idx;
01202 while (SH_PREV_IDX(start_idx)) {
01203 start_idx = SH_PREV_IDX(start_idx);
01204 }
01205
01206 end_idx = sh_idx;
01207 while (SH_NEXT_IDX(end_idx)) {
01208 end_idx = SH_NEXT_IDX(end_idx);
01209 }
01210
01211 insert_sh_chain(start_idx, end_idx, Before);
01212
01213 TRACE (Func_Exit, "insert_sh_chain_before", NULL);
01214
01215 return;
01216
01217 }
01218
01219
01220
01221
01222
01223
01224
01225
01226
01227
01228
01229
01230
01231
01232
01233
01234
01235
01236 boolean find_attr_in_ir(int attr_idx,
01237 int ir_idx,
01238 opnd_type *opnd)
01239 {
01240
01241 TRACE (Func_Entry, "find_attr_in_ir", NULL);
01242
01243 switch (IR_FLD_L(ir_idx)) {
01244 case AT_Tbl_Idx:
01245
01246 if (IR_IDX_L(ir_idx) == attr_idx) {
01247 COPY_OPND((*opnd), IR_OPND_L(ir_idx));
01248 return(TRUE);
01249 }
01250 break;
01251
01252 case IR_Tbl_Idx:
01253
01254 if (find_attr_in_ir(attr_idx, IR_IDX_L(ir_idx), opnd)) {
01255 return(TRUE);
01256 }
01257 break;
01258
01259 case IL_Tbl_Idx:
01260
01261 if (find_attr_in_il(attr_idx, IR_IDX_L(ir_idx), opnd)) {
01262 return(TRUE);
01263 }
01264 break;
01265
01266 case CN_Tbl_Idx:
01267 case NO_Tbl_Idx:
01268 case SH_Tbl_Idx:
01269 break;
01270 }
01271
01272 switch (IR_FLD_R(ir_idx)) {
01273 case AT_Tbl_Idx:
01274
01275 if (IR_IDX_R(ir_idx) == attr_idx) {
01276 COPY_OPND((*opnd), IR_OPND_R(ir_idx));
01277 return(TRUE);
01278 }
01279 break;
01280
01281 case IR_Tbl_Idx:
01282
01283 if (find_attr_in_ir(attr_idx, IR_IDX_R(ir_idx), opnd)) {
01284 return(TRUE);
01285 }
01286 break;
01287
01288 case IL_Tbl_Idx:
01289
01290 if (find_attr_in_il(attr_idx, IR_IDX_R(ir_idx), opnd)) {
01291 return(TRUE);
01292 }
01293 break;
01294
01295 case CN_Tbl_Idx:
01296 case NO_Tbl_Idx:
01297 case SH_Tbl_Idx:
01298 break;
01299 }
01300
01301 TRACE (Func_Exit, "find_attr_in_ir", NULL);
01302
01303 return(FALSE);
01304
01305 }
01306
01307
01308
01309
01310
01311
01312
01313
01314
01315
01316
01317
01318
01319
01320
01321
01322
01323
01324 boolean find_attr_in_il(int attr_idx,
01325 int il_idx,
01326 opnd_type *opnd)
01327 {
01328
01329 TRACE (Func_Entry, "find_attr_in_il", NULL);
01330
01331 while (il_idx != NULL_IDX) {
01332
01333 switch (IL_FLD(il_idx)) {
01334
01335 case AT_Tbl_Idx:
01336
01337 if (IL_IDX(il_idx) == attr_idx) {
01338 COPY_OPND((*opnd), IL_OPND(il_idx));
01339 return(TRUE);
01340 }
01341 break;
01342
01343 case IR_Tbl_Idx:
01344
01345 if (find_attr_in_ir(attr_idx, IL_IDX(il_idx), opnd)) {
01346 return(TRUE);
01347 }
01348 break;
01349
01350 case IL_Tbl_Idx:
01351
01352 if (find_attr_in_il(attr_idx, IL_IDX(il_idx), opnd)) {
01353 return(TRUE);
01354 }
01355 break;
01356
01357 case CN_Tbl_Idx:
01358 case NO_Tbl_Idx:
01359 case SH_Tbl_Idx:
01360 break;
01361 }
01362
01363 il_idx = IL_NEXT_LIST_IDX(il_idx);
01364 }
01365
01366 TRACE (Func_Exit, "find_attr_in_il", NULL);
01367
01368 return(FALSE);
01369
01370 }
01371
01372
01373
01374
01375
01376
01377
01378
01379
01380
01381
01382
01383
01384
01385
01386
01387
01388
01389
01390
01391
01392
01393
01394 boolean expr_is_symbolic_constant(opnd_type *opnd)
01395
01396 {
01397 int idx;
01398 opnd_type loc_opnd;
01399 opnd_type new_opnd;
01400 boolean symbolic;
01401
01402
01403 TRACE (Func_Entry, "expr_is_symbolic_constant", NULL);
01404
01405 switch (OPND_FLD((*opnd))) {
01406 case CN_Tbl_Idx:
01407 symbolic = TRUE;
01408 break;
01409
01410 case IL_Tbl_Idx:
01411 COPY_OPND(loc_opnd, (*opnd));
01412 copy_subtree(&loc_opnd, &new_opnd);
01413 idx = OPND_IDX(new_opnd);
01414 symbolic = il_is_symbolic_constant(idx);
01415
01416 if (symbolic) {
01417 OPND_IDX((*opnd)) = idx;
01418 }
01419 else {
01420 free_ir_list(idx);
01421 }
01422 break;
01423
01424 case IR_Tbl_Idx:
01425 COPY_OPND(loc_opnd, (*opnd));
01426 copy_subtree(&loc_opnd, &new_opnd);
01427 idx = OPND_IDX(new_opnd);
01428 symbolic = ir_is_symbolic_constant(idx);
01429
01430 if (symbolic) {
01431 OPND_IDX((*opnd)) = idx;
01432 }
01433 else {
01434 free_ir_stream(idx);
01435 }
01436 break;
01437
01438 case AT_Tbl_Idx:
01439 symbolic = (AT_OBJ_CLASS(OPND_IDX((*opnd))) == Data_Obj &&
01440 (ATD_SYMBOLIC_CONSTANT(OPND_IDX((*opnd))) ||
01441 (ATD_CLASS(OPND_IDX((*opnd))) == Constant &&
01442 ATD_FLD(OPND_IDX((*opnd))) == CN_Tbl_Idx)));
01443 break;
01444
01445 case SH_Tbl_Idx:
01446 symbolic = FALSE;
01447 break;
01448
01449 default:
01450 symbolic = FALSE;
01451 break;
01452 }
01453
01454 TRACE (Func_Exit, "expr_is_symbolic_constant", NULL);
01455
01456 return(symbolic);
01457
01458 }
01459
01460
01461
01462
01463
01464
01465
01466
01467
01468
01469
01470
01471
01472
01473
01474
01475 static boolean ir_is_symbolic_constant(int ir_idx)
01476
01477 {
01478 boolean symbolic;
01479
01480
01481 TRACE (Func_Entry, "ir_is_symbolic_constant", NULL);
01482
01483 switch (IR_OPR(ir_idx)) {
01484 case Mult_Opr:
01485 IR_OPR(ir_idx) = Symbolic_Mult_Opr;
01486 break;
01487
01488 case Div_Opr:
01489 IR_OPR(ir_idx) = Symbolic_Div_Opr;
01490 break;
01491
01492 case Uplus_Opr:
01493 IR_OPR(ir_idx) = Symbolic_Uplus_Opr;
01494 break;
01495
01496 case Uminus_Opr:
01497 IR_OPR(ir_idx) = Symbolic_Uminus_Opr;
01498 break;
01499
01500 case Plus_Opr:
01501 IR_OPR(ir_idx) = Symbolic_Plus_Opr;
01502 break;
01503
01504 case Minus_Opr:
01505 IR_OPR(ir_idx) = Symbolic_Minus_Opr;
01506 break;
01507
01508 default:
01509 symbolic = FALSE;
01510 goto EXIT;
01511 }
01512
01513 switch (IR_FLD_L(ir_idx)) {
01514 case AT_Tbl_Idx:
01515 symbolic = (AT_OBJ_CLASS(IR_IDX_L(ir_idx)) == Data_Obj &&
01516 (ATD_SYMBOLIC_CONSTANT(IR_IDX_L(ir_idx)) ||
01517 (ATD_CLASS(IR_IDX_L(ir_idx)) == Constant &&
01518 ATD_FLD(IR_IDX_L(ir_idx)) == CN_Tbl_Idx)));
01519 break;
01520
01521 case IR_Tbl_Idx:
01522 symbolic = ir_is_symbolic_constant(IR_IDX_L(ir_idx));
01523 break;
01524
01525 case IL_Tbl_Idx:
01526 symbolic = il_is_symbolic_constant(IR_IDX_L(ir_idx));
01527 break;
01528
01529 case CN_Tbl_Idx:
01530 case NO_Tbl_Idx:
01531 symbolic = TRUE;
01532 break;
01533
01534 case SH_Tbl_Idx:
01535 default:
01536 symbolic = FALSE;
01537 break;
01538 }
01539
01540 if (symbolic) {
01541
01542 switch (IR_FLD_R(ir_idx)) {
01543 case AT_Tbl_Idx:
01544 symbolic = (AT_OBJ_CLASS(IR_IDX_R(ir_idx)) == Data_Obj &&
01545 (ATD_SYMBOLIC_CONSTANT(IR_IDX_R(ir_idx)) ||
01546 (ATD_CLASS(IR_IDX_R(ir_idx)) == Constant &&
01547 ATD_FLD(IR_IDX_R(ir_idx)) == CN_Tbl_Idx)));
01548 break;
01549
01550 case IR_Tbl_Idx:
01551 symbolic = ir_is_symbolic_constant(IR_IDX_R(ir_idx));
01552 break;
01553
01554 case IL_Tbl_Idx:
01555 symbolic = il_is_symbolic_constant(IR_IDX_R(ir_idx));
01556 break;
01557
01558 case CN_Tbl_Idx:
01559 case NO_Tbl_Idx:
01560 symbolic = TRUE;
01561 break;
01562
01563 case SH_Tbl_Idx:
01564 default:
01565 symbolic = FALSE;
01566 break;
01567 }
01568 }
01569
01570 EXIT:
01571
01572 TRACE (Func_Exit, "ir_is_symbolic_constant", NULL);
01573
01574 return(symbolic);
01575
01576 }
01577
01578
01579
01580
01581
01582
01583
01584
01585
01586
01587
01588
01589
01590
01591
01592
01593 static boolean il_is_symbolic_constant(int il_idx)
01594 {
01595 boolean symbolic = TRUE;
01596
01597
01598 TRACE (Func_Entry, "il_is_symbolic_constant", NULL);
01599
01600 while (symbolic == TRUE && il_idx != NULL_IDX) {
01601
01602 switch (IL_FLD(il_idx)) {
01603
01604 case AT_Tbl_Idx:
01605 symbolic = (AT_OBJ_CLASS(IL_IDX(il_idx)) == Data_Obj &&
01606 (ATD_SYMBOLIC_CONSTANT(IL_IDX(il_idx)) ||
01607 (ATD_CLASS(IL_IDX(il_idx)) == Constant &&
01608 ATD_FLD(IL_IDX(il_idx)) == CN_Tbl_Idx)));
01609 break;
01610
01611 case IR_Tbl_Idx:
01612 symbolic = ir_is_symbolic_constant(IL_IDX(il_idx));
01613 break;
01614
01615 case IL_Tbl_Idx:
01616 symbolic = il_is_symbolic_constant(IL_IDX(il_idx));
01617 break;
01618
01619 case CN_Tbl_Idx:
01620 case NO_Tbl_Idx:
01621 symbolic = TRUE;
01622 break;
01623
01624 case SH_Tbl_Idx:
01625 default:
01626 symbolic = FALSE;
01627 break;
01628 }
01629
01630 il_idx = IL_NEXT_LIST_IDX(il_idx);
01631 }
01632
01633 TRACE (Func_Exit, "il_is_symbolic_constant", NULL);
01634
01635 return(symbolic);
01636
01637 }
01638
01639
01640
01641
01642
01643
01644
01645
01646
01647
01648
01649
01650
01651
01652
01653
01654
01655
01656 void copy_entry_exit_sh_list(int start_sh_idx,
01657 int end_sh_idx,
01658 int *new_start_sh_idx,
01659 int *new_end_sh_idx)
01660
01661 {
01662 int al_idx;
01663 int new_sh_idx;
01664 opnd_type opnd_o;
01665 opnd_type opnd_n;
01666 int sh_idx;
01667
01668 TRACE (Func_Entry, "copy_entry_exit_sh_list", NULL);
01669
01670 sh_idx = start_sh_idx;
01671 *new_start_sh_idx = NULL_IDX;
01672 label_copy_al_idx = NULL_IDX;
01673 gen_lbl_copy = TRUE;
01674
01675 while (sh_idx != SH_NEXT_IDX(end_sh_idx)) {
01676
01677
01678
01679
01680 if (IR_OPR(SH_IR_IDX(sh_idx)) != Init_Opr &&
01681 IR_OPR(SH_IR_IDX(sh_idx)) != Init_Reloc_Opr) {
01682
01683 OPND_FLD(opnd_o) = SH_Tbl_Idx;
01684 OPND_IDX(opnd_o) = sh_idx;
01685 copy_subtree(&opnd_o, &opnd_n);
01686 new_sh_idx = OPND_IDX(opnd_n);
01687
01688 if (*new_start_sh_idx == NULL_IDX) {
01689 *new_start_sh_idx = new_sh_idx;
01690 SH_PREV_IDX((*new_start_sh_idx)) = NULL_IDX;
01691 SH_NEXT_IDX((*new_start_sh_idx)) = NULL_IDX;
01692 *new_end_sh_idx = new_sh_idx;
01693 }
01694 else {
01695 SH_NEXT_IDX((*new_end_sh_idx)) = new_sh_idx;
01696 SH_PREV_IDX(new_sh_idx) = *new_end_sh_idx;
01697 SH_NEXT_IDX(new_sh_idx) = NULL_IDX;
01698 *new_end_sh_idx = new_sh_idx;
01699 }
01700 }
01701
01702 sh_idx = SH_NEXT_IDX(sh_idx);
01703 }
01704
01705 gen_lbl_copy = FALSE;
01706 al_idx = label_copy_al_idx;
01707
01708 while (al_idx != NULL_IDX) {
01709 ATL_NEW_LBL_IDX(AL_ATTR_IDX(al_idx)) = NULL_IDX;
01710 al_idx = AL_NEXT_IDX(al_idx);
01711 }
01712
01713 free_attr_list(label_copy_al_idx);
01714
01715 label_copy_al_idx = NULL_IDX;
01716
01717 TRACE (Func_Exit, "copy_entry_exit_sh_list", NULL);
01718
01719 return;
01720
01721 }
01722
01723
01724
01725
01726
01727
01728
01729
01730
01731
01732
01733
01734
01735
01736
01737
01738
01739
01740
01741
01742
01743
01744
01745
01746
01747
01748
01749 int gen_stmt_expansion_opr(int line,
01750 int col)
01751
01752 {
01753 int ir_idx;
01754 int list_idx;
01755
01756 TRACE (Func_Entry, "gen_stmt_expansion_opr", NULL);
01757
01758 NTR_IR_TBL(ir_idx);
01759 IR_OPR(ir_idx) = Stmt_Expansion_Opr;
01760 IR_TYPE_IDX(ir_idx) = TYPELESS_DEFAULT_TYPE;
01761 IR_LINE_NUM(ir_idx) = line;
01762 IR_COL_NUM(ir_idx) = col;
01763
01764 NTR_IR_LIST_TBL(list_idx);
01765 IL_FLD(list_idx) = SH_Tbl_Idx;
01766 IL_LINE_NUM(list_idx) = line;
01767 IL_COL_NUM(list_idx) = col;
01768 IR_FLD_R(ir_idx) = IL_Tbl_Idx;
01769 IR_IDX_R(ir_idx) = list_idx;
01770 IR_LIST_CNT_R(ir_idx) = 4;
01771
01772 NTR_IR_LIST_TBL(IL_NEXT_LIST_IDX(list_idx));
01773 IL_PREV_LIST_IDX(IL_NEXT_LIST_IDX(list_idx)) = list_idx;
01774 list_idx = IL_NEXT_LIST_IDX(list_idx);
01775 IL_FLD(list_idx) = SH_Tbl_Idx;
01776 IL_LINE_NUM(list_idx) = line;
01777 IL_COL_NUM(list_idx) = col;
01778
01779 NTR_IR_LIST_TBL(IL_NEXT_LIST_IDX(list_idx));
01780 IL_PREV_LIST_IDX(IL_NEXT_LIST_IDX(list_idx)) = list_idx;
01781 list_idx = IL_NEXT_LIST_IDX(list_idx);
01782 IL_FLD(list_idx) = SH_Tbl_Idx;
01783 IL_LINE_NUM(list_idx) = line;
01784 IL_COL_NUM(list_idx) = col;
01785
01786 NTR_IR_LIST_TBL(IL_NEXT_LIST_IDX(list_idx));
01787 IL_PREV_LIST_IDX(IL_NEXT_LIST_IDX(list_idx)) = list_idx;
01788 list_idx = IL_NEXT_LIST_IDX(list_idx);
01789 IL_FLD(list_idx) = SH_Tbl_Idx;
01790 IL_LINE_NUM(list_idx) = line;
01791 IL_COL_NUM(list_idx) = col;
01792
01793 if (defer_stmt_expansion) {
01794 number_of_functions++;
01795 }
01796
01797 TRACE (Func_Exit, "gen_stmt_expansion_opr", NULL);
01798
01799 return(ir_idx);
01800
01801 }
01802
01803
01804
01805
01806
01807
01808
01809
01810
01811
01812
01813
01814
01815
01816
01817
01818
01819 void free_stmt_expansion_opr(int ir_idx)
01820
01821 {
01822 int free_list;
01823 int list_idx;
01824
01825 TRACE (Func_Entry, "free_stmt_expansion_opr", NULL);
01826
01827 list_idx = IR_IDX_R(ir_idx);
01828 while (list_idx) {
01829 free_list = list_idx;
01830
01831 list_idx = IL_NEXT_LIST_IDX(list_idx);
01832 FREE_IR_LIST_NODE(free_list);
01833 }
01834
01835 FREE_IR_NODE(ir_idx);
01836
01837 TRACE (Func_Exit, "free_stmt_expansion_opr", NULL);
01838
01839 return;
01840
01841 }
01842
01843
01844
01845
01846
01847
01848
01849
01850
01851
01852
01853
01854
01855
01856
01857
01858
01859 int gen_ir(fld_type l_fld,
01860 int l_idx,
01861 operator_type opr,
01862 int type_idx,
01863 int line,
01864 int col,
01865 fld_type r_fld,
01866 int r_idx)
01867
01868 {
01869
01870 int cnt;
01871 int ir_idx;
01872 int list_idx;
01873 int rank_l = 0;
01874 int rank_r = 0;
01875
01876 TRACE (Func_Entry, "gen_ir", NULL);
01877
01878 # ifdef _DEBUG
01879 if (opr == Subscript_Opr ||
01880 opr == Whole_Subscript_Opr ||
01881 opr == Section_Subscript_Opr ||
01882 opr == Substring_Opr ||
01883 opr == Whole_Substring_Opr ||
01884 opr == Struct_Opr) {
01885
01886 PRINTMSG(line, 626, Internal, col,
01887 "no reference operator",
01888 "gen_ir");
01889 }
01890
01891 if ((opr == Loc_Opr || opr == Aloc_Opr) &&
01892 (l_fld == CN_Tbl_Idx ||
01893 l_fld == SB_Tbl_Idx ||
01894 l_fld == IL_Tbl_Idx ||
01895 l_fld == SH_Tbl_Idx ||
01896 (l_fld == IR_Tbl_Idx &&
01897 IR_OPR(l_idx) != Struct_Opr &&
01898 IR_OPR(l_idx) != Dv_Deref_Opr &&
01899 IR_OPR(l_idx) != Subscript_Opr &&
01900 IR_OPR(l_idx) != Whole_Subscript_Opr &&
01901 IR_OPR(l_idx) != Section_Subscript_Opr &&
01902 IR_OPR(l_idx) != Substring_Opr &&
01903 IR_OPR(l_idx) != Whole_Substring_Opr))) {
01904
01905 PRINTMSG(line, 626, Internal, col,
01906 "valid LOC opr",
01907 "gen_ir");
01908 }
01909
01910 # endif
01911
01912 NTR_IR_TBL(ir_idx);
01913 IR_TYPE_IDX(ir_idx) = type_idx;
01914 IR_OPR(ir_idx) = opr;
01915 IR_LINE_NUM(ir_idx) = line;
01916 IR_COL_NUM(ir_idx) = col;
01917
01918 if (l_fld != NO_Tbl_Idx) {
01919 IR_LINE_NUM_L(ir_idx) = line;
01920 IR_COL_NUM_L(ir_idx) = col;
01921 IR_FLD_L(ir_idx) = l_fld;
01922 IR_IDX_L(ir_idx) = l_idx;
01923
01924 if (l_fld == IR_Tbl_Idx) {
01925 rank_l = IR_RANK(l_idx);
01926 }
01927 else if (l_fld == IL_Tbl_Idx) {
01928 list_idx = l_idx;
01929 cnt = 0;
01930 while (list_idx) {
01931
01932 if (IL_FLD(list_idx) == IR_Tbl_Idx &&
01933 IR_RANK(IL_IDX(list_idx)) > rank_l) {
01934 rank_l = IR_RANK(IL_IDX(list_idx));
01935 }
01936 cnt++;
01937 list_idx = IL_NEXT_LIST_IDX(list_idx);
01938 }
01939 IR_LIST_CNT_L(ir_idx) = cnt;
01940 }
01941 }
01942
01943 if (r_fld != NO_Tbl_Idx) {
01944 IR_LINE_NUM_R(ir_idx) = line;
01945 IR_COL_NUM_R(ir_idx) = col;
01946 IR_FLD_R(ir_idx) = r_fld;
01947 IR_IDX_R(ir_idx) = r_idx;
01948
01949 if (r_fld == IR_Tbl_Idx) {
01950 rank_r = IR_RANK(r_idx);
01951 }
01952 else if (r_fld == IL_Tbl_Idx) {
01953 list_idx = r_idx;
01954 cnt = 0;
01955 while (list_idx) {
01956
01957 if (IL_FLD(list_idx) == IR_Tbl_Idx &&
01958 IR_RANK(IL_IDX(list_idx)) > rank_r) {
01959 rank_r = IR_RANK(IL_IDX(list_idx));
01960 }
01961 cnt++;
01962 list_idx = IL_NEXT_LIST_IDX(list_idx);
01963 }
01964 IR_LIST_CNT_R(ir_idx) = cnt;
01965 }
01966 }
01967
01968 IR_RANK(ir_idx) = (rank_l > rank_r ? rank_l : rank_r);
01969
01970 IR_ARRAY_SYNTAX(ir_idx) = (IR_RANK(ir_idx) ? TRUE : FALSE);
01971
01972 TRACE (Func_Exit, "gen_ir", NULL);
01973
01974 return(ir_idx);
01975
01976 }
01977
01978
01979
01980
01981
01982
01983
01984
01985
01986
01987
01988
01989
01990
01991
01992
01993
01994 void gen_opnd(opnd_type *opnd, int idx, fld_type fld, int line, int col)
01995
01996 {
01997
01998 TRACE (Func_Entry, "gen_opnd", NULL);
01999
02000 *opnd = null_opnd;
02001
02002 OPND_FLD((*opnd)) = fld;
02003 OPND_IDX((*opnd)) = idx;
02004 if (fld == IL_Tbl_Idx) {
02005 OPND_LIST_CNT((*opnd)) = line;
02006 }
02007 else if (fld == AT_Tbl_Idx || fld == CN_Tbl_Idx) {
02008 OPND_LINE_NUM((*opnd)) = line;
02009 OPND_COL_NUM((*opnd)) = col;
02010 }
02011
02012 TRACE (Func_Exit, "gen_opnd", NULL);
02013
02014 return;
02015
02016 }
02017
02018
02019
02020
02021
02022
02023
02024
02025
02026
02027
02028
02029
02030
02031
02032
02033
02034 void stmt_expansion_control_start(void)
02035
02036 {
02037 int col;
02038 int line;
02039 int save_curr_stmt_sh_idx;
02040
02041 TRACE (Func_Entry, "stmt_expansion_control_start", NULL);
02042 if (defer_stmt_expansion) {
02043 PUSH_CURR_STMT;
02044 save_curr_stmt_sh_idx = curr_stmt_sh_idx;
02045 curr_stmt_sh_idx = ntr_sh_tbl();
02046 PUSH_CURR_STMT;
02047 line = SH_GLB_LINE(save_curr_stmt_sh_idx);
02048 col = SH_COL_NUM(save_curr_stmt_sh_idx);
02049 SH_ERR_FLG(curr_stmt_sh_idx) = SH_ERR_FLG(save_curr_stmt_sh_idx);
02050 SH_COL_NUM(curr_stmt_sh_idx) = col;
02051 SH_GLB_LINE(curr_stmt_sh_idx) = line;
02052 SH_STMT_TYPE(curr_stmt_sh_idx) = SH_STMT_TYPE(save_curr_stmt_sh_idx);
02053
02054
02055
02056
02057
02058 defer_stmt_expansion = FALSE;
02059 gen_sh(Before, Null_Stmt, line, col, FALSE, FALSE, TRUE);
02060 gen_sh(After, Null_Stmt, line, col, FALSE, FALSE, TRUE);
02061 curr_stmt_sh_idx = SH_PREV_IDX(curr_stmt_sh_idx);
02062 defer_stmt_expansion = TRUE;
02063 }
02064
02065 TRACE (Func_Exit, "stmt_expansion_control_start", NULL);
02066
02067 return;
02068
02069 }
02070
02071
02072
02073
02074
02075
02076
02077
02078
02079
02080
02081
02082
02083
02084
02085
02086
02087 void stmt_expansion_control_end(opnd_type *opnd)
02088
02089 {
02090 int col;
02091 int line;
02092 int next_idx;
02093 int prev_idx;
02094 int sh_idx;
02095 int stmt_expansion_idx;
02096
02097 TRACE (Func_Entry, "stmt_expansion_control_end", NULL);
02098
02099 if (defer_stmt_expansion) {
02100 POP_CURR_STMT;
02101
02102
02103
02104 next_idx = NULL_IDX;
02105 prev_idx = NULL_IDX;
02106
02107 sh_idx = SH_PREV_IDX(curr_stmt_sh_idx);
02108
02109 while(SH_PREV_IDX(sh_idx)) {
02110 prev_idx = sh_idx;
02111 sh_idx = SH_PREV_IDX(sh_idx);
02112 }
02113
02114 # ifdef _DEBUG
02115 if (SH_STMT_TYPE(sh_idx) != Null_Stmt) {
02116 PRINTMSG(stmt_start_line, 626, Internal, stmt_start_col,
02117 "valid stmt_expansion_control",
02118 "stmt_expansion_control_end");
02119 }
02120 # endif
02121
02122 FREE_SH_NODE(sh_idx);
02123
02124 sh_idx = SH_NEXT_IDX(curr_stmt_sh_idx);
02125
02126 while(SH_NEXT_IDX(sh_idx)) {
02127 next_idx = sh_idx;
02128 sh_idx = SH_NEXT_IDX(sh_idx);
02129 }
02130
02131 # ifdef _DEBUG
02132 if (SH_STMT_TYPE(sh_idx) != Null_Stmt) {
02133 PRINTMSG(stmt_start_line, 626, Internal, stmt_start_col,
02134 "valid stmt_expansion_control",
02135 "stmt_expansion_control_end");
02136 }
02137 # endif
02138
02139 FREE_SH_NODE(sh_idx);
02140
02141 if (prev_idx || next_idx) {
02142 find_opnd_line_and_column(opnd, &line, &col);
02143 stmt_expansion_idx =
02144 gen_stmt_expansion_opr(line, col);
02145 if (prev_idx) {
02146 STMT_EXPAND_BEFORE_END_SH(stmt_expansion_idx) =
02147 SH_PREV_IDX(curr_stmt_sh_idx);
02148 STMT_EXPAND_BEFORE_START_SH(stmt_expansion_idx) = prev_idx;
02149 SH_PREV_IDX(prev_idx) = NULL_IDX;
02150 SH_NEXT_IDX(STMT_EXPAND_BEFORE_END_SH(stmt_expansion_idx)) =
02151 NULL_IDX;
02152 }
02153 if (next_idx) {
02154 STMT_EXPAND_AFTER_START_SH(stmt_expansion_idx) =
02155 SH_NEXT_IDX(curr_stmt_sh_idx);
02156 STMT_EXPAND_AFTER_END_SH(stmt_expansion_idx) = next_idx;
02157 SH_NEXT_IDX(next_idx) = NULL_IDX;
02158 SH_PREV_IDX(STMT_EXPAND_AFTER_START_SH(stmt_expansion_idx)) =
02159 NULL_IDX;
02160 }
02161 COPY_OPND(IR_OPND_L(stmt_expansion_idx), (*opnd));
02162 OPND_FLD((*opnd)) = IR_Tbl_Idx;
02163 OPND_IDX((*opnd)) = stmt_expansion_idx;
02164 }
02165 FREE_SH_NODE(curr_stmt_sh_idx);
02166 POP_CURR_STMT;
02167 }
02168
02169 TRACE (Func_Exit, "stmt_expansion_control_end", NULL);
02170
02171 return;
02172
02173 }
02174
02175
02176
02177
02178
02179
02180
02181
02182
02183
02184
02185
02186
02187
02188
02189
02190
02191 void remove_sh(int sh_idx)
02192
02193 {
02194
02195
02196 TRACE (Func_Entry, "remove_sh", NULL);
02197
02198 if (SH_NEXT_IDX(sh_idx)) {
02199 SH_PREV_IDX(SH_NEXT_IDX(sh_idx)) = SH_PREV_IDX(sh_idx);
02200 }
02201
02202 if (SH_PREV_IDX(sh_idx)) {
02203 SH_NEXT_IDX(SH_PREV_IDX(sh_idx)) = SH_NEXT_IDX(sh_idx);
02204 }
02205
02206 TRACE (Func_Exit, "remove_sh", NULL);
02207
02208 return;
02209
02210 }
02211
02212
02213
02214
02215
02216
02217
02218
02219
02220
02221
02222
02223
02224
02225
02226
02227
02228
02229
02230
02231
02232
02233 int gen_il(int count,
02234 boolean arg_desc,
02235 int line,
02236 int col,
02237 ...)
02238
02239 {
02240 # define MAX_LIST_ARGS 40
02241
02242 va_list arg_ptr;
02243 int i;
02244 int k;
02245 int list_idx;
02246 int list_idx2;
02247 int start_idx = NULL_IDX;
02248 int fld[MAX_LIST_ARGS];
02249 int idx[MAX_LIST_ARGS];
02250
02251 TRACE (Func_Entry, "gen_il", NULL);
02252
02253 if (count <= 0) {
02254 goto EXIT;
02255 }
02256
02257 # ifdef _DEBUG
02258 if (count > MAX_LIST_ARGS) {
02259 PRINTMSG(line, 626, Internal, col,
02260 "count <= MAX_LIST_ARGS",
02261 "gen_il");
02262 }
02263 # endif
02264
02265 va_start (arg_ptr, col);
02266
02267 for (i = 0; i < count; i++) {
02268 fld[i] = va_arg(arg_ptr, long);
02269 idx[i] = va_arg(arg_ptr, long);
02270 }
02271
02272 va_end(arg_ptr);
02273
02274 NTR_IR_LIST_TBL(list_idx);
02275 start_idx = list_idx;
02276
02277 if (arg_desc) {
02278 IL_ARG_DESC_VARIANT(list_idx) = TRUE;
02279 }
02280
02281 IL_FLD(list_idx) = (fld_type) fld[0];
02282 IL_IDX(list_idx) = idx[0];
02283
02284 if (IL_FLD(list_idx) == IL_Tbl_Idx) {
02285 k = 0;
02286 list_idx2 = IL_IDX(list_idx);
02287 while(list_idx2) {
02288 k++;
02289 list_idx2 = IL_NEXT_LIST_IDX(list_idx2);
02290 }
02291
02292 IL_LIST_CNT(list_idx) = k;
02293 }
02294 else if (IL_FLD(list_idx) != IR_Tbl_Idx) {
02295 IL_LINE_NUM(list_idx) = line;
02296 IL_COL_NUM(list_idx) = col;
02297 }
02298
02299 for (i = 1; i < count; i++) {
02300
02301 NTR_IR_LIST_TBL(IL_NEXT_LIST_IDX(list_idx));
02302
02303 if (arg_desc) {
02304 IL_ARG_DESC_VARIANT(IL_NEXT_LIST_IDX(list_idx)) = TRUE;
02305 }
02306 else {
02307 IL_PREV_LIST_IDX(IL_NEXT_LIST_IDX(list_idx)) = list_idx;
02308 }
02309 list_idx = IL_NEXT_LIST_IDX(list_idx);
02310
02311 IL_FLD(list_idx) = (fld_type) fld[i];
02312 IL_IDX(list_idx) = idx[i];
02313
02314 if (IL_FLD(list_idx) == IL_Tbl_Idx) {
02315 k = 0;
02316 list_idx2 = IL_IDX(list_idx);
02317 while(list_idx2) {
02318 k++;
02319 list_idx2 = IL_NEXT_LIST_IDX(list_idx2);
02320 }
02321
02322 IL_LIST_CNT(list_idx) = k;
02323 }
02324 else if (IL_FLD(list_idx) != IR_Tbl_Idx) {
02325 IL_LINE_NUM(list_idx) = line;
02326 IL_COL_NUM(list_idx) = col;
02327 }
02328 }
02329
02330 EXIT:
02331
02332 TRACE (Func_Exit, "gen_il", NULL);
02333
02334 return(start_idx);
02335
02336 }