2 static char rcsid[] = "$Id: gencode.c,v 2.5 1994/06/24 13:23:42 ceriel Exp $";
10 #include <cg_pattern.h>
16 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
17 * See the copyright notice in the ACK home directory, in the file "Copyright".
19 * Author: Hans van Staveren
23 extern FILE *freopen();
25 out_init(filename) char *filename; {
28 static char stderrbuff[BUFSIZ];
33 setbuf(stderr,stderrbuff);
36 if (filename == (char *) 0)
39 if ((codefile=freopen(filename,"w",stdout))==NULL)
40 error("Can't create %s",filename);
59 error("Write error on output");
62 gencode(code) register char *code; {
64 int tokno,fldno,insno,regno,subno;
68 while ((c= *code++)!=0) switch(c) {
74 tp = &fakestack[stackheight-tokno];
76 fprintf(codefile,"%s",codestrings[machregs[tp->t_att[0].ar].r_repr]);
83 tp = &fakestack[stackheight-tokno];
84 assert(tp->t_token != -1);
85 switch(tokens[tp->t_token].t_type[fldno-1]) {
89 fprintf(codefile,WRD_FMT,tp->t_att[fldno-1].aw);
92 fprintf(codefile,"%s",tp->t_att[fldno-1].as);
95 assert(tp->t_att[fldno-1].ar>0 && tp->t_att[fldno-1].ar<NREGS);
96 fprintf(codefile,"%s",codestrings[machregs[tp->t_att[fldno-1].ar].r_repr]);
102 fprintf(codefile,WRD_FMT,dollar[insno-1].e_v.e_con);
106 fprintf(codefile,"%s",dollar[insno-1].e_v.e_str);
110 subno = (*code++)&0377;
111 assert(regno>=1 && regno<=nallreg);
112 regno = allreg[regno-1];
115 assert(subno>=1 && subno<=MAXMEMBERS);
116 regno = machregs[regno].r_members[subno-1];
120 fprintf(codefile,"%s",codestrings[machregs[regno].r_repr]);
126 tp = &fakestack[stackheight-tokno];
127 assert(tp->t_token == -1);
128 fprintf(codefile,"%s",codestrings[machregs[machregs[tp->t_att[0].ar].r_members[subno-1]].r_repr]);
137 result= compute(&enodes[nodeno]);
138 switch(result.e_typ) {
139 default: assert(FALSE);
141 fprintf(codefile,WRD_FMT,result.e_v.e_con);
144 fprintf(codefile,"%s", codestrings[machregs[result.e_v.e_reg].r_repr]);
147 fprintf(codefile,"%s",result.e_v.e_str);
153 fputc('\n',codefile);
156 prtoken(tp) token_p tp; {
159 register tkdef_p tdp;
161 tdp = &tokens[tp->t_token];
162 assert(tdp->t_format != -1);
163 code = codestrings[tdp->t_format];
164 while ((c = *code++) != 0) {
165 if (c>=' ' && c<='~')
168 assert(c>0 && c<=TOKENSIZE);
169 switch(tdp->t_type[c-1]) {
173 fprintf(codefile,WRD_FMT,tp->t_att[c-1].aw);
176 fprintf(codefile,"%s",tp->t_att[c-1].as);
179 fprintf(codefile,"%s",codestrings[machregs[tp->t_att[c-1].ar].r_repr]);