Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

tree.c File Reference

#include "c.h"

Include dependency graph for tree.c:

Include dependency graph

Go to the source code of this file.

Data Structures

struct  nodeid

Functions

int nodeid (Tree p)
char * opname (int op)
int * printed (int id)
void printtree (Tree p, int fd)
void printtree1 (Tree, int, int)
Tree root (Tree p)
Tree root1 (Tree p)
Tree texpr (Tree(*f)(int), int tok, int a)
Tree tree (int op, Type type, Tree left, Tree right)

Variables

nodeid ids [500]
int nid = 1
int warn
int where = STMT


Function Documentation

int nodeid Tree  p  ) 
 

Definition at line 172 of file tree.c.

References i, ids, nid, nodeid::node, nodeid::printed, and Tree.

Referenced by printdag(), printdag1(), printnode(), and printtree1().

00172                    {
00173     int i = 1;
00174 
00175     ids[nid].node = p;
00176     while (ids[i].node != p)
00177         i++;
00178     if (i == nid)
00179         ids[nid++].printed = 0;
00180     return i;
00181 }

char* opname int  op  ) 
 

Definition at line 113 of file tree.c.

References AND, FIELD, generic, NELEMS, op, opindex, opsize, optype, stringd(), stringf(), and suffixes.

Referenced by doop(), dumptree(), Emit4(), getrule(), Inst(), Inst4(), InstImm(), InstImmU(), printnode(), and printtree1().

00113                      {
00114     static char *opnames[] = {
00115     "",
00116     "CNST",
00117     "ARG",
00118     "ASGN",
00119     "INDIR",
00120     "CVC",
00121     "CVD",
00122     "CVF",
00123     "CVI",
00124     "CVP",
00125     "CVS",
00126     "CVU",
00127     "NEG",
00128     "CALL",
00129     "*LOAD*",
00130     "RET",
00131     "ADDRG",
00132     "ADDRF",
00133     "ADDRL",
00134     "ADD",
00135     "SUB",
00136     "LSH",
00137     "MOD",
00138     "RSH",
00139     "BAND",
00140     "BCOM",
00141     "BOR",
00142     "BXOR",
00143     "DIV",
00144     "MUL",
00145     "EQ",
00146     "GE",
00147     "GT",
00148     "LE",
00149     "LT",
00150     "NE",
00151     "JUMP",
00152     "LABEL",
00153     "AND",
00154     "NOT",
00155     "OR",
00156     "COND",
00157     "RIGHT",
00158     "FIELD"
00159     }, *suffixes[] = {
00160         "0", "F", "D", "C", "S", "I", "U", "P", "V", "B",
00161         "10","11","12","13","14","15"
00162     };
00163 
00164     if (generic(op) >= AND && generic(op) <= FIELD && opsize(op) == 0)
00165         return opnames[opindex(op)];
00166     return stringf("%s%s%s",
00167         opindex(op) > 0 && opindex(op) < NELEMS(opnames) ?
00168             opnames[opindex(op)] : stringd(opindex(op)),
00169         suffixes[optype(op)], opsize(op) > 0 ? stringd(opsize(op)) : "");
00170 }

Here is the call graph for this function:

int* printed int  id  ) 
 

Definition at line 184 of file tree.c.

References ids, nid, and nodeid::printed.

Referenced by opt(), PointToPolygonFormFactor(), printdag(), printdag1(), printtree(), and printtree1().

00184                      {
00185     if (id)
00186         return &ids[id].printed;
00187     nid = 1;
00188     return 0;
00189 }

void printtree Tree  p,
int  fd
 

Definition at line 192 of file tree.c.

References p, printed(), printtree1(), and Tree.

00192                                {
00193     (void)printed(0);
00194     printtree1(p, fd, 1);
00195 }

Here is the call graph for this function:

void printtree1 Tree  ,
int  ,
int 
[static]
 

Definition at line 198 of file tree.c.

References f, FIELD, fieldright, fieldsize, fprint(), generic, i, NELEMS, nodeid(), opname(), p, printed(), stdout, Tree, and vtoa().

Referenced by printtree().

00198                                                 {
00199     FILE *f = fd == 1 ? stdout : stderr;
00200     int i;
00201     static char blanks[] = "                                                   ";
00202 
00203     if (p == 0 || *printed(i = nodeid(p)))
00204         return;
00205     fprint(f, "#%d%S%S", i, blanks, i < 10 ? 2 : i < 100 ? 1 : 0, blanks, lev);
00206     fprint(f, "%s %t", opname(p->op), p->type);
00207     *printed(i) = 1;
00208     for (i = 0; i < NELEMS(p->kids); i++)
00209         if (p->kids[i])
00210             fprint(f, " #%d", nodeid(p->kids[i]));
00211     if (p->op == FIELD && p->u.field)
00212         fprint(f, " %s %d..%d", p->u.field->name,
00213             fieldsize(p->u.field) + fieldright(p->u.field), fieldright(p->u.field));
00214     else if (generic(p->op) == CNST)
00215         fprint(f, " %s", vtoa(p->type, p->u.v));
00216     else if (p->u.sym)
00217         fprint(f, " %s", p->u.sym->name);
00218     if (p->node)
00219         fprint(f, " node=%p", p->node);
00220     fprint(f, "\n");
00221     for (i = 0; i < NELEMS(p->kids); i++)
00222         printtree1(p->kids[i], fd, lev + 1);
00223 }

Here is the call graph for this function:

Tree root Tree  p  ) 
 

Definition at line 108 of file tree.c.

References p, root1(), Tree, and warn.

Referenced by CreateNullCursor(), dcllocal(), emitrecalc(), GLW_SetMode(), main(), and simplify().

00108                   {
00109     warn = 0;
00110     return root1(p);
00111 }

