Alien-TinyCCx
view release on metacpan or search on metacpan
src/tccexsymtab.c view on Meta::CPAN
*p_next_data = NULL;
return to_return;
}
/* ram_hash_free(void * ram_hash)
* Frees memory associated with a ram_hash. Does not do anything with
* the leaves. Use ram_hash_iterate to go through the leaves and take
* care of memory allocations stored there.
*/
void ram_hash_free(ram_hash * rh)
{
int i;
if (rh == NULL) return;
for (i = 0; i < rh->N_buckets; i++) {
ram_hash_linked_list * curr;
if (rh->buckets[i].next == NULL) continue;
curr = rh->buckets[i].next;
do {
ram_hash_linked_list * next = curr->next;
tcc_free(curr);
curr = next;
} while(curr != NULL);
}
tcc_free(rh->buckets);
tcc_free(rh);
}
/******************************************************************************/
/* compiled symbol lookup */
/******************************************************************************/
void dump_sym_names(TCCState *state)
{
Section * s;
ElfW(Sym) *sym;
int sym_index;
const char *name;
s = state->symtab;
sym_index = 2;
sym = &((ElfW(Sym) *)s->data)[sym_index];
name = s->link->data + sym->st_name;
while (strcmp("_etext", name) != 0) {
printf("%s: sym_index = %d, st_shndx is %x, address is %p\n", name, sym_index, sym->st_shndx, (void*)sym->st_value);
sym_index++;
sym = &((ElfW(Sym) *)s->data)[sym_index];
name = s->link->data + sym->st_name;
}
}
char * type_lookup_table[16] = {
"int", "char", "short", "void",
"pointer", "enum", "func", "struct",
"float", "double", "long double", "bool",
"long long", "long", "qlong", "qfloat"
};
void tcc_dump_identifier_names(extended_symtab * symtab, char * outfile)
{
int i;
FILE * out_fh = fopen(outfile, "w");
/* report error? I think a lack of file will probably be sufficient */
if (!out_fh) return;
for (i = 0; symtab->tokenSym_list + i < symtab->tokenSym_last; i++) {
int btype;
TokenSym * ts;
Sym * curr_sym;
ts = symtab->tokenSym_list[i];
if (!ts->sym_identifier) continue;
curr_sym = ts->sym_identifier;
/* only indicate the things that have external linkage */
if ((curr_sym->type.t & (VT_EXTERN | VT_STATIC)) != VT_EXTERN) continue;
if (curr_sym->type.t & VT_TYPEDEF) continue;
/* name */
fprintf(out_fh, "%s ", ts->str);
/* qualifiers */
if (curr_sym->type.t & VT_CONSTANT) fprintf(out_fh, "constant ");
/* type */
btype = curr_sym->type.t & VT_BTYPE;
fprintf(out_fh, "%s\n", type_lookup_table[btype]);
}
fclose(out_fh);
}
/* tcc_get_next_extended_symbol_name: a simple mechanism for getting the names
* of all of the global symbols known to the extended symbol table. */
char * tcc_get_next_extended_symbol_name(extended_symtab * symtab, int * poffset)
{
/* Increment the counter to get to the next TokenSym */
for ((*poffset)++; symtab->tokenSym_list + *poffset < symtab->tokenSym_last; (*poffset)++)
{
TokenSym * ts = symtab->tokenSym_list[*poffset];
if (ts->sym_identifier) return ts->str;
}
/* Reached end of list. Reset the counter and return null */
*poffset = -1;
return NULL;
}
void copy_extended_symbols_to_exsymtab(TCCState *state)
{
Section * s;
ElfW(Sym) *sym;
int sym_index;
const char *name;
extended_symtab* exsymtab;
exsymtab = state->exsymtab;
s = state->symtab;
sym_index = 2;
sym = &((ElfW(Sym) *)s->data)[sym_index];
name = s->link->data + sym->st_name;
( run in 0.800 second using v1.01-cache-2.11-cpan-f0fbb3f571b )