00001 /* 00002 * Copyright 2005-2007 NVIDIA Corporation. All rights reserved. 00003 */ 00004 00005 /* 00006 00007 Copyright (C) 2000, 2001 Silicon Graphics, Inc. All Rights Reserved. 00008 00009 This program is free software; you can redistribute it and/or modify it 00010 under the terms of version 2 of the GNU General Public License as 00011 published by the Free Software Foundation. 00012 00013 This program is distributed in the hope that it would be useful, but 00014 WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00016 00017 Further, this software is distributed without any warranty that it is 00018 free of the rightful claim of any third person regarding infringement 00019 or the like. Any license provided herein, whether implied or 00020 otherwise, applies only to this software file. Patent licenses, if 00021 any, provided herein do not apply to combinations of this program with 00022 other software, or any other product whatsoever. 00023 00024 You should have received a copy of the GNU General Public License along 00025 with this program; if not, write the Free Software Foundation, Inc., 59 00026 Temple Place - Suite 330, Boston MA 02111-1307, USA. 00027 00028 Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pky, 00029 Mountain View, CA 94043, or: 00030 00031 http://www.sgi.com 00032 00033 For further information regarding this notice, see: 00034 00035 http://oss.sgi.com/projects/GenInfo/NoticeExplan 00036 00037 */ 00038 00039 00040 #ifndef dwarf_DST_mem_INCLUDED 00041 #define dwarf_DST_mem_INCLUDED 00042 #ifdef __cplusplus 00043 extern "C" { 00044 #endif 00045 00046 00047 00048 #ifdef _KEEP_RCS_ID 00049 static char *dwarf_DST_mem_rcs_id = "$Source: /scratch/mee/Patch0002-taketwo/kpro64-pending/common/com/SCCS/s.dwarf_DST_mem.h $ $Revision: 1.2 $"; 00050 #endif /* _KEEP_RCS_ID */ 00051 00052 #if 0 00053 #include "defs.h" 00054 #else 00055 #include "workaround.h" 00056 #endif 00057 00058 /*-------------------------------------------------* 00059 * Definition of DST_IDX (index to allocated data) * 00060 *-------------------------------------------------*/ 00061 00062 00063 typedef mINT32 DST_BYTE_IDX; 00064 typedef mINT32 DST_BLOCK_IDX; 00065 00066 00067 typedef struct DST_idx 00068 { 00069 DST_BYTE_IDX byte_idx; 00070 DST_BLOCK_IDX block_idx; 00071 } DST_IDX; 00072 00073 #define DST_INVALID_BLOCK_IDX -1 00074 #define DST_INVALID_BYTE_IDX -1 00075 #define DST_FOREIGN_BLOCK_IDX -2 00076 #define DST_FOREIGN_BYTE_IDX -2 00077 00078 00079 /* Represents a NULL DST_IDX value. Always initialize a declared 00080 * DST_IDX with DST_INVALID_IDX or DST_INVALID_INIT!! 00081 */ 00082 extern const DST_IDX DST_INVALID_IDX; 00083 #define DST_INVALID_INIT {DST_INVALID_BYTE_IDX, DST_INVALID_BLOCK_IDX} 00084 #define DST_FOREIGN_INIT {DST_FOREIGN_BYTE_IDX, DST_FOREIGN_BLOCK_IDX} 00085 00086 00087 /* Use this macro to test for a NULL DST_IDX value 00088 */ 00089 #define DST_IS_NULL(i) (((i).byte_idx == DST_INVALID_BYTE_IDX) ||\ 00090 ((i).block_idx == DST_INVALID_BLOCK_IDX)) 00091 00092 /* Use this macro to test for a FOREIGN DST_IDX value */ 00093 #define DST_IS_FOREIGN_OBJ(i) (((i).byte_idx == DST_FOREIGN_BYTE_IDX) || \ 00094 ((i).block_idx == DST_FOREIGN_BLOCK_IDX)) 00095 00096 00097 #ifdef __cplusplus 00098 00099 // == != operators can conflict with windows.h, 00100 // so just define an explicit equality routine. 00101 inline BOOL DST_ARE_EQUAL (const DST_IDX x, const DST_IDX y) { 00102 return x.byte_idx == y.byte_idx && x.block_idx == y.block_idx; 00103 } 00104 00105 inline bool operator < (const DST_IDX& x, const DST_IDX& y) { 00106 return (x.block_idx < y.block_idx) || 00107 (x.block_idx == y.block_idx && x.byte_idx < y.byte_idx); 00108 } 00109 00110 inline DST_IDX make_DST_IDX(DST_BYTE_IDX byte_idx, DST_BLOCK_IDX block_idx) { 00111 DST_idx result; 00112 result.byte_idx = byte_idx; 00113 result.block_idx = block_idx; 00114 return result; 00115 } 00116 00117 // Hash function for DST indices. 00118 struct DST_IDX_hash { 00119 size_t operator()(DST_IDX idx) const { 00120 return (static_cast<size_t>(idx.block_idx) << 10) + 00121 static_cast<size_t>(idx.byte_idx); 00122 } 00123 }; 00124 00125 #endif 00126 00127 /*----------------------------* 00128 * General Purpose Functions * 00129 *----------------------------*/ 00130 00131 00132 /* Converts an index to a char pointer 00133 */ 00134 extern char * DST_idx_to_string(DST_IDX); 00135 00136 /*-----------------------* 00137 * General purpose types * 00138 *-----------------------*/ 00139 00140 00141 /* The different kinds of a block of bytes. WARNING: Any changes to 00142 * this structure must result in similar changes in the .c file. The 00143 * order of the constants is paramount for the implementation in 00144 * dwarf_DST_mem.c. 00145 */ 00146 typedef enum DST_block_kind 00147 { 00148 DST_include_dirs_block = 0, /* For include directory path names */ 00149 DST_file_names_block = 1, /* For file names */ 00150 DST_macro_info_block = 2, /* For macro information */ 00151 DST_file_scope_block = 3, /* For file-scope symbols */ 00152 DST_local_scope_block = 4, /* For local-scope symbols */ 00153 DST_noblock = 5 /* Invalid block */ 00154 } DST_BLOCK_KIND; 00155 00156 /* DST_TYPE is a dummy pointer type to be used where USE_DST_INTERNALS 00157 * is not defined */ 00158 typedef void* DST_TYPE; 00159 extern DST_TYPE Current_DST; 00160 00161 #ifdef USE_DST_INTERNALS 00162 00163 typedef struct block_header_struct { 00164 DST_BLOCK_KIND kind; 00165 mINT32 size; 00166 mINT32 allocsize; 00167 char *offset; 00168 } block_header; 00169 00170 typedef struct dst_rec { 00171 block_header *dst_blocks; /* array of block headers */ 00172 block_header *current_dst; /* the current dst header */ 00173 DST_BLOCK_IDX last_block_header; 00174 DST_BLOCK_IDX max_block_header; 00175 DST_BLOCK_IDX current_block_header; 00176 DST_BLOCK_IDX block_list[DST_noblock]; 00177 } DST_Type; 00178 00179 #define FOREACH_DST_BLOCK(i) \ 00180 for (i = 0; i <= ((DST_Type *)Current_DST)->last_block_header; i++) 00181 00182 #endif /* USE_DST_INTERNALS */ 00183 00184 00185 /* Create a new DST. For backward-compatibility this is called automatically 00186 * from DST_Init when Current_DST is NULL. For IPA, this function must be 00187 * called explicitly for each input file. 00188 */ 00189 extern DST_TYPE 00190 New_DST (void); 00191 00192 /* Initialize the DST memory system. If start == NULL, then initializes 00193 * with no blocks allocated. Else it initializes with num_blocks allocated, 00194 * starting at the start address. 00195 */ 00196 extern void 00197 DST_Init (char *start, INT32 num_blocks); 00198 00199 /* Allocates the first block of a new block-list and makes it the current 00200 * block for DST_allocate(). This function can AT MOST be called once for 00201 * each of: DST_include_dirs_blocks, DST_file_names_blocks, 00202 * DST_macro_info_block, and DST_file_scope_blocks. It should be called 00203 * for each Program Unit (PU), such that the entries belonging to a PU 00204 * will be in a separate block-list from the entries belonging to other 00205 * PUs. Never call this function with DST_noblock! 00206 */ 00207 extern void 00208 DST_begin_block(DST_BLOCK_KIND block_kind); 00209 00210 00211 /* Resets the current block to become the last block in the block-list 00212 * into which idx points. 00213 */ 00214 extern void 00215 DST_return_to_block(DST_IDX idx); 00216 00217 00218 /* Allocates the given number of bytes in the current memory block, 00219 * aligned according to the given align. Will add a new block to 00220 * the block list, when there is not enough space left in the current 00221 * block. DST_begin_block() must have been called at least once. 00222 * Returns an index to the newly allocated memory area. 00223 */ 00224 extern DST_IDX 00225 DST_allocate(INT32 bytes, INT32 align); 00226 00227 00228 /* Returns an index to the first DST_INCLUDE_DIR entry, which may be 00229 * DST_INVALID_IDX in the abscence of any DST_INCLUDE_DIR entries. 00230 */ 00231 extern DST_IDX 00232 DST_get_include_dirs(void); 00233 00234 00235 /* Returns an index to the first DST_FILE_NAME entry, which may be 00236 * DST_INVALID_IDX in the abscence of any DST_FILE_NAME entries. 00237 */ 00238 extern DST_IDX 00239 DST_get_file_names(void); 00240 00241 00242 /* Returns an index to the first DST_MACRO_INFO entry, which may be 00243 * DST_INVALID_IDX in the abscence of any DST_MACRO_INFO entries. 00244 */ 00245 extern DST_IDX 00246 DST_get_macro_info(void); 00247 00248 00249 /* Returns an index to the DST_COMPILE_UNIT entry, which may be 00250 * DST_INVALID_IDX in the abscence of any DST_COMPILE_UNIT entry. 00251 */ 00252 extern DST_IDX 00253 DST_get_compile_unit(void); 00254 00255 #ifdef __cplusplus 00256 } 00257 #endif 00258 #endif /* dwarf_DST_mem_INCLUDED */
1.5.6