Quick Search:

Mode

Context

Displaying 3 lines of context. None | Less | More | Full

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.9
 
1.10
 
MAIN:ragge:20030707144238
 
optim.c
_>1 -#if 0
 2 -static char *sccsid ="@(#)optim.c       4.7 (Berkeley) 1/8/86";
 3 -#endif
  1+/*      $NetBSD$        */
  2+/*
  3+ * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
  4+ *
  5+ * Redistribution and use in source and binary forms, with or without
  6+ * modification, are permitted provided that the following conditions
  7+ * are met:
  8+ *
  9+ * Redistributions of source code and documentation must retain the above
  10+ * copyright notice, this list of conditions and the following disclaimer.
  11+ * Redistributions in binary form must reproduce the above copyright
  12+ * notice, this list of conditionsand the following disclaimer in the
  13+ * documentation and/or other materials provided with the distribution.
  14+ * All advertising materials mentioning features or use of this software
  15+ * must display the following acknowledgement:
  16+ *      This product includes software developed or owned by Caldera
  17+ *      International, Inc.
  18+ * Neither the name of Caldera International, Inc. nor the names of other
  19+ * contributors may be used to endorse or promote products derived from
  20+ * this software without specific prior written permission.
  21+ *
  22+ * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
  23+ * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
  24+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  25+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  26+ * DISCLAIMED.  IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE
  27+ * FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  28+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  29+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  30+ * HOWEVER CAUSED AND ON ANY THEORY OFLIABILITY, WHETHER IN CONTRACT,
  31+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  32+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  33+ * POSSIBILITY OF SUCH DAMAGE.
  34+ */
435 
 536 # include "pass1.h"
 637 
     
 !
1243 # define LO(p) p->n_left->n_op
 1344 # define LV(p) p->n_left->n_lval
 1445 
<>15 -        /* is p a constant without a name */
 16 -# define nncon(p)       ((p)->n_op == ICON && (p)->n_sp == NULL)
  46+static int nncon(NODE *);
1747 
 1848 int oflag = 0;
 1949 
     
 !
71101                 break;
 72102 
 73103         case UNARY AND:
<>74 -                if( LO(p) != NAME || !andable(p->n_left) ) return(p);
  104+                if( LO(p) != NAME ) cerror( "& error" );
75105 
<> 106+                if( !andable(p->n_left) ) return(p);
  107+
76108                 LO(p) = ICON;
 77109 
 78110                 setuleft:
     
 !
124156                         nfree(p->n_left);
 125157                         p->n_left = q;
 126158                 }
