Open64 (mfef90, whirl2f, and IR tools)
TAG: version-openad; SVN changeset: 916
|
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 /* -*-Mode: c++;-*- (Tell emacs to use c++ mode) */ 00037 00038 #ifndef symtab_idx_INCLUDED 00039 #define symtab_idx_INCLUDED 00040 00041 #ifndef ERRORS_INCLUDED 00042 #include "errors.h" // for Is_True assertion checking 00043 #endif 00044 00045 // indices to various tables 00046 00047 typedef mUINT32 ST_IDX; // idx to symbol table 00048 typedef mUINT32 TY_IDX; // idx to type table 00049 typedef mUINT32 FLD_IDX; // idx to struct field table 00050 typedef mUINT32 ARB_IDX; // idx to array bound table 00051 typedef mUINT32 TYLIST_IDX; // idx to function parm. list table 00052 typedef mUINT32 PU_IDX; // idx to pu table 00053 typedef mUINT32 TARGET_INFO_IDX; // idx to target_info table 00054 typedef mUINT32 TCON_IDX; // idx to tcon table 00055 typedef mUINT32 LABEL_IDX; // idx to label table 00056 typedef mUINT32 PREG_IDX; // idx to preg table 00057 typedef mUINT32 ST_ATTR_IDX; // idx to st_attr table 00058 typedef mUINT32 BLK_IDX; // idx to block table 00059 typedef mUINT32 INITO_IDX; // idx to initialized object table 00060 typedef mUINT32 INITV_IDX; // idx to initial value table 00061 typedef mUINT32 STR_IDX; // idx to string table 00062 typedef mUINT8 SYMTAB_IDX; // idx to scope array 00063 00064 // Reserved values for each index type. 00065 00066 static const ST_IDX ST_IDX_ZERO = 0; 00067 static const TY_IDX TY_IDX_ZERO = 0; 00068 static const FLD_IDX FLD_IDX_ZERO = 0; 00069 static const ARB_IDX ARB_IDX_ZERO = 0; 00070 static const TYLIST_IDX TYLIST_IDX_ZERO = 0; 00071 static const PU_IDX PU_IDX_ZERO = 0; 00072 static const TARGET_INFO_IDX TARGET_INFO_IDX_ZERO = 0; 00073 static const TCON_IDX TCON_IDX_ZERO = 0; 00074 static const LABEL_IDX LABEL_IDX_ZERO = 0; 00075 static const PREG_IDX PREG_IDX_ZERO = 0; 00076 static const ST_ATTR_IDX ST_ATTR_IDX_ZERO = 0; 00077 static const BLK_IDX BLK_IDX_ZERO = 0; 00078 static const INITO_IDX INITO_IDX_ZERO = 0; 00079 static const INITV_IDX INITV_IDX_ZERO = 0; 00080 static const STR_IDX STR_IDX_ZERO = 0; 00081 static const SYMTAB_IDX SYMTAB_IDX_ZERO = 0; 00082 00083 00084 // forward declarations 00085 struct ST; 00086 struct TY; 00087 struct FLD; 00088 struct ARB; 00089 struct PU; 00090 struct TCON; 00091 struct LABEL; 00092 struct PREG; 00093 struct ST_ATTR; 00094 struct INITO; 00095 struct INITV; 00096 struct SCOPE; 00097 struct FILE_INFO; 00098 00099 // index to a symbol table entry 00100 // 00101 // It should really be: 00102 // 00103 // struct ST_IDX { 00104 // mUINT32 index : 24; 00105 // mUINT32 level : 8; 00106 // }; 00107 // 00108 // However, until we generate good code for passing small struct as function 00109 // parameter, we need to keep it as an INT for efficiency. 00110 00111 template<class INDEX_TYPE, class LEVEL_INDEX_TYPE> 00112 inline LEVEL_INDEX_TYPE Extract_level8(INDEX_TYPE idx, LEVEL_INDEX_TYPE *) 00113 { 00114 return idx & 0xff; 00115 } 00116 00117 template<class INDEX_TYPE> 00118 inline UINT32 Extract_index24(INDEX_TYPE idx) { return idx >> 8; } 00119 00120 inline SYMTAB_IDX 00121 ST_IDX_level (ST_IDX st_idx) 00122 { 00123 return Extract_level8(st_idx, (SYMTAB_IDX *) 0); 00124 } 00125 00126 inline UINT32 00127 ST_IDX_index (ST_IDX st_idx) { return Extract_index24(st_idx); } 00128 00129 inline ST_IDX 00130 make_ST_IDX (UINT index, SYMTAB_IDX level) { 00131 return (ST_IDX)((index << 8)|level); 00132 } 00133 00134 // similar to ST_IDX, INITO_IDX consists of a level and index 00135 inline SYMTAB_IDX 00136 INITO_IDX_level (INITO_IDX inito_idx) 00137 { 00138 return Extract_level8(inito_idx, (SYMTAB_IDX *) 0); 00139 } 00140 00141 inline UINT32 00142 INITO_IDX_index (INITO_IDX inito_idx) { return Extract_index24(inito_idx); } 00143 00144 inline INITO_IDX 00145 make_INITO_IDX (UINT index, SYMTAB_IDX level) { 00146 return (INITO_IDX) ((index << 8)|level); 00147 } 00148 00149 template<class ENTRY_TYPE, 00150 class INDEX_TYPE, 00151 class LEVEL_INDEX_TYPE, 00152 class LEVEL_CONTAINER_TYPE, 00153 LEVEL_CONTAINER_TYPE *level_container_ptr, 00154 class LEVEL_MEMBER_ACCESSOR> 00155 struct TABLE_INDEXED_BY_LEVEL8_AND_INDEX24 { 00156 ENTRY_TYPE &operator[](INDEX_TYPE idx) 00157 { 00158 LEVEL_INDEX_TYPE level = Extract_level8(idx, (LEVEL_INDEX_TYPE *) 0); 00159 UINT32 index = Extract_index24(idx); 00160 return LEVEL_MEMBER_ACCESSOR()(level_container_ptr, level)->Entry(index); 00161 } 00162 00163 ENTRY_TYPE &operator()(LEVEL_CONTAINER_TYPE *lev_container_ptr, 00164 INDEX_TYPE idx) 00165 { // explicit version 00166 LEVEL_INDEX_TYPE level = Extract_level8(idx, (LEVEL_INDEX_TYPE *) 0); 00167 UINT32 index = Extract_index24(idx); 00168 return LEVEL_MEMBER_ACCESSOR()(lev_container_ptr, level)->Entry(index); 00169 } 00170 00171 ENTRY_TYPE &operator()(LEVEL_INDEX_TYPE level, UINT32 index) 00172 { 00173 #ifndef __GNU_BUG_WORKAROUND 00174 Is_True(LEVEL_MEMBER_ACCESSOR()(level_container_ptr, level) != NULL, 00175 ("Uninitialized ST_IDX-indexed table")); 00176 #endif 00177 return LEVEL_MEMBER_ACCESSOR()(level_container_ptr, level)->Entry(index); 00178 } 00179 00180 ENTRY_TYPE &operator()(LEVEL_CONTAINER_TYPE *lev_container_ptr, 00181 LEVEL_INDEX_TYPE level, UINT32 index) 00182 { // explicit version 00183 #ifndef __GNU_BUG_WORKAROUND 00184 Is_True(LEVEL_MEMBER_ACCESSOR()(lev_container_ptr, level) != NULL, 00185 ("Uninitialized ST_IDX-indexed table")); 00186 #endif 00187 return LEVEL_MEMBER_ACCESSOR()(lev_container_ptr, level)->Entry(index); 00188 } 00189 }; 00190 00191 // index to a type table entry 00192 // 00193 // Same reason as in ST_IDX, we define TY_IDX as an INT instead of a small 00194 // struct. 00195 // 00196 // Logically, it should be: 00197 // 00198 // struct TY_IDX { 00199 // UINT index : 24; 00200 // UINT _restrict : 1; 00201 // UINT _volatile : 1; 00202 // UINT _const : 1; 00203 // UINT _align : 5; 00204 // }; 00205 00206 00207 00208 00209 00210 const UINT32 TY_RESTRICT = 0x00000080; // restrict type qualifier 00211 const UINT32 TY_VOLATILE = 0x00000040; // volatile type qualifier 00212 const UINT32 TY_CONST = 0x00000020; // const type qualifier 00213 const UINT32 TY_ALIGN = 0x0000001f; // bit mask for alignment field 00214 00215 /* Old TY_IDX accessors */ 00216 inline UINT32 TY_IDX_index (TY_IDX ty_idx) { return ty_idx >> 8; } 00217 inline void Set_TY_IDX_index (TY_IDX &ty_idx, UINT32 index) 00218 { 00219 ty_idx = (ty_idx & 0xff) | (index << 8); 00220 } 00221 00222 inline TY_IDX 00223 make_TY_IDX (UINT32 index) { return index << 8; } 00224 00225 00226 /* inline UINT32 TY_IDX_index (TY_IDX ty_idx) { return ty_idx >> 9; } */ 00227 /* inline void Set_TY_IDX_index (TY_IDX &ty_idx, UINT32 index) */ 00228 /* { */ 00229 /* ty_idx = (ty_idx & 0x1ff) | (index << 9); */ 00230 /* } */ 00231 00232 /* inline TY_IDX */ 00233 /* make_TY_IDX (UINT32 index) { return index << 9; } */ 00234 /* inline BOOL TY_is_shared (TY_IDX ty_idx) { return ty_idx & TY_SHARED; } */ 00235 /* inline void Set_TY_is_shared (TY_IDX &ty_idx) { ty_idx |= TY_SHARED; } */ 00236 /* inline void Cleart_TY_is_shared (TY_IDX &ty_idx) { ty_idx &= ~TY_SHARED; } */ 00237 00238 inline BOOL TY_is_const (TY_IDX ty_idx) { return ty_idx & TY_CONST; } 00239 inline void Set_TY_is_const (TY_IDX &ty_idx) { ty_idx |= TY_CONST; } 00240 inline void Clear_TY_is_const (TY_IDX &ty_idx) { ty_idx &= ~TY_CONST; } 00241 00242 inline BOOL TY_is_volatile (TY_IDX ty_idx) { return ty_idx & TY_VOLATILE;} 00243 inline void Set_TY_is_volatile (TY_IDX &ty_idx) { ty_idx |= TY_VOLATILE; } 00244 inline void Clear_TY_is_volatile (TY_IDX &ty_idx){ ty_idx &= ~TY_VOLATILE; } 00245 00246 inline BOOL TY_is_restrict (TY_IDX ty_idx) { return ty_idx & TY_RESTRICT;} 00247 inline void Set_TY_is_restrict (TY_IDX &ty_idx) { ty_idx |= TY_RESTRICT; } 00248 inline void Clear_TY_is_restrict (TY_IDX &ty_idx){ ty_idx &= ~TY_RESTRICT; } 00249 00250 // TY_align_exp returns the exponent part of the alignment. That is, the 00251 // true alignment in bytes is 2 to the power of TY_align_exp () 00252 inline UINT TY_align_exp (TY_IDX ty_idx) { return ty_idx & TY_ALIGN; } 00253 inline void Set_TY_align_exp (TY_IDX &ty_idx, UINT exp) { 00254 ty_idx = (ty_idx & ~TY_ALIGN) | (exp & TY_ALIGN); 00255 } 00256 00257 inline UINT TY_align (TY_IDX ty_idx) { return 1 << (ty_idx & TY_ALIGN); } 00258 inline void Set_TY_align (TY_IDX &ty_idx, UINT32 align) { 00259 extern UINT32 TY_log_base2 (UINT32 align); 00260 00261 if (align & 0x3f) 00262 Set_TY_align_exp (ty_idx, 00263 (align & 0x7) ? (align >> 1) : 3 + (align >> 4)); 00264 else 00265 Set_TY_align_exp (ty_idx, TY_log_base2 (align)); 00266 } 00267 00268 00269 #endif /* symtab_idx_INCLUDED */ 00270 00271