| 1 | /* $Id: order.c,v 1.9 2021/11/21 16:31:04 ragge Exp $ */ |
| 2 | /* |
| 3 | * Copyright (c) 2006 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 | * 3. The name of the author may not be used to endorse or promote products |
| 15 | * derived from this software without specific prior written permission |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | |
| 30 | # include "pass2.h" |
| 31 | |
| 32 | #include <string.h> |
| 33 | |
| 34 | int canaddr(NODE *); |
| 35 | |
| 36 | /* is it legal to make an OREG or NAME entry which has an |
| 37 | * offset of off, (from a register of r), if the |
| 38 | * resulting thing had type t */ |
| 39 | int |
| 40 | notoff(TWORD t, int r, CONSZ off, char *cp) |
| 41 | { |
| 42 | if (x2debug) |
| 43 | printf("notoff: t %x r %d off %ld\n", t, r, off); |
| 44 | if (r < 2 || r > 3) |
| 45 | return 1; /* can only index ac2/3 */ |
| 46 | if (off < -128 || off > 127) |
| 47 | return 1; |
| 48 | return(0); /* YES */ |
| 49 | } |
| 50 | |
| 51 | /* |
| 52 | * Turn a UMUL-referenced node into OREG. |
| 53 | * Be careful about register classes, this is a place where classes change. |
| 54 | */ |
| 55 | void |
| 56 | offstar(NODE *p, int shape) |
| 57 | { |
| 58 | NODE *r; |
| 59 | |
| 60 | if (x2debug) |
| 61 | printf("offstar(%p)\n", p); |
| 62 | |
| 63 | r = p->n_right; |
| 64 | if ((p->n_op == PLUS || p->n_op == MINUS) && |
| 65 | r->n_op == ICON && (getlval(r) >= -128 && getlval(r) <= 127)) { |
| 66 | if (!isreg(p->n_left)) |
| 67 | (void)geninsn(p->n_left, INAREG); |
| 68 | return; |
| 69 | } |
| 70 | (void)geninsn(p, INAREG); |
| 71 | } |
| 72 | |
| 73 | /* |
| 74 | * Do the actual conversion of offstar-found OREGs into real OREGs. |
| 75 | */ |
| 76 | void |
| 77 | myormake(NODE *q) |
| 78 | { |
| 79 | if (x2debug) |
| 80 | printf("myormake(%p)\n", q); |
| 81 | } |
| 82 | |
| 83 | /* |
| 84 | * Shape matches for UMUL. Cooperates with offstar(). |
| 85 | */ |
| 86 | int |
| 87 | shumul(NODE *p, int shape) |
| 88 | { |
| 89 | |
| 90 | if (x2debug) |
| 91 | printf("shumul(%p)\n", p); |
| 92 | |
| 93 | /* Turns currently anything into OREG on x86 */ |
| 94 | if (shape & SOREG) |
| 95 | return SROREG; |
| 96 | return SRNOPE; |
| 97 | } |
| 98 | |
| 99 | /* |
| 100 | * Rewrite operations on binary operators (like +, -, etc...). |
| 101 | * Called as a result of table lookup. |
| 102 | */ |
| 103 | int |
| 104 | setbin(NODE *p) |
| 105 | { |
| 106 | |
| 107 | if (x2debug) |
| 108 | printf("setbin(%p)\n", p); |
| 109 | return 0; |
| 110 | |
| 111 | } |
| 112 | |
| 113 | /* setup for assignment operator */ |
| 114 | int |
| 115 | setasg(NODE *p, int cookie) |
| 116 | { |
| 117 | if (x2debug) |
| 118 | printf("setasg(%p)\n", p); |
| 119 | return(0); |
| 120 | } |
| 121 | |
| 122 | /* setup for unary operator */ |
| 123 | int |
| 124 | setuni(NODE *p, int cookie) |
| 125 | { |
| 126 | return 0; |
| 127 | } |
| 128 | |
| 129 | /* |
| 130 | * Set evaluation order of a binary node if it differs from default. |
| 131 | */ |
| 132 | int |
| 133 | setorder(NODE *p) |
| 134 | { |
| 135 | return 0; |
| 136 | } |
| 137 | /* |
| 138 | * Set registers "live" at function calls (like arguments in registers). |
| 139 | * This is for liveness analysis of registers. |
| 140 | */ |
| 141 | int * |
| 142 | livecall(NODE *p) |
| 143 | { |
| 144 | static int r[1] = { -1 }; /* Terminate with -1 */ |
| 145 | |
| 146 | return &r[0]; |
| 147 | } |
| 148 | |
| 149 | /* |
| 150 | * Signal whether the instruction is acceptable for this target. |
| 151 | */ |
| 152 | int |
| 153 | acceptable(struct optab *op) |
| 154 | { |
| 155 | return 1; |
| 156 | } |