<>127 -                if( RCON(p) && LO(p)==o && RCON(p->n_left) &&
 128 -                    conval( p->n_right, o, p->n_left->n_right ) ){
  159+                if( RCON(p) && LO(p)==o && RCON(p->n_left) && conval( p->n_right, o, p->n_left->n_right ) ){
129160                         goto zapleft;
 130161                         }
<>131 -                else if( LCON(p) && RCON(p) &&
 132 -                         conval( p->n_left, o, p->n_right ) ){
  162+                else if( LCON(p) && RCON(p) && conval( p->n_left, o, p->n_right ) ){
133163                         zapright:
 134164                         nfree(p->n_right);
 135165                         q = makety(p->n_left, p->n_type, p->n_df, p->n_sue);
 136166                         nfree(p);
 137167                         return clocal(q);
<>138 -                }
 139 -                /* FALL THROUGH */
  168+                        }
140169 
<>141 -        case ASG MUL:
 142 -                /* change muls to adds or shifts */
  170+                /* change muls to shifts */
143171 
<>144 -                if( (o == MUL || o == ASG MUL) &&
 145 -                    nncon(p->n_right) && (i=ispow2(RV(p)))>=0){
 146 -                        if( i == 0 ) /* multiplication by 1 */
  172+                if( o == MUL && nncon(p->n_right) && (i=ispow2(RV(p)))>=0){
  173+                        if( i == 0 ) { /* multiplication by 1 */
147174                                 goto zapright;
<>148 -                        /* c2 will turn 'i << 1' into 'i + i' for us */
 149 -                        else {
 150 -                                p->n_op = (asgop(o) ? ASG LS : LS);
 151 -                                o = p->n_op;
 152 -                                p->n_right->n_type = INT;
 153 -                                p->n_right->n_sue = MKSUE(INT);
 154 -                                RV(p) = i;
155175                                 }
<> 176+                        o = p->n_op = LS;
  177+                        p->n_right->n_type = INT;
  178+                        p->n_right->n_df = NULL;
  179+                        RV(p) = i;
156180                         }
 157181 
 158182                 /* change +'s of negative consts back to - */
 159183                 if( o==PLUS && nncon(p->n_right) && RV(p)<0 ){
 160184                         RV(p) = -RV(p);
 161185                         o = p->n_op = MINUS;
 162186                         }
<>163 -                /* FALL THROUGH */
 164 -        case ASG AND:
 165 -        case ASG PLUS:
 166 -        case ASG MINUS:
 167 -        case RS:
 168 -        case LS:
 169 -                /* Operations with zero */
 170 -                if( nncon(p->n_right) && RV(p) == 0 ) {
 171 -                        if( o == MUL || o == ASG MUL ||
 172 -                            o == AND || o == ASG AND ) {
 173 -                                if( asgop(o) )
 174 -                                        p->n_op = ASSIGN;
 175 -                                else if( optype(LO(p)) == LTYPE ) {
 176 -                                        q = p->n_right;
 177 -                                        nfree(p);
 178 -                                        nfree(p->n_left);
 179 -                                        p = q;
 180 -                                } else
 181 -                                        p->n_op = COMOP; /* side effects */
 182 -                        } else if( o == PLUS || o == MINUS ||
 183 -                                 o == ASG PLUS || o == ASG MINUS ||
 184 -                                 o == OR || o == ER ||
 185 -                                 o == LS || o == RS )
 186 -                                goto zapright;
 187 -                }
 188 -                if( o != LS && o != RS )
 189 -                        break;
 190 -                /* FALL THROUGH */
 191 -
 192 -        case ASG RS:
 193 -        case ASG LS:
 194 -                if( !ISUNSIGNED(p->n_left->n_type) )
 195 -                        break;
 196 -                if( p->n_right->n_op == ICON &&
 197 -                    p->n_right->n_lval < 0 ) {
 198 -                        /*
 199 -                         * Technically negative shifts are illegal
 200 -                         * but we can support them, at least with
 201 -                         * constants; you take potluck with variables.
 202 -                         */
 203 -                        p->n_right->n_lval = -p->n_right->n_lval;
 204 -                        switch( o ){
 205 -                        case LS:        p->n_op = RS; break;
 206 -                        case ASG LS:    p->n_op = ASG RS; break;
 207 -                        case RS:        p->n_op = LS; break;
 208 -                        case ASG RS:    p->n_op = ASG LS; break;
 209 -                                }
 210 -                        }
211187                 break;
 212188 
<>213 -        case ASG DIV:
214189         case DIV:
<>215 -                if( nncon( p->n_right ) ){
 216 -                        if( RV(p) == 0 ) uerror("division by zero");
 217 -                        else if( RV(p) == 1 ) goto zapright;
 218 -                        /* Unsigned division by a power of two */
 219 -                        else if( (i=ispow2(RV(p)))>=0 &&
 220 -                                 (ISUNSIGNED(p->n_left->n_type) ||
 221 -                                  ISUNSIGNED(p->n_right->n_type)) ){
 222 -                                p->n_op = (asgop(o) ? ASG RS : RS);
 223 -                                p->n_right->n_type = INT;
 224 -                                p->n_right->n_sue = MKSUE(INT);
 225 -                                RV(p) = i;
 226 -                                }
 227 -                        }
  190+                if( nncon( p->n_right ) && p->n_right->n_lval == 1 ) goto zapright;
228191                 break;
 229192 
<>230 -        case ASG MOD:
 231 -        case MOD:
 232 -                if( nncon(p->n_right) ){
 233 -                        if( RV(p) == 0 ) uerror("modulus of zero");
 234 -                        else if( RV(p) == 1 ){ /* mod by one gives zero */
 235 -                                RV(p) = 0;
 236 -                                if( asgop(o) )
 237 -                                        p->n_op = ASSIGN;
 238 -                                else if( optype(LO(p)) == LTYPE ) {
 239 -                                        q = p->n_right;
 240 -                                        nfree(p);
 241 -                                        nfree(p->n_left);
 242 -                                        p = q;
 243 -                                } else
 244 -                                        p->n_op = COMOP; /* side effects */
 245 -                        } else if ((i=ispow2(RV(p)))>=0 &&
 246 -                                 (ISUNSIGNED(p->n_left->n_type) ||
 247 -                                  ISUNSIGNED(p->n_right->n_type)) ){
 248 -                                /* Unsigned mod by a power of two */
 249 -                                p->n_op = (asgop(o) ? ASG AND : AND);
 250 -                                RV(p)--;
 251 -                        }
 252 -                }
 253 -                break;
 254 -
255193         case EQ:
 256194         case NE:
 257195         case LT:
     
 !
285223         for( i=0; c>1; ++i) c >>= 1;
 286224         return(i);
 287225 }
<_ 226+
  227+int
  228+nncon( p ) NODE *p; {
  229+        /* is p a constant without a name */
  230+        return( p->n_op == ICON && p->n_sp == NULL );
  231+        }
FishEye: Open Source License registered to PCC.
Your maintenance has expired. You can renew your license at http://www.atlassian.com/fisheye/renew
Atlassian FishEye, CVS analysis. (Version:1.6.3 Build:build-336 2008-11-04) - Administration - Page generated 2014-09-03 09:09 +0200