more internal buffering

This commit is contained in:
ceriel 1989-11-17 15:56:53 +00:00
parent 99cae8d6df
commit e9d477fd6e
5 changed files with 37 additions and 33 deletions

View file

@ -2,7 +2,7 @@
.ad
.SH NAME
wr_open, wr_close, wr_ohead, wr_sect, wr_outsect, wr_emit, wr_putc, wr_relo,
wr_name, wr_string, wr_arhdr, wr_ranlib, wr_int2, wr_long, wr_bytes, wr_fd,
wr_name, wr_string, wr_arhdr, wr_ranlib, wr_int2, wr_long, wr_bytes,
rd_open, rd_fdopen, rd_close, rd_ohead, rd_sect, rd_outsect,
rd_emit, rd_relo, rd_rew_relo, rd_name, rd_string, rd_arhdr, rd_ranlib,
rd_int2, rd_unsigned2, rd_long, rd_bytes, rd_fd\ \-\ routines to read
@ -82,8 +82,6 @@ and write ACK-object files and libraries
.br
.B long l;
.PP
.B int wr_fd()
.PP
.B int rd_open(filename)
.br
.B char *filename;
@ -261,9 +259,6 @@ bytes from
to file descriptor
.IB fd .
.PP
.I Wr_fd
returns the current output file descriptor.
.PP
Most of the
.I rd_
routines are the opposite of the

View file

@ -36,6 +36,7 @@
#define put4(l, c) (* ((long *) (c)) = (l))
#endif
#define SECTCNT 3 /* number of sections with own output buffer */
#if BIGMACHINE
#define WBUFSIZ (8*BUFSIZ)
#else
@ -55,17 +56,15 @@ struct fil {
extern struct fil __parts[];
#define OUTBYTE(p, b) {if (__parts[p].cnt == 0) __wr_flush(&__parts[p]);\
__parts[p].cnt--; *__parts[p].pnow++ = (b);}
#define PARTEMIT 0
#define PARTRELO 1
#define PARTNAME 2
#define PARTCHAR 3
#define PARTRELO (PARTEMIT+SECTCNT)
#define PARTNAME (PARTRELO+1)
#define PARTCHAR (PARTNAME+1)
#ifdef SYMDBUG
#define PARTDBUG 4
#define PARTDBUG (PARTCHAR+1)
#else
#define PARTDBUG 3
#define PARTDBUG (PARTCHAR+0)
#endif
#define NPARTS (PARTDBUG + 1)
#define getsect(s) (PARTEMIT+((s)>=(SECTCNT-1)?(SECTCNT-1):(s)))

View file

@ -11,6 +11,13 @@ extern long lseek();
/*
* Parts of the output file.
*/
#undef PARTEMIT
#undef PARTRELO
#undef PARTNAME
#undef PARTCHAR
#undef PARTDBUG
#undef NPARTS
#define PARTEMIT 0
#define PARTRELO 1
#define PARTNAME 2

View file

@ -26,7 +26,8 @@ struct fil __parts[NPARTS];
static int outfile;
static long currpos;
#endif
static int sectionnr;
int __sectionnr;
#define sectionnr __sectionnr
static int offcnt;
__wr_flush(ptr)
@ -40,7 +41,7 @@ __wr_flush(ptr)
#endif
wr_bytes(ptr->fd, ptr->pbegin, (long)(ptr->pnow - ptr->pbegin));
ptr->currpos += ptr->pnow - ptr->pbegin;
if (ptr == &__parts[PARTEMIT]) {
if (ptr < &__parts[PARTEMIT+SECTCNT]) {
offset[sectionnr] = ptr->currpos;
}
}
@ -70,7 +71,7 @@ static OUTWRITE(p, b, n)
n -= i;
b += i;
ptr->currpos += i;
if (ptr == &__parts[PARTEMIT]) {
if (ptr < &__parts[PARTEMIT+SECTCNT]) {
offset[sectionnr] = ptr->currpos;
}
}
@ -93,7 +94,7 @@ static OUTWRITE(p, b, n)
b += m;
n &= WBUFSIZ - 1;
ptr->currpos += m;
if (ptr == &__parts[PARTEMIT]) {
if (ptr < &__parts[PARTEMIT+SECTCNT]) {
offset[sectionnr] = ptr->currpos;
}
}
@ -126,6 +127,8 @@ static BEGINSEEK(p, o)
#else
ptr->currpos = lseek(ptr->fd, o, 0);
#endif
if (p >= PARTRELO) o = 0; /* no attempt to align writes
for the time being */
ptr->cnt = WBUFSIZ - ((int)o & (WBUFSIZ-1));
ptr->pbegin = ptr->pbuf + (WBUFSIZ - ptr->cnt);
ptr->pnow = ptr->pbegin;
@ -172,15 +175,6 @@ wr_close()
#endif /* OUTSEEK */
}
wr_fd()
{
#ifdef OUTSEEK
return outfile;
#else
return __parts[PARTEMIT].fd;
#endif
}
wr_ohead(head)
register struct outhead *head;
{
@ -239,6 +233,9 @@ wr_sect(sect, cnt1)
put4(sect->os_size, c); c += 4;
put4(sect->os_foff, c); c += 4;
}
if (offcnt >= 1 && offcnt < SECTCNT) {
BEGINSEEK(PARTEMIT+offcnt, sect->os_foff);
}
offset[offcnt++] = sect->os_foff;
#if ! (BYTES_REVERSED || WORDS_REVERSED)
if (sizeof(struct outsect) != SZ_SECT)
@ -262,10 +259,9 @@ wr_sect(sect, cnt1)
wr_outsect(s)
int s; /* section number */
{
register struct fil *ptr = &__parts[PARTEMIT];
register struct fil *ptr = &__parts[PARTEMIT + getsect(sectionnr)];
if (s != sectionnr &&
offset[s] != ptr->currpos + (ptr->pnow - ptr->pbegin)) {
if (s != sectionnr && s >= (SECTCNT-1) && sectionnr >= (SECTCNT-1)) {
#ifdef OUTSEEK
if (currpos != ptr->currpos)
currpos = lseek(ptr->fd, ptr->currpos, 0);
@ -276,7 +272,9 @@ wr_outsect(s)
#endif
ptr->currpos += ptr->pnow - ptr->pbegin;
offset[sectionnr] = ptr->currpos;
if (offset[s] != ptr->currpos) {
ptr->currpos = lseek(ptr->fd, offset[s], 0);
}
ptr->cnt = WBUFSIZ - ((int)offset[s] & (WBUFSIZ-1));
ptr->pbegin = ptr->pbuf + (WBUFSIZ - ptr->cnt);
ptr->pnow = ptr->pbegin;
@ -291,7 +289,7 @@ wr_emit(emit, cnt)
char *emit;
long cnt;
{
OUTWRITE(PARTEMIT, emit, cnt);
OUTWRITE(PARTEMIT + getsect(sectionnr) , emit, cnt);
}
wr_relo(relo, cnt)

View file

@ -5,7 +5,12 @@
*/
#include "object.h"
extern int __sectionnr;
wr_putc(ch)
{
OUTBYTE(PARTEMIT, ch);
register struct fil *ptr = &__parts[PARTEMIT+getsect(__sectionnr)];
if (ptr->cnt == 0) __wr_flush(ptr);
ptr->cnt--; *ptr->pnow++ = ch;
}