Open64 (mfef90, whirl2f, and IR tools)  TAG: version-openad; SVN changeset: 916
dwarf_DST_mem.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 dwarf_DST_mem_INCLUDED
00037 #define dwarf_DST_mem_INCLUDED
00038 
00039 /* 
00040  * Solaris CC workaround
00041  * CC requires that operator==(***), operator!=(***) operator overloading
00042  * must be defined in C++ language, and doesn't buy extern "C" here!
00043  * So remove it.
00044  */
00045 
00046 #if defined(_SOLARIS_SOLARIS) && !defined(__GNUC__)
00047 #else
00048 #ifdef __cplusplus
00049 extern "C" {
00050 #endif
00051 #endif
00052 
00053 
00054 #include "defs.h"
00055 
00056          /*-------------------------------------------------*
00057           * Definition of DST_IDX (index to allocated data) *
00058           *-------------------------------------------------*/
00059 
00060 
00061 typedef mINT32 DST_BYTE_IDX;
00062 typedef mINT32 DST_BLOCK_IDX;
00063 
00064 
00065 typedef struct DST_idx
00066 {
00067    DST_BYTE_IDX  byte_idx;
00068    DST_BLOCK_IDX block_idx;
00069 } DST_IDX;
00070 
00071 #define DST_INVALID_BLOCK_IDX -1
00072 #define DST_INVALID_BYTE_IDX -1
00073 #define DST_FOREIGN_BLOCK_IDX -2
00074 #define DST_FOREIGN_BYTE_IDX -2
00075 
00076 
00077 /* Represents a NULL DST_IDX value. Always initialize a declared
00078  * DST_IDX with DST_INVALID_IDX or DST_INVALID_INIT!!
00079 */
00080 extern const DST_IDX DST_INVALID_IDX;
00081 #define DST_INVALID_INIT {DST_INVALID_BYTE_IDX, DST_INVALID_BLOCK_IDX}
00082 #define DST_FOREIGN_INIT {DST_FOREIGN_BYTE_IDX, DST_FOREIGN_BLOCK_IDX}
00083 
00084 
00085 /* Use this macro to test for a NULL DST_IDX value
00086 */
00087 #define DST_IS_NULL(i) (((i).byte_idx == DST_INVALID_BYTE_IDX) ||\
00088                         ((i).block_idx == DST_INVALID_BLOCK_IDX))
00089 
00090 /* Use this macro to test for a FOREIGN DST_IDX value */
00091 #define DST_IS_FOREIGN_OBJ(i)   (((i).byte_idx == DST_FOREIGN_BYTE_IDX) || \
00092                                  ((i).block_idx == DST_FOREIGN_BLOCK_IDX))
00093 
00094 
00095 #ifdef __cplusplus
00096 
00097 inline bool operator==(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.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 #if defined(_SOLARIS_SOLARIS) && !defined(__GNUC__)
00256 #else
00257 #ifdef __cplusplus
00258 }
00259 #endif
00260 #endif
00261 
00262 #endif /* dwarf_DST_mem_INCLUDED */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines