all external names start with C_, output buffered

This commit is contained in:
ceriel 1987-06-30 16:09:18 +00:00
parent 329cc47ca6
commit 19ffd2c1f2
2 changed files with 106 additions and 61 deletions

View file

@ -10,8 +10,8 @@
/* /*
putbyte(), C_open() and C_close() are the basic routines for putbyte(), C_open() and C_close() are the basic routines for
respectively write on, open and close the output file. respectively write on, open and close the outpt file.
The put_*() functions serve as formatting functions of the The C_pt_*() functions serve as formatting functions of the
various EM language constructs. various EM language constructs.
See "Description of a Machine Architecture for use with See "Description of a Machine Architecture for use with
Block Structured Languages" par. 11.2 for the meaning of these Block Structured Languages" par. 11.2 for the meaning of these
@ -19,17 +19,36 @@
*/ */
static File *ofp = 0; static File *ofp = 0;
static char obuf[BUFSIZ];
static char *opp = obuf;
static
flush() {
if (sys_write(ofp, &obuf[0], opp - &obuf[0]) == 0) {
C_failed();
}
opp = &obuf[0];
}
#define Xputbyte(c) if (opp == &obuf[BUFSIZ]) flush(); *opp++ = (c)
static
C_putbyte(b)
int b;
{
Xputbyte(b);
}
C_init(w, p) C_init(w, p)
arith w, p; arith w, p;
{ {
} }
C_open(nm) /* open file for readable code output */ C_open(nm) /* open file for readable code outpt */
char *nm; char *nm;
{ {
if (nm == 0) if (nm == 0)
ofp = STDOUT; /* standard output */ ofp = STDOUT; /* standard outpt */
else else
if (sys_open(nm, OP_WRITE, &ofp) == 0) if (sys_open(nm, OP_WRITE, &ofp) == 0)
return 0; return 0;
@ -38,6 +57,7 @@ C_open(nm) /* open file for readable code output */
C_close() C_close()
{ {
if (opp != obuf) flush();
if (ofp != STDOUT) if (ofp != STDOUT)
sys_close(ofp); sys_close(ofp);
ofp = 0; ofp = 0;
@ -52,29 +72,49 @@ C_magic()
{ {
} }
/*** the readable code generating routines ***/ /*** the readable code generating routines ***/
put_ilb(l) static char buf[512];
static
wrs(s)
register char *s;
{
while (*s) C_putbyte(*s++);
}
C_pt_dnam(s)
char *s;
{
wrs(s);
}
C_pt_ilb(l)
label l; label l;
{ {
_prnt("*%ld", (long) l); sprint(buf, "*%ld", (long) l);
wrs(buf);
} }
extern char em_mnem[][4]; extern char em_mnem[][4];
extern char em_pseu[][4]; extern char em_pseu[][4];
put_op(x) C_pt_op(x)
{ {
_prnt(" %s ", em_mnem[x - sp_fmnem]); C_putbyte(' ');
wrs(em_mnem[x - sp_fmnem]);
C_putbyte(' ');
} }
put_cst(l) C_pt_cst(l)
arith l; arith l;
{ {
_prnt("%ld", (long) l); sprint(buf, "%ld", (long) l);
wrs(buf);
} }
put_scon(x, y) C_pt_scon(x, y)
char *x; char *x;
arith y; arith y;
{ {
@ -83,71 +123,76 @@ put_scon(x, y)
register char *p, *q = &sbuf[0]; register char *p, *q = &sbuf[0];
char *bts2str(); char *bts2str();
C_putbyte('\'');
p = bts2str(x, (int) y, buf); p = bts2str(x, (int) y, buf);
while (*p) { while (*p) {
if (*p == '\'') if (*p == '\'')
*q++ = '\\'; C_putbyte('\\');
*q++ = *p++; C_putbyte(*p++);
} }
*q = '\0'; C_putbyte('\'');
_prnt("'%s'", sbuf);
} }
put_ps(x) C_pt_ps(x)
{ {
_prnt(" %s ", em_pseu[x - sp_fpseu]); C_putbyte(' ');
wrs(em_pseu[x - sp_fpseu]);
C_putbyte(' ');
} }
put_dlb(l) C_pt_dlb(l)
label l; label l;
{ {
_prnt(".%ld", (long) l); sprint(buf, ".%ld", (long) l);
wrs(buf);
} }
put_doff(l, v) C_pt_doff(l, v)
label l; label l;
arith v; arith v;
{ {
if (v == 0) put_dlb(l); C_pt_dlb(l);
else _prnt(".%ld+%ld", (long) l, (long) v); if (v != 0) {
sprint(buf,"+%ld", (long) v);
wrs(buf);
}
} }
put_noff(s, v) C_pt_noff(s, v)
char *s; char *s;
arith v; arith v;
{ {
if (v == 0) _prnt(s); wrs(s);
else _prnt("%s+%ld", s, (long) v); if (v != 0) {
sprint(buf,"+%ld", (long) v);
wrs(buf);
}
} }
put_pnam(s) C_pt_pnam(s)
char *s; char *s;
{ {
_prnt("$%s", s); C_putbyte('$');
wrs(s);
} }
put_dfilb(l) C_pt_dfilb(l)
label l; label l;
{ {
_prnt("%ld", (long) l); sprint(buf, "%ld", (long) l);
wrs(buf);
} }
put_wcon(sp, v, sz) /* sp_icon, sp_ucon or sp_fcon with int repr */ C_pt_wcon(sp, v, sz) /* sp_icon, sp_ucon or sp_fcon with int repr */
int sp; int sp;
char *v; char *v;
arith sz; arith sz;
{ {
_prnt("%s%c%ld", v, sp == sp_icon ? 'I' : sp == sp_ucon ? 'U' : 'F', wrs(v);
(long) sz); C_putbyte(sp == sp_icon ? 'I' : sp == sp_ucon ? 'U' : 'F');
C_pt_cst(sz);
} }
_prnt(fmt, args) C_pt_nl() { C_putbyte('\n'); }
char *fmt; C_pt_comma() { C_putbyte(','); }
int args; C_pt_ccend() { wrs(" ?"); }
{
doprnt(ofp, fmt, (int *)&args);
}
put_nl() { _prnt("\n"); }
put_comma() { _prnt(","); }
put_ccend() { _prnt(" ?"); }

View file

@ -16,23 +16,23 @@
#include <em_reg.h> #include <em_reg.h>
/* macros used in the definitions of the interface functions C_* */ /* macros used in the definitions of the interface functions C_* */
#define OP(x) put_op(x) #define OP(x) C_pt_op(x)
#define CST(x) put_cst(x) #define CST(x) C_pt_cst(x)
#define DCST(x) put_cst(x) #define DCST(x) C_pt_cst(x)
#define SCON(x,y) put_scon((x), (y)) #define SCON(x,y) C_pt_scon((x), (y))
#define PS(x) put_ps(x) #define PS(x) C_pt_ps(x)
#define DLB(x) put_dlb(x) #define DLB(x) C_pt_dlb(x)
#define DFDLB(x) put_dlb(x) #define DFDLB(x) C_pt_dlb(x)
#define ILB(x) put_ilb(x) #define ILB(x) C_pt_ilb(x)
#define DFILB(x) put_dfilb(x) #define DFILB(x) C_pt_dfilb(x)
#define NOFF(x,y) put_noff((x), (y)) #define NOFF(x,y) C_pt_noff((x), (y))
#define DOFF(x,y) put_doff((x), (y)) #define DOFF(x,y) C_pt_doff((x), (y))
#define PNAM(x) put_pnam(x) #define PNAM(x) C_pt_pnam(x)
#define DNAM(x) _prnt(x) #define DNAM(x) C_pt_dnam(x)
#define DFDNAM(x) _prnt(x) #define DFDNAM(x) C_pt_dnam(x)
#define CEND() #define CEND()
#define CCEND() put_ccend() #define CCEND() C_pt_ccend()
#define WCON(x,y,z) put_wcon((x), (y), (z)) #define WCON(x,y,z) C_pt_wcon((x), (y), (z))
#define COMMA() put_comma() #define COMMA() C_pt_comma()
#define NL() put_nl() #define NL() C_pt_nl()
#define CILB(x) put_ilb(x) #define CILB(x) C_pt_ilb(x)