2 static char rcsid[] = "$Id: gencode.c,v 0.16 1994/06/24 13:27:25 ceriel Exp $";
19 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
20 * See the copyright notice in the ACK home directory, in the file "Copyright".
22 * Author: Hans van Staveren
28 extern FILE *freopen();
30 out_init(filename) char *filename; {
33 static char stderrbuff[BUFSIZ];
38 setbuf(stderr,stderrbuff);
41 if (filename == (char *) 0)
44 if ((codefile=freopen(filename,"w",stdout))==NULL)
45 error("Can't create %s",filename);
58 if (codefile) fclose(codefile);
67 error("Write error on output");
72 fputs(codestrings[stringno],codefile);
75 string ad2str(ad) addr_t ad; {
80 if ((long)ad.ea_off==(long)0) {
82 return(mystrcpy("0")); /* don't return empty string */
84 return(mystrcpy(ad.ea_str));
86 sprintf(buf,"%s%c%ld",ad.ea_str,ad.ea_off>=0 ? '+' : ' ',(long)ad.ea_off);
87 return(mystrcpy(buf));
90 praddr(ad) addr_t ad; {
92 if (ad.ea_str==0 || *(ad.ea_str) == '\0')
93 fprintf(codefile,WRD_FMT,ad.ea_off);
95 fputs(ad.ea_str, codefile);
98 fprintf(codefile,WRD_FMT,-ad.ea_off);
100 else if(ad.ea_off>0) {
102 fprintf(codefile,WRD_FMT,ad.ea_off);
111 prtoken(tp,leadingchar) token_p tp; {
114 register tkdef_p tdp;
116 putc(leadingchar,codefile);
117 if (tp->t_token == -1) {
118 fputs(codestrings[machregs[tp->t_att[0].ar].r_repr],codefile);
121 tdp = &tokens[tp->t_token];
122 assert(tdp->t_format != -1);
123 code = codestrings[tdp->t_format];
124 while ((c = *code++) != 0) {
125 if (c>=' ' && c<='~')
128 assert(c>0 && c<=TOKENSIZE);
129 switch(tdp->t_type[c-1]) {
133 fprintf(codefile,WRD_FMT,tp->t_att[c-1].aw);
136 praddr(tp->t_att[c-1].aa);
139 fputs(codestrings[machregs[tp->t_att[c-1].ar].r_repr],codefile);
150 newilb(dollar[labnum].e_v.e_addr.ea_str);