1 /* Id: order.c,v 1.63 2008/01/15 21:47:06 ragge Exp */ 2 /* $NetBSD: order.c,v 1.1.1.2 2010/06/03 18:57:23 plunky Exp $ */ 3 /* 4 * Copyright (c) 2003 Anders Magnusson (ragge@ludd.luth.se). 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. The name of the author may not be used to endorse or promote products 16 * derived from this software without specific prior written permission 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30 31 # include "pass2.h" 32 33 int canaddr(NODE *); 34 35 /* is it legal to make an OREG or NAME entry which has an 36 * offset of off, (from a register of r), if the 37 * resulting thing had type t */ 38 int 39 notoff(TWORD t, int r, CONSZ off, char *cp) 40 { 41 return(0); /* YES */ 42 } 43 44 int radebug = 0; 45 46 void 47 offstar(NODE *p, int shape) 48 { 49 NODE *q; 50 51 if (x2debug) 52 printf("offstar(%p)\n", p); 53 54 if( p->n_op == PLUS || p->n_op == MINUS ){ 55 if( p->n_right->n_op == ICON ){ 56 q = p->n_left; 57 if (q->n_op != REG) 58 geninsn(q, INAREG); 59 p->n_su = -1; 60 } 61 } 62 geninsn(p, INAREG); 63 } 64 65 /* 66 * findops() failed, see if we can rewrite it to match. 67 */ 68 int 69 setbin(NODE *p) 70 { 71 TWORD ty; 72 NODE *r, *s; 73 74 ty = p->n_type; 75 switch (p->n_op) { 76 case MINUS: 77 switch (ty) { 78 case PTR+CHAR: 79 case PTR+UCHAR: 80 case PTR+SHORT: 81 case PTR+USHORT: 82 /* 83 * Must negate the right side and change op to PLUS. 84 */ 85 r = p->n_right; 86 if (r->n_op == ICON) { 87 r->n_lval = -r->n_lval; 88 } else { 89 s = talloc(); 90 s->n_type = r->n_type; 91 s->n_op = UMINUS; 92 s->n_left = r; 93 p->n_right = s; 94 } 95 p->n_op = PLUS; 96 return 1; 97 } 98 } 99 return 0; 100 } 101 102 /* setup for assignment operator */ 103 int 104 setasg(NODE *p, int cookie) 105 { 106 return(0); 107 } 108 109 /* setup for unary operator */ 110 int 111 setuni(NODE *p, int cookie) 112 { 113 return 0; 114 } 115 116 int 117 special(NODE *p, int shape) 118 { 119 switch (shape) { 120 case SUSHCON: 121 if (p->n_op == ICON && p->n_name[0] == '\0' && 122 (p->n_lval > 0 && p->n_lval <= 0777777)) 123 return 1; 124 break; 125 126 case SNSHCON: 127 if (p->n_op == ICON && p->n_name[0] == '\0' && 128 (p->n_lval < 0 && p->n_lval > -01000000)) 129 return 1; 130 break; 131 case SILDB: 132 if (p->n_op == ASSIGN && p->n_left->n_op == REG && 133 p->n_right->n_op == PLUS && 134 p->n_right->n_left->n_op == REG && 135 p->n_right->n_right->n_op == ICON && 136 p->n_right->n_right->n_lval == 1 && 137 p->n_right->n_left->n_rval == p->n_left->n_rval) 138 return 1; 139 break; 140 } 141 return 0; 142 } 143 144 /* 145 * Set evaluation order of a binary node if it differs from default. 146 */ 147 int 148 setorder(NODE *p) 149 { 150 return 0; /* nothing differs on x86 */ 151 } 152 153 /* 154 * Special handling of some instruction register allocation. 155 */ 156 struct rspecial * 157 nspecial(struct optab *q) 158 { 159 return 0; /* XXX gcc */ 160 } 161 162 /* 163 * Do the actual conversion of offstar-found OREGs into real OREGs. 164 */ 165 void 166 myormake(NODE *p) 167 { 168 if (x2debug) 169 printf("myormake(%p)\n", p); 170 } 171 172 /* 173 * set registers in calling conventions live. 174 */ 175 int * 176 livecall(NODE *p) 177 { 178 static int r[8], *s = r; 179 180 *s = -1; 181 if (p->n_op == UCALL || p->n_op == UFORTCALL || p->n_op == USTCALL || 182 p->n_op == FORTCALL) 183 return s; 184 for (p = p->n_right; p->n_op == CM; p = p->n_left) { 185 if (p->n_right->n_op == ASSIGN && 186 p->n_right->n_left->n_op == REG) 187 *s++ = p->n_right->n_left->n_rval; 188 } 189 if (p->n_op == ASSIGN && 190 p->n_left->n_op == REG) 191 *s++ = p->n_left->n_rval; 192 *s = -1; 193 return r; 194 } 195 196 /* 197 * Signal whether the instruction is acceptable for this target. 198 */ 199 int 200 acceptable(struct optab *op) 201 { 202 return 1; 203 } 204