#include "defs.h" expand(c) REG CHP c; { TAG t=c->c_type; STRING oldq; STRING s_file; TAG t_p; /* parameter tree */ SIG t_s; /* actual signal parameters */ DEF t_m; /* definition node for macro */ TAG sav_sig, sav_chp; errmsg("....", "macro expansion\n"); notnil(c->c_tag); if(lslflg==0) prs(".f "); prs(c_type->tc); prs("("); prs(c->c_tag->tc); prs(")"); prc(NL); s_file=filename; filename=c_type->tc; t_m=CHEAT(DEF,t->nxt); t->nxt=nil(TAG); /* recursion check */ t_p=t_m->d_pin; t_s=c->c_sig; /* loop for all parameters */ while(t_s) { /* list of pins */ TAG tp=find(t_s->s_pinnam->tc, t_p); if(tp==nil(TAG)) { errmsg(t_s->s_pinnam->tc, "pin not found\n"); } else { /* list of actual signal parameters */ STRING signame=t_s->s_tag->tc; TAG ap=find(signame, *EXTSIG(signame)); INT onesig=(ap->nxt==0); notnil(ap); while(ap && tp) { /* formal signal parameter */ TAG fp=tp->val; STRING fn=fp->tc; TAG tf; if(fp==nil(TAG)) { errmsg(fn, "no signals found\n"); break; } if(global(fn)) { /* errmsg(fn, "formal signal is global\n"); */ tf=find(fn, ESIG); } else{ tf=find(fn, t_m->d_sig); } notnil(tf); while(tf && ap) { if(tf->val) { errmsg(tf->val->tc, "multiply defined\n"); } if(global(tf->tc)) { if(equstr(tf->tc,ap->tc)==0) errmsg(tf->tc, "global parameter error\n"); } else{ tf->val=follow(ap); } tf=tf->nxt; if(onesig==0) ap=ap->nxt; } if(tf) errmsg(tp->tc, "mismatched parameters\n"); tp->flg |= 1; tp=tp->nxt; } if(ap && (onesig==0)) errmsg(ap->tc, "no formal signal\n"); if(tp) errmsg(tp->tc, "no actual signal\n"); } t_s=t_s->s_next; } /* amend current qualifier */ oldq=qualifier; qualifier=movstr(c->c_tag->tc, qualifier); qualifier=movstr("/", qualifier); /* set up new signal and chip trees */ sav_sig=LSIG; LSIG=t_m->d_sig; sav_chp=LCHP; LCHP=t_m->d_chp; prchips(t_m->d_chips); /* clear out signal tree */ clr_sig(LSIG); LSIG=sav_sig; LCHP=sav_chp; qualifier=oldq; *qualifier=0; /* clear out parameter flags */ c_chip=nil(CHP); c_type=nil(TAG); clr_pin(t_p); if(lslflg==0) prs(".f\n"); filename=s_file; } clr_sig(s) TAG s; { if(s==nil(TAG)) return; clr_sig(s->l); s->val=nil(TAG); clr_sig(s->r); } clr_pin(s) TAG s; { if(s==nil(TAG)) return; clr_pin(s->l); if(s->flg==0) { if(lslflg==0){ prs(".o "); prs(s->val->tc); prs(";\t"); prs(s->tc); prc(NL); } errmsg(s->tc, "unused parameter\n"); } s->flg = 0; clr_pin(s->r); }