Version that implements a C_XXX to O_XXX library interface.
authorbruce <none@none>
Wed, 21 Jan 1987 14:27:04 +0000 (14:27 +0000)
committerbruce <none@none>
Wed, 21 Jan 1987 14:27:04 +0000 (14:27 +0000)
modules/src/em_opt/Makefile
modules/src/em_opt/aux.c
modules/src/em_opt/findworst.c
modules/src/em_opt/mkcalls.c
modules/src/em_opt/nopt.c
modules/src/em_opt/nopt.h
modules/src/em_opt/outcalls.c
modules/src/em_opt/outputdfa.c

index c8d1a55..943dacc 100644 (file)
@@ -1,25 +1,29 @@
 # $Header$
+
+# Where to find em home directory
+
 EMHOME=/usr/em
 MODLIB=$(EMHOME)/modules/lib
-PARSERLIB=$(EMHOME)/lib/em_data.a $(MODLIB)/libprint.a $(MODLIB)/liballoc.a\
-       $(MODLIB)/libstring.a $(MODLIB)/libsystem.a
-HOWMUCH=head -10
+
+# set HOWMUCH to head -20 to limit number of patterns used
+HOWMUCH=cat
+
 LEXLIB=-ll
-INCLDIR=-I$(EMHOME)/h -I$(EMHOME)/modules/h -I$(EMHOME)/modules/pkg
-PREFLAGS=$(INCLDIR) -DPRIVATE=static -DDEBUG
+INCLDIR=-I$(EMHOME)/h -I$(EMHOME)/modules/h -I$(EMHOME)/modules/pkg -I../h
+PREFLAGS=$(INCLDIR) -DPRIVATE=static
 PROFFLAG=-O
 CFLAGS=$(PREFLAGS) $(PROFFLAG)
 LLOPT=
-GFILES=parser.g
-POFILES=parser.o syntax.o outputdfa.o outcalls.o findworst.o outputrepl.o\
-       initlex.o Lpars.o 
-NOFILES=nopt.o dfa.o trans.o incalls.o psuedo.o aux.o mkcalls.o
+
 GENFILES=Lpars.h Lpars.c parserdummy parser.c syntax.c dfadummy\
        dfa.c dfa.c.save trans.c trans.c.save incalls.c incalls.c.save
 
 all:   libopt.a
 
+NOFILES=nopt.o dfa.o trans.o incalls.o pseudo.o aux.o mkcalls.o
+
 libopt.a:      dfadummy $(NOFILES)
+       rm -f libopt.a
        ar rc libopt.a $(NOFILES)
        ranlib libopt.a
 
@@ -35,9 +39,16 @@ dfadummy: patterns parser
        -if cmp -s incalls.c incalls.c.save; then mv incalls.c.save incalls.c; else exit 0; fi
        touch dfadummy
 
+POFILES=parser.o syntax.o outputdfa.o outcalls.o findworst.o initlex.o Lpars.o 
+
+PARSERLIB=$(EMHOME)/lib/em_data.a $(MODLIB)/libprint.a $(MODLIB)/liballoc.a\
+       $(MODLIB)/libstring.a $(MODLIB)/libsystem.a
+
 parser: parserdummy $(POFILES) $(PARSERLIB)
        $(CC) -o parser $(LDFLAGS) $(POFILES) $(PARSERLIB) $(LEXLIB)
 
+GFILES=parser.g
+
 parserdummy:   $(GFILES)
        LLgen $(LLOPT) $(GFILES)
        touch parserdummy
@@ -49,7 +60,7 @@ nopt.o:       nopt.h
 dfa.o: nopt.h
 aux.o: nopt.h
 trans.o:       nopt.h
-psuedo.o:      nopt.h
+pseudo.o:      nopt.h
 incalls.o:     nopt.h
 mkcalls.o:     nopt.h
 
@@ -59,5 +70,4 @@ syntax.o:     syntax.l parser.h Lpars.h
 outputdfa.o:   parser.h Lpars.h
 outcalls.o:    parser.h
 findworst.o:   parser.h
-outputrepl.o:  parser.h Lpars.h
 initlex.o:     parser.h
index bcb54a0..700fb0e 100644 (file)
@@ -1,24 +1,24 @@
 /* $Header$ */
 #include "nopt.h"
 
-rotate(w,amount)
+OO_rotate(w,amount)
        int w, amount;
 {
        long highmask, lowmask;
        highmask = (long)(-1) << amount;
        lowmask = ~highmask;
-       if(WSIZE!=4)
-               highmask &= (WSIZE==2)?0xFFFF:0xFF;
-       return(((w<<amount)&highmask) | ((w >> (8*WSIZE-amount))&lowmask));
+       if(OO_WSIZE!=4)
+               highmask &= (OO_WSIZE==2)?0xFFFF:0xFF;
+       return(((w<<amount)&highmask) | ((w >> (8*OO_WSIZE-amount))&lowmask));
 }
 
-samesign(a,b)
+OO_samesign(a,b)
        int a, b;
 {
        return( (a ^ b) >= 0);
 }
 
-sfit(val,nbits)
+OO_sfit(val,nbits)
        int val, nbits;
 {
        long mask = 0;
@@ -28,7 +28,7 @@ sfit(val,nbits)
        return(((val&mask) == 0) | (val&mask)==mask);
 }
 
-ufit(val, nbits)
+OO_ufit(val, nbits)
        int val, nbits;
 {
        long mask = 0;
@@ -38,7 +38,7 @@ ufit(val, nbits)
        return((val&mask) == 0);
 }
 
-sameext(a1,a2)
+OO_sameext(a1,a2)
        struct instr *a1, *a2;
 {
        if(a1->argtype != a2->argtype) return(0);
@@ -56,7 +56,7 @@ sameext(a1,a2)
        }
 }
 
-samenam(a1,a2)
+OO_samenam(a1,a2)
        struct instr *a1, *a2;
 {
        if(a1->argtype != a2->argtype) return(0);
@@ -72,7 +72,7 @@ samenam(a1,a2)
        }
 }
 
