Open64 (mfef90, whirl2f, and IR tools)  TAG: version-openad; SVN changeset: 916
stab_attr.h
Go to the documentation of this file.
00001 /*
00002 
00003   Copyright (C) 2000, 2001 Silicon Graphics, Inc.  All Rights Reserved.
00004 
00005   This program is free software; you can redistribute it and/or modify it
00006   under the terms of version 2 of the GNU General Public License as
00007   published by the Free Software Foundation.
00008 
00009   This program is distributed in the hope that it would be useful, but
00010   WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
00012 
00013   Further, this software is distributed without any warranty that it is
00014   free of the rightful claim of any third person regarding infringement 
00015   or the like.  Any license provided herein, whether implied or 
00016   otherwise, applies only to this software file.  Patent licenses, if 
00017   any, provided herein do not apply to combinations of this program with 
00018   other software, or any other product whatsoever.  
00019 
00020   You should have received a copy of the GNU General Public License along
00021   with this program; if not, write the Free Software Foundation, Inc., 59
00022   Temple Place - Suite 330, Boston MA 02111-1307, USA.
00023 
00024   Contact information:  Silicon Graphics, Inc., 1600 Amphitheatre Pky,
00025   Mountain View, CA 94043, or:
00026 
00027   http://www.sgi.com
00028 
00029   For further information regarding this notice, see:
00030 
00031   http://oss.sgi.com/projects/GenInfo/NoticeExplan
00032 
00033 */
00034 
00035 
00036 #ifndef stab_attr_INCLUDED
00037 #define stab_attr_INCLUDED
00038 /* ====================================================================
00039  * ====================================================================
00040  *
00041  *
00042  * Revision history:
00043  *  07-Mar-95 - Original Version
00044  *
00045  * Description:
00046  *
00047  * Get TY and ST information, beyond that provided through 
00048  * common/com/stab.h.  Also, provide functions to access
00049  * and create identifier name attributes.
00050  *
00051  * Symbol table information
00052  * ------------------------
00053  *
00054  *    FILE_SCOPE_ID:
00055  *       The scope_id given to TY and ST entries that are declared
00056  *       with file-scope.
00057  *
00058  * Reserved names
00059  * --------------
00060  *
00061  *    Stab_Reserved_Ty:
00062  *       TRUE when the given type is from a system file which will
00063  *       be included anyway (e.g. through whirl2c.h).  Do not declare
00064  *       symbols for which this condition is TRUE, since this will
00065  *       lead to non-compilable whirl2c/whirl2f output!
00066  *
00067  *    Stab_Reserved_St:
00068  *       TRUE when the given symbol is from a system file which will
00069  *       be included anyway (e.g. through whirl2c.h).  Do not declare
00070  *       symbols for which this condition is TRUE, since this will
00071  *       lead to non-compilable whirl2c/whirl2f output!
00072  *
00073  * Flag indicating referenced symbols
00074  * ----------------------------------
00075  *
00076  *    Stab_Reset_Referenced_Flag:
00077  *       Will reset this flag for FOR_ALL_LOCAL_SYMBOLS and
00078  *       FOR_ALL_CONSTANTS in the given symbol table.
00079  *
00080  * Type information
00081  * ----------------
00082  *
00083  *    MTYPE:
00084  *       The name "MTYPE" is more intuitive than TYPE_ID as a
00085  *       type for variables that hold elements from the MTYPE
00086  *       enumeration.
00087  *
00088  *    Stab_Identical_Types:
00089  *       Two types are only identical if they have the same qualifiers,
00090  *       compatible kinds, compatible MTYPEs, and identical substructure.
00091  *       ENUM types are treated as scalars.  While constructed types must
00092  *       have identical substructure, we allow more lenient checks for
00093  *       the top-level types:  We can turn off qualifier checks 
00094  *       (check_quals == FALSE); we can treat all scalar values as 
00095  *       identical (check_scalars == FALSE); and we can treat pointers
00096  *       as scalars (ptrs_as_scalars == TRUE).
00097  *
00098  *    Stab_Assignment_Compatible_Types:
00099  *       Similar to Stab_identical_types, but with the added leniency
00100  *       for pointer types (i.e. qualifiers of pointed types)
00101  *       specified in the ANSI/ISO C standard.
00102  *
00103  *    Stab_Is_Element_Type_Of_Array:
00104  *       True if the given etype is an element of the given a(rray)
00105  *       type, or if it is an element of array elements of the array
00106  *       type.
00107  *
00108  *    Stab_Array_Has_Dynamic_Bounds:
00109  *       This routine takes an array type [TODO: handle pointers
00110  *       as arrays at every call site], and returns TRUE if all
00111  *       bounds and stride information is given in terms of constant
00112  *       values; otherwise FALSE will be returned.
00113  *
00114  *    Stab_Get_Mload_Ty:
00115  *       We have very limited information about MLOAD types, since we
00116  *       only keep the base address in the WN node.  This returns the
00117  *       type of the first field in the given struct/union "base" struct
00118  *       at the given offset and of the given (non-zero) size.
00119  *
00120  *    Stab_Mtype_To_Ty:
00121  *       Get the TY of an mtype.
00122  *
00123  *    TY_IS_xxxxx:
00124  *       Inquiries about what kind of type (TY) we are dealing with.
00125  *
00126  * Function types
00127  * --------------
00128  *
00129  *    Func_Return_Type:
00130  *       The return type for a given function-type.  Will be a
00131  *       Void_Type for whirl2c when Func_Return_Character==TRUE,
00132  *       since in C we return CHARACTER strings through an explicit
00133  *       first parameter.
00134  *       
00135  *    Func_Return_Character:
00136  *       TRUE when the given function type returns a Fortran CHARACTER
00137  *       string.  Can only return TRUE in Fortran mode.
00138  *
00139  *    Func_Return_To_Param:
00140  *       TRUE when the given function type returns a value into the
00141  *       location denoted by the first parameter.
00142  *
00143  * Type creation
00144  * -------------
00145  *    Somtimes it may be necessary to create new TY entries beyond
00146  *    those in the symbol-table generated by the compiler-phases,
00147  *    and for these occations we provide the following facilities.
00148  *    After processing of a given symbol table, we must reset any 
00149  *    TY fields to what they were before this translation.
00150  *
00151  *    Stab_Pointer_To:
00152  *       If the given TY has a TY_pointer attribute, then simply
00153  *       return it; otherwise, create a new TY entry and set the
00154  *       TY_pointer attribute of the pointee to point to it.
00155  *
00156  *    Stab_Array_Of:
00157  *       Creates a unique one-dimensional array type with the given
00158  *       number of elements and the given element type.
00159  *
00160  *    Stab_initialize:
00161  *       Record the size of certain tables in the global symtab.  This
00162  *       information is then used later on in function Stab_finalize
00163  *       to reset the tables back to their original size and, thus,
00164  *       undo any additions made to these tables during whirl2c.
00165  *
00166  *    Stab_finalize:
00167  *       Reset certain tables in the global symtab back to their size
00168  *       at the start of whirl2c, thereby undoing any additions made
00169  *       to these tables during whirl2c.
00170  *
00171  *
00172  * Identifier naming utilities
00173  * ---------------------------
00174  *    We operate with a cyclic character buffer for identifier names,
00175  *    where the size of the buffer is a minimum of 1024 characters
00176  *    and at a maximum of 8 times the largest name encountered.  Note 
00177  *    that a call to any of the functions described below may allocate
00178  *    a new name buffer.  Name buffers are allocated from the cyclic
00179  *    character buffer, and a name-buffer may be reused at every 8th
00180  *    allocation.  We guarantee that a name-buffer is valid up until
00181  *    7 subsequent name-buffer allocations, but no longer.  After
00182  *    7 subsequent name-buffer allocations, the name buffer may be
00183  *    reused (overwritten) or even freed up from dynamic memory.  While
00184  *    the results from the calls to the functions provided here may be
00185  *    used to construct identifier names, these results should be saved
00186  *    off into a more permanent buffer area once the names have been
00187  *    constructed.
00188  *
00189  *    Stab_Free_Namebufs:
00190  *       Frees up the memory allocated for string buffers.  This should
00191  *       be done between processing individual PUs.
00192  *
00193  *    Get_Name_Buf_Slot:
00194  *       Allocate a new name-buffer slot of the given size.  It is up
00195  *       to the caller to ensure that no reference is made to 
00196  *       characters outside the allocated slot.  The cyclic name
00197  *       buffer will become at least 8 times the size of this slot,
00198  *       so do not use this as a method for obtaining an arbitrary 
00199  *       temporary memory-pool!
00200  *
00201  *    Number_as_String:
00202  *       Convert the number into an equivalent ASCII character 
00203  *       string representation, using the given <stdio.h> formatting.
00204  *       A maximum of 128 characters will be allocated to hold the
00205  *       resultant string value.  Note that the format must accept
00206  *       a 64 bits integral value.
00207  *
00208  *    Ptr_as_String:
00209  *       Convert the pointer into an equivalent ASCII character 
00210  *       string representation. A maximum of 128 characters will
00211  *       be allocated to hold the resultant string value.
00212  *
00213  *    Concat2_Strings/Concat3_Strings:
00214  *       Concatenate two and three strings, respectively, into
00215  *       a new combined character string.
00216  *
00217  *    Name_Hash_Idx:
00218  *       Using the hash-value returned from Get_Hash_Value_For_Name,
00219  *       this gets an index into the hash-table based on the log(2, 
00220  *       tbl_size) rightmost characters of the name.  For a 
00221  *       tbl_size of 173, the rightmost 2 characters determines 
00222  *       the hash_idx.  For an empty ('\0' or NULL) name, the 
00223  *       hash value and index will be zero
00224  *
00225  * Temporary variable information
00226  * ------------------------------
00227  *    Stab_Free_Tmpvars:
00228  *       This will free up memory associated with the maintenance of
00229  *       temporary variables, and should be called after processing each
00230  *       PU.
00231  *
00232  *    Stab_Lock_Tmpvar:
00233  *       Return an identifying index for a tempvar of the given type.
00234  *       If none existed before-hand, then a new one will be declared
00235  *       locally to the current PU, using the subroutine provided, which
00236  *       declares the temporary variable based on its type and index.
00237  *
00238  *    Stab_Unlock_Tmpvar:
00239  *       Given a tmpvar identifying index, this tmpvar will now become
00240  *       available for other uses.
00241  *
00242  * ====================================================================
00243  * ====================================================================
00244  */
00245 
00246                      /*------ Type Information ------*/
00247                      /*------------------------------*/
00248 
00249 typedef TYPE_ID MTYPE;
00250 
00251 extern BOOL Stab_Identical_Types(TY_IDX t1, 
00252                                  TY_IDX t2, 
00253                                  BOOL   check_quals, 
00254                                  BOOL   check_scalars,
00255                                  BOOL   ptrs_as_scalars);
00256 
00257 extern BOOL Stab_Assignment_Compatible_Types(TY_IDX t1, 
00258                                              TY_IDX t2, 
00259                                              BOOL   check_quals, 
00260                                              BOOL   check_scalars,
00261                                              BOOL   ptrs_as_scalars);
00262 
00263 extern BOOL Stab_Is_Element_Type_Of_Array(TY_IDX atype, TY_IDX etype);
00264 
00265 extern BOOL Stab_Array_Has_Dynamic_Bounds(TY_IDX ty);
00266 extern BOOL Stab_Is_Assumed_Sized_Array(TY_IDX ty);
00267 extern BOOL Stab_Is_Equivalenced_Struct(TY_IDX ty);
00268 
00269 extern TY_IDX Stab_Get_Mload_Ty(TY_IDX base,
00270                                 STAB_OFFSET offset,
00271                                 STAB_OFFSET size);
00272 
00273 inline TY_IDX Stab_Mtype_To_Ty(TYPE_ID mtype) { return Be_Type_Tbl(mtype); }
00274 
00275 inline BOOL TY_Is_Pointer(TY_IDX ty)
00276 {
00277    return (TY_kind(ty) == KIND_POINTER && !TY_is_f90_pointer(ty));
00278 } /* TY_Is_Pointer */
00279 
00280 inline BOOL TY_Is_Array(TY_IDX ty)
00281 {
00282    return TY_kind(ty) == KIND_ARRAY;
00283 } /* TY_Is_Array */
00284 
00285 inline BOOL TY_Is_Function(TY_IDX ty)
00286 {
00287    return TY_kind(ty) == KIND_FUNCTION;
00288 } /* TY_Is_Function */
00289 
00290 inline BOOL TY_Is_Struct(TY_IDX ty)
00291 {
00292    return TY_kind(ty) == KIND_STRUCT && !TY_is_union(ty);
00293 } /* TY_Is_Struct */
00294 
00295 inline BOOL TY_Is_Union(TY_IDX ty)
00296 {
00297    return TY_kind(ty) == KIND_STRUCT && TY_is_union(ty);
00298 } /* TY_Is_Union */
00299 
00300 inline BOOL TY_Is_Structured(TY_IDX ty)
00301 {
00302    return TY_kind(ty) == KIND_STRUCT;
00303 } /* TY_Is_Structured */
00304 
00305 inline BOOL TY_Is_String(TY_IDX ty)
00306 {
00307    return TY_mtype(ty) == MTYPE_STRING;
00308 } /* TY_Is_String */
00309 
00310 inline BOOL TY_Is_Integral(TY_IDX ty)
00311 {
00312    return (MTYPE_type_class(TY_mtype(ty)) & MTYPE_CLASS_INTEGER) != 0;
00313 } /* TY_Is_Integral */
00314 
00315 inline BOOL TY_Is_Quad(TY_IDX ty)
00316 {
00317    return TY_kind(ty) == KIND_SCALAR && TY_mtype(ty) == MTYPE_FQ;
00318 } /* TY_Is_Quad */
00319 
00320 inline BOOL TY_Is_Complex(TY_IDX ty)
00321 {
00322    return TY_kind(ty) == KIND_SCALAR && (TY_mtype(ty) == MTYPE_C4 ||
00323                                          TY_mtype(ty) == MTYPE_C8 ||
00324                                          TY_mtype(ty) == MTYPE_CQ);
00325 } /* TY_Is_Complex */
00326 
00327 inline BOOL TY_Is_Array_Or_Function(TY_IDX ty)
00328 {
00329    return ty != 0 && (TY_Is_Function(ty) || TY_Is_Array(ty));
00330 } /* TY_Is_Array_Or_Function */
00331 
00332 inline BOOL TY_Is_Scalar(TY_IDX ty)
00333 {
00334    return TY_kind(ty) == KIND_SCALAR;
00335 } /* TY_Is_Scalar */
00336 
00337 inline BOOL TY_Is_Pointer_Or_Scalar(TY_IDX ty)
00338 {
00339    return (TY_Is_Scalar(ty) || (TY_Is_Pointer(ty)&&!TY_is_f90_pointer(ty)));
00340 } /* TY_Is_Pointer_Or_Scalar */
00341 
00342 inline BOOL TY_Is_Array_Of_Chars(TY_IDX ty)
00343 {
00344    return TY_Is_Array(ty) &&
00345           TY_AR_ndims(ty) == 1 &&
00346           TY_Is_Integral(TY_AR_etype(ty)) &&
00347           TY_size(TY_AR_etype(ty)) == 1;
00348 } /* TY_Is_Array_Of_Chars */
00349 
00350 
00351 /* fortran FEs now generate U1 arrays for chars */
00352 
00353 inline BOOL TY_Is_Array_Of_UChars(TY_IDX ty)
00354 {
00355    return TY_Is_Array(ty) &&
00356           TY_AR_ndims(ty) == 1 &&
00357           TY_mtype(TY_AR_etype(ty)) == MTYPE_U1 ;
00358 } /* TY_Is_Array_Of_Chars */
00359 
00360 inline BOOL TY_Is_Preg_Type(TY_IDX ty)
00361 {
00362    /* Return True if ty is a valid type for pseudo registers;
00363       return False otherwise. */
00364    return TY_Is_Pointer_Or_Scalar(ty);
00365 } /* TY_Is_Preg_Type */
00366 
00367 inline BOOL FLD_Is_Bitfield(FLD_HANDLE fld, FLD_HANDLE next_fld,
00368                             INT64 max_size) 
00369 {
00370    /* fld must not be a member of a union! */
00371    return !FLD_equivalence(fld) &&
00372           (FLD_is_bit_field(fld) ||
00373            (next_fld.Is_Null () && max_size < TY_size(FLD_type(fld))) ||
00374            (!next_fld.Is_Null() && !FLD_equivalence(next_fld) &&
00375             FLD_ofst(next_fld) - FLD_ofst(fld) < TY_size(FLD_type(fld))));
00376 } /* FLD_Is_Bitfield */
00377 
00378                   /*------ Symbol table Information ------*/
00379                   /*--------------------------------------*/
00380 
00381 inline BOOL Stab_Is_Valid_Base(const ST *st)
00382 {
00383    return (ST_base(st) != NULL &&
00384            ST_base(st) != (st) &&
00385            ST_sym_class(ST_base(st)) != CLASS_BLOCK /* cg generated */ );
00386 } /* Stab_Is_Valid_Base */
00387 
00388 inline BOOL Stab_Is_Common_Block(const ST *st)
00389 {
00390    return ((ST_sclass(st) == SCLASS_COMMON ||
00391             ST_sclass(st) == SCLASS_DGLOBAL) &&
00392            TY_Is_Structured(ST_type(st)));
00393 } /* Stab_Is_Common_Block */
00394       
00395 inline BOOL Stab_Is_Equivalence_Block(const ST *st)
00396 {
00397    return (ST_sym_class(st) == CLASS_VAR                 &&
00398            TY_Is_Structured(ST_type(st))                 &&
00399            ST_sclass(st) != SCLASS_COMMON                &&
00400            ! TY_flist(Ty_Table[ST_type(st)]).Is_Null ()  &&
00401            FLD_equivalence(TY_fld(Ty_Table[ST_type(st)])));
00402 } /* Stab_Is_Equivalence_Block */
00403 
00404 inline BOOL Stab_Is_Based_At_Common_Or_Equivalence(const ST *st)
00405 {
00406    return (Stab_Is_Valid_Base(st) &&
00407            (Stab_Is_Common_Block(ST_base(st)) ||
00408             Stab_Is_Equivalence_Block(ST_base(st))));
00409 } /* Stab_Is_Based_At_Common_Or_Equivalence */
00410 
00411 inline BOOL Stab_No_Linkage(const ST *st)
00412 {
00413    return (ST_sclass(st) == SCLASS_AUTO   ||
00414            ST_sclass(st) == SCLASS_FORMAL ||
00415            ST_sclass(st) == SCLASS_FORMAL_REF);
00416 } /* Stab_No_Linkage */
00417 
00418 inline BOOL Stab_External_Linkage(const ST *st)
00419 {
00420    return (!Stab_No_Linkage(st)                   &&
00421            ST_sclass(st) != SCLASS_PSTATIC        &&
00422            ST_sclass(st) != SCLASS_FSTATIC        &&
00423            ST_sclass(st) != SCLASS_CPLINIT        &&
00424            ST_sclass(st) != SCLASS_EH_REGION      &&
00425            ST_sclass(st) != SCLASS_EH_REGION_SUPP &&
00426            ST_sclass(st) != SCLASS_DISTR_ARRAY);
00427 } /* Stab_External_Linkage */
00428 
00429 inline BOOL Stab_External_Def_Linkage(const ST *st)
00430 {
00431    return (Stab_External_Linkage(st) && ST_sclass(st) != SCLASS_EXTERN);
00432 } /* Stab_External_Def_Linkage */
00433 
00434 inline BOOL Stab_Identical_Quals(TY_IDX t1, TY_IDX t2)
00435 {
00436    return (TY_is_volatile(t1) == TY_is_volatile(t2) &&
00437            TY_is_restrict(t1) == TY_is_restrict(t2) &&
00438            TY_is_const(t1) == TY_is_const(t2));
00439 } /* Stab_Identical_Quals */
00440 
00441 inline BOOL Stab_Assign_Compatible_Pointer_Quals(TY_IDX t1, TY_IDX t2)
00442 {
00443    return ((TY_is_volatile(t2)? TY_is_volatile(t1) : TRUE) &&
00444            (TY_is_restrict(t2)? TY_is_restrict(t1) : TRUE) &&
00445            (TY_is_const(t2)?    TY_is_const(t1) : TRUE));
00446 } /* Stab_Assign_Compatible_Pointer_Quals */
00447 
00448 
00449                   /*----- Reserved Names Information -----*/
00450                   /*--------------------------------------*/
00451 
00452 extern BOOL Stab_Reserved_Ty(TY_IDX ty);
00453 extern BOOL Stab_Reserved_St(const ST *st);
00454 
00455                   /*------- Referenced Information -------*/
00456                   /*--------------------------------------*/
00457 
00458 extern void Stab_Reset_Referenced_Flag(SYMTAB_IDX symtab);
00459    
00460 
00461 
00462                /*------ Obtaining pointer/array types ------*/
00463                /*-------------------------------------------*/
00464 
00465 inline TY_IDX
00466 Stab_Pointer_To(TY_IDX pointee)          { return Make_Pointer_Type(pointee); }
00467 
00468 
00469 extern TY_IDX Stab_Array_Of(TY_IDX etype, mINT64 num_elts) ;
00470 
00471 extern void Stab_initialize(void);
00472 extern void Stab_finalize(void);
00473 extern void Stab_initialize_flags(void) ;
00474 extern void Stab_finalize_flags(void) ;
00475 
00476 
00477                  /*------ Name manipulation ------*/
00478                  /*-------------------------------*/
00479 
00480 extern void Stab_Free_Namebufs(void);
00481 extern char *Get_Name_Buf_Slot(UINT size);
00482 extern const char *Number_as_String(INT64 number, const char *fmt);
00483 extern const char *Ptr_as_String(const void *ptr);
00484 extern const char *Concat2_Strings(const char *name1, const char *name2);
00485 
00486 inline const char *Concat3_Strings(const char *name1,
00487                                    const char *name2,
00488                                    const char *name3)
00489 {
00490    return Concat2_Strings(name1, Concat2_Strings(name2, name3));
00491 } /* Concat3_Strings */
00492 
00493 extern UINT64 Get_Hash_Value_For_Name(const char *name);
00494 
00495 inline UINT32 Name_Hash_Idx(UINT64 hash_value, INT32 tbl_size)
00496 {
00497    return (UINT32)(hash_value % tbl_size);
00498 } /* Name_Hash_Idx */
00499 
00500 extern STAB_OFFSET Stab_Full_Split_Offset(const ST *split_out_st);
00501 
00502 
00503              /*---- temporary variable information -----*/
00504              /*-----------------------------------------*/
00505 
00506 extern void Stab_Free_Tmpvars(void);
00507 extern void Stab_Unlock_All_Tmpvars(void);
00508 extern UINT Stab_Lock_Tmpvar(TY_IDX ty, void (*declare_tmpvar)(TY_IDX, UINT));
00509 extern void Stab_Unlock_Tmpvar(UINT idx);
00510 
00511 #endif /* stab_attr_INCLUDED */
00512 
00513 
00514 
00515 
00516 
00517 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines