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 #include "defs.h" 00053 00054 /*-------------------------------------------------* 00055 * Definition of DST_IDX (index to allocated data) * 00056 *-------------------------------------------------*/ 00057 00058 00059 typedef mINT32 DST_BYTE_IDX; 00060 typedef mINT32 DST_BLOCK_IDX; 00061 00062 00063 typedef struct DST_idx 00064 { 00065 DST_BYTE_IDX byte_idx; 00066 DST_BLOCK_IDX block_idx; 00067 } DST_IDX; 00068 00069 #define DST_INVALID_BLOCK_IDX -1 00070 #define DST_INVALID_BYTE_IDX -1 00071 #define DST_FOREIGN_BLOCK_IDX -2 00072 #define DST_FOREIGN_BYTE_IDX -2 00073 00074 00075 /* Represents a NULL DST_IDX value. Always initialize a declared 00076 * DST_IDX with DST_INVALID_IDX or DST_INVALID_INIT!! 00077 */ 00078 extern const DST_IDX DST_INVALID_IDX; 00079 #define DST_INVALID_INIT {DST_INVALID_BYTE_IDX, DST_INVALID_BLOCK_IDX} 00080 #define DST_FOREIGN_INIT {DST_FOREIGN_BYTE_IDX, DST_FOREIGN_BLOCK_IDX} 00081 00082 00083 /* Use this macro to test for a NULL DST_IDX value 00084 */ 00085 #define DST_IS_NULL(i) (((i).byte_idx == DST_INVALID_BYTE_IDX) ||\ 00086 ((i).block_idx == DST_INVALID_BLOCK_IDX)) 00087 00088 /* Use this macro to test for a FOREIGN DST_IDX value */ 00089 #define DST_IS_FOREIGN_OBJ(i) (((i).byte_idx == DST_FOREIGN_BYTE_IDX) || \ 00090 ((i).block_idx == DST_FOREIGN_BLOCK_IDX)) 00091 00092 00093 #ifdef __cplusplus 00094 00095 // == != operators can conflict with windows.h, 00096 // so just define an explicit equality routine. 00097 inline BOOL DST_ARE_EQUAL (const DST_IDX x, const DST_IDX y) { 00098 return x.byte_idx == y.byte_idx && x.block_idx == y.block_idx; 00099 } 00100 00101 inline bool operator < (const DST_IDX& x, const DST_IDX& y) { 00102 return (x.block_idx < y.block_idx) || 00103 (x.block_idx == y.block_idx && x.byte_idx < y.byte_idx); 00104 } 00105 00106 inline DST_IDX make_DST_IDX(DST_BYTE_IDX byte_idx, DST_BLOCK_IDX block_idx) { 00107 DST_idx result; 00108 result.byte_idx = byte_idx; 00109 result.block_idx = block_idx; 00110 return result; 00111 } 00112 00113 // Hash function for DST indices. 00114 struct DST_IDX_hash { 00115 size_t operator()(DST_IDX idx) const { 00116 return (static_cast<size_t>(idx.block_idx) << 10) + 00117 static_cast<size_t>(idx.byte_idx); 00118 } 00119 }; 00120 00121 #endif 00122 00123 /*----------------------------* 00124 * General Purpose Functions * 00125 *----------------------------*/ 00126 00127 00128 /* Converts an index to a char pointer 00129 */ 00130 extern char * DST_idx_to_string(DST_IDX); 00131 00132 /*-----------------------* 00133 * General purpose types * 00134 *-----------------------*/ 00135 00136 00137 /* The different kinds of a block of bytes. WARNING: Any changes to 00138 * this structure must result in similar changes in the .c file. The 00139 * order of the constants is paramount for the implementation in 00140 * dwarf_DST_mem.c. 00141 */ 00142 typedef enum DST_block_kind 00143 { 00144 DST_include_dirs_block = 0, /* For include directory path names */ 00145 DST_file_names_block = 1, /* For file names */ 00146 DST_macro_info_block = 2, /* For macro information */ 00147 DST_file_scope_block = 3, /* For file-scope symbols */ 00148 DST_local_scope_block = 4, /* For local-scope symbols */ 00149 DST_noblock = 5 /* Invalid block */ 00150 } DST_BLOCK_KIND; 00151 00152 /* DST_TYPE is a dummy pointer type to be used where USE_DST_INTERNALS 00153 * is not defined */ 00154 typedef void* DST_TYPE; 00155 extern DST_TYPE Current_DST; 00156 00157 #ifdef USE_DST_INTERNALS 00158 00159 typedef struct block_header_struct { 00160 DST_BLOCK_KIND kind; 00161 mINT32 size; 00162 mINT32 allocsize; 00163 char *offset; 00164 } block_header; 00165 00166 typedef struct dst_rec { 00167 block_header *dst_blocks; /* array of block headers */ 00168 block_header *current_dst; /* the current dst header */ 00169 DST_BLOCK_IDX last_block_header; 00170 DST_BLOCK_IDX max_block_header; 00171 DST_BLOCK_IDX current_block_header; 00172 DST_BLOCK_IDX block_list[DST_noblock]; 00173 } DST_Type; 00174 00175 #define FOREACH_DST_BLOCK(i) \ 00176 for (i = 0; i <= ((DST_Type *)Current_DST)->last_block_header; i++) 00177 00178 #endif /* USE_DST_INTERNALS */ 00179 00180 00181 /* Create a new DST. For backward-compatibility this is called automatically 00182 * from DST_Init when Current_DST is NULL. For IPA, this function must be 00183 * called explicitly for each input file. 00184 */ 00185 extern DST_TYPE 00186 New_DST (void); 00187 00188 /* Initialize the DST memory system. If start == NULL, then initializes 00189 * with no blocks allocated. Else it initializes with num_blocks allocated, 00190 * starting at the start address. 00191 */ 00192 extern void 00193 DST_Init (char *start, INT32 num_blocks); 00194 00195 /* Allocates the first block of a new block-list and makes it the current 00196 * block for DST_allocate(). This function can AT MOST be called once for 00197 * each of: DST_include_dirs_blocks, DST_file_names_blocks, 00198 * DST_macro_info_block, and DST_file_scope_blocks. It should be called 00199 * for each Program Unit (PU), such that the entries belonging to a PU 00200 * will be in a separate block-list from the entries belonging to other 00201 * PUs. Never call this function with DST_noblock! 00202 */ 00203 extern void 00204 DST_begin_block(DST_BLOCK_KIND block_kind); 00205 00206 00207 /* Resets the current block to become the last block in the block-list 00208 * into which idx points. 00209 */ 00210 extern void 00211 DST_return_to_block(DST_IDX idx); 00212 00213 00214 /* Allocates the given number of bytes in the current memory block, 00215 * aligned according to the given align. Will add a new block to 00216 * the block list, when there is not enough space left in the current 00217 * block. DST_begin_block() must have been called at least once. 00218 * Returns an index to the newly allocated memory area. 00219 */ 00220 extern DST_IDX 00221 DST_allocate(INT32 bytes, INT32 align); 00222 00223 00224 /* Returns an index to the first DST_INCLUDE_DIR entry, which may be 00225 * DST_INVALID_IDX in the abscence of any DST_INCLUDE_DIR entries. 00226 */ 00227 extern DST_IDX 00228 DST_get_include_dirs(void); 00229 00230 00231 /* Returns an index to the first DST_FILE_NAME entry, which may be 00232 * DST_INVALID_IDX in the abscence of any DST_FILE_NAME entries. 00233 */ 00234 extern DST_IDX 00235 DST_get_file_names(void); 00236 00237 00238 /* Returns an index to the first DST_MACRO_INFO entry, which may be 00239 * DST_INVALID_IDX in the abscence of any DST_MACRO_INFO entries. 00240 */ 00241 extern DST_IDX 00242 DST_get_macro_info(void); 00243 00244 00245 /* Returns an index to the DST_COMPILE_UNIT entry, which may be 00246 * DST_INVALID_IDX in the abscence of any DST_COMPILE_UNIT entry. 00247 */ 00248 extern DST_IDX 00249 DST_get_compile_unit(void); 00250 00251 #ifdef __cplusplus 00252 } 00253 #endif 00254 #endif /* dwarf_DST_mem_INCLUDED */
1.5.6