-offset(a)
+OO_offset(a)
        struct instr *a;
 {
        switch(a->argtype) {
index 6192fae..065e73a 100644 (file)
@@ -6,8 +6,7 @@ static char rcsid[] = "$Header$";
 
 #define UPDATEWORST(backups) if(backups>mostbackups) mostbackups = backups;
 
-findworst(state,repl)
-       int state;
+findworst(repl)
        struct mnems repl;
 {
        /*
@@ -31,7 +30,7 @@ findworst(state,repl)
        int s;
        int mostbackups = 0;
        if(n==0) {
-               fprint(ofile,"\t\tbackup(%d);\n", longestpattern-1);
+               fprint(ofile,"\t\t\tOO_backup(%d);\n", longestpattern-1);
                return;
        }
        for(s=1;s<=higheststate;s++) {
@@ -58,7 +57,7 @@ findworst(state,repl)
                }
        }
        if(mostbackups)
-               fprint(ofile,"\t\tbackup(%d);\n",mostbackups);
+               fprint(ofile,"\t\t\tOO_backup(%d);\n",mostbackups);
 }
 
 findfail(state)
index 63d5489..c8e105c 100644 (file)
@@ -4,430 +4,337 @@ static char rcsid[] = "$Header$";
 
 #include "nopt.h"
 
-mkcalls(p)
+OO_mkcalls(p)
        struct instr *p;
 {
-       switch(p->argtype) {
-       case lab_ptyp:
+       switch(p->opcode) {
+       case op_aar:
+               if(p->argtype!=none_ptyp) O_aar(p->acst);
+               else O_aar_narg(); break;
+       case op_adf:
+               if(p->argtype!=none_ptyp) O_adf(p->acst);
+               else O_adf_narg(); break;
+       case op_adi:
+               if(p->argtype!=none_ptyp) O_adi(p->acst);
+               else O_adi_narg(); break;
+       case op_adp:
+               O_adp(p->acst); break;
+       case op_ads:
+               if(p->argtype!=none_ptyp) O_ads(p->acst);
+               else O_ads_narg(); break;
+       case op_adu:
+               if(p->argtype!=none_ptyp) O_adu(p->acst);
+               else O_adu_narg(); break;
+       case op_and:
+               if(p->argtype!=none_ptyp) O_and(p->acst);
+               else O_and_narg(); break;
+       case op_asp:
+               O_asp(p->acst); break;
+       case op_ass:
+               if(p->argtype!=none_ptyp) O_ass(p->acst);
+               else O_ass_narg(); break;
+       case op_beq:
+               O_beq((label)p->acst); break;
+       case op_bge:
+               O_bge((label)p->acst); break;
+       case op_bgt:
+               O_bgt((label)p->acst); break;
+       case op_ble:
+               O_ble((label)p->acst); break;
+       case op_blm:
+               O_blm(p->acst); break;
+       case op_bls:
+               if(p->argtype!=none_ptyp) O_bls(p->acst);
+               else O_bls_narg(); break;
+       case op_blt:
+               O_blt((label)p->acst); break;
+       case op_bne:
+               O_bne((label)p->acst); break;
+       case op_bra:
+               O_bra((label)p->acst); break;
+       case op_cai:
+               O_cai(); break;
+       case op_cal:
+               O_cal(p->apnam); break;
+       case op_cff:
+               O_cff(); break;
+       case op_cfi:
+               O_cfi(); break;
+       case op_cfu:
+               O_cfu(); break;
+       case op_cif:
+               O_cif(); break;
+       case op_cii:
+               O_cii(); break;
+       case op_ciu:
+               O_ciu(); break;
+       case op_cmf:
+               if(p->argtype!=none_ptyp) O_cmf(p->acst);
+               else O_cmf_narg(); break;
+       case op_cmi:
+               if(p->argtype!=none_ptyp) O_cmi(p->acst);
+               else O_cmi_narg(); break;
+       case op_cmp:
+               O_cmp(); break;
+       case op_cms:
+               if(p->argtype!=none_ptyp) O_cms(p->acst);
+               else O_cms_narg(); break;
+       case op_cmu:
+               if(p->argtype!=none_ptyp) O_cmu(p->acst);
+               else O_cmu_narg(); break;
+       case op_com:
+               if(p->argtype!=none_ptyp) O_com(p->acst);
+               else O_com_narg(); break;
+       case op_csa:
+               if(p->argtype!=none_ptyp) O_csa(p->acst);
+               else O_csa_narg(); break;
+       case op_csb:
+               if(p->argtype!=none_ptyp) O_csb(p->acst);
+               else O_csb_narg(); break;
+       case op_cuf:
+               O_cuf(); break;
+       case op_cui:
+               O_cui(); break;
+       case op_cuu:
+               O_cuu(); break;
+       case op_dch:
+               O_dch(); break;
+       case op_dec:
+               O_dec(); break;
+       case op_dee:
+               if(p->argtype==nof_ptyp) O_dee_dlb(p->adlb, p->anoff);
+               else O_dee_dnam(p->adnam, p->asoff); break;
+       case op_del:
+               O_del(p->acst); break;
+       case op_dup:
+               O_dup(p->acst); break;
+       case op_dus:
+               if(p->argtype!=none_ptyp) O_dus(p->acst);
+               else O_dus_narg(); break;
+       case op_dvf:
+               if(p->argtype!=none_ptyp) O_dvf(p->acst);
+               else O_dvf_narg(); break;
+       case op_dvi:
+               if(p->argtype!=none_ptyp) O_dvi(p->acst);
+               else O_dvi_narg(); break;
+       case op_dvu:
+               if(p->argtype!=none_ptyp) O_dvu(p->acst);
+               else O_dvu_narg(); break;
+       case op_exg:
+               if(p->argtype!=none_ptyp) O_exg(p->acst);
+               else O_exg_narg(); break;
+       case op_fef:
+               if(p->argtype!=none_ptyp) O_fef(p->acst);
+               else O_fef_narg(); break;
+       case op_fif:
+               if(p->argtype!=none_ptyp) O_fif(p->acst);
+               else O_fif_narg(); break;
+       case op_fil:
+               if(p->argtype==nof_ptyp) O_fil_dlb(p->adlb, p->anoff);
+               else O_fil_dnam(p->adnam, p->asoff); break;
+       case op_gto:
+               if(p->argtype==nof_ptyp) O_gto_dlb(p->adlb, p->anoff);
+               else O_gto_dnam(p->adnam, p->asoff); break;
+       case op_inc:
+               O_inc(); break;
+       case op_ine:
+               if(p->argtype==nof_ptyp) O_ine_dlb(p->adlb, p->anoff);
+               else O_ine_dnam(p->adnam, p->asoff); break;
+       case op_inl:
+               O_inl(p->acst); break;
+       case op_inn:
+               if(p->argtype!=none_ptyp) O_inn(p->acst);
+               else O_inn_narg(); break;
+       case op_ior:
+               if(p->argtype!=none_ptyp) O_ior(p->acst);
+               else O_ior_narg(); break;
+       case op_lab:
                O_df_ilb(p->alab); break;
-       case none_ptyp:
-               switch(p->opcode) {
-               case op_aar:
-                       O_aar_narg(); break;
-               case op_adf:
-                       O_adf_narg(); break;
-               case op_adi:
-                       O_adi_narg(); break;
-               case op_ads:
-                       O_ads_narg(); break;
-               case op_adu:
-                       O_adu_narg(); break;
-               case op_and:
-                       O_and_narg(); break;
-               case op_ass:
-                       O_ass_narg(); break;
-               case op_bls:
-                       O_bls_narg(); break;
-               case op_cmf:
-                       O_cmf_narg(); break;
-               case op_cmi:
-                       O_cmi_narg(); break;
-               case op_cms:
-                       O_cms_narg(); break;
-               case op_cmu:
-                       O_cmu_narg(); break;
-               case op_com:
-                       O_com_narg(); break;
-               case op_csa:
-                       O_csa_narg(); break;
-               case op_csb:
-                       O_csb_narg(); break;
-               case op_dus:
-                       O_dus_narg(); break;
-               case op_dvf:
-                       O_dvf_narg(); break;
-               case op_dvi:
-                       O_dvi_narg(); break;
-               case op_dvu:
-                       O_dvu_narg(); break;
-               case op_exg:
-                       O_exg_narg(); break;
-               case op_fef:
-                       O_fef_narg(); break;
-               case op_fif:
-                       O_fif_narg(); break;
-               case op_inn:
-                       O_inn_narg(); break;
-               case op_ior:
-                       O_ior_narg(); break;
-               case op_lar:
-                       O_lar_narg(); break;
-               case op_los:
-                       O_los_narg(); break;
-               case op_mlf:
-                       O_mlf_narg(); break;
-               case op_mli:
-                       O_mli_narg(); break;
-               case op_mlu:
-                       O_mlu_narg(); break;
-               case op_ngf:
-                       O_ngf_narg(); break;
-               case op_ngi:
-                       O_ngi_narg(); break;
-               case op_rck:
-                       O_rck_narg(); break;
-               case op_rmi:
-                       O_rmi_narg(); break;
-               case op_rmu:
-                       O_rmu_narg(); break;
-               case op_rol:
-                       O_rol_narg(); break;
-               case op_ror:
-                       O_ror_narg(); break;
-               case op_sar:
-                       O_sar_narg(); break;
-               case op_sbf:
-                       O_sbf_narg(); break;
-               case op_sbi:
-                       O_sbi_narg(); break;
-               case op_sbs:
-                       O_sbs_narg(); break;
-               case op_sbu:
-                       O_sbu_narg(); break;
-               case op_set:
-                       O_set_narg(); break;
-               case op_sli:
-                       O_sli_narg(); break;
-               case op_slu:
-                       O_slu_narg(); break;
-               case op_sri:
-                       O_sri_narg(); break;
-               case op_sru:
-                       O_sru_narg(); break;
-               case op_sts:
-                       O_sts_narg(); break;
-               case op_xor:
-                       O_xor_narg(); break;
-               case op_zer:
-                       O_zer_narg(); break;
-               case op_zrf:
-                       O_zrf_narg(); break;
-               /* no arguments */
-               case op_cai:
-                       O_cai(); break;
-               case op_cff:
-                       O_cff(); break;
-               case op_cfi:
-                       O_cfi(); break;
-               case op_cfu:
-                       O_cfu(); break;
-               case op_cif:
-                       O_cif(); break;
-               case op_cii:
-                       O_cii(); break;
-               case op_ciu:
-                       O_ciu(); break;
-               case op_cmp:
-                       O_cmp(); break;
-               case op_cuf:
-                       O_cuf(); break;
-               case op_cui:
-                       O_cui(); break;
-               case op_cuu:
-                       O_cuu(); break;
-               case op_dch:
-                       O_dch(); break;
-               case op_dec:
-                       O_dec(); break;
-               case op_inc:
-                       O_inc(); break;
-               case op_lim:
-                       O_lim(); break;
-               case op_lni:
-                       O_lni(); break;
-               case op_lpb:
-                       O_lpb(); break;
-               case op_mon:
-                       O_mon(); break;
-               case op_nop:
-                       O_nop(); break;
-               case op_rtt:
-                       O_rtt(); break;
-               case op_sig:
-                       O_sig(); break;
-               case op_sim:
-                       O_sim(); break;
-               case op_teq:
-                       O_teq(); break;
-               case op_tge:
-                       O_tge(); break;
-               case op_tgt:
-                       O_tgt(); break;
-               case op_tle:
-                       O_tle(); break;
-               case op_tlt:
-                       O_tlt(); break;
-               case op_tne:
-                       O_tne(); break;
-               case op_trp:
-                       O_trp(); break;
-               default:
-                       fatal("Illegal mnemonic(%d)",p->opcode);
-               }
-               break;
-       case cst_ptyp: /* one integer constant argument */
-               switch(p->opcode) {
-               case op_aar:
-                       O_aar(p->acst); break;
-               case op_adf:
-                       O_adf(p->acst); break;
-               case op_adi:
-                       O_adi(p->acst); break;
-               case op_adp:
-                       O_adp(p->acst); break;
-               case op_ads:
-                       O_ads(p->acst); break;
-               case op_adu:
-                       O_adu(p->acst); break;
-               case op_and:
-                       O_and(p->acst); break;
-               case op_asp:
-                       O_asp(p->acst); break;
-               case op_ass:
-                       O_ass(p->acst); break;
-               case op_blm:
-                       O_blm(p->acst); break;
-               case op_bls:
-                       O_bls(p->acst); break;
-               case op_cmf:
-                       O_cmf(p->acst); break;
-               case op_cmi:
-                       O_cmi(p->acst); break;
-               case op_cms:
-                       O_cms(p->acst); break;
-               case op_cmu:
-                       O_cmu(p->acst); break;
-               case op_com:
-                       O_com(p->acst); break;
-               case op_csa:
-                       O_csa(p->acst); break;
-               case op_csb:
-                       O_csb(p->acst); break;
-               case op_del:
-                       O_del(p->acst); break;
-               case op_dup:
-                       O_dup(p->acst); break;
-               case op_dus:
-                       O_dus(p->acst); break;
-               case op_dvf:
-                       O_dvf(p->acst); break;
-               case op_dvi:
-                       O_dvi(p->acst); break;
-               case op_dvu:
-                       O_dvu(p->acst); break;
-               case op_exg:
-                       O_exg(p->acst); break;
-               case op_fef:
-                       O_fef(p->acst); break;
-               case op_fif:
-                       O_fif(p->acst); break;
-               case op_inl:
-                       O_inl(p->acst); break;
-               case op_inn:
-                       O_inn(p->acst); break;
-               case op_ior:
-                       O_ior(p->acst); break;
-               case op_lal:
-                       O_lal(p->acst); break;
-               case op_lar:
-                       O_lar(p->acst); break;
-               case op_ldc:
-                       O_ldc(p->acst); break;
-               case op_ldf:
-                       O_ldf(p->acst); break;
-               case op_ldl:
-                       O_ldl(p->acst); break;
-               case op_lfr:
-                       O_lfr(p->acst); break;
-               case op_lil:
-                       O_lil(p->acst); break;
-               case op_lin:
-                       O_lin(p->acst); break;
-               case op_loc:
-                       O_loc(p->acst); break;
-               case op_lof:
-                       O_lof(p->acst); break;
-               case op_loi:
-                       O_loi(p->acst); break;
-               case op_lol:
-                       O_lol(p->acst); break;
-               case op_lor:
-                       O_lor(p->acst); break;
-               case op_los:
-                       O_los(p->acst); break;
-               case op_lxa:
-                       O_lxa(p->acst); break;
-               case op_lxl:
-                       O_lxl(p->acst); break;
-               case op_mlf:
-                       O_mlf(p->acst); break;
-               case op_mli:
-                       O_mli(p->acst); break;
-               case op_mlu:
-                       O_mlu(p->acst); break;
-               case op_ngf:
-                       O_ngf(p->acst); break;
-               case op_ngi:
-                       O_ngi(p->acst); break;
-               case op_rck:
-                       O_rck(p->acst); break;
-               case op_ret:
-                       O_ret(p->acst); break;
-               case op_rmi:
-                       O_rmi(p->acst); break;
-               case op_rmu:
-                       O_rmu(p->acst); break;
-               case op_rol:
-                       O_rol(p->acst); break;
-               case op_ror:
-                       O_ror(p->acst); break;
-               case op_sar:
-                       O_sar(p->acst); break;
-               case op_sbf:
-                       O_sbf(p->acst); break;
-               case op_sbi:
-                       O_sbi(p->acst); break;
-               case op_sbs:
-                       O_sbs(p->acst); break;
-               case op_sbu:
-                       O_sbu(p->acst); break;
-               case op_sdf:
-                       O_sdf(p->acst); break;
-               case op_sdl:
-                       O_sdl(p->acst); break;
-               case op_set:
-                       O_set(p->acst); break;
-               case op_sil:
-                       O_sil(p->acst); break;
-               case op_sli:
-                       O_sli(p->acst); break;
-               case op_slu:
-                       O_slu(p->acst); break;
-               case op_sri:
-                       O_sri(p->acst); break;
-               case op_sru:
-                       O_sru(p->acst); break;
-               case op_stf:
-                       O_stf(p->acst); break;
-               case op_sti:
-                       O_sti(p->acst); break;
-               case op_stl:
-                       O_stl(p->acst); break;
-               case op_str:
-                       O_str(p->acst); break;
-               case op_sts:
-                       O_sts(p->acst); break;
-               case op_xor:
-                       O_xor(p->acst); break;
-               case op_zer:
-                       O_zer(p->acst); break;
-               case op_zrf:
-                       O_zrf(p->acst); break;
-               case op_zrl:
-                       O_zrl(p->acst); break;
-               case op_beq:
-                       O_beq((label)p->acst); break;
-               case op_bge:
-                       O_bge((label)p->acst); break;
-               case op_bgt:
-                       O_bgt((label)p->acst); break;
-               case op_ble:
-                       O_ble((label)p->acst); break;
-               case op_blt:
-                       O_blt((label)p->acst); break;
-               case op_bne:
-                       O_bne((label)p->acst); break;
-               case op_bra:
-                       O_bra((label)p->acst); break;
-               case op_zeq:
-                       O_zeq((label)p->acst); break;
-               case op_zge:
-                       O_zge((label)p->acst); break;
-               case op_zgt:
-                       O_zgt((label)p->acst); break;
-               case op_zle:
-                       O_zle((label)p->acst); break;
-               case op_zlt:
-                       O_zlt((label)p->acst); break;
-               case op_zne:
-                       O_zne((label)p->acst); break;
-               default:
-                       fatal("Illegal mnemonic(%d)",p->opcode);
-               }
-               break;
-       case pro_ptyp: /* A procedure name argument */
-               switch(p->opcode) {
-               case op_cal:
-                       O_cal(p->apnam); break;
-               case op_lpi:
-                       O_lpi(p->apnam); break;
-               default:
-                       fatal("Illegal mnemonic(%d)",p->opcode);
-               }
-               break;
-       case nof_ptyp: /* a "g" argument */
-               switch(p->opcode) {
-               case op_dee:
-                       O_dee_dlb(p->adlb, p->anoff); break;
-               case op_fil:
-                       O_fil_dlb(p->adlb, p->anoff); break;
-               case op_gto:
-                       O_gto_dlb(p->adlb, p->anoff); break;
-               case op_ine:
-                       O_ine_dlb(p->adlb, p->anoff); break;
-               case op_lae:
-                       O_lae_dlb(p->adlb, p->anoff); break;
-               case op_lde:
-                       O_lde_dlb(p->adlb, p->anoff); break;
-               case op_loe:
-                       O_loe_dlb(p->adlb, p->anoff); break;
-               case op_sde:
-                       O_sde_dlb(p->adlb, p->anoff); break;
-               case op_ste:
-                       O_ste_dlb(p->adlb, p->anoff); break;
-               case op_zre:
-                       O_zre_dlb(p->adlb, p->anoff); break;
-               default:
-                       fatal("Illegal mnemonic(%d)",p->opcode);
-               }
-               break;
-       case sof_ptyp:
-               switch(p->opcode) {
-               case op_dee:
-                       O_dee_dnam(p->adnam, p->asoff); break;
-               case op_fil:
-                       O_fil_dnam(p->adnam, p->asoff); break;
-               case op_gto:
-                       O_gto_dnam(p->adnam, p->asoff); break;
-               case op_ine:
-                       O_ine_dnam(p->adnam, p->asoff); break;
-               case op_lae:
-                       O_lae_dnam(p->adnam, p->asoff); break;
-               case op_lde:
-                       O_lde_dnam(p->adnam, p->asoff); break;
-               case op_loe:
-                       O_loe_dnam(p->adnam, p->asoff); break;
-               case op_sde:
-                       O_sde_dnam(p->adnam, p->asoff); break;
-               case op_ste:
-                       O_ste_dnam(p->adnam, p->asoff); break;
-               case op_zre:
-                       O_zre_dnam(p->adnam, p->asoff); break;
-               default:
-                       fatal("Illegal mnemonic(%d)",p->opcode);
-               }
-               break;
-       default:
-               fatal("Illegal argtype(%d)",p->argtype);
+       case op_lae:
+               if(p->argtype==nof_ptyp) O_lae_dlb(p->adlb, p->anoff);
+               else O_lae_dnam(p->adnam, p->asoff); break;
+       case op_lal:
+               O_lal(p->acst); break;
+       case op_lar:
+               if(p->argtype!=none_ptyp) O_lar(p->acst);
+               else O_lar_narg(); break;
+       case op_ldc:
+               O_ldc(p->acst); break;
+       case op_lde:
+               if(p->argtype==nof_ptyp) O_lde_dlb(p->adlb, p->anoff);
+               else O_lde_dnam(p->adnam, p->asoff); break;
+       case op_ldf:
+               O_ldf(p->acst); break;
+       case op_ldl:
+               O_ldl(p->acst); break;
+       case op_lfr:
+               O_lfr(p->acst); break;
+       case op_lil:
+               O_lil(p->acst); break;
+       case op_lim:
+               O_lim(); break;
+       case op_lin:
+               O_lin(p->acst); break;
+       case op_lni:
+               O_lni(); break;
+       case op_loc:
+               O_loc(p->acst); break;
+       case op_loe:
+               if(p->argtype==nof_ptyp) O_loe_dlb(p->adlb, p->anoff);
+               else O_loe_dnam(p->adnam, p->asoff); break;
+       case op_lof:
+               O_lof(p->acst); break;
+       case op_loi:
+               O_loi(p->acst); break;
+       case op_lol:
+               O_lol(p->acst); break;
+       case op_lor:
+               O_lor(p->acst); break;
+       case op_los:
+               if(p->argtype!=none_ptyp) O_los(p->acst);
+               else O_los_narg(); break;
+       case op_lpb:
+               O_lpb(); break;
+       case op_lpi:
+               O_lpi(p->apnam); break;
+       case op_lxa:
+               O_lxa(p->acst); break;
+       case op_lxl:
+               O_lxl(p->acst); break;
+       case op_mlf:
+               if(p->argtype!=none_ptyp) O_mlf(p->acst);
+               else O_mlf_narg(); break;
+       case op_mli:
+               if(p->argtype!=none_ptyp) O_mli(p->acst);
+               else O_mli_narg(); break;
+       case op_mlu:
+               if(p->argtype!=none_ptyp) O_mlu(p->acst);
+               else O_mlu_narg(); break;
+       case op_mon:
+               O_mon(); break;
+       case op_ngf:
+               if(p->argtype!=none_ptyp) O_ngf(p->acst);
+               else O_ngf_narg(); break;
+       case op_ngi:
+               if(p->argtype!=none_ptyp) O_ngi(p->acst);
+               else O_ngi_narg(); break;
+       case op_nop:
+               O_nop(); break;
+       case op_rck:
+               if(p->argtype!=none_ptyp) O_rck(p->acst);
+               else O_rck_narg(); break;
+       case op_ret:
+               O_ret(p->acst); break;
+       case op_rmi:
+               if(p->argtype!=none_ptyp) O_rmi(p->acst);
+               else O_rmi_narg(); break;
+       case op_rmu:
+               if(p->argtype!=none_ptyp) O_rmu(p->acst);
+               else O_rmu_narg(); break;
+       case op_rol:
+               if(p->argtype!=none_ptyp) O_rol(p->acst);
+               else O_rol_narg(); break;
+       case op_ror:
+               if(p->argtype!=none_ptyp) O_ror(p->acst);
+               else O_ror_narg(); break;
+       case op_rtt:
+               O_rtt(); break;
+       case op_sar:
+               if(p->argtype!=none_ptyp) O_sar(p->acst);
+               else O_sar_narg(); break;
+       case op_sbf:
+               if(p->argtype!=none_ptyp) O_sbf(p->acst);
+               else O_sbf_narg(); break;
+       case op_sbi:
+               if(p->argtype!=none_ptyp) O_sbi(p->acst);
+               else O_sbi_narg(); break;
+       case op_sbs:
+               if(p->argtype!=none_ptyp) O_sbs(p->acst);
+               else O_sbs_narg(); break;
+       case op_sbu:
+               if(p->argtype!=none_ptyp) O_sbu(p->acst);
+               else O_sbu_narg(); break;
+       case op_sde:
+               if(p->argtype==nof_ptyp) O_sde_dlb(p->adlb, p->anoff);
+               else O_sde_dnam(p->adnam, p->asoff); break;
+       case op_sdf:
+               O_sdf(p->acst); break;
+       case op_sdl:
+               O_sdl(p->acst); break;
+       case op_set:
+               if(p->argtype!=none_ptyp) O_set(p->acst);
+               else O_set_narg(); break;
+       case op_sig:
+               O_sig(); break;
+       case op_sil:
+               O_sil(p->acst); break;
+       case op_sim:
+               O_sim(); break;
+       case op_sli:
+               if(p->argtype!=none_ptyp) O_sli(p->acst);
+               else O_sli_narg(); break;
+       case op_slu:
+               if(p->argtype!=none_ptyp) O_slu(p->acst);
+               else O_slu_narg(); break;
+       case op_sri:
+               if(p->argtype!=none_ptyp) O_sri(p->acst);
+               else O_sri_narg(); break;
+       case op_sru:
+               if(p->argtype!=none_ptyp) O_sru(p->acst);
+               else O_sru_narg(); break;
+       case op_ste:
+               if(p->argtype==nof_ptyp) O_ste_dlb(p->adlb, p->anoff);
+               else O_ste_dnam(p->adnam, p->asoff); break;
+       case op_stf:
+               O_stf(p->acst); break;
+       case op_sti:
+               O_sti(p->acst); break;
+       case op_stl:
+               O_stl(p->acst); break;
+       case op_str:
+               O_str(p->acst); break;
+       case op_sts:
+               if(p->argtype!=none_ptyp) O_sts(p->acst);
+               else O_sts_narg(); break;
+       case op_teq:
+               O_teq(); break;
+       case op_tge:
+               O_tge(); break;
+       case op_tgt:
+               O_tgt(); break;
+       case op_tle:
+               O_tle(); break;
+       case op_tlt:
+               O_tlt(); break;
+       case op_tne:
+               O_tne(); break;
+       case op_trp:
+               O_trp(); break;
+       case op_xor:
+               if(p->argtype!=none_ptyp) O_xor(p->acst);
+               else O_xor_narg(); break;
+       case op_zeq:
+               O_zeq((label)p->acst); break;
+       case op_zer:
+               if(p->argtype!=none_ptyp) O_zer(p->acst);
+               else O_zer_narg(); break;
+       case op_zge:
+               O_zge((label)p->acst); break;
+       case op_zgt:
+               O_zgt((label)p->acst); break;
+       case op_zle:
+               O_zle((label)p->acst); break;
+       case op_zlt:
+               O_zlt((label)p->acst); break;
+       case op_zne:
+               O_zne((label)p->acst); break;
+       case op_zre:
+               if(p->argtype==nof_ptyp) O_zre_dlb(p->adlb, p->anoff);
+               else O_zre_dnam(p->adnam, p->asoff); break;
+       case op_zrf:
+               if(p->argtype!=none_ptyp) O_zrf(p->acst);
+               else O_zrf_narg(); break;
+       case op_zrl:
+               O_zrl(p->acst); break;
        }
 }
