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 ==> 10/11 name+value(SB/SP)
364 * CONST ==> 20 $value
366 * &(10) ==> 12 $name+value(SB)
367 * &(11) ==> 1 $name+value(SP)
368 * (12) + (20) ==> 12 fold constants
369 * (1) + (20) ==> 1 fold constants
370 * *(12) ==> 10 back to name
371 * *(1) ==> 11 back to name
373 * (2,10,11) + (20) ==> 2 indirect w offset
375 * *(10,11) ==> 13 indirect, no index
377 * (20) * (X) ==> 7 multiplier in indexing
378 * (X,7) + (12,1) ==> 8 adder in indexing (addresses)
379 * (X,7) + (10,11,2) ==> 8 adder in indexing (names)
380 * (8) ==> &9 index, almost addressable
382 * (X)++ ==> X fake addressability
384 * calculate complexity (number of registers)
405 if(n->class == CPARAM || n->class == CAUTO)
425 if(n->type->etype != TIND)
432 n->addable = r->addable;
443 n->addable = l->addable;
450 l = new1(OXXX, Z, Z);
456 l = new1(OXXX, Z, Z);
479 if(n->addable == 8) {
481 l = new1(OINDEX, idx.basetree, idx.regtree);
482 l->scale = idx.scale;
484 l->complex = l->right->complex;
485 l->type = l->left->type;
523 if(typev[n->type->etype])
534 if(typev[n->type->etype])
562 if(typev[n->type->etype])
577 if(typev[n->type->etype])
589 if(typev[n->type->etype])
591 if(vconst(l) == -1) {
602 if(typev[n->type->etype])
615 if(typev[n->type->etype])
631 if(typev[n->type->etype])
634 aseae: /* hack that there are no byte/short mul/div operators */
635 if(n->type->etype == TCHAR || n->type->etype == TSHORT) {
636 n->right = new1(OCAST, n->right, Z);
637 n->right->type = types[TLONG];
638 n->type = types[TLONG];
640 if(n->type->etype == TUCHAR || n->type->etype == TUSHORT) {
641 n->right = new1(OCAST, n->right, Z);
642 n->right->type = types[TULONG];
643 n->type = types[TULONG];
658 if(typev[n->type->etype])
662 if(l->addable > INDEXED &&
664 r && r->complex < FNX)
665 n->addable = l->addable;
673 if(typev[n->type->etype])
675 if(l->addable > INDEXED &&
677 n->addable = l->addable;
693 n->complex = l->complex;
695 if(r->complex == n->complex)
696 n->complex = r->complex+1;
698 if(r->complex > n->complex)
699 n->complex = r->complex;
720 * symmetric operators, make right side simple
721 * if same, put constant on left to get movq
723 if(r->complex > l->complex ||
724 (r->complex == l->complex && r->addable == 20)) {
737 * relational operators, make right side simple
738 * if same, put constant on left to get movq
740 if(r->complex > l->complex || r->addable == 20) {
743 n->op = invrel[relindex(n->op)];
775 if(l->op == ONAME && r->op == ONAME)
777 if(r->etype != TIND) {
782 if(l->addable == 1 || l->addable == 12) {
792 if(l->addable != 7) {
796 if(l->right->addable == 20) {
797 idx.regtree = l->left;
798 idx.scale = l->right->vconst;
800 idx.regtree = l->right;
801 idx.scale = l->left->vconst;
803 t = ewidth[idx.regtree->type->etype];
808 diag(n, "index not W or L");
812 print("scale = %d\n", idx.scale);
813 prtree(idx.regtree, "index");
814 prtree(idx.basetree, "base");
824 if(tcompat(n, T, n->type, tnot))
829 boolgen(n, 1, D_NONE, Z, n);