Update generic part of the AS

This commit is contained in:
Godzil 2013-03-21 01:32:58 +01:00 committed by Manoël Trapier
parent b31c94cf32
commit a39e88ecca
7 changed files with 334 additions and 282 deletions

View File

@ -83,17 +83,21 @@ _include <stdio.h>
_include <string.h> _include <string.h>
_include <ctype.h> _include <ctype.h>
_include <signal.h> _include <signal.h>
_include <unistd.h>
#else #else
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdarg.h>
#include <ctype.h> #include <ctype.h>
#include <signal.h> #include <signal.h>
#include <unistd.h>
#endif #endif
#ifdef ASLD #ifdef ASLD
#include "arch.h" #include "arch.h"
#endif #endif
#include "object.h"
#include "out.h" #include "out.h"
#if DEBUG == 0 #if DEBUG == 0
@ -262,5 +266,3 @@ typedef struct sect_t sect_t;
#define MACHREL_BWR (0) #define MACHREL_BWR (0)
#endif #endif
#endif #endif
extern FILE *fopen(); /* some systems don't have this in stdio.h */

View File

@ -104,17 +104,81 @@ extern struct outhead outhead;
extern int curr_token; extern int curr_token;
/* forward function declarations */ /* forward function declarations */
int yyparse();
/* ========== comm4.c prototypes =========== */
void stop(int signal);
int main(int argc, char *argv[]);
int pass_1(int argc, char *argv[]);
void parse(char *s);
void pass_23(int n);
void newmodule(char *s);
void setupoutput(void);
void commfinish(void);
/* ========== comm5.c prototypes =========== */
int yylex(void);
void putval(int c);
int getval(int c);
int nextchar(void);
void readcode(int n);
int induo(int c);
int inident(int c);
int innumber(int c);
int instring(int termc);
int inescape(void);
int infbsym(char *p);
int hash(char *p);
item_t *item_search(char *p);
void item_insert(item_t *ip, int h);
item_t *item_alloc(int typ);
item_t *fb_alloc(int lab);
item_t *fb_shift(int lab);
#ifdef ASLD #ifdef ASLD
extern char *readident(); char *readident(int c);
#endif #endif
extern char *remember();
extern item_t *fb_shift(); /* ========== comm6.c prototypes =========== */
extern item_t *fb_alloc(); void newequate(item_t *ip, int typ);
extern item_t *item_alloc(); void newident(item_t *ip, int typ);
extern item_t *item_search(); void newlabel(item_t *ip);
extern valu_t load(); void newsect(item_t *ip);
extern FILE *ffcreat(); void newbase(valu_t base);
extern FILE *fftemp(); void newcomm(item_t *ip, valu_t val);
void switchsect(int newtyp);
void align(valu_t bytes);
long new_string(char *s);
void newsymb(char *name, int type, int desc, valu_t valu);
void new_common(item_t *ip);
#ifdef RELOCATION
void newrelo(int s, int n);
#endif
/* ========== comm7.c prototypes =========== */
valu_t load(item_t *ip);
int store(item_t *ip, valu_t val);
char *remember(char *s);
int combine(int typ1, int typ2, int op);
int small(int fitsmall, int gain);
void emit1(int arg);
void emit2(int arg);
void emit4(long arg);
void emitx(valu_t val, int n);
void emitstr(int zero);
void ffreopen(char *s, FILE *f);
FILE *ffcreat(char *s);
FILE *fftemp(char *path, char *tail);
void yyerror(char *str);
int printx(int ndig, valu_t val);
void nosect(void);
void wr_fatal(void);
void fatal(char *s, ...);
void assert1(void);
void serror(char *s, ...);
void warning(char *s, ...);
void diag(char *tail, char *s, ...);
void nofit(void);
void listline(int textline);
/* ========== Machine dependent C declarations ========== */ /* ========== Machine dependent C declarations ========== */

View File

