4 codgen(Node *n, Node *nn)
10 for(;; nn = nn->left) {
12 diag(Z, "cant find function name");
19 gpseudo(ATEXT, nn->sym, D_CONST, stkoff);
25 if(thisfn->link->etype != TVOID)
26 warn(Z, "no return at end of function: %s", nn->sym->name);
30 if(!debug['N'] || debug['R'] || debug['P'])
51 print("%L %O\n", nearln, o);
82 if(typesuv[n->type->etype]) {
83 sugen(l, D_TREE, nodret, n->type->width);
89 g = regalloc(n->type, regret(n->type));
92 if(typefd[n->type->etype])
107 gbranch(OGOTO); /* prevent self reference in reg */
116 if(n->complex == 0) {
117 diag(Z, "label undefined: %s", n->sym->name);
122 patch(p, n->xoffset);
126 patch(n->label, pc-1);
133 diag(n, "case/default outside a switch");
146 if(typechl[l->type->etype]) {
148 cases->val = l->vconst;
154 diag(n, "case expression must be integer constant");
163 if(!typechl[l->type->etype]) {
164 diag(n, "switch expression must be integer");
167 g = regalloc(types[TLONG], D_NONE);
168 n->type = types[TLONG];
173 gbranch(OGOTO); /* entry */
205 gbranch(OGOTO); /* entry */
223 bcomplex(l); /* test */
225 if(l->op != OCONST || vconst(l) == 0)
230 gen(n->right); /* body */
244 gen(l->right->left); /* init */
245 gbranch(OGOTO); /* entry */
261 gen(l->right->right); /* inc */
263 if(l->left != Z) { /* test */
266 if(l->left->op != OCONST || vconst(l->left) == 0)
269 gen(n->right); /* body */
283 diag(n, "continue not in a loop");
292 diag(n, "break not in a loop");
304 if(n->right->left != Z)
306 if(n->right->right != Z) {
310 gen(n->right->right);
323 usedset(Node *n, int o)
327 usedset(n->right, o);
332 case OADDR: /* volatile */
333 gopcode(OTST, types[TINT], D_TREE, n, D_NONE, Z);
338 gopcode(OTST, types[TINT], D_NONE, Z, D_TREE, n);
340 gopcode(OTST, types[TINT], D_TREE, n, D_NONE, Z);
351 gopcode(OTST, types[TINT], D_NONE, Z, regret(types[TLONG]), Z);
355 gopcode(OTST, types[TINT], D_NONE, Z, regret(types[TDOUBLE]), Z);
361 * calculate addressability as follows
362 * REGISTER ==> 12 register
363 * NAME ==> 11 name+value(SB/SP)
364 * note that 10 is no longer generated
365 * CONST ==> 20 $value
367 * &(10) ==> 12 $name+value(SB)
368 * &(11) ==> 1 $name+value(SP)
369 * (12) + (20) ==> 12 fold constants
370 * (1) + (20) ==> 1 fold constants
371 * *(12) ==> 10 back to name
372 * *(1) ==> 11 back to name
374 * (2,10,11) + (20) ==> 2 indirect w offset
376 * *(10,11) ==> 13 indirect, no index
378 * (20) * (X) ==> 7 multiplier in indexing
379 * (X,7) + (12,1) ==> 8 adder in indexing (addresses)
380 * (X,7) + (10,11,2) ==> 8 adder in indexing (names)
381 * (8) ==> &9 index, almost addressable
383 * (X)++ ==> X fake addressability
385 * calculate complexity (number of registers)
405 n->addable = 11; /* difference to make relocatable */
424 if(n->type->etype != TIND)
431 n->addable = r->addable;
438 n->addable = l->addable;
467 if(typev[n->type->etype])
478 if(typev[n->type->etype])
506 if(typev[n->type->etype])
521 if(typev[n->type->etype])
533 if(typev[n->type->etype])
535 if(vconst(l) == -1) {
546 if(typev[n->type->etype])
559 if(typev[n->type->etype])
575 if(typev[n->type->etype])
578 aseae: /* hack that there are no byte/short mul/div operators */
579 if(n->type->etype == TCHAR || n->type->etype == TSHORT) {
580 n->right = new1(OCAST, n->right, Z);
581 n->right->type = types[TLONG];
582 n->type = types[TLONG];
584 if(n->type->etype == TUCHAR || n->type->etype == TUSHORT) {
585 n->right = new1(OCAST, n->right, Z);
586 n->right->type = types[TULONG];
587 n->type = types[TULONG];
602 if(typev[n->type->etype])
606 if(l->addable > INDEXED &&
608 r && r->complex < FNX)
609 n->addable = l->addable;
617 if(typev[n->type->etype])
619 if(l->addable > INDEXED &&
621 n->addable = l->addable;
637 n->complex = l->complex;
639 if(r->complex == n->complex)
640 n->complex = r->complex+1;
642 if(r->complex > n->complex)
643 n->complex = r->complex;
664 * symmetric operators, make right side simple
665 * if same, put constant on left to get movq
667 if(r->complex > l->complex ||
668 (r->complex == l->complex && r->addable == 20)) {
681 * relational operators, make right side simple
682 * if same, put constant on left to get movq
684 if(r->complex > l->complex || r->addable == 20) {
687 n->op = invrel[relindex(n->op)];
699 if(tcompat(n, T, n->type, tnot))
704 boolgen(n, 1, D_NONE, Z, n);