index e087e26..0c41fd0 100644 (file)
@@ -14,15 +14,26 @@ static char rcsid[] = "$Header$";
 
 extern char em_mnem[][4];
 
-struct instr **patternqueue, **nextpatt;
-struct instr **backupqueue, **nextbackup, **lastbackup;
-struct instr **outputqueue, **nextoutput, **lastoutput;
-struct instr **freeiqueue,  **nextifree, **lastifree;
-char *strqueue, *nextstr, *laststr;
-
-int noutput;   /* number of instructions in output queue */
-int WSIZE;     /* wordlength */
-int PSIZE;     /* pointer length */
+struct instr **OO_patternqueue;
+struct instr **OO_nxtpatt;
+struct instr **OO_bkupqueue;
+struct instr **OO_nxtbackup;
+
+static char *filename;
+static struct instr **lastbackup;
+static struct instr **outputqueue;
+static struct instr **nextoutput;
+static struct instr **lastoutput;
+static struct instr **freeiqueue;
+static struct instr **nextifree;
+static struct instr **lastifree;
+static char *strqueue;
+static char *nextstr;
+static char *laststr;
+
+int OO_noutput;        /* number of instructions in output queue */
+int OO_WSIZE;  /* wordlength */
+int OO_PSIZE;  /* pointer length */
 
 #ifdef STATS
 int sflag = 1;                 /* pattern statistics output */
