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
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 #ifdef _KEEP_RCS_ID
00072
00073 #endif
00074
00075 #include "whirl2f_common.h"
00076 #include "PUinfo.h"
00077 #include "st2f.h"
00078 #include "wn2f.h"
00079 #include "ty2f.h"
00080 #include "tcon2f.h"
00081 #include "init2f.h"
00082
00083
00084
00085
00086
00087
00088
00089
00090 extern TOKEN_BUFFER Data_Stmt_Tokens;
00091
00092
00093
00094
00095
00096
00097 #define OFFSET_IS_IN_FLD(fld, ofst) \
00098 (FLD_ofst(fld) == ofst || \
00099 (ofst > FLD_ofst(fld) && (ofst - FLD_ofst(fld) < TY_size(FLD_type(fld)))))
00100
00101
00102 static void
00103 Set_Tcon_Value(TCON *tcon, MTYPE mtype, INT typesize, char *bytes)
00104 {
00105 typedef struct Tcon_Value
00106 {
00107 union
00108 {
00109 INT8 i1;
00110 UINT8 u1;
00111 INT16 i2;
00112 UINT16 u2;
00113 INT32 i4;
00114 UINT32 u4;
00115 INT64 i8;
00116 UINT64 u8;
00117 float f[2];
00118 double d[2];
00119 QUAD_TYPE q;
00120 } val1;
00121 union
00122 {
00123 float f;
00124 double d;
00125 QUAD_TYPE q;
00126 } val2;
00127 } TCON_VALUE;
00128
00129 union
00130 {
00131 char byte[sizeof(TCON_VALUE)];
00132 TCON_VALUE val;
00133 } rep;
00134 INT i;
00135
00136 INT k = 0 ;
00137
00138 if (typesize < 4)
00139 k = 4 - typesize;
00140
00141 for (i = 0; i < typesize ; i++)
00142 rep.byte[i+k] = bytes[i];
00143
00144 switch (mtype)
00145 {
00146 case MTYPE_I1:
00147 rep.val.val1.i1 = ( rep.val.val1.i1 << 24) >> 24 ;
00148 *tcon = Host_To_Targ(mtype, rep.val.val1.i1);
00149 break;
00150
00151 case MTYPE_I2:
00152 rep.val.val1.i2 = ( rep.val.val1.i2 << 16) >> 16 ;
00153 *tcon = Host_To_Targ(mtype, rep.val.val1.i2);
00154 break;
00155
00156 case MTYPE_I4:
00157 *tcon = Host_To_Targ(mtype, rep.val.val1.i4);
00158 break;
00159
00160 case MTYPE_I8:
00161 *tcon = Host_To_Targ(mtype, rep.val.val1.i8);
00162 break;
00163
00164 case MTYPE_U1:
00165 *tcon = Host_To_Targ(mtype, rep.val.val1.u1);
00166 break;
00167
00168 case MTYPE_U2:
00169 *tcon = Host_To_Targ(mtype, rep.val.val1.u2);
00170 break;
00171
00172 case MTYPE_U4:
00173 *tcon = Host_To_Targ(mtype, rep.val.val1.u4);
00174 break;
00175
00176 case MTYPE_U8:
00177 *tcon = Host_To_Targ(mtype, rep.val.val1.u8);
00178 break;
00179
00180 case MTYPE_F4:
00181
00182
00183 *tcon = Host_To_Targ_Float(mtype, rep.val.val1.f[0]);
00184 break;
00185
00186 case MTYPE_F8:
00187 *tcon = Host_To_Targ_Float(mtype, rep.val.val1.d[0]);
00188 break;
00189
00190 case MTYPE_FQ:
00191 *tcon = Host_To_Targ_Quad(rep.val.val1.q);
00192 break;
00193
00194 case MTYPE_C4:
00195 *tcon = Host_To_Targ_Complex_4 (mtype,rep.val.val1.f[0],rep.val.val1.f[1]);
00196 break;
00197
00198 case MTYPE_C8:
00199 *tcon = Host_To_Targ_Complex (mtype,rep.val.val1.d[0],rep.val.val1.d[1]);
00200 break;
00201
00202 case MTYPE_CQ:
00203 *tcon = Host_To_Targ_Complex_Quad (rep.val.val1.q,rep.val.val2.q);
00204 break;
00205
00206 default:
00207 ASSERT_DBG_FATAL(FALSE,
00208 (DIAG_W2F_UNEXPECTED_TYPE_KIND,
00209 mtype, "Set_Tcon_Value"));
00210 break;
00211 }
00212 }
00213
00214
00215 static void
00216 INIT2F_Prepend_Equivalence(TOKEN_BUFFER tokens,
00217 TOKEN_BUFFER name1_tokens,
00218 UINT tmpvar_idx)
00219 {
00220
00221
00222
00223
00224
00225 Prepend_Token_Special(tokens, ')');
00226 Prepend_Token_String(tokens, W2CF_Symtab_Nameof_Tempvar(tmpvar_idx));
00227 Prepend_Token_Special(tokens, ',');
00228 Prepend_And_Copy_Token_List(tokens, name1_tokens);
00229 Prepend_Token_Special(tokens, '(');
00230 Prepend_Token_String(tokens, "EQUIVALENCE");
00231 Prepend_F77_Indented_Newline(tokens, 1, NULL);
00232 }
00233
00234
00235 static void
00236 INIT2F_Append_Initializer(TOKEN_BUFFER tokens,
00237 TOKEN_BUFFER *init_tokens,
00238 INT repeat)
00239 {
00240
00241
00242
00243
00244 if (repeat > 1)
00245 {
00246 Prepend_Token_Special(*init_tokens, '*');
00247 Prepend_Token_String(*init_tokens, Number_as_String(repeat, "%llu"));
00248 }
00249 if (!Is_Empty_Token_Buffer(tokens))
00250 Append_Token_Special(tokens, ',');
00251 Append_And_Reclaim_Token_List(tokens, init_tokens);
00252 }
00253
00254 static UINT16
00255 INIT2F_choose_repeat(const INITV& initv)
00256 {
00257 UINT16 rep = 0 ;
00258
00259 switch(INITV_kind(initv))
00260 {
00261 case INITVKIND_ZERO:
00262 case INITVKIND_ONE:
00263 case INITVKIND_VAL:
00264 rep = INITV_repeat2(initv);
00265 break;
00266
00267 default:
00268 rep = INITV_repeat1(initv);
00269 break;
00270 }
00271
00272 return rep ;
00273 }
00274
00275 static void
00276 INIT2F_Next_Initv(const INITV& initv,
00277 UINT *initv_idx,
00278 UINT *initv_times)
00279 {
00280
00281
00282
00283
00284
00285 if (*initv_times+1 < INIT2F_choose_repeat(initv))
00286 {
00287 (*initv_times)++;
00288 }
00289 else
00290 {
00291 *initv_times = 0;
00292 (*initv_idx)++;
00293 }
00294 }
00295
00296 static void
00297 INIT2F_Skip_Padding(INITV_IDX *initv_array,
00298 TY_IDX object_ty,
00299 STAB_OFFSET *ofst,
00300 UINT *initv_idx)
00301 {
00302
00303
00304
00305
00306 INITV_IDX initv;
00307
00308 for (initv = initv_array[*initv_idx];
00309 (*ofst < TY_size(object_ty) &&
00310 initv != (INITV_IDX) 0 &&
00311 INITV_kind(Initv_Table[initv]) == INITVKIND_PAD);
00312 initv = initv_array[++(*initv_idx)])
00313 {
00314 *ofst += INITV_pad(Initv_Table[initv])*INIT2F_choose_repeat(Initv_Table[initv]);
00315 }
00316 if (*ofst < TY_size(object_ty) && initv == (INITV_IDX) 0)
00317 *ofst = TY_size(object_ty);
00318 }
00319
00320 static UINT
00321 INIT2F_Number_Of_Initvs(INITV_IDX initv)
00322 {
00323 UINT count = 0;
00324 UINT64 rep;
00325
00326 while (initv != 0)
00327 {
00328 INITV& ini = Initv_Table[initv];
00329
00330 if (INITV_kind(ini) == INITVKIND_BLOCK)
00331 {
00332 for (rep = 1; rep <= INIT2F_choose_repeat(ini) ; rep++)
00333 count += INIT2F_Number_Of_Initvs(INITV_blk(ini));
00334 }
00335 else
00336 count += 1;
00337
00338 initv = INITV_next(initv);
00339 }
00340 return count;
00341 }
00342
00343 static void
00344 INIT2F_Collect_Initvs(INITV_IDX *initv_array, UINT *initv_idx, INITV_IDX initv)
00345 {
00346 UINT64 rep;
00347
00348 while (initv != (INITV_IDX) 0)
00349 {
00350 if (INITV_kind(Initv_Table[initv]) == INITVKIND_BLOCK)
00351 for (rep = 1; rep <= INIT2F_choose_repeat(Initv_Table[initv]); rep++)
00352 INIT2F_Collect_Initvs(initv_array, initv_idx, INITV_blk(Initv_Table[initv]));
00353 else
00354 initv_array[(*initv_idx)++] = initv;
00355
00356 initv = INITV_next(initv);
00357 }
00358 }
00359
00360 static INITV_IDX *
00361 INIT2F_Get_Initv_Array(ST *st, INITO_IDX first_inito)
00362 {
00363
00364
00365
00366
00367
00368
00369 UINT number_of_initvs = 1;
00370 INITV_IDX *initv_array;
00371 UINT i ;
00372
00373
00374
00375 INITO *ini = &Inito_Table[first_inito] ;
00376
00377 FOREACH_INITO(ST_level(st),ini,i)
00378 {
00379 if (INITO_st(ini) == st)
00380 number_of_initvs += INIT2F_Number_Of_Initvs(INITO_val(*ini));
00381 }
00382
00383
00384
00385 initv_array = TYPE_ALLOC_N(INITV_IDX, number_of_initvs);
00386 initv_array[number_of_initvs-1] = (INITV_IDX) 0;
00387 number_of_initvs = 0;
00388
00389 ini = &Inito_Table[first_inito] ;
00390
00391 FOREACH_INITO(ST_level(st),ini,i)
00392 {
00393 if (INITO_st(ini) == st)
00394 INIT2F_Collect_Initvs(initv_array, &number_of_initvs, INITO_val(*ini));
00395 }
00396 return initv_array;
00397
00398 }
00399
00400
00401
00402
00403 static TY_IDX
00404 INITVKIND_ty(INITV_IDX initv_idx)
00405 {
00406
00407
00408 INITV& initv = Initv_Table[initv_idx] ;
00409 TY_IDX initv_ty;
00410
00411 switch (INITV_kind(initv))
00412 {
00413 case INITVKIND_VAL:
00414 if (TCON_ty(INITV_tc_val(initv)) == MTYPE_STRING)
00415 {
00416 initv_ty = Stab_Array_Of(Stab_Mtype_To_Ty(MTYPE_U1),
00417 Targ_String_Length(INITV_tc_val(initv)));
00418 Set_TY_is_character(Ty_Table[initv_ty]);
00419 }
00420 else
00421 initv_ty = Stab_Mtype_To_Ty(TCON_ty(INITV_tc_val(initv)));
00422 break;
00423
00424 case INITVKIND_SYMOFF:
00425
00426
00427
00428
00429 if (TY_Is_Structured(ST_type(INITV_st(initv))))
00430 initv_ty = Stab_Pointer_To(Void_Type);
00431 else
00432 initv_ty = Stab_Pointer_To(ST_type(INITV_st(initv)));
00433 break;
00434
00435 case INITVKIND_ZERO:
00436 case INITVKIND_ONE:
00437 initv_ty = Be_Type_Tbl(INITV_mtype(initv));
00438 break;
00439
00440 default:
00441 ASSERT_DBG_FATAL(FALSE,
00442 (DIAG_W2F_UNEXPECTED_INITV,
00443 INITV_kind(initv), "INITVKIND_ty"));
00444
00445 }
00446
00447 return initv_ty;
00448
00449 }
00450
00451 static void
00452 INITVKIND_symoff(TOKEN_BUFFER tokens,
00453 INT repeat,
00454 ST *st,
00455 STAB_OFFSET ofst,
00456 TY_IDX object_ty)
00457 {
00458 WN2F_CONTEXT context = INIT_WN2F_CONTEXT;
00459 TOKEN_BUFFER symref_tokens = New_Token_Buffer();
00460
00461 WN2F_Offset_Symref(symref_tokens,
00462 st,
00463 Stab_Pointer_To(ST_type(st)),
00464 object_ty,
00465 ofst,
00466 context);
00467 WN2F_Address_Of(symref_tokens);
00468 INIT2F_Append_Initializer(tokens, &symref_tokens, repeat);
00469 }
00470
00471 static void
00472 INITVKIND_val(TOKEN_BUFFER tokens,
00473 INT repeat,
00474 TCON *tcon,
00475 TY_IDX object_ty)
00476 {
00477
00478
00479
00480 TOKEN_BUFFER val_tokens = New_Token_Buffer();
00481
00482 if (TCON_ty(*tcon) == MTYPE_STRING &&
00483 !TY_Is_Array(object_ty) && !TY_Is_String(object_ty))
00484 {
00485
00486
00487 if (TY_Is_Scalar(object_ty))
00488 {
00489 char *strbase = Targ_String_Address(*tcon);
00490 INT strlen = Targ_String_Length(*tcon);
00491 INT stridx;
00492 INT repeatcount = 0;
00493 TCON t;
00494 char *valp = (TY_Is_Complex(object_ty)?
00495 (char *)&t.cmplxval :
00496 (char *)&t.vals);
00497
00498 while (repeatcount++ < repeat)
00499 {
00500 stridx = 0;
00501 while (stridx < strlen)
00502 {
00503 Set_Tcon_Value(&t,
00504 TY_mtype(object_ty),
00505 TY_size(object_ty),
00506 &strbase[stridx]);
00507 TCON2F_translate(val_tokens, t, TY_is_logical(Ty_Table[object_ty]));
00508 stridx += TY_size(object_ty);
00509 if (stridx < strlen)
00510 Append_Token_Special(val_tokens, ',');
00511
00512 }
00513 }
00514 }
00515 }
00516 else
00517 {
00518
00519
00520 TCON2F_translate(val_tokens, *tcon, TY_is_logical(Ty_Table[object_ty]),object_ty);
00521 }
00522 INIT2F_Append_Initializer(tokens, &val_tokens, repeat);
00523 }
00524
00525
00526
00527
00528 static const char * one_consts[6] = { "1", ".TRUE.", "1_1", "1_2" , "1_4", "1_8"} ;
00529 static const char * zero_consts[6] = { "0", ".FALSE.","0_1", "0_2" , "0_4", "0_8"} ;
00530
00531 static void
00532 INITVKIND_const(TOKEN_BUFFER tokens,
00533 INT repeat,
00534 const char** tbl,
00535 TY_IDX ty)
00536 {
00537 const char *p = tbl[0];
00538
00539 TOKEN_BUFFER val_tokens = New_Token_Buffer();
00540
00541 if (TY_is_logical(Ty_Table[ty]))
00542 p = tbl[1];
00543 else {
00544
00545 if (WN2F_F90_pu) {
00546 switch (TY_mtype(ty)) {
00547 case MTYPE_I1: p = tbl[2]; break;
00548 case MTYPE_I2: p = tbl[3]; break;
00549 case MTYPE_I4: p = tbl[4]; break;
00550 case MTYPE_I8: p = tbl[5]; break;
00551 }
00552 }
00553 }
00554 Append_Token_String(val_tokens,p);
00555 INIT2F_Append_Initializer(tokens, &val_tokens, repeat);
00556 }
00557
00558
00559 static void
00560 INITVKIND_translate(TOKEN_BUFFER tokens,
00561 INITV_IDX initv_idx,
00562 TY_IDX object_ty,
00563 UINT repeat)
00564 {
00565 INITV& initv = Initv_Table[initv_idx];
00566
00567 switch (INITV_kind(initv))
00568 {
00569 case INITVKIND_SYMOFF:
00570 INITVKIND_symoff(tokens,
00571 repeat,
00572 &St_Table[INITV_st(initv)],
00573 INITV_ofst(initv),
00574 object_ty);
00575 break;
00576
00577 case INITVKIND_VAL:
00578 INITVKIND_val(tokens, repeat, &Tcon_Table[INITV_tc(initv)], object_ty);
00579 break;
00580
00581 case INITVKIND_ONE:
00582 INITVKIND_const(tokens, repeat, one_consts, object_ty);
00583 break;
00584
00585 case INITVKIND_ZERO:
00586 INITVKIND_const(tokens, repeat, zero_consts, object_ty);
00587 break;
00588
00589 default:
00590 ASSERT_DBG_WARN(FALSE, (DIAG_W2F_UNEXPECTED_INITV,
00591 INITV_kind(initv), "INITV2F_ptr_or_scalar"));
00592 break;
00593 }
00594 }
00595
00596
00597
00598
00599 static void
00600 INIT2F_Translate_Char_Ref(TOKEN_BUFFER tokens,
00601 ST *base_object,
00602 TY_IDX array_etype,
00603 STAB_OFFSET base_ofst,
00604 STAB_OFFSET array_ofst,
00605 STAB_OFFSET string_ofst,
00606 UINT string_size,
00607 WN2F_CONTEXT context)
00608 {
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618 WN2F_Offset_Symref(tokens,
00619 base_object,
00620 Stab_Pointer_To(ST_type(base_object)),
00621 array_etype,
00622 base_ofst + array_ofst,
00623 context);
00624
00625
00626 if (string_size != TY_size(array_etype))
00627 {
00628 Append_Token_Special(tokens, '(');
00629 Append_Token_String(tokens,
00630 Number_as_String(string_ofst+1, "%llu"));
00631 Append_Token_Special(tokens, ':');
00632 Append_Token_String(tokens,
00633 Number_as_String(string_ofst+string_size, "%llu"));
00634 Append_Token_Special(tokens, ')');
00635 }
00636 }
00637
00638
00639
00640
00641
00642 typedef struct Array_Segment
00643 {
00644 INITV_IDX *initv_array;
00645 BOOL missing_padding;
00646 UINT num_initvs;
00647 UINT first_idx;
00648 UINT last_idx;
00649 UINT first_repeat;
00650 UINT last_repeat;
00651 STAB_OFFSET start_ofst;
00652 STAB_OFFSET end_ofst;
00653 TY_IDX atype;
00654 TY_IDX etype;
00655 } ARRAY_SEGMENT;
00656
00657
00658 static BOOL
00659 INIT2F_is_string_initv(INITV& ini, TY_IDX ty)
00660 {
00661 BOOL res = FALSE;
00662
00663 if (INITV_kind(ini) == INITVKIND_VAL)
00664 {
00665 res = (TCON_ty(INITV_tc_val(ini)) == MTYPE_STRING &&
00666 TY_size(ty) > 0 &&
00667 TY_size(ty) < Targ_String_Length(INITV_tc_val(ini))) ;
00668
00669 }
00670 return res ;
00671 }
00672
00673 static ARRAY_SEGMENT
00674 INIT2F_Get_Array_Segment(INITV_IDX *initv_array,
00675 UINT *initv_idx,
00676 UINT *initv_times,
00677 TY_IDX object_type,
00678 STAB_OFFSET *object_ofst)
00679 {
00680
00681
00682
00683
00684
00685
00686
00687 const UINT first_already_repeated = *initv_times;
00688 STAB_OFFSET max_ofst;
00689 ARRAY_SEGMENT aseg;
00690 INITV_IDX initv;
00691
00692
00693
00694 aseg.initv_array = initv_array;
00695 aseg.num_initvs = 0;
00696 aseg.first_idx = *initv_idx;
00697 aseg.last_idx = aseg.first_idx;
00698 aseg.start_ofst = *object_ofst;
00699 aseg.atype = object_type;
00700 aseg.etype = TY_AR_etype(object_type);
00701
00702
00703
00704
00705
00706
00707
00708
00709 initv = initv_array[aseg.first_idx];
00710 max_ofst = TY_size(object_type);
00711 while (max_ofst > *object_ofst &&
00712 initv != (INITV_IDX) 0
00713 && INITV_kind(Initv_Table[initv]) != INITVKIND_PAD)
00714 {
00715
00716 INITV& ini = Initv_Table[initv];
00717 aseg.num_initvs++;
00718 aseg.last_idx = *initv_idx;
00719 aseg.last_repeat = *initv_times+1;
00720
00721 if (INIT2F_is_string_initv(ini,aseg.etype))
00722 {
00723
00724
00725 if (!WN2F_F90_pu)
00726 {
00727 ASSERT_DBG_WARN(FALSE,
00728 (DIAG_W2F_UNEXPECTED_INITV,
00729 TCON_ty(INITV_tc_val(ini)),
00730 "[character string exceeds size of element type] "
00731 "INIT2F_Get_Array_Segment"));
00732 }
00733 *object_ofst += Targ_String_Length(INITV_tc_val(ini));
00734 }
00735 else if (TY_is_character(Ty_Table[aseg.etype]) &&
00736 TCON_ty(INITV_tc_val(ini)) == MTYPE_STRING)
00737 {
00738 *object_ofst += Targ_String_Length(INITV_tc_val(ini));
00739 }
00740 else
00741 *object_ofst += TY_size(aseg.etype);
00742
00743
00744
00745
00746 INIT2F_Next_Initv(ini, initv_idx, initv_times);
00747 initv = initv_array[*initv_idx];
00748 }
00749
00750 if (max_ofst > *object_ofst && initv == (INITV_IDX) 0)
00751 {
00752 aseg.missing_padding = TRUE;
00753 ASSERT_DBG_WARN(FALSE,
00754 (DIAG_W2F_UNEXPEXTED_NULL_PTR,
00755 "initv (missing padding for object initializer?)",
00756 "INIT2F_Get_Array_Segment"));
00757 }
00758 else
00759 aseg.missing_padding = FALSE;
00760
00761
00762
00763
00764
00765
00766 aseg.end_ofst = *object_ofst;
00767 if (aseg.last_idx > aseg.first_idx)
00768 {
00769 aseg.first_repeat =
00770 INIT2F_choose_repeat(Initv_Table[initv_array[aseg.first_idx]]) - first_already_repeated;
00771 }
00772 else
00773 {
00774 aseg.first_repeat = aseg.last_repeat - first_already_repeated;
00775 aseg.last_repeat = aseg.first_repeat;
00776 }
00777
00778 return aseg;
00779 }
00780
00781 static void
00782 INIT2F_Translate_Array_Value(TOKEN_BUFFER tokens,
00783 const ARRAY_SEGMENT *aseg)
00784 {
00785 UINT initv_idx, repeat;
00786 INITV_IDX initv;
00787
00788 for (initv_idx = aseg->first_idx; initv_idx <= aseg->last_idx; initv_idx++)
00789 {
00790
00791 initv = aseg->initv_array[initv_idx];
00792 if (initv_idx == aseg->first_idx)
00793 repeat = aseg->first_repeat;
00794 else if (initv_idx == aseg->last_idx)
00795 repeat = aseg->last_repeat;
00796 else
00797 repeat = INIT2F_choose_repeat(Initv_Table[initv]);
00798
00799
00800 INITVKIND_translate(tokens, initv, aseg->etype, repeat);
00801 }
00802 }
00803
00804 static void
00805 INIT2F_Implied_DoLoop(TOKEN_BUFFER tokens,
00806 TOKEN_BUFFER *abase_tokens,
00807 const ARRAY_SEGMENT *aseg)
00808 {
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819
00820
00821 const UINT current_indent = Current_Indentation();
00822 TOKEN_BUFFER aref_tokens;
00823 UINT ivar_idx, avar_idx;
00824 const char *ivar_name;
00825 TY_IDX atype;
00826
00827 ARB_HANDLE arb_base = TY_arb(aseg->atype);
00828 ARB_HANDLE arb = arb_base[0];
00829
00830
00831 ivar_idx = Stab_Lock_Tmpvar(Stab_Mtype_To_Ty(MTYPE_I8),
00832 &ST2F_Declare_Tempvar);
00833
00834
00835 aref_tokens = New_Token_Buffer();
00836 if (TY_AR_ndims(aseg->atype) > 1)
00837 {
00838
00839
00840
00841 atype = Stab_Array_Of(aseg->etype,
00842 TY_size(aseg->atype)/TY_size(aseg->etype));
00843 avar_idx = Stab_Lock_Tmpvar(atype, &ST2F_Declare_Tempvar);
00844 Set_Current_Indentation(PUinfo_local_decls_indent);
00845 INIT2F_Prepend_Equivalence(Data_Stmt_Tokens, *abase_tokens, avar_idx);
00846 Reclaim_Token_Buffer(abase_tokens);
00847 Set_Current_Indentation(current_indent);
00848
00849 Append_Token_String(aref_tokens, W2CF_Symtab_Nameof_Tempvar(avar_idx));
00850 Stab_Unlock_Tmpvar(avar_idx);
00851 }
00852 else
00853 {
00854 Append_And_Reclaim_Token_List(aref_tokens, abase_tokens);
00855 }
00856
00857
00858 ivar_name = W2CF_Symtab_Nameof_Tempvar(ivar_idx);
00859 Append_Token_Special(tokens, '(');
00860 Append_And_Reclaim_Token_List(tokens, &aref_tokens);
00861 Append_Token_Special(tokens, '(');
00862 Append_Token_String(tokens, ivar_name);
00863 Append_Token_Special(tokens, ')');
00864
00865 Append_Token_Special(tokens, ',');
00866 Append_Token_String(tokens, ivar_name);
00867 Append_Token_Special(tokens, '=');
00868
00869 # if 0//June
00870
00871 Append_Token_String(tokens,
00872 Number_as_String(aseg->start_ofst/TY_size(aseg->etype) + 1,
00873 "%llu"));
00874 # endif
00875
00876
00877
00878
00879
00880
00881 TCON2F_translate(tokens,
00882 Host_To_Targ(MTYPE_I4,
00883 ARB_lbnd_val(arb)),
00884 FALSE );
00885
00886 Append_Token_Special(tokens, ',');
00887
00888
00889 Append_Token_String(tokens,
00890 Number_as_String(aseg->end_ofst/TY_size(aseg->etype)+
00891 ARB_lbnd_val(arb)-1,
00892 "%llu"));
00893
00894 # if 0
00895
00896 TCON2F_translate(tokens,
00897 Host_To_Targ(MTYPE_I4,
00898 ARB_ubnd_val(arb)),
00899 FALSE );
00900
00901 #endif
00902
00903 Append_Token_Special(tokens, ',');
00904 Append_Token_String(tokens, Number_as_String(1, "%llu"));
00905 Append_Token_Special(tokens, ')');
00906
00907 Stab_Unlock_Tmpvar(ivar_idx);
00908 }
00909
00910 static void
00911 INIT2F_Translate_Array_Ref(TOKEN_BUFFER tokens,
00912 ST *base_object,
00913 STAB_OFFSET base_ofst,
00914 const ARRAY_SEGMENT *aseg)
00915 {
00916
00917
00918
00919
00920
00921
00922
00923 const STAB_OFFSET esize = TY_size(aseg->etype);
00924 STAB_OFFSET ofst;
00925 WN2F_CONTEXT context = INIT_WN2F_CONTEXT;
00926 TOKEN_BUFFER abase_tokens, aref_tokens;
00927 UINT first_idx = aseg->first_idx;
00928 INITV_IDX first_initv = aseg->initv_array[first_idx];
00929
00930
00931 if (aseg->num_initvs == 1 &&
00932 INIT2F_is_string_initv(Initv_Table[first_initv],aseg->etype))
00933 {
00934
00935
00936 abase_tokens = New_Token_Buffer();
00937 WN2F_Offset_Symref(abase_tokens,
00938 base_object,
00939 Stab_Pointer_To(ST_type(base_object)),
00940 aseg->atype,
00941 base_ofst,
00942 context);
00943
00944 aref_tokens = New_Token_Buffer();
00945 INIT2F_Implied_DoLoop(aref_tokens,
00946 &abase_tokens,
00947 aseg);
00948 INIT2F_Append_Initializer(tokens, &aref_tokens, 1);
00949 }
00950 else if (aseg->start_ofst % TY_size(aseg->etype) != 0 ||
00951 aseg->end_ofst % TY_size(aseg->etype) != 0 ||
00952 (!aseg->missing_padding &&
00953 aseg->num_initvs !=
00954 (aseg->end_ofst - aseg->start_ofst)/TY_size(aseg->etype)))
00955 {
00956
00957
00958
00959
00960 UINT initc, substring_size;
00961 UINT initv_idx = first_idx;
00962 INITV_IDX ini_idx = first_initv;
00963 UINT initv_repeat = INIT2F_choose_repeat(Initv_Table[ini_idx]) - aseg->first_repeat;
00964
00965 ofst = aseg->start_ofst;
00966 for (initc = 1; initc <= aseg->num_initvs; initc++)
00967 {
00968 INITV& initv = Initv_Table[ini_idx];
00969 substring_size = Targ_String_Length(INITV_tc_val(initv));
00970 aref_tokens = New_Token_Buffer();
00971 INIT2F_Translate_Char_Ref(aref_tokens,
00972 base_object,
00973 aseg->etype,
00974 base_ofst,
00975 (ofst/esize)*esize,
00976 ofst%esize,
00977 substring_size,
00978 context);
00979 INIT2F_Append_Initializer(tokens, &aref_tokens, 1);
00980 if (initc < aseg->num_initvs) {
00981 INIT2F_Next_Initv(initv, &initv_idx, &initv_repeat);
00982 ini_idx = aseg->initv_array[initv_idx];
00983 }
00984 ofst += substring_size;
00985 }
00986 }
00987 else
00988 {
00989
00990 abase_tokens = New_Token_Buffer();
00991 WN2F_Offset_Symref(abase_tokens,
00992 base_object,
00993 Stab_Pointer_To(ST_type(base_object)),
00994 aseg->atype,
00995 base_ofst,
00996 context);
00997
00998
00999
01000 if (aseg->num_initvs*TY_size(aseg->etype) == TY_size(aseg->atype))
01001 {
01002
01003 INIT2F_Append_Initializer(tokens, &abase_tokens, 1);
01004 }
01005 else if (aseg->num_initvs > 4)
01006 {
01007
01008 aref_tokens = New_Token_Buffer();
01009 INIT2F_Implied_DoLoop(aref_tokens,
01010 &abase_tokens,
01011 aseg);
01012 INIT2F_Append_Initializer(tokens, &aref_tokens, 1);
01013 }
01014 else if (aseg->num_initvs > 0)
01015 {
01016 INT elt;
01017
01018
01019 ofst = aseg->start_ofst;
01020 for (elt = 0; elt < aseg->num_initvs; elt++)
01021 {
01022 aref_tokens = New_Token_Buffer();
01023 Append_And_Copy_Token_List(aref_tokens, abase_tokens);
01024 TY2F_Translate_ArrayElt(aref_tokens, aseg->atype, ofst);
01025 INIT2F_Append_Initializer(tokens, &aref_tokens, 1);
01026 ofst += TY_size(aseg->etype);
01027 }
01028 Reclaim_Token_Buffer(&abase_tokens);
01029 }
01030 }
01031 }
01032
01033
01034
01035
01036 static void
01037 INIT2F_translate(TOKEN_BUFFER lhs_tokens,
01038 TOKEN_BUFFER rhs_tokens,
01039 ST *base_object,
01040 STAB_OFFSET base_ofst,
01041 STAB_OFFSET *object_ofst,
01042 TY_IDX object_ty,
01043 INITV_IDX *initv_array,
01044 UINT *initv_idx,
01045 UINT *initv_times);
01046
01047 static void
01048 INIT2F_ptr_or_scalar(TOKEN_BUFFER lhs_tokens,
01049 TOKEN_BUFFER rhs_tokens,
01050 ST *base_object,
01051 STAB_OFFSET base_ofst,
01052 STAB_OFFSET *object_ofst,
01053 TY_IDX object_ty,
01054 INITV_IDX *initv_array,
01055 UINT *initv_idx,
01056 UINT *initv_times)
01057 {
01058
01059
01060
01061
01062 INITV& initv = Initv_Table[initv_array[*initv_idx]];
01063 WN2F_CONTEXT context = INIT_WN2F_CONTEXT;
01064 TOKEN_BUFFER sym_tokens;
01065
01066 ASSERT_DBG_WARN(*object_ofst == 0,
01067 (DIAG_W2F_UNEXPEXTED_OFFSET,
01068 *object_ofst, "INITV2F_ptr_or_scalar"));
01069
01070
01071 INITVKIND_translate(rhs_tokens,
01072 initv_array[*initv_idx],
01073 object_ty,
01074 1) ;
01075
01076 INIT2F_Next_Initv(initv, initv_idx, initv_times);
01077
01078
01079 sym_tokens = New_Token_Buffer();
01080 WN2F_Offset_Symref(sym_tokens,
01081 base_object,
01082 Stab_Pointer_To(ST_type(base_object)),
01083 object_ty,
01084 base_ofst,
01085 context);
01086 INIT2F_Append_Initializer(lhs_tokens, &sym_tokens, 1);
01087
01088
01089 *object_ofst += TY_size(object_ty);
01090
01091 }
01092
01093
01094 static void
01095 INIT2F_array(TOKEN_BUFFER lhs_tokens,
01096 TOKEN_BUFFER rhs_tokens,
01097 ST *base_object,
01098 STAB_OFFSET base_ofst,
01099 STAB_OFFSET *object_ofst,
01100 TY_IDX object_ty,
01101 INITV_IDX *initv_array,
01102 UINT *initv_idx,
01103 UINT *initv_times)
01104 {
01105
01106
01107
01108
01109
01110
01111
01112 ARRAY_SEGMENT a_segment;
01113
01114 ASSERT_DBG_FATAL(TY_Is_Array(object_ty) && !TY_is_character(object_ty),
01115 (DIAG_W2F_UNEXPECTED_TYPE_KIND,
01116 TY_kind(object_ty), "INITV2F_array"));
01117
01118 INIT2F_Skip_Padding(initv_array,
01119 object_ty,
01120 object_ofst,
01121 initv_idx);
01122 while (*object_ofst < TY_size(object_ty))
01123 {
01124
01125
01126
01127
01128 INITV& initv = Initv_Table[initv_array[*initv_idx]];
01129
01130 #if 0
01131 ASSERT_DBG_FATAL(!(TY_Is_Array_Of_Chars(object_ty) &&
01132 INITV_kind(initv) == INITVKIND_VAL &&
01133 TCON_ty(INITV_tc_val(initv)) == MTYPE_STRING),
01134 (DIAG_W2F_UNEXPECTED_INITV,
01135 INITV_kind(initv), "INITV2F_array"));
01136 #endif
01137
01138
01139
01140 a_segment =
01141 INIT2F_Get_Array_Segment(initv_array,
01142 initv_idx,
01143 initv_times,
01144 object_ty,
01145 object_ofst);
01146
01147
01148
01149 INIT2F_Translate_Array_Value(rhs_tokens, &a_segment);
01150
01151
01152
01153 INIT2F_Translate_Array_Ref(lhs_tokens,
01154 base_object,
01155 base_ofst,
01156 &a_segment);
01157
01158
01159
01160 INIT2F_Skip_Padding(initv_array,
01161 object_ty,
01162 object_ofst,
01163 initv_idx);
01164
01165
01166
01167
01168 }
01169
01170 }
01171
01172 static void
01173 INIT2F_substring(TOKEN_BUFFER lhs_tokens,
01174 TOKEN_BUFFER rhs_tokens,
01175 ST *base_object,
01176 STAB_OFFSET base_ofst,
01177 STAB_OFFSET *object_ofst,
01178 TY_IDX object_ty,
01179 INITV_IDX *initv_array,
01180 UINT *initv_idx,
01181 UINT *initv_times)
01182 {
01183
01184
01185
01186
01187
01188 STAB_OFFSET substring_size;
01189 TOKEN_BUFFER substring_tokens;
01190 WN2F_CONTEXT context = INIT_WN2F_CONTEXT;
01191
01192 ASSERT_DBG_FATAL((TY_Is_String(object_ty) ||
01193 TY_Is_Array_Of_Chars(object_ty)),
01194 (DIAG_W2F_UNEXPECTED_TYPE_KIND,
01195 TY_kind(object_ty), "INITV2F_substring"));
01196
01197 INIT2F_Skip_Padding(initv_array,
01198 object_ty,
01199 object_ofst,
01200 initv_idx);
01201
01202 if (*object_ofst < TY_size(object_ty))
01203 {
01204
01205
01206 INITV_IDX initv = initv_array[*initv_idx];
01207 INITV& ini = Initv_Table[initv];
01208
01209 INITVKIND_translate(rhs_tokens, initv, object_ty, 1);
01210
01211
01212
01213 substring_size = Targ_String_Length(INITV_tc_val(ini));
01214 substring_tokens = New_Token_Buffer();
01215 INIT2F_Translate_Char_Ref(substring_tokens,
01216 base_object,
01217 object_ty,
01218 base_ofst,
01219 0,
01220 *object_ofst,
01221 substring_size,
01222 context);
01223 INIT2F_Append_Initializer(lhs_tokens, &substring_tokens, 1);
01224 INIT2F_Next_Initv(ini, initv_idx, initv_times);
01225 *object_ofst += substring_size;
01226 }
01227 }
01228
01229 static void
01230 INIT2F_structured(TOKEN_BUFFER lhs_tokens,
01231 TOKEN_BUFFER rhs_tokens,
01232 ST *base_object,
01233 STAB_OFFSET *object_ofst,
01234 TY_IDX object_ty,
01235 INITV_IDX *initv_array,
01236 UINT *initv_idx,
01237 UINT *initv_times)
01238 {
01239
01240
01241
01242
01243
01244 TY_IDX initv_ty;
01245 STAB_OFFSET fld_ofst;
01246 FLD_PATH_INFO *fpath;
01247
01248 ASSERT_DBG_FATAL(TY_Is_Structured(object_ty),
01249 (DIAG_W2F_UNEXPECTED_TYPE_KIND,
01250 TY_kind(object_ty), "INITV2F_structured"));
01251
01252
01253
01254
01255 INIT2F_Skip_Padding(initv_array, object_ty, object_ofst, initv_idx);
01256 while (*object_ofst < TY_size(object_ty))
01257 {
01258
01259 initv_ty = INITVKIND_ty(initv_array[*initv_idx]);
01260
01261
01262
01263
01264
01265
01266
01267 fpath = TY2F_Get_Fld_Path(object_ty, initv_ty, *object_ofst);
01268 {
01269 FLD_HANDLE fld;
01270
01271 if (fpath == NULL || fpath->fld.Is_Null ())
01272 {
01273
01274
01275
01276
01277 FLD_ITER fld_iter = Make_fld_iter (TY_fld(Ty_Table[object_ty]));
01278
01279 do
01280 {
01281 fld = FLD_HANDLE (fld_iter);
01282 } while (!FLD_last_field (fld_iter++) &&
01283 !OFFSET_IS_IN_FLD(fld, *object_ofst)) ;
01284 } else
01285 fld = fpath->fld;
01286
01287 if (fpath != NULL)
01288 TY2F_Free_Fld_Path(fpath);
01289
01290
01291
01292
01293
01294 fld_ofst = *object_ofst - FLD_ofst(fld);
01295 INIT2F_translate(lhs_tokens,
01296 rhs_tokens,
01297 base_object,
01298 FLD_ofst(fld),
01299 &fld_ofst,
01300 FLD_type(fld),
01301 initv_array,
01302 initv_idx,
01303 initv_times);
01304
01305
01306
01307 *object_ofst = FLD_ofst(fld) + fld_ofst;
01308 INIT2F_Skip_Padding(initv_array,
01309 object_ty,
01310 object_ofst,
01311 initv_idx);
01312 }
01313 }
01314 }
01315
01316 static void
01317 INIT2F_translate(TOKEN_BUFFER lhs_tokens,
01318 TOKEN_BUFFER rhs_tokens,
01319 ST *base_object,
01320 STAB_OFFSET base_ofst,
01321 STAB_OFFSET *object_ofst,
01322 TY_IDX object_ty,
01323 INITV_IDX *initv_array,
01324 UINT *initv_idx,
01325 UINT *initv_times)
01326 {
01327 if (TY_Is_Structured(object_ty))
01328 {
01329 INIT2F_structured(lhs_tokens,
01330 rhs_tokens,
01331 base_object,
01332 object_ofst,
01333 object_ty,
01334 initv_array,
01335 initv_idx,
01336 initv_times);
01337 }
01338 else if (TY_Is_Array(object_ty))
01339 {
01340 if (TY_is_character(Ty_Table[object_ty]))
01341
01342 INIT2F_substring(lhs_tokens,
01343 rhs_tokens,
01344 base_object,
01345 base_ofst,
01346 object_ofst,
01347 object_ty,
01348 initv_array,
01349 initv_idx,
01350 initv_times);
01351 else
01352 INIT2F_array(lhs_tokens,
01353 rhs_tokens,
01354 base_object,
01355 base_ofst,
01356 object_ofst,
01357 object_ty,
01358 initv_array,
01359 initv_idx,
01360 initv_times);
01361 }
01362 else if (TY_Is_Pointer_Or_Scalar(object_ty))
01363 {
01364 INIT2F_ptr_or_scalar(lhs_tokens,
01365 rhs_tokens,
01366 base_object,
01367 base_ofst,
01368 object_ofst,
01369 object_ty,
01370 initv_array,
01371 initv_idx,
01372 initv_times);
01373 }
01374 else
01375 ASSERT_DBG_WARN(FALSE,
01376 (DIAG_W2F_UNEXPECTED_SYMBOL, "INITV2F_translate"));
01377 }
01378
01379
01380
01381
01382
01383 void
01384 INITO2F_translate(TOKEN_BUFFER tokens, INITO_IDX inito)
01385 {
01386
01387
01388
01389
01390
01391 TOKEN_BUFFER lhs_tokens = New_Token_Buffer();
01392 TOKEN_BUFFER rhs_tokens = New_Token_Buffer();
01393 UINT initv_idx = 0;
01394 UINT initv_times = 0;
01395 TY_IDX object_ty = ST_type(INITO_st(inito));
01396 STAB_OFFSET object_ofst = 0;
01397 INITV_IDX *initv_array;
01398
01399 ASSERT_DBG_FATAL(!TY_Is_Structured(object_ty) ||
01400 Stab_Is_Common_Block(INITO_st(inito)) ||
01401 Stab_Is_Equivalence_Block(INITO_st(inito)),
01402 (DIAG_W2F_UNEXPECTED_SYMBOL, "INITO2F_translate"));
01403
01404
01405
01406
01407
01408
01409
01410
01411 initv_array = INIT2F_Get_Initv_Array(INITO_st(inito), inito);
01412
01413
01414
01415
01416
01417 INIT2F_translate(lhs_tokens,
01418 rhs_tokens,
01419 INITO_st(inito),
01420 0,
01421 &object_ofst,
01422 object_ty,
01423 initv_array,
01424 &initv_idx,
01425 &initv_times);
01426
01427
01428
01429 FREE(initv_array);
01430 Append_F77_Indented_Newline(tokens, 1, NULL);
01431 Append_Token_String(tokens, "DATA");
01432 Append_And_Reclaim_Token_List(tokens, &lhs_tokens);
01433 Append_Token_Special(tokens, '/');
01434 Append_And_Reclaim_Token_List(tokens, &rhs_tokens);
01435 Append_Token_Special(tokens, '/');
01436 }
01437
01438
01439 void
01440 PARAMETER2F_translate(TOKEN_BUFFER tokens, INITO_IDX inito)
01441 {
01442
01443
01444
01445
01446
01447 TOKEN_BUFFER lhs_tokens = New_Token_Buffer();
01448 TOKEN_BUFFER rhs_tokens = New_Token_Buffer();
01449 UINT initv_idx = 0;
01450 UINT initv_times = 0;
01451 TY_IDX object_ty = ST_type(INITO_st(inito));
01452 STAB_OFFSET object_ofst = 0;
01453 INITV_IDX *initv_array;
01454
01455 ASSERT_DBG_FATAL(!TY_Is_Structured(object_ty) ||
01456 Stab_Is_Common_Block(INITO_st(inito)) ||
01457 Stab_Is_Equivalence_Block(INITO_st(inito)),
01458 (DIAG_W2F_UNEXPECTED_SYMBOL, "INITO2F_translate"));
01459
01460
01461
01462
01463
01464
01465
01466
01467 initv_array = INIT2F_Get_Initv_Array(INITO_st(inito), inito);
01468
01469
01470
01471
01472
01473 INIT2F_translate(lhs_tokens,
01474 rhs_tokens,
01475 INITO_st(inito),
01476 0,
01477 &object_ofst,
01478 object_ty,
01479 initv_array,
01480 &initv_idx,
01481 &initv_times);
01482
01483
01484
01485 FREE(initv_array);
01486 Append_F77_Indented_Newline(tokens, 1, NULL);
01487 Append_Token_String(tokens, "PARAMETER (");
01488 Append_Token_String(tokens, ST_name(INITO_st(inito)));
01489 Append_Token_Special(tokens, '=');
01490 if (TY_Is_Structured(object_ty)) {
01491 Append_Token_String(tokens,W2CF_Symtab_Nameof_Ty(object_ty));
01492 Append_Token_Special(tokens,'(');
01493 }
01494 else
01495 Append_Token_String(tokens, "(/");
01496 Append_And_Reclaim_Token_List(tokens, &rhs_tokens);
01497 if (!TY_Is_Structured(object_ty))
01498 Append_Token_Special(tokens,'/');
01499 Append_Token_String(tokens, "))");
01500 }
01501
01502