OpenCores
URL https://opencores.org/ocsvn/eco32/eco32/trunk

Subversion Repositories eco32

[/] [eco32/] [trunk/] [lcc/] [src/] [expr.c] - Blame information for rev 82

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 hellwig
#include "c.h"
2
 
3
static char rcsid[] = "$Id: expr.c,v 1.1 2002/08/28 23:12:43 drh Exp $";
4
 
5
static char prec[] = {
6
#define xx(a,b,c,d,e,f,g) c,
7
#define yy(a,b,c,d,e,f,g) c,
8
#include "token.h"
9
};
10
static int oper[] = {
11
#define xx(a,b,c,d,e,f,g) d,
12
#define yy(a,b,c,d,e,f,g) d,
13
#include "token.h"
14
};
15
float refinc = 1.0;
16
static Tree expr2(void);
17
static Tree expr3(int);
18
static Tree nullcheck(Tree);
19
static Tree postfix(Tree);
20
static Tree unary(void);
21
static Tree primary(void);
22
static Type super(Type ty);
23
 
24
static Type super(Type ty) {
25
        switch (ty->op) {
26
        case INT:
27
                if (ty->size < inttype->size)
28
                        return inttype;
29
                break;
30
        case UNSIGNED:
31
                if (ty->size < unsignedtype->size)
32
                        return unsignedtype;
33
                break;
34
        case POINTER:
35
                return unsignedptr;
36
        }
37
        return ty;
38
}
39
Tree expr(int tok) {
40
        static char stop[] = { IF, ID, '}', 0 };
41
        Tree p = expr1(0);
42
 
43
        while (t == ',') {
44
                Tree q;
45
                t = gettok();
46
                q = pointer(expr1(0));
47
                p = tree(RIGHT, q->type, root(value(p)), q);
48
        }
49
        if (tok)
50
                test(tok, stop);
51
        return p;
52
}
53
Tree expr0(int tok) {
54
        return root(expr(tok));
55
}
56
Tree expr1(int tok) {
57
        static char stop[] = { IF, ID, 0 };
58
        Tree p = expr2();
59
 
60
        if (t == '='
61
        || (prec[t] >=  6 && prec[t] <=  8)
62
        || (prec[t] >= 11 && prec[t] <= 13)) {
63
                int op = t;
64
                t = gettok();
65
                if (oper[op] == ASGN)
66
                        p = asgntree(ASGN, p, value(expr1(0)));
67
                else
68
                        {
69
                                expect('=');
70
                                p = incr(op, p, expr1(0));
71
                        }
72
        }
73
        if (tok)
74
                test(tok, stop);
75
        return p;
76
}
77
Tree incr(int op, Tree v, Tree e) {
78
        return asgntree(ASGN, v, (*optree[op])(oper[op], v, e));
79
}
80
static Tree expr2(void) {
81
        Tree p = expr3(4);
82
 
83
        if (t == '?') {
84
                Tree l, r;
85
                Coordinate pts[2];
86
                if (Aflag > 1 && isfunc(p->type))
87
                        warning("%s used in a conditional expression\n",
88
                                funcname(p));
89
                p = pointer(p);
90
                t = gettok();
91
                pts[0] = src;
92
                l = pointer(expr(':'));
93
                pts[1] = src;
94
                r = pointer(expr2());
95
                if (generic(p->op) != CNST && events.points)
96
                        {
97
                                apply(events.points, &pts[0], &l);
98
                                apply(events.points, &pts[1], &r);
99
                        }
100
                p = condtree(p, l, r);
101
        }
102
        return p;
103
}
104
Tree value(Tree p) {
105
        int op = generic(rightkid(p)->op);
106
 
107
        if (p->type != voidtype
108
        && (op==AND || op==OR || op==NOT || op==EQ || op==NE
109
        ||  op== LE || op==LT || op== GE || op==GT))
110
                p = condtree(p, consttree(1, inttype),
111
                        consttree(0, inttype));
112
        return p;
113
}
114
static Tree expr3(int k) {
115
        int k1;
116
        Tree p = unary();
117
 
118
        for (k1 = prec[t]; k1 >= k; k1--)
119
                while (prec[t] == k1 && *cp != '=') {
120
                        Tree r;
121
                        Coordinate pt;
122
                        int op = t;
123
                        t = gettok();
124
                        pt = src;
125
                        p = pointer(p);
126
                        if (op == ANDAND || op == OROR) {
127
                                r = pointer(expr3(k1));
128
                                if (events.points)
129
                                        apply(events.points, &pt, &r);
130
                        } else
131
                                r = pointer(expr3(k1 + 1));
132
                        p = (*optree[op])(oper[op], p, r);
133
                }
134
        return p;
135
}
136
static Tree unary(void) {
137
        Tree p;
138
 
139
        switch (t) {
140
        case '*':    t = gettok(); p = unary(); p = pointer(p);
141
                                                  if (isptr(p->type)
142
                                                  && (isfunc(p->type->type) || isarray(p->type->type)))
143
                                                        p = retype(p, p->type->type);
144
                                                  else {
145
                                                        if (YYnull)
146
                                                                p = nullcheck(p);
147
                                                        p = rvalue(p);
148
                                                  } break;
149
        case '&':    t = gettok(); p = unary(); if (isarray(p->type) || isfunc(p->type))
150
                                                        p = retype(p, ptr(p->type));
151
                                                  else
152
                                                        p = lvalue(p);
153
                                                  if (isaddrop(p->op) && p->u.sym->sclass == REGISTER)
154
                                                        error("invalid operand of unary &; `%s' is declared register\n", p->u.sym->name);
155
 
156
                                                  else if (isaddrop(p->op))
157
                                                        p->u.sym->addressed = 1;
158
 break;
159
        case '+':    t = gettok(); p = unary(); p = pointer(p);
160
                                                  if (isarith(p->type))
161
                                                        p = cast(p, promote(p->type));
162
                                                  else
163
                                                        typeerror(ADD, p, NULL);  break;
164
        case '-':    t = gettok(); p = unary(); p = pointer(p);
165
                                                  if (isarith(p->type)) {
166
                                                        Type ty = promote(p->type);
167
                                                        p = cast(p, ty);
168
                                                        if (isunsigned(ty)) {
169
                                                                warning("unsigned operand of unary -\n");
170
                                                                p = simplify(ADD, ty, simplify(BCOM, ty, p, NULL), cnsttree(ty, 1UL));
171
                                                        } else
172
                                                                p = simplify(NEG, ty, p, NULL);
173
                                                  } else
174
                                                        typeerror(SUB, p, NULL); break;
175
        case '~':    t = gettok(); p = unary(); p = pointer(p);
176
                                                  if (isint(p->type)) {
177
                                                        Type ty = promote(p->type);
178
                                                        p = simplify(BCOM, ty, cast(p, ty), NULL);
179
                                                  } else
180
                                                        typeerror(BCOM, p, NULL);  break;
181
        case '!':    t = gettok(); p = unary(); p = pointer(p);
182
                                                  if (isscalar(p->type))
183
                                                        p = simplify(NOT, inttype, cond(p), NULL);
184
                                                  else
185
                                                        typeerror(NOT, p, NULL); break;
186
        case INCR:   t = gettok(); p = unary(); p = incr(INCR, pointer(p), consttree(1, inttype)); break;
187
        case DECR:   t = gettok(); p = unary(); p = incr(DECR, pointer(p), consttree(1, inttype)); break;
188
        case TYPECODE: case SIZEOF: { int op = t;
189
                                      Type ty;
190
                                      p = NULL;
191
                                      t = gettok();
192
                                      if (t == '(') {
193
                                        t = gettok();
194
                                        if (istypename(t, tsym)) {
195
                                                ty = typename();
196
                                                expect(')');
197
                                        } else {
198
                                                p = postfix(expr(')'));
199
                                                ty = p->type;
200
                                        }
201
                                      } else {
202
                                        p = unary();
203
                                        ty = p->type;
204
                                      }
205
                                      assert(ty);
206
                                      if (op == TYPECODE)
207
                                        p = cnsttree(inttype, (long)ty->op);
208
                                      else {
209
                                        if (isfunc(ty) || ty->size == 0)
210
                                                error("invalid type argument `%t' to `sizeof'\n", ty);
211
                                        else if (p && rightkid(p)->op == FIELD)
212
                                                error("`sizeof' applied to a bit field\n");
213
                                        p = cnsttree(unsignedlong, (unsigned long)ty->size);
214
                                      } } break;
215
        case '(':
216
                t = gettok();
217
                if (istypename(t, tsym)) {
218
                        Type ty, ty1 = typename(), pty;
219
                        expect(')');
220
                        ty = unqual(ty1);
221
                        if (isenum(ty)) {
222
                                Type ty2 = ty->type;
223
                                if (isconst(ty1))
224
                                        ty2 = qual(CONST, ty2);
225
                                if (isvolatile(ty1))
226
                                        ty2 = qual(VOLATILE, ty2);
227
                                ty1 = ty2;
228
                                ty = ty->type;
229
                        }
230
                        p = pointer(unary());
231
                        pty = p->type;
232
                        if (isenum(pty))
233
                                pty = pty->type;
234
                        if (isarith(pty) && isarith(ty)
235
                        ||  isptr(pty)   && isptr(ty)) {
236
                                explicitCast++;
237
                                p = cast(p, ty);
238
                                explicitCast--;
239
                        } else if (isptr(pty) && isint(ty)
240
                        ||       isint(pty) && isptr(ty)) {
241
                                if (Aflag >= 1 && ty->size < pty->size)
242
                                        warning("conversion from `%t' to `%t' is compiler dependent\n", p->type, ty);
243
 
244
                                p = cast(p, ty);
245
                        } else if (ty != voidtype) {
246
                                error("cast from `%t' to `%t' is illegal\n",
247
                                        p->type, ty1);
248
                                ty1 = inttype;
249
                        }
250
                        if (generic(p->op) == INDIR || ty->size == 0)
251
                                p = tree(RIGHT, ty1, NULL, p);
252
                        else
253
                                p = retype(p, ty1);
254
                } else
255
                        p = postfix(expr(')'));
256
                break;
257
        default:
258
                p = postfix(primary());
259
        }
260
        return p;
261
}
262
 
