From 03763cbbf0f0653a872c1e66fe7b17281c967936 Mon Sep 17 00:00:00 2001 From: Manoel Trapier Date: Thu, 14 Mar 2013 16:10:42 +0100 Subject: [PATCH] Starting ANSI C frontend --- lang/cem/cemcom.ansi/BigPars | 16 +++--- lang/cem/cemcom.ansi/LLlex.c | 91 +++++++++++++------------------ lang/cem/cemcom.ansi/LLmessage.c | 5 +- lang/cem/cemcom.ansi/SmallPars | 24 ++++---- lang/cem/cemcom.ansi/ch3mon.c | 2 +- lang/cem/cemcom.ansi/make.tokcase | 4 +- 6 files changed, 63 insertions(+), 79 deletions(-) diff --git a/lang/cem/cemcom.ansi/BigPars b/lang/cem/cemcom.ansi/BigPars index fa9f30c9f..74a3f7914 100644 --- a/lang/cem/cemcom.ansi/BigPars +++ b/lang/cem/cemcom.ansi/BigPars @@ -1,5 +1,5 @@ !File: lint.h -/*#define LINT 1 /* if defined, 'lint' is produced */ +/*#define LINT 1*/ /* if defined, 'lint' is produced */ !File: pathlength.h @@ -75,7 +75,7 @@ !File: botch_free.h -/*#define BOTCH_FREE 1 /* when defined, botch freed memory, as a check */ +/*#define BOTCH_FREE 1*/ /* when defined, botch freed memory, as a check */ !File: dataflow.h @@ -83,7 +83,7 @@ !File: debug.h -/*#define DEBUG 1 /* perform various self-tests */ +/*#define DEBUG 1*/ /* perform various self-tests */ #define NDEBUG 1 /* disable assertions */ @@ -112,17 +112,17 @@ !File: nopp.h -/*#define NOPP 1 /* if NOT defined, use built-int preprocessor */ +/*#define NOPP 1*/ /* if NOT defined, use built-int preprocessor */ !File: nobitfield.h -/*#define NOBITFIELD 1 /* if NOT defined, implement bitfields */ +/*#define NOBITFIELD 1*/ /* if NOT defined, implement bitfields */ !File: spec_arith.h /* describes internal compiler arithmetics */ #undef SPECIAL_ARITHMETICS /* something different from native long */ -/*#define UNSIGNED_ARITH unsigned arith /* if it is supported */ +/*#define UNSIGNED_ARITH unsigned arith*/ /* if it is supported */ !File: static.h @@ -130,11 +130,11 @@ !File: nocross.h -/*#define NOCROSS 1 /* if NOT defined, cross compiler */ +/*#define NOCROSS 1*/ /* if NOT defined, cross compiler */ !File: regcount.h -/*#define REGCOUNT 1 /* count occurrences for register messages */ +/*#define REGCOUNT 1*/ /* count occurrences for register messages */ !File: dbsymtab.h diff --git a/lang/cem/cemcom.ansi/LLlex.c b/lang/cem/cemcom.ansi/LLlex.c index 9736b4420..ac8b83c02 100644 --- a/lang/cem/cemcom.ansi/LLlex.c +++ b/lang/cem/cemcom.ansi/LLlex.c @@ -62,7 +62,7 @@ static LexSP = 0; E.g. at the invocation of a sub-parser that uses LLlex(), the state of the current parser should be saved. */ -PushLex() +void PushLex() { ASSERT(LexSP < MAX_LL_DEPTH); ASSERT(ASIDE == 0); /* ASIDE = 0; */ @@ -70,15 +70,14 @@ PushLex() LexStack[LexSP++] = dot; } -PopLex() +void PopLex() { ASSERT(LexSP > 0); dot = LexStack[--LexSP]; } #endif /* NOPP */ -int -LLlex() +int LLlex() { /* LLlex() plays the role of Lexical Analyzer for the C parser. The look-ahead and putting aside of tokens are taken into @@ -108,12 +107,13 @@ LLlex() } -char *string_token(); -arith char_constant(); +char *string_token(char *nm, int stop_char, int *plen); +arith char_constant(char *nm); +void skipcomment(); +void strint2tok(char intbuf[], struct token *ptok); +void strflt2tok(char fltbuf[], struct token *ptok); -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}*#" @@ -121,7 +121,7 @@ GetToken(ptok) needed. */ char buf[(IDFSIZE > NUMSIZE ? IDFSIZE : NUMSIZE) + 1]; - register int ch, nch; + int ch, nch; token_nmb++; @@ -227,8 +227,7 @@ garbage: case '<': if (AccFileSpecifier) { UnGetChar(); /* pushback nch */ - ptok->tk_bts = string_token("file specifier", - '>', &(ptok->tk_len)); + ptok->tk_bts = string_token("file specifier", '>', &(ptok->tk_len)); return ptok->tk_symb = FILESPECIFIER; } if (nch == '<') { @@ -312,10 +311,10 @@ garbage: /* fallthrough */ case STIDF: { - register char *tg = &buf[0]; - register int pos = -1; - register struct idf *idef; - extern int idfsize; /* ??? */ + char *tg = &buf[0]; + int pos = -1; + struct idf *idef; + int idfsize; /* ??? */ #ifndef NOPP int NoExpandNext = 0; @@ -361,8 +360,8 @@ garbage: } case STNUM: /* a numeric constant */ { - register int siz_left = NUMSIZE - 1; - register char *np = &buf[0]; + int siz_left = NUMSIZE - 1; + char *np = &buf[0]; int flags = 0; #define store(ch) if (--siz_left >= 0) \ @@ -444,10 +443,11 @@ garbage: crash("bad class for char 0%o", ch); } /*NOTREACHED*/ + return 0; } #ifndef NOPP -skipcomment() +void skipcomment() { /* The last character read has been the '*' of '/_*'. The characters, except NL and EOI, between '/_*' and the first @@ -459,7 +459,7 @@ skipcomment() EOI is returned by LoadChar only on encountering EOF of the top-level file... */ - register int c, oldc = '\0'; + int c, oldc = '\0'; NoUnstack++; c = GetChar(); @@ -501,12 +501,10 @@ skipcomment() } #endif /* NOPP */ -arith -char_constant(nm) - char *nm; +arith char_constant(char *nm) { - register arith val = 0; - register int ch; + arith val = 0; + int ch; int size = 0; ch = GetChar(); @@ -534,15 +532,12 @@ char_constant(nm) return val; } -char * -string_token(nm, stop_char, plen) - char *nm; - int *plen; +char *string_token(char *nm, int stop_char, int *plen) { - register int ch; - register int str_size; - register char *str = Malloc((unsigned) (str_size = ISTRSIZE)); - register int pos = 0; + int ch; + int str_size; + char *str = Malloc((unsigned) (str_size = ISTRSIZE)); + int pos = 0; ch = GetChar(); while (ch != stop_char) { @@ -567,9 +562,7 @@ string_token(nm, stop_char, plen) return str; } -int -quoted(ch) - register int ch; +int quoted(int ch) { /* quoted() replaces an escaped character sequence by the character meant. @@ -628,9 +621,7 @@ quoted(ch) } -int -hex_val(ch) - register int ch; +int hex_val(int ch) { return is_dig(ch) ? ch - '0' : is_hex(ch) ? (ch - 'a' + 10) & 017 @@ -638,13 +629,12 @@ hex_val(ch) } -int -GetChar() +int GetChar() { /* The routines GetChar and trigraph parses the trigraph sequences and removes occurences of \\\n. */ - register int ch; + int ch; #ifndef NOPP again: @@ -671,10 +661,9 @@ again: } #ifndef NOPP -int -trigraph() +int trigraph() { - register int ch; + int ch; LoadChar(ch); if (ch == '?') { @@ -718,11 +707,9 @@ trigraph() /* strflt2tok only checks the syntax of the floating-point number and * selects the right type for the number. */ -strflt2tok(fltbuf, ptok) -char fltbuf[]; -struct token *ptok; +void strflt2tok(char fltbuf[], struct token *ptok) { - register char *cp = fltbuf; + char *cp = fltbuf; int malformed = 0; while (is_dig(*cp)) cp++; @@ -757,11 +744,9 @@ struct token *ptok; } } -strint2tok(intbuf, ptok) -char intbuf[]; -struct token *ptok; +void strint2tok(char intbuf[], struct token *ptok) { - register char *cp = intbuf; + char *cp = intbuf; int base = 10; arith val = 0, dig, ubound; int uns_flg = 0, lng_flg = 0, malformed = 0, ovfl = 0; diff --git a/lang/cem/cemcom.ansi/LLmessage.c b/lang/cem/cemcom.ansi/LLmessage.c index c88c5eb24..80425757c 100644 --- a/lang/cem/cemcom.ansi/LLmessage.c +++ b/lang/cem/cemcom.ansi/LLmessage.c @@ -11,9 +11,10 @@ #include "LLlex.h" #include "Lpars.h" -extern char *symbol2str(); +char *symbol2str(int tok); -LLmessage(tk) { +void LLmessage(tk) +{ err_occurred = 1; if (tk < 0) { error("end of file expected"); diff --git a/lang/cem/cemcom.ansi/SmallPars b/lang/cem/cemcom.ansi/SmallPars index 237fd4dd0..6c9093766 100644 --- a/lang/cem/cemcom.ansi/SmallPars +++ b/lang/cem/cemcom.ansi/SmallPars @@ -1,5 +1,5 @@ !File: lint.h -/*#define LINT 1 /* if defined, 'lint' is produced */ +/*#define LINT 1*/ /* if defined, 'lint' is produced */ !File: pathlength.h @@ -75,24 +75,24 @@ !File: botch_free.h -/*#define BOTCH_FREE 1 /* when defined, botch freed memory, as a check */ +/*#define BOTCH_FREE 1*/ /* when defined, botch freed memory, as a check */ !File: dataflow.h -/*#define DATAFLOW 1 /* produce some compile-time xref */ +/*#define DATAFLOW 1*/ /* produce some compile-time xref */ !File: debug.h -/*#define DEBUG 1 /* perform various self-tests */ +/*#define DEBUG 1*/ /* perform various self-tests */ #define NDEBUG 1 /* disable assertions */ !File: use_tmp.h -/*#define PREPEND_SCOPES 1 /* collect exa, exp, ina and inp commands +/*#define PREPEND_SCOPES 1*/ /* collect exa, exp, ina and inp commands and if USE_TMP is defined let them precede the rest of the generated compact code */ -/*#define USE_TMP 1 /* use C_insertpart, C_endpart mechanism +/*#define USE_TMP 1*/ /* use C_insertpart, C_endpart mechanism to generate EM-code in the order needed for the code-generators. If not defined, the old-style peephole optimizer is @@ -108,7 +108,7 @@ !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 */ !File: nopp.h @@ -116,13 +116,13 @@ !File: nobitfield.h -/*#define NOBITFIELD 1 /* if NOT defined, implement bitfields */ +/*#define NOBITFIELD 1*/ /* if NOT defined, implement bitfields */ !File: spec_arith.h /* describes internal compiler arithmetics */ #undef SPECIAL_ARITHMETICS /* something different from native long */ -/*#define UNSIGNED_ARITH unsigned arith /* if it is supported */ +/*#define UNSIGNED_ARITH unsigned arith*/ /* if it is supported */ !File: static.h @@ -130,14 +130,14 @@ !File: nocross.h -/*#define NOCROSS 1 /* if NOT defined, cross compiler */ +/*#define NOCROSS 1*/ /* if NOT defined, cross compiler */ !File: regcount.h -/*#define REGCOUNT 1 /* count occurrences for register messages */ +/*#define REGCOUNT 1*/ /* count occurrences for register messages */ !File: dbsymtab.h -/*#define DBSYMTAB 1 /* ability to produce symbol table for debugger */ +/*#define DBSYMTAB 1*/ /* ability to produce symbol table for debugger */ diff --git a/lang/cem/cemcom.ansi/ch3mon.c b/lang/cem/cemcom.ansi/ch3mon.c index 40cc44025..64b6c3602 100644 --- a/lang/cem/cemcom.ansi/ch3mon.c +++ b/lang/cem/cemcom.ansi/ch3mon.c @@ -21,7 +21,7 @@ extern char options[]; extern arith full_mask[/*MAXSIZE + 1*/]; /* cstoper.c */ -char *symbol2str(); +char *symbol2str(int tok); ch3mon(oper, expp) register struct expr **expp; diff --git a/lang/cem/cemcom.ansi/make.tokcase b/lang/cem/cemcom.ansi/make.tokcase index 772489f0a..a092776be 100755 --- a/lang/cem/cemcom.ansi/make.tokcase +++ b/lang/cem/cemcom.ansi/make.tokcase @@ -5,9 +5,7 @@ cat <<'--EOT--' /* $Id$ */ #include "Lpars.h" -char * -symbol2str(tok) - int tok; +char *symbol2str(int tok) { #define SIZBUF 8 /* allow for a few invocations in f.i. an argument list */ -- 2.34.1