@@ -30,17 +41,16 @@ int sflag = 1;                      /* pattern statistics output */
 #ifdef COLLECT
 int cflag = 0;                 /* internal statistics output */
 #define UPDATEMAX(oldmax,n) if(cflag&&n>oldmax) oldmax=n
-int numwrites = 0;
-int numnextems = 0;
-int numpushs = 0;
-int numbackups = 0;
-int numflushes = 0;
-int numfrees = 0;
-int numdefaults = 0;
-int highestbackup = 0, totalbackup = 0;
-int highestoutput = 0, totaloutput = 0;
-int highestfreei = 0, totalfreei = 0;
-int higheststr = 0, totalstr = 0;
+static int numwrites = 0;
+static int numpushs = 0;
+static int numbackups = 0;
+static int numflushes = 0;
+static int numfrees = 0;
+static int numdefaults = 0;
+static int highestbackup = 0, totalbackup = 0;
+static int highestoutput = 0, totaloutput = 0;
+static int highestfreei = 0, totalfreei = 0;
+static int higheststr = 0, totalstr = 0;
 #endif
 
 C_init(wsize,psize)
@@ -48,13 +58,14 @@ C_init(wsize,psize)
 {
        allocmem();
        O_init(wsize,psize);
-       WSIZE = wsize;
-       PSIZE = psize;
+       OO_WSIZE = wsize;
+       OO_PSIZE = psize;
 }
 
 C_open(fname)
        char *fname;
 {
+       filename = fname;
        return(O_open(fname));
 }
 
