1 /* Id: order.c,v 1.4 2008/09/27 07:35:23 ragge Exp */ 2 /* $NetBSD: order.c,v 1.1.1.3 2010/06/03 18:57:21 plunky Exp $ */ 3 /* 4 * Copyright (c) 2006 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 #include <string.h> 34 35 int canaddr(NODE *); 36 37 /* is it legal to make an OREG or NAME entry which has an 38 * offset of off, (from a register of r), if the 39 * resulting thing had type t */ 40 int 41 notoff(TWORD t, int r, CONSZ off, char *cp) 42 { 43 if (r != 2 && r != 3) 44 return 1; /* can only index ac2 and ac3 */ 45 if (t == CHAR || t == UCHAR) { 46 if (off < -256 || off > 254) 47 return 1; 48 } else if (off < -128 || off > 127) 49 return 1; 50 return(0); /* YES */ 51 } 52 53 /* 54 * Turn a UMUL-referenced node into OREG. 55 * Be careful about register classes, this is a place where classes change. 56 */ 57 void 58 offstar(NODE *p, int shape) 59 { 60 NODE *r; 61 62 if (x2debug) 63 printf("offstar(%p)\n", p); 64 65 if (isreg(p)) 66 return; /* Is already OREG */ 67 68 r = p->n_right; 69 if( p->n_op == PLUS || p->n_op == MINUS ){ 70 if( r->n_op == ICON ){ 71 if (isreg(p->n_left) == 0 || 72 (p->n_left->n_op == REG && 73 p->n_left->n_rval != 2 && p->n_left->n_rval != 3)) 74 (void)geninsn(p->n_left, INBREG); 75 /* Converted in ormake() */ 76 return; 77 } 78 } 79 (void)geninsn(p, INBREG); 80 } 81 82 /* 83 * Do the actual conversion of offstar-found OREGs into real OREGs. 84 */ 85 void 86 myormake(NODE *q) 87 { 88 if (x2debug) 89 printf("myormake(%p)\n", q); 90 } 91 92 /* 93 * Shape matches for UMUL. Cooperates with offstar(). 94 */ 95 int 96 shumul(NODE *p, int order) 97 { 98 99 if (x2debug) 100 printf("shumul(%p)\n", p); 101 102 /* Turns currently anything into OREG on x86 */ 103 if (shape & SOREG) 104 return SROREG; 105 return SRNOPE; 106 } 107 108 /* 109 * Rewrite increment/decrement operation. 110 */ 111 int 112 setincr(NODE *p) 113 { 114 if (x2debug) 115 printf("setincr(%p)\n", p); 116 117 return(0); 118 } 119 120 /* 121 * Rewrite operations on binary operators (like +, -, etc...). 122 * Called as a result of table lookup. 123 */ 124 int 125 setbin(NODE *p) 126 { 127 128 if (x2debug) 129 printf("setbin(%p)\n", p); 130 return 0; 131 132 } 133 134 /* setup for assignment operator */ 135 int 136 setasg(NODE *p, int cookie) 137 { 138 if (x2debug) 139 printf("setasg(%p)\n", p); 140 return(0); 141 } 142 143 /* setup for unary operator */ 144 int 145 setuni(NODE *p, int cookie) 146 { 147 return 0; 148 } 149 150 /* 151 * Special handling of some instruction register allocation. 152 */ 153 struct rspecial * 154 nspecial(struct optab *q) 155 { 156 comperr("nspecial entry %d", q - table); 157 return 0; /* XXX gcc */ 158 } 159 160 /* 161 * Set evaluation order of a binary node if it differs from default. 162 */ 163 int 164 setorder(NODE *p) 165 { 166 return 0; 167 } 168 /* 169 * Set registers "live" at function calls (like arguments in registers). 170 * This is for liveness analysis of registers. 171 */ 172 int * 173 livecall(NODE *p) 174 { 175 static int r[1] = { -1 }; /* Terminate with -1 */ 176 177 return &r[0]; 178 } 179 180 /* 181 * Signal whether the instruction is acceptable for this target. 182 */ 183 int 184 acceptable(struct optab *op) 185 { 186 return 1; 187 } 188