1987-03-10 17:51:10 +00:00
|
|
|
/*
|
|
|
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
|
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
|
|
*/
|
1994-06-24 14:02:31 +00:00
|
|
|
/* $Id$ */
|
1986-03-10 13:07:55 +00:00
|
|
|
/* DUMP ROUTINES */
|
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
1986-09-24 13:53:16 +00:00
|
|
|
#include "nofloat.h"
|
1986-03-10 13:07:55 +00:00
|
|
|
#include "nopp.h"
|
|
|
|
#include "nobitfield.h"
|
|
|
|
#include "arith.h"
|
|
|
|
#include "stack.h"
|
|
|
|
#include "idf.h"
|
|
|
|
#include "def.h"
|
|
|
|
#include "type.h"
|
|
|
|
#include "struct.h"
|
|
|
|
#include "field.h"
|
|
|
|
#include "Lpars.h"
|
|
|
|
#include "label.h"
|
|
|
|
#include "expr.h"
|
1986-09-15 08:47:53 +00:00
|
|
|
#include "static.h"
|
1986-03-10 13:07:55 +00:00
|
|
|
|
|
|
|
/* Some routines (symbol2str, token2str, type2str) which should have
|
|
|
|
* yielded strings are written to yield a pointer to a transient piece
|
|
|
|
* of memory, containing the string, since this is the only reasonable
|
|
|
|
* thing to do in C. `Transient' means that the result may soon
|
|
|
|
* disappear, which is generally not a problem, since normally it is
|
|
|
|
* consumed immediately. Sometimes we need more than one of them, and
|
|
|
|
* MAXTRANS is the maximum number we will need simultaneously.
|
|
|
|
*/
|
|
|
|
#define MAXTRANS 6
|
|
|
|
|
|
|
|
extern char options[];
|
|
|
|
|
|
|
|
extern struct idf *idf_hashtable[];
|
|
|
|
extern char *symbol2str(), *type2str(), *next_transient();
|
|
|
|
|
|
|
|
enum sdef_kind {selector, field}; /* parameter for dumpsdefs */
|
|
|
|
|
|
|
|
static int dumplevel;
|
|
|
|
|
|
|
|
static
|
|
|
|
newline() {
|
1986-09-24 13:53:16 +00:00
|
|
|
register int dl = dumplevel;
|
1986-03-10 13:07:55 +00:00
|
|
|
|
1986-04-03 14:32:56 +00:00
|
|
|
print("\n");
|
1986-03-10 13:07:55 +00:00
|
|
|
while (dl >= 2) {
|
1986-04-03 14:32:56 +00:00
|
|
|
print("\t");
|
1986-03-10 13:07:55 +00:00
|
|
|
dl -= 2;
|
|
|
|
}
|
|
|
|
if (dl)
|
1986-04-03 14:32:56 +00:00
|
|
|
print(" ");
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dumpidftab(msg, opt)
|
|
|
|
char msg[];
|
|
|
|
{
|
|
|
|
/* Dumps the identifier table in readable form (but in
|
|
|
|
arbitrary order).
|
|
|
|
Unless opt & 1, macros are not dumped.
|
|
|
|
Unless opt & 2, reserved identifiers are not dumped.
|
|
|
|
Unless opt & 4, universal identifiers are not dumped.
|
|
|
|
*/
|
|
|
|
int i;
|
|
|
|
|
1986-04-03 14:32:56 +00:00
|
|
|
print(">>> DUMPIDF, %s (start)", msg);
|
1986-03-10 13:07:55 +00:00
|
|
|
dumpstack();
|
|
|
|
for (i = 0; i < HASHSIZE; i++) {
|
1986-09-24 13:53:16 +00:00
|
|
|
register struct idf *notch = idf_hashtable[i];
|
1986-03-10 13:07:55 +00:00
|
|
|
|
|
|
|
while (notch) {
|
|
|
|
dumpidf(notch, opt);
|
|
|
|
notch = notch->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
newline();
|
1986-04-03 14:32:56 +00:00
|
|
|
print(">>> DUMPIDF, %s (end)\n", msg);
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
|
|
|
|
1986-09-24 13:53:16 +00:00
|
|
|
dumpstack()
|
|
|
|
{
|
1986-03-10 13:07:55 +00:00
|
|
|
/* Dumps the identifier stack, starting at the top.
|
|
|
|
*/
|
1986-09-24 13:53:16 +00:00
|
|
|
register struct stack_level *stl = local_level;
|
1986-03-10 13:07:55 +00:00
|
|
|
|
|
|
|
while (stl) {
|
1986-09-24 13:53:16 +00:00
|
|
|
register struct stack_entry *se = stl->sl_entry;
|
1986-03-10 13:07:55 +00:00
|
|
|
|
|
|
|
newline();
|
1986-04-03 14:32:56 +00:00
|
|
|
print("%3d: ", stl->sl_level);
|
1986-03-10 13:07:55 +00:00
|
|
|
while (se) {
|
1986-04-03 14:32:56 +00:00
|
|
|
print("%s ", se->se_idf->id_text);
|
1986-03-10 13:07:55 +00:00
|
|
|
se = se->next;
|
|
|
|
}
|
|
|
|
stl = stl->sl_previous;
|
|
|
|
}
|
1986-04-03 14:32:56 +00:00
|
|
|
print("\n");
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dumpidf(idf, opt)
|
1986-09-24 13:53:16 +00:00
|
|
|
register struct idf *idf;
|
1986-03-10 13:07:55 +00:00
|
|
|
{
|
|
|
|
/* All information about the identifier idf is divulged in a
|
|
|
|
hopefully readable format.
|
|
|
|
*/
|
|
|
|
int started = 0;
|
|
|
|
|
|
|
|
if (!idf)
|
|
|
|
return;
|
|
|
|
#ifndef NOPP
|
|
|
|
if ((opt&1) && idf->id_macro) {
|
|
|
|
if (!started++) {
|
|
|
|
newline();
|
1986-04-03 14:32:56 +00:00
|
|
|
print("%s:", idf->id_text);
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
1986-04-03 14:32:56 +00:00
|
|
|
print(" macro");
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
1991-12-17 14:11:15 +00:00
|
|
|
#endif /* NOPP */
|
1986-03-10 13:07:55 +00:00
|
|
|
if ((opt&2) && idf->id_reserved) {
|
|
|
|
if (!started++) {
|
|
|
|
newline();
|
1986-04-03 14:32:56 +00:00
|
|
|
print("%s:", idf->id_text);
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
1986-04-03 14:32:56 +00:00
|
|
|
print(" reserved: %d;", idf->id_reserved);
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
|
|
|
if (idf->id_def && ((opt&4) || idf->id_def->df_level)) {
|
|
|
|
if (!started++) {
|
|
|
|
newline();
|
1986-04-03 14:32:56 +00:00
|
|
|
print("%s:", idf->id_text);
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
|
|
|
dumpdefs(idf->id_def, opt);
|
|
|
|
}
|
|
|
|
if (idf->id_sdef) {
|
|
|
|
if (!started++) {
|
|
|
|
newline();
|
1986-04-03 14:32:56 +00:00
|
|
|
print("%s:", idf->id_text);
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
|
|
|
dumpsdefs(idf->id_sdef, selector);
|
|
|
|
}
|
|
|
|
if (idf->id_struct) {
|
|
|
|
if (!started++) {
|
|
|
|
newline();
|
1986-04-03 14:32:56 +00:00
|
|
|
print("%s:", idf->id_text);
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
|
|
|
dumptags(idf->id_struct);
|
|
|
|
}
|
|
|
|
if (idf->id_enum) {
|
|
|
|
if (!started++) {
|
|
|
|
newline();
|
1986-04-03 14:32:56 +00:00
|
|
|
print("%s:", idf->id_text);
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
|
|
|
dumptags(idf->id_enum);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dumpdefs(def, opt)
|
|
|
|
register struct def *def;
|
|
|
|
{
|
|
|
|
dumplevel++;
|
|
|
|
while (def && ((opt&4) || def->df_level)) {
|
|
|
|
newline();
|
1987-11-02 17:59:18 +00:00
|
|
|
print("L%d: %s %s%s%s%s %lo;",
|
1986-03-10 13:07:55 +00:00
|
|
|
def->df_level,
|
|
|
|
symbol2str(def->df_sc),
|
|
|
|
def->df_initialized ? "init'd " : "",
|
|
|
|
def->df_used ? "used " : "",
|
|
|
|
type2str(def->df_type),
|
|
|
|
def->df_sc == ENUM ? ", =" : " at",
|
|
|
|
def->df_address
|
|
|
|
);
|
1988-08-29 15:51:48 +00:00
|
|
|
print("%s, line %u",
|
|
|
|
def->df_file ? def->df_file : "NO_FILE", def->df_line);
|
1986-03-10 13:07:55 +00:00
|
|
|
def = def->next;
|
|
|
|
}
|
|
|
|
dumplevel--;
|
|
|
|
}
|
|
|
|
|
|
|
|
dumptags(tag)
|
1986-09-24 13:53:16 +00:00
|
|
|
register struct tag *tag;
|
1986-03-10 13:07:55 +00:00
|
|
|
{
|
|
|
|
dumplevel++;
|
|
|
|
while (tag) {
|
|
|
|
register struct type *tp = tag->tg_type;
|
|
|
|
register int fund = tp->tp_fund;
|
|
|
|
|
|
|
|
newline();
|
1986-04-03 14:32:56 +00:00
|
|
|
print("L%d: %s %s",
|
1986-03-10 13:07:55 +00:00
|
|
|
tag->tg_level,
|
|
|
|
fund == STRUCT ? "struct" :
|
|
|
|
fund == UNION ? "union" :
|
|
|
|
fund == ENUM ? "enum" : "<UNKNOWN>",
|
|
|
|
tp->tp_idf->id_text
|
|
|
|
);
|
|
|
|
if (is_struct_or_union(fund)) {
|
1986-04-03 14:32:56 +00:00
|
|
|
print(" {");
|
1986-03-10 13:07:55 +00:00
|
|
|
dumpsdefs(tp->tp_sdef, field);
|
|
|
|
newline();
|
1986-04-03 14:32:56 +00:00
|
|
|
print("}");
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
1986-04-03 14:32:56 +00:00
|
|
|
print(";");
|
1986-03-10 13:07:55 +00:00
|
|
|
tag = tag->next;
|
|
|
|
}
|
|
|
|
dumplevel--;
|
|
|
|
}
|
|
|
|
|
|
|
|
dumpsdefs(sdef, sdk)
|
1986-09-24 13:53:16 +00:00
|
|
|
register struct sdef *sdef;
|
1986-03-10 13:07:55 +00:00
|
|
|
enum sdef_kind sdk;
|
|
|
|
{
|
|
|
|
/* Since sdef's are members of two chains, there are actually
|
|
|
|
two dumpsdefs's, one following the chain of all selectors
|
|
|
|
belonging to the same idf, starting at idf->id_sdef;
|
|
|
|
and the other following the chain of all selectors belonging
|
|
|
|
to the same struct, starting at stp->tp_sdef.
|
|
|
|
*/
|
|
|
|
|
|
|
|
dumplevel++;
|
|
|
|
while (sdef) {
|
|
|
|
newline();
|
1986-04-03 14:32:56 +00:00
|
|
|
print("L%d: ", sdef->sd_level);
|
1986-03-10 13:07:55 +00:00
|
|
|
#ifndef NOBITFIELD
|
|
|
|
if (sdk == selector)
|
1991-12-17 14:11:15 +00:00
|
|
|
#endif /* NOBITFIELD */
|
1986-04-03 14:32:56 +00:00
|
|
|
print("selector %s at offset %lu in %s;",
|
1986-03-10 13:07:55 +00:00
|
|
|
type2str(sdef->sd_type),
|
|
|
|
sdef->sd_offset, type2str(sdef->sd_stype)
|
|
|
|
);
|
|
|
|
#ifndef NOBITFIELD
|
1986-04-03 14:32:56 +00:00
|
|
|
else print("field %s at offset %lu;",
|
1986-03-10 13:07:55 +00:00
|
|
|
type2str(sdef->sd_type), sdef->sd_offset
|
|
|
|
);
|
1991-12-17 14:11:15 +00:00
|
|
|
#endif /* NOBITFIELD */
|
1986-03-10 13:07:55 +00:00
|
|
|
sdef = (sdk == selector ? sdef->next : sdef->sd_sdef);
|
|
|
|
}
|
|
|
|
dumplevel--;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
type2str(tp)
|
1986-09-24 13:53:16 +00:00
|
|
|
register struct type *tp;
|
1986-03-10 13:07:55 +00:00
|
|
|
{
|
|
|
|
/* Yields a pointer to a one-line description of the type tp.
|
|
|
|
*/
|
|
|
|
char *buf = next_transient();
|
|
|
|
int ops = 1;
|
|
|
|
|
|
|
|
buf[0] = '\0';
|
|
|
|
if (!tp) {
|
1986-04-03 14:32:56 +00:00
|
|
|
sprint(buf, "<NILTYPE>");
|
1986-03-10 13:07:55 +00:00
|
|
|
return buf;
|
|
|
|
}
|
1988-09-29 15:24:02 +00:00
|
|
|
|
|
|
|
sprint(buf, "%s(#%ld, &%d) ", buf, (long)tp->tp_size, tp->tp_align);
|
1986-03-10 13:07:55 +00:00
|
|
|
while (ops) {
|
|
|
|
switch (tp->tp_fund) {
|
|
|
|
case POINTER:
|
1986-04-03 14:32:56 +00:00
|
|
|
sprint(buf, "%spointer to ", buf);
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
|
|
|
case ARRAY:
|
1986-04-03 14:32:56 +00:00
|
|
|
sprint(buf, "%sarray [%ld] of ", buf, tp->tp_size);
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
|
|
|
case FUNCTION:
|
1986-04-03 14:32:56 +00:00
|
|
|
sprint(buf, "%sfunction yielding ", buf);
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
|
|
|
default:
|
1986-04-03 14:32:56 +00:00
|
|
|
sprint(buf, "%s%s%s", buf,
|
1986-03-10 13:07:55 +00:00
|
|
|
tp->tp_unsigned ? "unsigned " : "",
|
|
|
|
symbol2str(tp->tp_fund)
|
|
|
|
);
|
|
|
|
if (tp->tp_idf)
|
1986-04-03 14:32:56 +00:00
|
|
|
sprint(buf, "%s %s", buf,
|
1986-03-10 13:07:55 +00:00
|
|
|
tp->tp_idf->id_text);
|
|
|
|
#ifndef NOBITFIELD
|
|
|
|
if (tp->tp_field) {
|
|
|
|
struct field *fd = tp->tp_field;
|
|
|
|
|
1986-08-13 10:05:39 +00:00
|
|
|
sprint(buf, "%s [s=%ld,w=%ld] of ", buf,
|
1986-03-10 13:07:55 +00:00
|
|
|
fd->fd_shift, fd->fd_width);
|
|
|
|
}
|
1986-08-13 10:05:39 +00:00
|
|
|
else
|
1991-12-17 14:11:15 +00:00
|
|
|
#endif /* NOBITFIELD */
|
1986-03-10 13:07:55 +00:00
|
|
|
ops = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
tp = tp->tp_up;
|
|
|
|
}
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
1986-09-17 12:31:45 +00:00
|
|
|
GSTATIC char trans_buf[MAXTRANS][300];
|
1986-09-15 08:47:53 +00:00
|
|
|
|
1986-03-10 13:07:55 +00:00
|
|
|
char * /* the ultimate transient buffer supplier */
|
1986-03-27 11:01:12 +00:00
|
|
|
next_transient()
|
|
|
|
{
|
1986-03-10 13:07:55 +00:00
|
|
|
static int bnum;
|
|
|
|
|
|
|
|
if (++bnum == MAXTRANS)
|
|
|
|
bnum = 0;
|
1986-09-15 08:47:53 +00:00
|
|
|
return trans_buf[bnum];
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
print_expr(msg, expr)
|
|
|
|
char msg[];
|
|
|
|
struct expr *expr;
|
|
|
|
{
|
|
|
|
/* Provisional routine to print an expression preceded by a
|
|
|
|
message msg.
|
|
|
|
*/
|
|
|
|
if (options['x']) {
|
1986-04-03 14:32:56 +00:00
|
|
|
print("\n%s: ", msg);
|
|
|
|
print("(L=line, T=type, r/lV=r/lvalue, F=flags, D=depth)\n");
|
1986-03-10 13:07:55 +00:00
|
|
|
p1_expr(0, expr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
p1_expr(lvl, expr)
|
1986-09-24 13:53:16 +00:00
|
|
|
register struct expr *expr;
|
1986-03-10 13:07:55 +00:00
|
|
|
{
|
|
|
|
p1_indent(lvl);
|
|
|
|
if (!expr) {
|
1986-04-03 14:32:56 +00:00
|
|
|
print("NILEXPR\n");
|
1986-03-10 13:07:55 +00:00
|
|
|
return;
|
|
|
|
}
|
1986-04-03 14:32:56 +00:00
|
|
|
print("expr: L=%u, T=%s, %cV, F=%03o, D=%d, %s: ",
|
1986-03-10 13:07:55 +00:00
|
|
|
expr->ex_line,
|
|
|
|
type2str(expr->ex_type),
|
|
|
|
expr->ex_lvalue ? 'l' : 'r',
|
1986-03-27 18:17:48 +00:00
|
|
|
expr->ex_flags & 0xFF,
|
1986-03-10 13:07:55 +00:00
|
|
|
expr->ex_depth,
|
|
|
|
expr->ex_class == Value ? "Value" :
|
|
|
|
expr->ex_class == String ? "String" :
|
1986-09-12 09:16:07 +00:00
|
|
|
#ifndef NOFLOAT
|
1986-03-10 13:07:55 +00:00
|
|
|
expr->ex_class == Float ? "Float" :
|
1991-12-17 14:11:15 +00:00
|
|
|
#endif /* NOFLOAT */
|
1986-03-10 13:07:55 +00:00
|
|
|
expr->ex_class == Oper ? "Oper" :
|
|
|
|
expr->ex_class == Type ? "Type" : "UNKNOWN CLASS"
|
|
|
|
);
|
|
|
|
switch (expr->ex_class) {
|
|
|
|
struct oper *o;
|
|
|
|
case Value:
|
1986-04-02 08:37:17 +00:00
|
|
|
switch (expr->VL_CLASS) {
|
|
|
|
case Const:
|
1986-04-03 14:32:56 +00:00
|
|
|
print("(Const) ");
|
1986-04-02 08:37:17 +00:00
|
|
|
break;
|
|
|
|
case Name:
|
1986-04-03 14:32:56 +00:00
|
|
|
print("(Name) %s + ", expr->VL_IDF->id_text);
|
1986-04-02 08:37:17 +00:00
|
|
|
break;
|
|
|
|
case Label:
|
1986-04-03 14:32:56 +00:00
|
|
|
print("(Label) .%lu + ", expr->VL_LBL);
|
1986-04-02 08:37:17 +00:00
|
|
|
break;
|
|
|
|
default:
|
1986-04-03 14:32:56 +00:00
|
|
|
print("(Unknown) ");
|
1986-04-02 08:37:17 +00:00
|
|
|
break;
|
|
|
|
}
|
1986-04-03 14:32:56 +00:00
|
|
|
print(expr->ex_type->tp_unsigned ? "%lu\n" : "%ld\n",
|
1986-04-02 08:37:17 +00:00
|
|
|
expr->VL_VALUE);
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
|
|
|
case String:
|
1986-03-27 11:01:12 +00:00
|
|
|
{
|
1986-04-17 14:42:54 +00:00
|
|
|
char *bts2str();
|
1986-03-27 11:01:12 +00:00
|
|
|
|
1986-04-03 14:32:56 +00:00
|
|
|
print(
|
1988-10-12 16:05:17 +00:00
|
|
|
"\"%s\"\n",
|
|
|
|
bts2str(expr->SG_VALUE, expr->SG_LEN-1,
|
|
|
|
next_transient())
|
1986-03-27 11:01:12 +00:00
|
|
|
);
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
1986-03-27 11:01:12 +00:00
|
|
|
}
|
1986-09-12 09:16:07 +00:00
|
|
|
#ifndef NOFLOAT
|
1986-03-10 13:07:55 +00:00
|
|
|
case Float:
|
1986-04-03 14:32:56 +00:00
|
|
|
print("%s\n", expr->FL_VALUE);
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
1991-12-17 14:11:15 +00:00
|
|
|
#endif /* NOFLOAT */
|
1986-03-10 13:07:55 +00:00
|
|
|
case Oper:
|
|
|
|
o = &expr->ex_object.ex_oper;
|
1986-04-03 14:32:56 +00:00
|
|
|
print("\n");
|
1986-03-10 13:07:55 +00:00
|
|
|
p1_expr(lvl+1, o->op_left);
|
1986-08-13 10:05:39 +00:00
|
|
|
p1_indent(lvl);
|
|
|
|
print("%s <%s>\n", symbol2str(o->op_oper),
|
|
|
|
type2str(o->op_type)
|
|
|
|
);
|
1986-03-10 13:07:55 +00:00
|
|
|
p1_expr(lvl+1, o->op_right);
|
|
|
|
break;
|
|
|
|
case Type:
|
1986-04-03 14:32:56 +00:00
|
|
|
print("\n");
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
|
|
|
default:
|
1986-04-03 14:32:56 +00:00
|
|
|
print("UNKNOWN CLASS\n");
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1986-09-24 13:53:16 +00:00
|
|
|
p1_indent(lvl)
|
|
|
|
register int lvl;
|
|
|
|
{
|
1986-03-10 13:07:55 +00:00
|
|
|
while (lvl--)
|
1986-04-03 14:32:56 +00:00
|
|
|
print(" ");
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
1991-12-17 14:11:15 +00:00
|
|
|
#endif /* DEBUG */
|