@@ -72,19 +83,30 @@ C_close()
        O_close();
 }
 
+PRIVATE
+fatal(s,a)
+       char *s;
+       int a;
+{
+       fprint(STDERR, "%s: ", filename ? filename : "standard input");
+       fprint(STDERR,s,a);
+       fprint(STDERR,"\n");
+       sys_stop(S_EXIT);
+}
+
 PRIVATE
 allocmem()
 {
        /* Allocate memory for queues on heap */
-       nextpatt = patternqueue =
+       OO_nxtpatt = OO_patternqueue =
                (struct instr **)Malloc(MAXPATTERN*sizeof(struct instr *));
-       nextbackup = backupqueue =
+       OO_nxtbackup = OO_bkupqueue =
                (struct instr **)Malloc(MAXBACKUP*sizeof(struct instr *));
-       lastbackup = backupqueue + MAXBACKUP - 1;
+       lastbackup = OO_bkupqueue + MAXBACKUP - 1;
        nextoutput = outputqueue =
                (struct instr **)Malloc(MAXOUTPUT*sizeof(struct instr *));
        lastoutput = outputqueue + MAXOUTPUT - 1;
-       noutput = 0;
+       OO_noutput = 0;
        nextifree = freeiqueue =
                (struct instr **)Malloc(MAXFREEI*sizeof(struct instr *));
        lastifree = freeiqueue + MAXFREEI - 1;
@@ -99,7 +121,6 @@ outputstats()
 {
        int i;
        fprint(STDERR,"Total of %d instructions read, %d written\n",numreads,numwrites);
-       fprint(STDERR,"Total of %d calls to nextem\n",numnextems);
        fprint(STDERR,"Total of %d calls to flush\n",numflushes);
        fprint(STDERR,"Total of %d calls to myfree\n",numfrees);
        fprint(STDERR,"Total of %d instructions pushed back\n",numpushs-numbackups);
@@ -123,7 +144,7 @@ printav(n)
 }
 #endif
 
-myfree(p)
+OO_free(p)
        struct instr *p;
 {
 #ifdef DEBUG
@@ -148,12 +169,6 @@ myfree(p)
 #endif
 }
 
-nfree(n)
-{
-       while(n--)
-               myfree(*--nextpatt);
-}
-
 PRIVATE char *
 freestr(s)
        char *s;
@@ -170,21 +185,7 @@ freestr(s)
        return(res);
 }
 
-nextem()
-{
-       /*
-       /* Return the next instruction from backup queue else 0.
-       */
-#ifdef COLLECT
-       if(cflag)
-               numnextems++;
-#endif
-       if(nextbackup>backupqueue)
-               return((*nextpatt++ = *(--nextbackup))->opcode);
-       return(0);
-}
-
-flush()
+OO_flush()
 {
        /*
        /* Output all instructions waiting in the output queue and free their
@@ -198,86 +199,86 @@ flush()
        if(cflag) {
                numflushes++;
                totaloutput += nextoutput-outputqueue;
-               totalbackup += nextbackup-backupqueue;
+               totalbackup += OO_nxtbackup-OO_bkupqueue;
                totalfreei += nextifree-freeiqueue;
                totalstr += nextstr-strqueue;
        }
 #endif
-       if(noutput) {
+       if(OO_noutput) {
                for(p=outputqueue;p<nextoutput;p++) {
 #ifdef COLLECT
                        if(cflag)
                                numwrites++;
 #endif
-                       mkcalls(*p);
-                       myfree(*p);
+                       OO_mkcalls(*p);
+                       OO_free(*p);
                }
                nextoutput=outputqueue;
-               if(nextbackup==backupqueue)
+               if(OO_nxtbackup==OO_bkupqueue)
                        nextstr = strqueue;
-               noutput = 0;
+               OO_noutput = 0;
        }
 }
 
-outop(opcode)
+OO_outop(opcode)
        int opcode;
 {
        register struct instr *p = GETINSTR();
        p->opcode = opcode;
        p->argtype = none_ptyp;
-       output(p);
+       OO_output(p);
 }
 
-inop(opcode)
+OO_inop(opcode)
        int opcode;
 {
        register struct instr *p = GETINSTR();
        p->opcode = opcode;
        p->argtype = none_ptyp;
-       *nextpatt++ = p;
+       *OO_nxtpatt++ = p;
 }
 
-outcst(opcode,cst)
+OO_outcst(opcode,cst)
        int opcode,cst;
 {
        register struct instr *p = GETINSTR();
        p->opcode = opcode;
        p->argtype = cst_ptyp;
        p->acst = cst;
-       output(p);
+       OO_output(p);
 }
 
-incst(opcode,cst)
+OO_incst(opcode,cst)
        int opcode,cst;
 {
        register struct instr *p = GETINSTR();
        p->opcode = opcode;
        p->argtype = cst_ptyp;
        p->acst = cst;
-       *nextpatt++ = p;
+       *OO_nxtpatt++ = p;
 }
 
-outlab(opcode,lab)
+OO_outlab(opcode,lab)
        int opcode,lab;
 {
        register struct instr *p = GETINSTR();
        p->opcode = opcode;
        p->argtype = cst_ptyp;
        p->acst = lab;
-       output(p);
+       OO_output(p);
 }
 
-inlab(opcode,lab)
+OO_inlab(opcode,lab)
        int opcode,lab;
 {
        register struct instr *p = GETINSTR();
        p->opcode = opcode;
        p->argtype = cst_ptyp;
        p->acst = lab;
-       *nextpatt++ = p;
+       *OO_nxtpatt++ = p;
 }
 
-outpnam(opcode,pnam)
+OO_outpnam(opcode,pnam)
        int opcode;
        char *pnam;
 {
@@ -285,10 +286,10 @@ outpnam(opcode,pnam)
        p->opcode = opcode;
        p->argtype = pro_ptyp;
        p->apnam = pnam;
-       output(p);
+       OO_output(p);
 }
 
-inpnam(opcode,pnam)
+OO_inpnam(opcode,pnam)
        int opcode;
        char *pnam;
 {
@@ -296,10 +297,10 @@ inpnam(opcode,pnam)
        p->opcode = opcode;
        p->argtype = pro_ptyp;
        p->apnam = freestr(pnam);
-       *nextpatt++ = p;
+       *OO_nxtpatt++ = p;
 }
 
-outdefilb(opcode,deflb)
+OO_outdefilb(opcode,deflb)
        int opcode;
        label deflb;
 {
@@ -307,10 +308,10 @@ outdefilb(opcode,deflb)
        p->opcode = opcode;
        p->argtype = lab_ptyp;
        p->alab = deflb;
-       output(p);
+       OO_output(p);
 }
 
-indefilb(opcode,deflb)
+OO_indefilb(opcode,deflb)
        int opcode;
        label deflb;
 {
@@ -318,10 +319,10 @@ indefilb(opcode,deflb)
        p->opcode = opcode;
        p->argtype = lab_ptyp;
        p->alab = deflb;
-       *nextpatt++ = p;
+       *OO_nxtpatt++ = p;
 }
 
-outext(opcode,arg,soff)
+OO_outext(opcode,arg,soff)
        int opcode;
        struct instr *arg;
        int soff;
@@ -343,10 +344,10 @@ outext(opcode,arg,soff)
        default:
                fatal("Unexpected type %d in outext",arg->argtype);
        }
-       output(p);
+       OO_output(p);
 }
 
-indnam(opcode,name,off)
+OO_indnam(opcode,name,off)
        int opcode;
        char *name;
        int off;
@@ -356,10 +357,10 @@ indnam(opcode,name,off)
        p->argtype = sof_ptyp;
        p->adnam = freestr(name);
        p->asoff = off;
-       *nextpatt++ = p;
+       *OO_nxtpatt++ = p;
 }
 
-indlb(opcode,lab,off)
+OO_indlb(opcode,lab,off)
        int opcode;
        label lab;
        int off;
@@ -369,10 +370,10 @@ indlb(opcode,lab,off)
        p->argtype = nof_ptyp;
        p->adlb = lab;
        p->anoff = off;
-       *nextpatt++ = p;
+       *OO_nxtpatt++ = p;
 }
 
-output(p)
+OO_output(p)
        struct instr *p;
 {
        /* Put the instruction p on the output queue */
@@ -381,34 +382,34 @@ output(p)
                fprint(STDERR,"Overflow of outputqueue - output flushed\n");
                printstate("Output overflow");
 #endif
-               flush();
+               OO_flush();
        }
