00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 #ifdef USE_PCH
00062 #include "common_com_pch.h"
00063 #endif
00064 #pragma hdrstop
00065 #include "defs.h"
00066 #include "mempool.h"
00067 #define USE_DST_INTERNALS
00068 #include "dwarf_DST_mem.h"
00069 #include "errors.h"
00070 #include "stab.h"
00071
00072 static inline void *
00073 Symtab_Alloc (size_t bytes, BOOL is_global)
00074 {
00075 if ( is_global ) {
00076 return (void *) Src_Alloc ( bytes );
00077 } else {
00078 return (void *) Pu_Alloc ( bytes );
00079 }
00080 }
00081
00082
00083 #define NUM_BLOCK_HEADERS 1024
00084 #define BLOCK_SIZE 256
00085
00086 DST_TYPE Current_DST = NULL;
00087 DST_Type *current_DST = NULL;
00088
00089
00090
00091
00092
00093 const DST_IDX DST_INVALID_IDX = {DST_INVALID_BLOCK_IDX, DST_INVALID_BYTE_IDX};
00094
00095
00096
00097
00098
00099
00100 #ifdef Is_True_On
00101
00102
00103 static DST_BLOCK_IDX
00104 DST_CHECK_BLOCK_IDX(DST_BLOCK_IDX b)
00105 {
00106 Is_True((b != DST_INVALID_BLOCK_IDX && b >= 0 &&
00107 b <= current_DST->last_block_header),
00108 ("Illegal DST block idx"));
00109 return b;
00110 }
00111
00112 static DST_IDX
00113 DST_CHECK_IDX(DST_IDX i)
00114 {
00115 Is_True( ((i.byte_idx >= 0 &&
00116 i.byte_idx < current_DST->dst_blocks[DST_CHECK_BLOCK_IDX(i.block_idx)].size)) || DST_IS_FOREIGN_OBJ(i),
00117 ("Illegal DST idx"));
00118 return i;
00119 }
00120
00121 #else
00122
00123 #define DST_CHECK_BLOCK_IDX(b) (b)
00124 #define DST_CHECK_IDX(i) (i)
00125
00126
00127 #endif
00128
00129
00130 extern DST_TYPE
00131 New_DST (void)
00132 {
00133 INT32 i;
00134 DST_Type *dst = TYPE_MEM_POOL_ALLOC(DST_Type, MEM_src_pool_ptr);
00135
00136 dst->last_block_header = -1;
00137 dst->max_block_header = NUM_BLOCK_HEADERS;
00138 dst->current_block_header = -1;
00139
00140
00141
00142 for (i = 0; i < DST_noblock; i++) {
00143 dst->block_list[i] = DST_INVALID_BLOCK_IDX;
00144 }
00145
00146 return (DST_TYPE)dst;
00147 }
00148
00149
00150 extern void
00151 DST_Init (char *start, INT32 num_blocks)
00152 {
00153 INT i;
00154 block_header *blocks;
00155 DST_BLOCK_IDX *blklist;
00156
00157
00158 if (Current_DST == NULL)
00159 Current_DST = New_DST();
00160
00161 current_DST = (DST_Type *)Current_DST;
00162
00163 if (start == NULL) {
00164
00165 blocks = (block_header*) Symtab_Alloc (NUM_BLOCK_HEADERS*sizeof(block_header), TRUE);
00166 } else {
00167
00168 blocks = (block_header *) start;
00169 current_DST->max_block_header = num_blocks;
00170 current_DST->last_block_header = num_blocks - 1;
00171
00172 blklist = ¤t_DST->block_list[0];
00173 FOREACH_DST_BLOCK(i) {
00174
00175
00176
00177
00178
00179 if (blklist[blocks[i].kind] == DST_INVALID_BLOCK_IDX)
00180 blklist[blocks[i].kind] = i;
00181 }
00182 #if defined(_SUPPORT_IPA) || defined(_STANDALONE_INLINER) || defined(MONGOOSE_BE)
00183 blocks[current_DST->last_block_header].allocsize =
00184 blocks[current_DST->last_block_header].size;
00185 #endif
00186 }
00187 current_DST->dst_blocks = blocks;
00188 current_DST->current_dst = blocks;
00189 }
00190
00191 static void
00192 set_current_dst_to_current ( void )
00193 {
00194 current_DST->current_block_header = current_DST->last_block_header;
00195 current_DST->current_dst =
00196 ¤t_DST->dst_blocks[current_DST->current_block_header];
00197 }
00198
00199
00200
00201
00202
00203 static block_header *
00204 new_block (DST_BLOCK_KIND kind, INT32 size)
00205 {
00206 INT32 allocsize = (size < BLOCK_SIZE ? BLOCK_SIZE : size);
00207 DST_BLOCK_IDX last_block = current_DST->last_block_header;
00208 DST_BLOCK_IDX max_block = current_DST->max_block_header;
00209 block_header *blocks = current_DST->dst_blocks;
00210 block_header *current;
00211
00212 if (++last_block >= max_block) {
00213 blocks = TYPE_MEM_POOL_REALLOC_N(block_header,
00214 MEM_src_pool_ptr ,
00215 blocks, max_block,
00216 2 * max_block);
00217 max_block *= 2;
00218
00219 current_DST->dst_blocks = blocks;
00220 current_DST->max_block_header = max_block;
00221 }
00222 current_DST->last_block_header = last_block;
00223 current_DST->current_block_header = last_block;
00224
00225 #if defined(_SUPPORT_IPA) || defined(_STANDALONE_INLINER) || defined(MONGOOSE_BE)
00226
00227
00228 blocks[last_block].offset = (char*) Symtab_Alloc(allocsize,
00229 TRUE);
00230 #else
00231 blocks[last_block].offset = (char*) Symtab_Alloc(allocsize,
00232 (kind == DST_local_scope_block) ? FALSE : TRUE);
00233 #endif
00234 current = &blocks[last_block];
00235 current->kind = kind;
00236 current->size = 0;
00237 current->allocsize = allocsize;
00238 current_DST->current_dst = current;
00239
00240 return current;
00241 }
00242
00243
00244 extern void
00245 DST_begin_block (DST_BLOCK_KIND block_kind)
00246 {
00247 DST_BLOCK_IDX *blklist;
00248 current_DST = (DST_Type *)Current_DST;
00249 blklist = ¤t_DST->block_list[0];
00250 current_DST->current_dst = new_block (block_kind, 0);
00251 if (blklist[block_kind] == DST_INVALID_BLOCK_IDX)
00252 blklist[block_kind] = current_DST->last_block_header;
00253 }
00254
00255 extern DST_IDX
00256 DST_allocate (INT32 size, INT32 align)
00257 {
00258 DST_IDX new_idx;
00259 INT32 total_size;
00260 INT32 align_mod, align_padding;
00261 block_header *current;
00262 current_DST = (DST_Type *)Current_DST;
00263
00264 #if defined(_SUPPORT_IPA) || defined(_STANDALONE_INLINER) || defined(MONGOOSE_BE)
00265 #if 0
00266 if ((current_DST->dst_blocks == current_DST->current_dst) &&
00267 (current_DST->current_dst->kind != DST_local_scope_block)) {
00268
00269 current = new_block (DST_local_scope_block, size);
00270
00271 align_padding = 0;
00272 total_size = size;
00273 set_current_dst_to_current();
00274 }
00275 else {
00276 #endif
00277 set_current_dst_to_current();
00278 current = current_DST->current_dst;
00279 #if 0
00280 }
00281 #endif
00282 #else
00283 current = current_DST->current_dst;
00284 #endif
00285
00286
00287
00288 align_mod = current->size % align;
00289 align_padding = (align_mod ? (align - align_mod) : 0);
00290 total_size = current->size + size + align_padding;
00291
00292 if (total_size > current->allocsize) {
00293
00294
00295
00296
00297
00298
00299
00300 #if defined(_SUPPORT_IPA) || defined(_STANDALONE_INLINER) || defined(MONGOOSE_BE)
00301 current = new_block (DST_local_scope_block, size);
00302 #else
00303 current = new_block (current->kind, size);
00304 #endif
00305
00306 align_padding = 0;
00307 total_size = size;
00308 }
00309
00310 new_idx.block_idx = current_DST->current_block_header;
00311 new_idx.byte_idx = current->size + align_padding;
00312 current->size = total_size;
00313 return new_idx;
00314 }
00315
00316
00317
00318
00319
00320 extern void
00321 DST_return_to_block(DST_IDX idx)
00322 {
00323 DST_BLOCK_IDX current_block;
00324 current_DST = (DST_Type *)Current_DST;
00325 current_block = DST_CHECK_IDX(idx).block_idx;
00326 current_DST->current_block_header = current_block;
00327 current_DST->current_dst = ¤t_DST->dst_blocks[current_block];
00328 }
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338 extern char *
00339 DST_idx_to_string(DST_IDX idx)
00340 {
00341 block_header *block;
00342 current_DST = (DST_Type *)Current_DST;
00343 block = ¤t_DST->dst_blocks[DST_CHECK_IDX(idx).block_idx];
00344 if (idx.byte_idx == DST_INVALID_BYTE_IDX)
00345 return NULL;
00346 else
00347 return &(block->offset[idx.byte_idx]);
00348 }
00349
00350
00351 static DST_IDX
00352 DST_get_block_list(DST_BLOCK_KIND block_kind)
00353 {
00354 DST_IDX idx;
00355 DST_BLOCK_IDX bidx = current_DST->block_list[block_kind];
00356
00357 if ((bidx == DST_INVALID_BLOCK_IDX) ||
00358 (current_DST->dst_blocks[DST_CHECK_BLOCK_IDX(bidx)].size <= 0)) {
00359 idx = DST_INVALID_IDX;
00360 } else {
00361 idx.byte_idx = 0;
00362 idx.block_idx = bidx;
00363 current_DST->current_dst = ¤t_DST->dst_blocks[bidx];
00364 }
00365 return idx;
00366 }
00367
00368
00369
00370
00371
00372 extern DST_IDX
00373 DST_get_include_dirs(void)
00374 {
00375 current_DST = (DST_Type *)Current_DST;
00376 return DST_get_block_list(DST_include_dirs_block);
00377 }
00378
00379
00380
00381
00382
00383 extern DST_IDX
00384 DST_get_file_names(void)
00385 {
00386 current_DST = (DST_Type *)Current_DST;
00387 return DST_get_block_list(DST_file_names_block);
00388 }
00389
00390
00391
00392
00393
00394 extern DST_IDX
00395 DST_get_macro_info(void)
00396 {
00397 current_DST = (DST_Type *)Current_DST;
00398 return DST_get_block_list(DST_macro_info_block);
00399 }
00400
00401
00402
00403
00404
00405 extern DST_IDX
00406 DST_get_compile_unit(void)
00407 {
00408 current_DST = (DST_Type *)Current_DST;
00409 return DST_get_block_list(DST_file_scope_block);
00410 }
00411