| 1 | /* $Id: order.c,v 1.5 2016/01/30 17:26:19 ragge Exp $ */ |
| 2 | /* |
| 3 | * Copyright (c) 2014 Anders Magnusson ([email protected]). |
| 4 | * All rights reserved. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions |
| 8 | * are met: |
| 9 | * 1. Redistributions of source code must retain the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer. |
| 11 | * 2. Redistributions in binary form must reproduce the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer in the |
| 13 | * documentation and/or other materials provided with the distribution. |
| 14 | * |
| 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 | */ |
| 26 | |
| 27 | |
| 28 | # include "pass2.h" |
| 29 | |
| 30 | #include <string.h> |
| 31 | |
| 32 | int canaddr(NODE *); |
| 33 | |
| 34 | /* is it legal to make an OREG or NAME entry which has an |
| 35 | * offset of off, (from a register of r), if the |
| 36 | * resulting thing had type t */ |
| 37 | int |
| 38 | notoff(TWORD t, int r, CONSZ off, char *cp) |
| 39 | { |
| 40 | if (off > MAX_SHORT || off < MIN_SHORT) |
| 41 | return 1; /* max signed 16-bit offset */ |
| 42 | return(0); /* YES */ |
| 43 | } |
| 44 | |
| 45 | /* |
| 46 | * Turn a UMUL-referenced node into OREG. |
| 47 | * Be careful about register classes, this is a place where classes change. |
| 48 | * Especially on m68k we must be careful about class changes; |
| 49 | * Pointers can only have a scalar added to it if PLUS, but when |
| 50 | * MINUS may be either only pointers or left pointer and right scalar. |
| 51 | * |
| 52 | * So far we only handle the trivial OREGs here. |
| 53 | */ |
| 54 | void |
| 55 | offstar(NODE *p, int shape) |
| 56 | { |
| 57 | NODE *q; |
| 58 | |
| 59 | if (x2debug) { |
| 60 | printf("offstar(%p)\n", p); |
| 61 | fwalk(p, e2print, 0); |
| 62 | } |
| 63 | |
| 64 | if (isreg(p)) |
| 65 | return; /* Matched (%a0) */ |
| 66 | |
| 67 | q = p->n_right; |
| 68 | if ((p->n_op == PLUS || p->n_op == MINUS) && q->n_op == ICON && |
| 69 | notoff(0, 0, getlval(q), 0) == 0 && !isreg(p->n_left)) { |
| 70 | (void)geninsn(p->n_left, INBREG); |
| 71 | return; |
| 72 | } |
| 73 | (void)geninsn(p, INBREG); |
| 74 | } |
| 75 | |
| 76 | /* |
| 77 | * Do the actual conversion of offstar-found OREGs into real OREGs. |
| 78 | * For simple OREGs conversion should already be done. |
| 79 | */ |
| 80 | void |
| 81 | myormake(NODE *q) |
| 82 | { |
| 83 | } |
| 84 | |
| 85 | /* |
| 86 | * Shape matches for UMUL. Cooperates with offstar(). |
| 87 | */ |
| 88 | int |
| 89 | shumul(NODE *p, int shape) |
| 90 | { |
| 91 | |
| 92 | if (x2debug) |
| 93 | printf("shumul(%p)\n", p); |
| 94 | |
| 95 | /* Turns currently anything into OREG on x86 */ |
| 96 | if (shape & SOREG) |
| 97 | return SROREG; |
| 98 | return SRNOPE; |
| 99 | } |
| 100 | |
| 101 | /* |
| 102 | * Rewrite operations on binary operators (like +, -, etc...). |
| 103 | * Called as a result of table lookup. |
| 104 | */ |
| 105 | int |
| 106 | setbin(NODE *p) |
| 107 | { |
| 108 | |
| 109 | if (x2debug) |
| 110 | printf("setbin(%p)\n", p); |
| 111 | return 0; |
| 112 | |
| 113 | } |
| 114 | |
| 115 | /* setup for assignment operator */ |
| 116 | int |
| 117 | setasg(NODE *p, int cookie) |
| 118 | { |
| 119 | if (x2debug) |
| 120 | printf("setasg(%p)\n", p); |
| 121 | return(0); |
| 122 | } |
| 123 | |
| 124 | /* setup for unary operator */ |
| 125 | int |
| 126 | setuni(NODE *p, int cookie) |
| 127 | { |
| 128 | return 0; |
| 129 | } |
| 130 | |
| 131 | /* |
| 132 | * Special handling of some instruction register allocation. |
| 133 | */ |
| 134 | struct rspecial * |
| 135 | nspecial(struct optab *q) |
| 136 | { |
| 137 | switch (q->op) { |
| 138 | case STASG: |
| 139 | { |
| 140 | static struct rspecial s[] = { |
| 141 | { NEVER, D0 }, { NEVER, D1 }, |
| 142 | { NEVER, A0 }, { NEVER, A1 }, |
| 143 | /* { NRES, A0 }, */ { 0 } }; |
| 144 | return s; |
| 145 | } |
| 146 | } |
| 147 | comperr("nspecial entry %d", q - table); |
| 148 | return 0; /* XXX gcc */ |
| 149 | } |
| 150 | |
| 151 | /* |
| 152 | * Set evaluation order of a binary node if it differs from default. |
| 153 | */ |
| 154 | int |
| 155 | setorder(NODE *p) |
| 156 | { |
| 157 | return 0; |
| 158 | } |
| 159 | |
| 160 | /* |
| 161 | * set registers in calling conventions live. |
| 162 | */ |
| 163 | int * |
| 164 | livecall(NODE *p) |
| 165 | { |
| 166 | static int r[] = { A0, -1 }; |
| 167 | |
| 168 | if (p->n_op == STCALL) |
| 169 | return r; /* only if struct return */ |
| 170 | return &r[1]; |
| 171 | } |
| 172 | |
| 173 | /* |
| 174 | * Signal whether the instruction is acceptable for this target. |
| 175 | */ |
| 176 | int |
| 177 | acceptable(struct optab *op) |
| 178 | { |
| 179 | return 1; |
| 180 | } |