|
OpenADFortTk (basic)
|
00001 // ########################################################## 00002 // # This file is part of OpenADFortTk. # 00003 // # The full COPYRIGHT notice can be found in the top # 00004 // # level directory of the OpenADFortTk source tree. # 00005 // # For more information visit # 00006 // # http://www.mcs.anl.gov/openad # 00007 // ########################################################## 00008 00009 #ifndef stab_attr_INCLUDED 00010 #define stab_attr_INCLUDED 00011 /* ==================================================================== 00012 * ==================================================================== 00013 * 00014 * Description: 00015 * 00016 * Get TY and ST information, beyond that provided through 00017 * common/com/stab.h. Also, provide functions to access 00018 * and create identifier name attributes. 00019 * 00020 * Symbol table information 00021 * ------------------------ 00022 * 00023 * FILE_SCOPE_ID: 00024 * The scope_id given to TY and ST entries that are declared 00025 * with file-scope. 00026 * 00027 * Flag indicating referenced symbols 00028 * ---------------------------------- 00029 * 00030 * Stab_Reset_Referenced_Flag: 00031 * Will reset this flag for FOR_ALL_LOCAL_SYMBOLS and 00032 * FOR_ALL_CONSTANTS in the given symbol table. 00033 * 00034 * Type information 00035 * ---------------- 00036 * 00037 * MTYPE: 00038 * The name "MTYPE" is more intuitive than TYPE_ID as a 00039 * type for variables that hold elements from the MTYPE 00040 * enumeration. 00041 * 00042 * Stab_Identical_Types: 00043 * Two types are only identical if they have the same qualifiers, 00044 * compatible kinds, compatible MTYPEs, and identical substructure. 00045 * ENUM types are treated as scalars. While constructed types must 00046 * have identical substructure, we allow more lenient checks for 00047 * the top-level types: We can turn off qualifier checks 00048 * (check_quals == FALSE); we can treat all scalar values as 00049 * identical (check_scalars == FALSE); and we can treat pointers 00050 * as scalars (ptrs_as_scalars == TRUE). 00051 * 00052 * Stab_Assignment_Compatible_Types: 00053 * Similar to Stab_identical_types, but with the added leniency 00054 * for pointer types (i.e. qualifiers of pointed types) 00055 * specified in the ANSI/ISO C standard. 00056 * 00057 * Stab_Is_Element_Type_Of_Array: 00058 * True if the given etype is an element of the given a(rray) 00059 * type, or if it is an element of array elements of the array 00060 * type. 00061 * 00062 * Stab_Array_Has_Dynamic_Bounds: 00063 * This routine takes an array type [TODO: handle pointers 00064 * as arrays at every call site], and returns TRUE if all 00065 * bounds and stride information is given in terms of constant 00066 * values; otherwise FALSE will be returned. 00067 * 00068 * Stab_Get_Mload_Ty: 00069 * We have very limited information about MLOAD types, since we 00070 * only keep the base address in the WN node. This returns the 00071 * type of the first field in the given struct/union "base" struct 00072 * at the given offset and of the given (non-zero) size. 00073 * 00074 * Stab_Mtype_To_Ty: 00075 * Get the TY of an mtype. 00076 * 00077 * TY_IS_xxxxx: 00078 * Inquiries about what kind of type (TY) we are dealing with. 00079 * 00080 * Function types 00081 * -------------- 00082 * 00083 * Func_Return_Type: 00084 * The return type for a given function-type. Will be a 00085 * Void_Type for whirl2c when Func_Return_Character==TRUE, 00086 * since in C we return CHARACTER strings through an explicit 00087 * first parameter. 00088 * 00089 * Func_Return_Character: 00090 * TRUE when the given function type returns a Fortran CHARACTER 00091 * string. Can only return TRUE in Fortran mode. 00092 * 00093 * Func_Return_To_Param: 00094 * TRUE when the given function type returns a value into the 00095 * location denoted by the first parameter. 00096 * 00097 * Type creation 00098 * ------------- 00099 * Somtimes it may be necessary to create new TY entries beyond 00100 * those in the symbol-table generated by the compiler-phases, 00101 * and for these occations we provide the following facilities. 00102 * After processing of a given symbol table, we must reset any 00103 * TY fields to what they were before this translation. 00104 * 00105 * Stab_Pointer_To: 00106 * If the given TY has a TY_pointer attribute, then simply 00107 * return it; otherwise, create a new TY entry and set the 00108 * TY_pointer attribute of the pointee to point to it. 00109 * 00110 * Stab_Array_Of: 00111 * Creates a unique one-dimensional array type with the given 00112 * number of elements and the given element type. 00113 * 00114 * Identifier naming utilities 00115 * --------------------------- 00116 * We operate with a cyclic character buffer for identifier names, 00117 * where the size of the buffer is a minimum of 1024 characters 00118 * and at a maximum of 8 times the largest name encountered. Note 00119 * that a call to any of the functions described below may allocate 00120 * a new name buffer. Name buffers are allocated from the cyclic 00121 * character buffer, and a name-buffer may be reused at every 8th 00122 * allocation. We guarantee that a name-buffer is valid up until 00123 * 7 subsequent name-buffer allocations, but no longer. After 00124 * 7 subsequent name-buffer allocations, the name buffer may be 00125 * reused (overwritten) or even freed up from dynamic memory. While 00126 * the results from the calls to the functions provided here may be 00127 * used to construct identifier names, these results should be saved 00128 * off into a more permanent buffer area once the names have been 00129 * constructed. 00130 * 00131 * Stab_Free_Namebufs: 00132 * Frees up the memory allocated for string buffers. This should 00133 * be done between processing individual PUs. 00134 * 00135 * Get_Name_Buf_Slot: 00136 * Allocate a new name-buffer slot of the given size. It is up 00137 * to the caller to ensure that no reference is made to 00138 * characters outside the allocated slot. The cyclic name 00139 * buffer will become at least 8 times the size of this slot, 00140 * so do not use this as a method for obtaining an arbitrary 00141 * temporary memory-pool! 00142 * 00143 * Num2Str: 00144 * Convert the number into an equivalent ASCII character 00145 * string representation, using the given <stdio.h> formatting. 00146 * A maximum of 128 characters will be allocated to hold the 00147 * resultant string value. Note that the format must accept 00148 * a 64 bits integral value. 00149 * 00150 * Ptr_as_String: 00151 * Convert the pointer into an equivalent ASCII character 00152 * string representation. A maximum of 128 characters will 00153 * be allocated to hold the resultant string value. 00154 * 00155 * StrCat/StrCat: 00156 * Concatenate two and three strings, respectively, into 00157 * a new combined character string. 00158 * 00159 * Name_Hash_Idx: 00160 * Using the hash-value returned from Get_Hash_Value_For_Name, 00161 * this gets an index into the hash-table based on the log(2, 00162 * tbl_size) rightmost characters of the name. For a 00163 * tbl_size of 173, the rightmost 2 characters determines 00164 * the hash_idx. For an empty ('\0' or NULL) name, the 00165 * hash value and index will be zero 00166 * 00167 * Temporary variable information 00168 * ------------------------------ 00169 * Stab_Free_Tmpvars: 00170 * This will free up memory associated with the maintenance of 00171 * temporary variables, and should be called after processing each 00172 * PU. 00173 * 00174 * Stab_Lock_Tmpvar: 00175 * Return an identifying index for a tempvar of the given type. 00176 * If none existed before-hand, then a new one will be declared 00177 * locally to the current PU, using the subroutine provided, which 00178 * declares the temporary variable based on its type and index. 00179 * 00180 * Stab_Unlock_Tmpvar: 00181 * Given a tmpvar identifying index, this tmpvar will now become 00182 * available for other uses. 00183 * 00184 * ==================================================================== 00185 * ==================================================================== 00186 */ 00187 00188 //************************** System Include Files *************************** 00189 00190 //************************** Open64 Include Files *************************** 00191 00192 #include "Open64BasicTypes.h" 00193 00194 //*************************** User Include Files **************************** 00195 00196 //************************** Forward Declarations *************************** 00197 00198 //*************************************************************************** 00199 00200 // Referenced Information (REMOVE/FIXME) 00201 extern void 00202 Stab_Reset_Referenced_Flag(SYMTAB_IDX symtab); 00203 00204 //*************************************************************************** 00205 // Active Information 00206 //*************************************************************************** 00207 00208 // FIXME: temporary implementation and location 00209 bool 00210 IsActivePU(ST* pu_st); 00211 00212 //*************************************************************************** 00213 // Type Information 00214 //*************************************************************************** 00215 00216 extern BOOL 00217 Stab_Identical_Types(TY_IDX t1, TY_IDX t2, 00218 BOOL check_quals, 00219 BOOL check_scalars, 00220 BOOL ptrs_as_scalars); 00221 00222 extern BOOL 00223 Stab_Assignment_Compatible_Types(TY_IDX t1, TY_IDX t2, 00224 BOOL check_quals, 00225 BOOL check_scalars, 00226 BOOL ptrs_as_scalars); 00227 00228 // WN2F_Can_Assign_Types: This determines whether or not a value of 00229 // type t1 can be used anywhere we expect a value of type t2. When 00230 // this condition is TRUE, yet t1 is different from t2, we expect the 00231 // implicit Fortran type coersion to transform an object of one type 00232 // to the other. [FIXME-orig. text] 00233 bool 00234 WN2F_Can_Assign_Types(TY_IDX ty1, TY_IDX ty2); 00235 00236 extern BOOL 00237 Stab_Is_Element_Type_Of_Array(TY_IDX atype, TY_IDX etype); 00238 00239 extern BOOL 00240 Stab_Array_Has_Dynamic_Bounds(TY_IDX ty); 00241 extern BOOL 00242 Stab_Is_Assumed_Sized_Array(TY_IDX ty); 00243 extern BOOL 00244 Stab_Is_Equivalenced_Struct(TY_IDX ty); 00245 00246 extern TY_IDX 00247 Stab_Get_Mload_Ty(TY_IDX base, STAB_OFFSET offset, STAB_OFFSET size); 00248 00249 inline TY_IDX 00250 Stab_Mtype_To_Ty(TYPE_ID mtype) 00251 { 00252 return Be_Type_Tbl(mtype); 00253 } 00254 00255 inline BOOL 00256 TY_Is_Scalar(TY_IDX ty) 00257 { 00258 return (TY_kind(ty) == KIND_SCALAR); 00259 } 00260 00261 inline BOOL 00262 TY_IsNonScalar(TY_IDX ty) // cv Is_composite_Type symtab.h 00263 { 00264 return (TY_kind(ty) == KIND_ARRAY || TY_kind(ty) == KIND_STRUCT 00265 || TY_kind(ty) == KIND_POINTER); // FIXME 00266 } 00267 00268 inline BOOL 00269 TY_Is_Array(TY_IDX ty) 00270 { 00271 return (TY_kind(ty) == KIND_ARRAY); 00272 } 00273 00274 inline BOOL 00275 TY_IsRecord(TY_IDX ty) // FIXME 00276 { 00277 return (TY_kind(ty) == KIND_STRUCT); // note TY_is_union(ty) 00278 } 00279 00280 00281 inline BOOL 00282 TY_Is_Structured(TY_IDX ty) // REMOVE 00283 { 00284 return TY_kind(ty) == KIND_STRUCT; 00285 } 00286 00287 inline BOOL // REMOVE 00288 TY_Is_Struct(TY_IDX ty) 00289 { 00290 return (TY_kind(ty) == KIND_STRUCT && !TY_is_union(ty)); 00291 } 00292 00293 inline BOOL 00294 TY_Is_Union(TY_IDX ty) // REMOVE 00295 { 00296 return (TY_kind(ty) == KIND_STRUCT && TY_is_union(ty)); 00297 } 00298 00299 inline BOOL 00300 TY_Is_Pointer(TY_IDX ty) 00301 { 00302 return ((TY_kind(ty) == KIND_POINTER && !TY_is_f90_pointer(ty))); 00303 } 00304 00305 00306 inline BOOL 00307 TY_Is_String(TY_IDX ty) 00308 { 00309 return TY_mtype(ty) == MTYPE_STRING; 00310 } 00311 00312 inline BOOL 00313 TY_Is_Integral(TY_IDX ty) 00314 { 00315 return (MTYPE_type_class(TY_mtype(ty)) & MTYPE_CLASS_INTEGER) != 0; 00316 } 00317 00318 inline BOOL 00319 TY_Is_Quad(TY_IDX ty) 00320 { 00321 return TY_kind(ty) == KIND_SCALAR && TY_mtype(ty) == MTYPE_FQ; 00322 } 00323 00324 inline BOOL 00325 TY_Is_Complex(TY_IDX ty) 00326 { 00327 return TY_kind(ty) == KIND_SCALAR && (TY_mtype(ty) == MTYPE_C4 || 00328 TY_mtype(ty) == MTYPE_C8 || 00329 TY_mtype(ty) == MTYPE_CQ); 00330 } 00331 00332 00333 inline BOOL 00334 TY_Is_Function(TY_IDX ty) 00335 { 00336 return TY_kind(ty) == KIND_FUNCTION; 00337 } 00338 00339 inline BOOL 00340 TY_Is_Array_Or_Function(TY_IDX ty) 00341 { 00342 return ty != 0 && (TY_Is_Function(ty) || TY_Is_Array(ty)); 00343 } 00344 00345 inline BOOL 00346 TY_Is_Pointer_Or_Scalar(TY_IDX ty) 00347 { 00348 return (TY_Is_Scalar(ty) || (TY_Is_Pointer(ty)&&!TY_is_f90_pointer(ty))); 00349 } 00350 00351 inline BOOL 00352 TY_Is_Character_Reference(TY_IDX ty) 00353 { 00354 return TY_Is_Pointer(ty) 00355 && (TY_is_character(TY_pointed(ty)) 00356 || TY_mtype(TY_pointed(ty)) == MTYPE_STR); 00357 } 00358 00359 /* The front-end is not always reliable in where it sets the is_character 00360 * flag, so we look for it both on the array and on the element type. 00361 */ 00362 inline BOOL 00363 TY_Is_Character_String(TY_IDX ty) 00364 { 00365 return TY_is_character(ty) || 00366 TY_mtype(ty) == MTYPE_STR || 00367 (TY_Is_Array(ty) && 00368 TY_Is_Integral(TY_AR_etype(ty)) && 00369 TY_size(TY_AR_etype(ty)) == 1 && 00370 TY_is_character(TY_AR_etype(ty))); 00371 } 00372 00373 inline BOOL 00374 TY_Is_Chararray(TY_IDX ty) 00375 { 00376 return TY_Is_Array(ty) && TY_Is_Character_String(TY_AR_etype(ty)); 00377 } 00378 00379 inline BOOL 00380 TY_Is_Chararray_Reference(TY_IDX ty) 00381 { 00382 return TY_Is_Pointer(ty) && TY_Is_Chararray(TY_pointed(ty)); 00383 } 00384 00385 inline BOOL 00386 TY_Is_Array_Of_Chars(TY_IDX ty) 00387 { 00388 return TY_Is_Array(ty) && 00389 TY_AR_ndims(ty) == 1 && 00390 TY_Is_Integral(TY_AR_etype(ty)) && 00391 TY_size(TY_AR_etype(ty)) == 1; 00392 } 00393 00394 00395 /* fortran FEs now generate U1 arrays for chars */ 00396 inline BOOL 00397 TY_Is_Array_Of_UChars(TY_IDX ty) 00398 { 00399 return TY_Is_Array(ty) && 00400 TY_AR_ndims(ty) == 1 && 00401 TY_mtype(TY_AR_etype(ty)) == MTYPE_U1 ; 00402 } 00403 00404 inline BOOL 00405 TY_Is_Preg_Type(TY_IDX ty) 00406 { 00407 /* Return True if ty is a valid type for pseudo registers; 00408 return False otherwise. */ 00409 return TY_Is_Pointer_Or_Scalar(ty); 00410 } 00411 00412 inline BOOL 00413 FLD_Is_Bitfield(FLD_HANDLE fld, FLD_HANDLE next_fld, INT64 max_size) 00414 { 00415 /* fld must not be a member of a union! */ 00416 return !FLD_equivalence(fld) && 00417 (FLD_is_bit_field(fld) || 00418 (next_fld.Is_Null () && max_size < (INT64)TY_size(FLD_type(fld))) || 00419 (!next_fld.Is_Null() && !FLD_equivalence(next_fld) && 00420 FLD_ofst(next_fld) - FLD_ofst(fld) < TY_size(FLD_type(fld)))); 00421 } 00422 00423 //*************************************************************************** 00424 // Symbol table Information 00425 //*************************************************************************** 00426 00427 inline BOOL 00428 Stab_Is_Valid_Base(const ST *st) 00429 { 00430 return (ST_base(st) != NULL && 00431 ST_base(st) != (st) && 00432 ST_sym_class(ST_base(st)) != CLASS_BLOCK /* cg generated */ ); 00433 } 00434 00435 inline BOOL 00436 Stab_Is_Common_Block(const ST *st) 00437 { 00438 return ((ST_sclass(st) == SCLASS_COMMON || 00439 ST_sclass(st) == SCLASS_DGLOBAL) && 00440 TY_Is_Structured(ST_type(st))); 00441 } 00442 00443 inline BOOL 00444 Stab_Is_Equivalence_Block(const ST *st) 00445 { 00446 return (ST_sym_class(st) == CLASS_VAR && 00447 TY_Is_Structured(ST_type(st)) && 00448 ST_sclass(st) != SCLASS_COMMON && 00449 ! TY_flist(Ty_Table[ST_type(st)]).Is_Null () && 00450 FLD_equivalence(TY_fld(Ty_Table[ST_type(st)]))); 00451 } 00452 00453 00454 inline BOOL 00455 Stab_Is_Based_At_Common_Block(const ST *st) 00456 { 00457 return (Stab_Is_Valid_Base(st) && Stab_Is_Common_Block(ST_base(st))); 00458 } 00459 00460 inline BOOL 00461 Stab_Is_Based_At_Common_Or_Equivalence(const ST *st) 00462 { 00463 return (Stab_Is_Valid_Base(st) && 00464 (Stab_Is_Common_Block(ST_base(st)) || 00465 Stab_Is_Equivalence_Block(ST_base(st)))); 00466 } 00467 00468 inline BOOL 00469 Stab_Is_In_Module(const ST *st) 00470 { 00471 return (Stab_Is_Valid_Base(st) && 00472 ST_sclass(st) == SCLASS_MODULE); 00473 } 00474 00475 inline BOOL 00476 Stab_Is_Module(const ST *st) 00477 { 00478 return (ST_base(st) != NULL && 00479 // we are at the base 00480 ST_base(st) == (st) && 00481 // the module name has this class 00482 ST_sclass(st) == SCLASS_TEXT); 00483 } 00484 00485 inline BOOL 00486 Stab_No_Linkage(const ST *st) 00487 { 00488 return (ST_sclass(st) == SCLASS_AUTO || 00489 ST_sclass(st) == SCLASS_FORMAL || 00490 ST_sclass(st) == SCLASS_FORMAL_REF); 00491 } 00492 00493 inline BOOL 00494 Stab_External_Linkage(const ST *st) 00495 { 00496 return (!Stab_No_Linkage(st) && 00497 ST_sclass(st) != SCLASS_PSTATIC && 00498 ST_sclass(st) != SCLASS_FSTATIC && 00499 ST_sclass(st) != SCLASS_CPLINIT && 00500 ST_sclass(st) != SCLASS_EH_REGION && 00501 ST_sclass(st) != SCLASS_EH_REGION_SUPP && 00502 ST_sclass(st) != SCLASS_DISTR_ARRAY); 00503 } 00504 00505 inline BOOL 00506 Stab_External_Def_Linkage(const ST *st) 00507 { 00508 return (Stab_External_Linkage(st) && ST_sclass(st) != SCLASS_EXTERN); 00509 } 00510 00511 inline BOOL 00512 Stab_Identical_Quals(TY_IDX t1, TY_IDX t2) 00513 { 00514 return (TY_is_volatile(t1) == TY_is_volatile(t2) && 00515 TY_is_restrict(t1) == TY_is_restrict(t2) && 00516 TY_is_const(t1) == TY_is_const(t2)); 00517 } 00518 00519 inline BOOL 00520 Stab_Assign_Compatible_Pointer_Quals(TY_IDX t1, TY_IDX t2) 00521 { 00522 return ((TY_is_volatile(t2)? TY_is_volatile(t1) : TRUE) && 00523 (TY_is_restrict(t2)? TY_is_restrict(t1) : TRUE) && 00524 (TY_is_const(t2)? TY_is_const(t1) : TRUE)); 00525 } 00526 00527 00528 /* A macro to test if a parameter is a character string, in which case 00529 * it needs an implicit length parameter. Note that in the test on the 00530 * argument (caller) side we only need to consider reference types, since 00531 * the call-by-reference always should be explicit on that side. This 00532 * macro should only be used on the subprogram definition side! This 00533 * only applies to Fortran code. 00534 */ 00535 inline BOOL 00536 STAB_PARAM_HAS_IMPLICIT_LENGTH(const ST *st) 00537 { 00538 return ((ST_sclass(st) == SCLASS_FORMAL_REF && 00539 TY_Is_Character_String(ST_type(st))) || 00540 (ST_sclass(st) == SCLASS_FORMAL && 00541 (TY_Is_Character_Reference(ST_type(st)) || 00542 TY_Is_Chararray_Reference(ST_type(st))))); 00543 } 00544 00545 /* Identify cases when a reference parameter is explicitly represented 00546 * as a pointer (as opposed to an SCLASS_FORMAL_REF). This only applies 00547 * to Fortran code. 00548 */ 00549 inline BOOL 00550 STAB_IS_POINTER_REF_PARAM(const ST *st) 00551 { 00552 return (TY_Is_Pointer(ST_type(st)) && ST_sclass(st)==SCLASS_FORMAL 00553 && !ST_is_value_parm(st)); 00554 } 00555 00556 //*************************************************************************** 00557 // Function type attributes 00558 //*************************************************************************** 00559 00560 inline BOOL 00561 Func_Return_Character(TY_IDX func_ty) 00562 { 00563 return TY_is_character(Ty_Table[TY_ret_type(func_ty)]); 00564 } 00565 00566 inline TY_IDX 00567 Func_Return_Type(TY_IDX func_ty) 00568 { 00569 return TY_ret_type(func_ty); 00570 } 00571 00572 // see wn_attr: TY_IDX Func_Return_Type(WN* wn); 00573 00574 inline BOOL 00575 Func_Return_To_Param(TY_IDX func_ty) 00576 { 00577 return TY_return_to_param(Ty_Table[func_ty]); 00578 } 00579 00580 00581 //*************************************************************************** 00582 // Type creation 00583 //*************************************************************************** 00584 00585 inline TY_IDX 00586 Stab_Pointer_To(TY_IDX pointee) { return Make_Pointer_Type(pointee); } 00587 00588 extern TY_IDX 00589 Stab_Array_Of(TY_IDX etype, mINT64 num_elts); 00590 00591 00592 //*************************************************************************** 00593 // Identifier naming utilities 00594 //*************************************************************************** 00595 00596 extern void 00597 Stab_Free_Namebufs(void); 00598 00599 extern char * 00600 Get_Name_Buf_Slot(UINT size); 00601 00602 extern const char * 00603 Num2Str(INT64 number, const char *fmt); 00604 00605 extern const char * 00606 Ptr_as_String(const void *ptr); 00607 00608 extern const char * 00609 StrCat(const char *name1, const char *name2); 00610 00611 inline const char * 00612 StrCat(const char *s1, const char *s2, const char *s3) 00613 { 00614 return StrCat(s1, StrCat(s2, s3)); 00615 } 00616 00617 extern UINT64 00618 Get_Hash_Value_For_Name(const char *name); 00619 00620 inline UINT32 00621 Name_Hash_Idx(UINT64 hash_value, INT32 tbl_size) 00622 { 00623 return (UINT32)(hash_value % tbl_size); 00624 } 00625 00626 extern STAB_OFFSET 00627 Stab_Full_Split_Offset(const ST *split_out_st); 00628 00629 00630 // Temporary variable information 00631 extern void 00632 Stab_Free_Tmpvars(void); 00633 00634 extern void 00635 Stab_Unlock_All_Tmpvars(void); 00636 00637 extern UINT 00638 Stab_Lock_Tmpvar(TY_IDX ty, void (*declare_tmpvar)(TY_IDX, UINT)); 00639 00640 extern void 00641 Stab_Unlock_Tmpvar(UINT idx); 00642 00643 //*************************************************************************** 00644 00645 #endif /* stab_attr_INCLUDED */ 00646