Here is the call graph for this function:

Tree root1 Tree  p  )  [static]
 

Definition at line 34 of file tree.c.

References ADD, ADDRF, ADDRG, ADDRL, AND, ARG, ASGN, assert, B, BAND, BCOM, BOR, BXOR, CALL, CNST, COND, CVF, CVI, CVP, CVU, DIV, EQ, FIELD, GE, generic, GT, INDIR, isptr, isvolatile, JUMP, tree::kids, LABEL, LE, LSH, LT, MOD, MUL, NE, NEG, NOT, tree::op, OR, p, q, RIGHT, root1(), RSH, type::size, SUB, tree::sym, tree(), Tree, type::type, tree::type, tree::u, unqual, warn, and warning().

Referenced by root(), and root1().

00034                           {
00035     if (p == NULL)
00036         return p;
00037     if (p->type == voidtype)
00038         warn++;
00039     switch (generic(p->op)) {
00040     case COND: {
00041         Tree q = p->kids[1];
00042         assert(q && q->op == RIGHT);
00043         if (p->u.sym && q->kids[0] && generic(q->kids[0]->op) == ASGN)
00044             q->kids[0] = root1(q->kids[0]->kids[1]);
00045         else
00046             q->kids[0] = root1(q->kids[0]);
00047         if (p->u.sym && q->kids[1] && generic(q->kids[1]->op) == ASGN)
00048             q->kids[1] = root1(q->kids[1]->kids[1]);
00049         else
00050             q->kids[1] = root1(q->kids[1]);
00051         p->u.sym = 0;
00052         if (q->kids[0] == 0 && q->kids[1] == 0)
00053             p = root1(p->kids[0]);
00054         }
00055         break;
00056     case AND: case OR:
00057         if ((p->kids[1] = root1(p->kids[1])) == 0)
00058             p = root1(p->kids[0]);
00059         break;
00060     case NOT:
00061         if (warn++ == 0)
00062             warning("expression with no effect elided\n");
00063         return root1(p->kids[0]);
00064     case RIGHT:
00065         if (p->kids[1] == 0)
00066             return root1(p->kids[0]);
00067         if (p->kids[0] && p->kids[0]->op == CALL+B
00068         &&  p->kids[1] && p->kids[1]->op == INDIR+B)
00069             /* avoid premature release of the CALL+B temporary */
00070             return p->kids[0];
00071         if (p->kids[0] && p->kids[0]->op == RIGHT
00072         &&  p->kids[1] == p->kids[0]->kids[0])
00073             /* de-construct e++ construction */
00074             return p->kids[0]->kids[1];
00075         p = tree(RIGHT, p->type, root1(p->kids[0]), root1(p->kids[1]));
00076         return p->kids[0] || p->kids[1] ? p : (Tree)0;
00077     case EQ:  case NE:  case GT:   case GE:  case LE:  case LT: 
00078     case ADD: case SUB: case MUL:  case DIV: case MOD:
00079     case LSH: case RSH: case BAND: case BOR: case BXOR:
00080         if (warn++ == 0)
00081             warning("expression with no effect elided\n");
00082         p = tree(RIGHT, p->type, root1(p->kids[0]), root1(p->kids[1]));
00083         return p->kids[0] || p->kids[1] ? p : (Tree)0;
00084     case INDIR:
00085         if (p->type->size == 0 && unqual(p->type) != voidtype)
00086             warning("reference to `%t' elided\n", p->type);
00087         if (isptr(p->kids[0]->type) && isvolatile(p->kids[0]->type->type))
00088             warning("reference to `volatile %t' elided\n", p->type);
00089         /* fall thru */
00090     case CVI: case CVF: case CVU: case CVP:
00091     case NEG: case BCOM: case FIELD:
00092         if (warn++ == 0)
00093             warning("expression with no effect elided\n");
00094         return root1(p->kids[0]);
00095     case ADDRL: case ADDRG: case ADDRF: case CNST:
00096         if (needconst)
00097             return p;
00098         if (warn++ == 0)
00099             warning("expression with no effect elided\n");
00100         return NULL;
00101     case ARG: case ASGN: case CALL: case JUMP: case LABEL:
00102         break;
00103     default: assert(0);
00104     }
00105     return p;
00106 }

Here is the call graph for this function:

Tree texpr Tree(*)(int)  f,
int  tok,
int  a
 

Definition at line 25 of file tree.c.

References p, Tree, and where.

Referenced by forstmt(), and whilestmt().

00025                                            {
00026     int save = where;
00027     Tree p;
00028 
00029     where = a;
00030     p = (*f)(tok);
00031     where = save;
00032     return p;
00033 }

Tree tree int  op,
Type  type,
Tree  left,
Tree  right
 

Definition at line 14 of file tree.c.

References tree::kids, NEW0, tree::op, p, Tree, tree::type, Type, and where.

Referenced by addrtree(), bbcall(), bbincr(), listnodes(), retcode(), root1(), simplify(), swcode(), tracefinis(), tracevalue(), and yyparse().

00014                                                     {
00015     Tree p;
00016 
00017     NEW0(p, where);
00018     p->op = op;
00019     p->type = type;
00020     p->kids[0] = left;
00021     p->kids[1] = right;
00022     return p;
00023 }


Variable Documentation

struct nodeid ids[500] [static]
 

Referenced by nodeid(), and printed().

int nid = 1 [static]
 

Definition at line 6 of file tree.c.

Referenced by nodeid(), and printed().

int warn [static]
 

Definition at line 5 of file tree.c.

Referenced by root(), and root1().

int where = STMT
 

Definition at line 4 of file tree.c.

Referenced by texpr(), and tree().


Generated on Thu Aug 25 13:09:38 2005 for Quake III Arena by  doxygen 1.3.9.1