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 00037 static char *source_file = __FILE__; 00038 00039 #include "dwarf_DST.h" 00040 #include "errors.h" /* in ../common/util */ 00041 00042 00043 /*---------------------------------* 00044 * Macros used for error reporting * 00045 *---------------------------------*/ 00046 00047 #define DST_ASSERT(truth, msg) Is_True(truth, (msg)) 00048 00049 00050 /*------------------------------------------------------------- 00051 * Routine defining the parent->child relation of info entries 00052 *--------------------------------------------------------------*/ 00053 00054 00055 /* Gets a pointer to the child field of "parent", if one exists, 00056 * otherwise NULL is returned. WARNING: The parent->child 00057 * relation is localized to this routine. For any change in this 00058 * relation (e.g. by adding a new node with child attribute to the 00059 * DST specification) a corresponding change should be made to this 00060 * function. 00061 */ 00062 static DST_INFO_IDX * 00063 DST_get_ptr_to_firstChildField(DST_INFO *parent) 00064 { 00065 const DST_ATTR_IDX attr = DST_INFO_attributes(parent); 00066 const DST_flag flag = DST_INFO_flag(parent); 00067 DST_INFO_IDX *field_ptr = NULL; 00068 00069 switch (DST_INFO_tag(parent)) 00070 { 00071 case DW_TAG_compile_unit: 00072 field_ptr = &DST_COMPILE_UNIT_first_child( 00073 DST_ATTR_IDX_TO_PTR(attr, DST_COMPILE_UNIT)); 00074 break; 00075 00076 case DW_TAG_subprogram: 00077 if (DST_IS_memdef(flag)) 00078 field_ptr = &DST_SUBPROGRAM_memdef_first_child( 00079 DST_ATTR_IDX_TO_PTR(attr, DST_SUBPROGRAM)); 00080 else if (DST_IS_declaration(flag)) 00081 field_ptr = &DST_SUBPROGRAM_decl_first_child( 00082 DST_ATTR_IDX_TO_PTR(attr, DST_SUBPROGRAM)); 00083 else 00084 field_ptr = &DST_SUBPROGRAM_def_first_child( 00085 DST_ATTR_IDX_TO_PTR(attr, DST_SUBPROGRAM)); 00086 break; 00087 00088 case DW_TAG_entry_point: 00089 field_ptr = &DST_ENTRY_POINT_first_child( 00090 DST_ATTR_IDX_TO_PTR(attr, DST_ENTRY_POINT)); 00091 break; 00092 00093 case DW_TAG_inlined_subroutine: 00094 field_ptr = &DST_INLINED_SUBROUTINE_first_child( 00095 DST_ATTR_IDX_TO_PTR(attr, DST_INLINED_SUBROUTINE)); 00096 break; 00097 00098 case DW_TAG_common_block: 00099 field_ptr = &DST_COMMON_BLOCK_first_child( 00100 DST_ATTR_IDX_TO_PTR(attr, DST_COMMON_BLOCK)); 00101 break; 00102 00103 case DW_TAG_lexical_block: 00104 field_ptr = &DST_LEXICAL_BLOCK_first_child( 00105 DST_ATTR_IDX_TO_PTR(attr, DST_LEXICAL_BLOCK)); 00106 break; 00107 00108 case DW_TAG_array_type: 00109 field_ptr = &DST_ARRAY_TYPE_first_child( 00110 DST_ATTR_IDX_TO_PTR(attr, DST_ARRAY_TYPE)); 00111 break; 00112 00113 case DW_TAG_structure_type: 00114 field_ptr = &DST_STRUCTURE_TYPE_first_child( 00115 DST_ATTR_IDX_TO_PTR(attr, DST_STRUCTURE_TYPE)); 00116 break; 00117 00118 case DW_TAG_union_type: 00119 field_ptr = &DST_UNION_TYPE_first_child( 00120 DST_ATTR_IDX_TO_PTR(attr, DST_UNION_TYPE)); 00121 break; 00122 00123 case DW_TAG_class_type: 00124 field_ptr = &DST_CLASS_TYPE_first_child( 00125 DST_ATTR_IDX_TO_PTR(attr, DST_CLASS_TYPE)); 00126 break; 00127 00128 case DW_TAG_enumeration_type: 00129 field_ptr = &DST_ENUMERATION_TYPE_first_child( 00130 DST_ATTR_IDX_TO_PTR(attr, DST_ENUMERATION_TYPE)); 00131 break; 00132 00133 case DW_TAG_subroutine_type: 00134 field_ptr = &DST_SUBROUTINE_TYPE_first_child( 00135 DST_ATTR_IDX_TO_PTR(attr, DST_SUBROUTINE_TYPE)); 00136 break; 00137 00138 default: 00139 field_ptr = NULL; 00140 break; 00141 } 00142 return field_ptr; 00143 } /* DST_get_ptr_to_firstChildField */ 00144 00145 00146 /* 00147 #if !(defined(MONGOOSE_BE)) || defined(_STANDALONE_INLINER) || defined(_SUPPORT_IPA) 00148 */ 00149 /* Same as DST_get_ptr_to_childfield(), but for the "last_child" field. 00150 * For any change in this relation (e.g. by adding a new node with 00151 * child attribute to the DST specification) a corresponding change 00152 * should be made to this function. 00153 */ 00154 static DST_INFO_IDX * 00155 DST_get_ptr_to_lastChildField(DST_INFO *parent) 00156 { 00157 const DST_ATTR_IDX attr = DST_INFO_attributes(parent); 00158 const DST_flag flag = DST_INFO_flag(parent); 00159 DST_INFO_IDX *field_ptr = NULL; 00160 00161 switch (DST_INFO_tag(parent)) 00162 { 00163 case DW_TAG_compile_unit: 00164 field_ptr = &DST_COMPILE_UNIT_last_child( 00165 DST_ATTR_IDX_TO_PTR(attr, DST_COMPILE_UNIT)); 00166 break; 00167 00168 case DW_TAG_subprogram: 00169 if (DST_IS_memdef(flag)) 00170 field_ptr = &DST_SUBPROGRAM_memdef_last_child( 00171 DST_ATTR_IDX_TO_PTR(attr, DST_SUBPROGRAM)); 00172 else if (DST_IS_declaration(flag)) 00173 field_ptr = &DST_SUBPROGRAM_decl_last_child( 00174 DST_ATTR_IDX_TO_PTR(attr, DST_SUBPROGRAM)); 00175 else 00176 field_ptr = &DST_SUBPROGRAM_def_last_child( 00177 DST_ATTR_IDX_TO_PTR(attr, DST_SUBPROGRAM)); 00178 break; 00179 00180 case DW_TAG_entry_point: 00181 field_ptr = &DST_ENTRY_POINT_last_child( 00182 DST_ATTR_IDX_TO_PTR(attr, DST_ENTRY_POINT)); 00183 break; 00184 00185 case DW_TAG_inlined_subroutine: 00186 field_ptr = &DST_INLINED_SUBROUTINE_last_child( 00187 DST_ATTR_IDX_TO_PTR(attr, DST_INLINED_SUBROUTINE)); 00188 break; 00189 00190 case DW_TAG_common_block: 00191 field_ptr = &DST_COMMON_BLOCK_last_child( 00192 DST_ATTR_IDX_TO_PTR(attr, DST_COMMON_BLOCK)); 00193 break; 00194 00195 case DW_TAG_lexical_block: 00196 field_ptr = &DST_LEXICAL_BLOCK_last_child( 00197 DST_ATTR_IDX_TO_PTR(attr, DST_LEXICAL_BLOCK)); 00198 break; 00199 00200 case DW_TAG_array_type: 00201 field_ptr = &DST_ARRAY_TYPE_last_child( 00202 DST_ATTR_IDX_TO_PTR(attr, DST_ARRAY_TYPE)); 00203 break; 00204 00205 case DW_TAG_structure_type: 00206 field_ptr = &DST_STRUCTURE_TYPE_last_child( 00207 DST_ATTR_IDX_TO_PTR(attr, DST_STRUCTURE_TYPE)); 00208 break; 00209 00210 case DW_TAG_union_type: 00211 field_ptr = &DST_UNION_TYPE_last_child( 00212 DST_ATTR_IDX_TO_PTR(attr, DST_UNION_TYPE)); 00213 break; 00214 00215 case DW_TAG_class_type: 00216 field_ptr = &DST_CLASS_TYPE_last_child( 00217 DST_ATTR_IDX_TO_PTR(attr, DST_CLASS_TYPE)); 00218 break; 00219 00220 case DW_TAG_enumeration_type: 00221 field_ptr = &DST_ENUMERATION_TYPE_last_child( 00222 DST_ATTR_IDX_TO_PTR(attr, DST_ENUMERATION_TYPE)); 00223 break; 00224 00225 case DW_TAG_subroutine_type: 00226 field_ptr = &DST_SUBROUTINE_TYPE_last_child( 00227 DST_ATTR_IDX_TO_PTR(attr, DST_SUBROUTINE_TYPE)); 00228 break; 00229 00230 default: 00231 field_ptr = NULL; 00232 break; 00233 } 00234 return field_ptr; 00235 } /* DST_get_ptr_to_lastChildField */ 00236 /* 00237 #endif * !MONGOOSE_BE || _STANDALONE_INLINER || _SUPPORT_IPA */ 00238 00239 00240 /*----------------- 00241 * Visible routines 00242 *-----------------*/ 00243 00244 00245 DST_INFO_IDX 00246 DST_first_child(DST_INFO_IDX parent) 00247 { 00248 DST_INFO_IDX *child_ptr; 00249 00250 child_ptr = DST_get_ptr_to_firstChildField(DST_INFO_IDX_TO_PTR(parent)); 00251 if (child_ptr == NULL) 00252 return DST_INVALID_IDX; 00253 else 00254 return *child_ptr; 00255 } 00256 00257 00258 00259 /* 00260 #if !(defined(MONGOOSE_BE)) || defined(_STANDALONE_INLINER) || defined(_SUPPORT_IPA) 00261 */ 00262 DST_INFO_IDX 00263 DST_last_child(DST_INFO_IDX parent) 00264 { 00265 DST_INFO_IDX *child_ptr; 00266 00267 child_ptr = DST_get_ptr_to_lastChildField(DST_INFO_IDX_TO_PTR(parent)); 00268 if (child_ptr == NULL) 00269 return DST_INVALID_IDX; 00270 else 00271 return *child_ptr; 00272 } 00273 00274 00275 /* Appends a child to the end of the list of children (linked by sibling 00276 * indices) for the given "info" record. 00277 */ 00278 void 00279 DST_append_child(DST_INFO_IDX parent, DST_INFO_IDX child) 00280 { 00281 DST_INFO_IDX *last_child_field; 00282 DST_INFO *child_info; 00283 DST_INFO *parent_info = DST_INFO_IDX_TO_PTR(parent); 00284 00285 last_child_field = DST_get_ptr_to_lastChildField(parent_info); 00286 DST_ASSERT(last_child_field != NULL, "Illegal attempt to append DST child"); 00287 00288 if (DST_IS_NULL(*last_child_field)) 00289 { 00290 /* Set the pointer to the first child for this parent */ 00291 *DST_get_ptr_to_firstChildField(parent_info) = child; 00292 } 00293 else 00294 { 00295 /* Append the new child after the last child */ 00296 child_info = DST_INFO_IDX_TO_PTR(*last_child_field); 00297 DST_INFO_sibling(child_info) = child; 00298 } 00299 00300 /* The new child is now the last_child */ 00301 *last_child_field = child; 00302 } 00303 00304 extern "C" { 00305 00306 void 00307 DST_preorder_visit( 00308 DST_INFO_IDX i, 00309 INT32 init_val, 00310 INT32 (*action)(INT32, DST_DW_tag, DST_flag, DST_ATTR_IDX, DST_INFO_IDX)) 00311 { 00312 DST_INFO *info; 00313 DST_INFO_IDX idx, *idx_ptr; 00314 INT32 val; 00315 00316 DST_ASSERT(!DST_IS_NULL(i), "Attempt to visit invalid DST info"); 00317 00318 /* Visit this node */ 00319 info = DST_INFO_IDX_TO_PTR(i); 00320 val = (*action)(init_val, 00321 DST_INFO_tag(info), 00322 DST_INFO_flag(info), 00323 DST_INFO_attributes(info), 00324 i); 00325 00326 /* Now, visit each child */ 00327 idx_ptr = DST_get_ptr_to_firstChildField(info); 00328 if (idx_ptr != NULL) 00329 { 00330 for (idx = *idx_ptr; 00331 !DST_IS_NULL(idx); 00332 idx = DST_INFO_sibling(DST_INFO_IDX_TO_PTR(idx))) 00333 { 00334 DST_preorder_visit(idx, val, action); 00335 } 00336 } 00337 } 00338 00339 } /* extern "C" */ 00340 00341 /* #endif * MONGOOSE_BE || _STANDALONE_INLINER || _SUPPORT_IPA */ 00342 00343