ANSIfication] Another batch.
This commit is contained in:
parent
3d1d1277b7
commit
0946773758
@ -37,16 +37,13 @@ extern arith char_constant();
|
|||||||
#define FLG_ESEEN 0x01 /* possibly a floating point number */
|
#define FLG_ESEEN 0x01 /* possibly a floating point number */
|
||||||
#define FLG_DOTSEEN 0x02 /* certainly a floating point number */
|
#define FLG_DOTSEEN 0x02 /* certainly a floating point number */
|
||||||
|
|
||||||
int
|
int LLlex()
|
||||||
LLlex()
|
|
||||||
{
|
{
|
||||||
return (DOT != EOF) ? GetToken(&dot) : EOF;
|
return (DOT != EOF) ? GetToken(&dot) : EOF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int GetToken(struct token *ptok)
|
||||||
GetToken(ptok)
|
|
||||||
register struct token *ptok;
|
|
||||||
{
|
{
|
||||||
/* GetToken() is the actual token recognizer. It calls the
|
/* GetToken() is the actual token recognizer. It calls the
|
||||||
control line interpreter if it encounters a "\n{w}*#"
|
control line interpreter if it encounters a "\n{w}*#"
|
||||||
@ -325,9 +322,10 @@ garbage:
|
|||||||
crash("bad class for char 0%o", ch);
|
crash("bad class for char 0%o", ch);
|
||||||
}
|
}
|
||||||
/*NOTREACHED*/
|
/*NOTREACHED*/
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
skipcomment()
|
void skipcomment()
|
||||||
{
|
{
|
||||||
/* The last character read has been the '*' of '/_*'. The
|
/* The last character read has been the '*' of '/_*'. The
|
||||||
characters, except NL and EOI, between '/_*' and the first
|
characters, except NL and EOI, between '/_*' and the first
|
||||||
@ -358,9 +356,7 @@ skipcomment()
|
|||||||
NoUnstack--;
|
NoUnstack--;
|
||||||
}
|
}
|
||||||
|
|
||||||
arith
|
arith char_constant(char *nm)
|
||||||
char_constant(nm)
|
|
||||||
char *nm;
|
|
||||||
{
|
{
|
||||||
register arith val = 0;
|
register arith val = 0;
|
||||||
register int ch;
|
register int ch;
|
||||||
@ -391,9 +387,7 @@ char_constant(nm)
|
|||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *string_token(char *nm, int stop_char)
|
||||||
string_token(nm, stop_char)
|
|
||||||
char *nm;
|
|
||||||
{
|
{
|
||||||
register int ch;
|
register int ch;
|
||||||
register int str_size;
|
register int str_size;
|
||||||
@ -423,9 +417,7 @@ string_token(nm, stop_char)
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int quoted(int ch)
|
||||||
quoted(ch)
|
|
||||||
register int ch;
|
|
||||||
{
|
{
|
||||||
/* quoted() replaces an escaped character sequence by the
|
/* quoted() replaces an escaped character sequence by the
|
||||||
character meant.
|
character meant.
|
||||||
@ -483,9 +475,7 @@ quoted(ch)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int val_in_base(int ch, int base)
|
||||||
val_in_base(ch, base)
|
|
||||||
register int ch;
|
|
||||||
{
|
{
|
||||||
switch (base) {
|
switch (base) {
|
||||||
case 8:
|
case 8:
|
||||||
@ -500,11 +490,11 @@ val_in_base(ch, base)
|
|||||||
fatal("(val_in_base) illegal base value %d", base);
|
fatal("(val_in_base) illegal base value %d", base);
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int GetChar()
|
||||||
GetChar()
|
|
||||||
{
|
{
|
||||||
/* The routines GetChar and trigraph parses the trigraph
|
/* The routines GetChar and trigraph parses the trigraph
|
||||||
sequences and removes occurences of \\\n.
|
sequences and removes occurences of \\\n.
|
||||||
@ -532,8 +522,7 @@ again:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int trigraph()
|
||||||
trigraph()
|
|
||||||
{
|
{
|
||||||
register int ch;
|
register int ch;
|
||||||
|
|
||||||
|
|||||||
@ -41,6 +41,9 @@ extern int NoUnstack; /* buffer.c */
|
|||||||
|
|
||||||
extern int err_occurred; /* "error.c" */
|
extern int err_occurred; /* "error.c" */
|
||||||
|
|
||||||
|
|
||||||
|
void skipcomment();
|
||||||
|
|
||||||
#define DOT dot.tk_symb
|
#define DOT dot.tk_symb
|
||||||
|
|
||||||
#define EOF (-1)
|
#define EOF (-1)
|
||||||
|
|||||||
@ -9,9 +9,9 @@
|
|||||||
#include "LLlex.h"
|
#include "LLlex.h"
|
||||||
#include "Lpars.h"
|
#include "Lpars.h"
|
||||||
|
|
||||||
extern char *symbol2str();
|
|
||||||
|
|
||||||
LLmessage(tk) {
|
void LLmessage(int tk)
|
||||||
|
{
|
||||||
if (tk < 0)
|
if (tk < 0)
|
||||||
error("garbage at end of line");
|
error("garbage at end of line");
|
||||||
else if (tk) {
|
else if (tk) {
|
||||||
|
|||||||
@ -36,11 +36,11 @@
|
|||||||
|
|
||||||
|
|
||||||
!File: botch_free.h
|
!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
|
!File: debug.h
|
||||||
/*#define DEBUG 1 /* perform various self-tests */
|
/*#define DEBUG 1*/ /* perform various self-tests */
|
||||||
#define NDEBUG 1 /* disable assertions */
|
#define NDEBUG 1 /* disable assertions */
|
||||||
|
|
||||||
|
|
||||||
@ -53,7 +53,7 @@
|
|||||||
|
|
||||||
|
|
||||||
!File: inputtype.h
|
!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 */
|
/* If defined, we cannot read from a pipe */
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -10,9 +10,7 @@
|
|||||||
|
|
||||||
#define arith_sign (1L << (sizeof(arith)*8-1))
|
#define arith_sign (1L << (sizeof(arith)*8-1))
|
||||||
|
|
||||||
ch3bin(pval, pis_uns, oper, val, is_uns)
|
void ch3bin(arith *pval, int *pis_uns, int oper, arith val, int is_uns)
|
||||||
register arith *pval, val;
|
|
||||||
int oper, is_uns, *pis_uns;
|
|
||||||
{
|
{
|
||||||
if (is_uns) *pis_uns = 1;
|
if (is_uns) *pis_uns = 1;
|
||||||
switch (oper) {
|
switch (oper) {
|
||||||
|
|||||||
@ -9,9 +9,7 @@
|
|||||||
#include "arith.h"
|
#include "arith.h"
|
||||||
|
|
||||||
/*ARGSUSED2*/
|
/*ARGSUSED2*/
|
||||||
ch3mon(oper, pval, puns)
|
void ch3mon(int oper, arith *pval, int *puns)
|
||||||
register arith *pval;
|
|
||||||
int *puns;
|
|
||||||
{
|
{
|
||||||
switch (oper) {
|
switch (oper) {
|
||||||
case '~':
|
case '~':
|
||||||
|
|||||||
@ -5,6 +5,8 @@
|
|||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
/* PREPROCESSOR: CONTROLLINE INTERPRETER */
|
/* PREPROCESSOR: CONTROLLINE INTERPRETER */
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "arith.h"
|
#include "arith.h"
|
||||||
#include "LLlex.h"
|
#include "LLlex.h"
|
||||||
#include "Lpars.h"
|
#include "Lpars.h"
|
||||||
@ -26,21 +28,35 @@
|
|||||||
#include "macbuf.h"
|
#include "macbuf.h"
|
||||||
#include "replace.h"
|
#include "replace.h"
|
||||||
|
|
||||||
|
char *getwdir(char *fn); /* /util/cpp/input.c */
|
||||||
|
|
||||||
extern char options[];
|
extern char options[];
|
||||||
extern char **inctable; /* list of include directories */
|
extern char **inctable; /* list of include directories */
|
||||||
extern char *getwdir();
|
|
||||||
char ifstack[IFDEPTH]; /* if-stack: the content of an entry is */
|
char ifstack[IFDEPTH]; /* if-stack: the content of an entry is */
|
||||||
/* 1 if a corresponding ELSE has been */
|
/* 1 if a corresponding ELSE has been */
|
||||||
/* encountered. */
|
/* 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 nestlevel = -1;
|
||||||
int svnestlevel[30] = {-1};
|
int svnestlevel[30] = {-1};
|
||||||
int nestcount;
|
int nestcount;
|
||||||
extern int do_preprocess;
|
extern int do_preprocess;
|
||||||
|
|
||||||
char *
|
/* skiponerr => skip the rest of the line on error */
|
||||||
GetIdentifier(skiponerr)
|
char *GetIdentifier(int skiponerr)
|
||||||
int skiponerr; /* skip the rest of the line on error */
|
|
||||||
{
|
{
|
||||||
/* Returns a pointer to the identifier that is read from the
|
/* Returns a pointer to the identifier that is read from the
|
||||||
input stream. When the input does not contain an
|
input stream. When the input does not contain an
|
||||||
@ -73,7 +89,7 @@ GetIdentifier(skiponerr)
|
|||||||
Pragma's are handled by do_pragma(). They are passed on to the
|
Pragma's are handled by do_pragma(). They are passed on to the
|
||||||
compiler.
|
compiler.
|
||||||
*/
|
*/
|
||||||
domacro()
|
void domacro()
|
||||||
{
|
{
|
||||||
struct token tk; /* the token itself */
|
struct token tk; /* the token itself */
|
||||||
register struct idf *id;
|
register struct idf *id;
|
||||||
@ -154,8 +170,7 @@ domacro()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
skip_block(to_endif)
|
void skip_block(int to_endif)
|
||||||
int to_endif;
|
|
||||||
{
|
{
|
||||||
/* skip_block() skips the input from
|
/* skip_block() skips the input from
|
||||||
1) a false #if, #ifdef, #ifndef or #elif until the
|
1) a false #if, #ifdef, #ifndef or #elif until the
|
||||||
@ -275,7 +290,7 @@ int to_endif;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ifexpr()
|
int ifexpr()
|
||||||
{
|
{
|
||||||
/* ifexpr() returns whether the restricted constant
|
/* ifexpr() returns whether the restricted constant
|
||||||
expression following #if or #elif evaluates to true. This
|
expression following #if or #elif evaluates to true. This
|
||||||
@ -296,7 +311,7 @@ ifexpr()
|
|||||||
return (errors == err_occurred) && (ifval != (arith)0);
|
return (errors == err_occurred) && (ifval != (arith)0);
|
||||||
}
|
}
|
||||||
|
|
||||||
do_include()
|
void do_include()
|
||||||
{
|
{
|
||||||
/* do_include() performs the inclusion of a file.
|
/* do_include() performs the inclusion of a file.
|
||||||
*/
|
*/
|
||||||
@ -333,7 +348,7 @@ do_include()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
do_define()
|
void do_define()
|
||||||
{
|
{
|
||||||
/* do_define() interprets a #define control line.
|
/* do_define() interprets a #define control line.
|
||||||
*/
|
*/
|
||||||
@ -373,7 +388,7 @@ do_define()
|
|||||||
LineNumber++;
|
LineNumber++;
|
||||||
}
|
}
|
||||||
|
|
||||||
push_if()
|
void push_if()
|
||||||
{
|
{
|
||||||
if (nestlevel >= IFDEPTH)
|
if (nestlevel >= IFDEPTH)
|
||||||
fatal("too many nested #if/#ifdef/#ifndef");
|
fatal("too many nested #if/#ifdef/#ifndef");
|
||||||
@ -381,7 +396,7 @@ push_if()
|
|||||||
ifstack[++nestlevel] = 0;
|
ifstack[++nestlevel] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
do_elif()
|
void do_elif()
|
||||||
{
|
{
|
||||||
if (nestlevel <= svnestlevel[nestcount]) {
|
if (nestlevel <= svnestlevel[nestcount]) {
|
||||||
error("#elif without corresponding #if");
|
error("#elif without corresponding #if");
|
||||||
@ -398,7 +413,7 @@ do_elif()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
do_else()
|
void do_else()
|
||||||
{
|
{
|
||||||
if (SkipToNewLine()) {
|
if (SkipToNewLine()) {
|
||||||
if (!options['o'])
|
if (!options['o'])
|
||||||
@ -415,7 +430,7 @@ do_else()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
do_endif()
|
void do_endif()
|
||||||
{
|
{
|
||||||
if (SkipToNewLine()) {
|
if (SkipToNewLine()) {
|
||||||
if (!options['o'])
|
if (!options['o'])
|
||||||
@ -427,14 +442,14 @@ do_endif()
|
|||||||
else nestlevel--;
|
else nestlevel--;
|
||||||
}
|
}
|
||||||
|
|
||||||
do_if()
|
void do_if()
|
||||||
{
|
{
|
||||||
push_if();
|
push_if();
|
||||||
if (!ifexpr()) /* a false #if/#elif expression */
|
if (!ifexpr()) /* a false #if/#elif expression */
|
||||||
skip_block(0);
|
skip_block(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
do_ifdef(how)
|
void do_ifdef(int how)
|
||||||
{
|
{
|
||||||
register struct idf *id;
|
register struct idf *id;
|
||||||
register char *str;
|
register char *str;
|
||||||
@ -463,8 +478,7 @@ do_ifdef(how)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* argstr != NULL when the undef came from a -U option */
|
/* argstr != NULL when the undef came from a -U option */
|
||||||
do_undef(argstr)
|
void do_undef(char *argstr)
|
||||||
char *argstr;
|
|
||||||
{
|
{
|
||||||
register struct idf *id;
|
register struct idf *id;
|
||||||
register char *str = argstr;
|
register char *str = argstr;
|
||||||
@ -492,7 +506,7 @@ do_undef(argstr)
|
|||||||
error("illegal #undef construction");
|
error("illegal #undef construction");
|
||||||
}
|
}
|
||||||
|
|
||||||
do_error()
|
void do_error()
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
char *get_text();
|
char *get_text();
|
||||||
@ -503,10 +517,7 @@ do_error()
|
|||||||
LineNumber++;
|
LineNumber++;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int getparams(char *buf[], char parbuf[])
|
||||||
getparams(buf, parbuf)
|
|
||||||
char *buf[];
|
|
||||||
char parbuf[];
|
|
||||||
{
|
{
|
||||||
/* getparams() reads the formal parameter list of a macro
|
/* getparams() reads the formal parameter list of a macro
|
||||||
definition.
|
definition.
|
||||||
@ -570,11 +581,10 @@ getparams(buf, parbuf)
|
|||||||
c = skipspaces(c,0);
|
c = skipspaces(c,0);
|
||||||
}
|
}
|
||||||
/*NOTREACHED*/
|
/*NOTREACHED*/
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_def(id, text, nformals, length, flags)
|
void macro_def(struct idf *id, char *text, int nformals, int length, int flags)
|
||||||
register struct idf *id;
|
|
||||||
char *text;
|
|
||||||
{
|
{
|
||||||
register struct macro *newdef = id->id_macro;
|
register struct macro *newdef = id->id_macro;
|
||||||
|
|
||||||
@ -613,9 +623,7 @@ macro_def(id, text, nformals, length, flags)
|
|||||||
newdef->mc_flag = flags; /* special flags */
|
newdef->mc_flag = flags; /* special flags */
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int find_name(char *nm, char *index[])
|
||||||
find_name(nm, index)
|
|
||||||
char *nm, *index[];
|
|
||||||
{
|
{
|
||||||
/* find_name() returns the index of "nm" in the namelist
|
/* find_name() returns the index of "nm" in the namelist
|
||||||
"index" if it can be found there. 0 is returned if it is
|
"index" if it can be found there. 0 is returned if it is
|
||||||
@ -632,10 +640,7 @@ find_name(nm, index)
|
|||||||
|
|
||||||
#define BLANK(ch) ((ch == ' ') || (ch == '\t'))
|
#define BLANK(ch) ((ch == ' ') || (ch == '\t'))
|
||||||
|
|
||||||
char *
|
char *get_text(char *formals[], int *length)
|
||||||
get_text(formals, length)
|
|
||||||
char *formals[];
|
|
||||||
int *length;
|
|
||||||
{
|
{
|
||||||
/* get_text() copies the replacement text of a macro
|
/* get_text() copies the replacement text of a macro
|
||||||
definition with zero, one or more parameters, thereby
|
definition with zero, one or more parameters, thereby
|
||||||
@ -726,7 +731,7 @@ get_text(formals, length)
|
|||||||
add2repl(repl, ' ');
|
add2repl(repl, ' ');
|
||||||
}
|
}
|
||||||
/* construct the formal parameter mark or identifier */
|
/* 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);
|
add2repl(repl, FORMALP | (char) n);
|
||||||
else {
|
else {
|
||||||
idp = id_buf;
|
idp = id_buf;
|
||||||
@ -775,8 +780,7 @@ get_text(formals, length)
|
|||||||
as strings, without taking care of the leading and trailing
|
as strings, without taking care of the leading and trailing
|
||||||
blanks (spaces and tabs).
|
blanks (spaces and tabs).
|
||||||
*/
|
*/
|
||||||
macroeq(s, t)
|
int macroeq(char *s, char *t)
|
||||||
register char *s, *t;
|
|
||||||
{
|
{
|
||||||
|
|
||||||
/* skip leading spaces */
|
/* skip leading spaces */
|
||||||
@ -798,8 +802,7 @@ macroeq(s, t)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
do_line(l)
|
void do_line(unsigned int l)
|
||||||
unsigned int l;
|
|
||||||
{
|
{
|
||||||
struct token tk;
|
struct token tk;
|
||||||
int t = GetToken(&tk);
|
int t = GetToken(&tk);
|
||||||
|
|||||||
@ -23,8 +23,7 @@
|
|||||||
|
|
||||||
int err_occurred;
|
int err_occurred;
|
||||||
|
|
||||||
err_hdr(s)
|
void err_hdr(char *s)
|
||||||
char *s;
|
|
||||||
{
|
{
|
||||||
if (FileName) {
|
if (FileName) {
|
||||||
fprint(ERROUT, "\"%s\", line %d: %s", FileName, (int)LineNumber, s);
|
fprint(ERROUT, "\"%s\", line %d: %s", FileName, (int)LineNumber, s);
|
||||||
@ -34,7 +33,7 @@ err_hdr(s)
|
|||||||
|
|
||||||
#if __STDC__
|
#if __STDC__
|
||||||
/*VARARGS*/
|
/*VARARGS*/
|
||||||
error(char *fmt, ...)
|
void error(char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
@ -47,7 +46,7 @@ error(char *fmt, ...)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*VARARGS*/
|
/*VARARGS*/
|
||||||
warning(char *fmt, ...)
|
void warning(char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
@ -59,7 +58,7 @@ warning(char *fmt, ...)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*VARARGS*/
|
/*VARARGS*/
|
||||||
strict(char *fmt, ...)
|
void strict(char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
@ -71,7 +70,7 @@ strict(char *fmt, ...)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*VARARGS*/
|
/*VARARGS*/
|
||||||
crash(char *fmt, ...)
|
void crash(char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
@ -84,7 +83,7 @@ crash(char *fmt, ...)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*VARARGS*/
|
/*VARARGS*/
|
||||||
fatal(char *fmt, ...)
|
void fatal(char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
|
|||||||
@ -36,7 +36,7 @@ struct mkey {
|
|||||||
//char *strcpy();
|
//char *strcpy();
|
||||||
//char *sprint();
|
//char *sprint();
|
||||||
|
|
||||||
init_pp()
|
void init_pp()
|
||||||
{
|
{
|
||||||
static char *months[12] = {
|
static char *months[12] = {
|
||||||
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
||||||
@ -74,7 +74,7 @@ init_pp()
|
|||||||
/* __DATE__ */
|
/* __DATE__ */
|
||||||
sprint(dbuf, "\"%s %2d %d\"", months[tp->tm_mon],
|
sprint(dbuf, "\"%s %2d %d\"", months[tp->tm_mon],
|
||||||
tp->tm_mday, tp->tm_year+1900);
|
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);
|
macro_def(str2idf("__DATE__", 0), dbuf, -1, strlen(dbuf), NOUNDEF);
|
||||||
|
|
||||||
/* __TIME__ */
|
/* __TIME__ */
|
||||||
|
|||||||
@ -10,6 +10,7 @@
|
|||||||
#include <alloc.h>
|
#include <alloc.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <system.h>
|
#include <system.h>
|
||||||
|
#include <string.h>
|
||||||
#include "arith.h"
|
#include "arith.h"
|
||||||
#include "file_info.h"
|
#include "file_info.h"
|
||||||
#include "idfsize.h"
|
#include "idfsize.h"
|
||||||
@ -32,8 +33,13 @@ char *prog_name;
|
|||||||
extern char **inctable;
|
extern char **inctable;
|
||||||
extern int inc_max, inc_total;
|
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 */
|
/* parse and interpret the command line options */
|
||||||
prog_name = argv[0];
|
prog_name = argv[0];
|
||||||
@ -61,11 +67,12 @@ main(argc, argv)
|
|||||||
}
|
}
|
||||||
compile(argc - 1, &argv[1]);
|
compile(argc - 1, &argv[1]);
|
||||||
sys_stop(err_occurred ? S_EXIT : S_END);
|
sys_stop(err_occurred ? S_EXIT : S_END);
|
||||||
|
|
||||||
/*NOTREACHED*/
|
/*NOTREACHED*/
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
compile(argc, argv)
|
void compile(int argc, char *argv[])
|
||||||
char *argv[];
|
|
||||||
{
|
{
|
||||||
register char *source = 0;
|
register char *source = 0;
|
||||||
char *dummy;
|
char *dummy;
|
||||||
@ -94,10 +101,8 @@ compile(argc, argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct idf *file_head;
|
struct idf *file_head;
|
||||||
extern char *strrchr();
|
|
||||||
|
|
||||||
list_dependencies(source)
|
void list_dependencies(char *source)
|
||||||
char *source;
|
|
||||||
{
|
{
|
||||||
register struct idf *p = file_head;
|
register struct idf *p = file_head;
|
||||||
|
|
||||||
@ -112,7 +117,7 @@ list_dependencies(source)
|
|||||||
* object generated, so don't include the pathname
|
* object generated, so don't include the pathname
|
||||||
* leading to it.
|
* leading to it.
|
||||||
*/
|
*/
|
||||||
if (s = strrchr(source, '/')) {
|
if ( (s = strrchr(source, '/')) ) {
|
||||||
source = s + 1;
|
source = s + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -128,8 +133,7 @@ list_dependencies(source)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
add_dependency(s)
|
void add_dependency(char *s)
|
||||||
char *s;
|
|
||||||
{
|
{
|
||||||
register struct idf *p = str2idf(s, 0);
|
register struct idf *p = str2idf(s, 0);
|
||||||
|
|
||||||
@ -140,8 +144,7 @@ add_dependency(s)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependency(s, source)
|
void dependency(char *s, char *source)
|
||||||
char *s, *source;
|
|
||||||
{
|
{
|
||||||
if (options['i'] && !strncmp(s, "/usr/include/", 13)) {
|
if (options['i'] && !strncmp(s, "/usr/include/", 13)) {
|
||||||
return;
|
return;
|
||||||
@ -152,8 +155,7 @@ dependency(s, source)
|
|||||||
else fprint(dep_fd, "%s\n", s);
|
else fprint(dep_fd, "%s\n", s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void No_Mem() /* called by alloc package */
|
||||||
No_Mem() /* called by alloc package */
|
|
||||||
{
|
{
|
||||||
fatal("out of memory");
|
fatal("out of memory");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,10 +23,8 @@ char **inctable;
|
|||||||
char *dep_file = 0;
|
char *dep_file = 0;
|
||||||
|
|
||||||
extern int idfsize;
|
extern int idfsize;
|
||||||
int txt2int();
|
|
||||||
|
|
||||||
do_option(text)
|
void do_option(char *text)
|
||||||
char *text;
|
|
||||||
{
|
{
|
||||||
switch(*text++) {
|
switch(*text++) {
|
||||||
case '-':
|
case '-':
|
||||||
@ -127,9 +125,7 @@ do_option(text)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int txt2int(char **tp)
|
||||||
txt2int(tp)
|
|
||||||
char **tp;
|
|
||||||
{
|
{
|
||||||
/* the integer pointed to by *tp is read, while increasing
|
/* the integer pointed to by *tp is read, while increasing
|
||||||
*tp; the resulting value is yielded.
|
*tp; the resulting value is yielded.
|
||||||
|
|||||||
@ -29,12 +29,11 @@ extern int InputLevel;
|
|||||||
|
|
||||||
extern char *sprint();
|
extern char *sprint();
|
||||||
|
|
||||||
Xflush()
|
void Xflush()
|
||||||
{
|
{
|
||||||
sys_write(STDOUT, _obuf, OBUFSIZE);
|
sys_write(STDOUT, _obuf, OBUFSIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *SkipComment();
|
|
||||||
extern char options[];
|
extern char options[];
|
||||||
|
|
||||||
/* #pragma directives are saved here and passed to the compiler later on.
|
/* #pragma directives are saved here and passed to the compiler later on.
|
||||||
@ -47,7 +46,10 @@ struct prag_info {
|
|||||||
static struct prag_info *pragma_tab;
|
static struct prag_info *pragma_tab;
|
||||||
static int pragma_nr;
|
static int pragma_nr;
|
||||||
|
|
||||||
do_pragma()
|
static char *SkipComment(char *op, int *lineno);
|
||||||
|
void preprocess(char *fn);
|
||||||
|
|
||||||
|
void do_pragma()
|
||||||
{
|
{
|
||||||
register int size = ITEXTSIZE;
|
register int size = ITEXTSIZE;
|
||||||
char *cur_line = Malloc((unsigned)size);
|
char *cur_line = Malloc((unsigned)size);
|
||||||
@ -105,8 +107,7 @@ do_pragma()
|
|||||||
|
|
||||||
char Xbuf[256];
|
char Xbuf[256];
|
||||||
|
|
||||||
preprocess(fn)
|
void preprocess(char *fn)
|
||||||
char *fn;
|
|
||||||
{
|
{
|
||||||
register int c;
|
register int c;
|
||||||
register char *op = _obuf;
|
register char *op = _obuf;
|
||||||
@ -409,10 +410,7 @@ preprocess(fn)
|
|||||||
/*NOTREACHED*/
|
/*NOTREACHED*/
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
static char *SkipComment(char *op, int *lineno)
|
||||||
SkipComment(op, lineno)
|
|
||||||
char *op;
|
|
||||||
int *lineno;
|
|
||||||
{
|
{
|
||||||
char *ob = &_obuf[OBUFSIZE];
|
char *ob = &_obuf[OBUFSIZE];
|
||||||
register int c, oldc = '\0';
|
register int c, oldc = '\0';
|
||||||
|
|||||||
@ -26,15 +26,19 @@
|
|||||||
#include "macbuf.h"
|
#include "macbuf.h"
|
||||||
#include "replace.h"
|
#include "replace.h"
|
||||||
|
|
||||||
//extern char *GetIdentifier();
|
|
||||||
//extern char *strcpy();
|
|
||||||
//extern char *strcat();
|
|
||||||
extern int InputLevel;
|
extern int InputLevel;
|
||||||
struct repl *ReplaceList; /* list of currently active macros */
|
struct repl *ReplaceList; /* list of currently active macros */
|
||||||
|
|
||||||
int
|
void expand_defined(struct repl *repl);
|
||||||
replace(idf)
|
void getactuals(struct repl *repl, struct idf *idf);
|
||||||
register 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
|
/* replace is called by the lexical analyzer to perform
|
||||||
macro replacement. The routine actualy functions as a
|
macro replacement. The routine actualy functions as a
|
||||||
@ -60,13 +64,12 @@ replace(idf)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
unstackrepl()
|
void unstackrepl()
|
||||||
{
|
{
|
||||||
Unstacked++;
|
Unstacked++;
|
||||||
}
|
}
|
||||||
|
|
||||||
freeargs(args)
|
void freeargs(struct args *args)
|
||||||
struct args *args;
|
|
||||||
{
|
{
|
||||||
register int i;
|
register int i;
|
||||||
|
|
||||||
@ -84,7 +87,7 @@ freeargs(args)
|
|||||||
free_args(args);
|
free_args(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
EnableMacros()
|
void EnableMacros()
|
||||||
{
|
{
|
||||||
register struct repl *r = ReplaceList, *prev = 0;
|
register struct repl *r = ReplaceList, *prev = 0;
|
||||||
|
|
||||||
@ -106,9 +109,7 @@ EnableMacros()
|
|||||||
Unstacked = 0;
|
Unstacked = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
expand_macro(repl, idf)
|
int expand_macro(struct repl *repl, struct idf *idf)
|
||||||
register struct repl *repl;
|
|
||||||
register struct idf *idf;
|
|
||||||
{
|
{
|
||||||
/* expand_macro() does the actual macro replacement.
|
/* expand_macro() does the actual macro replacement.
|
||||||
"idf" is a description of the identifier which
|
"idf" is a description of the identifier which
|
||||||
@ -171,8 +172,7 @@ expand_macro(repl, idf)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
expand_defined(repl)
|
void expand_defined(struct repl *repl)
|
||||||
register struct repl *repl;
|
|
||||||
{
|
{
|
||||||
register int ch = GetChar();
|
register int ch = GetChar();
|
||||||
struct idf *id;
|
struct idf *id;
|
||||||
@ -207,16 +207,13 @@ expand_defined(repl)
|
|||||||
add2repl(repl, ' ');
|
add2repl(repl, ' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
newarg(args)
|
void newarg(struct args *args)
|
||||||
struct args *args;
|
|
||||||
{
|
{
|
||||||
args->a_expptr = args->a_expbuf = Malloc((unsigned)(args->a_expsize = ARGBUF));
|
args->a_expptr = args->a_expbuf = Malloc((unsigned)(args->a_expsize = ARGBUF));
|
||||||
args->a_rawptr = args->a_rawbuf = Malloc((unsigned)(args->a_rawsize = ARGBUF));
|
args->a_rawptr = args->a_rawbuf = Malloc((unsigned)(args->a_rawsize = ARGBUF));
|
||||||
}
|
}
|
||||||
|
|
||||||
getactuals(repl, idf)
|
void getactuals(struct repl *repl, struct idf *idf)
|
||||||
struct repl *repl;
|
|
||||||
register struct idf *idf;
|
|
||||||
{
|
{
|
||||||
/* Get the actual parameters from the input stream.
|
/* Get the actual parameters from the input stream.
|
||||||
The hard part is done by actual(), only comma's and
|
The hard part is done by actual(), only comma's and
|
||||||
@ -257,8 +254,7 @@ getactuals(repl, idf)
|
|||||||
error("too many macro arguments");
|
error("too many macro arguments");
|
||||||
}
|
}
|
||||||
|
|
||||||
saveraw(repl)
|
void saveraw(struct repl *repl)
|
||||||
struct repl *repl;
|
|
||||||
{
|
{
|
||||||
register struct repl *nrepl = ReplaceList;
|
register struct repl *nrepl = ReplaceList;
|
||||||
register struct args *ap = nrepl->r_args;
|
register struct args *ap = nrepl->r_args;
|
||||||
@ -295,9 +291,7 @@ struct repl *repl;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int actual(struct repl *repl)
|
||||||
actual(repl)
|
|
||||||
struct repl *repl;
|
|
||||||
{
|
{
|
||||||
/* This routine deals with the scanning of an actual parameter.
|
/* This routine deals with the scanning of an actual parameter.
|
||||||
It keeps in account the opening and closing brackets,
|
It keeps in account the opening and closing brackets,
|
||||||
@ -498,8 +492,7 @@ a_new_line: ch = GetChar();
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_func(idef)
|
void macro_func(struct idf *idef)
|
||||||
register struct idf *idef;
|
|
||||||
{
|
{
|
||||||
/* macro_func() performs the special actions needed with some
|
/* macro_func() performs the special actions needed with some
|
||||||
macros. These macros are __FILE__ and __LINE__ which
|
macros. These macros are __FILE__ and __LINE__ which
|
||||||
@ -528,10 +521,7 @@ macro_func(idef)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
macro2buffer(repl, idf, args)
|
void macro2buffer(struct repl *repl, struct idf *idf, struct args *args)
|
||||||
register struct repl *repl;
|
|
||||||
register struct idf *idf;
|
|
||||||
register struct args *args;
|
|
||||||
{
|
{
|
||||||
/* macro2buffer expands the replacement list and places the
|
/* macro2buffer expands the replacement list and places the
|
||||||
result onto the replacement buffer. It deals with the #
|
result onto the replacement buffer. It deals with the #
|
||||||
@ -681,11 +671,7 @@ macro2buffer(repl, idf, args)
|
|||||||
error("illegal use of ## operator");
|
error("illegal use of ## operator");
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *stringify(struct repl *repl, char *ptr, struct args *args)
|
||||||
stringify(repl, ptr, args)
|
|
||||||
register struct repl *repl;
|
|
||||||
register char *ptr;
|
|
||||||
register struct args *args;
|
|
||||||
{
|
{
|
||||||
/* If a parameter is immediately preceded by a # token
|
/* If a parameter is immediately preceded by a # token
|
||||||
both are replaced by a single string literal that
|
both are replaced by a single string literal that
|
||||||
@ -748,9 +734,7 @@ stringify(repl, ptr, args)
|
|||||||
|
|
||||||
/* The following routine is also called from domacro.c.
|
/* The following routine is also called from domacro.c.
|
||||||
*/
|
*/
|
||||||
add2repl(repl, ch)
|
void add2repl(struct repl *repl, int ch)
|
||||||
register struct repl *repl;
|
|
||||||
int ch;
|
|
||||||
{
|
{
|
||||||
register int index = repl->r_ptr - repl->r_text;
|
register int index = repl->r_ptr - repl->r_text;
|
||||||
|
|
||||||
@ -767,10 +751,7 @@ add2repl(repl, ch)
|
|||||||
* buffer. If the variable is zero, we must only stash into the expanded
|
* buffer. If the variable is zero, we must only stash into the expanded
|
||||||
* buffer. Otherwise, we must use both buffers.
|
* buffer. Otherwise, we must use both buffers.
|
||||||
*/
|
*/
|
||||||
stash(repl, ch, stashraw)
|
void stash(struct repl *repl, int ch, int stashraw)
|
||||||
struct repl *repl;
|
|
||||||
register int ch;
|
|
||||||
int stashraw;
|
|
||||||
{
|
{
|
||||||
/* Stash characters into the macro expansion buffer.
|
/* Stash characters into the macro expansion buffer.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -19,15 +19,11 @@ static struct idf *IDF_hashtable[IDF_HASHSIZE];
|
|||||||
|
|
||||||
_PROTOTYPE(static struct idf *IDF_new, (char *, int, int));
|
_PROTOTYPE(static struct idf *IDF_new, (char *, int, int));
|
||||||
|
|
||||||
void
|
void init_idf()
|
||||||
init_idf()
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct idf *
|
static struct idf *IDF_new(char *tg, int size, int cpy)
|
||||||
IDF_new(tg, size, cpy)
|
|
||||||
register char *tg;
|
|
||||||
register int size;
|
|
||||||
{
|
{
|
||||||
static int nidf;
|
static int nidf;
|
||||||
static struct idf *pidf;
|
static struct idf *pidf;
|
||||||
@ -67,8 +63,7 @@ IDF_new(tg, size, cpy)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef IDF_DEBUG
|
#ifdef IDF_DEBUG
|
||||||
void
|
void hash_stat()
|
||||||
hash_stat()
|
|
||||||
{
|
{
|
||||||
register int i;
|
register int i;
|
||||||
int total_count = 0;
|
int total_count = 0;
|
||||||
@ -91,10 +86,7 @@ hash_stat()
|
|||||||
print("End hash table tally\n");
|
print("End hash table tally\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void idfappfun(int (*fun)(struct idf *, int), int opt)
|
||||||
idfappfun(fun, opt)
|
|
||||||
int (*fun)();
|
|
||||||
int opt;
|
|
||||||
{
|
{
|
||||||
register int i;
|
register int i;
|
||||||
|
|
||||||
@ -109,9 +101,7 @@ idfappfun(fun, opt)
|
|||||||
}
|
}
|
||||||
#endif /* IDF_DEBUG */
|
#endif /* IDF_DEBUG */
|
||||||
|
|
||||||
struct idf *
|
struct idf *str2idf(char tg[], int cpy)
|
||||||
str2idf(tg, cpy)
|
|
||||||
char tg[];
|
|
||||||
{
|
{
|
||||||
/* str2idf() returns an entry in the symbol table for the
|
/* str2idf() returns an entry in the symbol table for the
|
||||||
identifier tg. If necessary, an entry is created.
|
identifier tg. If necessary, an entry is created.
|
||||||
@ -124,7 +114,7 @@ str2idf(tg, cpy)
|
|||||||
int size;
|
int size;
|
||||||
|
|
||||||
IDF_STARTHASH(hash);
|
IDF_STARTHASH(hash);
|
||||||
while (c = *cp++) {
|
while ((c = *cp++)) {
|
||||||
IDF_ENHASH(hash, c);
|
IDF_ENHASH(hash, c);
|
||||||
}
|
}
|
||||||
IDF_STOPHASH(hash);
|
IDF_STOPHASH(hash);
|
||||||
|
|||||||
@ -99,12 +99,16 @@ INP_PRIVATE struct INP_buffer_header *INP_head, *INP_free;
|
|||||||
|
|
||||||
_PROTOTYPE(INP_PRIVATE int INP_rdfile, (File *, char *, long *, char **));
|
_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_PRIVATE int
|
||||||
INP_rdfile(fd, fn, size, pbuf)
|
INP_rdfile(fd, fn, size, pbuf)
|
||||||
register File *fd;
|
register File *fd;
|
||||||
char *fn; /* file name */
|
char *fn; /* file name */
|
||||||
register long *size;
|
register long *size;
|
||||||
char **pbuf; /* output parameter */
|
char **pbuf; /* output parameter */
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
extern long sys_filesize();
|
extern long sys_filesize();
|
||||||
int rsize;
|
int rsize;
|
||||||
@ -137,8 +141,7 @@ INP_rdfile(fd, fn, size, pbuf)
|
|||||||
INP_PRIVATE struct INP_i_buf *i_ptr;
|
INP_PRIVATE struct INP_i_buf *i_ptr;
|
||||||
|
|
||||||
_PROTOTYPE(INP_PRIVATE char * INP_pbuf, (void));
|
_PROTOTYPE(INP_PRIVATE char * INP_pbuf, (void));
|
||||||
INP_PRIVATE char *
|
INP_PRIVATE char *INP_pbuf()
|
||||||
INP_pbuf()
|
|
||||||
{
|
{
|
||||||
register struct INP_i_buf *ib =
|
register struct INP_i_buf *ib =
|
||||||
(struct INP_i_buf *) malloc(sizeof(struct INP_i_buf));
|
(struct INP_i_buf *) malloc(sizeof(struct INP_i_buf));
|
||||||
@ -159,12 +162,11 @@ INP_pbuf()
|
|||||||
_PROTOTYPE(INP_PRIVATE struct INP_buffer_header *INP_push_bh, (void));
|
_PROTOTYPE(INP_PRIVATE struct INP_buffer_header *INP_push_bh, (void));
|
||||||
_PROTOTYPE(INP_PRIVATE int INP_pop_bh, (void));
|
_PROTOTYPE(INP_PRIVATE int INP_pop_bh, (void));
|
||||||
|
|
||||||
INP_PRIVATE struct INP_buffer_header *
|
INP_PRIVATE struct INP_buffer_header *INP_push_bh()
|
||||||
INP_push_bh()
|
|
||||||
{
|
{
|
||||||
register struct INP_buffer_header *bh;
|
register struct INP_buffer_header *bh;
|
||||||
|
|
||||||
if (bh = INP_head) {
|
if ((bh = INP_head)) {
|
||||||
bh->bh_ipp = _ipp;
|
bh->bh_ipp = _ipp;
|
||||||
#ifdef INP_TYPE
|
#ifdef INP_TYPE
|
||||||
bh->bh_i = INP_VAR;
|
bh->bh_i = INP_VAR;
|
||||||
@ -183,8 +185,7 @@ INP_push_bh()
|
|||||||
of headers. 0 is returned if there are no more
|
of headers. 0 is returned if there are no more
|
||||||
inputbuffers on the stack, 1 is returned in the other case.
|
inputbuffers on the stack, 1 is returned in the other case.
|
||||||
*/
|
*/
|
||||||
INP_PRIVATE int
|
INP_PRIVATE int INP_pop_bh()
|
||||||
INP_pop_bh()
|
|
||||||
{
|
{
|
||||||
register struct INP_buffer_header *bh = INP_head;
|
register struct INP_buffer_header *bh = INP_head;
|
||||||
|
|
||||||
@ -213,11 +214,15 @@ INP_pop_bh()
|
|||||||
*/
|
*/
|
||||||
_PROTOTYPE(INP_PRIVATE int INP_rdblock, (File *, char *, int *));
|
_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_PRIVATE int
|
||||||
INP_rdblock(fd, buf, n)
|
INP_rdblock(fd, buf, n)
|
||||||
File *fd;
|
File *fd;
|
||||||
char *buf;
|
char *buf;
|
||||||
int *n;
|
int *n;
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!sys_read(fd, buf, INP_BUFSIZE, n)) {
|
if (!sys_read(fd, buf, INP_BUFSIZE, n)) {
|
||||||
@ -235,10 +240,14 @@ _PROTOTYPE(INP_PRIVATE int INP_mk_filename, (char *, char *, char **));
|
|||||||
|
|
||||||
/* INP_mk_filename() concatenates a dir and filename.
|
/* 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_PRIVATE int
|
||||||
INP_mk_filename(dir, file, newname)
|
INP_mk_filename(dir, file, newname)
|
||||||
register char *dir, *file;
|
register char *dir, *file;
|
||||||
char **newname;
|
char **newname;
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
|
|
||||||
register char *dst;
|
register char *dst;
|
||||||
@ -247,21 +256,24 @@ INP_mk_filename(dir, file, newname)
|
|||||||
if (!dst) return 0;
|
if (!dst) return 0;
|
||||||
*newname = dst;
|
*newname = dst;
|
||||||
if (*dir) {
|
if (*dir) {
|
||||||
while (*dst++ = *dir++) ;
|
while (((*dst++) = (*dir++))) ;
|
||||||
*(dst-1) = '/';
|
*(dst-1) = '/';
|
||||||
}
|
}
|
||||||
while (*dst++ = *file++);
|
while (((*dst++) = (*file++)));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Interface routines : InsertFile, InsertText, and loadbuf
|
/* Interface routines : InsertFile, InsertText, and loadbuf
|
||||||
*/
|
*/
|
||||||
|
#if __STDC__
|
||||||
|
int InsertFile(char *filnam, char *table[], char **result)
|
||||||
|
#else
|
||||||
int
|
int
|
||||||
InsertFile(filnam, table, result)
|
InsertFile(filnam, table, result)
|
||||||
char *filnam;
|
char *filnam;
|
||||||
char *table[];
|
char *table[];
|
||||||
char **result;
|
char **result;
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
char *newfn = 0;
|
char *newfn = 0;
|
||||||
|
|
||||||
@ -327,9 +339,13 @@ InsertFile(filnam, table, result)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if __STDC__
|
||||||
|
int InsertText(char *text, int length)
|
||||||
|
#else
|
||||||
int
|
int
|
||||||
InsertText(text, length)
|
InsertText(text, length)
|
||||||
char *text;
|
char *text;
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
register struct INP_buffer_header *bh = INP_push_bh();
|
register struct INP_buffer_header *bh = INP_push_bh();
|
||||||
|
|
||||||
@ -346,8 +362,7 @@ InsertText(text, length)
|
|||||||
Note: this routine is exported due to its occurence in the definition
|
Note: this routine is exported due to its occurence in the definition
|
||||||
of LoadChar [input.h], that is defined as a macro.
|
of LoadChar [input.h], that is defined as a macro.
|
||||||
*/
|
*/
|
||||||
int
|
int loadbuf()
|
||||||
loadbuf()
|
|
||||||
{
|
{
|
||||||
register struct INP_buffer_header *bh = INP_head;
|
register struct INP_buffer_header *bh = INP_head;
|
||||||
static char buf[INP_NPUSHBACK + 1];
|
static char buf[INP_NPUSHBACK + 1];
|
||||||
|
|||||||
@ -113,9 +113,9 @@ registerdefs
|
|||||||
|
|
||||||
registerdef
|
registerdef
|
||||||
: IDENT '=' '(' STRING ',' NUMBER list1 ')' optregvar list1 '.'
|
: IDENT '=' '(' STRING ',' NUMBER list1 ')' optregvar list1 '.'
|
||||||
{ register ident_p ip;
|
{ ident_p ip;
|
||||||
register list1 l;
|
list1 l;
|
||||||
register reginfo r;
|
reginfo r;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
r=(reginfo) myalloc(sizeof(struct reginfo));
|
r=(reginfo) myalloc(sizeof(struct reginfo));
|
||||||
@ -190,8 +190,8 @@ tkdefs
|
|||||||
;
|
;
|
||||||
tkdef
|
tkdef
|
||||||
: IDENT '=' structdecl NUMBER optcost optformat
|
: IDENT '=' structdecl NUMBER optcost optformat
|
||||||
{ register token_p tp;
|
{ token_p tp;
|
||||||
register ident_p ip;
|
ident_p ip;
|
||||||
|
|
||||||
chktabsiz(nmachtokens,MAXTOKENS,"Token table");
|
chktabsiz(nmachtokens,MAXTOKENS,"Token table");
|
||||||
tp = &machtokens[nmachtokens];
|
tp = &machtokens[nmachtokens];
|
||||||
@ -253,7 +253,7 @@ tokenexpressions
|
|||||||
tokenexpressionline
|
tokenexpressionline
|
||||||
: IDENT '=' tokenexpression
|
: IDENT '=' tokenexpression
|
||||||
{
|
{
|
||||||
{ register ident_p ip;
|
{ ident_p ip;
|
||||||
|
|
||||||
chktabsiz(nmachsets,MAXSETS,"Expression table");
|
chktabsiz(nmachsets,MAXSETS,"Expression table");
|
||||||
machsets[nmachsets] = $3;
|
machsets[nmachsets] = $3;
|
||||||
@ -268,7 +268,7 @@ tokenexpression
|
|||||||
: PIDENT
|
: PIDENT
|
||||||
{ $$ = machprops[$1->i_i.i_prpno].propset; }
|
{ $$ = machprops[$1->i_i.i_prpno].propset; }
|
||||||
| TIDENT
|
| TIDENT
|
||||||
{ register i;
|
{ int i;
|
||||||
|
|
||||||
for(i=0;i<SETSIZE;i++) $$.set_val[i]=0;
|
for(i=0;i<SETSIZE;i++) $$.set_val[i]=0;
|
||||||
$$.set_val[($1->i_i.i_tokno+nmachregs+1)>>4] |=
|
$$.set_val[($1->i_i.i_tokno+nmachregs+1)>>4] |=
|
||||||
@ -278,7 +278,7 @@ tokenexpression
|
|||||||
| EIDENT
|
| EIDENT
|
||||||
{ $$=machsets[$1->i_i.i_expno]; }
|
{ $$=machsets[$1->i_i.i_expno]; }
|
||||||
| tokenexpression '*' tokenexpression
|
| tokenexpression '*' tokenexpression
|
||||||
{ register i;
|
{ int i;
|
||||||
|
|
||||||
if (($$.set_size=$1.set_size)==0)
|
if (($$.set_size=$1.set_size)==0)
|
||||||
$$.set_size = $3.set_size;
|
$$.set_size = $3.set_size;
|
||||||
@ -286,7 +286,7 @@ tokenexpression
|
|||||||
$$.set_val[i] = $1.set_val[i] & $3.set_val[i];
|
$$.set_val[i] = $1.set_val[i] & $3.set_val[i];
|
||||||
}
|
}
|
||||||
| tokenexpression '+' tokenexpression
|
| tokenexpression '+' tokenexpression
|
||||||
{ register i;
|
{ int i;
|
||||||
|
|
||||||
if ($1.set_size == -1)
|
if ($1.set_size == -1)
|
||||||
$$.set_size = $3.set_size;
|
$$.set_size = $3.set_size;
|
||||||
@ -300,7 +300,7 @@ tokenexpression
|
|||||||
$$.set_val[i] = $1.set_val[i] | $3.set_val[i];
|
$$.set_val[i] = $1.set_val[i] | $3.set_val[i];
|
||||||
}
|
}
|
||||||
| tokenexpression '-' tokenexpression
|
| tokenexpression '-' tokenexpression
|
||||||
{ register i;
|
{ int i;
|
||||||
|
|
||||||
if ($1.set_size == -1)
|
if ($1.set_size == -1)
|
||||||
$$.set_size = $3.set_size;
|
$$.set_size = $3.set_size;
|
||||||
@ -403,7 +403,7 @@ empattern
|
|||||||
: /* empty */
|
: /* empty */
|
||||||
{ empatlen=0; }
|
{ empatlen=0; }
|
||||||
| mnemlist optboolexpr
|
| mnemlist optboolexpr
|
||||||
{ register i;
|
{ int i;
|
||||||
|
|
||||||
empatexpr = $2;
|
empatexpr = $2;
|
||||||
patbyte(0);
|
patbyte(0);
|
||||||
@ -441,7 +441,7 @@ mnem : IDENT
|
|||||||
|
|
||||||
stackpattern
|
stackpattern
|
||||||
: optnocoerc tokenexpressionlist optstack
|
: optnocoerc tokenexpressionlist optstack
|
||||||
{ register i;
|
{ int i;
|
||||||
|
|
||||||
if (tokpatlen != 0) {
|
if (tokpatlen != 0) {
|
||||||
outbyte(($1 ? ( $3 ? DO_XXMATCH: DO_XMATCH ) : DO_MATCH)+(tokpatlen<<5));
|
outbyte(($1 ? ( $3 ? DO_XXMATCH: DO_XMATCH ) : DO_MATCH)+(tokpatlen<<5));
|
||||||
@ -703,7 +703,7 @@ movedef
|
|||||||
tokpatlen=2;
|
tokpatlen=2;
|
||||||
}
|
}
|
||||||
optboolexpr ',' code optcommacost ')'
|
optboolexpr ',' code optcommacost ')'
|
||||||
{ register move_p mp;
|
{ move_p mp;
|
||||||
|
|
||||||
outbyte(DO_RETURN);
|
outbyte(DO_RETURN);
|
||||||
fprintf(cfile,"\n");
|
fprintf(cfile,"\n");
|
||||||
@ -735,7 +735,7 @@ testdef : '(' tokenexpressionno
|
|||||||
tokpatlen=2;
|
tokpatlen=2;
|
||||||
}
|
}
|
||||||
optboolexpr ',' code optcommacost ')'
|
optboolexpr ',' code optcommacost ')'
|
||||||
{ register move_p mp;
|
{ move_p mp;
|
||||||
|
|
||||||
outbyte(DO_RETURN);
|
outbyte(DO_RETURN);
|
||||||
fprintf(cfile,"\n");
|
fprintf(cfile,"\n");
|
||||||
@ -765,7 +765,7 @@ stackdef
|
|||||||
tokpatlen=1;
|
tokpatlen=1;
|
||||||
}
|
}
|
||||||
optboolexpr ',' optprop ',' code optcommacost ')'
|
optboolexpr ',' optprop ',' code optcommacost ')'
|
||||||
{ register c1_p cp;
|
{ c1_p cp;
|
||||||
|
|
||||||
outbyte(DO_TOKREPLACE);
|
outbyte(DO_TOKREPLACE);
|
||||||
outbyte(DO_RETURN);
|
outbyte(DO_RETURN);
|
||||||
@ -1053,7 +1053,7 @@ tokeninstanceno
|
|||||||
|
|
||||||
tokeninstance
|
tokeninstance
|
||||||
: '%' '[' tokargno subreg ']'
|
: '%' '[' tokargno subreg ']'
|
||||||
{ register i;
|
{ int i;
|
||||||
|
|
||||||
if ($4!=0)
|
if ($4!=0)
|
||||||
chkregexp(pattokexp[$3]);
|
chkregexp(pattokexp[$3]);
|
||||||
@ -1065,7 +1065,7 @@ tokeninstance
|
|||||||
}
|
}
|
||||||
| '%' '[' tokargno '.' IDENT ']'
|
| '%' '[' tokargno '.' IDENT ']'
|
||||||
{ int typ;
|
{ int typ;
|
||||||
register i;
|
int i;
|
||||||
$$.in_which = IN_COPY;
|
$$.in_which = IN_COPY;
|
||||||
$$.in_info[0] = $3;
|
$$.in_info[0] = $3;
|
||||||
$$.in_info[1] = findstructel(pattokexp[$3],$5,&typ);
|
$$.in_info[1] = findstructel(pattokexp[$3],$5,&typ);
|
||||||
@ -1075,14 +1075,14 @@ tokeninstance
|
|||||||
$$.in_info[i] = 0;
|
$$.in_info[i] = 0;
|
||||||
}
|
}
|
||||||
| RIDENT
|
| RIDENT
|
||||||
{ register i;
|
{ int i;
|
||||||
$$.in_which = IN_RIDENT;
|
$$.in_which = IN_RIDENT;
|
||||||
$$.in_info[0] = $1->i_i.i_regno;
|
$$.in_info[0] = $1->i_i.i_regno;
|
||||||
for (i=1;i<TOKENSIZE;i++)
|
for (i=1;i<TOKENSIZE;i++)
|
||||||
$$.in_info[i] = 0;
|
$$.in_info[i] = 0;
|
||||||
}
|
}
|
||||||
| REGVAR '(' expr ')'
|
| REGVAR '(' expr ')'
|
||||||
{ register i;
|
{ int i;
|
||||||
MUST1BEINT($3);
|
MUST1BEINT($3);
|
||||||
$$.in_which = IN_REGVAR;
|
$$.in_which = IN_REGVAR;
|
||||||
$$.in_info[0] = exp1;
|
$$.in_info[0] = exp1;
|
||||||
@ -1090,7 +1090,7 @@ tokeninstance
|
|||||||
$$.in_info[i] = 0;
|
$$.in_info[i] = 0;
|
||||||
}
|
}
|
||||||
| '%' '[' LCASELETTER subreg ']'
|
| '%' '[' LCASELETTER subreg ']'
|
||||||
{ register i;
|
{ int i;
|
||||||
if ($3 >= 'a'+nallreg)
|
if ($3 >= 'a'+nallreg)
|
||||||
yyerror("Bad letter in %[x] construct");
|
yyerror("Bad letter in %[x] construct");
|
||||||
$$.in_which = IN_ALLOC;
|
$$.in_which = IN_ALLOC;
|
||||||
@ -1100,7 +1100,7 @@ tokeninstance
|
|||||||
$$.in_info[i] = 0;
|
$$.in_info[i] = 0;
|
||||||
}
|
}
|
||||||
| '{' TIDENT attlist '}'
|
| '{' TIDENT attlist '}'
|
||||||
{ register i;
|
{ int i;
|
||||||
$$.in_which = IN_DESCR;
|
$$.in_which = IN_DESCR;
|
||||||
$$.in_info[0] = $2->i_i.i_tokno;
|
$$.in_info[0] = $2->i_i.i_tokno;
|
||||||
for(i=0;i<narexp;i++) {
|
for(i=0;i<narexp;i++) {
|
||||||
|
|||||||
@ -21,6 +21,8 @@ static char rcsid2[]="$Id$";
|
|||||||
#include "booth.h"
|
#include "booth.h"
|
||||||
#include "y.tab.h"
|
#include "y.tab.h"
|
||||||
|
|
||||||
|
void yyerror(string s);
|
||||||
|
|
||||||
int lineno = 1;
|
int lineno = 1;
|
||||||
extern char *iname;
|
extern char *iname;
|
||||||
extern char *scopy();
|
extern char *scopy();
|
||||||
@ -158,10 +160,9 @@ return return(RETURN);
|
|||||||
. return(yytext[0]);
|
. 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\", line %d:",iname ? iname : "",lineno);
|
||||||
fprintf(stderr,s,a1,a2,a3,a4);
|
|
||||||
fprintf(stderr,"\n");
|
fprintf(stderr,"\n");
|
||||||
nerrors++;
|
nerrors++;
|
||||||
}
|
}
|
||||||
|
|||||||
305
util/cgg/main.c
305
util/cgg/main.c
@ -9,7 +9,23 @@
|
|||||||
|
|
||||||
#include "booth.h"
|
#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;
|
register char *p;
|
||||||
|
|
||||||
p= malloc((unsigned)n);
|
p= malloc((unsigned)n);
|
||||||
@ -20,21 +36,22 @@ char * myalloc(n) {
|
|||||||
return(p);
|
return(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
tstint(e) expr_t e; {
|
void tstint(expr_t e)
|
||||||
|
{
|
||||||
if(e.expr_typ != TYPINT)
|
if(e.expr_typ != TYPINT)
|
||||||
yyerror("Must be integer expression");
|
yyerror("Must be integer expression");
|
||||||
}
|
}
|
||||||
|
|
||||||
tstbool(e) expr_t e; {
|
void tstbool(expr_t e)
|
||||||
|
{
|
||||||
if(e.expr_typ != TYPBOOL)
|
if(e.expr_typ != TYPBOOL)
|
||||||
yyerror("Must be boolean expression");
|
yyerror("Must be boolean expression");
|
||||||
}
|
}
|
||||||
|
|
||||||
structsize(s) register list2 s; {
|
int structsize(register list2 s)
|
||||||
register list1 l;
|
{
|
||||||
register sum;
|
list1 l;
|
||||||
|
int sum;
|
||||||
|
|
||||||
sum = 0;
|
sum = 0;
|
||||||
while ( s != 0 ) {
|
while ( s != 0 ) {
|
||||||
@ -48,7 +65,8 @@ structsize(s) register list2 s; {
|
|||||||
return(sum);
|
return(sum);
|
||||||
}
|
}
|
||||||
|
|
||||||
list2 lookstruct(ll) list2 ll; {
|
list2 lookstruct(list2 ll)
|
||||||
|
{
|
||||||
list3 l3;
|
list3 l3;
|
||||||
list2 l21,l22;
|
list2 l21,l22;
|
||||||
list1 l11,l12;
|
list1 l11,l12;
|
||||||
@ -74,8 +92,9 @@ list2 lookstruct(ll) list2 ll; {
|
|||||||
return(ll);
|
return(ll);
|
||||||
}
|
}
|
||||||
|
|
||||||
instno(inst) inst_t inst; {
|
int instno(inst_t inst)
|
||||||
register i,j;
|
{
|
||||||
|
int i,j;
|
||||||
|
|
||||||
for(i=1;i<narinstance;i++) {
|
for(i=1;i<narinstance;i++) {
|
||||||
if (arinstance[i].in_which != inst.in_which)
|
if (arinstance[i].in_which != inst.in_which)
|
||||||
@ -91,16 +110,18 @@ instno(inst) inst_t inst; {
|
|||||||
return(narinstance++);
|
return(narinstance++);
|
||||||
}
|
}
|
||||||
|
|
||||||
string scopy(s) string s; {
|
string scopy(string s)
|
||||||
register string t;
|
{
|
||||||
|
string t;
|
||||||
|
|
||||||
t = (char *) myalloc(strlen(s)+1);
|
t = (char *) myalloc(strlen(s)+1);
|
||||||
strcpy(t,s);
|
strcpy(t,s);
|
||||||
return(t);
|
return(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
strlookup(s) string s; {
|
int strlookup(string s)
|
||||||
register i;
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
for(i=0;i<ncodestrings;i++)
|
for(i=0;i<ncodestrings;i++)
|
||||||
if(strcmp(s,codestrings[i])==0)
|
if(strcmp(s,codestrings[i])==0)
|
||||||
@ -110,9 +131,10 @@ strlookup(s) string s; {
|
|||||||
return(ncodestrings++);
|
return(ncodestrings++);
|
||||||
}
|
}
|
||||||
|
|
||||||
stringno(s) register string s; {
|
int stringno(string s)
|
||||||
|
{
|
||||||
char buf[256];
|
char buf[256];
|
||||||
register char *p=buf;
|
char *p=buf;
|
||||||
|
|
||||||
while(*s != 0) switch(*s) {
|
while(*s != 0) switch(*s) {
|
||||||
default:
|
default:
|
||||||
@ -212,7 +234,8 @@ stringno(s) register string s; {
|
|||||||
return(strlookup(buf));
|
return(strlookup(buf));
|
||||||
}
|
}
|
||||||
|
|
||||||
tabovf(tablename) string tablename; {
|
void tabovf(string tablename)
|
||||||
|
{
|
||||||
char buf[256];
|
char buf[256];
|
||||||
|
|
||||||
sprintf(buf,"%s overflow",tablename);
|
sprintf(buf,"%s overflow",tablename);
|
||||||
@ -220,8 +243,8 @@ tabovf(tablename) string tablename; {
|
|||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
main(argc,argv) char *argv[]; {
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
while (--argc) {
|
while (--argc) {
|
||||||
++argv;
|
++argv;
|
||||||
if (argv[0][0]=='-') {
|
if (argv[0][0]=='-') {
|
||||||
@ -252,16 +275,18 @@ main(argc,argv) char *argv[]; {
|
|||||||
}
|
}
|
||||||
debug();
|
debug();
|
||||||
exit(nerrors);
|
exit(nerrors);
|
||||||
|
return nerrors;
|
||||||
}
|
}
|
||||||
|
|
||||||
lookup(comm,operator,lnode,rnode) {
|
int lookup(int comm, int operator, int lnode, int rnode)
|
||||||
register node_p p;
|
{
|
||||||
|
node_p p;
|
||||||
|
|
||||||
for (p=nodes+1;p<lastnode;p++) {
|
for (p=nodes+1;p<lastnode;p++) {
|
||||||
if (p->ex_operator != operator)
|
if (p->ex_operator != operator)
|
||||||
continue;
|
continue;
|
||||||
if (!(p->ex_lnode == lnode && p->ex_rnode == rnode ||
|
if (!( ((p->ex_lnode == lnode) && (p->ex_rnode == rnode)) ||
|
||||||
comm && p->ex_lnode == rnode && p->ex_rnode == lnode))
|
((comm && p->ex_lnode == rnode) && (p->ex_rnode == lnode)) ) )
|
||||||
continue;
|
continue;
|
||||||
return(p-nodes);
|
return(p-nodes);
|
||||||
}
|
}
|
||||||
@ -274,8 +299,9 @@ lookup(comm,operator,lnode,rnode) {
|
|||||||
return(p-nodes);
|
return(p-nodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
compueq() {
|
void compueq()
|
||||||
register i,j;
|
{
|
||||||
|
int i,j;
|
||||||
|
|
||||||
for (i=1;i<nmachregs;i++) {
|
for (i=1;i<nmachregs;i++) {
|
||||||
for (j=1;j<i;j++)
|
for (j=1;j<i;j++)
|
||||||
@ -288,9 +314,10 @@ compueq() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
eqregclass(r1,r2) {
|
int eqregclass(int r1, int r2)
|
||||||
register reginfo rp1,rp2;
|
{
|
||||||
register i;
|
reginfo rp1,rp2;
|
||||||
|
int i;
|
||||||
short regbits[(MAXREGS+15)>>4];
|
short regbits[(MAXREGS+15)>>4];
|
||||||
int member;
|
int member;
|
||||||
|
|
||||||
@ -301,7 +328,7 @@ eqregclass(r1,r2) {
|
|||||||
for (i=0;i<((MAXREGS+15)>>4);i++)
|
for (i=0;i<((MAXREGS+15)>>4);i++)
|
||||||
regbits[i] = 0;
|
regbits[i] = 0;
|
||||||
for (i=0;i<maxmembers;i++) {
|
for (i=0;i<maxmembers;i++) {
|
||||||
if (member = rp1->rmembers[i])
|
if ( (member = rp1->rmembers[i]) )
|
||||||
regbits[member>>4] |= (1<<(member&017));
|
regbits[member>>4] |= (1<<(member&017));
|
||||||
}
|
}
|
||||||
for (i=0;i<maxmembers;i++) {
|
for (i=0;i<maxmembers;i++) {
|
||||||
@ -312,25 +339,34 @@ eqregclass(r1,r2) {
|
|||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned hash(name) register string name; {
|
unsigned hash(string name)
|
||||||
register unsigned sum;
|
{
|
||||||
register i;
|
unsigned int sum;
|
||||||
|
int i;
|
||||||
|
|
||||||
for (sum=i=0;*name;i+=3)
|
for (sum=i=0;*name;i+=3)
|
||||||
sum ^= (*name++)<<(i&07);
|
sum ^= (*name++)<<(i&07);
|
||||||
return(sum);
|
return(sum);
|
||||||
}
|
}
|
||||||
|
|
||||||
ident_p ilookup(name,enterf) string name; int enterf; {
|
ident_p ilookup(string name, int enterf)
|
||||||
|
{
|
||||||
register ident_p p,*pp;
|
register ident_p p,*pp;
|
||||||
|
|
||||||
pp = &identtab[hash(name)%ITABSIZE];
|
pp = &identtab[hash(name)%ITABSIZE];
|
||||||
while (*pp != 0) {
|
while (*pp != 0)
|
||||||
|
{
|
||||||
if (strcmp((*pp)->i_name,name)==0)
|
if (strcmp((*pp)->i_name,name)==0)
|
||||||
|
{
|
||||||
if (enterf != ENTER)
|
if (enterf != ENTER)
|
||||||
|
{
|
||||||
return(*pp);
|
return(*pp);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
yyerror("Multiply defined symbol");
|
yyerror("Multiply defined symbol");
|
||||||
|
}
|
||||||
|
}
|
||||||
pp = &(*pp)->i_next;
|
pp = &(*pp)->i_next;
|
||||||
}
|
}
|
||||||
if (enterf == LOOKUP)
|
if (enterf == LOOKUP)
|
||||||
@ -344,8 +380,8 @@ ident_p ilookup(name,enterf) string name; int enterf; {
|
|||||||
return(p);
|
return(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
initio() {
|
void initio()
|
||||||
|
{
|
||||||
if (iname!=0 && freopen(iname,"r",stdin)==NULL) {
|
if (iname!=0 && freopen(iname,"r",stdin)==NULL) {
|
||||||
fprintf(stderr,"Can't open %s\n",iname);
|
fprintf(stderr,"Can't open %s\n",iname);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
@ -367,8 +403,9 @@ initio() {
|
|||||||
patbyte(0);
|
patbyte(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
exprlookup(sett) set_t sett; {
|
int exprlookup(set_t sett)
|
||||||
register i,j,ok;
|
{
|
||||||
|
int i,j,ok;
|
||||||
|
|
||||||
for(i=0;i<nmachsets;i++) {
|
for(i=0;i<nmachsets;i++) {
|
||||||
ok= (sett.set_size == machsets[i].set_size);
|
ok= (sett.set_size == machsets[i].set_size);
|
||||||
@ -386,9 +423,10 @@ exprlookup(sett) set_t sett; {
|
|||||||
return(nmachsets++);
|
return(nmachsets++);
|
||||||
}
|
}
|
||||||
|
|
||||||
inittables() {
|
void inittables()
|
||||||
register reginfo r;
|
{
|
||||||
register i;
|
reginfo r;
|
||||||
|
int i;
|
||||||
inst_t inst;
|
inst_t inst;
|
||||||
set_t sett;
|
set_t sett;
|
||||||
|
|
||||||
@ -421,8 +459,9 @@ inittables() {
|
|||||||
cocosetno=exprlookup(sett);
|
cocosetno=exprlookup(sett);
|
||||||
}
|
}
|
||||||
|
|
||||||
outregs() {
|
void outregs()
|
||||||
register i,j,k;
|
{
|
||||||
|
int i,j,k;
|
||||||
static short rset[(MAXREGS+15)>>4];
|
static short rset[(MAXREGS+15)>>4];
|
||||||
int t,ready;
|
int t,ready;
|
||||||
|
|
||||||
@ -444,29 +483,53 @@ outregs() {
|
|||||||
*/
|
*/
|
||||||
for (j=0;j<((MAXREGS+15)>>4);j++)
|
for (j=0;j<((MAXREGS+15)>>4);j++)
|
||||||
rset[j]=0;
|
rset[j]=0;
|
||||||
|
|
||||||
rset[i>>4] |= (1<<(i&017));
|
rset[i>>4] |= (1<<(i&017));
|
||||||
do {
|
|
||||||
ready=1;
|
do
|
||||||
for (j=1;j<nmachregs;j++)
|
{
|
||||||
if (rset[j>>4]&(1<<(j&017)))
|
ready = 1;
|
||||||
for (k=0;k<maxmembers;k++)
|
for ( j = 1 ; j < nmachregs ; j++ )
|
||||||
if ((t=machregs[j]->rmembers[k])!=0) {
|
{
|
||||||
if ((rset[t>>4]&(1<<(t&017)))==0)
|
if ( rset[j >> 4] & (1 << (j & 017)) )
|
||||||
ready=0;
|
{
|
||||||
rset[t>>4] |= (1<<(t&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);
|
} while (!ready);
|
||||||
do {
|
|
||||||
ready=1;
|
do
|
||||||
for (j=1;j<nmachregs;j++)
|
{
|
||||||
for (k=0;k<maxmembers;k++)
|
ready=1;
|
||||||
if ((t=machregs[j]->rmembers[k])!=0)
|
for ( j = 1 ; j < nmachregs ; j++ )
|
||||||
if (rset[t>>4]&(1<<(t&017))) {
|
{
|
||||||
if (rset[j>>4]&(1<<(j&017))==0)
|
for ( k = 0 ; k < maxmembers ; k++ )
|
||||||
ready=0;
|
{
|
||||||
rset[j>>4] |= (1<<(j&017));
|
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);
|
} while (!ready);
|
||||||
|
|
||||||
fprintf(cfile,"},{");
|
fprintf(cfile,"},{");
|
||||||
for (j=0;j<((nmachregs+15)>>4);j++)
|
for (j=0;j<((nmachregs+15)>>4);j++)
|
||||||
fprintf(cfile,"%d,",rset[j]);
|
fprintf(cfile,"%d,",rset[j]);
|
||||||
@ -479,12 +542,13 @@ outregs() {
|
|||||||
fprintf(cfile,"};\n\n");
|
fprintf(cfile,"};\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
finishio() {
|
void finishio()
|
||||||
register i;
|
{
|
||||||
register node_p np;
|
int i;
|
||||||
|
node_p np;
|
||||||
int j;
|
int j;
|
||||||
int setsize;
|
int setsize;
|
||||||
register move_p mp;
|
move_p mp;
|
||||||
|
|
||||||
fprintf(cfile,"};\n\n");
|
fprintf(cfile,"};\n\n");
|
||||||
if (wsize>0)
|
if (wsize>0)
|
||||||
@ -637,8 +701,9 @@ finishio() {
|
|||||||
outregvar();
|
outregvar();
|
||||||
}
|
}
|
||||||
|
|
||||||
outregvar() {
|
void outregvar()
|
||||||
register i,j;
|
{
|
||||||
|
int i,j;
|
||||||
|
|
||||||
fprintf(hfile,"#define REGVARS\n");
|
fprintf(hfile,"#define REGVARS\n");
|
||||||
fprintf(cfile,"#include \"regvar.h\"\n");
|
fprintf(cfile,"#include \"regvar.h\"\n");
|
||||||
@ -670,8 +735,8 @@ outregvar() {
|
|||||||
fprintf(cfile,"};\n");
|
fprintf(cfile,"};\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
verbose() {
|
void verbose()
|
||||||
|
{
|
||||||
fprintf(stderr,"Codebytes %d\n",codebytes);
|
fprintf(stderr,"Codebytes %d\n",codebytes);
|
||||||
fprintf(stderr,"Registers %d(%d)\n",nmachregs,MAXREGS);
|
fprintf(stderr,"Registers %d(%d)\n",nmachregs,MAXREGS);
|
||||||
fprintf(stderr,"Properties %d(%d)\n",nprops,MAXPROPS);
|
fprintf(stderr,"Properties %d(%d)\n",nprops,MAXPROPS);
|
||||||
@ -683,10 +748,11 @@ verbose() {
|
|||||||
fprintf(stderr,"Patbytes %d(%d)\n",npatbytes,MAXPATTERN);
|
fprintf(stderr,"Patbytes %d(%d)\n",npatbytes,MAXPATTERN);
|
||||||
}
|
}
|
||||||
|
|
||||||
inbetween() {
|
void inbetween()
|
||||||
register ident_p ip;
|
{
|
||||||
register i,j;
|
ident_p ip;
|
||||||
register move_p mp;
|
int i,j;
|
||||||
|
move_p mp;
|
||||||
|
|
||||||
lookident=1; /* for lexical analysis */
|
lookident=1; /* for lexical analysis */
|
||||||
|
|
||||||
@ -728,11 +794,12 @@ inbetween() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
formconversion(p,tp) register char *p; register token_p tp; {
|
int formconversion(char *p, token_p tp)
|
||||||
|
{
|
||||||
char buf[256];
|
char buf[256];
|
||||||
register char *q=buf;
|
char *q=buf;
|
||||||
char field[256];
|
char field[256];
|
||||||
register char *f;
|
char *f;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (p==0)
|
if (p==0)
|
||||||
@ -768,10 +835,11 @@ formconversion(p,tp) register char *p; register token_p tp; {
|
|||||||
return(strlookup(buf));
|
return(strlookup(buf));
|
||||||
}
|
}
|
||||||
|
|
||||||
setfields(tp,format) register token_p tp; string format; {
|
void setfields(token_p tp, string format)
|
||||||
register i;
|
{
|
||||||
|
int i;
|
||||||
list2 ll;
|
list2 ll;
|
||||||
register list1 l;
|
list1 l;
|
||||||
int type;
|
int type;
|
||||||
|
|
||||||
for(i=0;i<TOKENSIZE-1;i++)
|
for(i=0;i<TOKENSIZE-1;i++)
|
||||||
@ -796,18 +864,20 @@ setfields(tp,format) register token_p tp; string format; {
|
|||||||
tp->t_format = -1;
|
tp->t_format = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
chkregexp(number) {
|
void chkregexp(int number)
|
||||||
register i;
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
for(i=nmachregs+1;i<nmachregs+1+nmachtokens;i++)
|
for(i=nmachregs+1;i<nmachregs+1+nmachtokens;i++)
|
||||||
if(machsets[number].set_val[i>>4]&(01<<(i&017)))
|
if(machsets[number].set_val[i>>4]&(01<<(i&017)))
|
||||||
yyerror("No tokens allowed in this set");
|
yyerror("No tokens allowed in this set");
|
||||||
}
|
}
|
||||||
|
|
||||||
findstructel(number,name,t) string name; int *t; {
|
int findstructel(int number, string name, int *t)
|
||||||
register i;
|
{
|
||||||
register token_p tp;
|
int i;
|
||||||
register list2 structdecl;
|
token_p tp;
|
||||||
|
list2 structdecl;
|
||||||
int offset;
|
int offset;
|
||||||
|
|
||||||
for(i=1;i<=nmachregs;i++)
|
for(i=1;i<=nmachregs;i++)
|
||||||
@ -839,8 +909,8 @@ findstructel(number,name,t) string name; int *t; {
|
|||||||
|
|
||||||
extern char em_flag[];
|
extern char em_flag[];
|
||||||
|
|
||||||
argtyp(mn) {
|
int argtyp(int mn)
|
||||||
|
{
|
||||||
switch(em_flag[mn-sp_fmnem]&EM_PAR) {
|
switch(em_flag[mn-sp_fmnem]&EM_PAR) {
|
||||||
case PAR_W:
|
case PAR_W:
|
||||||
case PAR_S:
|
case PAR_S:
|
||||||
@ -857,8 +927,8 @@ argtyp(mn) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
commontype(e1,e2) expr_t e1,e2; {
|
int commontype(expr_t e1, expr_t e2)
|
||||||
|
{
|
||||||
if(e1.expr_typ != e2.expr_typ)
|
if(e1.expr_typ != e2.expr_typ)
|
||||||
yyerror("Type incompatibility");
|
yyerror("Type incompatibility");
|
||||||
return(e1.expr_typ);
|
return(e1.expr_typ);
|
||||||
@ -873,15 +943,17 @@ struct hashmnem {
|
|||||||
byte h_value;
|
byte h_value;
|
||||||
} hashmnem[HASHSIZE];
|
} hashmnem[HASHSIZE];
|
||||||
|
|
||||||
inithash() {
|
void inithash()
|
||||||
register i;
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
for(i=0;i<=sp_lmnem-sp_fmnem;i++)
|
for(i=0;i<=sp_lmnem-sp_fmnem;i++)
|
||||||
enter(em_mnem[i],i+sp_fmnem);
|
enter(em_mnem[i],i+sp_fmnem);
|
||||||
}
|
}
|
||||||
|
|
||||||
enter(name,value) char *name; {
|
void enter(char *name, int value)
|
||||||
register unsigned h;
|
{
|
||||||
|
unsigned int h;
|
||||||
|
|
||||||
h=hash(name)%HASHSIZE;
|
h=hash(name)%HASHSIZE;
|
||||||
while (hashmnem[h].h_name[0] != 0)
|
while (hashmnem[h].h_name[0] != 0)
|
||||||
@ -890,8 +962,9 @@ enter(name,value) char *name; {
|
|||||||
hashmnem[h].h_value = value;
|
hashmnem[h].h_value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
int mlookup(name) char *name; {
|
int mlookup(char *name)
|
||||||
register unsigned h;
|
{
|
||||||
|
unsigned int h;
|
||||||
|
|
||||||
h = hash(name)%HASHSIZE;
|
h = hash(name)%HASHSIZE;
|
||||||
while (strncmp(hashmnem[h].h_name,name,3) != 0 &&
|
while (strncmp(hashmnem[h].h_name,name,3) != 0 &&
|
||||||
@ -900,10 +973,11 @@ int mlookup(name) char *name; {
|
|||||||
return(hashmnem[h].h_value&BMASK); /* 0 if not found */
|
return(hashmnem[h].h_value&BMASK); /* 0 if not found */
|
||||||
}
|
}
|
||||||
|
|
||||||
hashpatterns() {
|
void hashpatterns()
|
||||||
|
{
|
||||||
short index;
|
short index;
|
||||||
register byte *bp,*tp;
|
byte *bp,*tp;
|
||||||
register short i;
|
short i;
|
||||||
unsigned short hashvalue;
|
unsigned short hashvalue;
|
||||||
int patlen;
|
int patlen;
|
||||||
|
|
||||||
@ -937,18 +1011,19 @@ hashpatterns() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
debug() {
|
void debug()
|
||||||
register i,j;
|
{
|
||||||
|
int i,j;
|
||||||
|
|
||||||
for(i=0;i<ITABSIZE;i++) {
|
for(i=0;i<ITABSIZE;i++) {
|
||||||
register ident_p ip;
|
ident_p ip;
|
||||||
for(ip=identtab[i];ip!=0;ip=ip->i_next)
|
for(ip=identtab[i];ip!=0;ip=ip->i_next)
|
||||||
printf("%-14s %1d %3d\n",ip->i_name,
|
printf("%-14s %1d %3d\n",ip->i_name,
|
||||||
ip->i_type,ip->i_i.i_regno);
|
ip->i_type,ip->i_i.i_regno);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i=2;i<nmachregs;i++) {
|
for(i=2;i<nmachregs;i++) {
|
||||||
register reginfo rp;
|
reginfo rp;
|
||||||
|
|
||||||
rp=machregs[i];
|
rp=machregs[i];
|
||||||
printf("%s = (\"%s\", %d",rp->rname,rp->rrepr,rp->rsize);
|
printf("%s = (\"%s\", %d",rp->rname,rp->rrepr,rp->rsize);
|
||||||
@ -963,8 +1038,8 @@ debug() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
out(n) {
|
void out(int n)
|
||||||
|
{
|
||||||
assert(n>=0);
|
assert(n>=0);
|
||||||
if (n<128)
|
if (n<128)
|
||||||
outbyte(n);
|
outbyte(n);
|
||||||
@ -974,14 +1049,14 @@ out(n) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
outbyte(n) {
|
void outbyte(int n)
|
||||||
|
{
|
||||||
fprintf(cfile,"%d, ",n&BMASK);
|
fprintf(cfile,"%d, ",n&BMASK);
|
||||||
codebytes++;
|
codebytes++;
|
||||||
}
|
}
|
||||||
|
|
||||||
pat(n) {
|
void pat(int n)
|
||||||
|
{
|
||||||
assert(n>=0);
|
assert(n>=0);
|
||||||
if (n<128)
|
if (n<128)
|
||||||
patbyte(n);
|
patbyte(n);
|
||||||
@ -991,20 +1066,20 @@ pat(n) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
patshort(n) {
|
void patshort(int n)
|
||||||
|
{
|
||||||
patbyte(n&BMASK);
|
patbyte(n&BMASK);
|
||||||
patbyte(n>>BSHIFT);
|
patbyte(n>>BSHIFT);
|
||||||
}
|
}
|
||||||
|
|
||||||
patbyte(n) {
|
void patbyte(int n)
|
||||||
|
{
|
||||||
chktabsiz(npatbytes,MAXPATTERN,"Pattern table");
|
chktabsiz(npatbytes,MAXPATTERN,"Pattern table");
|
||||||
pattern[npatbytes++] = n;
|
pattern[npatbytes++] = n;
|
||||||
}
|
}
|
||||||
|
|
||||||
max(a,b) {
|
int max(int a, int b)
|
||||||
|
{
|
||||||
if (a>b)
|
if (a>b)
|
||||||
return(a);
|
return(a);
|
||||||
return(b);
|
return(b);
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
/* PREPROCESSOR: INITIALIZATION ROUTINES */
|
/* PREPROCESSOR: INITIALIZATION ROUTINES */
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
#include <system.h>
|
#include <system.h>
|
||||||
#include <alloc.h>
|
#include <alloc.h>
|
||||||
#include "class.h"
|
#include "class.h"
|
||||||
@ -12,7 +13,7 @@
|
|||||||
#include "idf.h"
|
#include "idf.h"
|
||||||
#include "interface.h"
|
#include "interface.h"
|
||||||
|
|
||||||
PRIVATE struct mkey {
|
static struct mkey {
|
||||||
char *mk_reserved;
|
char *mk_reserved;
|
||||||
int mk_key;
|
int mk_key;
|
||||||
} mkey[] = {
|
} mkey[] = {
|
||||||
@ -30,10 +31,7 @@ PRIVATE struct mkey {
|
|||||||
{0, K_UNKNOWN}
|
{0, K_UNKNOWN}
|
||||||
};
|
};
|
||||||
|
|
||||||
char *strcpy();
|
void init_pp()
|
||||||
|
|
||||||
EXPORT
|
|
||||||
init_pp()
|
|
||||||
{
|
{
|
||||||
long clock, sys_time();
|
long clock, sys_time();
|
||||||
static char date[30];
|
static char date[30];
|
||||||
|
|||||||
@ -15,10 +15,9 @@ struct file_info finfo;
|
|||||||
#include <inp_pkg.body>
|
#include <inp_pkg.body>
|
||||||
#include <alloc.h>
|
#include <alloc.h>
|
||||||
|
|
||||||
char * getwdir(char *fn)
|
char *getwdir(char *fn)
|
||||||
{
|
{
|
||||||
register char *p;
|
char *p;
|
||||||
char *strrchr();
|
|
||||||
|
|
||||||
p = strrchr(fn, '/');
|
p = strrchr(fn, '/');
|
||||||
while (p && *(p + 1) == '\0') { /* remove trailing /'s */
|
while (p && *(p + 1) == '\0') { /* remove trailing /'s */
|
||||||
@ -42,7 +41,7 @@ int NoUnstack;
|
|||||||
int Unstacked;
|
int Unstacked;
|
||||||
int InputLevel;
|
int InputLevel;
|
||||||
|
|
||||||
AtEoIT()
|
int AtEoIT()
|
||||||
{
|
{
|
||||||
/* if (NoUnstack) warning("unexpected EOF"); ??? */
|
/* if (NoUnstack) warning("unexpected EOF"); ??? */
|
||||||
/* This is wrong; in an #elif, NoUnstack can be set, but you
|
/* This is wrong; in an #elif, NoUnstack can be set, but you
|
||||||
@ -53,7 +52,7 @@ AtEoIT()
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
AtEoIF()
|
int AtEoIF()
|
||||||
{
|
{
|
||||||
extern int nestlevel;
|
extern int nestlevel;
|
||||||
extern int nestcount;
|
extern int nestcount;
|
||||||
|
|||||||
@ -3,6 +3,6 @@
|
|||||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
*/
|
*/
|
||||||
#define PRIVATE
|
#define PRIVATE
|
||||||
#define IMPORT extern
|
#define IMPORT extern
|
||||||
#define EXPORT
|
#define EXPORT
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
/* MAIN PROGRAM */
|
/* MAIN PROGRAM */
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#include <alloc.h>
|
#include <alloc.h>
|
||||||
#include <em_arith.h>
|
#include <em_arith.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@ -26,13 +27,16 @@ static File *dep_fd = STDOUT;
|
|||||||
|
|
||||||
arith ifval;
|
arith ifval;
|
||||||
|
|
||||||
|
void compile(int argc, char *argv[]);
|
||||||
|
void list_dependencies(char *source);
|
||||||
|
void dependency(char *s, char *source);
|
||||||
|
|
||||||
char *prog_name;
|
char *prog_name;
|
||||||
|
|
||||||
extern char **inctable;
|
extern char **inctable;
|
||||||
extern int inc_max, inc_total;
|
extern int inc_max, inc_total;
|
||||||
|
|
||||||
main(argc, argv)
|
int main(int argc, char *argv[])
|
||||||
char *argv[];
|
|
||||||
{
|
{
|
||||||
/* parse and interpret the command line options */
|
/* parse and interpret the command line options */
|
||||||
prog_name = argv[0];
|
prog_name = argv[0];
|
||||||
@ -61,10 +65,10 @@ main(argc, argv)
|
|||||||
}
|
}
|
||||||
compile(argc - 1, &argv[1]);
|
compile(argc - 1, &argv[1]);
|
||||||
exit(err_occurred);
|
exit(err_occurred);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
compile(argc, argv)
|
void compile(int argc, char *argv[])
|
||||||
char *argv[];
|
|
||||||
{
|
{
|
||||||
register char *source = 0;
|
register char *source = 0;
|
||||||
char *dummy;
|
char *dummy;
|
||||||
@ -93,10 +97,8 @@ compile(argc, argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct idf *file_head;
|
struct idf *file_head;
|
||||||
extern char *strrchr();
|
|
||||||
|
|
||||||
list_dependencies(source)
|
void list_dependencies(char *source)
|
||||||
char *source;
|
|
||||||
{
|
{
|
||||||
register struct idf *p = file_head;
|
register struct idf *p = file_head;
|
||||||
|
|
||||||
@ -111,7 +113,7 @@ list_dependencies(source)
|
|||||||
* object generated, so don't include the pathname
|
* object generated, so don't include the pathname
|
||||||
* leading to it.
|
* leading to it.
|
||||||
*/
|
*/
|
||||||
if (s = strrchr(source, '/')) {
|
if ( (s = strrchr(source, '/')) ) {
|
||||||
source = s + 1;
|
source = s + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -127,8 +129,7 @@ list_dependencies(source)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
add_dependency(s)
|
void add_dependency(char *s)
|
||||||
char *s;
|
|
||||||
{
|
{
|
||||||
register struct idf *p = str2idf(s, 0);
|
register struct idf *p = str2idf(s, 0);
|
||||||
|
|
||||||
@ -139,8 +140,7 @@ add_dependency(s)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependency(s, source)
|
void dependency(char *s, char *source)
|
||||||
char *s, *source;
|
|
||||||
{
|
{
|
||||||
if (options['i'] && !strncmp(s, "/usr/include/", 13)) {
|
if (options['i'] && !strncmp(s, "/usr/include/", 13)) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -23,10 +23,9 @@ char **inctable;
|
|||||||
char *dep_file = 0;
|
char *dep_file = 0;
|
||||||
|
|
||||||
extern int idfsize;
|
extern int idfsize;
|
||||||
int txt2int();
|
int txt2int(char **tp);
|
||||||
|
|
||||||
do_option(text)
|
void do_option(char *text)
|
||||||
char *text;
|
|
||||||
{
|
{
|
||||||
switch(*text++) {
|
switch(*text++) {
|
||||||
case '-':
|
case '-':
|
||||||
@ -130,9 +129,7 @@ do_option(text)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int txt2int(char **tp)
|
||||||
txt2int(tp)
|
|
||||||
char **tp;
|
|
||||||
{
|
{
|
||||||
/* the integer pointed to by *tp is read, while increasing
|
/* the integer pointed to by *tp is read, while increasing
|
||||||
*tp; the resulting value is yielded.
|
*tp; the resulting value is yielded.
|
||||||
|
|||||||
@ -22,12 +22,12 @@ char bits[128];
|
|||||||
char _obuf[OBUFSIZE];
|
char _obuf[OBUFSIZE];
|
||||||
extern int do_preprocess;
|
extern int do_preprocess;
|
||||||
|
|
||||||
Xflush()
|
void Xflush()
|
||||||
{
|
{
|
||||||
if (do_preprocess) sys_write(STDOUT, _obuf, OBUFSIZE);
|
if (do_preprocess) sys_write(STDOUT, _obuf, OBUFSIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
preprocess(fn)
|
void preprocess(fn)
|
||||||
char *fn;
|
char *fn;
|
||||||
{
|
{
|
||||||
register int c;
|
register int c;
|
||||||
|
|||||||
@ -20,15 +20,18 @@
|
|||||||
#include "class.h"
|
#include "class.h"
|
||||||
#include "interface.h"
|
#include "interface.h"
|
||||||
|
|
||||||
char *strcpy(), *strcat();
|
|
||||||
char *long2str();
|
|
||||||
extern int InputLevel;
|
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)
|
char *GetIdentifier(); /* domacro.c */
|
||||||
register struct idf *idef;
|
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
|
/* replace() is called by the lexical analyzer to perform
|
||||||
macro replacement. "idef" is the description of the
|
macro replacement. "idef" is the description of the
|
||||||
@ -41,8 +44,8 @@ replace(idef)
|
|||||||
*/
|
*/
|
||||||
register struct macro *mac = idef->id_macro;
|
register struct macro *mac = idef->id_macro;
|
||||||
register char c;
|
register char c;
|
||||||
char **actpars, **getactuals();
|
char **actpars;
|
||||||
char *reptext, *macro2buffer();
|
char *reptext;
|
||||||
register struct mlist *repl;
|
register struct mlist *repl;
|
||||||
int size;
|
int size;
|
||||||
|
|
||||||
@ -79,7 +82,6 @@ replace(idef)
|
|||||||
if (mac->mc_flag & FUNC) {
|
if (mac->mc_flag & FUNC) {
|
||||||
struct idf *param;
|
struct idf *param;
|
||||||
char *nam;
|
char *nam;
|
||||||
extern char *GetIdentifier();
|
|
||||||
|
|
||||||
UnknownIdIsZero = 0;
|
UnknownIdIsZero = 0;
|
||||||
nam = GetIdentifier();
|
nam = GetIdentifier();
|
||||||
@ -137,9 +139,7 @@ replace(idef)
|
|||||||
|
|
||||||
char FilNamBuf[PATHLENGTH];
|
char FilNamBuf[PATHLENGTH];
|
||||||
|
|
||||||
PRIVATE
|
static void macro_func(struct idf *idef)
|
||||||
macro_func(idef)
|
|
||||||
register struct idf *idef;
|
|
||||||
{
|
{
|
||||||
/* macro_func() performs the special actions needed with some
|
/* macro_func() performs the special actions needed with some
|
||||||
macros. These macros are __FILE__ and __LINE__ which
|
macros. These macros are __FILE__ and __LINE__ which
|
||||||
@ -167,11 +167,7 @@ macro_func(idef)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PRIVATE char *
|
static char *macro2buffer(struct idf *idef, char **actpars, int *siztext)
|
||||||
macro2buffer(idef, actpars, siztext)
|
|
||||||
struct idf *idef;
|
|
||||||
char **actpars;
|
|
||||||
int *siztext;
|
|
||||||
{
|
{
|
||||||
/* Macro2buffer() turns the macro replacement text, as it is
|
/* Macro2buffer() turns the macro replacement text, as it is
|
||||||
stored, into an input buffer, while each occurrence of the
|
stored, into an input buffer, while each occurrence of the
|
||||||
@ -214,14 +210,12 @@ macro2buffer(idef, actpars, siztext)
|
|||||||
return Realloc(text, pos+1);
|
return Realloc(text, pos+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
EXPORT
|
void DoUnstack()
|
||||||
DoUnstack()
|
|
||||||
{
|
{
|
||||||
Unstacked = 1;
|
Unstacked = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
EXPORT
|
void EnableMacros()
|
||||||
EnableMacros()
|
|
||||||
{
|
{
|
||||||
register struct mlist *p = ReplList, *prev = 0;
|
register struct mlist *p = ReplList, *prev = 0;
|
||||||
|
|
||||||
|
|||||||
@ -23,17 +23,17 @@
|
|||||||
#define EOS '\0'
|
#define EOS '\0'
|
||||||
#define overflow() (fatal("actual parameter buffer overflow"))
|
#define overflow() (fatal("actual parameter buffer overflow"))
|
||||||
|
|
||||||
PRIVATE char apbuf[LAPBUF]; /* temporary storage for actual parameters */
|
static char apbuf[LAPBUF]; /* temporary storage for actual parameters */
|
||||||
PRIVATE char *actparams[NPARAMS]; /* pointers to the text of the actuals */
|
static char *actparams[NPARAMS]; /* pointers to the text of the actuals */
|
||||||
PRIVATE char *aptr; /* pointer to last inserted character in apbuf */
|
static char *aptr; /* pointer to last inserted character in apbuf */
|
||||||
|
|
||||||
#define copy(ch) ((aptr < &apbuf[LAPBUF]) ? (*aptr++ = ch) : overflow())
|
#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 **
|
static void copyact(char ch1, char ch2, int level);
|
||||||
getactuals(idef)
|
|
||||||
struct idf *idef;
|
char **getactuals(struct idf *idef)
|
||||||
{
|
{
|
||||||
/* getactuals() collects the actual parameters and turns them
|
/* getactuals() collects the actual parameters and turns them
|
||||||
into a list of strings, a pointer to which is returned.
|
into a list of strings, a pointer to which is returned.
|
||||||
@ -76,10 +76,7 @@ getactuals(idef)
|
|||||||
return actparams;
|
return actparams;
|
||||||
}
|
}
|
||||||
|
|
||||||
PRIVATE
|
static void copyact(char ch1, char ch2, int level)
|
||||||
copyact(ch1, ch2, level)
|
|
||||||
char ch1, ch2;
|
|
||||||
int level;
|
|
||||||
{
|
{
|
||||||
/* copyact() is taken from Ceriel Jacobs' LLgen, with
|
/* copyact() is taken from Ceriel Jacobs' LLgen, with
|
||||||
permission. Its task is to build a list of actuals
|
permission. Its task is to build a list of actuals
|
||||||
|
|||||||
@ -9,9 +9,7 @@
|
|||||||
#include "class.h"
|
#include "class.h"
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
|
|
||||||
int
|
int skipspaces(int ch, int skipnl)
|
||||||
skipspaces(ch, skipnl)
|
|
||||||
register int ch;
|
|
||||||
{
|
{
|
||||||
/* skipspaces() skips any white space and returns the first
|
/* skipspaces() skips any white space and returns the first
|
||||||
non-space character.
|
non-space character.
|
||||||
@ -52,18 +50,18 @@ skipspaces(ch, skipnl)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
skipline()
|
void skipline()
|
||||||
{
|
{
|
||||||
/* skipline() skips all characters until a newline character
|
/* skipline() skips all characters until a newline character
|
||||||
is seen, not escaped by a '\\'.
|
is seen, not escaped by a '\\'.
|
||||||
Any comment is skipped.
|
Any comment is skipped.
|
||||||
*/
|
*/
|
||||||
register int c;
|
int c;
|
||||||
|
|
||||||
LoadChar(c);
|
LoadChar(c);
|
||||||
while (class(c) != STNL && c != EOI) {
|
while (class(c) != STNL && c != EOI) {
|
||||||
if (class(c) == STSTR || class(c) == STCHAR) {
|
if (class(c) == STSTR || class(c) == STCHAR) {
|
||||||
register int stopc = c;
|
int stopc = c;
|
||||||
int escaped;
|
int escaped;
|
||||||
do {
|
do {
|
||||||
escaped = 0;
|
escaped = 0;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user