1987-01-15 18:12:26 +00:00
|
|
|
#ifndef NORCSID
|
1987-07-07 16:31:16 +00:00
|
|
|
static char rcsidp5[] = "$Header$";
|
1987-01-15 18:12:26 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "parser.h"
|
|
|
|
#include "Lpars.h"
|
|
|
|
|
1987-07-07 16:31:16 +00:00
|
|
|
FILE *ofile;
|
1987-01-15 18:12:26 +00:00
|
|
|
|
|
|
|
outputnopt()
|
|
|
|
{
|
1987-07-09 09:02:41 +00:00
|
|
|
openofile("dfa.c");
|
1987-01-27 14:15:23 +00:00
|
|
|
outheaders();
|
|
|
|
outtables();
|
|
|
|
outdfa();
|
|
|
|
outdodefault();
|
1987-07-09 09:02:41 +00:00
|
|
|
installofile();
|
|
|
|
openofile("trans.h");
|
|
|
|
outtranshdr();
|
|
|
|
installofile();
|
|
|
|
openofile("trans.c");
|
1987-01-27 14:15:23 +00:00
|
|
|
outdotrans();
|
1987-07-09 09:02:41 +00:00
|
|
|
installofile();
|
|
|
|
openofile("incalls.r");
|
1987-01-15 18:12:26 +00:00
|
|
|
outputincalls();
|
1987-07-09 09:02:41 +00:00
|
|
|
installofile();
|
|
|
|
}
|
|
|
|
|
|
|
|
static char ofilename[80];
|
|
|
|
static char ofiletemp[80];
|
|
|
|
|
|
|
|
PRIVATE
|
|
|
|
openofile(filename)
|
|
|
|
char *filename;
|
|
|
|
{
|
1987-07-09 15:04:03 +00:00
|
|
|
char *strcpy(), *strcat();
|
1987-07-09 09:02:41 +00:00
|
|
|
strcpy(ofilename,filename);
|
|
|
|
strcpy(ofiletemp,filename);
|
|
|
|
strcat(ofiletemp,".new");
|
|
|
|
if((ofile=fopen(ofiletemp,"w"))==NULL) {
|
|
|
|
fprintf(stderr,"Fatal Error: cannot open output file %s\n",ofiletemp);
|
|
|
|
sys_stop(S_EXIT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRIVATE
|
|
|
|
installofile()
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* if contents of newly generated ofiletemp is different
|
|
|
|
* from that of ofilename then copy over old file else
|
|
|
|
* delete newly generated file
|
|
|
|
*/
|
|
|
|
register FILE *f1, *f2;
|
|
|
|
register int c1, c2;
|
|
|
|
fclose(ofile);
|
|
|
|
if((f1 = fopen(ofiletemp,"r")) == NULL) {
|
|
|
|
fprintf(stderr,"Fatal Error: cannont reopen file %s\n",ofiletemp);
|
|
|
|
sys_stop(S_EXIT);
|
|
|
|
}
|
|
|
|
if((f2 = fopen(ofilename,"r")) == NULL) {
|
|
|
|
fclose(f1);
|
|
|
|
RENAME(ofiletemp,ofilename);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
c1 = getc(f1);
|
|
|
|
c2 = getc(f2);
|
|
|
|
} while (c1 == c2 && c1 != EOF);
|
|
|
|
fclose(f1);
|
|
|
|
fclose(f2);
|
|
|
|
if (c1 != c2) {
|
|
|
|
RENAME(ofiletemp,ofilename);
|
|
|
|
}
|
|
|
|
else UNLINK(ofiletemp);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRIVATE
|
|
|
|
UNLINK(x)
|
|
|
|
char *x;
|
|
|
|
{
|
|
|
|
/* Must remove the file "x" */
|
|
|
|
unlink(x); /* systemcall to remove file */
|
|
|
|
}
|
|
|
|
|
|
|
|
PRIVATE
|
|
|
|
RENAME(x,y)
|
|
|
|
char *x, *y;
|
|
|
|
{
|
|
|
|
/* Must move the file "x" to the file "y" */
|
|
|
|
unlink(y);
|
|
|
|
if(link(x,y)!=0) {
|
|
|
|
fprintf(stderr,"Cannot link to %s",y);
|
|
|
|
sys_stop(S_EXIT);
|
|
|
|
}
|
|
|
|
unlink(x);
|
1987-01-15 18:12:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PRIVATE
|
1987-01-27 14:15:23 +00:00
|
|
|
outheaders()
|
1987-01-15 18:12:26 +00:00
|
|
|
{
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(ofile,"#include \"nopt.h\"\n");
|
1987-07-09 09:02:41 +00:00
|
|
|
fprintf(ofile,"#include \"trans.h\"\n");
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(ofile,"\n");
|
|
|
|
fprintf(ofile,"int OO_maxpattern = %d;\n", longestpattern);
|
|
|
|
fprintf(ofile,"\n");
|
1987-01-15 18:12:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PRIVATE
|
1987-01-27 14:15:23 +00:00
|
|
|
outtables()
|
1987-01-15 18:12:26 +00:00
|
|
|
{
|
|
|
|
int s;
|
1987-07-09 09:02:41 +00:00
|
|
|
int nout, ncpy, ngto;
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(ofile,"static struct defact {\n");
|
|
|
|
fprintf(ofile,"\tint numoutput;\n");
|
|
|
|
fprintf(ofile,"\tint numcopy;\n");
|
|
|
|
fprintf(ofile,"\tint nextstate;\n");
|
1987-07-09 09:02:41 +00:00
|
|
|
fprintf(ofile,"\tint (*transstate)();\n");
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(ofile,"} defaultactions[] = {\n");
|
1987-01-15 18:12:26 +00:00
|
|
|
for(s=0;s<=higheststate;s++) {
|
1987-07-09 09:02:41 +00:00
|
|
|
findfail(s,&nout,&ncpy,&ngto);
|
|
|
|
fprintf(ofile,"\t{%d, %d, %d, ",nout,ncpy,ngto);
|
|
|
|
if(actions[ngto]==NULL)
|
|
|
|
fprintf(ofile,"0");
|
|
|
|
else
|
|
|
|
fprintf(ofile,"OO_%ddotrans",ngto);
|
|
|
|
fprintf(ofile,"},\n");
|
1987-01-15 18:12:26 +00:00
|
|
|
}
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(ofile,"};\n");
|
|
|
|
fprintf(ofile,"\n");
|
1987-01-15 18:12:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PRIVATE
|
1987-01-27 14:15:23 +00:00
|
|
|
outdfa()
|
1987-01-15 18:12:26 +00:00
|
|
|
{
|
|
|
|
int s;
|
|
|
|
struct idf *op;
|
|
|
|
struct state *p;
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(ofile,"int OO_state = 0;\n");
|
|
|
|
fprintf(ofile,"\n");
|
|
|
|
fprintf(ofile,"OO_dfa(last) register int last; {\n");
|
|
|
|
fprintf(ofile,"\tfor(;;) {\n");
|
|
|
|
fprintf(ofile,"\t\tswitch(last) {\n");
|
1987-01-15 18:12:26 +00:00
|
|
|
for(op=ops;op!=(struct idf *)NULL;op=op->id_nextidf) {
|
|
|
|
if(!op->id_used)
|
|
|
|
continue;
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(ofile,"\t\tcase op_%s:\n",op->id_text);
|
|
|
|
fprintf(ofile,"\t\t\tswitch(OO_state) {\n");
|
1987-01-15 18:12:26 +00:00
|
|
|
if(!op->id_startpatt) {
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(ofile,"\t\t\tcase 0: ");
|
|
|
|
fprintf(ofile,"OO_out(*--OO_nxtpatt); ");
|
|
|
|
fprintf(ofile,"break;\n");
|
1987-01-15 18:12:26 +00:00
|
|
|
}
|
|
|
|
for(s=0;s<=higheststate;s++)
|
|
|
|
for(p=states[s];p!=(struct state *)NULL;p=p->next) {
|
|
|
|
if(p->op==op) {
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(ofile,"\t\t\tcase %d: ",s);
|
1987-01-15 18:12:26 +00:00
|
|
|
if(actions[p->goto_state]==(struct action *)NULL)
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(ofile,"OO_state = %d; ",p->goto_state);
|
1987-07-09 09:02:41 +00:00
|
|
|
else fprintf(ofile,"OO_%ddotrans(); ",p->goto_state);
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(ofile,"break;\n");
|
1987-01-15 18:12:26 +00:00
|
|
|
}
|
|
|
|
}
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(ofile,"\t\t\tdefault: dodefaultaction(); break;\n");
|
|
|
|
fprintf(ofile,"\t\t\t}\n");
|
|
|
|
fprintf(ofile,"\t\t\tbreak;\n");
|
1987-01-15 18:12:26 +00:00
|
|
|
}
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(ofile,"\t\tdefault:\n");
|
|
|
|
fprintf(ofile,"\t\t\tif(OO_state) dodefaultaction();\n");
|
|
|
|
fprintf(ofile,"\t\t\telse {\n");
|
|
|
|
fprintf(ofile,"\t\t\t\tOO_flush();\n");
|
|
|
|
fprintf(ofile,"\t\t\t\tEM_mkcalls(*--OO_nxtpatt);\n");
|
|
|
|
fprintf(ofile,"\t\t\t\tOO_free(*OO_nxtpatt);\n");
|
|
|
|
fprintf(ofile,"\t\t\t}\n");
|
|
|
|
fprintf(ofile,"\t\t\tbreak;\n");
|
|
|
|
fprintf(ofile,"\t\tcase OTHER:\n");
|
|
|
|
fprintf(ofile,"\t\t\tif(OO_state) dodefaultaction();\n");
|
|
|
|
fprintf(ofile,"\t\t\telse {\n");
|
|
|
|
fprintf(ofile,"\t\t\t\tOO_flush();\n");
|
|
|
|
fprintf(ofile,"\t\t\t\t--OO_nxtpatt;\n");
|
|
|
|
fprintf(ofile,"\t\t\t}\n");
|
|
|
|
fprintf(ofile,"\t\t\tbreak;\n");
|
|
|
|
fprintf(ofile,"\t\t}\n");
|
|
|
|
fprintf(ofile,"\t\tif (OO_nxtbackup==OO_bkupqueue)\n");
|
|
|
|
fprintf(ofile,"\t\t\treturn;\n");
|
|
|
|
fprintf(ofile,"\t\tlast = ((*OO_nxtpatt++ = *(--OO_nxtbackup))->em_opcode);\n");
|
|
|
|
fprintf(ofile,"\t}\n");
|
|
|
|
fprintf(ofile,"}\n");
|
1987-01-15 18:12:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PRIVATE
|
1987-01-27 14:15:23 +00:00
|
|
|
outmnems(l)
|
1987-01-15 18:12:26 +00:00
|
|
|
struct mnems l;
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for(i=1;i<=l.m_len;i++)
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(ofile,"%s ",l.m_elems[i-1]->op_code->id_text);
|
1987-01-15 18:12:26 +00:00
|
|
|
}
|
|
|
|
|
1987-07-09 09:02:41 +00:00
|
|
|
PRIVATE
|
|
|
|
outtranshdr()
|
|
|
|
{
|
|
|
|
register int s;
|
|
|
|
for(s=0;s<=higheststate;s++) {
|
|
|
|
if(actions[s]!=NULL)
|
|
|
|
fprintf(ofile,"extern OO_%ddotrans();\n",s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1987-01-15 18:12:26 +00:00
|
|
|
PRIVATE
|
1987-01-27 14:15:23 +00:00
|
|
|
outdotrans()
|
1987-01-15 18:12:26 +00:00
|
|
|
{
|
|
|
|
int s;
|
|
|
|
struct action *a;
|
|
|
|
int seennontested;
|
1987-07-09 15:04:03 +00:00
|
|
|
int seentested;
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(ofile,"#include \"nopt.h\"\n\n");
|
1987-07-09 09:02:41 +00:00
|
|
|
for(s=0;s<=higheststate;s++) {
|
1987-01-15 18:12:26 +00:00
|
|
|
if(actions[s]!=(struct action *)NULL) {
|
1987-07-09 09:02:41 +00:00
|
|
|
fprintf(ofile,"\nOO_%ddotrans() {\n",s);
|
1987-07-09 15:04:03 +00:00
|
|
|
fprintf(ofile,"\tregister p_instr *patt = OO_patternqueue;\n");
|
1987-07-09 09:02:41 +00:00
|
|
|
fprintf(ofile,"\t/* ");
|
1987-01-27 14:15:23 +00:00
|
|
|
outmnems(patterns[s]);
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(ofile," */\n");
|
1987-07-09 15:04:03 +00:00
|
|
|
seentested = seennontested=0;
|
1987-01-15 18:12:26 +00:00
|
|
|
for(a=actions[s];a!=(struct action *)NULL;a=a->next) {
|
|
|
|
if(a->test!=(struct exp_node *)NULL) {
|
1987-07-09 15:04:03 +00:00
|
|
|
seentested++;
|
1987-07-09 09:02:41 +00:00
|
|
|
fprintf(ofile,"\tif(");
|
1987-01-27 14:15:23 +00:00
|
|
|
outexp(a->test,s);
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(ofile,") {\n");
|
1987-01-27 14:15:23 +00:00
|
|
|
outoneaction(s,a);
|
1987-07-09 09:02:41 +00:00
|
|
|
fprintf(ofile,"\t\tgoto free;\n\t}\n");
|
1987-01-15 18:12:26 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(seennontested) {
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(stderr,"parser: more than one untested action on state %d\n",s);
|
1987-01-15 18:12:26 +00:00
|
|
|
nerrors++;
|
|
|
|
}
|
|
|
|
seennontested++;
|
1987-01-27 14:15:23 +00:00
|
|
|
outoneaction(s,a);
|
1987-01-15 18:12:26 +00:00
|
|
|
}
|
|
|
|
}
|
1987-07-09 09:02:41 +00:00
|
|
|
if(!seennontested) {
|
|
|
|
fprintf(ofile,"\tOO_state=%d;\n",s);
|
|
|
|
fprintf(ofile,"\treturn;\n");
|
|
|
|
}
|
1987-07-09 15:04:03 +00:00
|
|
|
if(seentested) fprintf(ofile,"free:");
|
|
|
|
fprintf(ofile,"\tOO_nfree(%d);\n",patterns[s].m_len);
|
1987-07-09 09:02:41 +00:00
|
|
|
fprintf(ofile,"}\n");
|
1987-01-15 18:12:26 +00:00
|
|
|
}
|
1987-07-09 09:02:41 +00:00
|
|
|
/*
|
|
|
|
* else fprintf(ofile,"\nOO_%ddotrans() {\n\tOO_state=%d;\n}\n",s,s);
|
|
|
|
*/
|
|
|
|
}
|
1987-01-15 18:12:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PRIVATE
|
1987-01-27 14:15:23 +00:00
|
|
|
outdodefault()
|
1987-01-15 18:12:26 +00:00
|
|
|
{
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(ofile,"\nstatic dodefaultaction() {\n");
|
|
|
|
fprintf(ofile,"\tregister struct defact *p = &defaultactions[OO_state];\n");
|
|
|
|
fprintf(ofile,"\tOO_pushback(*--OO_nxtpatt);\n");
|
|
|
|
fprintf(ofile,"\tOO_dodefault(p->numoutput,p->numcopy);\n");
|
1987-07-09 09:02:41 +00:00
|
|
|
fprintf(ofile,"\tOO_state=p->nextstate;\n");
|
|
|
|
fprintf(ofile,"\tif(p->transstate) (*(p->transstate))();\n");
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(ofile,"}\n");
|
1987-01-15 18:12:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PRIVATE
|
1987-01-27 14:15:23 +00:00
|
|
|
outoneaction(s,a)
|
1987-01-15 18:12:26 +00:00
|
|
|
int s;
|
|
|
|
struct action *a;
|
|
|
|
{
|
1987-07-09 09:02:41 +00:00
|
|
|
fprintf(ofile,"\t\t/* -> ");
|
1987-01-27 14:15:23 +00:00
|
|
|
outmnems(a->replacement);
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(ofile," */\n");
|
|
|
|
fprintf(ofile,"#ifdef STATS\n");
|
1987-07-09 09:02:41 +00:00
|
|
|
fprintf(ofile,"\t\tif(OO_wrstats) fprintf(stderr,\"%d\\n\");\n",a->linenum);
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(ofile,"#endif\n");
|
1987-07-09 15:04:03 +00:00
|
|
|
outrepl(s,a->replacement);
|
1987-01-21 14:27:04 +00:00
|
|
|
findworst(a->replacement);
|
1987-01-15 18:12:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PRIVATE
|
1987-07-09 15:04:03 +00:00
|
|
|
outrepl(state,repl)
|
1987-01-15 18:12:26 +00:00
|
|
|
int state;
|
1987-07-09 15:04:03 +00:00
|
|
|
struct mnems repl;
|
1987-01-15 18:12:26 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
/* Contruct <repl>=r1 r2 ... rn and put on output queue.
|
|
|
|
*/
|
|
|
|
int n = repl.m_len;
|
1987-07-09 15:04:03 +00:00
|
|
|
int i;
|
1987-01-15 18:12:26 +00:00
|
|
|
for(i=1;i<=n;i++) {
|
|
|
|
struct mnem_elem *ri = repl.m_elems[i-1];
|
|
|
|
char *mnem = ri->op_code->id_text;
|
|
|
|
switch(ri->op_code->id_argfmt) {
|
|
|
|
case NOARG:
|
1987-07-09 09:02:41 +00:00
|
|
|
fprintf(ofile,"\t\tOO_outop(op_%s);\n",mnem);
|
1987-01-15 18:12:26 +00:00
|
|
|
break;
|
|
|
|
case CST:
|
|
|
|
case CSTOPT:
|
1987-07-09 09:02:41 +00:00
|
|
|
fprintf(ofile,"\t\tOO_outcst(op_%s,",mnem);
|
1987-07-09 15:04:03 +00:00
|
|
|
fprintf(ofile,"(arith)");
|
1987-01-27 14:15:23 +00:00
|
|
|
outexp(ri->arg,state);
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(ofile,");\n");
|
1987-01-15 18:12:26 +00:00
|
|
|
break;
|
|
|
|
case LAB:
|
1987-07-09 09:02:41 +00:00
|
|
|
fprintf(ofile,"\t\tOO_outlab(op_%s,",mnem);
|
1987-01-27 14:15:23 +00:00
|
|
|
outexp(ri->arg,state);
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(ofile,");\n");
|
1987-01-15 18:12:26 +00:00
|
|
|
break;
|
|
|
|
case DEFILB:
|
1987-07-09 09:02:41 +00:00
|
|
|
fprintf(ofile,"\t\tOO_outdefilb(op_%s,",mnem);
|
1987-01-27 14:15:23 +00:00
|
|
|
outexp(ri->arg,state);
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(ofile,");\n");
|
1987-01-15 18:12:26 +00:00
|
|
|
break;
|
|
|
|
case PNAM:
|
1987-07-09 09:02:41 +00:00
|
|
|
fprintf(ofile,"\t\tOO_outpnam(op_%s,",mnem);
|
1987-01-27 14:15:23 +00:00
|
|
|
outexp(ri->arg,state);
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(ofile,");\n");
|
1987-01-15 18:12:26 +00:00
|
|
|
break;
|
|
|
|
case EXT:
|
1987-07-09 09:02:41 +00:00
|
|
|
fprintf(ofile,"\t\tOO_outext(op_%s,",mnem);
|
1987-01-27 14:15:23 +00:00
|
|
|
outexp(ri->arg,state);
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(ofile,");\n");
|
1987-01-15 18:12:26 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRIVATE
|
1987-01-27 14:15:23 +00:00
|
|
|
outexp(e,state)
|
1987-01-15 18:12:26 +00:00
|
|
|
struct exp_node *e;
|
|
|
|
int state;
|
|
|
|
{
|
|
|
|
switch(e->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:
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(ofile,"(");
|
1987-01-27 14:15:23 +00:00
|
|
|
outexp(e->exp_left,state);
|
|
|
|
outop(e->node_type);
|
|
|
|
outexp(e->exp_right,state);
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(ofile,")");
|
1987-01-15 18:12:26 +00:00
|
|
|
break;
|
|
|
|
case NOT:
|
|
|
|
case COMP:
|
|
|
|
case UPLUS:
|
|
|
|
case UMINUS:
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(ofile,"(");
|
1987-01-27 14:15:23 +00:00
|
|
|
outop(e->node_type);
|
|
|
|
outexp(e->exp_left,state);
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(ofile,")");
|
1987-01-15 18:12:26 +00:00
|
|
|
break;
|
|
|
|
case DEFINED:
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(ofile,"(patt[%d]->em_argtype)",e->leaf_val-1);
|
1987-01-15 18:12:26 +00:00
|
|
|
break;
|
|
|
|
case UNDEFINED:
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(ofile,"(patt[%d]->em_argtype==0)",e->leaf_val-1);
|
1987-01-15 18:12:26 +00:00
|
|
|
break;
|
|
|
|
case COMMA:
|
|
|
|
outext(e->exp_left);
|
1987-07-09 15:04:03 +00:00
|
|
|
fprintf(ofile,",");
|
|
|
|
fprintf(ofile,"(arith)");
|
|
|
|
outexp(e->exp_right,state);
|
1987-01-15 18:12:26 +00:00
|
|
|
break;
|
|
|
|
case SAMESIGN:
|
|
|
|
case SFIT:
|
|
|
|
case UFIT:
|
|
|
|
case ROTATE:
|
1987-01-27 14:15:23 +00:00
|
|
|
outop(e->node_type);
|
1987-07-09 15:04:03 +00:00
|
|
|
fprintf(ofile,"(arith)");
|
1987-01-27 14:15:23 +00:00
|
|
|
outexp(e->exp_left,state);
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(ofile,",");
|
1987-07-09 15:04:03 +00:00
|
|
|
fprintf(ofile,"(arith)");
|
1987-01-27 14:15:23 +00:00
|
|
|
outexp(e->exp_right,state);
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(ofile,")");
|
1987-01-15 18:12:26 +00:00
|
|
|
break;
|
|
|
|
case SAMEEXT:
|
|
|
|
case SAMENAM:
|
1987-01-27 14:15:23 +00:00
|
|
|
outop(e->node_type);
|
1987-01-15 18:12:26 +00:00
|
|
|
outext(e->exp_left);
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(ofile,",");
|
1987-07-09 15:04:03 +00:00
|
|
|
outext(e->exp_right);
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(ofile,")");
|
1987-01-15 18:12:26 +00:00
|
|
|
break;
|
|
|
|
case PATARG:
|
|
|
|
switch(patterns[state].m_elems[e->leaf_val-1]->op_code->id_argfmt) {
|
|
|
|
case NOARG:
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(stderr,"error: mnem %d has no argument\n",e->leaf_val);
|
1987-01-15 18:12:26 +00:00
|
|
|
nerrors++;
|
|
|
|
break;
|
|
|
|
case CST:
|
|
|
|
case CSTOPT:
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(ofile,"CST(patt[%d])",e->leaf_val-1);
|
1987-01-15 18:12:26 +00:00
|
|
|
break;
|
|
|
|
case LAB:
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(ofile,"LAB(patt[%d])",e->leaf_val-1);
|
1987-01-15 18:12:26 +00:00
|
|
|
break;
|
|
|
|
case DEFILB:
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(ofile,"DEFILB(patt[%d])",e->leaf_val-1);
|
1987-01-15 18:12:26 +00:00
|
|
|
break;
|
|
|
|
case PNAM:
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(ofile,"PNAM(patt[%d])",e->leaf_val-1);
|
1987-01-15 18:12:26 +00:00
|
|
|
break;
|
|
|
|
case EXT:
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(ofile,"OO_offset(patt[%d])",e->leaf_val-1);
|
1987-01-15 18:12:26 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PSIZE:
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(ofile,"OO_PSIZE"); break;
|
1987-01-15 18:12:26 +00:00
|
|
|
case WSIZE:
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(ofile,"OO_WSIZE"); break;
|
1987-01-15 18:12:26 +00:00
|
|
|
case INT:
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(ofile,"%d",e->leaf_val); break;
|
1987-01-15 18:12:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRIVATE
|
|
|
|
outext(e)
|
|
|
|
struct exp_node *e;
|
|
|
|
{
|
|
|
|
if(e->node_type!=PATARG) {
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(stderr,"Internal error in outext of parser\n");
|
1987-01-15 18:12:26 +00:00
|
|
|
nerrors++;
|
|
|
|
}
|
1987-07-07 16:31:16 +00:00
|
|
|
fprintf(ofile,"patt[%d]",e->leaf_val-1);
|
1987-01-15 18:12:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PRIVATE
|
1987-01-27 14:15:23 +00:00
|
|
|
outop(op)
|
1987-01-15 18:12:26 +00:00
|
|
|
int op;
|
|
|
|
{
|
|
|
|
switch(op) {
|
1987-07-07 16:31:16 +00:00
|
|
|
case LOGAND: fprintf(ofile,"&&"); break;
|
|
|
|
case LOGOR: fprintf(ofile,"||"); break;
|
|
|
|
case BITAND: fprintf(ofile,"&"); break;
|
|
|
|
case BITOR: fprintf(ofile,"|"); break;
|
|
|
|
case XOR: fprintf(ofile,"^"); break;
|
|
|
|
case MINUS: fprintf(ofile,"-"); break;
|
|
|
|
case PLUS: fprintf(ofile,"+"); break;
|
|
|
|
case TIMES: fprintf(ofile,"*"); break;
|
|
|
|
case DIV: fprintf(ofile,"/"); break;
|
|
|
|
case MOD: fprintf(ofile,"%%"); break;
|
|
|
|
case EQ: fprintf(ofile,"=="); break;
|
|
|
|
case NE: fprintf(ofile,"!="); break;
|
|
|
|
case LT: fprintf(ofile,"<"); break;
|
|
|
|
case LE: fprintf(ofile,"<="); break;
|
|
|
|
case GT: fprintf(ofile,">"); break;
|
|
|
|
case GE: fprintf(ofile,">="); break;
|
|
|
|
case LSHIFT: fprintf(ofile,"<<"); break;
|
|
|
|
case RSHIFT: fprintf(ofile,">>"); break;
|
|
|
|
case NOT: fprintf(ofile,"!"); break;
|
|
|
|
case COMP: fprintf(ofile,"~"); break;
|
|
|
|
case UPLUS: fprintf(ofile,"+"); break;
|
|
|
|
case UMINUS: fprintf(ofile,"-"); break;
|
|
|
|
case SAMESIGN: fprintf(ofile,"OO_signsame("); break;
|
|
|
|
case SFIT: fprintf(ofile,"OO_sfit("); break;
|
|
|
|
case UFIT: fprintf(ofile,"OO_ufit("); break;
|
|
|
|
case ROTATE: fprintf(ofile,"OO_rotate("); break;
|
|
|
|
case SAMEEXT: fprintf(ofile,"OO_extsame("); break;
|
|
|
|
case SAMENAM: fprintf(ofile,"OO_namsame("); break;
|
1987-01-15 18:12:26 +00:00
|
|
|
}
|
|
|
|
}
|