@ -23,28 +23,28 @@ struct outhead outhead = {
#include "y.tab.h" #include "y.tab.h"
item_t keytab[] = { item_t keytab[] = {
0, EXTERN, 0, ".define", { 0, EXTERN, 0, ".define" },
0, EXTERN, 0, ".extern", { 0, EXTERN, 0, ".extern" },
0, DOT, 0, ".", { 0, DOT, 0, "." },
0, DATA, 1, ".data1", { 0, DATA, 1, ".data1" },
0, DATA, 2, ".data2", { 0, DATA, 2, ".data2" },
0, DATA, 4, ".data4", { 0, DATA, 4, ".data4" },
0, ASCII, 0, ".ascii", { 0, ASCII, 0, ".ascii" },
0, ASCII, 1, ".asciz", { 0, ASCII, 1, ".asciz" },
0, ALIGN, 0, ".align", { 0, ALIGN, 0, ".align" },
0, ASSERT, 0, ".assert", { 0, ASSERT, 0, ".assert" },
0, SPACE, 0, ".space", { 0, SPACE, 0, ".space" },
0, COMMON, 0, ".comm", { 0, COMMON, 0, ".comm" },
0, SECTION, 0, ".sect", { 0, SECTION, 0, ".sect" },
0, BASE, 0, ".base", { 0, BASE, 0, ".base" },
0, SYMB, 0, ".symb", { 0, SYMB, 0, ".symb" },
0, SYMD, 0, ".symd", { 0, SYMD, 0, ".symd" },
0, LINE, 0, ".line", { 0, LINE, 0, ".line" },
0, FILe, 0, ".file", { 0, FILe, 0, ".file" },
#ifdef LISTING #ifdef LISTING
0, LIST, 0, ".nolist", { 0, LIST, 0, ".nolist" },
0, LIST, 1, ".list", { 0, LIST, 1, ".list" },
#endif #endif
#include "mach3.c" #include "mach3.c"
0, 0, 0, 0 { 0, 0, 0, 0 }
}; };

View File

@ -11,7 +11,6 @@
* Johan Stevenson, Han Schaminee and Hans de Vries * Johan Stevenson, Han Schaminee and Hans de Vries
* Philips S&I, T&M, PMDS, Eindhoven * Philips S&I, T&M, PMDS, Eindhoven
*/ */
#include "comm0.h" #include "comm0.h"
#include "comm1.h" #include "comm1.h"
#include "y.tab.h" #include "y.tab.h"
@ -20,7 +19,8 @@ extern YYSTYPE yylval;
/* ========== Machine independent C routines ========== */ /* ========== Machine independent C routines ========== */
void stop() { void stop(int signal)
{
#if DEBUG < 2 #if DEBUG < 2
unlink(temppath); unlink(temppath);
#ifdef LISTING #ifdef LISTING
@ -30,11 +30,10 @@ void stop() {
exit(nerrors != 0); exit(nerrors != 0);
} }
main(argc, argv) int main(int argc, char *argv[])
char **argv;
{ {
register char *p; char *p;
register i; int i;
static char sigs[] = { static char sigs[] = {
SIGHUP, SIGINT, SIGQUIT, SIGTERM, 0 SIGHUP, SIGINT, SIGQUIT, SIGTERM, 0
}; };
@ -49,7 +48,7 @@ char **argv;
} }
progname = *argv++; argc--; progname = *argv++; argc--;
for (p = sigs; i = *p++; ) for (p = sigs; (i = *p++); )
if (signal(i, SIG_IGN) != SIG_IGN) if (signal(i, SIG_IGN) != SIG_IGN)
signal(i, stop); signal(i, stop);
for (i = 0; i < argc; i++) { for (i = 0; i < argc; i++) {
@ -122,20 +121,20 @@ char **argv;
#endif #endif
pass_23(PASS_3); pass_23(PASS_3);
wr_close(); wr_close();
stop(); stop(0);
return 0;
} }
/* ---------- pass 1: arguments, modules, archives ---------- */ /* ---------- pass 1: arguments, modules, archives ---------- */
pass_1(argc, argv) int pass_1(int argc, char *argv[])
char **argv;
{ {
register char *p; char *p;
register item_t *ip; item_t *ip;
#ifdef ASLD #ifdef ASLD
char armagic[2]; char armagic[2];
#else #else
register nfile = 0; int nfile = 0;
#endif #endif
#ifdef THREE_PASS #ifdef THREE_PASS
@ -195,7 +194,7 @@ char **argv;
machfinish(PASS_1); machfinish(PASS_1);
#ifdef ASLD #ifdef ASLD
if (unresolved) { if (unresolved) {
register int i; int i;
nerrors++; nerrors++;
fflush(stdout); fflush(stdout);
@ -217,12 +216,14 @@ char **argv;
fatal("no source file"); fatal("no source file");
*/ */
#endif #endif
return 0;
} }
#ifdef ASLD #ifdef ASLD
archive() { void archive()
register long offset; {
long offset;
struct ar_hdr header; struct ar_hdr header;
char getsize[AR_TOTAL]; char getsize[AR_TOTAL];
@ -254,14 +255,14 @@ archive() {
archmode = 0; archmode = 0;
} }
needed() int needed()
{ {
register c, first; c, first;
register item_t *ip; item_t *ip;
register need; int need;
#ifdef LISTING #ifdef LISTING
register save; int save;
save = listflag; listflag = 0; save = listflag; listflag = 0;
#endif #endif
@ -306,12 +307,11 @@ needed()
} }
#endif /* ASLD */ #endif /* ASLD */
parse(s) void parse(char *s)
char *s;
{ {
register i; int i;
register item_t *ip; item_t *ip;
register char *p; char *p;
for (p = s; *p; ) for (p = s; *p; )
if (*p++ == '/') if (*p++ == '/')
@ -371,16 +371,16 @@ char *s;
} }
} }
pass_23(n) void pass_23(int n)
{ {
register i; int i;
#ifdef ASLD #ifdef ASLD
register ADDR_T base = 0; ADDR_T base = 0;
#endif #endif
register sect_t *sp; sect_t *sp;
if (nerrors) if (nerrors)
stop(); stop(0);
pass = n; pass = n;
#ifdef LISTING #ifdef LISTING
listmode >>= 3; listmode >>= 3;
@ -430,8 +430,7 @@ pass_23(n)
machfinish(n); machfinish(n);
} }
newmodule(s) void newmodule(char *s)
char *s;
{ {
static char nmbuf[STRINGMAX]; static char nmbuf[STRINGMAX];
@ -458,12 +457,12 @@ char *s;
#endif #endif
} }
setupoutput() void setupoutput()
{ {
register sect_t *sp; sect_t *sp;
register long off; long off;
struct outsect outsect; struct outsect outsect;
register struct outsect *pos = &outsect; struct outsect *pos = &outsect;
if (! wr_open(aoutpath)) { if (! wr_open(aoutpath)) {
fatal("can't create %s", aoutpath); fatal("can't create %s", aoutpath);
@ -493,15 +492,15 @@ setupoutput()
outhead.oh_nchar = off; /* see newsymb() */ outhead.oh_nchar = off; /* see newsymb() */
} }
commfinish() void commfinish()
{ {
#ifndef ASLD #ifndef ASLD
register int i; int i;
#endif #endif
register struct common_t *cp; struct common_t *cp;
register item_t *ip; item_t *ip;
register sect_t *sp; sect_t *sp;
register valu_t addr; valu_t addr;
switchsect(S_UND); switchsect(S_UND);
/* /*

View File

@ -11,9 +11,9 @@
extern YYSTYPE yylval; extern YYSTYPE yylval;
yylex() int yylex()
{ {
register c; int c;
if (pass == PASS_1) { if (pass == PASS_1) {
/* scan the input file */ /* scan the input file */
@ -68,11 +68,11 @@ yylex()
return(c); return(c);
} }
putval(c) void putval(int c)
{ {
register valu_t v; valu_t v;
register n = 0; int n = 0;
register char *p = 0; char *p = 0;
assert(c >= 256 && c < 256+128); assert(c >= 256 && c < 256+128);
switch (c) { switch (c) {
@ -141,11 +141,11 @@ putval(c)
putc(*p++, tempfile); putc(*p++, tempfile);
} }
getval(c) int getval(int c)
{ {
register n = 0; int n = 0;
register valu_t v; valu_t v;
register char *p = 0; char *p = 0;
switch (c) { switch (c) {
case CODE1: case CODE1:
@ -206,9 +206,9 @@ getval(c)
/* ---------- lexical scan in pass 1 ---------- */ /* ---------- lexical scan in pass 1 ---------- */
nextchar() int nextchar()
{ {
register c; int c;
if (peekc != -1) { if (peekc != -1) {
c = peekc; c = peekc;
@ -230,9 +230,9 @@ nextchar()
return(c); return(c);
} }
readcode(n) void readcode(int n)
{ {
register c; int c;
yylval.y_valu = 0; yylval.y_valu = 0;
do { do {
@ -249,8 +249,7 @@ readcode(n)
} while (--n); } while (--n);
} }
induo(c) int induo(int c)
register c;
{ {
static short duo[] = { static short duo[] = {
('='<<8) | '=', OP_EQ, ('='<<8) | '=', OP_EQ,
@ -262,7 +261,7 @@ register c;
('|'<<8) | '|', OP_OO, ('|'<<8) | '|', OP_OO,
('&'<<8) | '&', OP_AA, ('&'<<8) | '&', OP_AA,
}; };
register short *p; short *p;
c = (c<<8) | nextchar(); c = (c<<8) | nextchar();
for (p = duo; *p; p++) for (p = duo; *p; p++)
@ -274,12 +273,11 @@ register c;
static char name[NAMEMAX+1]; static char name[NAMEMAX+1];
inident(c) int inident(int c)
register c;
{ {
register char *p = name; char *p = name;
register item_t *ip; item_t *ip;
register n = NAMEMAX; int n = NAMEMAX;
do { do {
if (--n >= 0) if (--n >= 0)
@ -305,12 +303,10 @@ register c;
} }
#ifdef ASLD #ifdef ASLD
char * char *readident(int c)
readident(c)
register c;
{ {
register n = NAMEMAX; int n = NAMEMAX;
register char *p = name; char *p = name;
do { do {
if (--n >= 0) if (--n >= 0)
@ -323,11 +319,10 @@ register c;
} }
#endif #endif
innumber(c) int innumber(int c)
register c;
{ {
register char *p; char *p;
register radix; int radix;
static char num[20+1]; static char num[20+1];
p = num; p = num;
@ -359,7 +354,7 @@ register c;
if (radix != 16 && (c == 'f' || c == 'b')) if (radix != 16 && (c == 'f' || c == 'b'))
return(infbsym(num)); return(infbsym(num));
yylval.y_valu = 0; yylval.y_valu = 0;
while (c = *p++) { while ( (c = *p++) ) {
if (c > '9') if (c > '9')
c -= ('a' - '9' - 1); c -= ('a' - '9' - 1);
c -= '0'; c -= '0';
@ -370,10 +365,10 @@ register c;
return(NUMBER); return(NUMBER);
} }
instring(termc) int instring(int termc)
{ {
register char *p; char *p;
register c; int c;
static int maxstring = 0; static int maxstring = 0;
if (! maxstring) { if (! maxstring) {
@ -409,9 +404,9 @@ instring(termc)
return(STRING); return(STRING);
} }
inescape() int inescape()
{ {
register c, j, r; int c, j, r;
c = nextchar(); c = nextchar();
if (c >= '0' && c <= '7') { if (c >= '0' && c <= '7') {
@ -439,11 +434,10 @@ inescape()
return(c); return(c);
} }
infbsym(p) int infbsym(char *p)
register char *p;
{ {
register lab; int lab;
register item_t *ip; item_t *ip;
lab = *p++ - '0'; lab = *p++ - '0';
if ((unsigned)lab < 10) { if ((unsigned)lab < 10) {
@ -466,26 +460,23 @@ ok:
return(FBSYM); return(FBSYM);
} }
hash(p) int hash(char *p)
register char *p;
{ {
register unsigned short h; unsigned short h;
register c; int c;
h = 0; h = 0;
while (c = *p++) { while ( (c = *p++) ) {
h <<= 2; h <<= 2;
h += c; h += c;
} }
return(h % H_SIZE); return(h % H_SIZE);
} }
item_t * item_t *item_search(char *p)
item_search(p)
char *p;
{ {
register h; int h;
register item_t *ip; item_t *ip;
for (h = hash(p); h < H_TOTAL; h += H_SIZE) { for (h = hash(p); h < H_TOTAL; h += H_SIZE) {
ip = hashtab[h]; ip = hashtab[h];
@ -500,17 +491,15 @@ done:
return(ip); return(ip);
} }
item_insert(ip, h) void item_insert(item_t *ip, int h)
item_t *ip;
{ {
ip->i_next = hashtab[h]; ip->i_next = hashtab[h];
hashtab[h] = ip; hashtab[h] = ip;
} }
item_t * item_t *item_alloc(int typ)
item_alloc(typ)
{ {
register item_t *ip; item_t *ip;
static nleft = 0; static nleft = 0;
static item_t *next; static item_t *next;
@ -528,11 +517,9 @@ item_alloc(typ)
return(ip); return(ip);
} }
item_t * item_t *fb_alloc(int lab)
fb_alloc(lab)
register lab;
{ {
register item_t *ip, *p; item_t *ip, *p;
ip = item_alloc(S_UND); ip = item_alloc(S_UND);
p = fb_ptr[FB_TAIL+lab]; p = fb_ptr[FB_TAIL+lab];
@ -544,18 +531,22 @@ register lab;
return(ip); return(ip);
} }
item_t * item_t *fb_shift(int lab)
fb_shift(lab)
register lab;
{ {
register item_t *ip; item_t *ip;
ip = fb_ptr[FB_FORW+lab]; ip = fb_ptr[FB_FORW+lab];
if (ip == 0) if (ip == 0)
{
if (pass == PASS_1) if (pass == PASS_1)
{
ip = fb_alloc(lab); ip = fb_alloc(lab);
}
else else
{
ip = fb_ptr[FB_HEAD+lab]; ip = fb_ptr[FB_HEAD+lab];
}
}
fb_ptr[FB_BACK+lab] = ip; fb_ptr[FB_BACK+lab] = ip;
fb_ptr[FB_FORW+lab] = ip->i_next; fb_ptr[FB_FORW+lab] = ip->i_next;
return(ip); return(ip);

View File

@ -12,9 +12,7 @@
#include "comm1.h" #include "comm1.h"
#include "y.tab.h" #include "y.tab.h"
newequate(ip, typ) void newequate(item_t *ip, int typ)
register item_t *ip;
register int typ;
{ {
typ &= ~S_EXT; typ &= ~S_EXT;
if (typ & S_COM) if (typ & S_COM)
@ -34,10 +32,9 @@ register int typ;
newident(ip, typ); newident(ip, typ);
} }
newident(ip, typ) void newident(item_t *ip, int typ)
register item_t *ip;
{ {
register flag; int flag;
#ifdef GENLAB #ifdef GENLAB
static char genlab[] = GENLAB; static char genlab[] = GENLAB;
#endif /* GENLAB */ #endif /* GENLAB */
@ -74,12 +71,11 @@ register item_t *ip;
); );
} }
newlabel(ip) void newlabel(item_t *ip)
register item_t *ip;
{ {
#if DEBUG != 0 #if DEBUG != 0
#ifdef THREE_PASS #ifdef THREE_PASS
register ADDR_T oldval = ip->i_valu; ADDR_T oldval = ip->i_valu;
#endif #endif
#endif #endif
@ -94,11 +90,10 @@ register item_t *ip;
#endif #endif
} }
newsect(ip) void newsect(item_t *ip)
register item_t *ip;
{ {
register int typ; int typ;
register sect_t *sp = NULL; sect_t *sp = NULL;
typ = ip->i_type & S_TYP; typ = ip->i_type & S_TYP;
if (typ == S_UND) { if (typ == S_UND) {
@ -132,11 +127,10 @@ register item_t *ip;
} }
/*ARGSUSED*/ /*ARGSUSED*/
newbase(base) void newbase(valu_t base)
valu_t base;
{ {
#ifdef ASLD #ifdef ASLD
register sect_t *sp; sect_t *sp;
if ((sp = DOTSCT) == NULL) if ((sp = DOTSCT) == NULL)
nosect(); nosect();
@ -160,9 +154,7 @@ valu_t base;
* - maximum length of .comm is recorded in i_valu during PASS_1 * - maximum length of .comm is recorded in i_valu during PASS_1
* - i_valu is used for relocation info during PASS_3 * - i_valu is used for relocation info during PASS_3
*/ */
newcomm(ip, val) void newcomm(item_t *ip, valu_t val)
register item_t *ip;
valu_t val;
{ {
if (pass == PASS_1) { if (pass == PASS_1) {
if (DOTSCT == NULL) if (DOTSCT == NULL)
@ -183,12 +175,11 @@ valu_t val;
} }
} }
switchsect(newtyp) void switchsect(int newtyp)
int newtyp;
{ {
register sect_t *sp; sect_t *sp;
if (sp = DOTSCT) if ( (sp = DOTSCT) )
sp->s_size = DOTVAL - sp->s_base; sp->s_size = DOTVAL - sp->s_base;
if (newtyp == S_UND) { if (newtyp == S_UND) {
DOTSCT = NULL; DOTSCT = NULL;
@ -202,27 +193,35 @@ int newtyp;
DOTTYP = newtyp; DOTTYP = newtyp;
} }
align(bytes) void align(valu_t bytes)
valu_t bytes;
{ {
register valu_t gap; valu_t gap;
register sect_t *sp; sect_t *sp;
if ((sp = DOTSCT) == NULL) if ((sp = DOTSCT) == NULL)
nosect(); nosect();
if (bytes == 0) if (bytes == 0)
bytes = ALIGNWORD; bytes = ALIGNWORD;
if (sp->s_lign % bytes) if (sp->s_lign % bytes)
{
if (bytes % sp->s_lign) if (bytes % sp->s_lign)
{
serror("illegal alignment"); serror("illegal alignment");
}
else else
{
sp->s_lign = bytes; sp->s_lign = bytes;
}
}
if (pass == PASS_1) if (pass == PASS_1)
{
/* /*
* be pessimistic: biggest gap possible * be pessimistic: biggest gap possible
*/ */
gap = bytes - 1; gap = bytes - 1;
else { }
else
{
/* /*
* calculate gap correctly; * calculate gap correctly;
* will be the same in PASS_2 and PASS_3 * will be the same in PASS_2 and PASS_3
@ -242,7 +241,7 @@ valu_t bytes;
} }
#ifdef RELOCATION #ifdef RELOCATION
newrelo(s, n) void newrelo(int s, int n)
{ {
int iscomm; int iscomm;
struct outrelo outrelo; struct outrelo outrelo;
@ -270,16 +269,19 @@ newrelo(s, n)
s &= ~S_COM; s &= ~S_COM;
if ((n & RELPC) == 0 && ((s & ~S_VAR) == S_ABS)) if ((n & RELPC) == 0 && ((s & ~S_VAR) == S_ABS))
return; return;
if ((n & RELPC) != 0 && s == DOTTYP if ((n & RELPC) != 0 && s == DOTTYP
#ifndef ASLD #ifndef ASLD
&& ! iscomm && ! iscomm
#endif #endif
) )
return; return;
if (pass != PASS_3) { if (pass != PASS_3) {
outhead.oh_nrelo++; outhead.oh_nrelo++;
return; return;
} }
s &= ~S_VAR; s &= ~S_VAR;
outrelo.or_type = (char)n; outrelo.or_type = (char)n;
outrelo.or_sect = (char)DOTTYP; outrelo.or_sect = (char)DOTTYP;
@ -290,13 +292,16 @@ newrelo(s, n)
relonami = 0; relonami = 0;
} else } else
#endif #endif
if (s < S_MIN) { if (s < S_MIN)
{
assert(s == S_ABS); assert(s == S_ABS);
/* /*
* use first non existing entry (argh) * use first non existing entry (argh)
*/ */
outrelo.or_nami = outhead.oh_nname; outrelo.or_nami = outhead.oh_nname;
} else { }
else
{
/* /*
* section symbols are at the end * section symbols are at the end
*/ */
@ -310,9 +315,7 @@ newrelo(s, n)
} }
#endif #endif
long long new_string(char *s)
new_string(s)
char *s;
{ {
long r = 0; long r = 0;
@ -326,9 +329,7 @@ new_string(s)
return r; return r;
} }
newsymb(name, type, desc, valu) void newsymb(char *name, int type, int desc, valu_t valu)
register char *name;
valu_t valu;
{ {
struct outname outname; struct outname outname;
@ -350,10 +351,9 @@ valu_t valu;
wr_name(&outname, 1); wr_name(&outname, 1);
} }
new_common(ip) void new_common(item_t *ip)
item_t *ip;
{ {
register struct common_t *cp; struct common_t *cp;
static nleft = 0; static nleft = 0;
static struct common_t *next; static struct common_t *next;

View File

@ -12,12 +12,10 @@
#include "comm1.h" #include "comm1.h"
#include "y.tab.h" #include "y.tab.h"
valu_t valu_t load(item_t *ip)
load(ip)
register item_t *ip;
{ {
#ifdef ASLD #ifdef ASLD
register typ; int typ;
typ = ip->i_type & S_TYP; typ = ip->i_type & S_TYP;
if ((typ -= S_MIN) < 0) /* S_UND or S_ABS */ if ((typ -= S_MIN) < 0) /* S_UND or S_ABS */
@ -36,12 +34,10 @@ register item_t *ip;
#endif #endif
} }
store(ip, val) int store(item_t *ip, valu_t val)
register item_t *ip;
valu_t val;
{ {
#ifdef ASLD #ifdef ASLD
register typ; int typ;
typ = ip->i_type & S_TYP; typ = ip->i_type & S_TYP;
if ((typ -= S_MIN) >= 0) if ((typ -= S_MIN) >= 0)
@ -55,12 +51,10 @@ valu_t val;
return(1); return(1);
} }
char * char *remember(char *s)
remember(s)
register char *s;
{ {
register char *p; char *p;
register n; int n;
static nleft = 0; static nleft = 0;
static char *next; static char *next;
@ -77,15 +71,14 @@ register char *s;
assert(nleft >= 0); assert(nleft >= 0);
} }
p = next; p = next;
while (*p++ = *s++) while ( (*p++ = *s++) )
; ;
s = next; s = next;
next = p; next = p;
return(s); return(s);
} }
combine(typ1, typ2, op) int combine(int typ1, int typ2, int op)
register typ1, typ2;
{ {
switch (op) { switch (op) {
case '+': case '+':
@ -121,12 +114,11 @@ register typ1, typ2;
} }
#ifdef LISTING #ifdef LISTING
printx(ndig, val) int printx(int ndig, valu_t val)
valu_t val;
{ {
static char buf[8]; static char buf[8];
register char *p; char *p;
register c, n; int c, n;
p = buf; n = ndig; p = buf; n = ndig;
do { do {
@ -134,7 +126,7 @@ valu_t val;
val >>= 4; val >>= 4;
} while (--n); } while (--n);
do { do {
c = "0123456789ABCDEF"[*--p]; c = "0123456789ABCDEF"[*(unsigned char *)--p];
putchar(c); putchar(c);
} while (p > buf); } while (p > buf);
return(ndig); return(ndig);
@ -142,9 +134,9 @@ valu_t val;
#endif #endif
#ifdef LISTING #ifdef LISTING
listline(textline) void listline(int textline)
{ {
register c; int c;
if ((listflag & 4) && (c = getc(listfile)) != '\n' && textline) { if ((listflag & 4) && (c = getc(listfile)) != '\n' && textline) {
if (listcolm >= 24) if (listcolm >= 24)
@ -175,10 +167,10 @@ listline(textline)
#define PBITTABSZ 128 #define PBITTABSZ 128
static char *pbittab[PBITTABSZ]; static char *pbittab[PBITTABSZ];
small(fitsmall, gain) int small(int fitsmall, int gain)
{ {
register bit; int bit;
register char *p; char *p;
if (DOTSCT == NULL) if (DOTSCT == NULL)
nosect(); nosect();
@ -225,12 +217,13 @@ small(fitsmall, gain)
return(*p & bit); return(*p & bit);
} }
/*NOTREACHED*/ /*NOTREACHED*/
return 0;
} }
#endif #endif
/* ---------- output ---------- */ /* ---------- output ---------- */
emit1(arg) void emit1(int arg)
{ {
static int olddottyp = -1; static int olddottyp = -1;
#ifdef LISTING #ifdef LISTING
@ -268,8 +261,7 @@ emit1(arg)
DOTVAL++; DOTVAL++;
} }
emit2(arg) void emit2(int arg)
int arg;
{ {
#ifdef BYTES_REVERSED #ifdef BYTES_REVERSED
emit1((arg>>8)); emit1(arg); emit1((arg>>8)); emit1(arg);
@ -278,8 +270,7 @@ int arg;
#endif #endif
} }
emit4(arg) void emit4(long arg)
long arg;
{ {
#ifdef WORDS_REVERSED #ifdef WORDS_REVERSED
emit2((int)(arg>>16)); emit2((int)(arg)); emit2((int)(arg>>16)); emit2((int)(arg));
@ -288,9 +279,7 @@ long arg;
#endif #endif
} }
emitx(val, n) void emitx(valu_t val, int n)
valu_t val;
int n;
{ {
switch (n) { switch (n) {
case 1: case 1:
@ -314,10 +303,10 @@ int n;
} }
} }
emitstr(zero) void emitstr(int zero)
{ {
register i; int i;
register char *p; char *p;
p = stringbuf; p = stringbuf;
i = stringlen; i = stringlen;
@ -329,17 +318,13 @@ emitstr(zero)
/* ---------- Error checked file I/O ---------- */ /* ---------- Error checked file I/O ---------- */
ffreopen(s, f) void ffreopen(char *s, FILE *f)
char *s;
FILE *f;
{ {
if (freopen(s, "r", f) == NULL) if (freopen(s, "r", f) == NULL)
fatal("can't reopen %s", s); fatal("can't reopen %s", s);
} }
FILE * FILE *ffcreat(char *s)
ffcreat(s)
char *s;
{ {
FILE *f; FILE *f;
@ -353,11 +338,9 @@ char *s;
#endif #endif
char *tmp_dir = TMPDIR; char *tmp_dir = TMPDIR;
FILE * FILE *fftemp(char *path, char *tail)
fftemp(path, tail)
char *path, *tail;
{ {
register char *dir; char *dir;
if ((dir = getenv("TMPDIR")) == NULL) if ((dir = getenv("TMPDIR")) == NULL)
dir = tmp_dir; dir = tmp_dir;
@ -368,72 +351,85 @@ char *path, *tail;
/* ---------- Error handling ---------- */ /* ---------- Error handling ---------- */
/*VARARGS*/ /*VARARGS*/
yyerror(){} /* we will do our own error printing */ void yyerror(char *str){} /* we will do our own error printing */
nosect()
{
fatal("no sections");
}
wr_fatal()
{
fatal("write error");
}
/* VARARGS1 */ /* VARARGS1 */
fatal(s, a1, a2, a3, a4) static void vdiag(char *tail, char *s, va_list ap)
char *s;
{
nerrors++;
diag(" (fatal)\n", s, a1, a2, a3, a4);
stop();
}
#if DEBUG == 2
assert2(file, line)
char *file;
{
fatal("assertion failed (%s, %d)", file, line);
}
#endif
#if DEBUG == 1
assert1()
{
diag(" (fatal)\n", "assertion failed");
abort();
}
#endif
/* VARARGS1 */
serror(s, a1, a2, a3, a4)
char *s;
{
nerrors++;
diag("\n", s, a1, a2, a3, a4);
}
/* VARARGS1 */
warning(s, a1, a2, a3, a4)
char *s;
{
diag(" (warning)\n", s, a1, a2, a3, a4);
}
/* VARARGS1 */
diag(tail, s, a1, a2, a3, a4)
char *tail, *s;
{ {
fflush(stdout); fflush(stdout);
if (modulename) if (modulename)
fprintf(stderr, "\"%s\", line %ld: ", modulename, lineno); fprintf(stderr, "\"%s\", line %ld: ", modulename, lineno);
else else
fprintf(stderr, "%s: ", progname); fprintf(stderr, "%s: ", progname);
fprintf(stderr, s, a1, a2, a3, a4); vfprintf(stderr, s, ap);
fprintf(stderr, tail); fprintf(stderr, "%s", tail);
} }
nofit() void nosect()
{
fatal("no sections");
}
void wr_fatal()
{
fatal("write error");
}
/* VARARGS1 */
void fatal(char *s, ...)
{
va_list ap;
nerrors++;
va_start(ap, s);
vdiag(" (fatal)\n", s, ap);
va_end(ap);
stop(0);
}
#if DEBUG == 2
void assert2(char *file, int line)
{
fatal("assertion failed (%s, %d)", file, line);
}
#endif
#if DEBUG == 1
void assert1()
{
vdiag(" (fatal)\n", "assertion failed");
abort();
}
#endif
/* VARARGS1 */
void serror(char *s, ...)
{
va_list ap;
nerrors++;
va_start(ap, s);
vdiag("\n", s, ap);
va_end(ap);
}
/* VARARGS1 */
void warning(char *s, ...)
{
va_list ap;
va_start(ap, s);
vdiag(" (warning)\n", s, ap);
va_end(ap);
}
/* VARARGS1 */
void diag(char *tail, char *s, ...)
{
va_list ap;
va_start(ap, s);
vdiag(tail, s, ap);
va_end(ap);
}
void nofit()
{ {
if (pass == PASS_3) if (pass == PASS_3)
warning("too big"); warning("too big");