home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-01-11 | 32.5 KB | 1,330 lines |
- *** src/expr.c.o Tue Dec 01 23:26:23 1992
- --- src/expr.c Wed Dec 09 18:29:45 1992
- ***************
- *** 190,195 ****
- --- 190,196 ----
- tp1 = tp->btp;
- tp = mk_type(bt_pointer, tp_pointer.size);
- tp->btp = tp1;
- + tp->val_flag = 1;
- }
- return tp;
- }
- ***************
- *** 246,252 ****
- ep->esize = 4;
- break;
- }
- ! /* FALLTHU */
- case sc_global:
- case sc_external:
- *node = ep = mk_node(en_nacon, NIL_ENODE, NIL_ENODE);
- --- 247,253 ----
- ep->esize = 4;
- break;
- }
- ! /*FALLTHRU*/
- case sc_global:
- case sc_external:
- *node = ep = mk_node(en_nacon, NIL_ENODE, NIL_ENODE);
- ***************
- *** 379,393 ****
- enum e_sym st;
- {
- struct sym *sp;
- ! if (st == kw_char || st == kw_short || st == kw_int ||
- ! st == kw_long || st == kw_float || st == kw_double ||
- ! st == kw_struct || st == kw_union || st == kw_unsigned ||
- ! st == kw_const || st == kw_volatile ||
- ! st == kw_void || st == kw_enum)
- ! return 1;
- ! if (st == id && (sp = gsearch(lastid)) != 0 &&
- ! sp->storage_class == sc_typedef)
- ! return 1;
- return 0;
- }
-
- --- 380,406 ----
- enum e_sym st;
- {
- struct sym *sp;
- ! switch (st) {
- ! case kw_char:
- ! case kw_short:
- ! case kw_int:
- ! case kw_long:
- ! case kw_float:
- ! case kw_double:
- ! case kw_struct:
- ! case kw_union:
- ! case kw_unsigned:
- ! case kw_const:
- ! case kw_volatile:
- ! case kw_signed:
- ! case kw_void:
- ! case kw_enum:
- ! return 1;
- ! default:
- ! if (st == id && (sp = gsearch(lastid)) != 0 &&
- ! sp->storage_class == sc_typedef)
- ! return 1;
- ! }
- return 0;
- }
-
- ***************
- *** 404,409 ****
- --- 417,424 ----
- * primary.id
- * primary->id
- * primary( parameter list )
- + * primary++
- + * primary--
- * -- or just a semicolon, yields empty expression --
- *
- */
- ***************
- *** 413,418 ****
- --- 428,434 ----
- struct sym *sp;
- TYP *tptr;
- TYP *tp1,*tp2;
- + int i;
- switch (lastst) {
-
- case id:
- ***************
- *** 431,452 ****
- }
- break;
- case iconst:
- case uconst:
- case lconst:
- pnode = mk_icon((long)ival);
- ! if (lastst == uconst) {
- ! tptr = &tp_uint;
- ! pnode->etype = tp_uint.type;
- ! pnode->esize = tp_uint.size;
- ! } else if (lastst == lconst) {
- ! tptr = &tp_long;
- ! pnode->etype = bt_long;
- ! pnode->esize = 4;
- ! } else {
- ! tptr = &tp_int;
- ! pnode->etype = tp_int.type;
- ! pnode->esize = tp_int.size;
- ! }
- getsym();
- break;
- case rconst:
- --- 447,466 ----
- }
- break;
- case iconst:
- + tptr = &tp_int;
- + goto const1;
- case uconst:
- + tptr = &tp_uint;
- + goto const1;
- case lconst:
- + tptr = &tp_long;
- + goto const1;
- + case ulconst:
- + tptr = &tp_ulong;
- + const1:
- pnode = mk_icon((long)ival);
- ! pnode->etype = tptr->type;
- ! pnode->esize = tptr->size;
- getsym();
- break;
- case rconst:
- ***************
- *** 479,485 ****
- needpunc(closepa);
- } else { /* cast operator */
- struct typ *local_head = head, *local_tail=tail;
- ! decl((TABLE *) 0); /* do cast declaration */
- decl1();
- tptr = head;
- needpunc(closepa);
- --- 493,499 ----
- needpunc(closepa);
- } else { /* cast operator */
- struct typ *local_head = head, *local_tail=tail;
- ! decl(); /* do cast declaration */
- decl1();
- tptr = head;
- needpunc(closepa);
- ***************
- *** 516,521 ****
- --- 530,537 ----
- tp1 = expression(&pnode);
- tptr = tp1;
- }
- + if (!integral(tp2))
- + message(ERR_INTEGER);
-
- /*
- * now, pnode and tp1 describe the pointer,
- ***************
- *** 533,539 ****
- /*
- * qnode is the size of the referenced object
- */
- ! (void) cast_op(&rnode, tp2, &tp_long, 0);
- /*
- * we could check the type of the expression here...
- */
- --- 549,555 ----
- /*
- * qnode is the size of the referenced object
- */
- ! VOIDCAST cast_op(&rnode, tp2, &tp_long, 1);
- /*
- * we could check the type of the expression here...
- */
- ***************
- *** 540,546 ****
- qnode = mk_node(en_mul, qnode, rnode);
- qnode->etype = bt_long;
- qnode->esize = 4;
- ! (void) cast_op(&qnode, &tp_long, tp1, 0);
- pnode = mk_node(en_add, qnode, pnode);
- pnode->etype = bt_pointer;
- pnode->esize = 4;
- --- 556,562 ----
- qnode = mk_node(en_mul, qnode, rnode);
- qnode->etype = bt_long;
- qnode->esize = 4;
- ! VOIDCAST cast_op(&qnode, &tp_long, tp1, 1);
- pnode = mk_node(en_add, qnode, pnode);
- pnode->etype = bt_pointer;
- pnode->esize = 4;
- ***************
- *** 613,618 ****
- --- 629,672 ----
- pnode->esize = tptr->size;
- needpunc(closepa);
- break;
- + case autodec:
- + case autoinc:
- + if (tptr->type == bt_pointer)
- + i = tptr->btp->size;
- + else
- + i = 1;
- + if (i == UNKNOWN_SIZE)
- + message (ERR_SIZE);
- + if (lvalue(pnode)) {
- + if (floating(tptr)) {
- + qnode = mk_node(en_fcon, NIL_ENODE, NIL_ENODE);
- + #ifndef NOFLOAT
- + qnode->v.f = ((double)1);
- + #endif
- + if (tptr->type == bt_float) {
- + qnode->etype = tp_float.type;
- + qnode->esize = tp_float.size;
- + } else {
- + qnode->etype = tp_double.type;
- + qnode->esize = tp_double.size;
- + }
- + } else {
- + qnode = mk_icon((long) i);
- + qnode->etype = bt_long;
- + qnode->esize = 4;
- + }
- + if (lastst == autodec)
- + pnode = mk_node(en_adec, pnode, qnode);
- + else
- + pnode = mk_node(en_ainc, pnode, qnode);
- + pnode->etype = tptr->type;
- + pnode->esize = tptr->size;
- + } else
- + message(ERR_LVALUE);
- + getsym();
- + if (trad_option && lastst == pointsto)
- + needpunc(lastst+1); /* force an error as K&R doesn't allow this*/
- + break;
- default:
- goto fini;
- }
- ***************
- *** 628,635 ****
- * evaluated. unary expressions are any of:
- *
- * primary
- - * primary++
- - * primary--
- * !unary
- * ~unary
- * ++unary
- --- 682,687 ----
- ***************
- *** 673,679 ****
- } else if (floating(tp)) {
- ep2 = mk_node(en_fcon, NIL_ENODE, NIL_ENODE);
- #ifndef NOFLOAT
- ! ep2->v.f = 1.0;
- #endif
- if (tp->type == bt_float) {
- ep2->etype = tp_float.type;
- --- 725,731 ----
- } else if (floating(tp)) {
- ep2 = mk_node(en_fcon, NIL_ENODE, NIL_ENODE);
- #ifndef NOFLOAT
- ! ep2->v.f = ((double)1);
- #endif
- if (tp->type == bt_float) {
- ep2->etype = tp_float.type;
- ***************
- *** 792,797 ****
- --- 844,851 ----
- }
- } else if (tp->type == bt_pointer && tp->btp->type == bt_func) {
- message(WARN_ADDFUNC);
- + } else if (tp->type == bt_pointer && tp->val_flag) {
- + message(WARN_ADDARRAY);
- } else
- message(ERR_LVALUE);
- break;
- ***************
- *** 812,818 ****
- */
- tp1 = head;
- tp = tail;
- ! decl((TABLE *) 0);
- decl1();
- i = head->size;
- tail = tp;
- --- 866,872 ----
- */
- tp1 = head;
- tp = tail;
- ! decl();
- decl1();
- i = head->size;
- tail = tp;
- ***************
- *** 857,868 ****
- if (ep1->v.i == 0) {
- message(WARN_SIZEOF0);
- }
- ! if (short_option && ep1->v.i > 65535) {
- message(WARN_SIZEOFBIG);
- }
- ! tp = &tp_uint;
- ! ep1->etype = tp_uint.type;
- ! ep1->esize = tp_uint.size;
- break;
- case plus:
- if (trad_option == 0) {
- --- 911,922 ----
- if (ep1->v.i == 0) {
- message(WARN_SIZEOF0);
- }
- ! if (((ep1->v.i)>>(TP_SIZE.size * 4))>>(TP_SIZE.size*4) != 0) {
- message(WARN_SIZEOFBIG);
- }
- ! tp = &TP_SIZE;
- ! ep1->etype = TP_SIZE.type;
- ! ep1->esize = TP_SIZE.size;
- break;
- case plus:
- if (trad_option == 0) {
- ***************
- *** 878,920 ****
- /*FALLTHRU*/
- default:
- tp = primary(&ep1);
- - if (tp != 0) {
- - if (tp->type == bt_pointer)
- - i = tp->btp->size;
- - else
- - i = 1;
- - if (lastst == autodec || lastst == autoinc) {
- - if (i == -1)
- - message (ERR_SIZE);
- - if (lvalue(ep1)) {
- - if (floating(tp)) {
- - ep2 = mk_node(en_fcon, NIL_ENODE, NIL_ENODE);
- - #ifndef NOFLOAT
- - ep2->v.f = 1.0;
- - #endif
- - if (tp->type == bt_float) {
- - ep2->etype = tp_float.type;
- - ep2->esize = tp_float.size;
- - } else {
- - ep2->etype = tp_double.type;
- - ep2->esize = tp_double.size;
- - }
- - } else {
- - ep2 = mk_icon((long) i);
- - ep2->etype = bt_long;
- - ep2->esize = 4;
- - }
- - if (lastst == autodec)
- - ep1 = mk_node(en_adec, ep1, ep2);
- - else
- - ep1 = mk_node(en_ainc, ep1, ep2);
- - ep1->etype = tp->type;
- - ep1->esize = tp->size;
- - } else
- - message(ERR_LVALUE);
- - getsym();
- - }
- - }
- break;
- }
- *node = ep1;
- --- 932,937 ----
- ***************
- *** 1041,1047 ****
- switch (tp2->type) {
- case bt_char:
- case bt_uchar:
- ! (void) cast_op(node1, tp1, &tp_short, 0);
- return cast_op(node2, tp2, &tp_short, 0);
- case bt_short:
- case bt_long:
- --- 1058,1064 ----
- switch (tp2->type) {
- case bt_char:
- case bt_uchar:
- ! VOIDCAST cast_op(node1, tp1, &tp_short, 0);
- return cast_op(node2, tp2, &tp_short, 0);
- case bt_short:
- case bt_long:
- ***************
- *** 1062,1068 ****
- if (short_option)
- return cast_op (node1, tp1, &tp_ushort, 0);
- else {
- ! (void) cast_op (node1, tp1, &tp_long, 0);
- return cast_op (node2, tp2, &tp_long, 0);
- }
- case bt_short:
- --- 1079,1085 ----
- if (short_option)
- return cast_op (node1, tp1, &tp_ushort, 0);
- else {
- ! VOIDCAST cast_op (node1, tp1, &tp_long, 0);
- return cast_op (node2, tp2, &tp_long, 0);
- }
- case bt_short:
- ***************
- *** 1069,1075 ****
- if (short_option)
- return cast_op(node2, tp2, &tp_ushort, 0);
- else {
- ! (void) cast_op (node1, tp1, &tp_long, 0);
- return cast_op (node2, tp2, &tp_long, 0);
- }
- case bt_long:
- --- 1086,1092 ----
- if (short_option)
- return cast_op(node2, tp2, &tp_ushort, 0);
- else {
- ! VOIDCAST cast_op (node1, tp1, &tp_long, 0);
- return cast_op (node2, tp2, &tp_long, 0);
- }
- case bt_long:
- ***************
- *** 1218,1224 ****
- ep1 = mk_node(en_sub, ep1, ep2);
- ep1->etype = bt_pointer;
- ep1->esize = 4;
- ! (void) cast_op(&ep1, tp1, &tp_long, 0);
- /* divide the result by the size */
- ep2 = mk_icon((long) tp1->btp->size);
- ep2->etype = bt_long;
- --- 1235,1241 ----
- ep1 = mk_node(en_sub, ep1, ep2);
- ep1->etype = bt_pointer;
- ep1->esize = 4;
- ! VOIDCAST cast_op(&ep1, tp1, &tp_long, 1);
- /* divide the result by the size */
- ep2 = mk_icon((long) tp1->btp->size);
- ep2->etype = bt_long;
- ***************
- *** 1232,1240 ****
- * an 68000 with 32-bit pointers and 16-bit ints. In my opinion,
- * it should remain "long".
- */
- ! if (short_option)
- message(WARN_PTRDIFF16);
- ! tp1 = cast_op(&ep1, &tp_long, &tp_int, short_option);
- *node = ep1;
- continue;
- }
- --- 1249,1257 ----
- * an 68000 with 32-bit pointers and 16-bit ints. In my opinion,
- * it should remain "long".
- */
- ! if (TP_PTRDIFF.size == 2)
- message(WARN_PTRDIFF16);
- ! tp1 = cast_op(&ep1, &tp_long, &TP_PTRDIFF, TP_PTRDIFF.size == 2);
- *node = ep1;
- continue;
- }
- ***************
- *** 1244,1250 ****
- message(ERR_INTEGER);
- if (tp1->btp->size == UNKNOWN_SIZE)
- message (ERR_SIZE);
- ! (void) cast_op(&ep2, tp2, &tp_long, 0);
- ep3 = mk_icon((long) tp1->btp->size);
- ep3->etype = bt_long;
- ep3->esize = 4;
- --- 1261,1267 ----
- message(ERR_INTEGER);
- if (tp1->btp->size == UNKNOWN_SIZE)
- message (ERR_SIZE);
- ! VOIDCAST cast_op(&ep2, tp2, &tp_long, 0);
- ep3 = mk_icon((long) tp1->btp->size);
- ep3->etype = bt_long;
- ep3->esize = 4;
- ***************
- *** 1262,1268 ****
- message(ERR_INTEGER);
- if (tp2->btp->size == UNKNOWN_SIZE)
- message (ERR_SIZE);
- ! (void) cast_op(&ep1, tp1, &tp_long, 0);
- ep3 = mk_icon((long) tp2->btp->size);
- ep3->etype = bt_long;
- ep3->esize = 4;
- --- 1279,1285 ----
- message(ERR_INTEGER);
- if (tp2->btp->size == UNKNOWN_SIZE)
- message (ERR_SIZE);
- ! VOIDCAST cast_op(&ep1, tp1, &tp_long, 0);
- ep3 = mk_icon((long) tp2->btp->size);
- ep3->etype = bt_long;
- ep3->esize = 4;
- ***************
- *** 1592,1598 ****
- if (tp1->type == bt_pointer && integral(tp2)) {
- if (tp1->btp->size == UNKNOWN_SIZE)
- message (ERR_SIZE);
- ! (void) cast_op(&ep2, tp2, &tp_long, 0);
- ep3 = mk_icon((long) tp1->btp->size);
- ep3->etype = bt_long;
- ep3->esize = 4;
- --- 1609,1615 ----
- if (tp1->type == bt_pointer && integral(tp2)) {
- if (tp1->btp->size == UNKNOWN_SIZE)
- message (ERR_SIZE);
- ! VOIDCAST cast_op(&ep2, tp2, &tp_long, 1);
- ep3 = mk_icon((long) tp1->btp->size);
- ep3->etype = bt_long;
- ep3->esize = 4;
- ***************
- *** 1599,1605 ****
- ep2 = mk_node(en_mul, ep2, ep3);
- ep2->etype = bt_long;
- ep2->esize = 4;
- ! tp2 = cast_op(&ep2, &tp_long, tp1, 0);
- }
- goto ascomm2;
- case asminus:
- --- 1616,1622 ----
- ep2 = mk_node(en_mul, ep2, ep3);
- ep2->etype = bt_long;
- ep2->esize = 4;
- ! tp2 = cast_op(&ep2, &tp_long, tp1, 1);
- }
- goto ascomm2;
- case asminus:
- ***************
- *** 1737,1743 ****
- return tp2;
- }
-
- ! if ((*ep)->nodetype == en_icon)
- if (integral(tp2) || tp2->type == bt_pointer || tp2->type == bt_void) {
- long j = (*ep)->v.i;
- (*ep)->etype = tp2->type;
- --- 1754,1761 ----
- return tp2;
- }
-
- ! switch ((*ep)->nodetype) {
- ! case en_icon:
- if (integral(tp2) || tp2->type == bt_pointer || tp2->type == bt_void) {
- long j = (*ep)->v.i;
- (*ep)->etype = tp2->type;
- ***************
- *** 1763,1775 ****
- message(ERR_CASTCON);
- return 0;
- }
- ! if (tp2->type != bt_void && tp2->type != bt_float
- ! && tp1->size > tp2->size && (flag==0))
- ! message(WARN_NARROWER);
- ! else if (tp2->type == bt_pointer && tp1->size < tp_pointer.size)
- message(WARN_SHORTPTR);
-
- -
- ep2 = mk_node(en_cast, *ep, NIL_ENODE);
- ep2->etype = tp2->type;
- ep2->esize = tp2->size;
- --- 1781,1814 ----
- message(ERR_CASTCON);
- return 0;
- }
- ! case en_fcon:
- ! if (integral(tp2)) {
- ! long j = (*ep)->v.f;
- ! (*ep)->nodetype = en_icon;
- ! (*ep)->etype = tp2->type;
- ! (*ep)->esize = tp2->size;
- ! (*ep)->v.i = strip_icon(j, tp2->type);
- ! if (j != (*ep)->v.f ) {
- ! message(WARN_CONSTCAST, j, (*ep)->v.i);
- ! }
- ! return tp2;
- ! }
- ! }
- ! if(tp2->type == bt_struct || tp2->type == bt_union ||
- ! tp1->type == bt_struct || tp1->type == bt_union ) {
- ! message(ERR_ILLCAST);
- ! return(tp2);
- ! }
- ! if (flag == 0) {
- ! if (tp2->type == bt_pointer || tp1->type == bt_pointer)
- ! message(WARN_TYPECAST);
- ! if (tp2->type != bt_void && tp2->type != bt_float
- ! && tp1->size > tp2->size )
- ! message(WARN_NARROWER);
- ! }
- ! if (tp2->type == bt_pointer && tp1->size < tp_pointer.size)
- message(WARN_SHORTPTR);
-
- ep2 = mk_node(en_cast, *ep, NIL_ENODE);
- ep2->etype = tp2->type;
- ep2->esize = tp2->size;
- ***************
- *** 1820,1823 ****
- --- 1859,1910 ----
- }
- return i;
- }
- +
- +
- + #ifdef TRACE
- + void
- + traceexpr(node)
- + struct enode **node;
- + {
- + struct enode *pnode;
- + struct enode *ep1, *ep2;
- + static struct enode *ep;
- + extern int act_line;
- + extern char act_file[];
- +
- + if (ep == 0) {
- + struct sym *sp;
- + ++global_flag;
- + sp = (struct sym *) xalloc((int) sizeof(struct sym));
- + sp->tp = &tp_func;
- + sp->name = strsave(".stmttrace");
- + sp->storage_class = sc_external;
- + ep = mk_node(en_nacon, NIL_ENODE, NIL_ENODE);
- + ep->v.sp = sp->name;
- + ep->etype = bt_pointer;
- + ep->esize = 4;
- + --global_flag;
- + }
- +
- + /* create line number parameter */
- + ep2 = mk_icon((long)act_line);
- + ep2->etype = tp_int.type;
- + ep2->esize = tp_int.size;
- + ep1 = mk_node(en_list, ep2, NIL_ENODE);
- +
- + /* create file name parameter */
- + ep2 = mk_node(en_labcon, NIL_ENODE, NIL_ENODE);
- + ep2->v.i = stringlit(act_file, (int)strlen(act_file));
- + ep2->etype = bt_pointer;
- + ep2->esize = 4;
- + ep1 = mk_node(en_list, ep2, ep1);
- +
- + /* do function call */
- + pnode = mk_node(en_fcall, ep, ep1);
- + pnode->etype = bt_void;
- + pnode->esize = 0;
- + *node = pnode;
- + return;
- + }
- + #endif /* TRACE */
-
- *** src/gen68k.c.o Mon Dec 7 13:11:20 1992
- --- src/gen68k.c Sun Dec 6 19:38:18 1992
- ***************
- *** 601,607 ****
- if (!(flags & F_NOVALUE)) {
- ap = temp_addr();
- g_code(op_move, 4, mk_reg(RESULT), ap);
- ! ap->mode = am_ind;
- return mk_legal(ap, flags, node->esize);
- } else {
- return 0;
- --- 601,608 ----
- if (!(flags & F_NOVALUE)) {
- ap = temp_addr();
- g_code(op_move, 4, mk_reg(RESULT), ap);
- ! ap=copy_addr(ap);
- ! ap->mode = am_ind;
- return mk_legal(ap, flags, node->esize);
- } else {
- return 0;
- ***************
- *** 1925,1931 ****
- /*
- * if (!tworegs)
- * saves a function call result in D0
- ! * it is assumed that flags contain either F_DREG or F_AREG
- *
- * if (tworegs)
- * saves a function call result in D0/D1
- --- 1926,1932 ----
- /*
- * if (!tworegs)
- * saves a function call result in D0
- ! * it is assumed that flags contain either F_MEM, F_DREG or F_AREG
- *
- * if (tworegs)
- * saves a function call result in D0/D1
- ***************
- *** 1966,1973 ****
- g_code(op_move, 4, mk_reg(RESULT), ap);
- return ap;
- }
- ! }
- ! fatal("gen68k/func_result","illegal addressing mode");
- return 0;
- }
- #endif /* NODOUBLE */
- --- 1967,1979 ----
- g_code(op_move, 4, mk_reg(RESULT), ap);
- return ap;
- }
- ! if (flags & F_MEM) {
- ! ap = mk_scratch(4l);
- ! g_code(op_move, 4, mk_reg(RESULT), ap);
- ! return ap;
- ! }
- ! }
- ! fatal("gen68k/func_result","illegal addressing mode (%d, %d)", tworegs,flags);
- return 0;
- }
- #endif /* NODOUBLE */
- ***************
- *** 2598,2606 ****
- p->label = lab0;
- p->value = node->v.f;
- p->less = p->more = NULL;
- ! if (q == NULL)
- ! fptree = p;
- ! else if (q->value < node->v.f)
- q->less = p;
- else
- q->more = p;
- --- 2604,2615 ----
- p->label = lab0;
- p->value = node->v.f;
- p->less = p->more = NULL;
- ! if (q == NULL) {
- ! if (node->etype == bt_double)
- ! dfptree=p;
- ! else
- ! fptree=p;
- ! } else if (q->value < node->v.f)
- q->less = p;
- else
- q->more = p;
- *** src/genstmt.c.o Mon Dec 7 13:12:04 1992
- --- src/genstmt.c Mon Dec 7 13:12:08 1992
- ***************
- *** 40,46 ****
- /* genstmt.c */
- static struct amode *mk_strlab P_((char *s));
- static void genwhile P_((struct snode *stmt));
- ! static void g_for P_((struct snode *stmt));
- static void genif P_((struct snode *stmt));
- static void gendo P_((struct snode *stmt));
- static void genswitch P_((struct snode *stmt));
- --- 40,46 ----
- /* genstmt.c */
- static struct amode *mk_strlab P_((char *s));
- static void genwhile P_((struct snode *stmt));
- ! static void genfor P_((struct snode *stmt));
- static void genif P_((struct snode *stmt));
- static void gendo P_((struct snode *stmt));
- static void genswitch P_((struct snode *stmt));
- ***************
- *** 126,131 ****
- --- 126,132 ----
- return ap;
- }
-
- + #if 0
- static void
- genwhile(stmt)
- /*
- ***************
- *** 177,250 ****
- }
- contlab = lab1; /* restore old continue label */
- }
- !
- ! static void
- ! g_for(stmt)
- ! /*
- ! * generate code to evaluate a for loop
- */
- struct snode *stmt;
- {
- ! unsigned int old_break, old_cont, exit_label, loop_label;
- old_break = breaklab;
- old_cont = contlab;
- loop_label = nextlabel++;
- ! exit_label = nextlabel++;
- ! if (stmt->v2.e != 0)
- ! contlab = nextlabel++;
- ! else
- ! contlab = loop_label;
- #ifdef ICODE
- if (icode_option) {
- if (stmt->exp != 0)
- g_icode(stmt->exp);
- ! iprintf("\tL%u:\n", loop_label);
- }
- #endif
- initstack();
- if (stmt->exp != 0) {
- ! (void) g_expr(stmt->exp, F_ALL | F_NOVALUE);
- ! checkstack();
- ! }
- ! g_label(loop_label);
- ! initstack();
- ! if (stmt->v1.e != 0) {
- ! #ifdef ICODE
- ! if (icode_option) {
- ! iprintf("*falsejp L%u\n", exit_label);
- ! g_icode(stmt->v1.e);
- ! }
- ! #endif
- ! falsejp(stmt->v1.e, exit_label);
- ! checkstack();
- ! }
- ! if (stmt->s1 != 0) {
- ! breaklab = exit_label;
- ! genstmt(stmt->s1);
- ! }
- ! #ifdef ICODE
- ! if (icode_option) {
- ! if (stmt->v2.e != 0) {
- ! iprintf("\tL%u:\n", contlab);
- ! g_icode(stmt->v2.e);
- ! }
- ! iprintf("\tbranch_unconditional\tL%u\n", loop_label);
- ! }
- ! #endif
- ! initstack();
- ! if (stmt->v2.e != 0) {
- ! g_label(contlab);
- ! (void) g_expr(stmt->v2.e, F_ALL | F_NOVALUE);
- ! checkstack();
- ! }
- ! g_code(op_bra, 0, mk_label(loop_label), NIL_AMODE);
- ! breaklab = old_break;
- ! contlab = old_cont;
- ! g_label(exit_label);
- ! #ifdef ICODE
- ! if (icode_option)
- ! iprintf("\tL%u:\n", exit_label);
- ! #endif
- }
-
- static void
- --- 178,300 ----
- }
- contlab = lab1; /* restore old continue label */
- }
- ! #endif
- !
- ! static void
- ! genwhile(stmt)
- ! /*
- ! * generate code to evaluate a while statement.
- */
- struct snode *stmt;
- {
- ! unsigned int lab1, lab2, looplab;
- ! initstack(); /* initialize temp registers */
- ! lab1 = contlab; /* save old continue label */
- ! lab2 = breaklab; /* save old break label */
- ! looplab = nextlabel++; /* loop pabel */
- ! contlab = nextlabel++; /* new continue label */
- ! breaklab = nextlabel++; /* new break label */
- ! #ifdef ICODE
- ! if (icode_option) {
- ! iprintf("\tbranch_unconditional\tL%u\n", contlab);
- ! iprintf("\tL%u:\n", looplab);
- ! }
- ! #endif
- ! g_code(op_bra, 0, mk_label(contlab), NIL_AMODE);
- ! g_label(looplab);
- ! #ifdef ICODE
- ! if (icode_option)
- ! g_icode(stmt->exp);
- ! #endif
- ! genstmt(stmt->s1);
- ! #ifdef ICODE
- ! if (icode_option) {
- ! iprintf("\tL%u:\n", contlab);
- ! iprintf("*truejp L%u\n", looplab);
- ! }
- ! #endif
- ! g_label(contlab);
- ! initstack();
- ! truejp(stmt->exp, looplab);
- ! checkstack();
- ! #ifdef ICODE
- ! if (icode_option)
- ! iprintf("\tL%u:\n", breaklab);
- ! #endif
- ! g_label(breaklab);
- ! breaklab = lab2; /* restore old break label */
- ! contlab = lab1; /* restore old continue label */
- ! }
- !
- ! static void
- ! genfor(stmt)
- ! /*
- ! * generate code to evaluate a for loop
- ! */
- ! struct snode *stmt;
- ! {
- ! unsigned int old_break, old_cont, loop_label, entry_label;
- old_break = breaklab;
- old_cont = contlab;
- loop_label = nextlabel++;
- ! entry_label = nextlabel++;
- ! breaklab = nextlabel++;
- ! contlab = nextlabel++;
- #ifdef ICODE
- if (icode_option) {
- if (stmt->exp != 0)
- g_icode(stmt->exp);
- ! iprintf("\tbranch_unconditional\tL%u\n", entry_label);
- }
- #endif
- initstack();
- if (stmt->exp != 0) {
- ! VOIDCAST g_expr(stmt->exp, F_ALL | F_NOVALUE);
- ! checkstack();
- ! }
- ! g_code(op_bra, 0, mk_label(entry_label), NIL_AMODE);
- ! g_label(loop_label);
- ! #ifdef ICODE
- ! if (icode_option) {
- ! g_icode(stmt->v1.e);
- ! iprintf("\tL%u:\n", contlabel);
- ! }
- ! #endif
- ! genstmt(stmt->s1);
- ! g_label(contlab);
- ! initstack();
- ! #ifdef ICODE
- ! if (icode_option) {
- ! if (stmt->v2.e != 0)
- ! g_icode(stmt->v2.e);
- ! iprintf("\tL%u:\n", entry_lab);
- ! }
- ! #endif
- ! if (stmt->v2.e != 0) {
- ! VOIDCAST g_expr(stmt->v2.e, F_ALL | F_NOVALUE);
- ! checkstack();
- ! }
- ! g_label(entry_label);
- ! initstack();
- ! if (stmt->v1.e == 0) {
- ! #ifdef ICODE
- ! if (icode_option)
- ! iprintf("\tbranch_unconditional\tL%u\n", entry_label);
- ! #endif
- ! g_code(op_bra, 0, mk_label(loop_label), NIL_AMODE);
- ! } else {
- ! #ifdef ICODE
- ! if (icode_option) {
- ! g_icode(stmt->v1.e);
- ! iprintf("*truejp L%u\n", loop_label);
- ! }
- ! #endif
- ! truejp(stmt->v1.e, loop_label);
- ! checkstack();
- ! }
- ! g_label(breaklab);
- ! breaklab = old_break;
- ! contlab = old_cont;
- }
-
- static void
- ***************
- *** 371,381 ****
- #ifdef MC680X0
- struct amode *ap2;
- #endif
- ! struct enode *ep,*stmtexp;
- long size;
- enum e_bt type;
- long min_caselabel, max_caselabel, nxt_caselabel;
- int number_of_cases;
- defcase = 0;
- #ifdef ICODE
- if (icode_option) {
- --- 421,436 ----
- #ifdef MC680X0
- struct amode *ap2;
- #endif
- ! #ifdef INTEL_386
- ! struct enode *ep;
- ! #endif
- ! struct enode *stmtexp;
- long size;
- enum e_bt type;
- long min_caselabel, max_caselabel, nxt_caselabel;
- int number_of_cases;
- + struct swtab *sw;
- + int *labels;
- defcase = 0;
- #ifdef ICODE
- if (icode_option) {
- ***************
- *** 543,568 ****
- iprintf("default ==> L%u\n",
- (unsigned int) deflab);
- #endif
- ! #ifdef SEPARATE_I_D
- ! dseg();
- ! #else
- ! cseg();
- ! #endif
- ! nl();
- ! put_align(AL_POINTER);
- ! put_label(tablab);
- ! ep = mk_node(en_labcon, NIL_ENODE, NIL_ENODE);
- while (min_caselabel <= max_caselabel) {
- nxt_caselabel = max_caselabel + 1;
- s = stmt;
- while (s != 0) {
- if (s->stype != st_default) {
- if (s->v2.i == min_caselabel) {
- ! ep->v.i = nextlabel;
- ! s->v2.i = nextlabel++;
- ! /* remove statment from the list */
- ! s->stype = st_default;
- ! genptr(ep);
- #ifdef ICODE
- if (icode_option)
- iprintf("case-value %8ld ==> L%u\n",
- --- 598,618 ----
- iprintf("default ==> L%u\n",
- (unsigned int) deflab);
- #endif
- ! sw = xalloc((int)sizeof(struct swtab));
- ! sw->tablab = tablab;
- ! sw->numlabs = max_caselabel-min_caselabel +1;
- ! sw->labels = labels = xalloc((int)sizeof(int) * sw->numlabs);
- ! sw->next = swtables;
- ! swtables = sw;
- while (min_caselabel <= max_caselabel) {
- nxt_caselabel = max_caselabel + 1;
- s = stmt;
- while (s != 0) {
- if (s->stype != st_default) {
- if (s->v2.i == min_caselabel) {
- ! s->v2.i = *labels++ = nextlabel++;
- ! /* remove statment from the list */
- ! s->stype = st_default;
- #ifdef ICODE
- if (icode_option)
- iprintf("case-value %8ld ==> L%u\n",
- ***************
- *** 575,582 ****
- }
- /* fill the holes */
- for (i = min_caselabel + 1; i < nxt_caselabel; i++) {
- ! ep->v.i = deflab;
- ! genptr(ep);
- #ifdef ICODE
- if (icode_option)
- iprintf("case-value %8ld ==> L%u\n",
- --- 625,631 ----
- }
- /* fill the holes */
- for (i = min_caselabel + 1; i < nxt_caselabel; i++) {
- ! *labels++ = deflab;
- #ifdef ICODE
- if (icode_option)
- iprintf("case-value %8ld ==> L%u\n",
- ***************
- *** 715,721 ****
- ep1 = mk_node(en_assign, ep1, stmt->exp);
- ep1->etype = ret_type->type;
- ep1->esize = ret_type->size;
- ! (void) g_expr(ep1, F_ALL | F_NOVALUE);
- #ifdef MC680X0
- /* move pointer to D0 */
- ap = g_expr(ep, F_ALL);
- --- 764,770 ----
- ep1 = mk_node(en_assign, ep1, stmt->exp);
- ep1->etype = ret_type->type;
- ep1->esize = ret_type->size;
- ! VOIDCAST g_expr(ep1, F_ALL | F_NOVALUE);
- #ifdef MC680X0
- /* move pointer to D0 */
- ap = g_expr(ep, F_ALL);
- ***************
- *** 742,748 ****
- case bt_float:
- #ifdef INTEL_386
- /* return floating point value on top of fpu stack */
- ! (void) g_expr(stmt->exp, F_FPSTACK);
- #ifdef FUNCS_USE_387
- if (!fpu_option)
- /*
- --- 791,797 ----
- case bt_float:
- #ifdef INTEL_386
- /* return floating point value on top of fpu stack */
- ! VOIDCAST g_expr(stmt->exp, F_FPSTACK);
- #ifdef FUNCS_USE_387
- if (!fpu_option)
- /*
- ***************
- *** 895,901 ****
- g_icode(stmt->exp);
- #endif
- initstack();
- ! (void) g_expr(stmt->exp, F_ALL | F_NOVALUE);
- checkstack();
- break;
- case st_return:
- --- 944,950 ----
- g_icode(stmt->exp);
- #endif
- initstack();
- ! VOIDCAST g_expr(stmt->exp, F_ALL | F_NOVALUE);
- checkstack();
- break;
- case st_return:
- ***************
- *** 911,917 ****
- gendo(stmt);
- break;
- case st_for:
- ! g_for(stmt);
- break;
- case st_continue:
- g_code(op_bra, 0, mk_label(contlab), NIL_AMODE);
- --- 960,966 ----
- gendo(stmt);
- break;
- case st_for:
- ! genfor(stmt);
- break;
- case st_continue:
- g_code(op_bra, 0, mk_label(contlab), NIL_AMODE);
- ***************
- *** 962,973 ****
- if (lc_auto % AL_DEFAULT != 0)
- lc_auto += AL_DEFAULT - (lc_auto % AL_DEFAULT);
- #ifdef VERBOSE
- ! (void) times(&tms_buf);
- ltime = tms_buf.tms_utime;
- #endif /* VERBOSE */
- opt1(stmt);
- #ifdef VERBOSE
- ! (void) times(&tms_buf);
- opt_time += tms_buf.tms_utime - ltime;
- #endif /* VERBOSE */
- genstmt(stmt);
- --- 1011,1022 ----
- if (lc_auto % AL_DEFAULT != 0)
- lc_auto += AL_DEFAULT - (lc_auto % AL_DEFAULT);
- #ifdef VERBOSE
- ! VOIDCAST times(&tms_buf);
- ltime = tms_buf.tms_utime;
- #endif /* VERBOSE */
- opt1(stmt);
- #ifdef VERBOSE
- ! VOIDCAST times(&tms_buf);
- opt_time += tms_buf.tms_utime - ltime;
- #endif /* VERBOSE */
- genstmt(stmt);
- *** src/init.c.o Mon Dec 7 13:12:39 1992
- --- src/init.c Sat Nov 28 09:17:12 1992
- ***************
- *** 61,67 ****
- else
- g_strlab(sp->name);
- getsym();
- ! (void) inittype(sp->tp);
- sp->used |= SYM_DEFINED;
- }
-
- --- 61,67 ----
- else
- g_strlab(sp->name);
- getsym();
- ! VOIDCAST inittype(sp->tp);
- sp->used |= SYM_DEFINED;
- }
-
- ***************
- *** 130,140 ****
- if (( lastst == sconst)
- && (tp->btp->type == bt_char || tp->btp->type == bt_uchar)) {
- len = lstrlen;
- ! nbytes = len + 1;
- p = laststr;
- while (len--)
- genbyte((int)*p++);
- ! genbyte(0);
- while (nbytes < tp->size) {
- genbyte(0);
- nbytes++;
- --- 130,141 ----
- if (( lastst == sconst)
- && (tp->btp->type == bt_char || tp->btp->type == bt_uchar)) {
- len = lstrlen;
- ! nbytes = len;
- p = laststr;
- while (len--)
- genbyte((int)*p++);
- ! if (tp->size == 0)
- ! tp->size = nbytes+1;
- while (nbytes < tp->size) {
- genbyte(0);
- nbytes++;
- ***************
- *** 146,151 ****
- --- 147,154 ----
- if (lastst == comma)
- getsym();
- if (lastst == end || lastst == semicolon) {
- + if (nbytes < tp->size)
- + message(WARN_INCOMPLETE);
- while (nbytes < tp->size) {
- genbyte(0);
- nbytes++;
- ***************
- *** 202,209 ****
- nbytes += inittype(sp->tp);
- if (lastst == comma)
- getsym();
- ! if (lastst == end || lastst == semicolon)
- ! break;
- sp = sp->next;
- }
- while (nbytes < tp->size) {
- --- 205,215 ----
- nbytes += inittype(sp->tp);
- if (lastst == comma)
- getsym();
- ! if (lastst == end || lastst == semicolon) {
- ! if (sp->next != NULL)
- ! message (WARN_INCOMPLETE);
- ! break;
- ! }
- sp = sp->next;
- }
- while (nbytes < tp->size) {
- ***************
- *** 216,229 ****
- static int
- initchar()
- {
- ! genbyte((int) intexpr());
- return 1;
- }
-
- static int
- initshort()
- {
- ! genword((int) intexpr());
- return 2;
- }
-
- --- 222,235 ----
- static int
- initchar()
- {
- ! genbyte((int) arithexpr());
- return 1;
- }
-
- static int
- initshort()
- {
- ! genword((int) arithexpr());
- return 2;
- }
-
- *** src/intexpr.c.o Mon Dec 7 13:12:50 1992
- --- src/intexpr.c Mon Dec 7 13:12:52 1992
- ***************
- *** 55,61 ****
- #endif /* !NOFLOAT */
-
- long
- ! intexpr()
- {
- struct enode *ep;
- struct typ *tp;
- --- 55,62 ----
- #endif /* !NOFLOAT */
-
- long
- ! arithexpr()
- ! /* integer arithmetic expression */
- {
- struct enode *ep;
- struct typ *tp;
- ***************
- *** 63,68 ****
- --- 64,95 ----
- tp = exprnc(&ep);
- if (tp == 0) {
- message(ERR_INTEXPR);
- + return (double) 0;
- + }
- +
- + opt4(&ep);
- +
- + if (ep->nodetype == en_icon)
- + return ep->v.i;
- +
- + #ifndef NOFLOAT
- + if (ep->nodetype == en_fcon)
- + return (long) ep->v.f;
- + #endif /* !NOFLOAT */
- +
- + message (ERR_CONSTEXPR);
- + return 0;
- + }
- +
- + long
- + intexpr()
- + {
- + struct enode *ep;
- + struct typ *tp;
- +
- + tp = exprnc(&ep);
- + if (tp == 0) {
- + message(ERR_INTEXPR);
- /*
- * any return value is wrong, but 1 is
- * less likely than 0 to cause spurious
-