263
static Tree postfix(Tree p) {
264
        for (;;)
265
                switch (t) {
266
                case INCR:  p = tree(RIGHT, p->type,
267
                                tree(RIGHT, p->type,
268
                                        p,
269
                                        incr(t, p, consttree(1, inttype))),
270
                                p);
271
                            t = gettok(); break;
272
                case DECR:  p = tree(RIGHT, p->type,
273
                                tree(RIGHT, p->type,
274
                                        p,
275
                                        incr(t, p, consttree(1, inttype))),
276
                                p);
277
                            t = gettok(); break;
278
                case '[':   {
279
                                Tree q;
280
                                t = gettok();
281
                                q = expr(']');
282
                                if (YYnull)
283
                                        if (isptr(p->type))
284
                                                p = nullcheck(p);
285
                                        else if (isptr(q->type))
286
                                                q = nullcheck(q);
287
                                p = (*optree['+'])(ADD, pointer(p), pointer(q));
288
                                if (isptr(p->type) && isarray(p->type->type))
289
                                        p = retype(p, p->type->type);
290
                                else
291
                                        p = rvalue(p);
292
                            } break;
293
                case '(':   {
294
                                Type ty;
295
                                Coordinate pt;
296
                                p = pointer(p);
297
                                if (isptr(p->type) && isfunc(p->type->type))
298
                                        ty = p->type->type;
299
                                else {
300
                                        error("found `%t' expected a function\n", p->type);
301
                                        ty = func(voidtype, NULL, 1);
302
                                        p = retype(p, ptr(ty));
303
                                }
304
                                pt = src;
305
                                t = gettok();
306
                                p = call(p, ty, pt);
307
                            } break;
308
                case '.':   t = gettok();
309
                            if (t == ID) {
310
                                if (isstruct(p->type)) {
311
                                        Tree q = addrof(p);
312
                                        p = field(q, token);
313
                                        q = rightkid(q);
314
                                        if (isaddrop(q->op) && q->u.sym->temporary)
315
                                                p = tree(RIGHT, p->type, p, NULL);
316
                                } else
317
                                        error("left operand of . has incompatible type `%t'\n",
318
                                                p->type);
319
                                t = gettok();
320
                            } else
321
                                error("field name expected\n"); break;
322
                case DEREF: t = gettok();
323
                            p = pointer(p);
324
                            if (t == ID) {
325
                                if (isptr(p->type) && isstruct(p->type->type)) {
326
                                        if (YYnull)
327
                                                p = nullcheck(p);
328
                                        p = field(p, token);
329
                                } else
330
                                        error("left operand of -> has incompatible type `%t'\n", p->type);
331
 
332
                                t = gettok();
333
                            } else
334
                                error("field name expected\n"); break;
335
                default:
336
                        return p;
337
                }
338
}
339
static Tree primary(void) {
340
        Tree p;
341
 
342
        assert(t != '(');
343
        switch (t) {
344
        case ICON:
345
        case FCON: p = tree(mkop(CNST,tsym->type), tsym->type, NULL, NULL);
346
                   p->u.v = tsym->u.c.v;
347
 break;
348
        case SCON: if (ischar(tsym->type->type))
349
                        tsym->u.c.v.p = stringn(tsym->u.c.v.p, tsym->type->size);
350
                   else
351
                        tsym->u.c.v.p = memcpy(allocate((tsym->type->size/widechar->size)*sizeof (int), PERM),
352
                                tsym->u.c.v.p, (tsym->type->size/widechar->size)*sizeof (int));
353
                   tsym = constant(tsym->type, tsym->u.c.v);
354
                   if (tsym->u.c.loc == NULL)
355
                        tsym->u.c.loc = genident(STATIC, tsym->type, GLOBAL);
356
                   p = idtree(tsym->u.c.loc); break;
357
        case ID:   if (tsym == NULL)
358
                        {
359
                                Symbol p = install(token, &identifiers, level, PERM);
360
                                p->src = src;
361
                                if (getchr() == '(') {
362
                                        Symbol q = lookup(token, externals);
363
                                        p->type = func(inttype, NULL, 1);
364
                                        p->sclass = EXTERN;
365
                                        if (Aflag >= 1)
366
                                                warning("missing prototype\n");
367
                                        if (q && !eqtype(q->type, p->type, 1))
368
                                                warning("implicit declaration of `%s' does not match previous declaration at %w\n", q->name, &q->src);
369
 
370
                                        if (q == NULL) {
371
                                                q = install(p->name, &externals, GLOBAL, PERM);
372
                                                q->type = p->type;
373
                                                q->sclass = EXTERN;
374
                                                q->src = src;
375
                                                (*IR->defsymbol)(q);
376
                                        }
377
                                        p->u.alias = q;
378
                                } else {
379
                                        error("undeclared identifier `%s'\n", p->name);
380
                                        p->sclass = AUTO;
381
                                        p->type = inttype;
382
                                        if (p->scope == GLOBAL)
383
                                                (*IR->defsymbol)(p);
384
                                        else
385
                                                addlocal(p);
386
                                }
387
                                t = gettok();
388
                                if (xref)
389
                                        use(p, src);
390
                                return idtree(p);
391
                        }
392
                   if (xref)
393
                        use(tsym, src);
394
                   if (tsym->sclass == ENUM)
395
                        p = consttree(tsym->u.value, inttype);
396
                   else {
397
                        if (tsym->sclass == TYPEDEF)
398
                                error("illegal use of type name `%s'\n", tsym->name);
399
                        p = idtree(tsym);
400
                   } break;
401
        case FIRSTARG:
402
                if (level > PARAM && cfunc && cfunc->u.f.callee[0])
403
                        p = idtree(cfunc->u.f.callee[0]);
404
                else {
405
                        error("illegal use of `%k'\n", FIRSTARG);
406
                        p = cnsttree(inttype, 0L);
407
                }
408
                break;
409
        default:
410
                error("illegal expression\n");
411
                        p = cnsttree(inttype, 0L);
412
        }
413
        t = gettok();
414
        return p;
415
}
416
Tree idtree(Symbol p) {
417
        int op;
418
        Tree e;
419
        Type ty = p->type ? unqual(p->type) : voidptype;
420
 
421
        if (p->scope == GLOBAL || p->sclass == STATIC)
422
                op = ADDRG;
423
        else if (p->scope == PARAM) {
424
                op = ADDRF;
425
                if (isstruct(p->type) && !IR->wants_argb)
426
                        {
427
                                e = tree(mkop(op,voidptype), ptr(ptr(p->type)), NULL, NULL);
428
                                e->u.sym = p;
429
                                return rvalue(rvalue(e));
430
                        }
431
        } else if (p->sclass == EXTERN) {
432
                assert(p->u.alias);
433
                p = p->u.alias;
434
                op = ADDRG;
435
        } else
436
                op = ADDRL;
437
        p->ref += refinc;
438
        if (isarray(ty))
439
                e = tree(mkop(op,voidptype), p->type,      NULL, NULL);
440
        else if (isfunc(ty))
441
                e = tree(mkop(op,funcptype), p->type,      NULL, NULL);
442
        else
443
                e = tree(mkop(op,voidptype), ptr(p->type), NULL, NULL);
444
        e->u.sym = p;
445
        if (isptr(e->type))
446
                e = rvalue(e);
447
        return e;
448
}
449
 
