summaryrefslogtreecommitdiff
path: root/bcc/dbnode.c
blob: e4a944cd129465d75659e68ae1a339ef00f120ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/* dbnode.c - print debug messages for operators for bcc */

/* Copyright (C) 1992 Bruce Evans */

#include "bcc.h"

#ifdef DBNODE
#include "gencode.h"
#include "reg.h"
#include "sc.h"
#include "scan.h"
#include "type.h"

PRIVATE char *opname[LASTOP - FIRSTOP + 1] =	/* operator names */
{				/* order must agree with op.h */
    "cond?",
    "or",
    "eor",
    "and",
    "gt", "lt",
    "add",
    "div", "mod",
    "lognot", "not",
    "strucelt", "strucptr",
    "eq",
    "addab", "andab", "divab", "eorab", "modab", "mulab", "orab",
    "slab", "srab", "subab",
    "comma",
    "cond:",
    "logor",
    "logand",
    "logeq",
    "ne",
    "ge", "le",
    "sl", "sr",
    "sub",
    "mul",
    "address", "cast", "indirect", "neg",
    "predec", "preinc", "postdec", "postinc",
    "func", "list", "rootlist",
    "leaf",
    "ptraddab", "ptradd", "ptrsub",
};

FORWARD void outindchars P((int byte, indn_pt count));

PUBLIC void dbitem(item)
struct symstruct *item;
{
    dbtype(item->type);
    if (item->storage == NOSTORAGE)
    {
	outbyte(' ');
	outstr(item->name.namep + 2);
	outstr(" (offset ");
	outshex(item->offset.offi);
	outbyte(')');
	return;
    }
    if (item->storage == LOCAL)
    {
	outbyte(' ');
	if (item->flags == TEMP)
	    outstr("(temp)");
	else
	    outstr(item->name.namep);
    }
    outstr(" = ");
    outindchars('[', item->indcount);
    switch (item->storage)
    {
    case CONSTANT:
	outstr("const ");
	if (item->type->scalar & RSCALAR)
	    outstr("(whatever)");
	else if (item->type->scalar & UNSIGNED)
	    outuvalue((uvalue_t) item->offset.offv);
	else
	    outvalue(item->offset.offv);
	break;
    case BREG:
    case DREG:
    case INDREG0:
    case INDREG1:
    case INDREG2:
#ifdef DATREG1
    case DATREG1:
#endif
#ifdef DATREG2
    case DATREG2:
#endif
	outregname(item->storage);
	if (item->level == OFFKLUDGELEVEL)
	{
	    outplus();
	    if (item->flags & LABELLED)
		outlabel(item->name.label);
	    else
		outccname(item->name.namep);
	}
	break;
    case LOCAL:
	outbyte('S');
	if (sp <= 0)
	    outplus();
	outshex(-sp);
	break;
    case GLOBAL:
	if (item->flags & LABELLED)
	    outlabel(item->name.label);
	else
	    outstr(item->name.namep);
	break;
    default:
	outstr("bad storage (");
	outhex((uoffset_T) item->storage);
	outbyte(')');
	outstr(" offset ");
    }
    if (item->storage != CONSTANT)
    {
	if (item->offset.offi >= 0)
	    outplus();
	outshex(item->offset.offi);
    }
    outindchars(']', item->indcount);
}

PUBLIC void dbtype(type)
struct typestruct *type;
{
    for ( ; type != NULL; type = type->nexttype)
    {
	outbyte(' ');
	switch (type->constructor)
	{
	case ARRAY:
	    outbyte('[');
	    outhex(type->typesize / type->nexttype->typesize);
	    outbyte(']');
	    break;
	case FUNCTION:
	    outstr("()");
	    break;
	case POINTER:
	    outbyte('*');
	    break;
	case STRUCTU:
	    outstr("struct ");
	default:
	    if (type->scalar & UNSIGNED)
		outstr("unsigned ");
	    outstr(type->tname);
	    break;
	}
    }
}

PUBLIC void dbnode(exp)		/* sub-nodes must be leaves */
struct nodestruct *exp;
{
    if (!dbnodeon)
	return;
    outstr("! Debug: ");
    if (exp->tag < FIRSTOP && exp->tag > LASTOP)
	outstr("unknown op");
    else
	outstr(opname[exp->tag - FIRSTOP]);
    if (exp->right != NULL && exp->tag != FUNCOP &&
	exp->tag != LISTOP && exp->tag != ROOTLISTOP)
    {
	dbitem(exp->right->left.symptr);
	outstr(" to");
    }
    dbitem(exp->left.nodeptr->left.symptr);
    outstr(" (used reg = ");
    if (reguse & INDREG0)
	outregname(INDREG0);
    if (reguse & INDREG1)
	outregname(INDREG1);
    if (reguse & INDREG2)
	outregname(INDREG2);
    outnstr(")");
}

PUBLIC void dbnodeswap()
{
    if (dbnodeon)
	outnstr("! Debug: expression subtree swapping");
}

PRIVATE void outindchars(byte, count)
int byte;
indn_pt count;
{
    while (count--)
	outbyte(byte);
}

#endif /* DBNODE */