-       noutput++;
+       OO_noutput++;
        *nextoutput++ = p;
 #ifdef COLLECT
        UPDATEMAX(highestoutput,nextoutput-outputqueue);
 #endif
 }
 
-pushback(p)
+OO_pushback(p)
        struct instr *p;
 {
-       /* push instr. p onto backupqueue */
-       if(nextbackup > lastbackup) {
+       /* push instr. p onto bkupqueue */
+       if(OO_nxtbackup > lastbackup) {
 #ifdef DEBUG
-               fprint(STDERR,"Warning: Overflow of backupqueue-backup ignored\n");
+               fprint(STDERR,"Warning: Overflow of bkupqueue-backup ignored\n");
                printstate("Backup overflow");
 #endif
                return;
        }
-       *nextbackup++ = p;
+       *OO_nxtbackup++ = p;
 #ifdef COLLECT
-       UPDATEMAX(highestbackup,nextbackup-backupqueue);
+       UPDATEMAX(highestbackup,OO_nxtbackup-OO_bkupqueue);
        numpushs++;
 #endif
 }
 
-backup(n)
+OO_backup(n)
        int n;
 {
        /* copy (up to) n instructions from output to backup queues */
@@ -417,25 +418,25 @@ backup(n)
                if(cflag)
                        numbackups++;
 #endif
-               pushback(*(--nextoutput));
-               noutput--;
+               OO_pushback(*(--nextoutput));
+               OO_noutput--;
        }
 }
 
-dodefault(numout, numcopy)
+OO_dodefault(numout, numcopy)
        int numout, numcopy;
 {
        register struct instr **p,**q;
-       q = (p = patternqueue) + numout;
+       q = (p = OO_patternqueue) + numout;
        while(numcopy--) {
                if(numout) {
                        numout--;
-                       output(*p);
+                       OO_output(*p);
                }
                *p++ = *q++;
        }
-       nextpatt = p;
-       while(numout--) output(*p++);
+       OO_nxtpatt = p;
+       while(numout--) OO_output(*p++);
 #ifdef COLLECT
        if(cflag)
                numdefaults++;
@@ -453,12 +454,12 @@ printstate(mess)
        while(p<nextoutput)
                prtinst(*p++);
        fprint(STDERR," |==| ");
-       p = patternqueue;
-       while(p<nextpatt)
+       p = OO_patternqueue;
+       while(p<OO_nxtpatt)
                prtinst(*p++);
        fprint(STDERR," |==| ");
-       p = backupqueue;
-       while(p<nextbackup)
+       p = OO_bkupqueue;
+       while(p<OO_nxtbackup)
                prtinst(*p++);
        fprint(STDERR,"\n");
 }
index 5702b92..d4e3118 100644 (file)
 #include <em_comp.h>
 #include <system.h>
 #include <idf_pkg.spec>
+#include <emO_code.h>
 
 #define NULL 0
-#define FLUSHDFA()     if(state) { inop(OTHER); dfa(OTHER); } \
-                       else if(noutput) flush();
+#define FLUSHDFA()     if(OO_state) { OO_inop(OTHER); OO_dfa(OTHER); } \
+                       else if(OO_noutput) OO_flush();
+#define NEXTEM()       ((OO_nxtbackup>OO_bkupqueue)?\
+                               ((*OO_nxtpatt++ = *(--OO_nxtbackup))->opcode):\
+                               0)
 
 #define op_lab 255
 #define OTHER  254
@@ -47,11 +51,14 @@ struct instr {
 #define asoff val.sdlb.soff
 };
 
-extern struct instr **patternqueue, **nextpatt;
-extern int state;
-extern int noutput;    /* number of instructions in output queue */
-extern int WSIZE;      /* wordlength */
-extern int PSIZE;      /* pointer length */
+extern struct instr **OO_patternqueue;
+extern struct instr **OO_nxtpatt;
+extern struct instr **OO_bkupqueue;
+extern struct instr **OO_nxtbackup;
+extern int OO_state;
+extern int OO_noutput; /* number of instructions in output queue */
+extern int OO_WSIZE;   /* wordlength */
+extern int OO_PSIZE;   /* pointer length */
 #ifdef DEBUG
 extern int dflag;                      /* debugging output */
 #endif
