1987-03-09 19:15:41 +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-10 13:35:39 +00:00
|
|
|
#ifndef lint
|
1994-06-24 11:31:16 +00:00
|
|
|
static char rcsid[] = "$Id$";
|
1985-01-10 13:35:39 +00:00
|
|
|
#endif
|
|
|
|
|
2017-11-10 03:22:13 +00:00
|
|
|
#include <assert.h>
|
1985-01-10 13:35:39 +00:00
|
|
|
#include <stdio.h>
|
2017-01-18 18:55:56 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
2006-07-22 17:58:49 +00:00
|
|
|
#include <string.h>
|
2019-03-22 19:15:40 +00:00
|
|
|
#include <object.h>
|
2006-07-22 17:58:49 +00:00
|
|
|
#include "out.h"
|
2019-03-24 09:08:45 +00:00
|
|
|
#include "object.h"
|
1985-01-10 13:35:39 +00:00
|
|
|
#include "const.h"
|
|
|
|
#include "memory.h"
|
2018-03-11 11:37:23 +00:00
|
|
|
#include "sym.h"
|
2019-03-24 09:08:45 +00:00
|
|
|
#include "error.h"
|
|
|
|
#include "write.h"
|
1985-01-10 13:35:39 +00:00
|
|
|
|
|
|
|
extern struct outhead outhead;
|
|
|
|
extern struct outsect outsect[];
|
|
|
|
extern int flagword;
|
2019-03-24 09:08:45 +00:00
|
|
|
extern bool incore;
|
1985-01-10 13:35:39 +00:00
|
|
|
|
2019-03-24 09:08:45 +00:00
|
|
|
static long off_char;
|
|
|
|
|
|
|
|
void wr_fatal(void)
|
1986-10-20 10:17:57 +00:00
|
|
|
{
|
|
|
|
fatal("write error");
|
|
|
|
}
|
1985-01-10 13:35:39 +00:00
|
|
|
|
2019-03-24 09:08:45 +00:00
|
|
|
|
1985-01-10 13:35:39 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Open the output file according to the chosen strategy.
|
|
|
|
* Write away the header and section table: they will not change anymore.
|
|
|
|
*/
|
2019-03-24 09:08:45 +00:00
|
|
|
void begin_write(void)
|
1985-01-10 13:35:39 +00:00
|
|
|
{
|
1986-10-20 10:17:57 +00:00
|
|
|
register struct outhead *hd = &outhead;
|
1985-01-10 13:35:39 +00:00
|
|
|
|
1986-10-20 10:17:57 +00:00
|
|
|
assert(! incore);
|
|
|
|
wr_ohead(hd);
|
|
|
|
wr_sect(outsect, hd->oh_nsect);
|
|
|
|
off_char = OFF_CHAR(*hd);
|
1985-01-10 13:35:39 +00:00
|
|
|
}
|
|
|
|
|
2019-03-24 09:08:45 +00:00
|
|
|
static struct outname *sectname(int sectindex)
|
1985-01-10 13:35:39 +00:00
|
|
|
{
|
|
|
|
static struct outname namebuf;
|
|
|
|
|
|
|
|
namebuf.on_foff = (long)0; /* No string name. */
|
|
|
|
namebuf.on_type = (S_MIN + sectindex) | S_SCT;
|
|
|
|
namebuf.on_desc = 0;
|
|
|
|
namebuf.on_valu = outsect[sectindex].os_base;
|
|
|
|
|
|
|
|
return &namebuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write out the symbol table and the section names.
|
|
|
|
*/
|
2019-03-24 09:08:45 +00:00
|
|
|
void end_write(void)
|
1985-01-10 13:35:39 +00:00
|
|
|
{
|
|
|
|
register struct outname *name;
|
|
|
|
register int sectindex;
|
1987-04-08 17:15:30 +00:00
|
|
|
extern long NGChars;
|
1985-01-10 13:35:39 +00:00
|
|
|
|
|
|
|
assert(!incore);
|
|
|
|
assert(!(flagword & SFLAG));
|
|
|
|
name = (struct outname *)address(ALLOGLOB, (ind_t)0);
|
1987-04-08 17:15:30 +00:00
|
|
|
namecpy(name, NGlobals, off_char);
|
|
|
|
wr_name(name, NGlobals);
|
|
|
|
wr_string(mems[ALLOGCHR].mem_base+1, NGChars);
|
|
|
|
off_char += NGChars;
|
1985-01-10 13:35:39 +00:00
|
|
|
|
|
|
|
for (sectindex = 0; sectindex < outhead.oh_nsect; sectindex++)
|
1987-04-08 17:15:30 +00:00
|
|
|
wrt_name(sectname(sectindex), 1);
|
1985-01-10 13:35:39 +00:00
|
|
|
}
|
2017-01-18 18:55:56 +00:00
|
|
|
|
2019-03-24 09:08:45 +00:00
|
|
|
void wrt_emit(char *emit, int sectindex, long cnt)
|
1985-01-10 13:35:39 +00:00
|
|
|
{
|
|
|
|
|
1986-10-20 10:17:57 +00:00
|
|
|
wr_outsect(sectindex);
|
|
|
|
wr_emit(emit, cnt);
|
1985-01-10 13:35:39 +00:00
|
|
|
}
|
|
|
|
|
2019-03-24 09:08:45 +00:00
|
|
|
void wrt_nulls(int sectindex, register long cnt)
|
1985-01-10 13:35:39 +00:00
|
|
|
{
|
1986-10-20 10:17:57 +00:00
|
|
|
static char nullbuf[BUFSIZ];
|
1985-01-10 13:35:39 +00:00
|
|
|
|
1986-10-20 10:17:57 +00:00
|
|
|
wr_outsect(sectindex);
|
1985-01-10 13:35:39 +00:00
|
|
|
while (cnt) {
|
1986-10-20 10:17:57 +00:00
|
|
|
register int n = cnt >= BUFSIZ ? BUFSIZ : cnt;
|
|
|
|
wr_emit(nullbuf, (long)n);
|
1985-01-10 13:35:39 +00:00
|
|
|
cnt -= n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-24 09:08:45 +00:00
|
|
|
void wrt_name(register struct outname *name, int writename)
|
1985-01-10 13:35:39 +00:00
|
|
|
{
|
|
|
|
assert(!incore);
|
|
|
|
assert(!(flagword & SFLAG));
|
|
|
|
if (name->on_mptr != (char *)0) {
|
1986-10-20 10:17:57 +00:00
|
|
|
register long len = strlen(name->on_mptr) + 1;
|
1985-01-10 13:35:39 +00:00
|
|
|
|
1986-10-20 10:17:57 +00:00
|
|
|
wr_string(name->on_mptr, len);
|
|
|
|
name->on_foff = off_char;
|
|
|
|
off_char += len;
|
1985-01-10 13:35:39 +00:00
|
|
|
} else {
|
|
|
|
name->on_foff = (long)0;
|
|
|
|
}
|
1987-04-08 17:15:30 +00:00
|
|
|
if (writename) wr_name(name, 1);
|
1985-01-10 13:35:39 +00:00
|
|
|
}
|