~ubuntu-branches/ubuntu/utopic/linux86/utopic

« back to all changes in this revision

Viewing changes to bcc/dbnode.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-12-07 20:33:39 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20071207203339-uonmnsb2j32kh0sg
Tags: 0.16.17-2ubuntu1
* Merge with Debian; remaining changes:
  - Build elks-libc for lpia.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* dbnode.c - print debug messages for operators for bcc */
 
2
 
 
3
/* Copyright (C) 1992 Bruce Evans */
 
4
 
 
5
#include "bcc.h"
 
6
 
 
7
#ifdef DBNODE
 
8
#include "gencode.h"
 
9
#include "reg.h"
 
10
#include "sc.h"
 
11
#include "scan.h"
 
12
#include "type.h"
 
13
 
 
14
PRIVATE char *opname[LASTOP - FIRSTOP + 1] =    /* operator names */
 
15
{                               /* order must agree with op.h */
 
16
    "cond?",
 
17
    "or",
 
18
    "eor",
 
19
    "and",
 
20
    "gt", "lt",
 
21
    "add",
 
22
    "div", "mod",
 
23
    "lognot", "not",
 
24
    "strucelt", "strucptr",
 
25
    "eq",
 
26
    "addab", "andab", "divab", "eorab", "modab", "mulab", "orab",
 
27
    "slab", "srab", "subab",
 
28
    "comma",
 
29
    "cond:",
 
30
    "logor",
 
31
    "logand",
 
32
    "logeq",
 
33
    "ne",
 
34
    "ge", "le",
 
35
    "sl", "sr",
 
36
    "sub",
 
37
    "mul",
 
38
    "address", "cast", "indirect", "neg",
 
39
    "predec", "preinc", "postdec", "postinc",
 
40
    "func", "list", "rootlist",
 
41
    "leaf",
 
42
    "ptraddab", "ptradd", "ptrsub",
 
43
};
 
44
 
 
45
FORWARD void outindchars P((int byte, indn_pt count));
 
46
 
 
47
PUBLIC void dbitem(item)
 
48
struct symstruct *item;
 
49
{
 
50
    dbtype(item->type);
 
51
    if (item->storage == NOSTORAGE)
 
52
    {
 
53
        outbyte(' ');
 
54
        outstr(item->name.namep + 2);
 
55
        outstr(" (offset ");
 
56
        outshex(item->offset.offi);
 
57
        outbyte(')');
 
58
        return;
 
59
    }
 
60
    if (item->storage == LOCAL)
 
61
    {
 
62
        outbyte(' ');
 
63
        if (item->flags == TEMP)
 
64
            outstr("(temp)");
 
65
        else
 
66
            outstr(item->name.namep);
 
67
    }
 
68
    outstr(" = ");
 
69
    outindchars('[', item->indcount);
 
70
    switch (item->storage)
 
71
    {
 
72
    case CONSTANT:
 
73
        outstr("const ");
 
74
        if (item->type->scalar & RSCALAR)
 
75
            outstr("(whatever)");
 
76
        else if (item->type->scalar & UNSIGNED)
 
77
            outuvalue((uvalue_t) item->offset.offv);
 
78
        else
 
79
            outvalue(item->offset.offv);
 
80
        break;
 
81
    case BREG:
 
82
    case DREG:
 
83
    case INDREG0:
 
84
    case INDREG1:
 
85
    case INDREG2:
 
86
#ifdef DATREG1
 
87
    case DATREG1:
 
88
#endif
 
89
#ifdef DATREG2
 
90
    case DATREG2:
 
91
#endif
 
92
        outregname(item->storage);
 
93
        if (item->level == OFFKLUDGELEVEL)
 
94
        {
 
95
            outplus();
 
96
            if (item->flags & LABELLED)
 
97
                outlabel(item->name.label);
 
98
            else
 
99
                outccname(item->name.namep);
 
100
        }
 
101
        break;
 
102
    case LOCAL:
 
103
        outbyte('S');
 
104
        if (sp <= 0)
 
105
            outplus();
 
106
        outshex(-sp);
 
107
        break;
 
108
    case GLOBAL:
 
109
        if (item->flags & LABELLED)
 
110
            outlabel(item->name.label);
 
111
        else
 
112
            outstr(item->name.namep);
 
113
        break;
 
114
    default:
 
115
        outstr("bad storage (");
 
116
        outhex((uoffset_T) item->storage);
 
117
        outbyte(')');
 
118
        outstr(" offset ");
 
119
    }
 
120
    if (item->storage != CONSTANT)
 
121
    {
 
122
        if (item->offset.offi >= 0)
 
123
            outplus();
 
124
        outshex(item->offset.offi);
 
125
    }
 
126
    outindchars(']', item->indcount);
 
127
}
 
128
 
 
129
PUBLIC void dbtype(type)
 
130
struct typestruct *type;
 
131
{
 
132
    for ( ; type != NULL; type = type->nexttype)
 
133
    {
 
134
        outbyte(' ');
 
135
        switch (type->constructor)
 
136
        {
 
137
        case ARRAY:
 
138
            outbyte('[');
 
139
            outhex(type->typesize / type->nexttype->typesize);
 
140
            outbyte(']');
 
141
            break;
 
142
        case FUNCTION:
 
143
            outstr("()");
 
144
            break;
 
145
        case POINTER:
 
146
            outbyte('*');
 
147
            break;
 
148
        case STRUCTU:
 
149
            outstr("struct ");
 
150
        default:
 
151
            if (type->scalar & UNSIGNED)
 
152
                outstr("unsigned ");
 
153
            outstr(type->tname);
 
154
            break;
 
155
        }
 
156
    }
 
157
}
 
158
 
 
159
PUBLIC void dbnode(exp)         /* sub-nodes must be leaves */
 
160
struct nodestruct *exp;
 
161
{
 
162
    if (!dbnodeon)
 
163
        return;
 
164
    outstr("! Debug: ");
 
165
    if (exp->tag < FIRSTOP && exp->tag > LASTOP)
 
166
        outstr("unknown op");
 
167
    else
 
168
        outstr(opname[exp->tag - FIRSTOP]);
 
169
    if (exp->right != NULL && exp->tag != FUNCOP &&
 
170
        exp->tag != LISTOP && exp->tag != ROOTLISTOP)
 
171
    {
 
172
        dbitem(exp->right->left.symptr);
 
173
        outstr(" to");
 
174
    }
 
175
    dbitem(exp->left.nodeptr->left.symptr);
 
176
    outstr(" (used reg = ");
 
177
    if (reguse & INDREG0)
 
178
        outregname(INDREG0);
 
179
    if (reguse & INDREG1)
 
180
        outregname(INDREG1);
 
181
    if (reguse & INDREG2)
 
182
        outregname(INDREG2);
 
183
    outnstr(")");
 
184
}
 
185
 
 
186
PUBLIC void dbnodeswap()
 
187
{
 
188
    if (dbnodeon)
 
189
        outnstr("! Debug: expression subtree swapping");
 
190
}
 
191
 
 
192
PRIVATE void outindchars(byte, count)
 
193
int byte;
 
194
indn_pt count;
 
195
{
 
196
    while (count--)
 
197
        outbyte(byte);
 
198
}
 
199
 
 
200
#endif /* DBNODE */