Add additional defines for compilation.

This commit is contained in:
carl 2019-03-24 17:08:45 +08:00
parent b3814af1ba
commit c5f5bace63
22 changed files with 250 additions and 237 deletions

View file

@ -13,15 +13,24 @@ static char rcsid[] = "$Id$";
#include "arch.h"
#include "out.h"
#include "ranlib.h"
#include "object.h"
#include "const.h"
#include "debug.h"
#include "finish.h"
#include "extract.h"
#include "defs.h"
#include "memory.h"
#include "scan.h"
#include "error.h"
#include "save.h"
#define ENDLIB ((long)0)
static struct ar_hdr arhdr;
void notelib(long pos);
/*
* First read a long telling how many ranlib structs there are, then
* the structs themselves. Second read a long telling how many chars there are
@ -29,15 +38,14 @@ static struct ar_hdr arhdr;
* We keep only one ranlib table in core, so this table always starts at offset
* (ind_t)0 from its base.
*/
static long
getsymdeftable()
static long getsymdeftable(void)
{
register ind_t off;
register struct ranlib *ran;
register long count;
register long nran, nchar;
extern long rd_long();
extern int infile;
extern FILE* infile;
count = nran = rd_long(infile);
debug("%ld ranlib structs, ", nran, 0, 0, 0);
@ -81,7 +89,7 @@ extern char *modulname;
* scan the table again. We perform these actions as long as new symbols
* are defined.
*/
arch()
void arch(void)
{
long nran;
bool resolved;
@ -143,8 +151,7 @@ arch()
* An archive member that will be loaded is remembered by storing its position
* in the archive into the table of positions.
*/
notelib(pos)
long pos;
void notelib(long pos)
{
register ind_t off;
@ -165,7 +172,7 @@ static ind_t posindex = (ind_t)0;
* that we've processed all needed modules in this archive. Each group of
* positions of an archive is terminated with ENDLIB.
*/
arch2()
void arch2(void)
{
register long *pos;
register ind_t localpos;

View file

@ -2,8 +2,10 @@ cprogram {
name = "led",
srcs = { "./*.c" },
deps = {
"./const.h", "./debug.h", "./defs.h", "./mach.h",
"./memory.h", "./orig.h", "./scan.h",
"./archive.h", "./const.h", "./debug.h", "./defs.h",
"./error.h", "./extract.h", "./finish.h", "./mach.h",
"./memory.h", "./orig.h", "./output.h", "./relocate.h",
"./save.h", "./scan.h", "./sym.h", "./write.h",
"modules/src/string+lib",
"modules/src/object+lib",
"h+emheaders",

View file

@ -4,6 +4,9 @@
*/
/* $Id$ */
#ifndef __CONST_H_INCLUDED__
#define __CONST_H_INCLUDED__
#define FALSE 0
#define TRUE 1
@ -22,3 +25,5 @@
#define SECOND 2 /* Idem. */
#define BADOFF ((ind_t)-1)
#endif /* __CONST_H_INCLUDED__ */

View file

@ -4,6 +4,10 @@
*/
/* $Id$ */
#ifndef __DEBUG_H_INCLUDED__
#define __DEBUG_H_INCLUDED__
#ifdef NDEBUG
#define debug(s, a1, a2, a3, a4)
@ -19,3 +23,5 @@ extern int Verbose;
#define verbose(s, a1, a2, a3, a4) (Verbose && do_verbose(s, a1, a2, a3, a4))
extern void fatal(char* format, ...);
#endif /* __DEBUG_H_INCLUDED__ */

View file

@ -3,6 +3,9 @@
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* $Id$ */
#ifndef __DEFS_H_INCLUDED__
#define __DEFS_H_INCLUDED__
/*
* We need the S_EXT because we leave locals alone.
@ -12,3 +15,6 @@
#define ISCOMMON(n) (((n)->on_type & (S_COM | S_EXT)) == (S_COM | S_EXT))
#define mustsavelocal(name) (!((name)->on_type & S_SCT))
#endif /* __DEFS_H_INCLUDED__ */

View file

@ -17,13 +17,13 @@ static char rcsid[] = "$Id$";
static short nerrors = 0;
static void diag(char *, char *, va_list);
stop()
void stop(void)
{
extern char *outputname;
extern int exitstatus;
if (nerrors) {
unlink(outputname);
remove(outputname);
exit(nerrors);
}
@ -31,8 +31,7 @@ stop()
}
/* VARARGS1 */
void
fatal(char *format, ...)
void fatal(char *format, ...)
{
va_list ap;
va_start(ap, format);
@ -42,8 +41,7 @@ fatal(char *format, ...)
}
/* VARARGS1 */
void
warning(char *format, ...)
void warning(char *format, ...)
{
va_list ap;
va_start(ap, format);
@ -52,8 +50,7 @@ warning(char *format, ...)
}
/* VARARGS1 */
void
error(char *format, ...)
void error(char *format, ...)
{
va_list ap;
va_start(ap, format);
@ -63,17 +60,16 @@ error(char *format, ...)
}
/* VARARGS1 */
void
do_verbose(char *format, ...)
int do_verbose(char *format, ...)
{
va_list ap;
va_start(ap, format);
diag((char *) 0, format, ap);
va_end(ap);
return 1;
}
static void
diag(char *tail, char *format, va_list ap)
static void diag(char *tail, char *format, va_list ap)
{
extern char *progname, *archname, *modulname;

View file

@ -17,22 +17,27 @@ static char rcsid[] = "$Id$";
#include "memory.h"
#include "orig.h"
#include "scan.h"
#include "save.h"
#include "sym.h"
#include "error.h"
static void getexternal(register struct outname *);
static void get_names(register struct outhead *);
static void process(register struct outhead *);
static void redefine(register struct outname *, register struct outname *);
static void transfer(register struct outname *, register struct outname *);
static void process(register struct outhead *);
static get_names();
static process();
static getexternal();
static redefine();
static transfer();
extern ind_t savechar();
extern struct orig relorig[];
void namerelocate();
/*
* Get section sizes and symboltable information from present module.
*/
extract()
void extract(void)
{
struct outhead head;
@ -52,9 +57,7 @@ extract()
* appear in the final output file if this module is linked.
* That number will be returned.
*/
static
get_names(head)
register struct outhead *head;
static void get_names(register struct outhead *head)
{
register int nnames;
register ind_t nameindex, charindex;
@ -106,11 +109,9 @@ get_names(head)
}
}
extern struct orig relorig[];
static
process(head)
register struct outhead *head;
static void process(register struct outhead *head)
{
register struct outsect *sects;
register struct outsect *outsp;
@ -152,9 +153,7 @@ process(head)
* Otherwise we just add the accumulated size of all normal parts in preceding
* sections with the same size.
*/
void
namerelocate(name)
register struct outname *name;
void namerelocate(register struct outname *name)
{
register int type = name->on_type;
register int sct = type & S_TYP;
@ -174,9 +173,7 @@ namerelocate(name)
* we might need it later on. Otherwise it must confirm to what we already
* know about it, and eventually add to that knowledge.
*/
static
getexternal(name)
register struct outname *name;
static void getexternal(register struct outname *name)
{
register char *string;
register int h;
@ -216,9 +213,7 @@ getexternal(name)
* greatest value so that the common declared name always has enough space.
* If a common is defined as a not-common, the old definition is ignored.
*/
static
redefine(new, old)
register struct outname *new, *old;
static void redefine(register struct outname *new, register struct outname *old)
{
if (!ISCOMMON(old)) {
if (!ISCOMMON(new))
@ -244,9 +239,7 @@ redefine(new, old)
/*
* Transfer things we want to know from `src' to `dst'.
*/
static
transfer(src, dst)
register struct outname *src, *dst;
static void transfer(register struct outname *src, register struct outname *dst)
{
debug("%s defined here\n", src->on_mptr, 0, 0, 0);
dst->on_valu = src->on_valu;

View file

@ -10,21 +10,30 @@ static char rcsid[] = "$Id$";
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <out.h>
#include "out.h"
#include "arch.h"
#include "const.h"
#include "defs.h"
#include "memory.h"
#include "orig.h"
#include "scan.h"
#include "sym.h"
#include "object.h"
#include "write.h"
#include "relocate.h"
#include "extract.h"
#include "finish.h"
extern bool incore;
extern unsigned short NLocals;
extern int flagword;
extern struct outname *searchname();
extern void addbase(struct outname *name);
static adjust_names();
static handle_relos();
static put_locals();
static compute_origins();
static void adjust_names(register struct outname *, struct outhead *, register char *);
static void handle_relos(struct outhead *, struct outsect *, struct outname *);
static void put_locals(struct outname *, register unsigned int);
static void compute_origins(register struct outsect *, register unsigned int);
/*
* We know all there is to know about the current module.
@ -32,7 +41,7 @@ static compute_origins();
* those to the final output file. Then we compute the relative origins
* for the next module.
*/
finish()
void finish(void)
{
struct outhead *head;
struct outsect *sects;
@ -59,11 +68,8 @@ finish()
/*
* Adjust all local names for the move into core.
*/
static
adjust_names(name, head, chars)
register struct outname *name;
struct outhead *head;
register char *chars;
static void adjust_names(register struct outname *name, struct outhead *head, register char *chars)
{
register int cnt;
register long charoff;
@ -81,9 +87,7 @@ adjust_names(name, head, chars)
}
}
do_crs(base, count)
struct outname *base;
unsigned count;
void do_crs(struct outname *base, unsigned int count)
{
register struct outname *name = base;
@ -116,16 +120,14 @@ do_crs(base, count)
* the relocation table again, because the relocation entries of one section
* need not be consecutive.
*/
static
handle_relos(head, sects, names)
struct outhead *head;
struct outsect *sects;
struct outname *names;
static void handle_relos(struct outhead *head, struct outsect *sects, struct outname *names)
{
register struct outrelo *relo;
register int sectindex;
register int nrelo;
register char *emit;
extern char *getemit();
extern struct outrelo *nextrelo();
static long zeros[MAXSECT];
if (incore) {
@ -166,6 +168,7 @@ handle_relos(head, sects, names)
long sz = sects[sectindex].os_flen;
long sf = 0;
long blksz;
char *getblk();
emit = getblk(sz, &blksz, sectindex);
while (sz) {
@ -206,10 +209,8 @@ handle_relos(head, sects, names)
/*
* Write out the local names that must be saved.
*/
static
put_locals(name, nnames)
struct outname *name;
register unsigned nnames;
static void put_locals(struct outname *name, register unsigned int nnames)
{
register struct outname *oname = name;
register struct outname *iname = oname;
@ -230,10 +231,7 @@ put_locals(name, nnames)
* Add all flen's and all (size - flen == zero)'s of preceding sections
* with the same number.
*/
static
compute_origins(sect, nsect)
register struct outsect *sect;
register unsigned nsect;
static void compute_origins(register struct outsect *sect, register unsigned int nsect)
{
extern struct orig relorig[];
register struct orig *orig = relorig;
@ -250,9 +248,7 @@ compute_origins(sect, nsect)
* Write out what is after the string area. This is likely to be
* debugging information.
*/
static
put_dbug(offdbug)
long offdbug;
static void put_dbug(long offdbug)
{
char buf[512];
register int nbytes;

View file

@ -9,8 +9,11 @@
* Values depend on the machine on which this program should run.
* Now for Vax 11/750.
*/
#ifndef __MACH_H_INCLUDED__
#define __MACH_H_INCLUDED__
#include <local.h>
#include "local.h"
#define K 1024L
@ -49,3 +52,5 @@
mems[ALLOMODL].mem_left = 12 * K;
mems[ALLORANL].mem_left = 4 * K;
#endif
#endif /* __MACH_H_INCLUDED__ */

View file

@ -22,8 +22,15 @@ static char rcsid[] = "$Id$";
#include "defs.h"
#include "memory.h"
#include "orig.h"
#include "scan.h"
#include "sym.h"
#include "extract.h"
#include "error.h"
#include "output.h"
#include "finish.h"
#include "archive.h"
extern bool incore;
#ifndef NOSTATISTICS
int statistics;
#endif
@ -32,30 +39,29 @@ int DEB = 0;
#endif
int Verbose = 0;
static initializations();
static first_pass();
static uint32_t number(const char *);
static void initializations(int, char*[]);
static void first_pass(char**);
static uint32_t number(const char *);
static void setlign(int, uint32_t);
static void setbase(int, uint32_t);
static void enterundef(const char *, int);
static pass1();
static evaluate();
static struct outname *makename(char*);
static void pass1(char*);
static void evaluate(void);
static void norm_commons();
static complete_sections();
static void change_names();
static bool setbit();
static bool tstbit();
static second_pass();
static pass2();
static void complete_sections(void);
static void change_names(void);
static void enterundef(const char *, int);
static bool setbit(int, char[]);
static bool tstbit(int, char[]);
static void second_pass(char**);
static void pass2(char*);
#ifndef NOSTATISTICS
static do_statistics();
static void do_statistics(void);
#endif
void addbase();
void addbase(struct outname *);
main(argc, argv)
int argc;
char **argv;
int main(int argc, char **argv)
{
initializations(argc, argv);
first_pass(argv);
@ -71,8 +77,7 @@ main(argc, argv)
}
#ifndef NOSTATISTICS
static
do_statistics()
static void do_statistics(void)
{
register struct memory *m = mems;
@ -92,10 +97,7 @@ struct outhead outhead; /* Header of final output file. */
struct outsect outsect[MAXSECT];/* Its section table. */
/* ARGSUSED */
static
initializations(argc, argv)
int argc;
char *argv[];
static void initializations(int argc, char *argv[])
{
/*
* Avoid malloc()s.
@ -123,9 +125,7 @@ int exitstatus = 0;
* If the argument starts with a '-', it's a flag, else it is either
* a plain file to be loaded, or an archive.
*/
static
first_pass(argv)
register char **argv;
static void first_pass(register char **argv)
{
register char *argp;
int sectno;
@ -255,8 +255,7 @@ first_pass(argv)
* else if it starts with 0, it's octal,
* else it's decimal.
*/
static uint32_t
number(const char *s)
static uint32_t number(const char *s)
{
register int digit;
register uint32_t value = 0;
@ -273,7 +272,7 @@ number(const char *s)
s++;
}
}
while (digit = *s++) {
while ((digit = *s++)) {
if (digit >= 'A' && digit <= 'F')
digit = digit - 'A' + 10;
else if (digit >= 'a' && digit <= 'f')
@ -298,13 +297,11 @@ static uint32_t sect_base[MAXSECT];
static char lignmap[MAXSECT / WIDTH];
static uint32_t sect_lign[MAXSECT];
/*
/*
* Set the alignment of section `sectno' to `lign', if this doesn't
* conflict with earlier alignment.
*/
static void
setlign(int sectno, uint32_t lign)
static void setlign(int sectno, uint32_t lign)
{
extern bool setbit();
@ -332,8 +329,7 @@ setbase(int sectno, uint32_t base)
/*
* Do -u name by entering the undefined name in the symbol table.
*/
static void
enterundef(const char *string, int hashval)
static void enterundef(const char *string, int hashval)
{
struct outname namebuf;
size_t len;
@ -364,9 +360,7 @@ enterundef(const char *string, int hashval)
* extracted. If it is an archive it is examined to see if it defines any
* undefined symbols.
*/
static
pass1(file)
char *file;
static void pass1(char* file)
{
if (getfile(file) == PLAIN) {
debug("%s: plain file\n", file, 0, 0, 0);
@ -388,8 +382,7 @@ pass1(file)
* sections. We then add the section bases to the values of names in
* corresponding sections.
*/
static
evaluate()
static void evaluate(void)
{
norm_commons();
complete_sections();
@ -411,8 +404,7 @@ long sect_comm[MAXSECT];
* just like "normal" names. We also count the total size of common names
* within each section to be able to compute the final size in the machine.
*/
static void
norm_commons()
static void norm_commons(void)
{
register struct outname *name;
register int cnt;
@ -470,8 +462,7 @@ struct orig relorig[MAXSECT];
* Compute the offsets in file and machine that the sections will have.
* Also set the origins to 0.
*/
static
complete_sections()
static void complete_sections(void)
{
register uint32_t base = 0;
register uint32_t foff;
@ -508,8 +499,7 @@ complete_sections()
* For each name we add the base of its section to its value, unless
* the output has to be able to be linked again, as indicated by RFLAG.
*/
static void
change_names()
static void change_names(void)
{
register int cnt;
register struct outname *name;
@ -539,10 +529,7 @@ change_names()
* This function sets a bit with index `indx' in string.
* It returns whether it was already set.
*/
bool
setbit(indx, string)
int indx;
char string[];
bool setbit(int indx, char string[])
{
register int byte_index, bit_index;
register int byte;
@ -562,10 +549,7 @@ setbit(indx, string)
/*
* This function returns whether the bit given by `indx' is set in `string'.
*/
static bool
tstbit(indx, string)
int indx;
char string[];
static bool tstbit(int indx, char string[])
{
register int byte_index, bit_index;
register int byte;
@ -581,9 +565,7 @@ tstbit(indx, string)
/*
* Add the base of the section of a name to its value.
*/
void
addbase(name)
struct outname *name;
void addbase(struct outname *name)
{
register int type = name->on_type & S_TYP;
register int sectindex = type - S_MIN;
@ -607,9 +589,7 @@ addbase(name)
/*
* Flags have already been processed, so we ignore them here.
*/
static
second_pass(argv)
char **argv;
static void second_pass(char **argv)
{
passnumber = SECOND;
while (*++argv) {
@ -628,9 +608,7 @@ second_pass(argv)
}
}
static
pass2(file)
char *file;
static void pass2(char* file)
{
if (getfile(file) == PLAIN) {
debug("%s: plain file\n", file, 0, 0, 0);

View file

@ -40,6 +40,8 @@ static char rcsid[] = "$Id$";
#include "memory.h"
#include "object.h"
#include "sym.h"
#include "finish.h"
#include "write.h"
#ifndef USEMALLOC
static void copy_down(struct memory* mem, ind_t dist);
@ -655,8 +657,7 @@ void core_free(int piece, char* p)
* Reset index into piece of memory for modules and
* take care that the allocated pieces will not be moved.
*/
void
freeze_core()
void freeze_core(void)
{
register int i;

View file

@ -4,6 +4,9 @@
*/
/* $Id$ */
#ifndef __MEMORY_H_INCLUDED__
#define __MEMORY_H_INCLUDED__
#include <stdbool.h>
#include <stddef.h>
@ -35,6 +38,8 @@ struct memory {
};
extern struct memory mems[];
struct outname;
#define address(piece,offset) (mems[(piece)].mem_base+(offset))
#define modulptr(offset) (mems[ALLOMODL].mem_base+core_position+(offset))
@ -49,4 +54,7 @@ extern void dealloc(int piece);
extern char *core_alloc(int piece, size_t size);
extern void core_free(int piece, char* p);
extern void write_bytes(void);
extern void freeze_core(void);
extern void namecpy(struct outname* name, unsigned nname, long offchar);
#endif /* #ifndef __MEMORY_H_INCLUDED__ */

View file

@ -3,7 +3,11 @@
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* $Id$ */
#ifndef __ORIG_H_INCLUDED__
#define __ORIG_H_INCLUDED__
struct orig {
long org_size; /* Accumulated length of preceding sections. */
};
#endif /* __ORIG_H_INCLUDED__ */

View file

@ -10,14 +10,19 @@ static char rcsid[] = "$Id$";
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <out.h>
#include "out.h"
#include "object.h"
#include "const.h"
#include "output.h"
#include "memory.h"
#include "error.h"
#include "write.h"
#include "sym.h"
static void generate_section_names();
static void generate_section_names(void);
extern struct outhead outhead;
extern bool incore;
extern int flagword;
/*
@ -26,7 +31,7 @@ extern int flagword;
* flag was given.
* If this flag is given we don't need the string table either.
*/
beginoutput()
void beginoutput(void)
{
extern long NLChars, NGChars;
extern char *outputname;
@ -54,8 +59,7 @@ beginoutput()
* Generate names for all sections and put them after the global names.
* Section names are used for relocation.
*/
static void
generate_section_names()
static void generate_section_names(void)
{
register struct outname *name;
register int sectindex;
@ -80,7 +84,7 @@ generate_section_names()
* written out, and we just finish that.
* If we did, we write out our pieces of core.
*/
endoutput()
void endoutput(void)
{
if (!incore) {
if (!(flagword & SFLAG))

View file

@ -10,10 +10,11 @@ static char rcsid[] = "$Id$";
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include "error.h"
int infile; /* The current input file. */
rd_fatal()
void rd_fatal(void)
{
fatal("read error");
}

View file

@ -17,6 +17,7 @@ static char rcsid[] = "$Id$";
#include "defs.h"
#include "orig.h"
#include "sym.h"
#include "relocate.h"
#define UBYTE(x) ((x)&BYTEMASK)
@ -443,7 +444,7 @@ static void put_mips_valu(char* addr, uint32_t value)
* significance should be attributed to each byte.
* We do not check for overflow.
*/
static putvalu(uint32_t valu, char* addr, uint16_t type)
static void putvalu(uint32_t valu, char* addr, uint16_t type)
{
switch (type & RELSZ)
@ -547,11 +548,7 @@ long* valu_out; /* Out variable. */
* which the header is pointed to by `head'. Relocation is relative to the
* names in `names'; `relo' tells how to relocate.
*/
relocate(head, emit, names, relo, off) struct outhead* head;
char* emit;
struct outname names[];
struct outrelo* relo;
long off;
void relocate(struct outhead *head, char* emit, struct outname names[], struct outrelo *relo, long off)
{
long valu;
int sectindex = relo->or_sect - S_MIN;

View file

@ -17,51 +17,51 @@ static char rcsid[] = "$Id$";
#include <stdbool.h>
#include <string.h>
#include "arch.h"
#include "save.h"
#include "out.h"
#include "const.h"
#include "memory.h"
void
savemagic()
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)
{
register char *p;
if (!incore)
return;
if ((p = core_alloc(ALLOMODL, sizeof(int))) != (char *)0) {
if ((p = core_alloc(ALLOMODL, (long)sizeof(int))) != (char *)0) {
*(unsigned short *)p = AALMAG;
core_position += sizeof(int);
}
}
void
savehdr(hdr)
struct ar_hdr *hdr;
void savehdr(struct ar_hdr *hdr)
{
register char *p;
if (!incore)
return;
if ((p=core_alloc(ALLOMODL, sizeof(struct ar_hdr)))!=(char *)0) {
if ((p=core_alloc(ALLOMODL,(long)sizeof(struct ar_hdr)))!=(char *)0) {
*(struct ar_hdr *)p = *hdr;
core_position += int_align(sizeof(struct ar_hdr));
}
}
long NLChars = 0; /* Size of string area for local names. */
long NGChars = 0; /* Idem for global names. */
/*
* 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.
*/
ind_t
savechar(piece, off)
register int piece;
register ind_t off;
ind_t savechar(register int piece, register ind_t off)
{
register size_t len;
register ind_t newoff;
@ -90,9 +90,7 @@ savechar(piece, off)
* allocation, but the string of which name->on_foff is the offset may be
* destroyed, so we save that first.
*/
void
savelocal(name)
struct outname *name;
void savelocal(struct outname *name)
{
ind_t savindex;
struct outname *new;
@ -101,7 +99,7 @@ savelocal(name)
return;
new = (struct outname *)
core_alloc(ALLOLOCL, sizeof(struct outname));
core_alloc(ALLOLOCL, (long)sizeof(struct outname));
if (new != (struct outname *)0) {
*new = *name;
new->on_foff = savindex;

View file

@ -35,7 +35,7 @@ static char rcsid[] = "$Id$";
#define IND_DBUG(x) (IND_RELO(x) + sizeof(ind_t))
#endif /* SYMDBUG */
extern int infile;
extern FILE* infile;
extern int passnumber;
char *archname; /* Name of archive, if reading from archive. */
@ -66,9 +66,7 @@ static void scan_modul(void);
* In case of a plain file, the file pointer is repositioned after the
* examination. Otherwise it is at the beginning of the table of contents.
*/
int
getfile(filename)
char *filename;
int getfile(char* filename)
{
unsigned int rd_unsigned2();
struct ar_hdr archive_header;
@ -81,7 +79,7 @@ getfile(filename)
modulname = (char *)0;
if (passnumber == FIRST || !incore) {
if ((infile = open(filename, READ)) < 0)
if ((infile = fopen(filename, "rb")) == NULL)
fatal("can't read %s", filename);
magic_number = rd_unsigned2(infile);
} else {
@ -122,7 +120,7 @@ getfile(filename)
void closefile(char* filename)
{
if (passnumber == FIRST || !incore)
close(infile);
fclose(infile);
}
void get_archive_header(struct ar_hdr* archive_header)
@ -156,8 +154,7 @@ void get_modul(void)
* to keep everything in core is abandoned, but we will always put the header,
* the section table, and the name and string table into core.
*/
static void
scan_modul(void)
static void scan_modul(void)
{
bool space;
struct outhead *head;
@ -188,8 +185,7 @@ scan_modul(void)
* If possible, allocate space for the rest of the module. Return whether
* this was possible.
*/
static bool
all_alloc(void)
static bool all_alloc(void)
{
struct outhead head;
@ -208,9 +204,7 @@ all_alloc(void)
* First allocate the section table and read it in, then allocate the rest
* and return whether this succeeded.
*/
static bool
direct_alloc(head)
struct outhead *head;
static bool direct_alloc(struct outhead *head)
{
ind_t sectindex = IND_SECT(*head);
register struct outsect *sects;
@ -245,9 +239,7 @@ direct_alloc(head)
* Allocate space for the indirectly accessed pieces: the section contents and
* the relocation table, and put their indices in the right place.
*/
static bool
indirect_alloc(head)
struct outhead *head;
static bool indirect_alloc(struct outhead *head)
{
register int allopiece;
unsigned short nsect = head->oh_nsect;
@ -283,8 +275,7 @@ indirect_alloc(head)
* at offset `sectindex'. Put the offset of the allocated piece at offset
* `emitoff'.
*/
static bool
putemitindex(ind_t sectindex, ind_t emitoff, int allopiece)
static bool putemitindex(ind_t sectindex, ind_t emitoff, int allopiece)
{
long flen;
ind_t emitindex;
@ -358,8 +349,7 @@ putdbugindex(ind_t dbugoff, size_t ndbugbytes)
* Compute addresses and read in. Remember that the contents of the sections
* and also the relocation table are accessed indirectly.
*/
static void
get_indirect(struct outhead* head, struct outsect* sect)
static void get_indirect(struct outhead* head, struct outsect* sect)
{
register ind_t *emitindex;
register int nsect;
@ -385,7 +375,7 @@ get_indirect(struct outhead* head, struct outsect* sect)
void seek(long pos)
{
if (passnumber == FIRST || !incore)
lseek(infile, pos, 0);
fseek(infile, pos, SEEK_SET);
}
/*
@ -410,8 +400,7 @@ void skip_modul(struct outhead* head)
/*
* Read in what we need in pass 2, because we couldn't keep it in core.
*/
static void
read_modul(void)
static void read_modul(void)
{
struct outhead *head;
register struct outsect *sects;
@ -544,11 +533,7 @@ struct outrelo* nextrelo(void)
* Get the section contents in core of which the describing struct has index
* `sectindex'. `Head' points to the header of the module.
*/
char *
getemit(head, sects, sectindex)
struct outhead *head;
struct outsect *sects;
int sectindex;
char *getemit(struct outhead *head, struct outsect *sects, int sectindex)
{
char *ret;
ind_t off;
@ -573,11 +558,7 @@ getemit(head, sects, sectindex)
return address(ALLOEMIT + sectindex, off);
}
char *
getblk(totalsz, pblksz, sectindex)
long totalsz;
long *pblksz;
int sectindex;
char *getblk(long totalsz, long *pblksz, int sectindex)
{
char *ret;
long sz = (1L << 30);
@ -596,7 +577,7 @@ getblk(totalsz, pblksz, sectindex)
sz >>= 1;
}
fatal("no space for section contents");
return (char *) 0;
return (char *) NULL;
}
void endemit(char* emit)

View file

@ -4,6 +4,11 @@
*/
/* $Id$ */
#ifndef __SCAN_H_INCLUDED__
#define __SCAN_H_INCLUDED__
#include "arch.h"
/*
* Offsets of the pieces of the input module in core.
*/
@ -26,3 +31,12 @@ extern struct outrelo* nextrelo(void);
extern char* getemit(struct outhead* head, struct outsect* sects, int sectindex);
extern char* getblk(long totalsz, long* pblksz, int sectindex);
extern void endemit(char* emit);
/*
* Open the file with name `filename' (if necessary) and examine the first
* few bytes to see if it's a plain file or an archive.
* In case of a plain file, the file pointer is repositioned after the
* examination. Otherwise it is at the beginning of the table of contents.
*/
int getfile(char* filename);
#endif /* __SCAN_H_INCLUDED__ */

View file

@ -16,6 +16,7 @@ static char rcsid[] = "$Id$";
#include <stdbool.h>
#include "out.h"
#include "const.h"
#include "error.h"
#include "memory.h"
#include "debug.h"
#include "sym.h"
@ -41,7 +42,7 @@ unsigned short NGlobals = 0; /* Number of global names. */
/*
* Initialize the symbol table. All indices should be noticeably invalid.
*/
init_symboltable()
void init_symboltable(void)
{
register ind_t *rap;
@ -56,10 +57,7 @@ init_symboltable()
* in this element of the list is returned. When a match cannot be found,
* NIL is returned.
*/
struct outname *
searchname(string, hashval)
char *string;
int hashval;
struct outname *searchname(char *string, int hashval)
{
register char *rcp;
register char *namestring;
@ -105,9 +103,9 @@ void entername(struct outname* name, int hashval)
debug("entername %s %d %x %x", modulptr((ind_t)name->on_foff), hashval, name->on_type, name->on_desc);
savindex = savechar(ALLOGCHR, (ind_t)name->on_foff);
symindex = hard_alloc(ALLOSYMB, sizeof(struct symbol));
symindex = hard_alloc(ALLOSYMB, (long)sizeof(struct symbol));
debug("; %ld\n", symindex, 0, 0, 0);
namindex = hard_alloc(ALLOGLOB, sizeof(struct outname));
namindex = hard_alloc(ALLOGLOB, (long)sizeof(struct outname));
if (savindex == BADOFF || symindex == BADOFF || namindex == BADOFF)
fatal("symbol table overflow");
sym = (struct symbol *)address(ALLOSYMB, symindex);
@ -124,9 +122,7 @@ void entername(struct outname* name, int hashval)
* Return the index of `name' in the symbol table in the order in which
* it was entered. We need a REAL index, not a byte offset.
*/
unsigned
indexof(name)
struct outname *name;
unsigned int indexof(struct outname *name)
{
return name - (struct outname *)address(ALLOGLOB, (ind_t)0);
}
@ -136,9 +132,7 @@ indexof(name)
* 0 <= hash(p) < NHASH, so it can - and will - be used
* as index in a hash table.
*/
int
hash(p)
register char *p;
int hash(register char* p)
{
register unsigned short h = 0;
register int c;

View file

@ -1,9 +1,27 @@
#ifndef SYM_H
#define SYM_H
#ifndef __SYM_H_INCLUDED__
#define __SYM_H_INCLUDED__
extern unsigned short NLocals; /* Number of local names to be saved. */
extern unsigned short NGlobals; /* Number of global names. */
extern void entername(struct outname* name, int hashval);
/** Enter a new name in the symbol table.*/
void entername(struct outname* name, int hashval);
/** Initialize the symbol table. All indices should be noticeably invalid. */
void init_symboltable(void);
/** Return the hash value of the string represented in p. */
int hash(register char* p);
/** Return the index of `name' in the symbol table. */
unsigned int indexof(struct outname *name);
/*
* Search for `string' in the symboltable. The hash value of `string' is in
* `hashval'. The linked list belonging to the entry of hashval
* in the hash table is followed. If the names match, a pointer to the outname
* in this element of the list is returned. When a match cannot be found,
* NIL is returned.
*/
struct outname *searchname(char *string, int hashval);
#endif
#endif /* __SYM_H_INCLUDED__ */

View file

@ -13,26 +13,32 @@ static char rcsid[] = "$Id$";
#include <stdbool.h>
#include <string.h>
#include "out.h"
#include "object.h"
#include "const.h"
#include "memory.h"
#include "sym.h"
#include "error.h"
#include "write.h"
extern struct outhead outhead;
extern struct outsect outsect[];
extern int flagword;
extern bool incore;
wr_fatal()
static long off_char;
void wr_fatal(void)
{
fatal("write error");
}
static long off_char;
/*
* Open the output file according to the chosen strategy.
* Write away the header and section table: they will not change anymore.
*/
begin_write()
void begin_write(void)
{
register struct outhead *hd = &outhead;
@ -42,9 +48,7 @@ begin_write()
off_char = OFF_CHAR(*hd);
}
static struct outname *
sectname(sectindex)
int sectindex;
static struct outname *sectname(int sectindex)
{
static struct outname namebuf;
@ -59,7 +63,7 @@ sectname(sectindex)
/*
* Write out the symbol table and the section names.
*/
end_write()
void end_write(void)
{
register struct outname *name;
register int sectindex;
@ -77,18 +81,14 @@ end_write()
wrt_name(sectname(sectindex), 1);
}
wrt_emit(emit, sectindex, cnt)
char *emit;
int sectindex;
long cnt;
void wrt_emit(char *emit, int sectindex, long cnt)
{
wr_outsect(sectindex);
wr_emit(emit, cnt);
}
wrt_nulls(sectindex, cnt)
register long cnt;
void wrt_nulls(int sectindex, register long cnt)
{
static char nullbuf[BUFSIZ];
@ -100,8 +100,7 @@ wrt_nulls(sectindex, cnt)
}
}
wrt_name(name, writename)
register struct outname *name;
void wrt_name(register struct outname *name, int writename)
{
assert(!incore);
assert(!(flagword & SFLAG));