ref: 3ee77ddba4ad86c4f8d0357a90d5dd855e8c619e
dir: /cc2/arch/qbe/cgen.c/
/* See LICENSE file for copyright and license details. */ #include <assert.h> #include <stdlib.h> #include "arch.h" #include "../../cc2.h" #include "../../../inc/sizes.h" Node rhs(Node *np) { } Node lhs(Node *np) { } Node expr(Node *np) { } Node * cgen(Node *np) { } /* * This is strongly influenced by * http://plan9.bell-labs.com/sys/doc/compiler.ps (/sys/doc/compiler.ps) * calculate addresability as follows * AUTO => 11 value+fp * REG => 11 reg * STATIC => 11 (value) * CONST => 11 $value * These values of addressability are not used in the code generation. * They are only used to calculate the Sethi-Ullman numbers. Since * QBE is AMD64 targered we could do a better job there, and try to * detect some of the complex addressing modes of these processors. */ Node * sethi(Node *np) { Node *lp, *rp; if (!np) return np; np->complex = 0; np->address = 0; lp = np->left; rp = np->right; switch (np->op) { case OAUTO: case OREG: case OMEM: case OCONST: np->address = 11; break; case OCPL: np->op = OAND; rp = newnode(OCONST); rp->type = np->type; rp->u.i = 0; rp->u.i = ~np->u.i; goto binary; case ONEG: np->op = OSUB; rp = lp; lp = newnode(OCONST); lp->type = np->type; if (np->type.flags & INTF) lp->u.i = 0; else lp->u.f = 0.0; default: binary: lp = sethi(lp); rp = sethi(rp); break; } np->left = lp; np->right = rp; if (np->address > 10) return np; if (lp) np->complex = lp->complex; if (rp) { int d = np->complex - rp->complex; if (d == 0) ++np->complex; else if (d < 0) np->complex = rp->complex; } if (np->complex == 0) ++np->complex; return np; }