1985-01-08 15:34:54 +00:00
|
|
|
#ifndef NORCSID
|
1994-06-24 14:02:31 +00:00
|
|
|
static char rcsid[] = "$Id$";
|
1985-01-08 15:34:54 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "assert.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "param.h"
|
|
|
|
#include "tables.h"
|
|
|
|
#include "types.h"
|
|
|
|
#include <cgg_cg.h>
|
|
|
|
#include "data.h"
|
|
|
|
#include "result.h"
|
|
|
|
#include "extern.h"
|
1990-09-04 17:16:00 +00:00
|
|
|
#ifdef USE_TES
|
1990-07-18 14:53:19 +00:00
|
|
|
#include "mach.h"
|
|
|
|
#endif
|
1985-01-08 15:34:54 +00:00
|
|
|
|
|
|
|
/*
|
1987-03-10 01:26:51 +00:00
|
|
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
|
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
1985-01-08 15:34:54 +00:00
|
|
|
*
|
|
|
|
* Author: Hans van Staveren
|
|
|
|
*/
|
|
|
|
|
|
|
|
string mystrcpy();
|
|
|
|
|
|
|
|
FILE *codefile;
|
1987-09-01 15:24:15 +00:00
|
|
|
extern FILE *freopen();
|
1985-01-08 15:34:54 +00:00
|
|
|
|
|
|
|
out_init(filename) char *filename; {
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
static char stderrbuff[BUFSIZ];
|
|
|
|
|
|
|
|
if (Debug) {
|
|
|
|
codefile = stderr;
|
|
|
|
if (!isatty(2))
|
|
|
|
setbuf(stderr,stderrbuff);
|
|
|
|
} else {
|
|
|
|
#endif
|
|
|
|
if (filename == (char *) 0)
|
|
|
|
codefile = stdout;
|
|
|
|
else
|
|
|
|
if ((codefile=freopen(filename,"w",stdout))==NULL)
|
|
|
|
error("Can't create %s",filename);
|
|
|
|
#ifndef NDEBUG
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
out_finish() {
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
if (Debug)
|
|
|
|
fflush(stderr);
|
|
|
|
else
|
|
|
|
#endif
|
1988-04-14 16:09:02 +00:00
|
|
|
if (codefile) fclose(codefile);
|
1985-01-08 15:34:54 +00:00
|
|
|
#ifdef TABLEDEBUG
|
|
|
|
termlset();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
tstoutput() {
|
|
|
|
|
|
|
|
if (ferror(codefile))
|
|
|
|
error("Write error on output");
|
|
|
|
}
|
|
|
|
|
|
|
|
genstr(stringno) {
|
|
|
|
|
|
|
|
fputs(codestrings[stringno],codefile);
|
|
|
|
}
|
|
|
|
|
|
|
|
string ad2str(ad) addr_t ad; {
|
|
|
|
static char buf[100];
|
|
|
|
|
|
|
|
if (ad.ea_str==0)
|
|
|
|
ad.ea_str="";
|
1986-10-09 16:15:00 +00:00
|
|
|
if ((long)ad.ea_off==(long)0) {
|
1986-10-24 16:58:46 +00:00
|
|
|
if(ad.ea_str[0]==0)
|
1986-10-09 16:15:00 +00:00
|
|
|
return(mystrcpy("0")); /* don't return empty string */
|
|
|
|
else
|
|
|
|
return(mystrcpy(ad.ea_str));
|
|
|
|
}
|
1987-01-28 13:00:33 +00:00
|
|
|
sprintf(buf,"%s%c%ld",ad.ea_str,ad.ea_off>=0 ? '+' : ' ',(long)ad.ea_off);
|
1985-01-08 15:34:54 +00:00
|
|
|
return(mystrcpy(buf));
|
|
|
|
}
|
|
|
|
|
|
|
|
praddr(ad) addr_t ad; {
|
|
|
|
|
1987-01-16 13:51:45 +00:00
|
|
|
if (ad.ea_str==0 || *(ad.ea_str) == '\0')
|
1985-01-08 15:34:54 +00:00
|
|
|
fprintf(codefile,WRD_FMT,ad.ea_off);
|
|
|
|
else {
|
1987-09-01 15:24:15 +00:00
|
|
|
fputs(ad.ea_str, codefile);
|
1987-01-16 13:51:45 +00:00
|
|
|
if (ad.ea_off<0) {
|
1987-09-01 15:24:15 +00:00
|
|
|
putc('-', codefile);
|
1987-01-16 13:51:45 +00:00
|
|
|
fprintf(codefile,WRD_FMT,-ad.ea_off);
|
|
|
|
}
|
1985-01-08 15:34:54 +00:00
|
|
|
else if(ad.ea_off>0) {
|
1987-09-01 15:24:15 +00:00
|
|
|
putc('+',codefile);
|
1985-01-08 15:34:54 +00:00
|
|
|
fprintf(codefile,WRD_FMT,ad.ea_off);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gennl() {
|
1987-09-01 15:24:15 +00:00
|
|
|
putc('\n',codefile);
|
1985-01-08 15:34:54 +00:00
|
|
|
}
|
|
|
|
|
2016-11-10 21:04:18 +00:00
|
|
|
void
|
1985-01-08 15:34:54 +00:00
|
|
|
prtoken(tp,leadingchar) token_p tp; {
|
|
|
|
register c;
|
|
|
|
register char *code;
|
|
|
|
register tkdef_p tdp;
|
|
|
|
|
1987-09-01 15:24:15 +00:00
|
|
|
putc(leadingchar,codefile);
|
1985-01-08 15:34:54 +00:00
|
|
|
if (tp->t_token == -1) {
|
1987-09-01 15:24:15 +00:00
|
|
|
fputs(codestrings[machregs[tp->t_att[0].ar].r_repr],codefile);
|
1985-01-08 15:34:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
tdp = &tokens[tp->t_token];
|
|
|
|
assert(tdp->t_format != -1);
|
|
|
|
code = codestrings[tdp->t_format];
|
|
|
|
while ((c = *code++) != 0) {
|
|
|
|
if (c>=' ' && c<='~')
|
1987-09-01 15:24:15 +00:00
|
|
|
putc(c,codefile);
|
1985-01-08 15:34:54 +00:00
|
|
|
else {
|
|
|
|
assert(c>0 && c<=TOKENSIZE);
|
|
|
|
switch(tdp->t_type[c-1]) {
|
|
|
|
default:
|
|
|
|
assert(FALSE);
|
|
|
|
case EV_INT:
|
|
|
|
fprintf(codefile,WRD_FMT,tp->t_att[c-1].aw);
|
|
|
|
break;
|
|
|
|
case EV_ADDR:
|
|
|
|
praddr(tp->t_att[c-1].aa);
|
|
|
|
break;
|
|
|
|
case EV_REG:
|
1987-09-01 15:24:15 +00:00
|
|
|
fputs(codestrings[machregs[tp->t_att[c-1].ar].r_repr],codefile);
|
1985-01-08 15:34:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1990-07-18 14:53:19 +00:00
|
|
|
|
1990-09-04 17:16:00 +00:00
|
|
|
#ifdef USE_TES
|
1990-07-18 14:53:19 +00:00
|
|
|
printlabel(labnum)
|
|
|
|
int labnum;
|
|
|
|
{
|
|
|
|
newilb(dollar[labnum].e_v.e_addr.ea_str);
|
|
|
|
}
|
|
|
|
#endif
|