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
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If everything is kept in core, we must save some things for the second pass.
|
|
|
|
*/
|
|
|
|
|
2017-11-10 03:22:13 +00:00
|
|
|
#include <assert.h>
|
2006-07-30 23:40:35 +00:00
|
|
|
#include <stdio.h>
|
2017-01-18 18:55:56 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
2006-07-30 23:40:35 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include "arch.h"
|
2019-03-24 09:08:45 +00:00
|
|
|
#include "save.h"
|
2006-07-30 23:40:35 +00:00
|
|
|
#include "out.h"
|
1985-01-10 13:35:39 +00:00
|
|
|
#include "const.h"
|
|
|
|
#include "memory.h"
|
|
|
|
|
2019-03-24 09:08:45 +00:00
|
|
|
extern bool incore;
|
|
|
|
extern char *core_alloc();
|
|
|
|
|
|
|
|
long NLChars = 0; /* Size of string area for local names. */
|
|
|
|
long NGChars = 0; /* Idem for global names. */
|
|
|
|
|
|
|
|
void savemagic(void)
|
1985-01-10 13:35:39 +00:00
|
|
|
{
|
|
|
|
register char *p;
|
|
|
|
|
|
|
|
if (!incore)
|
|
|
|
return;
|
|
|
|
|
2019-03-24 09:08:45 +00:00
|
|
|
if ((p = core_alloc(ALLOMODL, (long)sizeof(int))) != (char *)0) {
|
1991-12-17 15:28:58 +00:00
|
|
|
*(unsigned short *)p = AALMAG;
|
1988-04-21 18:53:31 +00:00
|
|
|
core_position += sizeof(int);
|
1985-01-10 13:35:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-24 09:08:45 +00:00
|
|
|
void savehdr(struct ar_hdr *hdr)
|
1985-01-10 13:35:39 +00:00
|
|
|
{
|
|
|
|
register char *p;
|
|
|
|
|
|
|
|
if (!incore)
|
|
|
|
return;
|
|
|
|
|
2019-03-24 09:08:45 +00:00
|
|
|
if ((p=core_alloc(ALLOMODL,(long)sizeof(struct ar_hdr)))!=(char *)0) {
|
1985-01-10 13:35:39 +00:00
|
|
|
*(struct ar_hdr *)p = *hdr;
|
1988-04-21 18:53:31 +00:00
|
|
|
core_position += int_align(sizeof(struct ar_hdr));
|
1985-01-10 13:35:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-24 09:08:45 +00:00
|
|
|
|
1985-01-10 13:35:39 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Put the string in cp into the block allocated for the string area.
|
|
|
|
* Return its offset in this area. We don't use the first char of the string
|
|
|
|
* area, so that empty strings can be distinguished from the first string.
|
|
|
|
*/
|
2019-03-24 09:08:45 +00:00
|
|
|
ind_t savechar(register int piece, register ind_t off)
|
1985-01-10 13:35:39 +00:00
|
|
|
{
|
2018-11-12 03:51:17 +00:00
|
|
|
register size_t len;
|
1985-01-10 13:35:39 +00:00
|
|
|
register ind_t newoff;
|
|
|
|
|
|
|
|
if (off == (ind_t)0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
len = strlen(modulptr(off)) + 1;
|
|
|
|
if (piece == ALLOLCHR) {
|
|
|
|
NLChars += len;
|
|
|
|
if (!incore || (newoff = alloc(piece, len)) == BADOFF)
|
|
|
|
return BADOFF;
|
|
|
|
} else {
|
|
|
|
assert(piece == ALLOGCHR);
|
|
|
|
NGChars += len;
|
|
|
|
if ((newoff = hard_alloc(piece, len)) == BADOFF)
|
|
|
|
return BADOFF;
|
|
|
|
}
|
|
|
|
strcpy(address(piece, newoff), modulptr(off));
|
|
|
|
return newoff;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Put the local in `name' in the piece allocated for local names that must
|
|
|
|
* be saved. `Name' points to a private copy, so will not become invalid after
|
|
|
|
* allocation, but the string of which name->on_foff is the offset may be
|
|
|
|
* destroyed, so we save that first.
|
|
|
|
*/
|
2019-03-24 09:08:45 +00:00
|
|
|
void savelocal(struct outname *name)
|
1985-01-10 13:35:39 +00:00
|
|
|
{
|
|
|
|
ind_t savindex;
|
|
|
|
struct outname *new;
|
|
|
|
|
|
|
|
if ((savindex = savechar(ALLOLCHR, (ind_t)name->on_foff)) == BADOFF)
|
|
|
|
return;
|
|
|
|
|
|
|
|
new = (struct outname *)
|
2019-03-24 09:08:45 +00:00
|
|
|
core_alloc(ALLOLOCL, (long)sizeof(struct outname));
|
1985-01-10 13:35:39 +00:00
|
|
|
if (new != (struct outname *)0) {
|
|
|
|
*new = *name;
|
|
|
|
new->on_foff = savindex;
|
|
|
|
}
|
|
|
|
}
|