printf("Number of patterns: %d\n", numpatterns);
printf("Longest pattern: %d\n", maxpattern);
printf("Longest replacement: %d\n", maxreplacement);
- printf("Dfa contains %d distinct state/opcode pairs\n", numentries);
+ printf("Dfa contains %d states and %d distinct state/opcode pairs\n",
+ higheststate+1,numentries);
printf("Compacted using row displacement into %d entries\n",maxpos);
/* output the arrays */
fprintf(ofile,"struct dfa OO_checknext[] = {\n");
fprintf(ofile,"%s ",l.m_elems[i-1]->op_code->id_text);
}
+PRIVATE int
+sametest(s1,s2,e1,e2)
+ int s1,s2;
+ struct exp_node *e1,*e2;
+{
+ /* retrun 1 if tests are identical */
+ if(e1) {
+ if(!e2) return 0;
+ if(e1->node_type!=e2->node_type) return 0;
+ switch(e1->node_type) {
+ case LOGAND:
+ case LOGOR:
+ case BITAND:
+ case BITOR:
+ case XOR:
+ case MINUS:
+ case PLUS:
+ case TIMES:
+ case DIV:
+ case MOD:
+ case EQ:
+ case NE:
+ case LT:
+ case LE:
+ case GT:
+ case GE:
+ case LSHIFT:
+ case RSHIFT:
+ case COMMA:
+ case SAMESIGN:
+ case SFIT:
+ case UFIT:
+ case ROTATE:
+ case SAMEEXT:
+ case SAMENAM:
+ return (sametest(e1->exp_left,e2->exp_left) &&
+ sametest(e1->exp_right,e2->exp_right));
+ case NOT:
+ case COMP:
+ case UPLUS:
+ case UMINUS:
+ return sametest(e1->exp_left,e2->exp_left);
+ case DEFINED:
+ case UNDEFINED:
+ case INT:
+ return (e1->leaf_val == e2->leaf_val);
+ case PATARG:
+ /* depends on pattern !! */
+ if (e1->leaf_val != e2->leaf_val) return 0;
+ return (patterns[s1].m_elems[e1->leaf_val-1]->
+ op_code->id_argfmt
+ == patterns[s1].m_elems[e2->leaf_val-1]->
+ op_code->id_argfmt);
+ case PSIZE:
+ case WSIZE:
+ return 1;
+
+ }
+ }
+ else return (e2==0);
+}
+
+PRIVATE int
+samerepl(s1,s2,r1,r2)
+ int s1,s2;
+ struct mnems r1,r2;
+{
+ /* return 1 if replacements are identical */
+ register int i;
+ register struct mnem_elem *m1,*m2;
+ if (r1.m_len != r2.m_len) return 0; /* different length */
+ for(i=0;i<r1.m_len;i++) {
+ m1=r1.m_elems[i];
+ m2=r2.m_elems[i];
+ if(m1->op_code!=m2->op_code) return 0;
+ if(!sametest(s1,s2,m1->arg,m2->arg)) return 0;
+ }
+ return 1;
+}
+
+PRIVATE int
+samecode(s1,s2)
+ int s1,s2;
+{
+ /* return 1 if replacement code of state s1 and s2 are identical */
+ register struct action *a1,*a2;
+ if (patterns[s1].m_len != patterns[s2].m_len) return 0;
+ a1 = actions[s1];
+ a2 = actions[s2];
+ while(a1) {
+ if(!a2) return 0; /* a2 is shorter */
+ if(!samerepl(s1,s2,a1->replacement,a2->replacement)) return 0;
+ if(!sametest(s1,s2,a1->test,a2->test)) return 0;
+ a1 = a1->next;
+ a2 = a2->next;
+ }
+ if(a2) return 0; /* a2 is longer */
+ return 1;
+}
+
PRIVATE
outdotrans()
{
- int s;
+ register int s,t;
struct action *a;
int seennontested;
+ int *farray;
fprintf(ofile,"#include \"nopt.h\"\n\n");
- /* declare all the trans functions */
- for(s=0;s<=higheststate;s++) {
- if(actions[s]!=(struct action *)NULL)
- fprintf(ofile,"static do%dtrans();\n",s);
- }
- /* output the array itself */
- fprintf(ofile,"\nint (*OO_ftrans[])()=\n{\n");
- for(s=0;s<=higheststate;s++) {
- if(actions[s]!=(struct action *)NULL)
- fprintf(ofile,"\tdo%dtrans,\n",s);
- else
- fprintf(ofile,"\t0,\n");
- }
- fprintf(ofile,"};\n\n");
- /* now output the functions */
+ /* keep track of which procedure used for each state */
+ farray = (int *)Malloc((unsigned)(higheststate+1)*sizeof(int));
+ for(s=0;s<=higheststate;s++) farray[s] = EMPTY;
+ /* output the functions avoiding duplicates */
for(s=0;s<=higheststate;s++) {
if(actions[s]!=(struct action *)NULL) {
+ /* first look for a previous identical function */
+ for(t=0;t<s;t++) {
+ if(actions[t]!=(struct action *)NULL &&
+ samecode(s,t)) {
+ /* use state 't' instead */
+ farray[s]=t;
+ goto next_func;
+ }
+ }
+ /* no identical function so make new one */
+ farray[s] = s;
fprintf(ofile,"\nstatic do%dtrans() {\n",s);
fprintf(ofile,"\tregister p_instr patt = OO_patternqueue;\n");
fprintf(ofile,"\t/* ");
}
fprintf(ofile,"}\n");
}
+ next_func:
+ continue;
+ }
+ /* output the array itself */
+ fprintf(ofile,"\n\nint (*OO_ftrans[])()=\n{\n");
+ for(s=0;s<=higheststate;s++) {
+ if(farray[s]!=EMPTY)
+ fprintf(ofile,"\tdo%dtrans,\n",farray[s]);
+ else
+ fprintf(ofile,"\t0,\n");
}
+ fprintf(ofile,"};\n");
}
PRIVATE
-df_dlb | label:l |
+insertpart | int:id |
FLUSHDFA();
- C_df_dlb(l);
-df_dnam | char *:s |
+ C_insertpart(id);
+beginpart | int:id |
FLUSHDFA();
- C_df_dnam(s);
+ C_beginpart(id);
+endpart | int:id |
+ FLUSHDFA();
+ C_endpart(id);
pro | char *:s arith:l |
FLUSHDFA();
C_pro(s,l);
end_narg | |
FLUSHDFA();
C_end_narg();
+df_dlb | label:l |
+ C_df_dlb(l);
+df_dnam | char *:s |
+ C_df_dnam(s);
exa_dnam | char *:s |
- FLUSHDFA();
C_exa_dnam(s);
exa_dlb | label:l |
- FLUSHDFA();
C_exa_dlb(l);
exp | char *:s |
- FLUSHDFA();
C_exp(s);
ina_dnam | char *:s |
- FLUSHDFA();
C_ina_dnam(s);
ina_dlb | label:l |
- FLUSHDFA();
C_ina_dlb(l);
inp | char *:s |
- FLUSHDFA();
C_inp(s);
bss_cst | arith:n arith:w int:i |
- FLUSHDFA();
C_bss_cst(n,w,i);
bss_icon | arith:n char *:s arith:sz int:i |
- FLUSHDFA();
C_bss_icon(n,s,sz,i);
bss_ucon | arith:n char *:s arith:sz int:i |
- FLUSHDFA();
C_bss_ucon(n,s,sz,i);
bss_fcon | arith:n char *:s arith:sz int:i |
- FLUSHDFA();
C_bss_fcon(n,s,sz,i);
bss_dnam | arith:n char *:s arith:offs int:i |
- FLUSHDFA();
C_bss_dnam(n,s,offs,i);
bss_dlb | arith:n label:l arith:offs int:i |
- FLUSHDFA();
C_bss_dlb(n,l,offs,i);
bss_ilb | arith:n label:l int:i |
- FLUSHDFA();
C_bss_ilb(n,l,i);
bss_pnam | arith:n char *:s int:i |
- FLUSHDFA();
C_bss_pnam(n,s,i);
hol_cst | arith:n arith:w int:i |
- FLUSHDFA();
C_hol_cst(n,w,i);
hol_icon | arith:n char *:s arith:sz int:i |
- FLUSHDFA();
C_hol_icon(n,s,sz,i);
hol_ucon | arith:n char *:s arith:sz int:i |
- FLUSHDFA();
C_hol_ucon(n,s,sz,i);
hol_fcon | arith:n char *:s arith:sz int:i |
- FLUSHDFA();
C_hol_fcon(n,s,sz,i);
hol_dnam | arith:n char *:s arith:offs int:i |
- FLUSHDFA();
C_hol_dnam(n,s,offs,i);
hol_dlb | arith:n label:l arith:offs int:i |
- FLUSHDFA();
C_hol_dlb(n,l,offs,i);
hol_ilb | arith:n label:l int:i |
- FLUSHDFA();
C_hol_ilb(n,l,i);
hol_pnam | arith:n char *:s int:i |
- FLUSHDFA();
C_hol_pnam(n,s,i);
con_cst | arith:l |
- FLUSHDFA();
C_con_cst(l);
con_icon | char *:val arith:siz |
- FLUSHDFA();
C_con_icon(val,siz);
con_ucon | char *:val arith:siz |
- FLUSHDFA();
C_con_ucon(val,siz);
con_fcon | char *:val arith:siz |
- FLUSHDFA();
C_con_fcon(val,siz);
con_scon | char *:str arith:siz |
- FLUSHDFA();
C_con_scon(str,siz);
con_dnam | char *:str arith:val |
- FLUSHDFA();
C_con_dnam(str,val);
con_dlb | label:l arith:val |
- FLUSHDFA();
C_con_dlb(l,val);
con_ilb | label:l |
- FLUSHDFA();
C_con_ilb(l);
con_pnam | char *:str |
- FLUSHDFA();
C_con_pnam(str);
rom_cst | arith:l |
- FLUSHDFA();
C_rom_cst(l);
rom_icon | char *:val arith:siz |
- FLUSHDFA();
C_rom_icon(val,siz);
rom_ucon | char *:val arith:siz |
- FLUSHDFA();
C_rom_ucon(val,siz);
rom_fcon | char *:val arith:siz |
- FLUSHDFA();
C_rom_fcon(val,siz);
rom_scon | char *:str arith:siz |
- FLUSHDFA();
C_rom_scon(str,siz);
rom_dnam | char *:str arith:val |
- FLUSHDFA();
C_rom_dnam(str,val);
rom_dlb | label:l arith:val |
- FLUSHDFA();
C_rom_dlb(l,val);
rom_ilb | label:l |
- FLUSHDFA();
C_rom_ilb(l);
rom_pnam | char *:str |
- FLUSHDFA();
C_rom_pnam(str);
cst | arith:l |
- FLUSHDFA();
C_cst(l);
icon | char *:val arith:siz |
- FLUSHDFA();
C_icon(val,siz);
ucon | char *:val arith:siz |
- FLUSHDFA();
C_ucon(val,siz);
fcon | char *:val arith:siz |
- FLUSHDFA();
C_fcon(val,siz);
scon | char *:str arith:siz |
- FLUSHDFA();
C_scon(str,siz);
dnam | char *:str arith:val |
- FLUSHDFA();
C_dnam(str,val);
dlb | label:l arith:val |
- FLUSHDFA();
C_dlb(l,val);
ilb | label:l |
- FLUSHDFA();
C_ilb(l);
pnam | char *:str |
- FLUSHDFA();
C_pnam(str);
mes_begin | int:ms |
- FLUSHDFA();
C_mes_begin(ms);
mes_end | |
- FLUSHDFA();
C_mes_end();
exc | arith:c1 arith:c2 |
- FLUSHDFA();
C_exc(c1,c2);
-insertpart | int:id |
- FLUSHDFA();
- C_insertpart(id);
-beginpart | int:id |
- FLUSHDFA();
- C_beginpart(id);
-endpart | int:id |
- FLUSHDFA();
- C_endpart(id);