📄 match.c
字号:
#ifndef lintstatic char *sccsid = "@(#)match.c 1.3 (ULTRIX) 3/12/86";#endif lint/************************************************************************ * * * Copyright (c) 1984 by * * Digital Equipment Corporation, Maynard, MA * * All rights reserved. * * * * This software is furnished under a license and may be used and * * copied only in accordance with the terms of such license and * * with the inclusion of the above copyright notice. This * * software or any other copies thereof may not be provided or * * otherwise made available to any other person. No title to and * * ownership of the software is hereby transferred. * * * * This software is derived from software received from the * * University of California, Berkeley, and from Bell * * Laboratories. Use, duplication, or disclosure is subject to * * restrictions under license agreements with University of * * California and with AT&T. * * * * The information in this software is subject to change without * * notice and should not be construed as a commitment by Digital * * Equipment Corporation. * * * * Digital assumes no responsibility for the use or reliability * * of its software on equipment which is not supplied by Digital. * * * ************************************************************************//************************************************************************ Modification History* Lu anne Van de Pas 02-mar-86* vdp003 - added support for doing f floating arithmetic in f float when* fflag is set. Uses the productions with need FLOATFLG. Also * added qdebug which prints out the table production the was matched* * Rich Phillips 8-17-84* RAP002 Add code to put out code for UNARY CALL's to _asm.** Rich Phillips 7-11-84* RAP001 Print an error message when the register number in tshape* is out of bounds. If it happens, its probably because oreg is* changed to a register when a structure is passed as a parameter* for some reason (see genargs in order.c).**************************************************************************/# include "mfile2"# ifdef WCARD1# ifdef WCARD2# define NOINDIRECT# endif# endifextern qdebug; /*vdp003 print out the code template matched*/extern vdebug;extern int fflag; /*vdp003 floating point */ int fldsz, fldshf;static int mamask[] = { /* masks for matching dope with shapes */ SIMPFLG, /* OPSIMP */ SIMPFLG|ASGFLG, /* ASG OPSIMP */ COMMFLG, /* OPCOMM */ COMMFLG|ASGFLG, /* ASG OPCOMM */ MULFLG, /* OPMUL */ MULFLG|ASGFLG, /* ASG OPMUL */ DIVFLG, /* OPDIV */ DIVFLG|ASGFLG, /* ASG OPDIV */ UTYPE, /* OPUNARY */ TYFLG, /* ASG OPUNARY is senseless */ LTYPE, /* OPLEAF */ TYFLG, /* ASG OPLEAF is senseless */ 0, /* OPANY */ ASGOPFLG|ASGFLG, /* ASG OPANY */ LOGFLG, /* OPLOG */ TYFLG, /* ASG OPLOG is senseless */ FLOFLG, /* OPFLOAT */ FLOFLG|ASGFLG, /* ASG OPFLOAT */ SHFFLG, /* OPSHFT */ SHFFLG|ASGFLG, /* ASG OPSHIFT */ SPFLG, /* OPLTYPE */ TYFLG, /* ASG OPLTYPE is senseless */ };int sdebug = 0;tshape( p, shape ) NODE *p; { /* return true if shape is appropriate for the node p side effect for SFLD is to set up fldsz,etc */ register o, mask; o = p->in.op;# ifndef BUG3 if( sdebug ){ printf( "tshape( %o, %o), op = %d\n", p, shape, o ); }# endif if( shape & SPECIAL ){ switch( shape ){ case SZERO: case SONE: case SMONE: case SSCON: case SCCON: if( o != ICON || p->in.name[0] ) return(0); if( p->tn.lval == 0 && shape == SZERO ) return(1); else if( p->tn.lval == 1 && shape == SONE ) return(1); else if( p->tn.lval == -1 && shape == SMONE ) return(1); else if( p->tn.lval > -129 && p->tn.lval < 128 && shape == SCCON ) return(1); else if( p->tn.lval > -32769 && p->tn.lval < 32768 && shape == SSCON ) return(1); else return(0); case SSOREG: /* non-indexed OREG */ if( o == OREG && !R2TEST(p->tn.rval) ) return(1); else return(0); default:# ifdef MULTILEVEL if( shape & MULTILEVEL ) return( mlmatch(p,shape,0) ); else# endif return( special( p, shape ) ); } } if( shape & SANY ) return(1); if( (shape&INTEMP) && shtemp(p) ) return(1); if( (shape&SWADD) && (o==NAME||o==OREG) ){ if( BYTEOFF(p->tn.lval) ) return(0); }# ifdef WCARD1 if( shape & WCARD1 ) return( wcard1(p) & shape );# endif# ifdef WCARD2 if( shape & WCARD2 ) return( wcard2(p) & shape );# endif switch( o ){ case NAME: return( shape&SNAME ); case ICON: mask = SCON; return( shape & mask ); case FLD: if( shape & SFLD ){ if( !flshape( p->in.left ) ) return(0); /* it is a FIELD shape; make side-effects */ o = p->tn.rval; fldsz = UPKFSZ(o);# ifdef RTOLBYTES fldshf = UPKFOFF(o);# else fldshf = SZINT - fldsz - UPKFOFF(o);# endif return(1); } return(0); case CCODES: return( shape&SCC ); case REG: /* distinctions: SAREG any scalar register STAREG any temporary scalar register SBREG any lvalue (index) register STBREG any temporary lvalue register */ mask = isbreg( p->tn.rval ) ? SBREG : SAREG; /* RAP001 */ if (p->tn.rval >=REGSZ ) cerror ("incorrect register number in tshape"); if( istreg( p->tn.rval ) && busy[p->tn.rval]<=1 ) mask |= mask==SAREG ? STAREG : STBREG; return( shape & mask ); case OREG: return( shape & SOREG );# ifndef NOINDIRECT case UNARY MUL: /* return STARNM or STARREG or 0 */ return( shumul(p->in.left) & shape );# endif } return(0); }int tdebug = 0;ttype( t, tword ) TWORD t; { /* does the type t match tword */ if( tword & TANY ) return(1); if( t == UNDEF ) t=INT; /* void functions eased thru tables */# ifndef BUG3 if( tdebug ){ printf( "ttype( %o, %o )\n", t, tword ); }# endif if( ISPTR(t) && (tword&TPTRTO) ) { do { t = DECREF(t); } while ( ISARY(t) ); /* arrays that are left are usually only in structure references... */ return( ttype( t, tword&(~TPTRTO) ) ); } if( t != BTYPE(t) ) return( tword & TPOINT ); /* TPOINT means not simple! */ if( tword & TPTRTO ) return(0); switch( t ){ case CHAR: return( tword & TCHAR ); case SHORT: return( tword & TSHORT ); case STRTY: case UNIONTY: return( tword & TSTRUCT ); case INT: return( tword & TINT ); case UNSIGNED: return( tword & TUNSIGNED ); case USHORT: return( tword & TUSHORT ); case UCHAR: return( tword & TUCHAR ); case ULONG: return( tword & TULONG ); case LONG: return( tword & TLONG ); case FLOAT: return( tword & TFLOAT ); case DOUBLE: return( tword & TDOUBLE ); } return(0); }struct optab *rwtable;struct optab *opptr[DSIZE];setrew(){ /* set rwtable to first value which allows rewrite */ register struct optab *q; register int i;# ifdef MULTILEVEL /* also initialize multi-level tree links */ mlinit();# endif for( q = table; q->op != FREE; ++q ){ if( q->needs == REWRITE ){ rwtable = q; goto more; } } cerror( "bad setrew" ); more: for( i=0; i<DSIZE; ++i ){ if( dope[i] ){ /* there is an op... */ for( q=table; q->op != FREE; ++q ){ /* beware; things like LTYPE that match multiple things in the tree must not try to look at the NIL at this stage of things! Put something else first in table.c */ /* at one point, the operator matching was 15% of the total comile time; thus, the function call that was here was removed... */ if( q->op < OPSIMP ){ if( q->op==i ) break; } else { register opmtemp; if((opmtemp=mamask[q->op - OPSIMP])&SPFLG){ if( i==NAME || i==ICON || i==OREG ) break; else if( shltype( i, NIL ) ) break; } else if( (dope[i]&(opmtemp|ASGFLG)) == opmtemp ) break; } } opptr[i] = q; } } }match( p, cookie ) NODE *p; { /* called by: order, gencall look for match in table and generate code if found unless entry specified REWRITE. returns MDONE, MNOPE, or rewrite specification from table */ register struct optab *q; register NODE *r; rcount(); if( cookie == FORREW ) q = rwtable; else q = opptr[p->in.op]; for( ; q->op != FREE; ++q ){ /* at one point the call that was here was over 15% of the total time; thus the function call was expanded inline */ if( q->op < OPSIMP ){ if( q->op!=p->in.op ) continue; } else { register opmtemp; if((opmtemp=mamask[q->op - OPSIMP])&SPFLG){ if( p->in.op!=NAME && p->in.op!=ICON && p->in.op!= OREG && ! shltype( p->in.op, p ) ) continue; } else if( (dope[p->in.op]&(opmtemp|ASGFLG)) != opmtemp ) continue; } if( !(q->visit & cookie ) ) continue; r = getlr( p, 'L' ); /* see if left child matches */ if( !tshape( r, q->lshape ) ) continue; if( !ttype( r->in.type, q->ltype ) ) continue; r = getlr( p, 'R' ); /* see if right child matches */ if( !tshape( r, q->rshape ) ) continue; if( !ttype( r->in.type, q->rtype ) ) continue; /* No match if floating point flag is not set and we have a * float production (i.e. FLOATFLG) -ugh- vdp003 */ if ((!fflag) && (q->needs & FLOATFLG) ) continue; /* REWRITE means no code from this match but go ahead * and rewrite node to help future match */ if( q->needs & REWRITE ) return( q->rewrite ); if( !allo( p, q ) ) continue; /* if can't generate code, skip entry */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -