#define FLG_ESEEN 0x01 /* possibly a floating point number */
#define FLG_DOTSEEN 0x02 /* certainly a floating point number */
-int
-LLlex()
+int LLlex()
{
return (DOT != EOF) ? GetToken(&dot) : EOF;
}
-int
-GetToken(ptok)
- register struct token *ptok;
+int GetToken(struct token *ptok)
{
/* GetToken() is the actual token recognizer. It calls the
control line interpreter if it encounters a "\n{w}*#"
crash("bad class for char 0%o", ch);
}
/*NOTREACHED*/
+ return -1;
}
-skipcomment()
+void skipcomment()
{
/* The last character read has been the '*' of '/_*'. The
characters, except NL and EOI, between '/_*' and the first
NoUnstack--;
}
-arith
-char_constant(nm)
- char *nm;
+arith char_constant(char *nm)
{
register arith val = 0;
register int ch;
return val;
}
-char *
-string_token(nm, stop_char)
- char *nm;
+char *string_token(char *nm, int stop_char)
{
register int ch;
register int str_size;
return str;
}
-int
-quoted(ch)
- register int ch;
+int quoted(int ch)
{
/* quoted() replaces an escaped character sequence by the
character meant.
}
-int
-val_in_base(ch, base)
- register int ch;
+int val_in_base(int ch, int base)
{
switch (base) {
case 8:
fatal("(val_in_base) illegal base value %d", base);
/* NOTREACHED */
}
+ return -1;
}
-int
-GetChar()
+int GetChar()
{
/* The routines GetChar and trigraph parses the trigraph
sequences and removes occurences of \\\n.
}
-int
-trigraph()
+int trigraph()
{
register int ch;
extern int err_occurred; /* "error.c" */
+
+void skipcomment();
+
#define DOT dot.tk_symb
#define EOF (-1)
#include "LLlex.h"
#include "Lpars.h"
-extern char *symbol2str();
-LLmessage(tk) {
+void LLmessage(int tk)
+{
if (tk < 0)
error("garbage at end of line");
else if (tk) {
!File: botch_free.h
-/*#define BOTCH_FREE 1 /* botch freed memory, as a check */
+/*#define BOTCH_FREE 1*/ /* botch freed memory, as a check */
!File: debug.h
-/*#define DEBUG 1 /* perform various self-tests */
+/*#define DEBUG 1*/ /* perform various self-tests */
#define NDEBUG 1 /* disable assertions */
!File: inputtype.h
-/*#define INP_READ_IN_ONE 1 /* read input file in one. */
+/*#define INP_READ_IN_ONE 1*/ /* read input file in one. */
/* If defined, we cannot read from a pipe */
#define arith_sign (1L << (sizeof(arith)*8-1))
-ch3bin(pval, pis_uns, oper, val, is_uns)
- register arith *pval, val;
- int oper, is_uns, *pis_uns;
+void ch3bin(arith *pval, int *pis_uns, int oper, arith val, int is_uns)
{
if (is_uns) *pis_uns = 1;
switch (oper) {
#include "arith.h"
/*ARGSUSED2*/
-ch3mon(oper, pval, puns)
- register arith *pval;
- int *puns;
+void ch3mon(int oper, arith *pval, int *puns)
{
switch (oper) {
case '~':
/* $Id$ */
/* PREPROCESSOR: CONTROLLINE INTERPRETER */
+#include <string.h>
+
#include "arith.h"
#include "LLlex.h"
#include "Lpars.h"
#include "macbuf.h"
#include "replace.h"
+char *getwdir(char *fn); /* /util/cpp/input.c */
+
extern char options[];
extern char **inctable; /* list of include directories */
-extern char *getwdir();
char ifstack[IFDEPTH]; /* if-stack: the content of an entry is */
/* 1 if a corresponding ELSE has been */
/* encountered. */
+void do_include();
+void do_define();
+void do_elif();
+void push_if();
+void do_else();
+void do_endif();
+void do_if();
+void do_ifdef(int how);
+void do_undef(char *argstr);
+void do_error();
+void do_line(unsigned int l);
+
+void macro_def(struct idf *id, char *text, int nformals, int length, int flags);
+
int nestlevel = -1;
int svnestlevel[30] = {-1};
int nestcount;
extern int do_preprocess;
-char *
-GetIdentifier(skiponerr)
- int skiponerr; /* skip the rest of the line on error */
+/* skiponerr => skip the rest of the line on error */
+char *GetIdentifier(int skiponerr)
{
/* Returns a pointer to the identifier that is read from the
input stream. When the input does not contain an
Pragma's are handled by do_pragma(). They are passed on to the
compiler.
*/
-domacro()
+void domacro()
{
struct token tk; /* the token itself */
register struct idf *id;
}
}
-skip_block(to_endif)
-int to_endif;
+void skip_block(int to_endif)
{
/* skip_block() skips the input from
1) a false #if, #ifdef, #ifndef or #elif until the
}
-ifexpr()
+int ifexpr()
{
/* ifexpr() returns whether the restricted constant
expression following #if or #elif evaluates to true. This
return (errors == err_occurred) && (ifval != (arith)0);
}
-do_include()
+void do_include()
{
/* do_include() performs the inclusion of a file.
*/
}
}
-do_define()
+void do_define()
{
/* do_define() interprets a #define control line.
*/
LineNumber++;
}
-push_if()
+void push_if()
{
if (nestlevel >= IFDEPTH)
fatal("too many nested #if/#ifdef/#ifndef");
ifstack[++nestlevel] = 0;
}
-do_elif()
+void do_elif()
{
if (nestlevel <= svnestlevel[nestcount]) {
error("#elif without corresponding #if");
}
}
-do_else()
+void do_else()
{
if (SkipToNewLine()) {
if (!options['o'])
}
}
-do_endif()
+void do_endif()
{
if (SkipToNewLine()) {
if (!options['o'])
else nestlevel--;
}
-do_if()
+void do_if()
{
push_if();
if (!ifexpr()) /* a false #if/#elif expression */
skip_block(0);
}
-do_ifdef(how)
+void do_ifdef(int how)
{
register struct idf *id;
register char *str;
}
/* argstr != NULL when the undef came from a -U option */
-do_undef(argstr)
- char *argstr;
+void do_undef(char *argstr)
{
register struct idf *id;
register char *str = argstr;
error("illegal #undef construction");
}
-do_error()
+void do_error()
{
int len;
char *get_text();
LineNumber++;
}
-int
-getparams(buf, parbuf)
- char *buf[];
- char parbuf[];
+int getparams(char *buf[], char parbuf[])
{
/* getparams() reads the formal parameter list of a macro
definition.
c = skipspaces(c,0);
}
/*NOTREACHED*/
+ return -1;
}
-macro_def(id, text, nformals, length, flags)
- register struct idf *id;
- char *text;
+void macro_def(struct idf *id, char *text, int nformals, int length, int flags)
{
register struct macro *newdef = id->id_macro;
newdef->mc_flag = flags; /* special flags */
}
-int
-find_name(nm, index)
- char *nm, *index[];
+int find_name(char *nm, char *index[])
{
/* find_name() returns the index of "nm" in the namelist
"index" if it can be found there. 0 is returned if it is
#define BLANK(ch) ((ch == ' ') || (ch == '\t'))
-char *
-get_text(formals, length)
- char *formals[];
- int *length;
+char *get_text(char *formals[], int *length)
{
/* get_text() copies the replacement text of a macro
definition with zero, one or more parameters, thereby
add2repl(repl, ' ');
}
/* construct the formal parameter mark or identifier */
- if (n = find_name(id_buf, formals))
+ if ( (n = find_name(id_buf, formals)) )
add2repl(repl, FORMALP | (char) n);
else {
idp = id_buf;
as strings, without taking care of the leading and trailing
blanks (spaces and tabs).
*/
-macroeq(s, t)
- register char *s, *t;
+int macroeq(char *s, char *t)
{
/* skip leading spaces */
}
}
-do_line(l)
- unsigned int l;
+void do_line(unsigned int l)
{
struct token tk;
int t = GetToken(&tk);
int err_occurred;
-err_hdr(s)
- char *s;
+void err_hdr(char *s)
{
if (FileName) {
fprint(ERROUT, "\"%s\", line %d: %s", FileName, (int)LineNumber, s);
#if __STDC__
/*VARARGS*/
-error(char *fmt, ...)
+void error(char *fmt, ...)
{
va_list ap;
}
/*VARARGS*/
-warning(char *fmt, ...)
+void warning(char *fmt, ...)
{
va_list ap;
}
/*VARARGS*/
-strict(char *fmt, ...)
+void strict(char *fmt, ...)
{
va_list ap;
}
/*VARARGS*/
-crash(char *fmt, ...)
+void crash(char *fmt, ...)
{
va_list ap;
}
/*VARARGS*/
-fatal(char *fmt, ...)
+void fatal(char *fmt, ...)
{
va_list ap;
//char *strcpy();
//char *sprint();
-init_pp()
+void init_pp()
{
static char *months[12] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
/* __DATE__ */
sprint(dbuf, "\"%s %2d %d\"", months[tp->tm_mon],
tp->tm_mday, tp->tm_year+1900);
- /* if (tp->tm_mday < 10) dbuf[5] = ' '; /* hack */
+ /* if (tp->tm_mday < 10) dbuf[5] = ' ';*/ /* hack */
macro_def(str2idf("__DATE__", 0), dbuf, -1, strlen(dbuf), NOUNDEF);
/* __TIME__ */
#include <alloc.h>
#include <assert.h>
#include <system.h>
+#include <string.h>
#include "arith.h"
#include "file_info.h"
#include "idfsize.h"
extern char **inctable;
extern int inc_max, inc_total;
-main(argc, argv)
- char *argv[];
+
+void compile(int argc, char *argv[]);
+void list_dependencies(char *source);
+void dependency(char *s, char *source);
+
+
+int main(int argc, char *argv[])
{
/* parse and interpret the command line options */
prog_name = argv[0];
}
compile(argc - 1, &argv[1]);
sys_stop(err_occurred ? S_EXIT : S_END);
+
/*NOTREACHED*/
+ return -1;
}
-compile(argc, argv)
- char *argv[];
+void compile(int argc, char *argv[])
{
register char *source = 0;
char *dummy;
}
struct idf *file_head;
-extern char *strrchr();
-list_dependencies(source)
- char *source;
+void list_dependencies(char *source)
{
register struct idf *p = file_head;
* object generated, so don't include the pathname
* leading to it.
*/
- if (s = strrchr(source, '/')) {
+ if ( (s = strrchr(source, '/')) ) {
source = s + 1;
}
}
}
}
-add_dependency(s)
- char *s;
+void add_dependency(char *s)
{
register struct idf *p = str2idf(s, 0);
}
}
-dependency(s, source)
- char *s, *source;
+void dependency(char *s, char *source)
{
if (options['i'] && !strncmp(s, "/usr/include/", 13)) {
return;
else fprint(dep_fd, "%s\n", s);
}
-void
-No_Mem() /* called by alloc package */
+void No_Mem() /* called by alloc package */
{
fatal("out of memory");
}
char *dep_file = 0;
extern int idfsize;
-int txt2int();
-do_option(text)
- char *text;
+void do_option(char *text)
{
switch(*text++) {
case '-':
}
}
-int
-txt2int(tp)
- char **tp;
+int txt2int(char **tp)
{
/* the integer pointed to by *tp is read, while increasing
*tp; the resulting value is yielded.
extern char *sprint();
-Xflush()
+void Xflush()
{
sys_write(STDOUT, _obuf, OBUFSIZE);
}
-static char *SkipComment();
extern char options[];
/* #pragma directives are saved here and passed to the compiler later on.
static struct prag_info *pragma_tab;
static int pragma_nr;
-do_pragma()
+static char *SkipComment(char *op, int *lineno);
+void preprocess(char *fn);
+
+void do_pragma()
{
register int size = ITEXTSIZE;
char *cur_line = Malloc((unsigned)size);
char Xbuf[256];
-preprocess(fn)
- char *fn;
+void preprocess(char *fn)
{
register int c;
register char *op = _obuf;
/*NOTREACHED*/
}
-static char *
-SkipComment(op, lineno)
-char *op;
-int *lineno;
+static char *SkipComment(char *op, int *lineno)
{
char *ob = &_obuf[OBUFSIZE];
register int c, oldc = '\0';
#include "macbuf.h"
#include "replace.h"
-//extern char *GetIdentifier();
-//extern char *strcpy();
-//extern char *strcat();
extern int InputLevel;
struct repl *ReplaceList; /* list of currently active macros */
-int
-replace(idf)
- register struct idf *idf;
+void expand_defined(struct repl *repl);
+void getactuals(struct repl *repl, struct idf *idf);
+void macro_func(struct idf *idef);
+void macro2buffer(struct repl *repl, struct idf *idf, struct args *args);
+void add2repl(struct repl *repl, int ch);
+void stash(struct repl *repl, int ch, int stashraw);
+
+char *GetIdentifier(int skiponerr); /* domacro.c */
+
+int replace(struct idf *idf)
{
/* replace is called by the lexical analyzer to perform
macro replacement. The routine actualy functions as a
return 1;
}
-unstackrepl()
+void unstackrepl()
{
Unstacked++;
}
-freeargs(args)
- struct args *args;
+void freeargs(struct args *args)
{
register int i;
free_args(args);
}
-EnableMacros()
+void EnableMacros()
{
register struct repl *r = ReplaceList, *prev = 0;
Unstacked = 0;
}
-expand_macro(repl, idf)
- register struct repl *repl;
- register struct idf *idf;
+int expand_macro(struct repl *repl, struct idf *idf)
{
/* expand_macro() does the actual macro replacement.
"idf" is a description of the identifier which
return 1;
}
-expand_defined(repl)
- register struct repl *repl;
+void expand_defined(struct repl *repl)
{
register int ch = GetChar();
struct idf *id;
add2repl(repl, ' ');
}
-newarg(args)
- struct args *args;
+void newarg(struct args *args)
{
args->a_expptr = args->a_expbuf = Malloc((unsigned)(args->a_expsize = ARGBUF));
args->a_rawptr = args->a_rawbuf = Malloc((unsigned)(args->a_rawsize = ARGBUF));
}
-getactuals(repl, idf)
- struct repl *repl;
- register struct idf *idf;
+void getactuals(struct repl *repl, struct idf *idf)
{
/* Get the actual parameters from the input stream.
The hard part is done by actual(), only comma's and
error("too many macro arguments");
}
-saveraw(repl)
-struct repl *repl;
+void saveraw(struct repl *repl)
{
register struct repl *nrepl = ReplaceList;
register struct args *ap = nrepl->r_args;
}
}
-int
-actual(repl)
- struct repl *repl;
+int actual(struct repl *repl)
{
/* This routine deals with the scanning of an actual parameter.
It keeps in account the opening and closing brackets,
}
}
-macro_func(idef)
- register struct idf *idef;
+void macro_func(struct idf *idef)
{
/* macro_func() performs the special actions needed with some
macros. These macros are __FILE__ and __LINE__ which
}
}
-macro2buffer(repl, idf, args)
- register struct repl *repl;
- register struct idf *idf;
- register struct args *args;
+void macro2buffer(struct repl *repl, struct idf *idf, struct args *args)
{
/* macro2buffer expands the replacement list and places the
result onto the replacement buffer. It deals with the #
error("illegal use of ## operator");
}
-char *
-stringify(repl, ptr, args)
- register struct repl *repl;
- register char *ptr;
- register struct args *args;
+char *stringify(struct repl *repl, char *ptr, struct args *args)
{
/* If a parameter is immediately preceded by a # token
both are replaced by a single string literal that
/* The following routine is also called from domacro.c.
*/
-add2repl(repl, ch)
- register struct repl *repl;
- int ch;
+void add2repl(struct repl *repl, int ch)
{
register int index = repl->r_ptr - repl->r_text;
* buffer. If the variable is zero, we must only stash into the expanded
* buffer. Otherwise, we must use both buffers.
*/
-stash(repl, ch, stashraw)
- struct repl *repl;
- register int ch;
- int stashraw;
+void stash(struct repl *repl, int ch, int stashraw)
{
/* Stash characters into the macro expansion buffer.
*/
_PROTOTYPE(static struct idf *IDF_new, (char *, int, int));
-void
-init_idf()
+void init_idf()
{
}
-static struct idf *
-IDF_new(tg, size, cpy)
- register char *tg;
- register int size;
+static struct idf *IDF_new(char *tg, int size, int cpy)
{
static int nidf;
static struct idf *pidf;
}
#ifdef IDF_DEBUG
-void
-hash_stat()
+void hash_stat()
{
register int i;
int total_count = 0;
print("End hash table tally\n");
}
-void
-idfappfun(fun, opt)
- int (*fun)();
- int opt;
+void idfappfun(int (*fun)(struct idf *, int), int opt)
{
register int i;
}
#endif /* IDF_DEBUG */
-struct idf *
-str2idf(tg, cpy)
- char tg[];
+struct idf *str2idf(char tg[], int cpy)
{
/* str2idf() returns an entry in the symbol table for the
identifier tg. If necessary, an entry is created.
int size;
IDF_STARTHASH(hash);
- while (c = *cp++) {
+ while ((c = *cp++)) {
IDF_ENHASH(hash, c);
}
IDF_STOPHASH(hash);
_PROTOTYPE(INP_PRIVATE int INP_rdfile, (File *, char *, long *, char **));
+#if __STDC__
+INP_PRIVATE int INP_rdfile(File *fd, char *fn, long size, char **pbuf)
+#else
INP_PRIVATE int
INP_rdfile(fd, fn, size, pbuf)
register File *fd;
char *fn; /* file name */
register long *size;
char **pbuf; /* output parameter */
+#endif
{
extern long sys_filesize();
int rsize;
INP_PRIVATE struct INP_i_buf *i_ptr;
_PROTOTYPE(INP_PRIVATE char * INP_pbuf, (void));
-INP_PRIVATE char *
-INP_pbuf()
+INP_PRIVATE char *INP_pbuf()
{
register struct INP_i_buf *ib =
(struct INP_i_buf *) malloc(sizeof(struct INP_i_buf));
_PROTOTYPE(INP_PRIVATE struct INP_buffer_header *INP_push_bh, (void));
_PROTOTYPE(INP_PRIVATE int INP_pop_bh, (void));
-INP_PRIVATE struct INP_buffer_header *
-INP_push_bh()
+INP_PRIVATE struct INP_buffer_header *INP_push_bh()
{
register struct INP_buffer_header *bh;
- if (bh = INP_head) {
+ if ((bh = INP_head)) {
bh->bh_ipp = _ipp;
#ifdef INP_TYPE
bh->bh_i = INP_VAR;
of headers. 0 is returned if there are no more
inputbuffers on the stack, 1 is returned in the other case.
*/
-INP_PRIVATE int
-INP_pop_bh()
+INP_PRIVATE int INP_pop_bh()
{
register struct INP_buffer_header *bh = INP_head;
*/
_PROTOTYPE(INP_PRIVATE int INP_rdblock, (File *, char *, int *));
+#if __STDC__
+INP_PRIVATE int INP_rdblock(File *fd, char *buf, int *n)
+#else
INP_PRIVATE int
INP_rdblock(fd, buf, n)
File *fd;
char *buf;
int *n;
+#endif
{
if (!sys_read(fd, buf, INP_BUFSIZE, n)) {
/* INP_mk_filename() concatenates a dir and filename.
*/
+#if __STDC__
+INP_PRIVATE int INP_mk_filename(char *dir, char *file, char **newname)
+#else
INP_PRIVATE int
INP_mk_filename(dir, file, newname)
register char *dir, *file;
char **newname;
+#endif
{
register char *dst;
if (!dst) return 0;
*newname = dst;
if (*dir) {
- while (*dst++ = *dir++) ;
+ while (((*dst++) = (*dir++))) ;
*(dst-1) = '/';
}
- while (*dst++ = *file++);
+ while (((*dst++) = (*file++)));
return 1;
}
/* Interface routines : InsertFile, InsertText, and loadbuf
*/
-
+#if __STDC__
+int InsertFile(char *filnam, char *table[], char **result)
+#else
int
InsertFile(filnam, table, result)
char *filnam;
char *table[];
char **result;
+#endif
{
char *newfn = 0;
return 0;
}
+#if __STDC__
+int InsertText(char *text, int length)
+#else
int
InsertText(text, length)
char *text;
+#endif
{
register struct INP_buffer_header *bh = INP_push_bh();
Note: this routine is exported due to its occurence in the definition
of LoadChar [input.h], that is defined as a macro.
*/
-int
-loadbuf()
+int loadbuf()
{
register struct INP_buffer_header *bh = INP_head;
static char buf[INP_NPUSHBACK + 1];
registerdef
: IDENT '=' '(' STRING ',' NUMBER list1 ')' optregvar list1 '.'
- { register ident_p ip;
- register list1 l;
- register reginfo r;
+ { ident_p ip;
+ list1 l;
+ reginfo r;
int i;
r=(reginfo) myalloc(sizeof(struct reginfo));
;
tkdef
: IDENT '=' structdecl NUMBER optcost optformat
- { register token_p tp;
- register ident_p ip;
+ { token_p tp;
+ ident_p ip;
chktabsiz(nmachtokens,MAXTOKENS,"Token table");
tp = &machtokens[nmachtokens];
tokenexpressionline
: IDENT '=' tokenexpression
{
- { register ident_p ip;
+ { ident_p ip;
chktabsiz(nmachsets,MAXSETS,"Expression table");
machsets[nmachsets] = $3;
: PIDENT
{ $$ = machprops[$1->i_i.i_prpno].propset; }
| TIDENT
- { register i;
+ { int i;
for(i=0;i<SETSIZE;i++) $$.set_val[i]=0;
$$.set_val[($1->i_i.i_tokno+nmachregs+1)>>4] |=
| EIDENT
{ $$=machsets[$1->i_i.i_expno]; }
| tokenexpression '*' tokenexpression
- { register i;
+ { int i;
if (($$.set_size=$1.set_size)==0)
$$.set_size = $3.set_size;
$$.set_val[i] = $1.set_val[i] & $3.set_val[i];
}
| tokenexpression '+' tokenexpression
- { register i;
+ { int i;
if ($1.set_size == -1)
$$.set_size = $3.set_size;
$$.set_val[i] = $1.set_val[i] | $3.set_val[i];
}
| tokenexpression '-' tokenexpression
- { register i;
+ { int i;
if ($1.set_size == -1)
$$.set_size = $3.set_size;
: /* empty */
{ empatlen=0; }
| mnemlist optboolexpr
- { register i;
+ { int i;
empatexpr = $2;
patbyte(0);
stackpattern
: optnocoerc tokenexpressionlist optstack
- { register i;
+ { int i;
if (tokpatlen != 0) {
outbyte(($1 ? ( $3 ? DO_XXMATCH: DO_XMATCH ) : DO_MATCH)+(tokpatlen<<5));
tokpatlen=2;
}
optboolexpr ',' code optcommacost ')'
- { register move_p mp;
+ { move_p mp;
outbyte(DO_RETURN);
fprintf(cfile,"\n");
tokpatlen=2;
}
optboolexpr ',' code optcommacost ')'
- { register move_p mp;
+ { move_p mp;
outbyte(DO_RETURN);
fprintf(cfile,"\n");
tokpatlen=1;
}
optboolexpr ',' optprop ',' code optcommacost ')'
- { register c1_p cp;
+ { c1_p cp;
outbyte(DO_TOKREPLACE);
outbyte(DO_RETURN);
tokeninstance
: '%' '[' tokargno subreg ']'
- { register i;
+ { int i;
if ($4!=0)
chkregexp(pattokexp[$3]);
}
| '%' '[' tokargno '.' IDENT ']'
{ int typ;
- register i;
+ int i;
$$.in_which = IN_COPY;
$$.in_info[0] = $3;
$$.in_info[1] = findstructel(pattokexp[$3],$5,&typ);
$$.in_info[i] = 0;
}
| RIDENT
- { register i;
+ { int i;
$$.in_which = IN_RIDENT;
$$.in_info[0] = $1->i_i.i_regno;
for (i=1;i<TOKENSIZE;i++)
$$.in_info[i] = 0;
}
| REGVAR '(' expr ')'
- { register i;
+ { int i;
MUST1BEINT($3);
$$.in_which = IN_REGVAR;
$$.in_info[0] = exp1;
$$.in_info[i] = 0;
}
| '%' '[' LCASELETTER subreg ']'
- { register i;
+ { int i;
if ($3 >= 'a'+nallreg)
yyerror("Bad letter in %[x] construct");
$$.in_which = IN_ALLOC;
$$.in_info[i] = 0;
}
| '{' TIDENT attlist '}'
- { register i;
+ { int i;
$$.in_which = IN_DESCR;
$$.in_info[0] = $2->i_i.i_tokno;
for(i=0;i<narexp;i++) {
#include "booth.h"
#include "y.tab.h"
+void yyerror(string s);
+
int lineno = 1;
extern char *iname;
extern char *scopy();
. return(yytext[0]);
%%
-yyerror(s,a1,a2,a3,a4) string s; {
-
+void yyerror(string s)
+{
fprintf(stderr,"\"%s\", line %d:",iname ? iname : "",lineno);
- fprintf(stderr,s,a1,a2,a3,a4);
fprintf(stderr,"\n");
nerrors++;
}
#include "booth.h"
-char * myalloc(n) {
+void tabovf(string tablename);
+void compueq();
+void initio();
+void inittables();
+void finishio();
+void outregvar();
+void verbose();
+void chkregexp(int number);
+void inithash();
+void enter(char *name, int value);
+void debug();
+void outbyte(int n);
+void patbyte(int n);
+void hashpatterns();
+
+char * myalloc(int n)
+{
register char *p;
p= malloc((unsigned)n);
return(p);
}
-tstint(e) expr_t e; {
-
+void tstint(expr_t e)
+{
if(e.expr_typ != TYPINT)
yyerror("Must be integer expression");
}
-tstbool(e) expr_t e; {
-
+void tstbool(expr_t e)
+{
if(e.expr_typ != TYPBOOL)
yyerror("Must be boolean expression");
}
-structsize(s) register list2 s; {
- register list1 l;
- register sum;
+int structsize(register list2 s)
+{
+ list1 l;
+ int sum;
sum = 0;
while ( s != 0 ) {
return(sum);
}
-list2 lookstruct(ll) list2 ll; {
+list2 lookstruct(list2 ll)
+{
list3 l3;
list2 l21,l22;
list1 l11,l12;
return(ll);
}
-instno(inst) inst_t inst; {
- register i,j;
+int instno(inst_t inst)
+{
+ int i,j;
for(i=1;i<narinstance;i++) {
if (arinstance[i].in_which != inst.in_which)
return(narinstance++);
}
-string scopy(s) string s; {
- register string t;
+string scopy(string s)
+{
+ string t;
t = (char *) myalloc(strlen(s)+1);
strcpy(t,s);
return(t);
}
-strlookup(s) string s; {
- register i;
+int strlookup(string s)
+{
+ int i;
for(i=0;i<ncodestrings;i++)
if(strcmp(s,codestrings[i])==0)
return(ncodestrings++);
}
-stringno(s) register string s; {
+int stringno(string s)
+{
char buf[256];
- register char *p=buf;
+ char *p=buf;
while(*s != 0) switch(*s) {
default:
return(strlookup(buf));
}
-tabovf(tablename) string tablename; {
+void tabovf(string tablename)
+{
char buf[256];
sprintf(buf,"%s overflow",tablename);
exit(-1);
}
-main(argc,argv) char *argv[]; {
-
+int main(int argc, char *argv[])
+{
while (--argc) {
++argv;
if (argv[0][0]=='-') {
}
debug();
exit(nerrors);
+ return nerrors;
}
-lookup(comm,operator,lnode,rnode) {
- register node_p p;
+int lookup(int comm, int operator, int lnode, int rnode)
+{
+ node_p p;
for (p=nodes+1;p<lastnode;p++) {
if (p->ex_operator != operator)
continue;
- if (!(p->ex_lnode == lnode && p->ex_rnode == rnode ||
- comm && p->ex_lnode == rnode && p->ex_rnode == lnode))
+ if (!( ((p->ex_lnode == lnode) && (p->ex_rnode == rnode)) ||
+ ((comm && p->ex_lnode == rnode) && (p->ex_rnode == lnode)) ) )
continue;
return(p-nodes);
}
return(p-nodes);
}
-compueq() {
- register i,j;
+void compueq()
+{
+ int i,j;
for (i=1;i<nmachregs;i++) {
for (j=1;j<i;j++)
}
}
-eqregclass(r1,r2) {
- register reginfo rp1,rp2;
- register i;
+int eqregclass(int r1, int r2)
+{
+ reginfo rp1,rp2;
+ int i;
short regbits[(MAXREGS+15)>>4];
int member;
for (i=0;i<((MAXREGS+15)>>4);i++)
regbits[i] = 0;
for (i=0;i<maxmembers;i++) {
- if (member = rp1->rmembers[i])
+ if ( (member = rp1->rmembers[i]) )
regbits[member>>4] |= (1<<(member&017));
}
for (i=0;i<maxmembers;i++) {
return(1);
}
-unsigned hash(name) register string name; {
- register unsigned sum;
- register i;
+unsigned hash(string name)
+{
+ unsigned int sum;
+ int i;
for (sum=i=0;*name;i+=3)
sum ^= (*name++)<<(i&07);
return(sum);
}
-ident_p ilookup(name,enterf) string name; int enterf; {
+ident_p ilookup(string name, int enterf)
+{
register ident_p p,*pp;
pp = &identtab[hash(name)%ITABSIZE];
- while (*pp != 0) {
+ while (*pp != 0)
+ {
if (strcmp((*pp)->i_name,name)==0)
+ {
if (enterf != ENTER)
+ {
return(*pp);
+ }
else
+ {
yyerror("Multiply defined symbol");
+ }
+ }
pp = &(*pp)->i_next;
}
if (enterf == LOOKUP)
return(p);
}
-initio() {
-
+void initio()
+{
if (iname!=0 && freopen(iname,"r",stdin)==NULL) {
fprintf(stderr,"Can't open %s\n",iname);
exit(-1);
patbyte(0);
}
-exprlookup(sett) set_t sett; {
- register i,j,ok;
+int exprlookup(set_t sett)
+{
+ int i,j,ok;
for(i=0;i<nmachsets;i++) {
ok= (sett.set_size == machsets[i].set_size);
return(nmachsets++);
}
-inittables() {
- register reginfo r;
- register i;
+void inittables()
+{
+ reginfo r;
+ int i;
inst_t inst;
set_t sett;
cocosetno=exprlookup(sett);
}
-outregs() {
- register i,j,k;
+void outregs()
+{
+ int i,j,k;
static short rset[(MAXREGS+15)>>4];
int t,ready;
*/
for (j=0;j<((MAXREGS+15)>>4);j++)
rset[j]=0;
+
rset[i>>4] |= (1<<(i&017));
- do {
- ready=1;
- for (j=1;j<nmachregs;j++)
- if (rset[j>>4]&(1<<(j&017)))
- for (k=0;k<maxmembers;k++)
- if ((t=machregs[j]->rmembers[k])!=0) {
- if ((rset[t>>4]&(1<<(t&017)))==0)
- ready=0;
- rset[t>>4] |= (1<<(t&017));
+
+ do
+ {
+ ready = 1;
+ for ( j = 1 ; j < nmachregs ; j++ )
+ {
+ if ( rset[j >> 4] & (1 << (j & 017)) )
+ {
+ for ( k = 0 ; k < maxmembers ; k++ )
+ {
+ if ( (t = machregs[j]->rmembers[k]) != 0 )
+ {
+ if ( ( rset[t >> 4] & (1 << (t & 017)) ) == 0 )
+ {
+ ready = 0;
+ }
+ rset[t >> 4] |= (1 << (t & 017));
+ }
+ }
}
+ }
} while (!ready);
- do {
- ready=1;
- for (j=1;j<nmachregs;j++)
- for (k=0;k<maxmembers;k++)
- if ((t=machregs[j]->rmembers[k])!=0)
- if (rset[t>>4]&(1<<(t&017))) {
- if (rset[j>>4]&(1<<(j&017))==0)
- ready=0;
- rset[j>>4] |= (1<<(j&017));
+
+ do
+ {
+ ready=1;
+ for ( j = 1 ; j < nmachregs ; j++ )
+ {
+ for ( k = 0 ; k < maxmembers ; k++ )
+ {
+ if ( ( t = machregs[j]->rmembers[k] ) !=0 )
+ {
+ if ( rset[t >> 4] & (1 << (t & 017)) )
+ {
+ if ( ( rset[j >> 4] & (1 << (j & 017)) ) == 0)
+ {
+ ready=0;
+ }
+ rset[j >> 4] |= (1 << (j & 017));
+ }
+ }
}
+ }
} while (!ready);
+
fprintf(cfile,"},{");
for (j=0;j<((nmachregs+15)>>4);j++)
fprintf(cfile,"%d,",rset[j]);
fprintf(cfile,"};\n\n");
}
-finishio() {
- register i;
- register node_p np;
+void finishio()
+{
+ int i;
+ node_p np;
int j;
int setsize;
- register move_p mp;
+ move_p mp;
fprintf(cfile,"};\n\n");
if (wsize>0)
outregvar();
}
-outregvar() {
- register i,j;
+void outregvar()
+{
+ int i,j;
fprintf(hfile,"#define REGVARS\n");
fprintf(cfile,"#include \"regvar.h\"\n");
fprintf(cfile,"};\n");
}
-verbose() {
-
+void verbose()
+{
fprintf(stderr,"Codebytes %d\n",codebytes);
fprintf(stderr,"Registers %d(%d)\n",nmachregs,MAXREGS);
fprintf(stderr,"Properties %d(%d)\n",nprops,MAXPROPS);
fprintf(stderr,"Patbytes %d(%d)\n",npatbytes,MAXPATTERN);
}
-inbetween() {
- register ident_p ip;
- register i,j;
- register move_p mp;
+void inbetween()
+{
+ ident_p ip;
+ int i,j;
+ move_p mp;
lookident=1; /* for lexical analysis */
}
}
-formconversion(p,tp) register char *p; register token_p tp; {
+int formconversion(char *p, token_p tp)
+{
char buf[256];
- register char *q=buf;
+ char *q=buf;
char field[256];
- register char *f;
+ char *f;
int i;
if (p==0)
return(strlookup(buf));
}
-setfields(tp,format) register token_p tp; string format; {
- register i;
+void setfields(token_p tp, string format)
+{
+ int i;
list2 ll;
- register list1 l;
+ list1 l;
int type;
for(i=0;i<TOKENSIZE-1;i++)
tp->t_format = -1;
}
-chkregexp(number) {
- register i;
+void chkregexp(int number)
+{
+ int i;
for(i=nmachregs+1;i<nmachregs+1+nmachtokens;i++)
if(machsets[number].set_val[i>>4]&(01<<(i&017)))
yyerror("No tokens allowed in this set");
}
-findstructel(number,name,t) string name; int *t; {
- register i;
- register token_p tp;
- register list2 structdecl;
+int findstructel(int number, string name, int *t)
+{
+ int i;
+ token_p tp;
+ list2 structdecl;
int offset;
for(i=1;i<=nmachregs;i++)
extern char em_flag[];
-argtyp(mn) {
-
+int argtyp(int mn)
+{
switch(em_flag[mn-sp_fmnem]&EM_PAR) {
case PAR_W:
case PAR_S:
}
}
-commontype(e1,e2) expr_t e1,e2; {
-
+int commontype(expr_t e1, expr_t e2)
+{
if(e1.expr_typ != e2.expr_typ)
yyerror("Type incompatibility");
return(e1.expr_typ);
byte h_value;
} hashmnem[HASHSIZE];
-inithash() {
- register i;
+void inithash()
+{
+ int i;
for(i=0;i<=sp_lmnem-sp_fmnem;i++)
enter(em_mnem[i],i+sp_fmnem);
}
-enter(name,value) char *name; {
- register unsigned h;
+void enter(char *name, int value)
+{
+ unsigned int h;
h=hash(name)%HASHSIZE;
while (hashmnem[h].h_name[0] != 0)
hashmnem[h].h_value = value;
}
-int mlookup(name) char *name; {
- register unsigned h;
+int mlookup(char *name)
+{
+ unsigned int h;
h = hash(name)%HASHSIZE;
while (strncmp(hashmnem[h].h_name,name,3) != 0 &&
return(hashmnem[h].h_value&BMASK); /* 0 if not found */
}
-hashpatterns() {
+void hashpatterns()
+{
short index;
- register byte *bp,*tp;
- register short i;
+ byte *bp,*tp;
+ short i;
unsigned short hashvalue;
int patlen;
}
}
-debug() {
- register i,j;
+void debug()
+{
+ int i,j;
for(i=0;i<ITABSIZE;i++) {
- register ident_p ip;
+ ident_p ip;
for(ip=identtab[i];ip!=0;ip=ip->i_next)
printf("%-14s %1d %3d\n",ip->i_name,
ip->i_type,ip->i_i.i_regno);
}
for(i=2;i<nmachregs;i++) {
- register reginfo rp;
+ reginfo rp;
rp=machregs[i];
printf("%s = (\"%s\", %d",rp->rname,rp->rrepr,rp->rsize);
}
}
-out(n) {
-
+void out(int n)
+{
assert(n>=0);
if (n<128)
outbyte(n);
}
}
-outbyte(n) {
-
+void outbyte(int n)
+{
fprintf(cfile,"%d, ",n&BMASK);
codebytes++;
}
-pat(n) {
-
+void pat(int n)
+{
assert(n>=0);
if (n<128)
patbyte(n);
}
}
-patshort(n) {
-
+void patshort(int n)
+{
patbyte(n&BMASK);
patbyte(n>>BSHIFT);
}
-patbyte(n) {
-
+void patbyte(int n)
+{
chktabsiz(npatbytes,MAXPATTERN,"Pattern table");
pattern[npatbytes++] = n;
}
-max(a,b) {
-
+int max(int a, int b)
+{
if (a>b)
return(a);
return(b);
*/
/* PREPROCESSOR: INITIALIZATION ROUTINES */
+#include <string.h>
#include <system.h>
#include <alloc.h>
#include "class.h"
#include "idf.h"
#include "interface.h"
-PRIVATE struct mkey {
+static struct mkey {
char *mk_reserved;
int mk_key;
} mkey[] = {
{0, K_UNKNOWN}
};
-char *strcpy();
-
-EXPORT
-init_pp()
+void init_pp()
{
long clock, sys_time();
static char date[30];
#include <inp_pkg.body>
#include <alloc.h>
-char * getwdir(char *fn)
+char *getwdir(char *fn)
{
- register char *p;
- char *strrchr();
+ char *p;
p = strrchr(fn, '/');
while (p && *(p + 1) == '\0') { /* remove trailing /'s */
int Unstacked;
int InputLevel;
-AtEoIT()
+int AtEoIT()
{
/* if (NoUnstack) warning("unexpected EOF"); ??? */
/* This is wrong; in an #elif, NoUnstack can be set, but you
return 0;
}
-AtEoIF()
+int AtEoIF()
{
extern int nestlevel;
extern int nestcount;
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
-#define PRIVATE
+#define PRIVATE
#define IMPORT extern
#define EXPORT
/* MAIN PROGRAM */
#include <stdlib.h>
+#include <string.h>
#include <alloc.h>
#include <em_arith.h>
#include <assert.h>
arith ifval;
+void compile(int argc, char *argv[]);
+void list_dependencies(char *source);
+void dependency(char *s, char *source);
+
char *prog_name;
extern char **inctable;
extern int inc_max, inc_total;
-main(argc, argv)
- char *argv[];
+int main(int argc, char *argv[])
{
/* parse and interpret the command line options */
prog_name = argv[0];
}
compile(argc - 1, &argv[1]);
exit(err_occurred);
+ return 0;
}
-compile(argc, argv)
- char *argv[];
+void compile(int argc, char *argv[])
{
register char *source = 0;
char *dummy;
}
struct idf *file_head;
-extern char *strrchr();
-list_dependencies(source)
- char *source;
+void list_dependencies(char *source)
{
register struct idf *p = file_head;
* object generated, so don't include the pathname
* leading to it.
*/
- if (s = strrchr(source, '/')) {
+ if ( (s = strrchr(source, '/')) ) {
source = s + 1;
}
}
}
}
-add_dependency(s)
- char *s;
+void add_dependency(char *s)
{
register struct idf *p = str2idf(s, 0);
}
}
-dependency(s, source)
- char *s, *source;
+void dependency(char *s, char *source)
{
if (options['i'] && !strncmp(s, "/usr/include/", 13)) {
return;
char *dep_file = 0;
extern int idfsize;
-int txt2int();
+int txt2int(char **tp);
-do_option(text)
- char *text;
+void do_option(char *text)
{
switch(*text++) {
case '-':
}
}
-int
-txt2int(tp)
- char **tp;
+int txt2int(char **tp)
{
/* the integer pointed to by *tp is read, while increasing
*tp; the resulting value is yielded.
char _obuf[OBUFSIZE];
extern int do_preprocess;
-Xflush()
+void Xflush()
{
if (do_preprocess) sys_write(STDOUT, _obuf, OBUFSIZE);
}
-preprocess(fn)
+void preprocess(fn)
char *fn;
{
register int c;
#include "class.h"
#include "interface.h"
-char *strcpy(), *strcat();
-char *long2str();
extern int InputLevel;
-PRIVATE struct mlist *ReplList; /* list of currently active macros */
+static struct mlist *ReplList; /* list of currently active macros */
+static char *macro2buffer(struct idf *idef, char **actpars, int *siztext);
+static void macro_func(struct idf *idef);
-EXPORT int
-replace(idef)
- register struct idf *idef;
+
+char *GetIdentifier(); /* domacro.c */
+char **getactuals(struct idf *idef); /* scan.c */
+char *long2str(long value, int base); /* External lib */
+
+int replace(struct idf *idef)
{
/* replace() is called by the lexical analyzer to perform
macro replacement. "idef" is the description of the
*/
register struct macro *mac = idef->id_macro;
register char c;
- char **actpars, **getactuals();
- char *reptext, *macro2buffer();
+ char **actpars;
+ char *reptext;
register struct mlist *repl;
int size;
if (mac->mc_flag & FUNC) {
struct idf *param;
char *nam;
- extern char *GetIdentifier();
UnknownIdIsZero = 0;
nam = GetIdentifier();
char FilNamBuf[PATHLENGTH];
-PRIVATE
-macro_func(idef)
- register struct idf *idef;
+static void macro_func(struct idf *idef)
{
/* macro_func() performs the special actions needed with some
macros. These macros are __FILE__ and __LINE__ which
}
}
-PRIVATE char *
-macro2buffer(idef, actpars, siztext)
- struct idf *idef;
- char **actpars;
- int *siztext;
+static char *macro2buffer(struct idf *idef, char **actpars, int *siztext)
{
/* Macro2buffer() turns the macro replacement text, as it is
stored, into an input buffer, while each occurrence of the
return Realloc(text, pos+1);
}
-EXPORT
-DoUnstack()
+void DoUnstack()
{
Unstacked = 1;
}
-EXPORT
-EnableMacros()
+void EnableMacros()
{
register struct mlist *p = ReplList, *prev = 0;
#define EOS '\0'
#define overflow() (fatal("actual parameter buffer overflow"))
-PRIVATE char apbuf[LAPBUF]; /* temporary storage for actual parameters */
-PRIVATE char *actparams[NPARAMS]; /* pointers to the text of the actuals */
-PRIVATE char *aptr; /* pointer to last inserted character in apbuf */
+static char apbuf[LAPBUF]; /* temporary storage for actual parameters */
+static char *actparams[NPARAMS]; /* pointers to the text of the actuals */
+static char *aptr; /* pointer to last inserted character in apbuf */
#define copy(ch) ((aptr < &apbuf[LAPBUF]) ? (*aptr++ = ch) : overflow())
-PRIVATE int nr_of_params; /* number of actuals read until now */
+static int nr_of_params; /* number of actuals read until now */
-PRIVATE char **
-getactuals(idef)
- struct idf *idef;
+static void copyact(char ch1, char ch2, int level);
+
+char **getactuals(struct idf *idef)
{
/* getactuals() collects the actual parameters and turns them
into a list of strings, a pointer to which is returned.
return actparams;
}
-PRIVATE
-copyact(ch1, ch2, level)
- char ch1, ch2;
- int level;
+static void copyact(char ch1, char ch2, int level)
{
/* copyact() is taken from Ceriel Jacobs' LLgen, with
permission. Its task is to build a list of actuals
#include "class.h"
#include "input.h"
-int
-skipspaces(ch, skipnl)
- register int ch;
+int skipspaces(int ch, int skipnl)
{
/* skipspaces() skips any white space and returns the first
non-space character.
}
}
-skipline()
+void skipline()
{
/* skipline() skips all characters until a newline character
is seen, not escaped by a '\\'.
Any comment is skipped.
*/
- register int c;
+ int c;
LoadChar(c);
while (class(c) != STNL && c != EOI) {
if (class(c) == STSTR || class(c) == STCHAR) {
- register int stopc = c;
+ int stopc = c;
int escaped;
do {
escaped = 0;