450
Tree rvalue(Tree p) {
451
        Type ty = deref(p->type);
452
 
453
        ty = unqual(ty);
454
        return tree(mkop(INDIR,ty), ty, p, NULL);
455
}
456
Tree lvalue(Tree p) {
457
        if (generic(p->op) != INDIR) {
458
                error("lvalue required\n");
459
                return value(p);
460
        } else if (unqual(p->type) == voidtype)
461
                warning("`%t' used as an lvalue\n", p->type);
462
        return p->kids[0];
463
}
464
Tree retype(Tree p, Type ty) {
465
        Tree q;
466
 
467
        if (p->type == ty)
468
                return p;
469
        q = tree(p->op, ty, p->kids[0], p->kids[1]);
470
        q->node = p->node;
471
        q->u = p->u;
472
        return q;
473
}
474
Tree rightkid(Tree p) {
475
        while (p && p->op == RIGHT)
476
                if (p->kids[1])
477
                        p = p->kids[1];
478
                else if (p->kids[0])
479
                        p = p->kids[0];
480
                else
481
                        assert(0);
482
        assert(p);
483
        return p;
484
}
485
int hascall(Tree p) {
486
        if (p == 0)
487
                return 0;
488
        if (generic(p->op) == CALL || (IR->mulops_calls &&
489
          (p->op == DIV+I || p->op == MOD+I || p->op == MUL+I
490
        || p->op == DIV+U || p->op == MOD+U || p->op == MUL+U)))
491
                return 1;
492
        return hascall(p->kids[0]) || hascall(p->kids[1]);
493
}
494
Type binary(Type xty, Type yty) {
495
#define xx(t) if (xty == t || yty == t) return t
496
        xx(longdouble);
497
        xx(doubletype);
498
        xx(floattype);
499
        xx(unsignedlonglong);
500
        xx(longlong);
501
        xx(unsignedlong);
502
        if (xty == longtype     && yty == unsignedtype
503
        ||  xty == unsignedtype && yty == longtype)
504
                if (longtype->size > unsignedtype->size)
505
                        return longtype;
506
                else
507
                        return unsignedlong;
508
        xx(longtype);
509
        xx(unsignedtype);
510
        return inttype;
511
#undef xx
512
}
513
Tree pointer(Tree p) {
514
        if (isarray(p->type))
515
                /* assert(p->op != RIGHT || p->u.sym == NULL), */
516
                p = retype(p, atop(p->type));
517
        else if (isfunc(p->type))
518
                p = retype(p, ptr(p->type));
519
        return p;
520
}
521
Tree cond(Tree p) {
522
        int op = generic(rightkid(p)->op);
523
 
524
        if (op == AND || op == OR || op == NOT
525
        ||  op == EQ  || op == NE
526
        ||  op == LE  || op == LT || op == GE || op == GT)
527
                return p;
528
        p = pointer(p);
529
        return (*optree[NEQ])(NE, p, consttree(0, inttype));
530
}
531
Tree cast(Tree p, Type type) {
532
        Type src, dst;
533
 
534
        p = value(p);
535
        if (p->type == type)
536
                return p;
537
        dst = unqual(type);
538
        src = unqual(p->type);
539
        if (src->op != dst->op || src->size != dst->size) {
540
                switch (src->op) {
541
                case INT:
542
                        if (src->size < inttype->size)
543
                                p = simplify(CVI, inttype, p, NULL);
544
                        break;
545
                case UNSIGNED:
546
                        if (src->size < inttype->size)
547
                                p = simplify(CVU, inttype, p, NULL);
548
                        else if (src->size < unsignedtype->size)
549
                                p = simplify(CVU, unsignedtype, p, NULL);
550
                        break;
551
                case ENUM:
552
                        p = retype(p, inttype);
553
                        break;
554
                case POINTER:
555
                        if (isint(dst) && src->size > dst->size)
556
                                warning("conversion from `%t' to `%t' is undefined\n", p->type, type);
557
                        p = simplify(CVP, super(src), p, NULL);
558
                        break;
559
                case FLOAT:
560
                        break;
561
                default: assert(0);
562
                }
563
                {
564
                        src = unqual(p->type);
565
                        dst = super(dst);
566
                        if (src->op != dst->op)
567
                                switch (src->op) {
568
                                case INT:
569
                                        p = simplify(CVI, dst, p, NULL);
570
                                        break;
571
                                case UNSIGNED:
572
                                        if (isfloat(dst)) {
573
                                                Type ssrc = signedint(src);
574
                                                Tree two = cnsttree(longdouble, (long double)2.0);
575
                                                p = (*optree['+'])(ADD,
576
                                                        (*optree['*'])(MUL,
577
                                                                two,
578
                                                                simplify(CVU, ssrc,
579
                                                                        simplify(RSH, src,
580
                                                                                p, consttree(1, inttype)), NULL)),
581
                                                        simplify(CVU, ssrc,
582
                                                                simplify(BAND, src,
583
                                                                        p, consttree(1, unsignedtype)), NULL));
584
                                        } else
585
                                                p = simplify(CVU, dst, p, NULL);
586
                                        break;
587
                                case FLOAT:
588
                                        if (isunsigned(dst)) {
589
                                                Type sdst = signedint(dst);
590
                                                Tree c = cast(cnsttree(longdouble, (long double)sdst->u.sym->u.limits.max.i + 1), src);
591
                                                p = condtree(
592
                                                        simplify(GE, src, p, c),
593
                                                        (*optree['+'])(ADD,
594
                                                                cast(cast(simplify(SUB, src, p, c), sdst), dst),
595
                                                                cast(cnsttree(unsignedlong, (unsigned long)sdst->u.sym->u.limits.max.i + 1), dst)),
596
                                                        simplify(CVF, sdst, p, NULL));
597
                                        } else
598
                                                p = simplify(CVF, dst, p, NULL);
599
                                        break;
600
                                default: assert(0);
601
                                }
602
                        dst = unqual(type);
603
                }
604
        }
605
        src = unqual(p->type);
606
        switch (src->op) {
607
        case INT:
608
                if (src->op != dst->op || src->size != dst->size)
609
                        p = simplify(CVI, dst, p, NULL);
610
                break;
611
        case UNSIGNED:
612
                if (src->op != dst->op || src->size != dst->size)
613
                        p = simplify(CVU, dst, p, NULL);
614
                break;
615
        case FLOAT:
616
                if (src->op != dst->op || src->size != dst->size)
617
                        p = simplify(CVF, dst, p, NULL);
618
                break;
619
        case POINTER:
620
                if (src->op != dst->op)
621
                        p = simplify(CVP, dst, p, NULL);
622
                else {
623
                        if (isfunc(src->type) && !isfunc(dst->type)
624
                        || !isfunc(src->type) &&  isfunc(dst->type))
625
                                warning("conversion from `%t' to `%t' is compiler dependent\n", p->type, type);
626
 
627
                        if (src->size != dst->size)
628
                                p = simplify(CVP, dst, p, NULL);
629
                }
630
                break;
631
        default: assert(0);
632
        }
633
        return retype(p, type);
634
}
635
Tree field(Tree p, const char *name) {
636
        Field q;
637
        Type ty1, ty = p->type;
638
 
639
        if (isptr(ty))
640
                ty = deref(ty);
641
        ty1 = ty;
642
        ty = unqual(ty);
643
        if ((q = fieldref(name, ty)) != NULL) {
644
                if (isarray(q->type)) {
645
                        ty = q->type->type;
646
                        if (isconst(ty1) && !isconst(ty))
647
                                ty = qual(CONST, ty);
648
                        if (isvolatile(ty1) && !isvolatile(ty))
649
                                ty = qual(VOLATILE, ty);
650
                        ty = array(ty, q->type->size/ty->size, q->type->align);
651
                } else {
652
                        ty = q->type;
653
                        if (isconst(ty1) && !isconst(ty))
654
                                ty = qual(CONST, ty);
655
                        if (isvolatile(ty1) && !isvolatile(ty))
656
                                ty = qual(VOLATILE, ty);
657
                        ty = ptr(ty);
658
                }
659
                if (YYcheck && !isaddrop(p->op) && q->offset > 0)        /* omit */
660
                        p = nullcall(ty, YYcheck, p, consttree(q->offset, inttype));    /* omit */
661
                else                                    /* omit */
662
                p = simplify(ADD+P, ty, p, consttree(q->offset, signedptr));
663
 
664
                if (q->lsb) {
665
                        p = tree(FIELD, ty->type, rvalue(p), NULL);
666
                        p->u.field = q;
667
                } else if (!isarray(q->type))
668
                        p = rvalue(p);
669
 
670
        } else {
671
                error("unknown field `%s' of `%t'\n", name, ty);
672
                p = rvalue(retype(p, ptr(inttype)));
673
        }
674
        return p;
675
}
676
/* funcname - return name of function f or a function' */
677
char *funcname(Tree f) {
678
        if (isaddrop(f->op))
679
                return stringf("`%s'", f->u.sym->name);
680
        return "a function";
681
}
682
static Tree nullcheck(Tree p) {
683
        if (!needconst && YYnull && isptr(p->type)) {
684
                p = value(p);
685
                if (strcmp(YYnull->name, "_YYnull") == 0) {
686
                        Symbol t1 = temporary(REGISTER, voidptype);
687
                        p = tree(RIGHT, p->type,
688
                                tree(OR, voidtype,
689
                                        cond(asgn(t1, cast(p, voidptype))),
690
                                        vcall(YYnull, voidtype, (file && *file ? pointer(idtree(mkstr(file)->u.c.loc)) : cnsttree(voidptype, NULL)), cnsttree(inttype, (long)lineno)            , NULL)),
691
                                idtree(t1));
692
                }
693
 
694
                else
695
                        p = nullcall(p->type, YYnull, p, cnsttree(inttype, 0L));
696
 
697
        }
698
        return p;
699
}
700
Tree nullcall(Type pty, Symbol f, Tree p, Tree e) {
701
        Type ty;
702
 
703
        if (isarray(pty))
704
                return retype(nullcall(atop(pty), f, p, e), pty);
705
        ty = unqual(unqual(p->type)->type);
706
        return vcall(f, pty,
707
                p, e,
708
                cnsttree(inttype, (long)ty->size),
709
                cnsttree(inttype, (long)ty->align),
710
                (file && *file ? pointer(idtree(mkstr(file)->u.c.loc)) : cnsttree(voidptype, NULL)), cnsttree(inttype, (long)lineno)            , NULL);
711
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.