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 extern "C"{
00058 #include "gspin-wgen-interface.h"
00059 }
00060 #if defined(BUILD_OS_DARWIN)
00061 #include <limits.h>
00062 #else
00063 #include <values.h>
00064 #endif
00065 #include "defs.h"
00066 #include "errors.h"
00067
00068 #include "symtab.h"
00069 #include "strtab.h"
00070 #include "wn.h"
00071 #include "wgen_expr.h"
00072 #include "wgen_decl.h"
00073 #include "wgen_misc.h"
00074 #include "wgen_dst.h"
00075 #include "ir_reader.h"
00076 #include "wgen_spin_symbol.h"
00077 #include "wgen_stmt.h"
00078 #include <map>
00079 #include "erfe.h"
00080 #ifdef TARG_X8664
00081 #include <ctype.h>
00082 #endif
00083
00084
00085 #include <ext/hash_set>
00086 using __gnu_cxx::hash_set;
00087 typedef struct {
00088 size_t operator()(void* p) const { return reinterpret_cast<size_t>(p); }
00089 } void_ptr_hash;
00090
00091 extern int pstatic_as_global;
00092 extern BOOL flag_no_common;
00093 extern gs_t decl_arguments;
00094
00095 extern void Push_Deferred_Function(gs_t);
00096 extern char *WGEN_Tree_Node_Name(gs_t op);
00097
00098 #ifdef KEY
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111 BOOL processing_function_prototype = FALSE;
00112 #endif
00113
00114
00115 std::multimap<gs_t, gs_t> duplicate_of;
00116 void
00117 add_duplicates (gs_t newdecl, gs_t olddecl)
00118 {
00119 duplicate_of.insert (pair<gs_t, gs_t>(newdecl, olddecl));
00120 duplicate_of.insert (pair<gs_t, gs_t>(olddecl, newdecl));
00121 }
00122
00123
00124 void
00125 erase_duplicates (gs_t decl)
00126 {
00127 int i, j;
00128 int count = duplicate_of.count (decl);
00129
00130 for (i=0; i<count; i++) {
00131 std::multimap<gs_t, gs_t>::iterator iter = duplicate_of.find(decl);
00132 gs_t t = (*iter).second;
00133
00134
00135 int count2 = duplicate_of.count(t);
00136 for (j=0; j<count2; j++) {
00137 std::multimap<gs_t, gs_t>::iterator iter2 = duplicate_of.find(t);
00138 gs_t t2 = (*iter2).second;
00139 if (t2 == decl) {
00140 duplicate_of.erase (iter2);
00141 }
00142 }
00143
00144
00145 duplicate_of.erase (iter);
00146 }
00147 }
00148
00149 static ST*
00150 get_duplicate_st (gs_t decl)
00151 {
00152 int count = duplicate_of.count (decl);
00153
00154 for (int i=0; i<count; ++i) {
00155 std::multimap<gs_t, gs_t>::iterator iter = duplicate_of.find(decl);
00156 gs_t t = (*iter).second;
00157
00158
00159 if (gs_tree_code(t) == GS_FUNCTION_DECL &&
00160 gs_decl_name(t) == gs_decl_name(decl) &&
00161 gs_decl_assembler_name_set_p(t) == gs_decl_assembler_name_set_p(decl) &&
00162 (!gs_decl_assembler_name_set_p(t) ||
00163 gs_decl_assembler_name(t) == gs_decl_assembler_name(decl))) {
00164
00165 ST *st = DECL_ST(t);
00166 if (st != NULL)
00167 return st;
00168 }
00169 duplicate_of.erase (iter);
00170 }
00171 return NULL;
00172 }
00173
00174 static char*
00175 Get_Name (gs_t node)
00176 {
00177 static UINT anon_num = 0;
00178 static char buf[64];
00179
00180 if (node == NULL) {
00181 ++anon_num;
00182 sprintf(buf, ".anonymous.%d", anon_num);
00183 return buf;
00184 }
00185 else if (gs_tree_code (node) == GS_IDENTIFIER_NODE)
00186 return ((char *) gs_identifier_pointer (node));
00187 else if (gs_tree_code (node) == GS_TYPE_DECL)
00188
00189 #ifdef FE_GNU_4_2_0 // bug 14137
00190 if (gs_decl_name(node) == NULL) {
00191 ++anon_num;
00192 sprintf(buf, ".anonymous.%d", anon_num);
00193 return buf;
00194 }
00195 else
00196 #endif
00197 return ((char *) gs_identifier_pointer (gs_decl_name (node)));
00198 else
00199 FmtAssert(FALSE, ("Get_Name unexpected tree"));
00200 return NULL;
00201 }
00202
00203 static void
00204 dump_field(gs_t field)
00205 {
00206 printf("%s: ", Get_Name(gs_decl_name(field)));
00207 printf("%d\n", DECL_FIELD_ID(field));
00208 }
00209
00210
00211
00212
00213
00214
00215
00216 gs_t
00217 get_first_real_or_virtual_field (gs_t type_tree)
00218 {
00219
00220
00221
00222 if (lang_cplus && gs_type_fields(type_tree) && gs_type_vfield(type_tree))
00223 return gs_type_vfield(type_tree);
00224
00225 return gs_type_fields(type_tree);
00226 }
00227
00228 gs_t
00229 get_virtual_field (gs_t type_tree)
00230 {
00231 gs_t vfield;
00232
00233
00234 if (lang_cplus &&
00235 gs_type_fields(type_tree) &&
00236 (vfield = gs_type_vfield(type_tree)) != NULL)
00237 return vfield;
00238 return NULL;
00239 }
00240
00241 gs_t
00242 get_first_real_field (gs_t type_tree)
00243 {
00244 gs_t field = gs_type_fields(type_tree);
00245
00246 if (!field)
00247 return NULL;
00248
00249
00250
00251 if (field == gs_type_vfield(type_tree))
00252 {
00253 Is_True (lang_cplus, ("get_first_real_field: TYPE_VFIELD used for C"));
00254 return gs_tree_chain(field);
00255 }
00256 return field;
00257 }
00258
00259 gs_t
00260 next_real_field (gs_t type_tree, gs_t field)
00261 {
00262 BOOL first_real_field = FALSE;
00263
00264 if (field == gs_type_vfield(type_tree))
00265 {
00266 #if 0 // bug 13102
00267 Is_True (lang_cplus, ("next_real_field: TYPE_VFIELD used for C"));
00268 #endif
00269 first_real_field = TRUE;
00270 }
00271
00272
00273 if (first_real_field && field != gs_type_fields (type_tree))
00274 return gs_type_fields (type_tree);
00275
00276
00277 return gs_tree_chain (field);
00278 }
00279
00280 static void
00281 Do_Base_Types (gs_t type_tree)
00282 {
00283 gs_t binfo = gs_type_binfo(type_tree);
00284 gs_t basetypes = binfo ? gs_binfo_base_binfos(binfo) : 0;
00285 gs_t list;
00286 if (basetypes) {
00287 for (list = basetypes; gs_code(list) != EMPTY; list = gs_operand(list, 1))
00288 (void) Get_TY (gs_binfo_type(gs_operand(list, 0)));
00289 }
00290 }
00291
00292 size_t
00293 Roundup (size_t offset, int alignment)
00294 {
00295 return (offset % alignment) ? offset + alignment - offset % alignment
00296 : offset;
00297 }
00298
00299 size_t
00300 Type_Size_Without_Vbases (gs_t type_tree)
00301 {
00302 gs_t field;
00303 gs_t last_field_decl = 0;
00304
00305 for (field = get_first_real_or_virtual_field(type_tree);
00306 field;
00307 field = next_real_field (type_tree, field)) {
00308 if (gs_tree_code(field) == GS_FIELD_DECL)
00309 last_field_decl = field;
00310 }
00311
00312 if (last_field_decl == 0)
00313 return 0;
00314
00315 return
00316 gs_get_integer_value (gs_decl_field_offset(last_field_decl)) +
00317 gs_get_integer_value (gs_decl_field_bit_offset(last_field_decl)) / BITSPERBYTE +
00318 gs_get_integer_value (gs_decl_size(last_field_decl)) / BITSPERBYTE;
00319 }
00320
00321 bool
00322 is_empty_base_class (gs_t type_tree)
00323 {
00324 gs_t field = gs_type_fields(type_tree);
00325 return gs_tree_code(field) == GS_TYPE_DECL && gs_tree_chain(field) == 0;
00326 }
00327
00328
00329 gs_t
00330 lookup_attribute(char *attr_name, gs_t attr_list)
00331 {
00332 gs_t nd;
00333 for (nd = attr_list; nd; nd = gs_tree_chain(nd)) {
00334 Is_True(gs_tree_code(nd) == GS_TREE_LIST,
00335 ("lookup_attributes: TREE_LIST node not found"));
00336 gs_t attr = gs_tree_purpose(nd);
00337 if (is_attribute(attr_name, attr))
00338 return nd;
00339 }
00340 return NULL;
00341 }
00342
00343
00344 extern TY_IDX
00345 Create_TY_For_Tree (gs_t type_tree, TY_IDX idx)
00346 {
00347
00348 if(gs_tree_code(type_tree) == GS_ERROR_MARK)
00349 return idx;
00350
00351 TY_IDX orig_idx = idx;
00352 if(gs_tree_code_class(type_tree) != GS_TCC_TYPE) {
00353 DevWarn("Bad tree class passed to Create_TY_For_Tree %c",
00354 gs_tree_code_class(type_tree));
00355 return idx;
00356 }
00357
00358
00359 #ifdef KEY
00360 UINT align = gs_type_align(type_tree) / BITSPERBYTE;
00361 #endif
00362
00363 if (gs_type_name(type_tree) &&
00364 idx == 0 &&
00365 (gs_tree_code(type_tree) == GS_RECORD_TYPE ||
00366 gs_tree_code(type_tree) == GS_UNION_TYPE) &&
00367 gs_tree_code(gs_type_name(type_tree)) == GS_TYPE_DECL &&
00368 gs_type_main_variant(type_tree) != type_tree) {
00369 idx = Get_TY (gs_type_main_variant(type_tree));
00370 if (gs_type_readonly(type_tree))
00371 Set_TY_is_const (idx);
00372 if (gs_type_volatile(type_tree))
00373 Set_TY_is_volatile (idx);
00374 #ifdef KEY
00375 if (gs_type_restrict(type_tree))
00376 Set_TY_is_restrict (idx);
00377 Set_TY_align (idx, align);
00378 #endif
00379 TYPE_TY_IDX(type_tree) = idx;
00380 if(Debug_Level >= 2) {
00381 #ifdef KEY // bug 11782
00382 defer_DST_type(type_tree, idx, orig_idx);
00383 #else
00384 DST_INFO_IDX dst = Create_DST_type_For_Tree(type_tree,
00385 idx,orig_idx);
00386 TYPE_DST_IDX(type_tree) = dst;
00387 #endif
00388 }
00389 TYPE_FIELD_IDS_USED(type_tree) =
00390 TYPE_FIELD_IDS_USED(gs_type_main_variant(type_tree));
00391 return idx;
00392 }
00393
00394 TYPE_ID mtype;
00395 INT64 tsize;
00396 BOOL variable_size = FALSE;
00397 gs_t type_size = gs_type_size(type_tree);
00398 #ifndef KEY
00399 UINT align = gs_type_align(type_tree) / BITSPERBYTE;
00400 #endif
00401 if (type_size == NULL) {
00402
00403
00404 FmtAssert(gs_tree_code(type_tree) == GS_ARRAY_TYPE
00405 || gs_tree_code(type_tree) == GS_ENUMERAL_TYPE
00406 || gs_tree_code(type_tree) == GS_UNION_TYPE
00407 || gs_tree_code(type_tree) == GS_RECORD_TYPE
00408 || gs_tree_code(type_tree) == GS_LANG_TYPE
00409 || gs_tree_code(type_tree) == GS_FUNCTION_TYPE
00410 || gs_tree_code(type_tree) == GS_VOID_TYPE,
00411 ("Create_TY_For_Tree: type_size NULL for non ARRAY/RECORD/VOID, type is %d",
00412 (int) gs_tree_code(type_tree)));
00413 tsize = 0;
00414 }
00415 else {
00416 if (gs_tree_code(type_size) != GS_INTEGER_CST) {
00417 if (gs_tree_code(type_tree) == GS_ARRAY_TYPE)
00418 DevWarn ("Encountered VLA at line %d", lineno);
00419 else
00420 #ifndef KEY
00421 Fail_FmtAssertion ("VLA at line %d not currently implemented", lineno);
00422 #else
00423
00424 {
00425
00426 printf("pathcc: variable-length structure not yet implemented\n");
00427 exit(2);
00428 }
00429 #endif
00430 variable_size = TRUE;
00431 tsize = 0;
00432 }
00433 else
00434 #ifdef KEY // bug 3045
00435 tsize = (gs_get_integer_value(type_size) + BITSPERBYTE - 1)
00436 / BITSPERBYTE;
00437 #else
00438 tsize = gs_get_integer_value(type_size) / BITSPERBYTE;
00439 #endif
00440 }
00441 switch (gs_tree_code(type_tree)) {
00442 case GS_VOID_TYPE:
00443 case GS_LANG_TYPE:
00444 idx = MTYPE_To_TY (MTYPE_V);
00445 break;
00446 case GS_BOOLEAN_TYPE:
00447 case GS_INTEGER_TYPE:
00448 case GS_OFFSET_TYPE:
00449 switch (tsize) {
00450 case 1: mtype = MTYPE_I1; break;
00451 case 2: mtype = MTYPE_I2; break;
00452 case 4: mtype = MTYPE_I4; break;
00453 case 8: mtype = MTYPE_I8; break;
00454 #if !defined(TARG_X8664) && !defined(TARG_MIPS) // Bug 12358
00455 #ifdef _LP64
00456 case 16: mtype = MTYPE_I8; break;
00457 #endif
00458 #else
00459
00460
00461
00462
00463 case 16: mtype = MTYPE_I8; break;
00464 #endif
00465 default: FmtAssert(FALSE,
00466 ("Get_TY unexpected size %d", tsize));
00467 }
00468 if (gs_decl_unsigned(type_tree)) {
00469 mtype = MTYPE_complement(mtype);
00470 }
00471 #ifdef KEY
00472 if (lookup_attribute("may_alias",gs_type_attributes(type_tree)))
00473 {
00474
00475
00476 TY &ty = New_TY (idx);
00477 TY_Init (ty, tsize, KIND_SCALAR, mtype,
00478 Save_Str(Get_Name(gs_type_name(type_tree))) );
00479 Set_TY_no_ansi_alias (ty);
00480 } else
00481 #endif
00482 idx = MTYPE_To_TY (mtype);
00483 #ifdef TARG_X8664
00484
00485
00486
00487 if( TARGET_64BIT )
00488 #endif // TARG_X8664
00489 Set_TY_align (idx, align);
00490 break;
00491 case GS_CHAR_TYPE:
00492 mtype = (gs_decl_unsigned(type_tree) ? MTYPE_U1 : MTYPE_I1);
00493 idx = MTYPE_To_TY (mtype);
00494 break;
00495 case GS_ENUMERAL_TYPE:
00496 #ifdef KEY
00497 switch (tsize) {
00498 case 1:
00499 mtype = (gs_decl_unsigned(type_tree) ? MTYPE_U1 :
00500 MTYPE_I1);
00501 break;
00502 case 2:
00503 mtype = (gs_decl_unsigned(type_tree) ? MTYPE_U2 :
00504 MTYPE_I2);
00505 break;
00506 case 8:
00507 mtype = (gs_decl_unsigned(type_tree) ? MTYPE_U8 :
00508 MTYPE_I8);
00509 break;
00510 default:
00511 mtype = (gs_decl_unsigned(type_tree) ? MTYPE_U4 :
00512 MTYPE_I4);
00513 }
00514 #else
00515 mtype = (gs_decl_unsigned(type_tree) ? MTYPE_U4 : MTYPE_I4);
00516 #endif
00517 idx = MTYPE_To_TY (mtype);
00518 break;
00519 case GS_REAL_TYPE:
00520 switch (tsize) {
00521 case 4: mtype = MTYPE_F4; break;
00522 case 8: mtype = MTYPE_F8; break;
00523 #ifdef TARG_IA64
00524 case 12:
00525 case 16: mtype = MTYPE_F10; break;
00526 #endif
00527 #ifdef TARG_X8664
00528 case 12: mtype = MTYPE_FQ; break;
00529 #endif
00530 #if defined(TARG_MIPS) || defined(TARG_IA32) || defined(TARG_X8664)
00531 case 16: mtype = MTYPE_FQ; break;
00532 #endif
00533 default: FmtAssert(FALSE, ("Get_TY unexpected size"));
00534 }
00535 idx = MTYPE_To_TY (mtype);
00536 break;
00537 case GS_COMPLEX_TYPE:
00538 switch (tsize) {
00539 case 2:
00540 case 4: ErrMsg (EC_Unsupported_Type, "Complex integer");
00541 case 8: mtype = MTYPE_C4; break;
00542 case 16: mtype = MTYPE_C8; break;
00543 #ifdef TARG_IA64
00544 case 32: mtype = MTYPE_C10; break;
00545 #endif
00546 #ifdef TARG_X8664
00547 case 24: mtype = MTYPE_CQ; break;
00548 #endif
00549 #if defined(TARG_MIPS) || defined(TARG_IA32) || defined(TARG_X8664)
00550 case 32: mtype = MTYPE_CQ; break;
00551 #endif
00552 default: FmtAssert(FALSE, ("Get_TY unexpected size"));
00553 }
00554 idx = MTYPE_To_TY (mtype);
00555 break;
00556 case GS_POINTER_TYPE:
00557 if (gs_type_ptrmem_p(type_tree)) {
00558
00559 idx = Be_Type_Tbl(Pointer_Size == 8 ? MTYPE_I8 : MTYPE_I4);
00560 break;
00561 }
00562
00563 case GS_REFERENCE_TYPE:
00564 idx = Make_Pointer_Type (Get_TY (gs_tree_type(type_tree)));
00565 Set_TY_align (idx, align);
00566 break;
00567 case GS_ARRAY_TYPE:
00568 {
00569 #ifdef KEY
00570 TY &ty = (idx == TY_IDX_ZERO) ? New_TY(idx) : Ty_Table[idx];
00571 Clear_TY_is_incomplete (idx);
00572 #else
00573 TY &ty = New_TY (idx);
00574 #endif
00575 TY_Init (ty, tsize, KIND_ARRAY, MTYPE_M,
00576 Save_Str(Get_Name(gs_type_name(type_tree))) );
00577
00578 if (gs_type_name(type_tree) == NULL)
00579 Set_TY_anonymous(ty);
00580 Set_TY_etype (ty, Get_TY (gs_tree_type(type_tree)));
00581 Set_TY_align (idx, TY_align(TY_etype(ty)));
00582
00583
00584 ARB_HANDLE arb = New_ARB ();
00585 ARB_Init (arb, 0, 0, 0);
00586 Set_TY_arb (ty, arb);
00587 Set_ARB_first_dimen (arb);
00588 Set_ARB_last_dimen (arb);
00589 Set_ARB_dimension (arb, 1);
00590 if (gs_type_size(gs_tree_type(type_tree)) == 0)
00591 break;
00592
00593
00594 if (gs_tree_code(gs_type_size(gs_tree_type(type_tree))) == GS_INTEGER_CST) {
00595 Set_ARB_const_stride (arb);
00596 Set_ARB_stride_val (arb,
00597 gs_get_integer_value (gs_type_size(gs_tree_type(type_tree)))
00598 / BITSPERBYTE);
00599 }
00600 #ifdef KEY
00601 else if (!expanding_function_definition &&
00602 processing_function_prototype)
00603 {
00604 Set_ARB_const_stride (arb);
00605
00606 Set_ARB_stride_val (arb, 4);
00607 Set_TY_is_incomplete (idx);
00608 }
00609 #endif
00610 else {
00611 WN *swn;
00612 swn = WGEN_Expand_Expr (gs_type_size(gs_tree_type(type_tree)));
00613 if (WN_opcode (swn) == OPC_U4I4CVT ||
00614 WN_opcode (swn) == OPC_U8I8CVT) {
00615 swn = WN_kid0 (swn);
00616 }
00617 #ifdef KEY
00618
00619
00620
00621
00622 if (WN_operator (swn) != OPR_LDID) {
00623 TY_IDX ty_idx =
00624 Get_TY (gs_tree_type (type_size));
00625 TYPE_ID mtype = TY_mtype (ty_idx);
00626 ST *st;
00627 st = Gen_Temp_Symbol (ty_idx, "__save_expr");
00628 #ifdef FE_GNU_4_2_0
00629 WGEN_add_pragma_to_enclosing_regions (WN_PRAGMA_LOCAL, st);
00630 #endif
00631 WGEN_Set_ST_Addr_Saved (swn);
00632 swn = WN_Stid (mtype, 0, st, ty_idx, swn);
00633 WGEN_Stmt_Append (swn, Get_Srcpos());
00634 swn = WN_Ldid (mtype, 0, st, ty_idx);
00635 }
00636 #endif
00637 FmtAssert (WN_operator (swn) == OPR_LDID,
00638 ("stride operator for VLA not LDID"));
00639 ST *st = WN_st (swn);
00640 TY_IDX ty_idx = ST_type (st);
00641 WN *wn = WN_CreateXpragma (WN_PRAGMA_COPYIN_BOUND,
00642 (ST_IDX) NULL, 1);
00643 WN_kid0 (wn) = WN_Ldid (TY_mtype (ty_idx), 0, st, ty_idx);
00644 WGEN_Stmt_Append (wn, Get_Srcpos());
00645 Clear_ARB_const_stride (arb);
00646 Set_ARB_stride_var (arb, (ST_IDX) ST_st_idx (st));
00647 #ifdef KEY
00648 Clear_TY_is_incomplete (idx);
00649 #endif
00650 }
00651
00652
00653 Set_ARB_const_lbnd (arb);
00654 Set_ARB_lbnd_val (arb, 0);
00655
00656
00657 if (type_size) {
00658 #ifdef KEY
00659
00660 if (!gs_type_max_value (gs_type_domain (type_tree))) {
00661 Set_ARB_const_ubnd (arb);
00662 Set_ARB_ubnd_val (arb, 0xffffffff);
00663 } else
00664 #endif
00665 if (gs_tree_code(gs_type_max_value (gs_type_domain (type_tree))) ==
00666 GS_INTEGER_CST) {
00667 Set_ARB_const_ubnd (arb);
00668 Set_ARB_ubnd_val (arb, gs_get_integer_value (
00669 gs_type_max_value (gs_type_domain (type_tree)) ));
00670 }
00671 #ifdef KEY
00672 else if (!expanding_function_definition &&
00673 processing_function_prototype) {
00674 Set_ARB_const_ubnd (arb);
00675
00676 Set_ARB_ubnd_val (arb, 8);
00677 Set_TY_is_incomplete (idx);
00678 }
00679 #endif
00680 else {
00681 WN *uwn = WGEN_Expand_Expr (gs_type_max_value (gs_type_domain (type_tree)) );
00682 if (WN_opcode (uwn) == OPC_U4I4CVT ||
00683 WN_opcode (uwn) == OPC_U8I8CVT) {
00684 uwn = WN_kid0 (uwn);
00685 }
00686 ST *st;
00687 TY_IDX ty_idx;
00688 WN *wn;
00689 if (WN_operator (uwn) != OPR_LDID) {
00690 ty_idx = Get_TY (gs_tree_type (gs_type_max_value (gs_type_domain (type_tree)) ) );
00691 st = Gen_Temp_Symbol (ty_idx, "__vla_bound");
00692 #ifdef FE_GNU_4_2_0
00693 WGEN_add_pragma_to_enclosing_regions (WN_PRAGMA_LOCAL, st);
00694 #endif
00695 wn = WN_Stid (TY_mtype (ty_idx), 0, st, ty_idx, uwn);
00696 WGEN_Stmt_Append (wn, Get_Srcpos());
00697 }
00698 else {
00699 st = WN_st (uwn);
00700 ty_idx = ST_type (st);
00701 }
00702 wn = WN_CreateXpragma (WN_PRAGMA_COPYIN_BOUND, (ST_IDX) NULL, 1);
00703 WN_kid0 (wn) = WN_Ldid (TY_mtype (ty_idx), 0, st, ty_idx);
00704 WGEN_Stmt_Append (wn, Get_Srcpos());
00705 Clear_ARB_const_ubnd (arb);
00706 Set_ARB_ubnd_var (arb, ST_st_idx (st));
00707 #ifdef KEY
00708 Clear_TY_is_incomplete (idx);
00709 #endif
00710 }
00711 }
00712 else {
00713 Clear_ARB_const_ubnd (arb);
00714 Set_ARB_ubnd_val (arb, 0);
00715 }
00716
00717
00718 if (variable_size) {
00719 #ifdef KEY
00720 if (!expanding_function_definition &&
00721 processing_function_prototype) {
00722 Set_TY_is_incomplete (idx);
00723 }
00724 else
00725 #endif
00726 {
00727 WN *swn, *wn;
00728 swn = WGEN_Expand_Expr (type_size);
00729 if (TY_size(TY_etype(ty))) {
00730 if (WN_opcode (swn) == OPC_U4I4CVT ||
00731 WN_opcode (swn) == OPC_U8I8CVT) {
00732 swn = WN_kid0 (swn);
00733 }
00734 #ifdef KEY
00735
00736
00737
00738
00739 if (WN_operator (swn) != OPR_LDID) {
00740 TY_IDX ty_idx =
00741 Get_TY (gs_tree_type (type_size));
00742 TYPE_ID mtype = TY_mtype (ty_idx);
00743 ST *st;
00744 st = Gen_Temp_Symbol (ty_idx, "__save_expr");
00745 #ifdef FE_GNU_4_2_0
00746 WGEN_add_pragma_to_enclosing_regions (WN_PRAGMA_LOCAL, st);
00747 #endif
00748 WGEN_Set_ST_Addr_Saved (swn);
00749 swn = WN_Stid (mtype, 0, st, ty_idx, swn);
00750 WGEN_Stmt_Append (swn, Get_Srcpos());
00751 swn = WN_Ldid (mtype, 0, st, ty_idx);
00752 }
00753 #endif
00754 FmtAssert (WN_operator (swn) == OPR_LDID,
00755 ("size operator for VLA not LDID"));
00756 ST *st = WN_st (swn);
00757 TY_IDX ty_idx = ST_type (st);
00758 TYPE_ID mtype = TY_mtype (ty_idx);
00759 swn = WN_Div (mtype, swn, WN_Intconst (mtype, BITSPERBYTE));
00760 wn = WN_Stid (mtype, 0, st, ty_idx, swn);
00761 WGEN_Stmt_Append (wn, Get_Srcpos());
00762 }
00763 #ifdef KEY
00764 Clear_TY_is_incomplete (idx);
00765 #endif
00766 }
00767 }
00768 }
00769 break;
00770 case GS_RECORD_TYPE:
00771 case GS_UNION_TYPE:
00772 {
00773
00774 TY &ty = (idx == TY_IDX_ZERO) ? New_TY(idx) : Ty_Table[idx];
00775 #ifdef KEY
00776
00777
00778 if (Debug_Level >= 2)
00779 defer_DST_type(type_tree, idx, orig_idx);
00780
00781
00782
00783 if (tsize != 0 &&
00784
00785
00786 gs_type_lang_specific(type_tree) &&
00787
00788 gs_classtype_as_base(type_tree) &&
00789 gs_classtype_size(type_tree) &&
00790 gs_is_empty_class(type_tree))
00791 tsize = 0;
00792 #endif // KEY
00793 TY_Init (ty, tsize, KIND_STRUCT, MTYPE_M,
00794 Save_Str(Get_Name(gs_type_name(type_tree))) );
00795
00796 if (gs_type_name(type_tree) == NULL)
00797 Set_TY_anonymous(ty);
00798
00799 if (gs_tree_code(type_tree) == GS_UNION_TYPE) {
00800 Set_TY_is_union(idx);
00801 }
00802 #ifdef KEY
00803 if (gs_aggregate_value_p(type_tree)) {
00804 Set_TY_return_in_mem(idx);
00805 }
00806 #endif
00807 if (align == 0) align = 1;
00808 Set_TY_align (idx, align);
00809
00810 TYPE_TY_IDX(type_tree) = idx;
00811 Do_Base_Types (type_tree);
00812
00813
00814
00815 for (gs_t field = get_first_real_or_virtual_field (type_tree);
00816 field;
00817 field = next_real_field(type_tree, field)) {
00818 Set_TY_content_seen(idx);
00819 if (gs_tree_code(field) == GS_TYPE_DECL ||
00820 gs_tree_code(field) == GS_FIELD_DECL) {
00821 gs_t field_type = gs_tree_type(field);
00822 if ((gs_tree_code(field_type) == GS_RECORD_TYPE ||
00823 gs_tree_code(field_type) == GS_UNION_TYPE) &&
00824 field_type != type_tree) {
00825 #ifdef KEY
00826
00827
00828
00829
00830 if (gs_tree_code(field) == GS_TYPE_DECL)
00831 defer_decl(field_type);
00832 else
00833 #endif
00834 Get_TY(field_type);
00835 }
00836 }
00837 #ifdef KEY // Defer expansion of static vars until all the fields in
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855 else if (gs_tree_code(field) == GS_VAR_DECL)
00856 defer_decl(field);
00857 #else
00858 else if (gs_tree_code(field) == GS_VAR_DECL)
00859 WGEN_Expand_Decl(field, TRUE);
00860 #endif
00861 else if (gs_tree_code(field) == GS_TEMPLATE_DECL)
00862 WGEN_Expand_Decl(field, TRUE);
00863 }
00864
00865 Set_TY_fld (ty, FLD_HANDLE());
00866 FLD_IDX first_field_idx = Fld_Table.Size ();
00867 gs_t field;
00868 gs_t method = gs_type_methods(type_tree);
00869 FLD_HANDLE fld;
00870 INT32 next_field_id = 1;
00871
00872 #ifdef KEY
00873
00874
00875
00876
00877
00878 gs_t vfield = get_virtual_field(type_tree);
00879 if (vfield) {
00880 Is_True(gs_tree_code(vfield) == GS_FIELD_DECL,
00881 ("Create_TY_For_Tree: bad vfield code"));
00882 Is_True(gs_decl_name(vfield) &&
00883 !strncmp(Get_Name(gs_decl_name(vfield)),"_vptr", 5),
00884 ("Create_TY_For_Tree: bad vfield name"));
00885
00886 Is_True(DECL_FIELD_ID(vfield) <= 1,
00887 ("Create_TY_For_Tree: invalid vfield field ID"));
00888
00889 DECL_FIELD_ID(vfield) = next_field_id;
00890 next_field_id += TYPE_FIELD_IDS_USED(gs_tree_type(vfield)) +1;
00891 fld = New_FLD ();
00892 FLD_Init(fld, Save_Str(Get_Name(gs_decl_name(vfield))),
00893 0,
00894 gs_get_integer_value(gs_decl_field_offset(vfield))
00895 + gs_get_integer_value(gs_decl_field_bit_offset(vfield))
00896 / BITSPERBYTE);
00897 }
00898 #endif
00899
00900
00901
00902
00903 INT32 offset = 0;
00904 INT32 anonymous_fields = 0;
00905 #ifndef KEY // g++'s class.c already laid out the base types. Bug 11622.
00906 gs_t type_binfo, basetypes;
00907 if ((type_binfo = gs_type_binfo(type_tree)) != NULL &&
00908 (basetypes = gs_binfo_base_binfos(type_binfo)) != NULL) {
00909 gs_t list;
00910 for (list = basetypes; gs_code(list) != EMPTY;
00911 list = gs_operand(list, 1)) {
00912 gs_t binfo = gs_operand(list, 0);
00913 gs_t basetype = gs_binfo_type(binfo);
00914 offset = Roundup (offset,
00915 gs_type_align(basetype) / BITSPERBYTE);
00916 if (!is_empty_base_class(basetype) ||
00917 !gs_binfo_virtual_p(binfo)) {
00918 ++next_field_id;
00919 ++anonymous_fields;
00920 next_field_id += TYPE_FIELD_IDS_USED(basetype);
00921 fld = New_FLD();
00922 FLD_Init (fld, Save_Str(Get_Name(0)),
00923 Get_TY(basetype), offset);
00924 offset += Type_Size_Without_Vbases (basetype);
00925 Set_FLD_is_anonymous(fld);
00926 #ifdef KEY
00927
00928
00929
00930
00931
00932 if (offset > tsize)
00933 {
00934 tsize = offset;
00935 Set_TY_size (ty, tsize);
00936 }
00937 #endif // KEY
00938 }
00939 }
00940 }
00941 #endif // KEY
00942
00943 hash_set <gs_t, void_ptr_hash> anonymous_base;
00944 gs_t type_binfo, basetypes;
00945
00946
00947 if ((type_binfo = gs_type_binfo(type_tree)) != NULL &&
00948 (basetypes = gs_binfo_base_binfos(type_binfo)) != NULL) {
00949 gs_t list;
00950 for (list = basetypes; gs_code(list) != EMPTY;
00951 list = gs_operand(list, 1)) {
00952 gs_t binfo = gs_operand(list, 0);
00953 gs_t basetype = gs_binfo_type(binfo);
00954 anonymous_base.insert(basetype);
00955 }
00956 }
00957
00958
00959
00960 for (field = get_first_real_field(type_tree);
00961 field;
00962 field = next_real_field(type_tree, field) )
00963 {
00964 if (gs_tree_code(field) == GS_TYPE_DECL) {
00965 continue;
00966 }
00967 if (gs_tree_code(field) == GS_CONST_DECL) {
00968 DevWarn ("got CONST_DECL in field list");
00969 continue;
00970 }
00971 if (gs_tree_code(field) == GS_VAR_DECL) {
00972 continue;
00973 }
00974 if (gs_tree_code(field) == GS_TEMPLATE_DECL) {
00975 continue;
00976 }
00977
00978
00979
00980
00981
00982 Is_True(DECL_FIELD_ID(field) == 0 ||
00983 DECL_FIELD_ID(field) == next_field_id,
00984 ("Create_TY_For_Tree: field ID already set"));
00985
00986 DECL_FIELD_ID(field) = next_field_id;
00987 next_field_id +=
00988 TYPE_FIELD_IDS_USED(gs_tree_type(field)) + 1;
00989 fld = New_FLD ();
00990 FLD_Init (fld, Save_Str(Get_Name(gs_decl_name(field))),
00991 0,
00992 gs_get_integer_value(gs_decl_field_offset(field)) +
00993 gs_get_integer_value(gs_decl_field_bit_offset(field))
00994 / BITSPERBYTE);
00995 if (gs_decl_name(field) == NULL)
00996 Set_FLD_is_anonymous(fld);
00997 if (anonymous_base.find(gs_tree_type(field)) != anonymous_base.end())
00998 Set_FLD_is_base_class(fld);
00999 }
01000
01001 TYPE_FIELD_IDS_USED(type_tree) = next_field_id - 1;
01002 FLD_IDX last_field_idx = Fld_Table.Size () - 1;
01003 if (last_field_idx >= first_field_idx) {
01004 Set_TY_fld (ty, FLD_HANDLE (first_field_idx));
01005 Set_FLD_last_field (FLD_HANDLE (last_field_idx));
01006 }
01007
01008
01009 fld = TY_fld(ty);
01010 #ifdef KEY
01011
01012 if (vfield) {
01013 Is_True(gs_tree_code(gs_tree_type(vfield)) == GS_POINTER_TYPE,
01014 ("Create_TY_For_Tree: vtable ptr should be GS_POINTER_TYPE"));
01015
01016
01017
01018
01019 fld = TY_fld(ty);
01020 TY_IDX p_idx = Make_Pointer_Type(MTYPE_To_TY(MTYPE_U8),FALSE);
01021 Set_FLD_type(fld, p_idx);
01022 defer_field(vfield, fld);
01023 fld = FLD_next(fld);
01024 }
01025 #endif
01026
01027
01028 while (anonymous_fields--)
01029 fld = FLD_next(fld);
01030
01031 for (field = get_first_real_field(type_tree);
01032
01033
01034 field && fld.Entry();
01035 field = next_real_field(type_tree, field))
01036 {
01037 #ifdef KEY
01038 const int FLD_BIT_FIELD_SIZE = 64;
01039 #endif
01040 if (gs_tree_code(field) == GS_TYPE_DECL)
01041 continue;
01042 if (gs_tree_code(field) == GS_CONST_DECL)
01043 continue;
01044 if (gs_tree_code(field) == GS_VAR_DECL)
01045 continue;
01046 if (gs_tree_code(field) == GS_TEMPLATE_DECL)
01047 continue;
01048 #ifdef KEY
01049
01050
01051
01052
01053 if (gs_tree_code(gs_tree_type(field)) == GS_POINTER_TYPE) {
01054
01055
01056 TY_IDX p_idx =
01057 Make_Pointer_Type(MTYPE_To_TY(MTYPE_U8),
01058 FALSE);
01059 Set_FLD_type(fld, p_idx);
01060 defer_field(field, fld);
01061 fld = FLD_next(fld);
01062 continue;
01063 }
01064 #endif
01065 TY_IDX fty_idx = Get_TY(gs_tree_type(field));
01066
01067 if ((TY_align (fty_idx) > align) || (TY_is_packed (fty_idx)))
01068 Set_TY_is_packed (ty);
01069 #if 1 // wgen bug 10470
01070 if (! gs_tree_this_volatile(field))
01071 Clear_TY_is_volatile (fty_idx);
01072 #endif
01073 Set_FLD_type(fld, fty_idx);
01074
01075 if ( ! gs_decl_bit_field(field)
01076 #if 1
01077 && gs_tree_code(gs_tree_type(field)) != GS_RECORD_TYPE
01078 && gs_tree_code(gs_tree_type(field)) != GS_UNION_TYPE
01079 #endif
01080 && gs_decl_size(field)
01081 && gs_get_integer_value(gs_decl_size(field)) > 0
01082 #ifdef KEY
01083
01084
01085 && gs_get_integer_value(gs_decl_size(field)) <=
01086 FLD_BIT_FIELD_SIZE
01087
01088 && TY_size(Get_TY(gs_tree_type(field))) != 0
01089 #endif
01090 && gs_get_integer_value(gs_decl_size(field))
01091 != (TY_size(Get_TY(gs_tree_type(field)))
01092 * BITSPERBYTE) )
01093 {
01094 #ifdef KEY
01095 FmtAssert( gs_get_integer_value(gs_decl_size(field)) <=
01096 FLD_BIT_FIELD_SIZE,
01097 ("field size too big") );
01098 #endif
01099
01100
01101
01102
01103
01104 DevWarn("field size %lld doesn't match type size %lld",
01105 gs_get_integer_value(gs_decl_size(field)),
01106 TY_size(Get_TY(gs_tree_type(field)))
01107 * BITSPERBYTE );
01108 gs_set_decl_bit_field(field, 1);
01109 }
01110 if (gs_decl_bit_field(field)) {
01111 Set_FLD_is_bit_field (fld);
01112
01113 Set_FLD_bofst (fld,
01114 gs_get_integer_value(
01115 gs_decl_field_bit_offset(field))
01116 % BITSPERBYTE);
01117 Set_FLD_bsize (fld, gs_get_integer_value(
01118 gs_decl_size(field)));
01119 }
01120 fld = FLD_next(fld);
01121 }
01122
01123 #ifndef KEY // Don't expand methods by going through TYPE_METHODS,
01124
01125
01126
01127
01128
01129
01130
01131
01132
01133
01134
01135
01136
01137
01138
01139
01140
01141
01142
01143 if (!Enable_WGEN_DFE) {
01144 if (cp_type_quals(type_tree) == TYPE_UNQUALIFIED) {
01145 while (method != NULL_TREE) {
01146 WGEN_Expand_Decl (method, TRUE);
01147 method = TREE_CHAIN(method);
01148 }
01149 }
01150 }
01151 #endif // KEY
01152 }
01153 break;
01154 case GS_METHOD_TYPE:
01155
01156 case GS_FUNCTION_TYPE:
01157 {
01158 gs_t arg;
01159 INT32 num_args, i;
01160 #ifdef KEY
01161 TY &ty = (idx == TY_IDX_ZERO) ? New_TY(idx) : Ty_Table[idx];
01162 Clear_TY_is_incomplete (idx);
01163 #else
01164 TY &ty = New_TY (idx);
01165 #endif
01166 TY_Init (ty, 0, KIND_FUNCTION, MTYPE_UNKNOWN, 0);
01167 Set_TY_align (idx, 1);
01168 TY_IDX ret_ty_idx;
01169 TY_IDX arg_ty_idx;
01170 TYLIST tylist_idx;
01171
01172
01173
01174
01175
01176 ret_ty_idx = Get_TY(gs_tree_type(type_tree));
01177 for (arg = gs_type_arg_types(type_tree);
01178 arg;
01179 arg = gs_tree_chain(arg))
01180 {
01181 arg_ty_idx = Get_TY(gs_tree_value(arg));
01182 #ifdef KEY
01183 if (TY_is_incomplete (arg_ty_idx) ||
01184 (TY_kind(arg_ty_idx) == KIND_POINTER &&
01185 TY_is_incomplete(TY_pointed(arg_ty_idx))))
01186 Set_TY_is_incomplete (idx);
01187 #endif
01188 }
01189
01190
01191
01192 if (!WGEN_Keep_Zero_Length_Structs &&
01193 TY_mtype (ret_ty_idx) == MTYPE_M &&
01194 TY_size (ret_ty_idx) == 0) {
01195
01196 DevWarn ("function returning zero length struct at line %d", lineno);
01197 ret_ty_idx = Be_Type_Tbl (MTYPE_V);
01198 }
01199
01200 #ifdef KEY
01201
01202
01203 if (TY_return_in_mem(ret_ty_idx)) {
01204 ret_ty_idx = Be_Type_Tbl (MTYPE_V);
01205 Set_TY_return_to_param(idx);
01206 }
01207 #endif
01208 Set_TYLIST_type (New_TYLIST (tylist_idx), ret_ty_idx);
01209 Set_TY_tylist (ty, tylist_idx);
01210 for (num_args = 0, arg = gs_type_arg_types(type_tree);
01211 arg;
01212 num_args++, arg = gs_tree_chain(arg))
01213 {
01214 arg_ty_idx = Get_TY(gs_tree_value(arg));
01215 Is_True (!TY_is_incomplete (arg_ty_idx) ||
01216 TY_is_incomplete (idx),
01217 ("Create_TY_For_Tree: unexpected TY flag"));
01218 if (!WGEN_Keep_Zero_Length_Structs &&
01219 TY_mtype (arg_ty_idx) == MTYPE_M &&
01220 TY_size (arg_ty_idx) == 0) {
01221
01222 DevWarn ("zero length struct encountered in function prototype at line %d", lineno);
01223 }
01224 else
01225 Set_TYLIST_type (New_TYLIST (tylist_idx), arg_ty_idx);
01226 }
01227 if (num_args)
01228 {
01229 Set_TY_has_prototype(idx);
01230 if (arg_ty_idx != Be_Type_Tbl(MTYPE_V))
01231 {
01232 Set_TYLIST_type (New_TYLIST (tylist_idx), 0);
01233 Set_TY_is_varargs(idx);
01234 }
01235 else
01236 Set_TYLIST_type (Tylist_Table [tylist_idx], 0);
01237 }
01238 else
01239 Set_TYLIST_type (New_TYLIST (tylist_idx), 0);
01240 #ifdef TARG_X8664
01241 if (!TARGET_64BIT && !TY_is_varargs(idx))
01242 {
01243
01244 if (SSE_Reg_Parm ||
01245 lookup_attribute("sseregparm",
01246 gs_type_attributes(type_tree)))
01247 Set_TY_has_sseregister_parm (idx);
01248 if (gs_t attr = lookup_attribute("regparm",
01249 gs_type_attributes(type_tree)))
01250 {
01251 gs_t value = gs_tree_value (attr);
01252 Is_True (gs_tree_code(value) == GS_TREE_LIST,
01253 ("Expected TREE_LIST"));
01254 value = gs_tree_value (value);
01255 if (gs_tree_code(value) == GS_INTEGER_CST)
01256 Set_TY_register_parm (idx, gs_get_integer_value (value));
01257 }
01258 else if (Reg_Parm_Count)
01259 Set_TY_register_parm (idx, Reg_Parm_Count);
01260 }
01261 #endif
01262 }
01263 break;
01264 #ifdef TARG_X8664
01265
01266 case GS_VECTOR_TYPE:
01267 {
01268 char *p = gs_type_mode(type_tree);
01269 idx = 0;
01270 if (strcmp(p, "BLK") == 0) {
01271 TY_IDX elem_ty = Get_TY(gs_tree_type(type_tree));
01272 TYPE_ID elem_mtype = TY_mtype(elem_ty);
01273 switch (gs_n(gs_type_precision(type_tree))) {
01274 case 2: if (elem_mtype == MTYPE_I4)
01275 idx = MTYPE_To_TY(MTYPE_V8I4);
01276 else if (elem_mtype == MTYPE_F4)
01277 idx = MTYPE_To_TY(MTYPE_V8F4);
01278 else if (elem_mtype == MTYPE_I8)
01279 idx = MTYPE_To_TY(MTYPE_V16I8);
01280 else if (elem_mtype == MTYPE_F8)
01281 idx = MTYPE_To_TY(MTYPE_V16F8);
01282 break;
01283 case 4: if (elem_mtype == MTYPE_I4)
01284 idx = MTYPE_To_TY(MTYPE_V16I4);
01285 else if (elem_mtype == MTYPE_F4)
01286 idx = MTYPE_To_TY(MTYPE_V16F4);
01287 else if (elem_mtype == MTYPE_I2)
01288 idx = MTYPE_To_TY(MTYPE_M8I2);
01289 break;
01290 case 8: if (elem_mtype == MTYPE_I1)
01291 idx = MTYPE_To_TY(MTYPE_M8I1);
01292 else if (elem_mtype == MTYPE_I2)
01293 idx = MTYPE_To_TY(MTYPE_V16I2);
01294 break;
01295 case 16: if (elem_mtype == MTYPE_I1)
01296 idx = MTYPE_To_TY(MTYPE_V16I1);
01297 break;
01298 default:
01299 Fail_FmtAssertion ("Get_TY: unexpected vector type element count");
01300 }
01301 }
01302 else {
01303 if (toupper(*p++) != 'V') {
01304 if (gs_type_name(type_tree)) {
01305 p = gs_identifier_pointer(gs_decl_name(gs_type_name(type_tree)));
01306 if (toupper(*p++) != 'V')
01307 Fail_FmtAssertion("Get_TY: NYI");
01308 }
01309 else Fail_FmtAssertion("Get_TY: NYI");
01310 }
01311 int num_elems = strtol(p, &p, 10);
01312 if (strncasecmp(p, "DI", 2) == 0)
01313 idx = MTYPE_To_TY(MTYPE_V16I8);
01314 else if (strncasecmp(p, "DF", 2) == 0)
01315 idx = MTYPE_To_TY(MTYPE_V16F8);
01316 else if (strncasecmp(p, "SI", 2) == 0) {
01317 if (num_elems == 2)
01318 if ( Is_Target_64bit())
01319 idx = MTYPE_To_TY(MTYPE_V8I4);
01320 else
01321 idx = MTYPE_To_TY(MTYPE_M8I4);
01322 else if (num_elems == 4)
01323 idx = MTYPE_To_TY(MTYPE_V16I4);
01324 }
01325 else if (strncasecmp(p, "SF", 2) == 0) {
01326 if (num_elems == 2)
01327 if ( Is_Target_64bit())
01328 idx = MTYPE_To_TY(MTYPE_V8F4);
01329 else
01330 idx = MTYPE_To_TY(MTYPE_M8F4);
01331 else if (num_elems == 4)
01332 idx = MTYPE_To_TY(MTYPE_V16F4);
01333 }
01334 else if (strncasecmp(p, "HI", 2) == 0) {
01335 if (num_elems == 4)
01336 idx = MTYPE_To_TY(MTYPE_M8I2);
01337 else if (num_elems == 8)
01338 idx = MTYPE_To_TY(MTYPE_V16I2);
01339 }
01340 else if (strncasecmp(p, "QI", 2) == 0) {
01341 if (num_elems == 8)
01342 idx = MTYPE_To_TY(MTYPE_M8I1);
01343 else if (num_elems == 16)
01344 idx = MTYPE_To_TY(MTYPE_V16I1);
01345 }
01346 }
01347 if (idx == 0)
01348 Fail_FmtAssertion ("Get_TY: unexpected vector type");
01349 }
01350 break;
01351 #endif // TARG_X8664
01352 default:
01353 FmtAssert(FALSE, ("Get_TY unexpected tree_type"));
01354 }
01355 if (gs_type_readonly(type_tree))
01356 Set_TY_is_const (idx);
01357 if (gs_type_volatile(type_tree))
01358 Set_TY_is_volatile (idx);
01359 #ifdef KEY
01360 if (gs_type_restrict(type_tree))
01361 Set_TY_is_restrict (idx);
01362 #endif
01363 TYPE_TY_IDX(type_tree) = idx;
01364 if(Debug_Level >= 2) {
01365 #ifdef KEY
01366
01367
01368
01369 if (gs_tree_code(type_tree) != GS_RECORD_TYPE &&
01370 gs_tree_code(type_tree) != GS_UNION_TYPE &&
01371
01372
01373
01374 !TY_is_incomplete(idx) &&
01375 !(TY_kind(idx) == KIND_POINTER &&
01376 TY_is_incomplete(TY_pointed(idx)))) {
01377
01378
01379
01380
01381 defer_DST_type(type_tree, idx, orig_idx);
01382 }
01383 #else
01384 DST_INFO_IDX dst =
01385 Create_DST_type_For_Tree(type_tree,
01386 idx,orig_idx);
01387 TYPE_DST_IDX(type_tree) = dst;
01388 #endif
01389 }
01390
01391 return idx;
01392 }
01393
01394 void
01395 Create_DST_For_Tree (gs_t decl_node, ST* st)
01396 {
01397 DST_INFO_IDX dst =
01398 Create_DST_decl_For_Tree(decl_node,st);
01399 DECL_DST_IDX(decl_node) = dst;
01400 return;
01401 }
01402
01403 #if 1 // wgen
01404
01405
01406 ST *
01407 Search_decl_arguments(char *name)
01408 {
01409 gs_t p;
01410 if (name) {
01411 for (p = decl_arguments; p; p = gs_tree_chain(p)) {
01412 if (gs_decl_name(p) == NULL)
01413 return DECL_ST(p);
01414 if (strcmp(name, (char *) gs_identifier_pointer(gs_decl_name(p))) == 0)
01415 return DECL_ST(p);
01416 }
01417 }
01418 else {
01419 for (p = decl_arguments; p; p = gs_tree_chain(p)) {
01420 if (gs_decl_name(p) == NULL)
01421 return DECL_ST(p);
01422 }
01423 }
01424 return NULL;
01425 }
01426 #endif
01427
01428 #ifdef KEY // bug 12668
01429 static BOOL
01430 Has_label_decl(gs_t init)
01431 {
01432 if (gs_tree_code(init) == GS_LABEL_DECL)
01433 return TRUE;
01434 if (gs_tree_code(init) == GS_ADDR_EXPR)
01435 return Has_label_decl(gs_tree_operand(init,0));
01436 #ifdef FE_GNU_4_2_0 // bug 12699
01437 if (gs_tree_code(init) == GS_NOP_EXPR)
01438 return Has_label_decl(gs_tree_operand(init,0));
01439 #endif
01440 if (gs_tree_code(init) == GS_CONSTRUCTOR) {
01441 #ifdef FE_GNU_4_2_0
01442 INT length = gs_constructor_length(init);
01443 gs_t element_value;
01444 for (INT idx = 0; idx < length; idx++) {
01445 element_value = gs_constructor_elts_value(init, idx);
01446 if (Has_label_decl(element_value))
01447 return TRUE;
01448 }
01449 #else
01450 gs_t nd;
01451 for (nd = gs_constructor_elts(init); nd; nd = gs_tree_chain(nd)) {
01452 if (Has_label_decl(gs_tree_value(nd)))
01453 return TRUE;
01454 }
01455 #endif
01456 }
01457 return FALSE;
01458 }
01459 #endif
01460
01461 ST*
01462 Create_ST_For_Tree (gs_t decl_node)
01463 {
01464 TY_IDX ty_idx;
01465 ST* st = NULL;
01466 char *name;
01467 char tempname[32];
01468 ST_SCLASS sclass;
01469 ST_EXPORT eclass;
01470 SYMTAB_IDX level;
01471 static INT anon_count = 0;
01472 BOOL anon_st = FALSE;
01473
01474
01475
01476
01477
01478 if (gs_tree_code(decl_node) == GS_FUNCTION_DECL) {
01479 st = get_duplicate_st (decl_node);
01480 if (st) {
01481 set_DECL_ST(decl_node, st);
01482 return st;
01483 }
01484 }
01485
01486
01487
01488 if (gs_tree_code(decl_node) == GS_RESULT_DECL) {
01489 sprintf(tempname, ".result_decl_%d", gs_decl_uid(decl_node));
01490 name = tempname;
01491 anon_st = TRUE;
01492 }
01493 else if ((gs_tree_code(decl_node) == GS_FUNCTION_DECL ||
01494 gs_tree_code(decl_node) == GS_PARM_DECL ||
01495 (gs_tree_code(decl_node) == GS_VAR_DECL &&
01496 gs_decl_asmreg(decl_node) >= 0)) &&
01497 gs_decl_name(decl_node) != 0)
01498 name = (char *) gs_identifier_pointer (gs_decl_name (decl_node));
01499 else if (gs_decl_assembler_name (decl_node))
01500 name = (char *) gs_identifier_pointer (gs_decl_assembler_name (decl_node));
01501 else if (gs_decl_name (decl_node))
01502 name = (char *) gs_identifier_pointer (gs_decl_name (decl_node));
01503 else {
01504 sprintf(tempname, "anon%d", ++anon_count);
01505 name = tempname;
01506 anon_st = TRUE;
01507 }
01508
01509 #ifdef KEY
01510 BOOL guard_var = FALSE;
01511
01512 if (strncmp("_ZGV", name, 4) == 0) {
01513 guard_var = TRUE;
01514 }
01515 #endif
01516
01517 switch (gs_tree_code(decl_node)) {
01518
01519 case GS_FUNCTION_DECL:
01520 {
01521 if (Enable_WFE_DFE) {
01522 gs_t body = gs_decl_saved_tree(decl_node);
01523 if (gs_decl_thunk_p(decl_node) &&
01524 gs_tree_code(gs_cp_decl_context(decl_node)) != GS_NAMESPACE_DECL)
01525 Push_Deferred_Function (decl_node);
01526
01527
01528
01529
01530
01531 else
01532 if (body != NULL && !gs_decl_external(decl_node) &&
01533 (gs_decl_template_info(decl_node) == NULL ||
01534 gs_decl_friend_pseudo_template_instantiation(decl_node) ||
01535 gs_decl_template_instantiated(decl_node) ||
01536 gs_decl_template_specialization(decl_node))) {
01537 Push_Deferred_Function (decl_node);
01538 }
01539 }
01540
01541 #ifdef KEY
01542 Is_True (!processing_function_prototype,
01543 ("Create_ST_For_Tree: processing another function prototype?"));
01544 processing_function_prototype = TRUE;
01545 TY_IDX func_ty_idx = Get_TY(gs_tree_type(decl_node));
01546 processing_function_prototype = FALSE;
01547 #else
01548 TY_IDX func_ty_idx = Get_TY(gs_tree_type(decl_node));
01549 #endif
01550
01551 sclass = SCLASS_EXTERN;
01552 eclass = gs_tree_public(decl_node) || gs_decl_weak(decl_node) ?
01553 EXPORT_PREEMPTIBLE :
01554 EXPORT_LOCAL;
01555 level = GLOBAL_SYMTAB+1;
01556
01557 PU_IDX pu_idx;
01558 PU& pu = New_PU (pu_idx);
01559
01560 PU_Init (pu, func_ty_idx, level);
01561
01562 #ifdef KEY
01563 st = New_ST (level - 1);
01564 #else
01565 st = New_ST (GLOBAL_SYMTAB);
01566 #endif
01567
01568
01569
01570 char *p;
01571 if (gs_decl_assembler_name(decl_node) == NULL)
01572 p = name;
01573 else p = gs_identifier_pointer (gs_decl_assembler_name (decl_node));
01574 if (*p == '*')
01575 p++;
01576 ST_Init (st, Save_Str(p),
01577 CLASS_FUNC, sclass, eclass, TY_IDX (pu_idx));
01578
01579
01580 if (gs_decl_complete_constructor_p(decl_node) && !gs_decl_copy_constructor_p(decl_node))
01581 Set_PU_is_constructor(pu);
01582
01583 if (gs_decl_pure_virtual_p(decl_node) || strncmp(p, "__cxa_pure_virtual", 18) == 0)
01584 Set_ST_is_pure_vfunc(st);
01585
01586 if (gs_tree_code(gs_tree_type(decl_node)) == GS_METHOD_TYPE) {
01587 TY_IDX base = Get_TY(gs_type_method_basetype(gs_tree_type(decl_node)));
01588 Set_PU_base_class(pu, base);
01589 }
01590
01591 if (gs_decl_thunk_p(decl_node) &&
01592 gs_tree_code(gs_cp_decl_context(decl_node)) != GS_NAMESPACE_DECL &&
01593 eclass != EXPORT_LOCAL &&
01594 eclass != EXPORT_LOCAL_INTERNAL)
01595 Set_ST_is_weak_symbol(st);
01596 }
01597 break;
01598
01599 #ifdef KEY
01600 case GS_RESULT_DECL:
01601 #if 0
01602
01603 should not be needed any more.
01604 if (TY_return_in_mem
01605 (Get_TY
01606 (gs_tree_type
01607 (gs_tree_type
01608 (Current_Function_Decl()) ) ) ) )
01609 {
01610
01611
01612 WN *first_formal = WN_formal(Current_Entry_WN(), 0);
01613 if (!get_DECL_ST(decl_node))
01614 set_DECL_ST(decl_node, WN_st(first_formal));
01615 return get_DECL_ST(decl_node);
01616 }
01617
01618 #endif
01619 #endif
01620 case GS_PARM_DECL:
01621 case GS_VAR_DECL:
01622 {
01623 if (gs_tree_code(decl_node) == GS_PARM_DECL) {
01624 #ifdef KEY
01625
01626 if (decl_arguments) {
01627 st = Search_decl_arguments(gs_decl_name(decl_node) ? name : NULL);
01628 if (st) {
01629 set_DECL_ST(decl_node, st);
01630 return st;
01631 }
01632 }
01633 #endif
01634 sclass = SCLASS_FORMAL;
01635 eclass = EXPORT_LOCAL;
01636 level = CURRENT_SYMTAB;
01637 }
01638 else {
01639 if (gs_decl_context (decl_node) == 0 ||
01640 gs_tree_code (gs_decl_context (decl_node)) == GS_NAMESPACE_DECL ||
01641 gs_tree_code (gs_decl_context (decl_node)) == GS_RECORD_TYPE ) {
01642 if (gs_tree_public (decl_node)) {
01643
01644 if (gs_decl_external(decl_node) ||
01645 (gs_decl_lang_specific(decl_node) &&
01646 gs_decl_really_extern(decl_node)))
01647 sclass = SCLASS_EXTERN;
01648 else
01649 if (gs_decl_initial(decl_node))
01650 sclass = SCLASS_UGLOBAL;
01651 else if (gs_tree_static(decl_node)) {
01652 #ifdef KEY
01653
01654 if (flag_no_common || !gs_decl_common (decl_node) ||
01655 (!lang_cplus &&
01656 gs_decl_section_name (decl_node) ))
01657 #else
01658 if (flag_no_common)
01659 #endif
01660 sclass = SCLASS_UGLOBAL;
01661 else
01662 sclass = SCLASS_COMMON;
01663 }
01664 else
01665 sclass = SCLASS_EXTERN;
01666 eclass = EXPORT_PREEMPTIBLE;
01667 }
01668 else {
01669 sclass = SCLASS_FSTATIC;
01670 eclass = EXPORT_LOCAL;
01671 }
01672 level = GLOBAL_SYMTAB;
01673 }
01674 else {
01675 #ifdef KEY
01676
01677 gs_t section_name = gs_decl_section_name(decl_node);
01678 if (section_name &&
01679 !strncmp(gs_tree_string_pointer(section_name),
01680 ".gnu.linkonce.", 14)) {
01681 if (!strncmp(gs_tree_string_pointer(section_name),
01682 ".gnu.linkonce.b.", 16)
01683
01684 || !strncmp(gs_tree_string_pointer(section_name),
01685 ".gnu.linkonce.sb.", 17)) {
01686 sclass = SCLASS_UGLOBAL;
01687 level = GLOBAL_SYMTAB;
01688 eclass = EXPORT_PREEMPTIBLE;
01689 } else {
01690
01691 Fail_FmtAssertion("Create_ST_For_Tree: %s section NYI",
01692 gs_tree_string_pointer(section_name));
01693 }
01694 }
01695
01696
01697
01698
01699
01700
01701
01702
01703 else if (section_name &&
01704 (!strncmp(gs_tree_string_pointer(section_name),
01705 ".sbss.", 6) ||
01706 !strncmp(gs_tree_string_pointer(section_name),
01707 ".bss.", 5))) {
01708 sclass = SCLASS_UGLOBAL;
01709 level = GLOBAL_SYMTAB;
01710 eclass = EXPORT_PREEMPTIBLE;
01711 }
01712 else
01713 #endif
01714 if (gs_decl_external(decl_node) || gs_decl_weak(decl_node)) {
01715
01716
01717 if (!flag_no_common && gs_decl_common (decl_node)) {
01718
01719
01720 sclass = SCLASS_COMMON;
01721 }
01722 else if (gs_tree_static (decl_node)) {
01723
01724
01725 sclass = SCLASS_UGLOBAL;
01726 }
01727 else {
01728
01729
01730 sclass = SCLASS_EXTERN;
01731 }
01732 level = GLOBAL_SYMTAB;
01733 eclass = EXPORT_PREEMPTIBLE;
01734 }
01735 #ifdef KEY
01736
01737 else if (!flag_no_common &&
01738 gs_tree_static (decl_node) &&
01739 gs_decl_common (decl_node) &&
01740 gs_tree_public (decl_node)) {
01741 sclass = SCLASS_COMMON;
01742 level = GLOBAL_SYMTAB;
01743 eclass = EXPORT_PREEMPTIBLE;
01744 }
01745 #endif
01746 else {
01747 if (gs_tree_static (decl_node)) {
01748 sclass = SCLASS_PSTATIC;
01749 if (pstatic_as_global
01750 #ifdef KEY
01751 && ! (gs_decl_initial(decl_node) &&
01752 !gs_decl_external(decl_node) &&
01753 Has_label_decl(gs_decl_initial(decl_node)))
01754 #endif
01755 )
01756 level = GLOBAL_SYMTAB;
01757 else
01758 level = CURRENT_SYMTAB;
01759 }
01760 else {
01761 sclass = SCLASS_AUTO;
01762 level = DECL_SYMTAB_IDX(decl_node) ?
01763 DECL_SYMTAB_IDX(decl_node) : CURRENT_SYMTAB;
01764 }
01765 eclass = EXPORT_LOCAL;
01766 }
01767 }
01768 }
01769
01770
01771
01772
01773
01774 if (guard_var) {
01775 level = GLOBAL_SYMTAB;
01776 sclass = SCLASS_UGLOBAL;
01777 eclass = EXPORT_PREEMPTIBLE;
01778 }
01779
01780
01781
01782
01783
01784 ty_idx = Get_TY (gs_tree_type(decl_node));
01785 st = DECL_ST(decl_node);
01786 if (st)
01787 return st;
01788 st = New_ST (level);
01789 if (TY_kind (ty_idx) == KIND_ARRAY &&
01790 gs_tree_static (decl_node) &&
01791 gs_decl_initial (decl_node) == FALSE &&
01792 TY_size (ty_idx) == 0) {
01793 Set_TY_size (ty_idx, TY_size (Get_TY (gs_tree_type (gs_tree_type (decl_node)))));
01794 }
01795 #ifndef KEY
01796
01797
01798 if (TY_mtype (ty_idx) == MTYPE_M &&
01799 Aggregate_Alignment > 0 &&
01800 Aggregate_Alignment > TY_align (ty_idx))
01801 Set_TY_align (ty_idx, Aggregate_Alignment);
01802 #endif // !KEY
01803
01804 if (gs_tree_readonly(decl_node))
01805 Set_TY_is_const (ty_idx);
01806 if (gs_tree_this_volatile(decl_node))
01807 Set_TY_is_volatile (ty_idx);
01808 #if 1 // wgen bug 10470
01809 else Clear_TY_is_volatile (ty_idx);
01810 #endif
01811 #ifdef KEY
01812
01813 if (gs_decl_user_align (decl_node))
01814 Set_TY_align (ty_idx, gs_decl_align_unit(decl_node));
01815
01816
01817
01818
01819
01820 #endif // KEY
01821
01822
01823 char *p = name;
01824 if (*p == '*')
01825 p++;
01826 ST_Init (st, Save_Str(p), CLASS_VAR, sclass, eclass, ty_idx);
01827 #ifdef KEY
01828 #ifdef FE_GNU_4_2_0
01829 if (gs_tree_code (decl_node) == GS_VAR_DECL &&
01830
01831
01832
01833 gs_decl_thread_local (decl_node) &&
01834 ((!lang_cplus && gs_c_decl_threadprivate_p (decl_node)) ||
01835 (lang_cplus && gs_cp_decl_threadprivate_p (decl_node))))
01836 Set_ST_is_thread_private (st);
01837
01838 if (gs_tree_code (decl_node) == GS_VAR_DECL && anon_st)
01839 WGEN_add_pragma_to_enclosing_regions (WN_PRAGMA_LOCAL, st);
01840 #endif
01841
01842 if (gs_decl_size_unit (decl_node) &&
01843 gs_tree_code (gs_decl_size_unit (decl_node)) != GS_INTEGER_CST)
01844 {
01845
01846 int idx;
01847 if (!Set_Current_Scope_Has_Alloca (idx))
01848 {
01849 ST * save_st = WGEN_Alloca_0 ();
01850 Set_Current_Scope_Alloca_St (save_st, idx);
01851 }
01852 WN * size = WGEN_Expand_Expr (gs_decl_size_unit (decl_node));
01853
01854 ST * alloca_st = New_ST (CURRENT_SYMTAB);
01855 ST_Init (alloca_st, Save_Str (name),
01856 CLASS_VAR, SCLASS_AUTO, EXPORT_LOCAL,
01857 Make_Pointer_Type (ty_idx, FALSE));
01858 Set_ST_is_temp_var (alloca_st);
01859 Set_ST_pt_to_unique_mem (alloca_st);
01860 Set_ST_base_idx (st, ST_st_idx (alloca_st));
01861 WN *wn = WN_CreateAlloca (size);
01862 wn = WN_Stid (Pointer_Mtype, 0, alloca_st, ST_type (alloca_st), wn);
01863 WGEN_Stmt_Append (wn, Get_Srcpos());
01864 Set_PU_has_alloca (Get_Current_PU());
01865
01866 Add_Current_Scope_Alloca_St (alloca_st, idx);
01867 }
01868 #endif // KEY
01869 if (gs_tree_code(decl_node) == GS_PARM_DECL) {
01870 Set_ST_is_value_parm(st);
01871 }
01872 }
01873 break;
01874 default:
01875 {
01876 Fail_FmtAssertion ("Create_ST_For_Tree: unexpected tree type %s",
01877 WGEN_Tree_Node_Name(decl_node));
01878 }
01879 break;
01880 }
01881
01882 set_DECL_ST(decl_node, st);
01883
01884
01885
01886 if (gs_tree_code(decl_node) == GS_VAR_DECL && gs_decl_register(decl_node) &&
01887 gs_decl_asmreg(decl_node) >= 0) {
01888 extern PREG_NUM Map_Reg_To_Preg [];
01889 int reg = gs_decl_asmreg(decl_node);
01890 PREG_NUM preg = Map_Reg_To_Preg [reg];
01891 FmtAssert (preg >= 0,
01892 ("mapping register %d to preg failed\n", reg));
01893 TY_IDX ty_idx = ST_type (st);
01894 Set_TY_is_volatile (ty_idx);
01895 Set_ST_type (st, ty_idx);
01896 Set_ST_assigned_to_dedicated_preg (st);
01897 ST_ATTR_IDX st_attr_idx;
01898
01899
01900 ST_ATTR& st_attr = New_ST_ATTR (level, st_attr_idx);
01901 ST_ATTR_Init (st_attr, ST_st_idx (st), ST_ATTR_DEDICATED_REGISTER, preg);
01902 }
01903
01904 if (gs_tree_code(decl_node) == GS_VAR_DECL) {
01905 if (gs_decl_context(decl_node) &&
01906 gs_tree_code(gs_decl_context(decl_node)) == GS_RECORD_TYPE) {
01907 Get_TY(gs_decl_context(decl_node));
01908 }
01909 if (gs_decl_thread_local(decl_node)
01910 #ifdef FE_GNU_4_2_0
01911
01912
01913
01914 && ((!lang_cplus && !gs_c_decl_threadprivate_p(decl_node)) ||
01915 (lang_cplus && !gs_cp_decl_threadprivate_p(decl_node)))
01916 #endif
01917 ) {
01918 Set_ST_is_thread_local(st);
01919 }
01920 }
01921
01922 if (Enable_WFE_DFE) {
01923 if (gs_tree_code(decl_node) == GS_VAR_DECL &&
01924 level == GLOBAL_SYMTAB &&
01925 !gs_decl_external (decl_node) &&
01926 gs_decl_initial (decl_node)) {
01927 Push_Deferred_Function (decl_node);
01928 }
01929 }
01930
01931 if (gs_decl_weak (decl_node) &&
01932 (!gs_decl_external (decl_node)
01933 #ifdef KEY
01934
01935
01936
01937 || gs_decl_alias_target(decl_node))
01938 #endif
01939 ) {
01940 Set_ST_is_weak_symbol (st);
01941 }
01942
01943 #ifdef KEY
01944
01945
01946
01947
01948
01949
01950
01951
01952
01953
01954
01955
01956
01957
01958 if (make_symbols_weak) {
01959 if (eclass != EXPORT_LOCAL &&
01960 eclass != EXPORT_LOCAL_INTERNAL &&
01961
01962
01963 WEAK_WORKAROUND(st) != WEAK_WORKAROUND_dont_make_weak &&
01964
01965 !(gs_tree_code(decl_node) == GS_FUNCTION_DECL &&
01966 gs_decl_built_in(decl_node))) {
01967 Set_ST_is_weak_symbol (st);
01968 WEAK_WORKAROUND(st) = WEAK_WORKAROUND_made_weak;
01969 }
01970 }
01971
01972 else if (guard_var) {
01973 Set_ST_is_weak_symbol (st);
01974 Set_ST_init_value_zero (st);
01975 Set_ST_is_initialized (st);
01976 }
01977 #endif
01978
01979 if (gs_decl_section_name (decl_node)) {
01980 if (strncmp(gs_tree_string_pointer (gs_decl_section_name (decl_node)),
01981 ".gnu.linkonce.",
01982 14) != 0 ) {
01983
01984 DevWarn ("section %s specified for %s",
01985 gs_tree_string_pointer (gs_decl_section_name (decl_node)),
01986 ST_name (st));
01987 if (gs_tree_code (decl_node) == GS_FUNCTION_DECL)
01988 level = GLOBAL_SYMTAB;
01989 ST_ATTR_IDX st_attr_idx;
01990 ST_ATTR& st_attr = New_ST_ATTR (level, st_attr_idx);
01991 ST_ATTR_Init (st_attr, ST_st_idx (st), ST_ATTR_SECTION_NAME,
01992 Save_Str (gs_tree_string_pointer (gs_decl_section_name (decl_node))));
01993 if (!lang_cplus)
01994 Set_ST_has_named_section (st);
01995 }
01996 else {
01997
01998 DevWarn ("Ignore section %s specified for %s",
01999 gs_tree_string_pointer (gs_decl_section_name (decl_node)),
02000 ST_name (st));
02001 }
02002 }
02003
02004 #if defined(KEY) && defined(TARG_IA64)
02005
02006 if (gs_tree_code (decl_node) == GS_FUNCTION_DECL)
02007 {
02008
02009 gs_t type_attr_list = gs_type_attributes(gs_tree_type(decl_node));
02010 gs_t type_attr;
02011 for ( type_attr = type_attr_list; type_attr; type_attr = gs_tree_chain(type_attr)) {
02012
02013 if (gs_tree_purpose(type_attr) != NULL &&
02014 gs_code(gs_tree_purpose(type_attr)) == GS_IDENTIFIER_NODE ) {
02015 const char * attr_name = gs_tree_string_pointer(gs_tree_purpose(type_attr));
02016 if( strcmp("syscall_linkage", attr_name) == 0 ) {
02017
02018 DevWarn("Encounter syscall_linkage attribute!!!");
02019 Set_PU_has_syscall_linkage (Pu_Table [ST_pu(st)]);
02020
02021 break;
02022 }
02023 }
02024 }
02025 }
02026 #endif
02027
02028
02029 if(Debug_Level >= 2) {
02030
02031 if (ST_sclass(st) != SCLASS_EXTERN) {
02032
02033 add_deferred_DST_types();
02034
02035 DST_INFO_IDX dst = Create_DST_decl_For_Tree(decl_node,st);
02036 DECL_DST_IDX(decl_node) = dst;
02037 }
02038 }
02039
02040 #ifdef KEY
02041
02042
02043
02044
02045
02046 if (lang_cplus && gs_tree_code(decl_node) == GS_VAR_DECL &&
02047 !expanded_decl(decl_node))
02048 WGEN_Expand_Decl(decl_node, TRUE);
02049 #endif
02050
02051 return st;
02052 }
02053
02054 #include <ext/hash_map>
02055
02056 namespace {
02057
02058 using __gnu_cxx::hash_map;
02059
02060 struct ptrhash {
02061 size_t operator()(void* p) const { return reinterpret_cast<size_t>(p); }
02062 };
02063
02064 hash_map<gs_t, TY_IDX, ptrhash> ty_idx_map;
02065 hash_map<gs_t, ST*, ptrhash> st_map;
02066 hash_map<gs_t, SYMTAB_IDX, ptrhash> symtab_idx_map;
02067 hash_map<gs_t, LABEL_IDX, ptrhash> label_idx_map;
02068 hash_map<gs_t, ST*, ptrhash> string_st_map;
02069 hash_map<gs_t, BOOL, ptrhash> bool_map;
02070 hash_map<gs_t, INT32, ptrhash> field_id_map;
02071 hash_map<gs_t, INT32, ptrhash> type_field_ids_used_map;
02072 hash_map<gs_t, INT32, ptrhash> scope_number_map;
02073 hash_map<gs_t, gs_t, ptrhash> label_scope_map;
02074 hash_map<gs_t, DST_INFO_IDX,ptrhash> decl_idx_map;
02075 hash_map<gs_t, DST_INFO_IDX,ptrhash> decl_field_idx_map;
02076 hash_map<gs_t, DST_INFO_IDX,ptrhash> decl_specification_idx_map;
02077 hash_map<gs_t, DST_INFO_IDX,ptrhash> type_idx_map;
02078 hash_map<gs_t, LABEL_IDX, ptrhash> handler_label_map;
02079 hash_map<gs_t, DST_INFO_IDX,ptrhash> abstract_root_map;
02080 #ifdef KEY
02081
02082 hash_map<PU*, hash_map<gs_t, ST*, ptrhash>*, ptrhash> pu_map;
02083
02084 hash_map<gs_t, BOOL, ptrhash> expanded_decl_map;
02085
02086 hash_map<gs_t, BOOL, ptrhash> func_PU_uplevel_map;
02087 hash_map<gs_t, gs_t, ptrhash> parent_scope_map;
02088
02089
02090
02091
02092 hash_map<ST*, INT32, ptrhash> weak_workaround_map;
02093 #endif
02094 hash_map<gs_t, ST*, ptrhash> decl_st2_map;
02095 }
02096
02097 TY_IDX& TYPE_TY_IDX(gs_t t) { return ty_idx_map[t]; }
02098
02099 BOOL& expanded_decl(gs_t t) {
02100 FmtAssert (t, ("func_expanded: not a decl"));
02101 return expanded_decl_map[t];
02102 }
02103
02104
02105 void
02106 set_DECL_ST(gs_t t, ST* st) {
02107
02108
02109 gs_t t_index;
02110 if (gs_tree_code(t) == GS_VAR_DECL &&
02111 (gs_decl_context(t) == 0 ||
02112 gs_tree_code(gs_decl_context(t)) == GS_NAMESPACE_DECL) &&
02113 gs_decl_name (t) && gs_decl_assembler_name(t))
02114 t_index = gs_decl_assembler_name(t);
02115 else
02116 t_index = t;
02117
02118
02119
02120
02121 if (st == (ST *) 1) {
02122 st_map[t_index] = st;
02123 return;
02124 }
02125
02126
02127
02128
02129
02130
02131
02132
02133
02134
02135
02136
02137 if (Current_scope != 0 &&
02138 (gs_tree_code(t) == GS_PARM_DECL ||
02139 (gs_tree_code(t) == GS_VAR_DECL &&
02140 (ST_sclass(st) == SCLASS_AUTO ||
02141 (! pstatic_as_global &&
02142 ST_sclass(st) == SCLASS_PSTATIC))))) {
02143
02144
02145
02146
02147
02148
02149
02150
02151 if (Scope_tab[Current_scope].st != NULL) {
02152
02153 PU *pu = &Get_Current_PU();
02154 hash_map<PU*, hash_map<gs_t, ST*, ptrhash>*, ptrhash>::iterator it =
02155 pu_map.find(pu);
02156 if (it == pu_map.end()) {
02157
02158 pu_map[pu] = new hash_map<gs_t, ST*, ptrhash>;
02159 }
02160
02161 (*(pu_map[pu]))[t_index] = st;
02162 }
02163 } else {
02164 #ifdef Is_True_On
02165 if (st_map[t_index]) {
02166
02167 FmtAssert (ST_is_weak_symbol(st_map[t_index]),
02168 ("set_DECL_ST: st_map already set"));
02169 }
02170 #endif
02171
02172 st_map[t_index] = st;
02173 }
02174 }
02175
02176
02177 ST*&
02178 get_DECL_ST(gs_t t) {
02179 static ST *null_ST = (ST *) NULL;
02180
02181
02182 gs_t t_index;
02183 if (gs_tree_code(t) == GS_VAR_DECL &&
02184 (gs_decl_context(t) == 0 ||
02185 gs_tree_code(gs_decl_context(t)) == GS_NAMESPACE_DECL) &&
02186 gs_decl_name (t) && gs_decl_assembler_name(t))
02187 t_index = gs_decl_assembler_name(t);
02188 else
02189 t_index = t;
02190
02191
02192
02193
02194 if (Current_scope == 0)
02195 return st_map[t_index];
02196
02197
02198 if (st_map[t_index]) {
02199 return st_map[t_index];
02200 }
02201
02202
02203 INT scope = Current_scope;
02204 do {
02205
02206
02207 if (Scope_tab[scope].st != NULL) {
02208
02209 PU *pu = &Get_Scope_PU(scope);
02210 hash_map<PU*, hash_map<gs_t, ST*, ptrhash>*, ptrhash>::iterator pu_map_it =
02211 pu_map.find(pu);
02212 if (pu_map_it != pu_map.end()) {
02213
02214 hash_map<gs_t, ST*, ptrhash> *st_map2 = pu_map[pu];
02215 if ((*st_map2)[t_index])
02216 return (*st_map2)[t_index];
02217 }
02218 }
02219 scope--;
02220 } while (scope > 1);
02221 return null_ST;
02222 }
02223
02224 BOOL&
02225 func_PU_uplevel(gs_t t) {
02226 FmtAssert (gs_tree_code(t) == GS_FUNCTION_DECL,
02227 ("func_PU_uplevel: not a FUNCTION_DECL tree node"));
02228 return func_PU_uplevel_map[t];
02229 }
02230
02231 INT32& WEAK_WORKAROUND(ST *st) { return weak_workaround_map[st]; }
02232
02233 SYMTAB_IDX& DECL_SYMTAB_IDX(gs_t t) { return symtab_idx_map[t]; }
02234 LABEL_IDX& DECL_LABEL_IDX(gs_t t) { return label_idx_map[t]; }
02235 ST*& TREE_STRING_ST(gs_t t) { return string_st_map[t]; }
02236 BOOL& DECL_LABEL_DEFINED(gs_t t) { return bool_map[t]; }
02237 INT32& DECL_FIELD_ID(gs_t t) { return field_id_map[t]; }
02238 INT32 & TYPE_FIELD_IDS_USED(gs_t t) { return type_field_ids_used_map[t]; }
02239 INT32 & SCOPE_NUMBER(gs_t t) { return scope_number_map[t]; }
02240 #ifdef KEY
02241 gs_t & PARENT_SCOPE(gs_t t) { return parent_scope_map[t]; }
02242 #endif
02243 gs_t & LABEL_SCOPE(gs_t t) { return label_scope_map[t]; }
02244 ST* & DECL_ST2(gs_t t) { return decl_st2_map[t]; }
02245
02246
02247
02248
02249
02250
02251 DST_INFO_IDX & DECL_DST_IDX(gs_t t)
02252 {
02253 hash_map<gs_t, DST_INFO_IDX,ptrhash>::iterator it =
02254 decl_idx_map.find(t);
02255 if(it == decl_idx_map.end()) {
02256
02257 DST_INFO_IDX dsti = DST_INVALID_IDX;
02258 decl_idx_map[t] = dsti;
02259 }
02260 return decl_idx_map[t];
02261 }
02262
02263
02264
02265
02266
02267
02268
02269 DST_INFO_IDX & DECL_DST_SPECIFICATION_IDX(gs_t t)
02270 {
02271 hash_map<gs_t, DST_INFO_IDX,ptrhash>::iterator it =
02272 decl_specification_idx_map.find(t);
02273 if(it == decl_specification_idx_map.end()) {
02274
02275 DST_INFO_IDX dsti = DST_INVALID_IDX;
02276 decl_specification_idx_map[t] = dsti;
02277 }
02278 return decl_specification_idx_map[t];
02279 }
02280
02281
02282
02283
02284
02285
02286
02287
02288 DST_INFO_IDX & DECL_DST_FIELD_IDX(gs_t t)
02289 {
02290 hash_map<gs_t, DST_INFO_IDX,ptrhash>::iterator it =
02291 decl_field_idx_map.find(t);
02292 if(it == decl_idx_map.end()) {
02293
02294 DST_INFO_IDX dsti = DST_INVALID_IDX;
02295 decl_field_idx_map[t] = dsti;
02296 }
02297 return decl_field_idx_map[t];
02298 }
02299
02300
02301
02302 DST_INFO_IDX & TYPE_DST_IDX(gs_t t)
02303 {
02304 hash_map<gs_t, DST_INFO_IDX,ptrhash>::iterator it =
02305 type_idx_map.find(t);
02306 if(it == type_idx_map.end()) {
02307
02308 DST_INFO_IDX dsti = DST_INVALID_IDX;
02309 type_idx_map[t] = dsti;
02310 }
02311 return type_idx_map[t];
02312 }
02313
02314
02315
02316 DST_INFO_IDX & DECL_DST_ABSTRACT_ROOT_IDX(gs_t t)
02317 {
02318 hash_map<gs_t, DST_INFO_IDX,ptrhash>::iterator it =
02319 abstract_root_map.find(t);
02320 if(it == abstract_root_map.end()) {
02321
02322 DST_INFO_IDX dsti = DST_INVALID_IDX;
02323 abstract_root_map[t] = dsti;
02324 }
02325 return abstract_root_map[t];
02326 }
02327
02328
02329 LABEL_IDX& HANDLER_LABEL(gs_t t) { return handler_label_map[t]; }