view ticoff/symtab.c @ 78:c2445afce514

tiobjd: symbol storage classes decoded into mnemonics
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Wed, 26 Mar 2014 01:24:17 +0000
parents 590396e27e96
children 8f4996bff904
line wrap: on
line source

/*
 * Code for working with the symbol table
 */

#include <sys/types.h>
#include <stdio.h>
#include "filestruct.h"
#include "intstruct.h"
#include "coffconst.h"
#include "globals.h"

static struct classmap {
	int	code;
	char	*str;
} classtab[] = {
	{C_NULL, "NULL"},
	{C_AUTO, "AUTO"},
	{C_EXT, "EXT"},
	{C_STAT, "STAT"},
	{C_REG, "REG"},
	{C_EXTREF, "EXTREF"},
	{C_LABEL, "LABEL"},
	{C_ULABEL, "ULABEL"},
	{C_MOS, "MOS"},
	{C_ARG, "ARG"},
	{C_STRTAG, "STRTAG"},
	{C_MOU, "MOU"},
	{C_UNTAG, "UNTAG"},
	{C_TPDEF, "TPDEF"},
	{C_USTATIC, "USTATIC"},
	{C_ENTAG, "ENTAG"},
	{C_MOE, "MOE"},
	{C_REGPARM, "REGPARM"},
	{C_FIELD, "FIELD"},
	{C_UEXT, "UEXT"},
	{C_STATLAB, "STATLAB"},
	{C_EXTLAB, "EXTLAB"},
	{C_SYSTEM, "SYSTEM"},
	{C_VARARG, "VARARG"},
	{C_BLOCK, "BLOCK"},
	{C_FCN, "FCN"},
	{C_EOS, "EOS"},
	{C_FILE, "FILE"},
	{C_LINE, "LINE"},
	{0, 0}
};

char *
storage_class_to_string(code, numbuf)
	char *numbuf;
{
	struct classmap *tp;

	for (tp = classtab; tp->str; tp++)
		if (tp->code == code)
			return(tp->str);
	sprintf(numbuf, "%d", code);
	return(numbuf);
}

dump_symtab()
{
	unsigned n;
	struct internal_syment *sym;
	char *sec, secstr[8];
	char *class, classbuf[8];

	printf("%-5s %-30s %-4s %-7s %-12s %-8s\n",
		"Num", "Name", "Type", "Class", "Section", "Value");
	for (n = 0; n < nsymtab; n++) {
		sym = symtab[n];
		if (!sym)
			continue;
		if (sym->scnum >= 1 && (unsigned)sym->scnum <= nsections)
			sec = sections[sym->scnum - 1].name;
		else {
			sprintf(secstr, "%d", sym->scnum);
			sec = secstr;
		}
		class = storage_class_to_string(sym->class, classbuf);
		printf("%-5u %-30s %04X %-7s %-12s %08X%s\n",
			n, sym->name, sym->type, class,
			sec, sym->value, sym->aux ? " Aux" : "");
	}
	return(0);
}