1 /* $Id: order.c,v 1.63 2008/01/15 21:47:06 ragge Exp $ */
3 * Copyright (c) 2003 Anders Magnusson (ragge@ludd.luth.se).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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
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.
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 */
38 notoff(TWORD t
, int r
, CONSZ off
, char *cp
)
46 offstar(NODE
*p
, int shape
)
51 printf("offstar(%p)\n", p
);
53 if( p
->n_op
== PLUS
|| p
->n_op
== MINUS
){
54 if( p
->n_right
->n_op
== ICON
){
65 * findops() failed, see if we can rewrite it to match.
82 * Must negate the right side and change op to PLUS.
85 if (r
->n_op
== ICON
) {
86 r
->n_lval
= -r
->n_lval
;
89 s
->n_type
= r
->n_type
;
101 /* setup for assignment operator */
103 setasg(NODE
*p
, int cookie
)
108 /* setup for unary operator */
110 setuni(NODE
*p
, int cookie
)
116 special(NODE
*p
, int shape
)
120 if (p
->n_op
== ICON
&& p
->n_name
[0] == '\0' &&
121 (p
->n_lval
> 0 && p
->n_lval
<= 0777777))
126 if (p
->n_op
== ICON
&& p
->n_name
[0] == '\0' &&
127 (p
->n_lval
< 0 && p
->n_lval
> -01000000))
131 if (p
->n_op
== ASSIGN
&& p
->n_left
->n_op
== REG
&&
132 p
->n_right
->n_op
== PLUS
&&
133 p
->n_right
->n_left
->n_op
== REG
&&
134 p
->n_right
->n_right
->n_op
== ICON
&&
135 p
->n_right
->n_right
->n_lval
== 1 &&
136 p
->n_right
->n_left
->n_rval
== p
->n_left
->n_rval
)
144 * Set evaluation order of a binary node if it differs from default.
149 return 0; /* nothing differs on x86 */
153 * Special handling of some instruction register allocation.
156 nspecial(struct optab
*q
)
158 return 0; /* XXX gcc */
162 * Do the actual conversion of offstar-found OREGs into real OREGs.
168 printf("myormake(%p)\n", p
);
172 * set registers in calling conventions live.
177 static int r
[8], *s
= r
;
180 if (p
->n_op
== UCALL
|| p
->n_op
== UFORTCALL
|| p
->n_op
== USTCALL
||
183 for (p
= p
->n_right
; p
->n_op
== CM
; p
= p
->n_left
) {
184 if (p
->n_right
->n_op
== ASSIGN
&&
185 p
->n_right
->n_left
->n_op
== REG
)
186 *s
++ = p
->n_right
->n_left
->n_rval
;
188 if (p
->n_op
== ASSIGN
&&
189 p
->n_left
->n_op
== REG
)
190 *s
++ = p
->n_left
->n_rval
;
196 * Signal whether the instruction is acceptable for this target.
199 acceptable(struct optab
*op
)