/* * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * See the copyright notice in the ACK home directory, in the file "Copyright". */ #ifndef NORCSID static char rcsid[]= "$Id$"; #endif #include #include #include "assert.h" #include "param.h" #include "set.h" #include "reg.h" #include "lookup.h" #include "token.h" #include "property.h" #include "expr.h" #include "regvar.h" #include #include #include "extern.h" extern set_t l_sets[]; i_expr(e) expr_t e; { if (e.ex_typ != TYPINT) error("Expression should be integer"); return(e.ex_index); } b_expr(e) expr_t e; { if (e.ex_typ != TYPBOOL) error("Expression should be boolean"); return(e.ex_index); } expr_t make_expr(type,operator,op1,op2) { expr_t result; result.ex_typ=type; result.ex_index=ex_lookup(operator,op1,op2); return(result); } expr_t regno_expr(regno) { expr_t result; register i; result.ex_typ = TYPREG; result.ex_index = ex_lookup(EX_REG,regno,0); for (i=0;isy_type==symconst) return(make_expr(TYPINT,EX_CON, (int) (sy_p->sy_value.syv_cstval&0xFFFF), (int) (sy_p->sy_value.syv_cstval>>16))); else if (sy_p->sy_type==symsconst) return(make_expr(TYPADDR,EX_STRING,sy_p->sy_value.syv_stringno,0)); else if (sy_p->sy_type!=symreg) error("Wrong type of identifier %s",name); return(regno_expr(sy_p->sy_value.syv_regno)); } expr_t subreg_expr(tokarg,subreg) { expr_t result; result.ex_typ = TYPREG; subregset(l_sets[tokpatset[tokarg > 0 ? tokarg-1 : tokarg]].set_val, subreg,result.ex_regset); result.ex_index = ex_lookup(EX_SUBREG,tokarg,subreg); return(result); } subregset(sp,subreg,regset) register short *sp; register short *regset; { register i; register reginfo *rp; for (i=0;iri_memb[subreg-1]==0) error("Register %s in set has no member %d", rp->ri_name,subreg); BIS(regset,rp->ri_memb[subreg-1]); } else BIS(regset,i); } for(;itk_name); } membset(setno,name,regset,appearance,restyp,typp) char *name,*appearance; short *regset; int *typp; { register short *sp; register token_p tp; register i,j,k; int thistyp; int typesdiffer=0; int res_j= -1; if (setno < 0) return 0; sp = l_sets[setno].set_val; for (i=1;itk_att[j].ta_type == -3 || strcmp(tp->tk_att[j].ta_name,name));j++) ; if (j==MAXATT) error("Token %s does not contain %s",tp->tk_name,name); else if (j!=res_j && res_j != -1) typesdiffer=1; else { res_j = j; thistyp = tp->tk_att[j].ta_type; if (thistyp== -2) { if (restyp!=TYPADDR && restyp!=0) typesdiffer=1; else restyp=TYPADDR; } else if (thistyp== -1) { if (restyp!=TYPINT && restyp!=0) typesdiffer=1; else restyp=TYPINT; } else { if (restyp!=TYPREG && restyp!=0) typesdiffer=1; else { restyp=TYPREG; for(k=0;ktk_att[j].ta_type].pr_regset[k]; } } } } if (typesdiffer) error("%s is not a valid expression; types differ in the set", appearance); *typp = restyp==0 ? TYPINT : restyp; return(res_j == -1 ? 0 : res_j); } expr_t memb_expr(setno,name,appearance,tokarg) char *name,*appearance; { expr_t result; int res_j; res_j = membset(setno,name,result.ex_regset,appearance,0,&result.ex_typ); result.ex_index = ex_lookup(EX_TOKFIELD,tokarg,res_j+1); return(result); } expr_t tokm_expr(tokarg,name) char *name; { char app[100]; int tokarg1 = tokarg > 0 ? tokarg : 1; sprintf(app,"%%%d.%s",tokarg1,name); return(memb_expr(tokpatset[tokarg1-1],name,app,tokarg)); } expr_t perc_ident_expr(name) char *name; { char app[100]; sprintf(app,"%%%s",name); return(memb_expr(cursetno,name,app,0)); } expr_t all_expr(all_no,subreg) { set_t localset; register i; register short *sp; expr_t result; sp = l_props[allreg[all_no]].pr_regset; for (i=0;iex_operator != operator) continue; if (p->ex_lnode != lnode) continue; if (p->ex_rnode != rnode) continue; return(p-nodes); } NEXT(nnodes,MAXNODES,"Node"); p->ex_operator = operator; p->ex_lnode = lnode; p->ex_rnode = rnode; return(p-nodes); }