index 0c6727e..17c1d86 100644 (file)
@@ -21,8 +21,8 @@ outputincalls()
                case NOARG:
                        fprint(ofile,"\nC_%s() {\n",s);
                        if(op->id_used) {
-                               fprint(ofile,"\tinop(op_%s);\n",s);
-                               fprint(ofile,"\tdfa(op_%s);\n",s);
+                               fprint(ofile,"\tOO_inop(op_%s);\n",s);
+                               fprint(ofile,"\tOO_dfa(op_%s);\n",s);
                        }
                        else {
                                fprint(ofile,"\tFLUSHDFA();\n");
@@ -33,8 +33,8 @@ outputincalls()
                case CSTOPT:
                        fprint(ofile,"\nC_%s_narg() {\n",s);
                        if(op->id_used) {
-                               fprint(ofile,"\tinop(op_%s);\n",s);
-                               fprint(ofile,"\tdfa(op_%s);\n",s);
+                               fprint(ofile,"\tOO_inop(op_%s);\n",s);
+                               fprint(ofile,"\tOO_dfa(op_%s);\n",s);
                        }
                        else {
                                fprint(ofile,"\tFLUSHDFA();\n");
@@ -45,8 +45,8 @@ outputincalls()
                case CST:
                        fprint(ofile,"\nC_%s(n) int n; {\n",s);
                        if(op->id_used) {
-                               fprint(ofile,"\tincst(op_%s,n);\n",s);
-                               fprint(ofile,"\tdfa(op_%s);\n",s);
+                               fprint(ofile,"\tOO_incst(op_%s,n);\n",s);
+                               fprint(ofile,"\tOO_dfa(op_%s);\n",s);
                        }
                        else {
                                fprint(ofile,"\tFLUSHDFA();\n");
@@ -57,8 +57,8 @@ outputincalls()
                case DEFILB:
                        fprint(ofile,"\nC_df_ilb(l) label l; {\n");
                        if(op->id_used) {
-                               fprint(ofile,"\tindefilb(op_%s,l);\n",s);
-                               fprint(ofile,"\tdfa(op_%s);\n",s);
+                               fprint(ofile,"\tOO_indefilb(op_%s,l);\n",s);
+                               fprint(ofile,"\tOO_dfa(op_%s);\n",s);
                        }
                        else {
                                fprint(ofile,"\tFLUSHDFA();\n");
@@ -69,8 +69,8 @@ outputincalls()
                case PNAM:
                        fprint(ofile,"\nC_%s(s) char *s; {\n",s);
                        if(op->id_used) {
-                               fprint(ofile,"\tinpnam(op_%s,s);\n",s);
-                               fprint(ofile,"\tdfa(op_%s);\n",s);
+                               fprint(ofile,"\tOO_inpnam(op_%s,s);\n",s);
+                               fprint(ofile,"\tOO_dfa(op_%s);\n",s);
                        }
                        else {
                                fprint(ofile,"\tFLUSHDFA();\n");
@@ -81,8 +81,8 @@ outputincalls()
                case LAB:
                        fprint(ofile,"\nC_%s(l) label l; {\n",s);
                        if(op->id_used) {
-                               fprint(ofile,"\tinlab(op_%s,l);\n",s);
-                               fprint(ofile,"\tdfa(op_%s);\n",s);
+                               fprint(ofile,"\tOO_inlab(op_%s,l);\n",s);
+                               fprint(ofile,"\tOO_dfa(op_%s);\n",s);
                        }
                        else {
                                fprint(ofile,"\tFLUSHDFA();\n");
@@ -93,8 +93,8 @@ outputincalls()
                case EXT:
                        fprint(ofile,"\nC_%s(n) int n; {\n",s);
                        if(op->id_used) {
-                               fprint(ofile,"\tincst(op_%s,n);\n",s);
-                               fprint(ofile,"\tdfa(op_%s);\n",s);
+                               fprint(ofile,"\tOO_incst(op_%s,n);\n",s);
+                               fprint(ofile,"\tOO_dfa(op_%s);\n",s);
                        }
                        else {
                                fprint(ofile,"\tFLUSHDFA();\n");
@@ -103,8 +103,8 @@ outputincalls()
                        fprint(ofile,"}\n",s);
                        fprint(ofile,"\nC_%s_dnam(s,n) char *s; int n; {\n",s);
                        if(op->id_used) {
-                               fprint(ofile,"\tindnam(op_%s,s,n);\n",s);
-                               fprint(ofile,"\tdfa(op_%s);\n",s);
+                               fprint(ofile,"\tOO_indnam(op_%s,s,n);\n",s);
+                               fprint(ofile,"\tOO_dfa(op_%s);\n",s);
                        }
                        else {
                                fprint(ofile,"\tFLUSHDFA();\n");
@@ -113,8 +113,8 @@ outputincalls()
                        fprint(ofile,"}\n",s);
                        fprint(ofile,"\nC_%s_dlb(l,n) label l; int n; {\n",s);
                        if(op->id_used) {
-                               fprint(ofile,"\tindlb(op_%s,l,n);\n",s);
-                               fprint(ofile,"\tdfa(op_%s);\n",s);
+                               fprint(ofile,"\tOO_indlb(op_%s,l,n);\n",s);
+                               fprint(ofile,"\tOO_dfa(op_%s);\n",s);
                        }
                        else {
                                fprint(ofile,"\tFLUSHDFA();\n");
index e8eff2a..408433f 100644 (file)
@@ -32,7 +32,7 @@ PRIVATE
 outputtables()
 {
        int s;
-       fprint(ofile,"struct defact {\n");
+       fprint(ofile,"static struct defact {\n");
        fprint(ofile,"\tint numoutput;\n");
        fprint(ofile,"\tint numcopy;\n");
        fprint(ofile,"\tint nextstate;\n");
@@ -52,19 +52,19 @@ outputdfa()
        int s;
        struct idf *op;
        struct state *p;
-       fprint(ofile,"int state = 0;\n");
+       fprint(ofile,"int OO_state = 0;\n");
        fprint(ofile,"\n");
-       fprint(ofile,"dfa(last) int last; {\n");
+       fprint(ofile,"OO_dfa(last) int last; {\n");
        fprint(ofile,"\twhile(last) {\n");
        fprint(ofile,"\t\tswitch(last) {\n");
        for(op=ops;op!=(struct idf *)NULL;op=op->id_nextidf) {
                if(!op->id_used)
                        continue;
                fprint(ofile,"\t\tcase op_%s:\n",op->id_text);
-               fprint(ofile,"\t\t\tswitch(state) {\n");
+               fprint(ofile,"\t\t\tswitch(OO_state) {\n");
                if(!op->id_startpatt) {
                                fprint(ofile,"\t\t\tcase 0: ");
-                               fprint(ofile,"output(*--nextpatt); ");
+                               fprint(ofile,"OO_output(*--OO_nxtpatt); ");
                                fprint(ofile,"break;\n");
                }
                for(s=0;s<=higheststate;s++)
@@ -72,8 +72,8 @@ outputdfa()
                                if(p->op==op) {
                                        fprint(ofile,"\t\t\tcase %d: ",s);
                                        if(actions[p->goto_state]==(struct action *)NULL)
-                                               fprint(ofile,"state = %d; ",p->goto_state);
-                                       else fprint(ofile,"dotrans(%d); ",p->goto_state);
+                                               fprint(ofile,"OO_state = %d; ",p->goto_state);
+                                       else fprint(ofile,"OO_dotrans(%d); ",p->goto_state);
                                        fprint(ofile,"break;\n");
                                }
                        }
@@ -82,30 +82,29 @@ outputdfa()
                fprint(ofile,"\t\t\tbreak;\n");
        }
        fprint(ofile,"\t\tdefault:\n");
-       fprint(ofile,"\t\t\tif(state) defaultaction();\n");
+       fprint(ofile,"\t\t\tif(OO_state) defaultaction();\n");
        fprint(ofile,"\t\t\telse {\n");
-       fprint(ofile,"\t\t\t\tflush();\n");
-       fprint(ofile,"\t\t\t\tmkcalls(*--nextpatt);\n");
-       fprint(ofile,"\t\t\t\tmyfree(*nextpatt);\n");
+       fprint(ofile,"\t\t\t\tOO_flush();\n");
+       fprint(ofile,"\t\t\t\tOO_mkcalls(*--OO_nxtpatt);\n");
+       fprint(ofile,"\t\t\t\tOO_free(*OO_nxtpatt);\n");
        fprint(ofile,"\t\t\t}\n");
        fprint(ofile,"\t\t\tbreak;\n");
        fprint(ofile,"\t\tcase OTHER:\n");
-       fprint(ofile,"\t\t\tif(state) defaultaction();\n");
+       fprint(ofile,"\t\t\tif(OO_state) defaultaction();\n");
        fprint(ofile,"\t\t\telse {\n");
-       fprint(ofile,"\t\t\t\tflush();\n");
-       fprint(ofile,"\t\t\t\tmyfree(*--nextpatt);\n");
+       fprint(ofile,"\t\t\t\tOO_flush();\n");
+       fprint(ofile,"\t\t\t\tOO_free(*--OO_nxtpatt);\n");
        fprint(ofile,"\t\t\t}\n");
        fprint(ofile,"\t\t\tbreak;\n");
        fprint(ofile,"\t\t}\n");
-       fprint(ofile,"\tlast = nextem();\n");
+       fprint(ofile,"\tlast = NEXTEM();\n");
        fprint(ofile,"\t}\n");
        fprint(ofile,"}\n");
 }
 
 PRIVATE
-outputmnems(l,state)
+outputmnems(l)
        struct mnems l;
-       int state;
 {
        int i;
        for(i=1;i<=l.m_len;i++) 
@@ -116,6 +115,7 @@ PRIVATE
 outputdotrans()
 {
        int s;
+       int i;
        struct state *p;
        struct action *a;
        int seennontested;
@@ -124,30 +124,23 @@ outputdotrans()
                sys_stop(S_EXIT);
        }
        fprint(ofile,"#include \"nopt.h\"\n\n");
-       fprint(ofile,"\ndotrans(s) int s; {\n");
-       fprint(ofile,"\tswitch(state=s) {\n");
+       fprint(ofile,"\nOO_dotrans(s) int s; {\n");
+       fprint(ofile,"\tregister struct instr **patt = OO_patternqueue;\n");
+       fprint(ofile,"\tswitch(OO_state=s) {\n");
        fprint(ofile,"\tdefault: return;\n");
        for(s=0;s<=higheststate;s++)
                if(actions[s]!=(struct action *)NULL) {
                        fprint(ofile,"\tcase %d: /*",s);
-                       outputmnems(patterns[s],s);
+                       outputmnems(patterns[s]);
                        fprint(ofile," */\n");
                        seennontested=0;
                        for(a=actions[s];a!=(struct action *)NULL;a=a->next) {
                                if(a->test!=(struct exp_node *)NULL) {
                                        fprint(ofile,"\t\tif(");
                                        outputexp(a->test,s);
-                                       /*
-                                       /*fprint(ofile,"dotest(%d)",a->linenum);
-                                       */
                                        fprint(ofile,") {\n");
-                                       /*
-                                       /*fprint(ofile,"\t\t\tdoaction(%d);\n",a->linenum);
-                                       */
                                        outputoneaction(s,a);
-                                       fprint(ofile,"\t\t\tnfree(%d);\n",patterns[s].m_len);
-                                       fprint(ofile,"\t\t\tstate=0;\n");
-                                       fprint(ofile,"\t\t\tbreak;\n");
+                                       fprint(ofile,"\t\t\tgoto free%d;\n",patterns[s].m_len);
                                        fprint(ofile,"\t\t}\n");
                                }
                                else {
@@ -156,18 +149,17 @@ outputdotrans()
                                                nerrors++;
                                        }
                                        seennontested++;
-                                       /*
-                                       /*fprint(ofile,"\t\t\tdoaction(%d);\n",a->linenum);
-                                       */
                                        outputoneaction(s,a);
-                                       fprint(ofile,"\t\tnfree(%d);\n",patterns[s].m_len);
-                                       fprint(ofile,"\t\tstate=0;\n");
-                                       fprint(ofile,"\t\tbreak;\n");
+                                       fprint(ofile,"\t\t\tgoto free%d;\n",patterns[s].m_len);
                                }
                        }
-                       fprint(ofile,"\t\tbreak;\n");
+                       fprint(ofile,"\t\treturn;\n");
                }
        fprint(ofile,"\t}\n");
+       for(i=longestpattern;i>0;i--)
+               fprint(ofile," free%d: OO_free(*--OO_nxtpatt);\n",i);
+       fprint(ofile," free0: ;\n");
+       fprint(ofile,"\tOO_state=0;\n");
        fprint(ofile,"}\n");
        fprint(ofile,"\n");
 }
@@ -176,10 +168,10 @@ PRIVATE
 outputdodefault()
 {
        fprint(ofile,"\nstatic defaultaction() {\n");
-       fprint(ofile,"\tregister struct defact *p = &defaultactions[state];\n");
-       fprint(ofile,"\tpushback(*--nextpatt);\n");
-       fprint(ofile,"\tdodefault(p->numoutput,p->numcopy);\n");
-       fprint(ofile,"\tdotrans(p->nextstate);\n");
+       fprint(ofile,"\tregister struct defact *p = &defaultactions[OO_state];\n");
+       fprint(ofile,"\tOO_pushback(*--OO_nxtpatt);\n");
+       fprint(ofile,"\tOO_dodefault(p->numoutput,p->numcopy);\n");
+       fprint(ofile,"\tOO_dotrans(p->nextstate);\n");
        fprint(ofile,"}\n");
 }
 
@@ -190,10 +182,10 @@ outputoneaction(s,a)
 {
        fprint(ofile,"\t\t/* ");
        fprint(ofile," -> ");
-       outputmnems(a->replacement,s);
+       outputmnems(a->replacement);
        fprint(ofile," */\n");
        outputrepl(s,patterns[s],a->replacement);
-       findworst(s,a->replacement);
+       findworst(a->replacement);
 }
 
 PRIVATE
@@ -212,31 +204,31 @@ outputrepl(state,patt,repl)
                char *mnem = ri->op_code->id_text;
                switch(ri->op_code->id_argfmt) {
                case NOARG:
-                       fprint(ofile,"\t\toutop(op_%s);\n",mnem);
+                       fprint(ofile,"\t\tOO_outop(op_%s);\n",mnem);
                        break;
                case CST:
                case CSTOPT:
-                       fprint(ofile,"\t\toutcst(op_%s,",mnem);
+                       fprint(ofile,"\t\tOO_outcst(op_%s,",mnem);
                        outputexp(ri->arg,state);
                        fprint(ofile,");\n");
                        break;
                case LAB:
-                       fprint(ofile,"\t\toutlab(op_%s,",mnem);
+                       fprint(ofile,"\t\tOO_outlab(op_%s,",mnem);
                        outputexp(ri->arg,state);
                        fprint(ofile,");\n");
                        break;
                case DEFILB:
-                       fprint(ofile,"\t\toutdefilb(op_%s,",mnem);
+                       fprint(ofile,"\t\tOO_outdefilb(op_%s,",mnem);
                        outputexp(ri->arg,state);
                        fprint(ofile,");\n");
                        break;
                case PNAM:
-                       fprint(ofile,"\t\toutpnam(op_%s,",mnem);
+                       fprint(ofile,"\t\tOO_outpnam(op_%s,",mnem);
                        outputexp(ri->arg,state);
                        fprint(ofile,");\n");
                        break;
                case EXT:
-                       fprint(ofile,"\t\toutext(op_%s,",mnem);
+                       fprint(ofile,"\t\tOO_outext(op_%s,",mnem);
                        outputexp(ri->arg,state);
                        fprint(ofile,");\n");
                        break;
@@ -284,10 +276,10 @@ outputexp(e,state)
                fprint(ofile,")");
                break;
        case DEFINED:
-               fprint(ofile,"(patternqueue[%d]->argtype!=none_ptyp)",e->leaf_val-1);
+               fprint(ofile,"(patt[%d]->argtype!=none_ptyp)",e->leaf_val-1);
                break;
        case UNDEFINED:
-               fprint(ofile,"(patternqueue[%d]->argtype==none_ptyp)",e->leaf_val-1);
+               fprint(ofile,"(patt[%d]->argtype==none_ptyp)",e->leaf_val-1);
                break;
        case COMMA:
                outext(e->exp_left);
@@ -319,26 +311,26 @@ outputexp(e,state)
                        break;
                case CST:
                case CSTOPT:
-                       fprint(ofile,"CST(patternqueue[%d])",e->leaf_val-1);
+                       fprint(ofile,"CST(patt[%d])",e->leaf_val-1);
                        break;
                case LAB:
-                       fprint(ofile,"LAB(patternqueue[%d])",e->leaf_val-1);
+                       fprint(ofile,"LAB(patt[%d])",e->leaf_val-1);
                        break;
                case DEFILB:
-                       fprint(ofile,"DEFILB(patternqueue[%d])",e->leaf_val-1);
+                       fprint(ofile,"DEFILB(patt[%d])",e->leaf_val-1);
                        break;
                case PNAM:
-                       fprint(ofile,"PNAM(patternqueue[%d])",e->leaf_val-1);
+                       fprint(ofile,"PNAM(patt[%d])",e->leaf_val-1);
                        break;
                case EXT:
-                       fprint(ofile,"offset(patternqueue[%d])",e->leaf_val-1);
+                       fprint(ofile,"OO_offset(patt[%d])",e->leaf_val-1);
                        break;
                }
                break;
        case PSIZE:
-               fprint(ofile,"PSIZE"); break;
+               fprint(ofile,"OO_PSIZE"); break;
        case WSIZE:
-               fprint(ofile,"WSIZE"); break;
+               fprint(ofile,"OO_WSIZE"); break;
        case INT:
                fprint(ofile,"%d",e->leaf_val); break;
        }
@@ -352,7 +344,7 @@ outext(e)
                fprint(STDERR,"Internal error in outext of parser\n");
                nerrors++;
        }
-       fprint(ofile,"patternqueue[%d]",e->leaf_val-1);
+       fprint(ofile,"patt[%d]",e->leaf_val-1);
 }
 
 PRIVATE
@@ -382,11 +374,11 @@ outputop(op)
        case COMP:      fprint(ofile,"~");      break;
        case UPLUS:     fprint(ofile,"+");      break;
        case UMINUS:    fprint(ofile,"-");      break;
-       case SAMESIGN:  fprint(ofile,"samesign(");      break;
-       case SFIT:      fprint(ofile,"sfit(");  break;
-       case UFIT:      fprint(ofile,"ufit(");  break;
-       case ROTATE:    fprint(ofile,"rotate(");        break;
-       case SAMEEXT:   fprint(ofile,"sameext(");       break;
-       case SAMENAM:   fprint(ofile,"samenam(");       break;
+       case SAMESIGN:  fprint(ofile,"OO_samesign(");   break;
+       case SFIT:      fprint(ofile,"OO_sfit(");       break;
+       case UFIT:      fprint(ofile,"OO_ufit(");       break;
+       case ROTATE:    fprint(ofile,"OO_rotate(");     break;
+       case SAMEEXT:   fprint(ofile,"OO_sameext(");    break;
+       case SAMENAM:   fprint(ofile,"OO_samenam(");    break;
        }
 }