Compare commits
10 Commits
to_ansi
...
dtrg-exper
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3f09da5045 | ||
|
|
33b4873932 | ||
|
|
d91a1dc1a6 | ||
|
|
b9b808e01a | ||
|
|
99d7f513f2 | ||
|
|
bcfb3d802f | ||
|
|
8e2d027c49 | ||
|
|
8d0261473d | ||
|
|
c93cb69959 | ||
|
|
c8fdcff960 |
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,5 +0,0 @@
|
||||
*~
|
||||
*.o
|
||||
.*
|
||||
-.gitignore
|
||||
/pattern.c
|
||||
32
Copyright
Normal file
32
Copyright
Normal file
@ -0,0 +1,32 @@
|
||||
Copyright (c) 1987, 1990, 1993, 2005 Vrije Universiteit, Amsterdam, The Netherlands.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use of the Amsterdam Compiler Kit in source and
|
||||
binary forms, with or without modification, are permitted provided
|
||||
that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following
|
||||
disclaimer in the documentation and/or other materials provided
|
||||
with the distribution.
|
||||
|
||||
* Neither the name of Vrije Universiteit nor the names of the
|
||||
software authors or contributors may be used to endorse or
|
||||
promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS, AUTHORS, AND
|
||||
CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL VRIJE UNIVERSITEIT OR ANY AUTHORS OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
32
LICENSE
32
LICENSE
@ -1,32 +0,0 @@
|
||||
Copyright (c) 1987, 1990, 1993, 2005 Vrije Universiteit, Amsterdam, The Netherlands.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use of the Amsterdam Compiler Kit in source and
|
||||
binary forms, with or without modification, are permitted provided
|
||||
that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following
|
||||
disclaimer in the documentation and/or other materials provided
|
||||
with the distribution.
|
||||
|
||||
* Neither the name of Vrije Universiteit nor the names of the
|
||||
software authors or contributors may be used to endorse or
|
||||
promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS, AUTHORS, AND
|
||||
CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL VRIJE UNIVERSITEIT OR ANY AUTHORS OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
37
README
37
README
@ -1,8 +1,9 @@
|
||||
THE AMSTERDAM COMPILER KIT V6.0pre4
|
||||
===================================
|
||||
THE AMSTERDAM COMPILER KIT V6.0pre4
|
||||
===================================
|
||||
|
||||
© 1987-2005 Vrije Universiteit, Amsterdam
|
||||
2010-08-08
|
||||
|
||||
© 1987-2005 Vrije Universiteit, Amsterdam 2010-08-08
|
||||
© 2013-2014 Manoel Trapier, Paris
|
||||
|
||||
INTRODUCTION
|
||||
============
|
||||
@ -17,23 +18,6 @@ lot is supported, the build mechanism needs work, and a lot of things are
|
||||
probably broken. However, what's there should be sufficient to get things
|
||||
done and to evaluate how the full 6.0 release should work.
|
||||
|
||||
This is a fork from the original repository found on sourceforge. This
|
||||
fork exist for three reason, the first is I strongly prefere git than
|
||||
mercurial (this is a personal preference) and second I want to make it
|
||||
work on Mac OS X but the OSX clang/gcc does not really like the K&R
|
||||
syntax, so I take into the process of ANSIfy it. The third reason is why
|
||||
I want to use the ACK, it support old CPU, like the 6502 or i8080, i8086
|
||||
and it is open source unlike a lot of compiler we can found nowadays for
|
||||
such targets, and it support more than C that is a wonderfull bonus!
|
||||
|
||||
I have plan to add targets like the NES, add support for the 65c816 and
|
||||
add the SNES target, add the WonderSwan as a target and so on. I see in
|
||||
this compiler kit a wonderfull project for all sort of old computer that
|
||||
are still used nowadays and used CPU that are no longuer targeted by
|
||||
modern compilers.
|
||||
|
||||
I plan to push my changes on the original version, at least for the new
|
||||
targets and cpu.
|
||||
|
||||
SUPPORT
|
||||
=======
|
||||
@ -171,19 +155,16 @@ more welcome.
|
||||
The ACK is licensed under a BSD-like license. Please see the 'Copyright' file
|
||||
for the full text.
|
||||
|
||||
You will find this "ANSI Fork" on github:
|
||||
|
||||
http://github.com/Godzil/ack
|
||||
|
||||
You can find the ACK mailing list and the original project's web site:
|
||||
You can find the mailing list on the project's web site:
|
||||
|
||||
http://tack.sourceforge.net/
|
||||
|
||||
Please enjoy.
|
||||
|
||||
Manoel Trapier (aka godzil) for the ANSI-fication port
|
||||
|
||||
David Given (dtrg on Sourceforge)
|
||||
dg@cowlark.com
|
||||
2010-08-08
|
||||
|
||||
# $Source$
|
||||
# $State$
|
||||
# $Revision$
|
||||
|
||||
@ -25,7 +25,7 @@ CXXPROGRAM = "%CXXCOMPILER% %CBUILDFLAGS% %CLINKFLAGS% %CEXTRAFLAGS% -o %out% %i
|
||||
|
||||
CLIBRARY = "rm -f %out% && ar cr %out% %in% && ranlib %out%"
|
||||
|
||||
CBUILDFLAGS = {"-g", "-Werror", "-std=c89"}
|
||||
CBUILDFLAGS = {"-g"}
|
||||
CINCLUDES = EMPTY
|
||||
CDEFINES = EMPTY
|
||||
CEXTRAFLAGS = EMPTY
|
||||
|
||||
@ -3,7 +3,7 @@ yacc = simple {
|
||||
outputs = {"%U%/%I%.c"},
|
||||
|
||||
command = {
|
||||
"byacc -t -b %out[1]:dirname%/y -d %in%",
|
||||
"yacc -t -b %out[1]:dirname%/y -d %in%",
|
||||
"mv %out[1]:dirname%/y.tab.c %out[1]%"
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,9 +4,6 @@
|
||||
*/
|
||||
/* $Id$ */
|
||||
|
||||
#ifndef H_CGG_CG_H
|
||||
#define H_CGG_CG_H
|
||||
|
||||
/* offsets of interesting fields in EM-pattern */
|
||||
|
||||
#define PO_HASH 0
|
||||
@ -42,6 +39,7 @@
|
||||
#define DO_TOSTACK 23
|
||||
#define DO_KILLREG 24
|
||||
#define DO_LABDEF 25
|
||||
#define DO_STACKADJUST 26
|
||||
|
||||
#ifndef MAXATT
|
||||
#define MAXATT TOKENSIZE
|
||||
@ -136,6 +134,7 @@ typedef struct exprnode *node_p;
|
||||
#define EX_ISROM 44
|
||||
#define EX_TOPELTSIZE 45
|
||||
#define EX_FALLTHROUGH 46
|
||||
#define EX_STACKOFFSET 47
|
||||
|
||||
|
||||
typedef struct { /* to stack coercions */
|
||||
@ -168,5 +167,3 @@ typedef struct { /* one to one coercions */
|
||||
if ((a=((*(b)++)&BMASK)) >= 128) {\
|
||||
a = ((a-128)<<BSHIFT) | (*(b)++&BMASK); \
|
||||
}
|
||||
|
||||
#endif /* H_CGG_CG_H */
|
||||
16
h/con_float
16
h/con_float
@ -55,7 +55,10 @@
|
||||
+ (FL_MSB_AT_LOW_ADDRESS ? 1 : 0))
|
||||
|
||||
#ifndef USE_FLT
|
||||
static int float_cst(char *str, int sz, char *buf)
|
||||
static int
|
||||
float_cst(str, sz, buf)
|
||||
char *str, *buf;
|
||||
int sz;
|
||||
{
|
||||
int i;
|
||||
char *p;
|
||||
@ -84,7 +87,10 @@ static int float_cst(char *str, int sz, char *buf)
|
||||
#include <ctype.h>
|
||||
#include <flt_arith.h>
|
||||
|
||||
int float_cst(char *str, int sz, char *buf)
|
||||
int
|
||||
float_cst(str, sz, buf)
|
||||
char *str, *buf;
|
||||
int sz;
|
||||
{
|
||||
int overflow = 0;
|
||||
flt_arith e;
|
||||
@ -231,7 +237,7 @@ int float_cst(char *str, int sz, char *buf)
|
||||
#endif /* USE_FLT */
|
||||
|
||||
#ifdef CODE_GENERATOR
|
||||
void con_float()
|
||||
con_float()
|
||||
{
|
||||
char buf[8];
|
||||
int rval = float_cst(str, (int)argval, buf);
|
||||
@ -254,7 +260,9 @@ void con_float()
|
||||
#endif /* CODE_GENERATOR */
|
||||
|
||||
#ifdef CODE_EXPANDER
|
||||
void con_float(char *str, arith argval)
|
||||
con_float(str, argval)
|
||||
char *str;
|
||||
arith argval;
|
||||
{
|
||||
char buf[8];
|
||||
int rval = float_cst(str, (int)argval, buf);
|
||||
|
||||
@ -1,29 +0,0 @@
|
||||
#ifndef H_MISSING_PROTO_H
|
||||
#define H_MISSING_PROTO_H
|
||||
|
||||
#ifdef NOSBRK
|
||||
void *sbrk(__intptr_t increment);
|
||||
void *brk(void * addr);
|
||||
#endif
|
||||
|
||||
#ifdef NOMKTEMP
|
||||
char *mktemp(char *template);
|
||||
#endif
|
||||
|
||||
#ifdef EMULATE_BRK
|
||||
void *sbrk_emu(int increment);
|
||||
void *brk_emu(const void * addr);
|
||||
|
||||
#ifdef sbrk
|
||||
#undef sbrk
|
||||
#endif
|
||||
#ifdef brk
|
||||
#undef brk
|
||||
#endif
|
||||
|
||||
#define sbrk sbrk_emu
|
||||
#define brk brk_emu
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* H_MISSING_H */
|
||||
5
h/out.h
5
h/out.h
@ -61,7 +61,10 @@ struct outname {
|
||||
#define RELSZ 0x07 /* relocation length */
|
||||
#define RELO1 1 /* 1 byte */
|
||||
#define RELO2 2 /* 2 bytes */
|
||||
#define RELO4 4 /* 4 bytes */
|
||||
#define RELO4 3 /* 4 bytes */
|
||||
#define RELOPPC 4 /* PowerPC 26-bit address */
|
||||
#define RELOH2 5 /* write top 2 bytes of 4 byte word */
|
||||
|
||||
#define RELPC 0x08 /* pc relative */
|
||||
#define RELBR 0x10 /* High order byte lowest address. */
|
||||
#define RELWR 0x20 /* High order word lowest address. */
|
||||
|
||||
@ -1,15 +0,0 @@
|
||||
/*
|
||||
* The Amsterdam Compiler Kit
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
|
||||
#ifndef H_SYMBOL2STR_H
|
||||
#define H_SYMBOL2STR_H
|
||||
|
||||
/* A lot of component use a version of this function, there is currently no header file
|
||||
* that contain it, and all use the same prototype as they are all generated from the same
|
||||
* generator.
|
||||
*/
|
||||
char *symbol2str(int tok);
|
||||
|
||||
#endif
|
||||
@ -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
|
||||
|
||||
@ -22,9 +22,6 @@
|
||||
#include "class.h"
|
||||
#include "assert.h"
|
||||
#include "sizes.h"
|
||||
#include "error.h"
|
||||
#include "domacro.h"
|
||||
#include "replace_loc.h"
|
||||
#include "specials.h" /* registration of special identifiers */
|
||||
|
||||
/* Data about the token yielded */
|
||||
@ -65,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.
|
||||
*/
|
||||
void PushLex()
|
||||
PushLex()
|
||||
{
|
||||
ASSERT(LexSP < MAX_LL_DEPTH);
|
||||
ASSERT(ASIDE == 0); /* ASIDE = 0; */
|
||||
@ -73,14 +70,15 @@ void PushLex()
|
||||
LexStack[LexSP++] = dot;
|
||||
}
|
||||
|
||||
void PopLex()
|
||||
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
|
||||
@ -110,13 +108,12 @@ int LLlex()
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
char *string_token();
|
||||
arith char_constant();
|
||||
|
||||
int GetToken(struct token *ptok)
|
||||
int
|
||||
GetToken(ptok)
|
||||
register struct token *ptok;
|
||||
{
|
||||
/* GetToken() is the actual token recognizer. It calls the
|
||||
control line interpreter if it encounters a "\n{w}*#"
|
||||
@ -124,7 +121,7 @@ int GetToken(struct token *ptok)
|
||||
needed.
|
||||
*/
|
||||
char buf[(IDFSIZE > NUMSIZE ? IDFSIZE : NUMSIZE) + 1];
|
||||
int ch, nch;
|
||||
register int ch, nch;
|
||||
|
||||
token_nmb++;
|
||||
|
||||
@ -230,7 +227,8 @@ 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 == '<') {
|
||||
@ -314,10 +312,10 @@ garbage:
|
||||
/* fallthrough */
|
||||
case STIDF:
|
||||
{
|
||||
char *tg = &buf[0];
|
||||
int pos = -1;
|
||||
struct idf *idef;
|
||||
extern int idfsize;
|
||||
register char *tg = &buf[0];
|
||||
register int pos = -1;
|
||||
register struct idf *idef;
|
||||
extern int idfsize; /* ??? */
|
||||
#ifndef NOPP
|
||||
int NoExpandNext = 0;
|
||||
|
||||
@ -363,8 +361,8 @@ garbage:
|
||||
}
|
||||
case STNUM: /* a numeric constant */
|
||||
{
|
||||
int siz_left = NUMSIZE - 1;
|
||||
char *np = &buf[0];
|
||||
register int siz_left = NUMSIZE - 1;
|
||||
register char *np = &buf[0];
|
||||
int flags = 0;
|
||||
|
||||
#define store(ch) if (--siz_left >= 0) \
|
||||
@ -446,11 +444,10 @@ garbage:
|
||||
crash("bad class for char 0%o", ch);
|
||||
}
|
||||
/*NOTREACHED*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef NOPP
|
||||
void skipcomment()
|
||||
skipcomment()
|
||||
{
|
||||
/* The last character read has been the '*' of '/_*'. The
|
||||
characters, except NL and EOI, between '/_*' and the first
|
||||
@ -462,7 +459,7 @@ void skipcomment()
|
||||
EOI is returned by LoadChar only on encountering EOF of the
|
||||
top-level file...
|
||||
*/
|
||||
int c, oldc = '\0';
|
||||
register int c, oldc = '\0';
|
||||
|
||||
NoUnstack++;
|
||||
c = GetChar();
|
||||
@ -504,10 +501,12 @@ void skipcomment()
|
||||
}
|
||||
#endif /* NOPP */
|
||||
|
||||
arith char_constant(char *nm)
|
||||
arith
|
||||
char_constant(nm)
|
||||
char *nm;
|
||||
{
|
||||
arith val = 0;
|
||||
int ch;
|
||||
register arith val = 0;
|
||||
register int ch;
|
||||
int size = 0;
|
||||
|
||||
ch = GetChar();
|
||||
@ -535,12 +534,15 @@ arith char_constant(char *nm)
|
||||
return val;
|
||||
}
|
||||
|
||||
char *string_token(char *nm, int stop_char, int *plen)
|
||||
char *
|
||||
string_token(nm, stop_char, plen)
|
||||
char *nm;
|
||||
int *plen;
|
||||
{
|
||||
int ch;
|
||||
int str_size;
|
||||
char *str = Malloc((unsigned) (str_size = ISTRSIZE));
|
||||
int pos = 0;
|
||||
register int ch;
|
||||
register int str_size;
|
||||
register char *str = Malloc((unsigned) (str_size = ISTRSIZE));
|
||||
register int pos = 0;
|
||||
|
||||
ch = GetChar();
|
||||
while (ch != stop_char) {
|
||||
@ -565,7 +567,9 @@ char *string_token(char *nm, int stop_char, int *plen)
|
||||
return str;
|
||||
}
|
||||
|
||||
int quoted(int ch)
|
||||
int
|
||||
quoted(ch)
|
||||
register int ch;
|
||||
{
|
||||
/* quoted() replaces an escaped character sequence by the
|
||||
character meant.
|
||||
@ -624,7 +628,9 @@ int quoted(int ch)
|
||||
}
|
||||
|
||||
|
||||
int hex_val(int ch)
|
||||
int
|
||||
hex_val(ch)
|
||||
register int ch;
|
||||
{
|
||||
return is_dig(ch) ? ch - '0'
|
||||
: is_hex(ch) ? (ch - 'a' + 10) & 017
|
||||
@ -632,12 +638,13 @@ int hex_val(int ch)
|
||||
}
|
||||
|
||||
|
||||
int GetChar()
|
||||
int
|
||||
GetChar()
|
||||
{
|
||||
/* The routines GetChar and trigraph parses the trigraph
|
||||
sequences and removes occurences of \\\n.
|
||||
*/
|
||||
int ch;
|
||||
register int ch;
|
||||
|
||||
#ifndef NOPP
|
||||
again:
|
||||
@ -664,9 +671,10 @@ again:
|
||||
}
|
||||
|
||||
#ifndef NOPP
|
||||
int trigraph()
|
||||
int
|
||||
trigraph()
|
||||
{
|
||||
int ch;
|
||||
register int ch;
|
||||
|
||||
LoadChar(ch);
|
||||
if (ch == '?') {
|
||||
@ -710,22 +718,24 @@ int trigraph()
|
||||
/* strflt2tok only checks the syntax of the floating-point number and
|
||||
* selects the right type for the number.
|
||||
*/
|
||||
void strflt2tok(char fltbuf[], struct token *ptok)
|
||||
strflt2tok(fltbuf, ptok)
|
||||
char fltbuf[];
|
||||
struct token *ptok;
|
||||
{
|
||||
char *cp = fltbuf;
|
||||
register char *cp = fltbuf;
|
||||
int malformed = 0;
|
||||
|
||||
while (is_dig(*(unsigned char *)cp)) cp++;
|
||||
while (is_dig(*cp)) cp++;
|
||||
if (*cp == '.') {
|
||||
cp++;
|
||||
while (is_dig(*(unsigned char *)cp)) cp++;
|
||||
while (is_dig(*cp)) cp++;
|
||||
}
|
||||
if (*cp == 'e' || *cp == 'E') {
|
||||
cp++;
|
||||
if (*cp == '+' || *cp == '-')
|
||||
cp++;
|
||||
if (!is_dig(*(unsigned char *)cp)) malformed++;
|
||||
while (is_dig(*(unsigned char *)cp)) cp++;
|
||||
if (!is_dig(*cp)) malformed++;
|
||||
while (is_dig(*cp)) cp++;
|
||||
}
|
||||
if (*cp == 'f' || *cp == 'F') {
|
||||
if (*(cp + 1)) malformed++;
|
||||
@ -747,9 +757,11 @@ void strflt2tok(char fltbuf[], struct token *ptok)
|
||||
}
|
||||
}
|
||||
|
||||
void strint2tok(char intbuf[], struct token *ptok)
|
||||
strint2tok(intbuf, ptok)
|
||||
char intbuf[];
|
||||
struct token *ptok;
|
||||
{
|
||||
char *cp = intbuf;
|
||||
register char *cp = intbuf;
|
||||
int base = 10;
|
||||
arith val = 0, dig, ubound;
|
||||
int uns_flg = 0, lng_flg = 0, malformed = 0, ovfl = 0;
|
||||
@ -769,8 +781,8 @@ void strint2tok(char intbuf[], struct token *ptok)
|
||||
*/
|
||||
ubound = max_arith / (base / 2);
|
||||
|
||||
while (is_hex(*(unsigned char *)cp)) {
|
||||
dig = hex_val(*(unsigned char *)cp);
|
||||
while (is_hex(*cp)) {
|
||||
dig = hex_val(*cp);
|
||||
if (dig >= base) {
|
||||
malformed++; /* ignore */
|
||||
}
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
#ifndef LANG_CEM_CEMCOM_ANSI_LLLEX_H
|
||||
#define LANG_CEM_CEMCOM_ANSI_LLLEX_H
|
||||
/*
|
||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
@ -65,21 +63,3 @@ extern int err_occurred; /* "error.c" */
|
||||
#define ASIDE aside.tk_symb
|
||||
|
||||
#define EOF (-1)
|
||||
|
||||
/* lang/cem/cemcom.ansi/LLlex.c */
|
||||
void PushLex(void);
|
||||
void PopLex(void);
|
||||
int LLlex(void);
|
||||
int GetToken(struct token *ptok);
|
||||
void skipcomment(void);
|
||||
arith char_constant(char *nm);
|
||||
char *string_token(char *nm, int stop_char, int *plen);
|
||||
int quoted(int ch);
|
||||
int hex_val(int ch);
|
||||
int GetChar(void);
|
||||
int trigraph(void);
|
||||
void strflt2tok(char fltbuf[], struct token *ptok);
|
||||
void strint2tok(char intbuf[], struct token *ptok);
|
||||
|
||||
#endif /* LANG_CEM_CEMCOM_ANSI_LLLEX_H */
|
||||
|
||||
|
||||
@ -10,14 +10,10 @@
|
||||
#include "arith.h"
|
||||
#include "LLlex.h"
|
||||
#include "Lpars.h"
|
||||
#include "error.h"
|
||||
|
||||
#include <symbol2str.h>
|
||||
extern char *symbol2str();
|
||||
|
||||
void insert_token(int tk);
|
||||
|
||||
void LLmessage(tk)
|
||||
{
|
||||
LLmessage(tk) {
|
||||
err_occurred = 1;
|
||||
if (tk < 0) {
|
||||
error("end of file expected");
|
||||
@ -38,7 +34,8 @@ void LLmessage(tk)
|
||||
tk_nmb_at_last_syn_err = token_nmb;
|
||||
}
|
||||
|
||||
void insert_token(int tk)
|
||||
insert_token(tk)
|
||||
int tk;
|
||||
{
|
||||
aside = dot;
|
||||
|
||||
|
||||
@ -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 */
|
||||
|
||||
|
||||
|
||||
@ -27,19 +27,15 @@
|
||||
#include "field.h"
|
||||
#include "mes.h"
|
||||
#include "assert.h"
|
||||
#include "ch3.h"
|
||||
#include "ch3bin.h"
|
||||
#include "code_c.h"
|
||||
#include "conversion.h"
|
||||
#include "cstoper.h"
|
||||
#include "expr_loc.h"
|
||||
#include "error.h"
|
||||
|
||||
#include <symbol2str.h>
|
||||
|
||||
extern char *symbol2str();
|
||||
extern char options[];
|
||||
extern arith flt_flt2arith();
|
||||
extern label code_string();
|
||||
|
||||
void arithbalance(struct expr **e1p, int oper, struct expr **e2p) /* 3.1.2.5 */
|
||||
arithbalance(e1p, oper, e2p) /* 3.1.2.5 */
|
||||
register struct expr **e1p, **e2p;
|
||||
int oper;
|
||||
{
|
||||
/* The expressions *e1p and *e2p are balanced to be operands
|
||||
of the arithmetic operator oper.
|
||||
@ -48,16 +44,16 @@ void arithbalance(struct expr **e1p, int oper, struct expr **e2p) /* 3.1.2.5 */
|
||||
have a floating type, in which case the flags shouldn't
|
||||
travel upward in the expression tree.
|
||||
*/
|
||||
int t1, t2, u1, u2;
|
||||
register int t1, t2, u1, u2;
|
||||
int shifting = (oper == LEFT || oper == RIGHT
|
||||
|| oper == LEFTAB || oper == RIGHTAB);
|
||||
|| oper == LEFTAB || oper == RIGHTAB);
|
||||
int ptrdiff = 0;
|
||||
|
||||
t1 = any2arith(e1p, oper);
|
||||
t2 = any2arith(e2p, oper);
|
||||
|
||||
if (int_size != pointer_size) {
|
||||
if ((ptrdiff = ((*e1p)->ex_flags & EX_PTRDIFF))
|
||||
if (ptrdiff = ((*e1p)->ex_flags & EX_PTRDIFF)
|
||||
|| ((*e2p)->ex_flags & EX_PTRDIFF)) {
|
||||
if (!((*e1p)->ex_flags & EX_PTRDIFF) && t1 == LONG)
|
||||
ptrdiff = 0;
|
||||
@ -86,16 +82,10 @@ void arithbalance(struct expr **e1p, int oper, struct expr **e2p) /* 3.1.2.5 */
|
||||
return;
|
||||
} else if (t2 == LNGDBL) {
|
||||
if (t1 != LNGDBL)
|
||||
{
|
||||
if (t1 == DOUBLE || t1 == FLOAT)
|
||||
{
|
||||
float2float(e1p, lngdbl_type);
|
||||
}
|
||||
else
|
||||
{
|
||||
int2float(e1p, lngdbl_type);
|
||||
}
|
||||
}
|
||||
if (t1 == DOUBLE || t1 == FLOAT)
|
||||
float2float(e1p, lngdbl_type);
|
||||
else
|
||||
int2float(e1p, lngdbl_type);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -183,7 +173,8 @@ void arithbalance(struct expr **e1p, int oper, struct expr **e2p) /* 3.1.2.5 */
|
||||
}
|
||||
}
|
||||
|
||||
void relbalance(struct expr **e1p, int oper, struct expr **e2p)
|
||||
relbalance(e1p, oper, e2p)
|
||||
register struct expr **e1p, **e2p;
|
||||
{
|
||||
/* The expressions *e1p and *e2p are balanced to be operands
|
||||
of the relational operator oper, or the ':'.
|
||||
@ -192,7 +183,7 @@ void relbalance(struct expr **e1p, int oper, struct expr **e2p)
|
||||
allows assignments of a null-pointer to a function
|
||||
pointer.
|
||||
*/
|
||||
struct expr *e1 = *e1p, *e2 = *e2p;
|
||||
register struct expr *e1 = *e1p, *e2 = *e2p;
|
||||
struct expr *tmpexpr;
|
||||
|
||||
if (e1->ex_type->tp_fund == POINTER
|
||||
@ -215,13 +206,15 @@ void relbalance(struct expr **e1p, int oper, struct expr **e2p)
|
||||
arithbalance(e1p, oper, e2p);
|
||||
}
|
||||
|
||||
void ch3pointer(struct expr **expp, int oper, struct type *tp)
|
||||
ch3pointer(expp, oper, tp)
|
||||
struct expr **expp;
|
||||
register struct type *tp;
|
||||
{
|
||||
/* Checks whether *expp may be compared to tp using oper,
|
||||
as described in chapter 3.3.8 and 3.3.9.
|
||||
tp is known to be a pointer.
|
||||
*/
|
||||
struct expr *exp = *expp;
|
||||
register struct expr *exp = *expp;
|
||||
|
||||
if (exp->ex_type->tp_fund == POINTER) {
|
||||
if (exp->ex_type != tp)
|
||||
@ -246,7 +239,10 @@ void ch3pointer(struct expr **expp, int oper, struct type *tp)
|
||||
}
|
||||
}
|
||||
|
||||
int any2arith(struct expr **expp, int oper)
|
||||
int
|
||||
any2arith(expp, oper)
|
||||
register struct expr **expp;
|
||||
register int oper;
|
||||
{
|
||||
/* Turns any expression into int_type, long_type,
|
||||
float_type, double_type or lngdbl_type.
|
||||
@ -301,7 +297,8 @@ int any2arith(struct expr **expp, int oper)
|
||||
return (*expp)->ex_type->tp_fund;
|
||||
}
|
||||
|
||||
void erroneous2int(struct expr **expp)
|
||||
erroneous2int(expp)
|
||||
struct expr **expp;
|
||||
{
|
||||
/* the (erroneous) expression *expp is replaced by an
|
||||
int expression
|
||||
@ -315,12 +312,16 @@ void erroneous2int(struct expr **expp)
|
||||
*expp = exp;
|
||||
}
|
||||
|
||||
struct expr *arith2arith(struct type *tp, int oper, struct expr *expr)
|
||||
struct expr *
|
||||
arith2arith(tp, oper, expr)
|
||||
struct type *tp;
|
||||
int oper;
|
||||
register struct expr *expr;
|
||||
{
|
||||
/* arith2arith constructs a new expression containing a
|
||||
run-time conversion between some arithmetic types.
|
||||
*/
|
||||
struct expr *new = new_expr();
|
||||
register struct expr *new = new_expr();
|
||||
|
||||
new->ex_file = expr->ex_file;
|
||||
new->ex_line = expr->ex_line;
|
||||
@ -329,15 +330,18 @@ struct expr *arith2arith(struct type *tp, int oper, struct expr *expr)
|
||||
return new_oper(tp, new, oper, expr);
|
||||
}
|
||||
|
||||
int int2int(struct expr **expp, struct type *tp)
|
||||
int
|
||||
int2int(expp, tp)
|
||||
struct expr **expp;
|
||||
register struct type *tp;
|
||||
{
|
||||
/* The expression *expp, which is of some integral type, is
|
||||
converted to the integral type tp.
|
||||
*/
|
||||
struct expr *exp = *expp;
|
||||
register struct expr *exp = *expp;
|
||||
|
||||
if (is_cp_cst(exp)) {
|
||||
struct type *tp1 = exp->ex_type;
|
||||
register struct type *tp1 = exp->ex_type;
|
||||
|
||||
exp->ex_type = tp;
|
||||
if (! tp1->tp_unsigned && tp->tp_unsigned) {
|
||||
@ -367,12 +371,14 @@ int int2int(struct expr **expp, struct type *tp)
|
||||
/* With compile-time constants, we don't set fp_used, since this is done
|
||||
* only when necessary in eval.c.
|
||||
*/
|
||||
void int2float(struct expr **expp, struct type *tp)
|
||||
int2float(expp, tp)
|
||||
register struct expr **expp;
|
||||
struct type *tp;
|
||||
{
|
||||
/* The expression *expp, which is of some integral type, is
|
||||
converted to the floating type tp.
|
||||
*/
|
||||
struct expr *exp = *expp;
|
||||
register struct expr *exp = *expp;
|
||||
int uns = exp->ex_type->tp_unsigned;
|
||||
|
||||
if (is_cp_cst(exp)) {
|
||||
@ -386,12 +392,14 @@ void int2float(struct expr **expp, struct type *tp)
|
||||
}
|
||||
}
|
||||
|
||||
void float2int(struct expr **expp, struct type *tp)
|
||||
float2int(expp, tp)
|
||||
struct expr **expp;
|
||||
struct type *tp;
|
||||
{
|
||||
/* The expression *expp, which is of some floating type, is
|
||||
converted to the integral type tp.
|
||||
*/
|
||||
struct expr *ex = *expp;
|
||||
register struct expr *ex = *expp;
|
||||
|
||||
if (is_fp_cst(ex)) {
|
||||
arith ar = flt_flt2arith(&ex->FL_ARITH, tp->tp_unsigned);
|
||||
@ -412,7 +420,9 @@ void float2int(struct expr **expp, struct type *tp)
|
||||
}
|
||||
}
|
||||
|
||||
void float2float(struct expr**expp, struct type *tp)
|
||||
float2float(expp, tp)
|
||||
register struct expr **expp;
|
||||
struct type *tp;
|
||||
{
|
||||
/* The expression *expp, which is of some floating type, is
|
||||
converted to the floating type tp.
|
||||
@ -428,7 +438,8 @@ void float2float(struct expr**expp, struct type *tp)
|
||||
}
|
||||
}
|
||||
|
||||
void array2pointer(struct expr *exp)
|
||||
array2pointer(exp)
|
||||
register struct expr *exp;
|
||||
{
|
||||
/* The expression, which must be an array, is converted
|
||||
to a pointer.
|
||||
@ -438,7 +449,8 @@ void array2pointer(struct expr *exp)
|
||||
, (arith)0, NO_PROTO);
|
||||
}
|
||||
|
||||
void function2pointer(struct expr *exp)
|
||||
function2pointer(exp)
|
||||
register struct expr *exp;
|
||||
{
|
||||
/* The expression, which must be a function, is converted
|
||||
to a pointer to the function.
|
||||
@ -447,7 +459,8 @@ void function2pointer(struct expr *exp)
|
||||
(arith)0, NO_PROTO);
|
||||
}
|
||||
|
||||
void string2pointer(struct expr *ex)
|
||||
string2pointer(ex)
|
||||
register struct expr *ex;
|
||||
{
|
||||
/* The expression, which must be a string constant, is converted
|
||||
to a pointer to the string-containing area.
|
||||
@ -461,9 +474,11 @@ void string2pointer(struct expr *ex)
|
||||
ex->VL_VALUE = (arith)0;
|
||||
}
|
||||
|
||||
void opnd2integral(struct expr **expp, int oper)
|
||||
opnd2integral(expp, oper)
|
||||
register struct expr **expp;
|
||||
int oper;
|
||||
{
|
||||
int fund = (*expp)->ex_type->tp_fund;
|
||||
register int fund = (*expp)->ex_type->tp_fund;
|
||||
|
||||
if (fund != INT && fund != LONG) {
|
||||
expr_error(*expp, "%s operand to %s",
|
||||
@ -473,7 +488,9 @@ void opnd2integral(struct expr **expp, int oper)
|
||||
}
|
||||
}
|
||||
|
||||
void opnd2logical(struct expr **expp, int oper)
|
||||
opnd2logical(expp, oper)
|
||||
register struct expr **expp;
|
||||
int oper;
|
||||
{
|
||||
int fund = (*expp)->ex_type->tp_fund;
|
||||
|
||||
@ -509,7 +526,8 @@ void opnd2logical(struct expr **expp, int oper)
|
||||
}
|
||||
}
|
||||
|
||||
void opnd2test(struct expr **expp, int oper)
|
||||
opnd2test(expp, oper)
|
||||
register struct expr **expp;
|
||||
{
|
||||
opnd2logical(expp, oper);
|
||||
if ((*expp)->ex_class == Oper) {
|
||||
@ -533,7 +551,8 @@ void opnd2test(struct expr **expp, int oper)
|
||||
ch3bin(expp, NOTEQUAL, intexpr((arith)0, INT));
|
||||
}
|
||||
|
||||
void any2opnd(struct expr **expp, int oper)
|
||||
any2opnd(expp, oper)
|
||||
register struct expr **expp;
|
||||
{
|
||||
if (!*expp)
|
||||
return;
|
||||
@ -544,9 +563,7 @@ void any2opnd(struct expr **expp, int oper)
|
||||
case CHAR:
|
||||
case SHORT:
|
||||
case ENUM:
|
||||
#if 0
|
||||
case FLOAT: /* not necessary anymore */
|
||||
#endif
|
||||
/* case FLOAT: /* not necessary anymore */
|
||||
any2arith(expp, oper);
|
||||
break;
|
||||
case ARRAY:
|
||||
@ -567,7 +584,8 @@ void any2opnd(struct expr **expp, int oper)
|
||||
}
|
||||
}
|
||||
|
||||
void any2parameter(struct expr **expp)
|
||||
any2parameter(expp)
|
||||
register struct expr **expp;
|
||||
{
|
||||
/* To handle default argument promotions
|
||||
*/
|
||||
@ -580,13 +598,14 @@ void any2parameter(struct expr **expp)
|
||||
}
|
||||
|
||||
#ifndef NOBITFIELD
|
||||
void field2arith(struct expr **expp)
|
||||
field2arith(expp)
|
||||
register struct expr **expp;
|
||||
{
|
||||
/* The expression to extract the bitfield value from the
|
||||
memory word is put in the tree.
|
||||
*/
|
||||
struct type *tp = (*expp)->ex_type->tp_up;
|
||||
struct field *fd = (*expp)->ex_type->tp_field;
|
||||
register struct type *tp = (*expp)->ex_type->tp_up;
|
||||
register struct field *fd = (*expp)->ex_type->tp_field;
|
||||
|
||||
(*expp)->ex_type = word_type;
|
||||
|
||||
@ -611,7 +630,8 @@ void field2arith(struct expr **expp)
|
||||
/* switch_sign_fp() negates the given floating constant expression,
|
||||
* and frees the string representing the old value.
|
||||
*/
|
||||
void switch_sign_fp(struct expr *expr)
|
||||
switch_sign_fp(expr)
|
||||
register struct expr *expr;
|
||||
{
|
||||
flt_umin(&(expr->FL_ARITH));
|
||||
}
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
#ifndef LANG_CEM_CEMCOM_ANSI_ARITH_H
|
||||
#define LANG_CEM_CEMCOM_ANSI_ARITH_H
|
||||
/*
|
||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
@ -25,40 +23,10 @@
|
||||
|
||||
/* All preprocessor arithmetic should be done in longs.
|
||||
*/
|
||||
#include <stdint.h>
|
||||
|
||||
typedef int32_t arith; /* dummy */
|
||||
#define arith long /* dummy */
|
||||
|
||||
#endif /* SPECIAL_ARITHMETICS */
|
||||
|
||||
#define arith_size (sizeof(arith))
|
||||
#define arith_sign ((arith) 1 << (arith_size * 8 - 1))
|
||||
#define max_arith (~arith_sign)
|
||||
|
||||
struct expr;
|
||||
struct type;
|
||||
|
||||
/* lang/cem/cemcom.ansi/arith.c */
|
||||
void arithbalance(struct expr **e1p, int oper, struct expr **e2p);
|
||||
void relbalance(struct expr **e1p, int oper, struct expr **e2p);
|
||||
void ch3pointer(struct expr **expp, int oper, struct type *tp);
|
||||
int any2arith(struct expr **expp, int oper);
|
||||
void erroneous2int(struct expr **expp);
|
||||
struct expr *arith2arith(struct type *tp, int oper, struct expr *expr);
|
||||
int int2int(struct expr **expp, struct type *tp);
|
||||
void int2float(struct expr **expp, struct type *tp);
|
||||
void float2int(struct expr **expp, struct type *tp);
|
||||
void float2float(struct expr **expp, struct type *tp);
|
||||
void array2pointer(struct expr *exp);
|
||||
void function2pointer(struct expr *exp);
|
||||
void string2pointer(struct expr *ex);
|
||||
void opnd2integral(struct expr **expp, int oper);
|
||||
void opnd2logical(struct expr **expp, int oper);
|
||||
void opnd2test(struct expr **expp, int oper);
|
||||
void any2opnd(struct expr **expp, int oper);
|
||||
void any2parameter(struct expr **expp);
|
||||
void field2arith(struct expr **expp);
|
||||
void switch_sign_fp(struct expr *expr);
|
||||
|
||||
#endif /* LANG_CEM_CEMCOM_ANSI_ARITH_H */
|
||||
|
||||
|
||||
@ -18,16 +18,9 @@
|
||||
#include "label.h"
|
||||
#include "stack.h"
|
||||
#include "Lpars.h"
|
||||
#include "util_loc.h"
|
||||
#include "error.h"
|
||||
#include "idf_loc.h"
|
||||
#include "def.h"
|
||||
|
||||
extern arith NewLocal();
|
||||
#define LocalPtrVar() NewLocal(pointer_size, pointer_align, reg_pointer, REGISTER)
|
||||
#define LocalIntVar() NewLocal(int_size, int_align, reg_any, REGISTER)
|
||||
|
||||
static void copy_loop(arith sz, arith src, arith dst);
|
||||
|
||||
#endif /* STB */
|
||||
|
||||
/* Because EM does not support the loading and storing of
|
||||
@ -59,7 +52,9 @@ static void copy_loop(arith sz, arith src, arith dst);
|
||||
while we need a loop to store the stack block into a memory object.
|
||||
*/
|
||||
|
||||
static int suitable_sz(arith sz, int al)
|
||||
suitable_sz(sz, al)
|
||||
arith sz;
|
||||
int al;
|
||||
{
|
||||
return ((int)sz % (int)word_size == 0 && al % word_align == 0) ||
|
||||
(
|
||||
@ -69,7 +64,9 @@ static int suitable_sz(arith sz, int al)
|
||||
);
|
||||
}
|
||||
|
||||
void store_block(arith sz, int al)
|
||||
store_block(sz, al)
|
||||
arith sz;
|
||||
int al;
|
||||
{
|
||||
if (suitable_sz(sz, al))
|
||||
C_sti(sz);
|
||||
@ -105,7 +102,9 @@ void store_block(arith sz, int al)
|
||||
}
|
||||
}
|
||||
|
||||
void load_block(arith sz, int al)
|
||||
load_block(sz, al)
|
||||
arith sz;
|
||||
int al;
|
||||
{
|
||||
|
||||
if (suitable_sz(sz, al))
|
||||
@ -139,7 +138,9 @@ void load_block(arith sz, int al)
|
||||
}
|
||||
}
|
||||
|
||||
void copy_block(arith sz, int al)
|
||||
copy_block(sz, al)
|
||||
arith sz;
|
||||
int al;
|
||||
{
|
||||
|
||||
if (suitable_sz(sz, al))
|
||||
@ -166,7 +167,8 @@ void copy_block(arith sz, int al)
|
||||
}
|
||||
|
||||
#ifndef STB
|
||||
static void copy_loop(arith sz, arith src, arith dst)
|
||||
copy_loop(sz, src, dst)
|
||||
arith sz, src, dst;
|
||||
{
|
||||
/* generate inline byte-copy loop */
|
||||
label l_cont = text_label(), l_stop = text_label();
|
||||
|
||||
@ -1,8 +0,0 @@
|
||||
#ifndef LANG_CEM_CEMCOM_ANSI_BLOCKS_H
|
||||
#define LANG_CEM_CEMCOM_ANSI_BLOCKS_H
|
||||
|
||||
void store_block(arith sz, int al);
|
||||
void load_block(arith sz, int al);
|
||||
void copy_block(arith sz, int al);
|
||||
|
||||
#endif
|
||||
@ -20,35 +20,26 @@
|
||||
#include "Lpars.h"
|
||||
#include "assert.h"
|
||||
#include "file_info.h"
|
||||
#include "ch3.h"
|
||||
#include "ch3bin.h"
|
||||
#include "decspecs.h"
|
||||
#include "conversion.h"
|
||||
#include "error.h"
|
||||
#include "idf_loc.h"
|
||||
#include "expr_loc.h"
|
||||
#include <symbol2str.h>
|
||||
|
||||
extern char options[];
|
||||
|
||||
static int check_pseudoproto(struct proto *pl, struct proto *opl, int diag);
|
||||
static int legal_mixture(struct type *tp, struct type *otp, int diag);
|
||||
static int equal_proto(struct proto *pl, struct proto *opl, int diag);
|
||||
static int is_arith_type(struct type *tp);
|
||||
extern char *symbol2str();
|
||||
extern struct type *qualifier_type();
|
||||
|
||||
/* Most expression-handling routines have a pointer to a
|
||||
(struct type *) as first parameter. The object under the pointer
|
||||
gets updated in the process.
|
||||
*/
|
||||
|
||||
void ch3sel(struct expr **expp, int oper, struct idf *idf)
|
||||
ch3sel(expp, oper, idf)
|
||||
struct expr **expp;
|
||||
struct idf *idf;
|
||||
{
|
||||
/* The selector idf is applied to *expp; oper may be '.' or
|
||||
ARROW.
|
||||
*/
|
||||
struct expr *exp;
|
||||
struct type *tp;
|
||||
struct sdef *sd;
|
||||
register struct expr *exp;
|
||||
register struct type *tp;
|
||||
register struct sdef *sd;
|
||||
|
||||
any2opnd(expp, oper);
|
||||
exp = *expp;
|
||||
@ -171,7 +162,8 @@ void ch3sel(struct expr **expp, int oper, struct idf *idf)
|
||||
*expp = exp;
|
||||
}
|
||||
|
||||
void ch3incr(struct expr **expp, int oper)
|
||||
ch3incr(expp, oper)
|
||||
struct expr **expp;
|
||||
{
|
||||
/* The monadic prefix/postfix incr/decr operator oper is
|
||||
applied to *expp.
|
||||
@ -179,15 +171,17 @@ void ch3incr(struct expr **expp, int oper)
|
||||
ch3asgn(expp, oper, intexpr((arith)1, INT));
|
||||
}
|
||||
|
||||
void ch3cast(struct expr **expp, int oper, struct type *tp)
|
||||
ch3cast(expp, oper, tp)
|
||||
register struct expr **expp;
|
||||
register struct type *tp;
|
||||
{
|
||||
/* The expression *expp is cast to type tp; the cast is
|
||||
caused by the operator oper. If the cast has
|
||||
to be passed on to run time, its left operand will be an
|
||||
expression of class Type.
|
||||
*/
|
||||
struct type *oldtp;
|
||||
struct expr *exp = *expp;
|
||||
register struct type *oldtp;
|
||||
register struct expr *exp = *expp;
|
||||
int qual_lev, ascompat = 0;
|
||||
|
||||
if (oper == RETURN && tp->tp_fund == VOID) {
|
||||
@ -416,7 +410,9 @@ void ch3cast(struct expr **expp, int oper, struct type *tp)
|
||||
|
||||
/* Determine whether two types are equal.
|
||||
*/
|
||||
int equal_type(struct type *tp, struct type *otp, int qual_lev, int diag)
|
||||
equal_type(tp, otp, qual_lev, diag)
|
||||
register struct type *tp, *otp;
|
||||
int qual_lev, diag;
|
||||
{
|
||||
if (tp == otp)
|
||||
return 1;
|
||||
@ -477,7 +473,8 @@ int equal_type(struct type *tp, struct type *otp, int qual_lev, int diag)
|
||||
}
|
||||
}
|
||||
|
||||
static int check_pseudoproto(struct proto *pl, struct proto *opl, int diag)
|
||||
check_pseudoproto(pl, opl, diag)
|
||||
register struct proto *pl, *opl;
|
||||
{
|
||||
int retval = 1;
|
||||
|
||||
@ -520,11 +517,13 @@ static int check_pseudoproto(struct proto *pl, struct proto *opl, int diag)
|
||||
return retval;
|
||||
}
|
||||
|
||||
static int legal_mixture(struct type *tp, struct type *otp, int diag)
|
||||
legal_mixture(tp, otp, diag)
|
||||
struct type *tp, *otp;
|
||||
int diag;
|
||||
{
|
||||
struct proto *pl = tp->tp_proto, *opl = otp->tp_proto;
|
||||
int retval = 1;
|
||||
struct proto *prot;
|
||||
register struct proto *prot;
|
||||
int fund;
|
||||
|
||||
ASSERT( (pl != 0) ^ (opl != 0));
|
||||
@ -561,7 +560,9 @@ static int legal_mixture(struct type *tp, struct type *otp, int diag)
|
||||
return retval;
|
||||
}
|
||||
|
||||
static int equal_proto(struct proto *pl, struct proto *opl, int diag)
|
||||
equal_proto(pl, opl, diag)
|
||||
register struct proto *pl, *opl;
|
||||
int diag;
|
||||
{
|
||||
if (pl == opl)
|
||||
return 1;
|
||||
@ -583,9 +584,11 @@ static int equal_proto(struct proto *pl, struct proto *opl, int diag)
|
||||
}
|
||||
|
||||
/* check if a type has a consqualified member */
|
||||
int recurqual(struct type *tp, int qual)
|
||||
recurqual(tp, qual)
|
||||
struct type *tp;
|
||||
int qual;
|
||||
{
|
||||
struct sdef *sdf;
|
||||
register struct sdef *sdf;
|
||||
|
||||
ASSERT(tp);
|
||||
|
||||
@ -605,7 +608,9 @@ int recurqual(struct type *tp, int qual)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ch3asgn(struct expr **expp, int oper, struct expr *expr)
|
||||
ch3asgn(expp, oper, expr)
|
||||
struct expr **expp;
|
||||
struct expr *expr;
|
||||
{
|
||||
/* The assignment operators.
|
||||
"f op= e" should be interpreted as
|
||||
@ -620,7 +625,7 @@ void ch3asgn(struct expr **expp, int oper, struct expr *expr)
|
||||
f (typeof (f op e))e
|
||||
EVAL should however take care of evaluating (typeof (f op e))f
|
||||
*/
|
||||
struct expr *exp = *expp;
|
||||
register struct expr *exp = *expp;
|
||||
int fund = exp->ex_type->tp_fund;
|
||||
struct type *tp;
|
||||
char *oper_string = symbol2str(oper);
|
||||
@ -680,7 +685,9 @@ void ch3asgn(struct expr **expp, int oper, struct expr *expr)
|
||||
|
||||
/* Some interesting (?) questions answered.
|
||||
*/
|
||||
int is_integral_type(struct type *tp)
|
||||
int
|
||||
is_integral_type(tp)
|
||||
register struct type *tp;
|
||||
{
|
||||
switch (tp->tp_fund) {
|
||||
case CHAR:
|
||||
@ -698,7 +705,9 @@ int is_integral_type(struct type *tp)
|
||||
}
|
||||
}
|
||||
|
||||
static int is_arith_type(struct type *tp)
|
||||
int
|
||||
is_arith_type(tp)
|
||||
register struct type *tp;
|
||||
{
|
||||
switch (tp->tp_fund) {
|
||||
case CHAR:
|
||||
|
||||
@ -1,17 +0,0 @@
|
||||
/*
|
||||
* The Amsterdam Compiler Kit
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
|
||||
#ifndef LANG_CEM_CEMCOM_ANSI_CH3_H
|
||||
#define LANG_CEM_CEMCOM_ANSI_CH3_H
|
||||
|
||||
void ch3cast(struct expr **expp, int oper, struct type *tp);
|
||||
void ch3sel(struct expr **expp, int oper, struct idf *idf);
|
||||
void ch3incr(struct expr **expp, int oper);
|
||||
int equal_type(struct type *tp, struct type *otp, int qual_lev, int diag);
|
||||
int recurqual(struct type *tp, int qual);
|
||||
void ch3asgn(struct expr **expp, int oper, struct expr *expr);
|
||||
int is_integral_type(struct type *tp);
|
||||
|
||||
#endif
|
||||
@ -18,24 +18,9 @@
|
||||
#include "expr.h"
|
||||
#include "Lpars.h"
|
||||
#include "sizes.h"
|
||||
#include "ch3.h"
|
||||
#include "ch3bin.h"
|
||||
#include "ch3mon.h"
|
||||
#include "cstoper.h"
|
||||
#include "error.h"
|
||||
#include "expr_loc.h"
|
||||
#include "struct_loc.h"
|
||||
#include "fltcstoper.h"
|
||||
|
||||
#include <symbol2str.h>
|
||||
|
||||
extern char options[];
|
||||
|
||||
static void pntminuspnt(struct expr **expp, int oper, struct expr *expr);
|
||||
static int arg_switched(int oper);
|
||||
static void mk_binop(struct expr **expp, int oper, struct expr *expr, int commutative);
|
||||
static void pointer_arithmetic(struct expr **expp1, int oper, struct expr **expp2);
|
||||
static void pointer_binary(struct expr **expp, int oper, struct expr *expr);
|
||||
extern char *symbol2str();
|
||||
|
||||
/* This chapter asks for the repeated application of code to handle
|
||||
an operation that may be executed at compile time or at run time,
|
||||
@ -50,7 +35,9 @@ static void pointer_binary(struct expr **expp, int oper, struct expr *expr);
|
||||
#define commutative_binop(expp, oper, expr) mk_binop(expp, oper, expr, 1)
|
||||
#define non_commutative_relop(expp, oper, expr) mk_binop(expp, oper, expr, 1)
|
||||
|
||||
void ch3bin(struct expr **expp, int oper, struct expr *expr)
|
||||
ch3bin(expp, oper, expr)
|
||||
register struct expr **expp;
|
||||
struct expr *expr;
|
||||
{
|
||||
/* apply binary operator oper between *expp and expr.
|
||||
NB: don't swap operands if op is one of the op= operators!!!
|
||||
@ -308,7 +295,8 @@ void ch3bin(struct expr **expp, int oper, struct expr *expr)
|
||||
}
|
||||
}
|
||||
|
||||
static void pntminuspnt(struct expr **expp, int oper, struct expr *expr)
|
||||
pntminuspnt(expp, oper, expr)
|
||||
register struct expr **expp, *expr;
|
||||
{
|
||||
/* Subtracting two pointers is so complicated it merits a
|
||||
routine of its own.
|
||||
@ -339,7 +327,8 @@ static void pntminuspnt(struct expr **expp, int oper, struct expr *expr)
|
||||
* when the arguments are switched. This is special for some relational
|
||||
* operators.
|
||||
*/
|
||||
static int arg_switched(int oper)
|
||||
int
|
||||
arg_switched(oper)
|
||||
{
|
||||
switch (oper) {
|
||||
case '<': return '>';
|
||||
@ -350,7 +339,9 @@ static int arg_switched(int oper)
|
||||
}
|
||||
}
|
||||
|
||||
static void mk_binop(struct expr **expp, int oper, struct expr *expr, int commutative)
|
||||
mk_binop(expp, oper, expr, commutative)
|
||||
struct expr **expp;
|
||||
register struct expr *expr;
|
||||
{
|
||||
/* Constructs in *expp the operation indicated by the operands.
|
||||
"commutative" indicates whether "oper" is a commutative
|
||||
@ -374,7 +365,8 @@ static void mk_binop(struct expr **expp, int oper, struct expr *expr, int commut
|
||||
}
|
||||
}
|
||||
|
||||
static void pointer_arithmetic(struct expr **expp1, int oper, struct expr **expp2)
|
||||
pointer_arithmetic(expp1, oper, expp2)
|
||||
register struct expr **expp1, **expp2;
|
||||
{
|
||||
int typ;
|
||||
/* prepares the integral expression expp2 in order to
|
||||
@ -394,7 +386,8 @@ static void pointer_arithmetic(struct expr **expp1, int oper, struct expr **expp
|
||||
);
|
||||
}
|
||||
|
||||
static void pointer_binary(struct expr **expp, int oper, struct expr *expr)
|
||||
pointer_binary(expp, oper, expr)
|
||||
register struct expr **expp, *expr;
|
||||
{
|
||||
/* constructs the pointer arithmetic expression out of
|
||||
a pointer expression, a binary operator and an integral
|
||||
|
||||
@ -1,11 +0,0 @@
|
||||
/*
|
||||
* The Amsterdam Compiler Kit
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
|
||||
#ifndef LANG_CEM_CEMCOM_ANSI_CH3BIN_H
|
||||
#define LANG_CEM_CEMCOM_ANSI_CH3BIN_H
|
||||
|
||||
void ch3bin(struct expr **expp, int oper, struct expr *expr);
|
||||
|
||||
#endif
|
||||
@ -18,22 +18,13 @@
|
||||
#include "idf.h"
|
||||
#include "def.h"
|
||||
#include "sizes.h"
|
||||
#include "ch3.h"
|
||||
#include "ch3mon.h"
|
||||
#include "error.h"
|
||||
#include "expr_loc.h"
|
||||
#include "stab.h"
|
||||
#include "util.h"
|
||||
#include "struct_loc.h"
|
||||
#include "dataflow.h"
|
||||
|
||||
#include <symbol2str.h>
|
||||
|
||||
extern char options[];
|
||||
extern arith full_mask[/*MAXSIZE + 1*/]; /* cstoper.c */
|
||||
char *symbol2str();
|
||||
|
||||
|
||||
void ch3mon(int oper, struct expr **expp)
|
||||
ch3mon(oper, expp)
|
||||
register struct expr **expp;
|
||||
{
|
||||
/* The monadic prefix operator oper is applied to *expp.
|
||||
*/
|
||||
|
||||
@ -1,11 +0,0 @@
|
||||
/*
|
||||
* The Amsterdam Compiler Kit
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
|
||||
#ifndef LANG_CEM_CEMCOM_ANSI_CH3MON_H
|
||||
#define LANG_CEM_CEMCOM_ANSI_CH3MON_H
|
||||
|
||||
void ch3mon(int oper, struct expr **expp);
|
||||
|
||||
#endif
|
||||
@ -40,21 +40,6 @@
|
||||
#include "assert.h"
|
||||
#include "LLlex.h"
|
||||
#include "align.h"
|
||||
#include "blocks.h"
|
||||
#include "code_c.h"
|
||||
#include "conversion.h"
|
||||
#include "util_loc.h"
|
||||
#include "stab.h"
|
||||
#include "error.h"
|
||||
#include "struct_loc.h"
|
||||
#include "ch3.h"
|
||||
#include "idf_loc.h"
|
||||
#include "expr_loc.h"
|
||||
#include "ival.h"
|
||||
#include "eval.h"
|
||||
|
||||
#include <symbol2str.h>
|
||||
|
||||
#ifdef LINT
|
||||
#include "l_lint.h"
|
||||
#endif /* LINT */
|
||||
@ -66,6 +51,7 @@ label lab_count = 1;
|
||||
label datlab_count = 1;
|
||||
|
||||
int fp_used;
|
||||
extern arith NewLocal(); /* util.c */
|
||||
|
||||
/* global function info */
|
||||
char *func_name;
|
||||
@ -80,14 +66,12 @@ static int pro_id;
|
||||
#endif /* USE_TMP */
|
||||
|
||||
extern char options[];
|
||||
extern char *symbol2str();
|
||||
extern char *source;
|
||||
|
||||
static void def_strings(struct string_cst *sc);
|
||||
static void prc_entry(char *name);
|
||||
static void prc_exit();
|
||||
|
||||
#ifndef LINT
|
||||
void init_code(char *dst_file)
|
||||
init_code(dst_file)
|
||||
char *dst_file;
|
||||
{
|
||||
/* init_code() initialises the output file on which the
|
||||
compact EM code is written
|
||||
@ -124,7 +108,10 @@ void init_code(char *dst_file)
|
||||
|
||||
struct string_cst *str_list = 0;
|
||||
|
||||
label code_string(char *val, int len)
|
||||
label
|
||||
code_string(val, len)
|
||||
char *val;
|
||||
int len;
|
||||
{
|
||||
register struct string_cst *sc = new_string_cst();
|
||||
label dlb = data_label();
|
||||
@ -138,7 +125,8 @@ label code_string(char *val, int len)
|
||||
return dlb;
|
||||
}
|
||||
|
||||
static void def_strings(struct string_cst *sc)
|
||||
def_strings(sc)
|
||||
register struct string_cst *sc;
|
||||
{
|
||||
while (sc) {
|
||||
struct string_cst *sc1 = sc;
|
||||
@ -152,8 +140,7 @@ static void def_strings(struct string_cst *sc)
|
||||
}
|
||||
|
||||
/* flush_strings() is called from program.g after each external definition */
|
||||
void flush_strings()
|
||||
{
|
||||
flush_strings() {
|
||||
if (str_list) {
|
||||
def_strings(str_list);
|
||||
str_list = 0;
|
||||
@ -161,7 +148,7 @@ void flush_strings()
|
||||
}
|
||||
|
||||
#ifndef LINT
|
||||
void end_code()
|
||||
end_code()
|
||||
{
|
||||
/* end_code() performs the actions to be taken when closing
|
||||
the output stream.
|
||||
@ -176,19 +163,19 @@ void end_code()
|
||||
#endif /* LINT */
|
||||
|
||||
#ifdef PREPEND_SCOPES
|
||||
void prepend_scopes()
|
||||
prepend_scopes()
|
||||
{
|
||||
/* prepend_scopes() runs down the list of global idf's
|
||||
and generates those exa's, exp's, ina's and inp's
|
||||
that superior hindsight has provided.
|
||||
*/
|
||||
struct stack_entry *se = local_level->sl_entry;
|
||||
register struct stack_entry *se = local_level->sl_entry;
|
||||
|
||||
#ifdef USE_TMP
|
||||
C_beginpart(tmp_id);
|
||||
#endif /* USE_TMP */
|
||||
while (se != 0) {
|
||||
struct def *df = se->se_idf->id_def;
|
||||
register struct def *df = se->se_idf->id_def;
|
||||
|
||||
if (df && (df->df_initialized || df->df_used || df->df_alloc)) {
|
||||
code_scope(se->se_idf->id_text, df);
|
||||
@ -201,7 +188,9 @@ void prepend_scopes()
|
||||
}
|
||||
#endif /* PREPEND_SCOPES */
|
||||
|
||||
void code_scope(char *text, struct def *def)
|
||||
code_scope(text, def)
|
||||
char *text;
|
||||
register struct def *def;
|
||||
{
|
||||
/* generates code for one name, text, of the storage class
|
||||
as given by def, if meaningful.
|
||||
@ -232,8 +221,9 @@ static int struct_return;
|
||||
static char *last_fn_given = (char *)0;
|
||||
static label file_name_label;
|
||||
|
||||
/* to be called when entering a procedure */
|
||||
void begin_proc(struct decspecs *ds, struct idf *idf)
|
||||
begin_proc(ds, idf) /* to be called when entering a procedure */
|
||||
struct decspecs *ds;
|
||||
struct idf *idf;
|
||||
{
|
||||
/* begin_proc() is called at the entrance of a new function
|
||||
and performs the necessary code generation:
|
||||
@ -243,8 +233,8 @@ void begin_proc(struct decspecs *ds, struct idf *idf)
|
||||
does not fit in the return area
|
||||
- a fil pseudo instruction
|
||||
*/
|
||||
char *name = idf->id_text;
|
||||
struct def *def = idf->id_def;
|
||||
register char *name = idf->id_text;
|
||||
register struct def *def = idf->id_def;
|
||||
|
||||
/* idf->id_def does not indicate the right def structure
|
||||
* when the function being defined has a parameter of the
|
||||
@ -330,7 +320,8 @@ void begin_proc(struct decspecs *ds, struct idf *idf)
|
||||
#endif
|
||||
}
|
||||
|
||||
void end_proc(arith fbytes)
|
||||
end_proc(fbytes)
|
||||
arith fbytes;
|
||||
{
|
||||
/* end_proc() deals with the code to be generated at the end of
|
||||
a function, as there is:
|
||||
@ -400,7 +391,7 @@ void end_proc(arith fbytes)
|
||||
options['n'] = optionsn;
|
||||
}
|
||||
|
||||
void do_return()
|
||||
do_return()
|
||||
{
|
||||
/* do_return handles the case of a return without expression.
|
||||
This version branches to the return label, which is
|
||||
@ -413,7 +404,8 @@ void do_return()
|
||||
C_bra(return2_label);
|
||||
}
|
||||
|
||||
void do_return_expr(struct expr *expr)
|
||||
do_return_expr(expr)
|
||||
struct expr *expr;
|
||||
{
|
||||
/* do_return_expr() generates the expression and the jump for
|
||||
a return statement with an expression.
|
||||
@ -428,12 +420,11 @@ void do_return_expr(struct expr *expr)
|
||||
return_expr_occurred = 1;
|
||||
}
|
||||
|
||||
/* struct idf *idf idf to be declared
|
||||
* struct expr *expr initialisation; NULL if absent
|
||||
* int lvl declaration level
|
||||
* int sc storage class, as in the declaration
|
||||
*/
|
||||
void code_declaration(struct idf *idf, struct expr *expr, int lvl, int sc)
|
||||
code_declaration(idf, expr, lvl, sc)
|
||||
register struct idf *idf; /* idf to be declared */
|
||||
struct expr *expr; /* initialisation; NULL if absent */
|
||||
int lvl; /* declaration level */
|
||||
int sc; /* storage class, as in the declaration */
|
||||
{
|
||||
/* code_declaration() does the actual declaration of the
|
||||
variable indicated by "idf" on declaration level "lvl".
|
||||
@ -454,8 +445,8 @@ void code_declaration(struct idf *idf, struct expr *expr, int lvl, int sc)
|
||||
The sc is the actual storage class, as given in the
|
||||
declaration.
|
||||
*/
|
||||
struct def *def = idf->id_def;
|
||||
arith size = def->df_type->tp_size;
|
||||
register struct def *def = idf->id_def;
|
||||
register arith size = def->df_type->tp_size;
|
||||
int fund = def->df_type->tp_fund;
|
||||
int def_sc = def->df_sc;
|
||||
|
||||
@ -541,15 +532,17 @@ void code_declaration(struct idf *idf, struct expr *expr, int lvl, int sc)
|
||||
}
|
||||
}
|
||||
|
||||
void loc_init(struct expr *expr, struct idf *id)
|
||||
loc_init(expr, id)
|
||||
struct expr *expr;
|
||||
struct idf *id;
|
||||
{
|
||||
/* loc_init() generates code for the assignment of
|
||||
expression expr to the local variable described by id.
|
||||
It frees the expression afterwards.
|
||||
*/
|
||||
struct expr *e = expr;
|
||||
struct def *df = id->id_def;
|
||||
struct type *tp = df->df_type;
|
||||
register struct expr *e = expr;
|
||||
register struct def *df = id->id_def;
|
||||
register struct type *tp = df->df_type;
|
||||
static arith tmpoffset = 0;
|
||||
static arith unknownsize = 0;
|
||||
|
||||
@ -617,11 +610,12 @@ void loc_init(struct expr *expr, struct idf *id)
|
||||
}
|
||||
}
|
||||
|
||||
void bss(struct idf *idf)
|
||||
bss(idf)
|
||||
register struct idf *idf;
|
||||
{
|
||||
/* bss() allocates bss space for the global idf.
|
||||
*/
|
||||
struct def *df = idf->id_def;
|
||||
register struct def *df = idf->id_def;
|
||||
|
||||
#ifndef PREPEND_SCOPES
|
||||
code_scope(idf->id_text, df);
|
||||
@ -647,13 +641,15 @@ void bss(struct idf *idf)
|
||||
}
|
||||
}
|
||||
|
||||
void formal_cvt(int hasproto, struct def *df)
|
||||
formal_cvt(hasproto,df)
|
||||
int hasproto;
|
||||
register struct def *df;
|
||||
{
|
||||
/* formal_cvt() converts a formal parameter of type char or
|
||||
short from int to that type. It also converts a formal
|
||||
parameter of type float from a double to a float.
|
||||
*/
|
||||
struct type *tp = df->df_type;
|
||||
register struct type *tp = df->df_type;
|
||||
|
||||
if (tp->tp_size != int_size &&
|
||||
(tp->tp_fund == CHAR || tp->tp_fund == SHORT)
|
||||
@ -677,7 +673,9 @@ void formal_cvt(int hasproto, struct def *df)
|
||||
#ifdef LINT
|
||||
/*ARGSUSED*/
|
||||
#endif /* LINT */
|
||||
void code_expr(struct expr *expr, int val, int code, label tlbl, label flbl)
|
||||
code_expr(expr, val, code, tlbl, flbl)
|
||||
struct expr *expr;
|
||||
label tlbl, flbl;
|
||||
{
|
||||
/* code_expr() is the parser's interface to the expression code
|
||||
generator. If line number trace is wanted, it generates a
|
||||
@ -710,9 +708,9 @@ static struct stmt_block *stmt_stack; /* top of statement stack */
|
||||
which are the only ones that are stacked, only the top of
|
||||
the stack is interesting.
|
||||
*/
|
||||
void code_break()
|
||||
code_break()
|
||||
{
|
||||
struct stmt_block *stmt_block = stmt_stack;
|
||||
register struct stmt_block *stmt_block = stmt_stack;
|
||||
|
||||
#ifdef DBSYMTAB
|
||||
if (options['g']) db_line(dot.tk_file, dot.tk_line);
|
||||
@ -728,9 +726,9 @@ void code_break()
|
||||
it generates a branch instruction to the continue label of the
|
||||
innermost statement in which continue has a meaning.
|
||||
*/
|
||||
void code_continue()
|
||||
code_continue()
|
||||
{
|
||||
struct stmt_block *stmt_block = stmt_stack;
|
||||
register struct stmt_block *stmt_block = stmt_stack;
|
||||
|
||||
while (stmt_block) {
|
||||
if (stmt_block->st_continue) {
|
||||
@ -745,9 +743,10 @@ void code_continue()
|
||||
error("continue not inside for, while or do");
|
||||
}
|
||||
|
||||
void stack_stmt(label break_label, label cont_label)
|
||||
stack_stmt(break_label, cont_label)
|
||||
label break_label, cont_label;
|
||||
{
|
||||
struct stmt_block *stmt_block = new_stmt_block();
|
||||
register struct stmt_block *stmt_block = new_stmt_block();
|
||||
|
||||
stmt_block->next = stmt_stack;
|
||||
stmt_block->st_break = break_label;
|
||||
@ -755,7 +754,7 @@ void stack_stmt(label break_label, label cont_label)
|
||||
stmt_stack = stmt_block;
|
||||
}
|
||||
|
||||
void unstack_stmt()
|
||||
unstack_stmt()
|
||||
{
|
||||
/* unstack_stmt() unstacks the data of a statement
|
||||
which may contain break or continue
|
||||
@ -767,7 +766,8 @@ void unstack_stmt()
|
||||
|
||||
static label prc_name;
|
||||
|
||||
static void prc_entry(char *name)
|
||||
prc_entry(name)
|
||||
char *name;
|
||||
{
|
||||
if (options['p']) {
|
||||
C_df_dlb(prc_name = data_label());
|
||||
@ -778,7 +778,7 @@ static void prc_entry(char *name)
|
||||
}
|
||||
}
|
||||
|
||||
static void prc_exit()
|
||||
prc_exit()
|
||||
{
|
||||
if (options['p']) {
|
||||
C_lae_dlb(prc_name, (arith) 0);
|
||||
@ -788,7 +788,9 @@ static void prc_exit()
|
||||
}
|
||||
|
||||
#ifdef DBSYMTAB
|
||||
void db_line(char *file, unsigned int line)
|
||||
db_line(file, line)
|
||||
char *file;
|
||||
unsigned int line;
|
||||
{
|
||||
static unsigned oldline;
|
||||
static char *oldfile;
|
||||
|
||||
@ -1,42 +0,0 @@
|
||||
/*
|
||||
* The Amsterdam Compiler Kit
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
#ifndef LANG_CEM_CEMCOM_ANSI_CODE_H
|
||||
#define LANG_CEM_CEMCOM_ANSI_CODE_H
|
||||
|
||||
struct decspecs;
|
||||
|
||||
void init_code(char *dst_file);
|
||||
label code_string(char *val, int len);
|
||||
void flush_strings();
|
||||
void code_scope(char *text, struct def *def);
|
||||
void begin_proc(struct decspecs *ds, struct idf *idf);
|
||||
void end_proc(arith fbytes);
|
||||
void do_return();
|
||||
void do_return_expr(struct expr *expr);
|
||||
void code_declaration(struct idf *idf, struct expr *expr, int lvl, int sc);
|
||||
void loc_init(struct expr *expr, struct idf *id);
|
||||
void bss(struct idf *idf);
|
||||
void code_expr(struct expr *expr, int val, int code, label tlbl, label flbl);
|
||||
void code_break();
|
||||
void code_continue();
|
||||
void stack_stmt(label break_label, label cont_label);
|
||||
void unstack_stmt();
|
||||
void formal_cvt(int hasproto, struct def *df);
|
||||
|
||||
|
||||
|
||||
#ifdef DBSYMTAB
|
||||
void db_line(char *file, unsigned int line);
|
||||
#endif
|
||||
|
||||
#ifdef PREPEND_SCOPES
|
||||
void prepend_scopes();
|
||||
#endif
|
||||
|
||||
#ifndef LINT
|
||||
void end_code();
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -13,7 +13,6 @@
|
||||
#include "type.h"
|
||||
#include "sizes.h"
|
||||
#include "Lpars.h"
|
||||
#include "error.h"
|
||||
|
||||
#define T_SIGNED 1
|
||||
#define T_UNSIGNED 2
|
||||
@ -28,12 +27,13 @@
|
||||
C??
|
||||
*/
|
||||
|
||||
static int convtype(struct type *tp);
|
||||
static int convtype();
|
||||
|
||||
void conversion(struct type *from_type, struct type *to_type)
|
||||
conversion(from_type, to_type)
|
||||
register struct type *from_type, *to_type;
|
||||
{
|
||||
arith from_size = from_type->tp_size;
|
||||
arith to_size = to_type->tp_size;
|
||||
register arith from_size = from_type->tp_size;
|
||||
register arith to_size = to_type->tp_size;
|
||||
int from_cnvtype = convtype(from_type);
|
||||
int to_cnvtype = convtype(to_type);
|
||||
|
||||
@ -126,7 +126,9 @@ void conversion(struct type *from_type, struct type *to_type)
|
||||
/* convtype() returns in which category a given type falls:
|
||||
signed, unsigned or floating
|
||||
*/
|
||||
static int convtype(struct type *tp)
|
||||
static int
|
||||
convtype(tp)
|
||||
register struct type *tp;
|
||||
{
|
||||
switch (tp->tp_fund) {
|
||||
case CHAR:
|
||||
|
||||
@ -1,8 +0,0 @@
|
||||
#ifndef LANG_CEM_CEMCOM_ANSI_CONVERSION_H
|
||||
#define LANG_CEM_CEMCOM_ANSI_CONVERSION_H
|
||||
|
||||
struct type;
|
||||
|
||||
void conversion(struct type *from_type, struct type *to_type);
|
||||
|
||||
#endif
|
||||
@ -15,9 +15,6 @@
|
||||
#include "sizes.h"
|
||||
#include "Lpars.h"
|
||||
#include "assert.h"
|
||||
#include "cstoper.h"
|
||||
#include "error.h"
|
||||
#include "expr_loc.h"
|
||||
|
||||
/* full_mask[1] == 0XFF, full_mask[2] == 0XFFFF, .. */
|
||||
arith full_mask[MAXSIZE + 1];
|
||||
@ -27,14 +24,15 @@ arith max_unsigned; /* maximum unsigned on target machine */
|
||||
#endif /* NOCROSS */
|
||||
extern int ResultKnown;
|
||||
|
||||
void cstbin(struct expr **expp, int oper, struct expr *expr)
|
||||
cstbin(expp, oper, expr)
|
||||
register struct expr **expp, *expr;
|
||||
{
|
||||
/* The operation oper is performed on the constant
|
||||
expressions *expp(ld) and expr(ct), and the result restored in
|
||||
*expp.
|
||||
*/
|
||||
arith o1 = (*expp)->VL_VALUE;
|
||||
arith o2 = expr->VL_VALUE;
|
||||
register arith o1 = (*expp)->VL_VALUE;
|
||||
register arith o2 = expr->VL_VALUE;
|
||||
int uns = (*expp)->ex_type->tp_unsigned;
|
||||
|
||||
ASSERT(is_ld_cst(*expp) && is_cp_cst(expr));
|
||||
@ -207,12 +205,13 @@ void cstbin(struct expr **expp, int oper, struct expr *expr)
|
||||
free_expression(expr);
|
||||
}
|
||||
|
||||
void cut_size(struct expr *expr)
|
||||
cut_size(expr)
|
||||
register struct expr *expr;
|
||||
{
|
||||
/* The constant value of the expression expr is made to
|
||||
conform to the size of the type of the expression.
|
||||
*/
|
||||
arith o1 = expr->VL_VALUE;
|
||||
register arith o1 = expr->VL_VALUE;
|
||||
int uns = expr->ex_type->tp_unsigned;
|
||||
int size = (int) expr->ex_type->tp_size;
|
||||
|
||||
@ -242,10 +241,10 @@ void cut_size(struct expr *expr)
|
||||
expr->VL_VALUE = o1;
|
||||
}
|
||||
|
||||
void init_cst()
|
||||
init_cst()
|
||||
{
|
||||
int i = 0;
|
||||
arith bt = (arith)0;
|
||||
register int i = 0;
|
||||
register arith bt = (arith)0;
|
||||
|
||||
while (!(bt < 0)) {
|
||||
bt = (bt << 8) + 0377, i++;
|
||||
|
||||
@ -1,8 +0,0 @@
|
||||
#ifndef LANG_CEM_CEMCOM_ANSI_CSTOPER_H
|
||||
#define LANG_CEM_CEMCOM_ANSI_CSTOPER_H
|
||||
|
||||
void cstbin(struct expr **expp, int oper, struct expr *expr);
|
||||
void cut_size(struct expr *expr);
|
||||
void init_cst();
|
||||
|
||||
#endif
|
||||
@ -1,11 +0,0 @@
|
||||
/*
|
||||
* The Amsterdam Compiler Kit
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
#ifndef LANG_CEM_CEMCOM_ANSI_DATAFLOW_H
|
||||
#define LANG_CEM_CEMCOM_ANSI_DATAFLOW_H
|
||||
|
||||
/* lang/cem/cemcom.ansi/dataflow.c */
|
||||
|
||||
#endif /* LANG_CEM_CEMCOM_ANSI_DATAFLOW_H */
|
||||
|
||||
@ -17,27 +17,17 @@
|
||||
#include "label.h"
|
||||
#include "code.h"
|
||||
#include "idf.h"
|
||||
#include "idf_loc.h"
|
||||
#include "type.h"
|
||||
#include "type_loc.h"
|
||||
#include "proto.h"
|
||||
#include "proto_loc.h"
|
||||
#include "struct.h"
|
||||
#include "struct_loc.h"
|
||||
#include "field.h"
|
||||
#include "decspecs.h"
|
||||
#include "def.h"
|
||||
#include "declar.h"
|
||||
#include "label.h"
|
||||
#include "expr.h"
|
||||
#include "expr_loc.h"
|
||||
#include "sizes.h"
|
||||
#include "level.h"
|
||||
#include "code_c.h"
|
||||
#include "error.h"
|
||||
#include "stab.h"
|
||||
#include "declarator.h"
|
||||
|
||||
#ifdef LINT
|
||||
#include "l_lint.h"
|
||||
#endif /* LINT */
|
||||
@ -722,7 +712,7 @@ parameter_declarator(register struct declarator *dc;)
|
||||
|
||||
primary_parameter_declarator(register struct declarator *dc;)
|
||||
:
|
||||
[%if ((AHEAD == ')' || first_of_parameter_type_list(AHEAD))
|
||||
[%if (AHEAD == ')' || first_of_parameter_type_list(AHEAD)
|
||||
&& (AHEAD != IDENTIFIER))
|
||||
/* empty */
|
||||
|
|
||||
|
||||
@ -4,8 +4,6 @@
|
||||
*/
|
||||
/* $Id$ */
|
||||
/* DEFINITION OF DECLARATOR DESCRIPTORS */
|
||||
#ifndef LANG_CEM_CEMCOM_ANSI_DECLARE_STR
|
||||
#define LANG_CEM_CEMCOM_ANSI_DECLARE_STR
|
||||
|
||||
/* A 'declarator' consists of an idf and a linked list of
|
||||
language-defined unary operations: *, [] and (), called
|
||||
@ -41,5 +39,3 @@ struct decl_unary {
|
||||
|
||||
extern struct type *declare_type();
|
||||
extern struct declarator null_declarator;
|
||||
|
||||
#endif /* LANG_CEM_CEMCOM_ANSI_DECLARE_STR */
|
||||
|
||||
@ -20,14 +20,14 @@
|
||||
#include "expr.h"
|
||||
#include "sizes.h"
|
||||
#include "level.h"
|
||||
#include "error.h"
|
||||
#include "idf_loc.h"
|
||||
#include "proto_loc.h"
|
||||
|
||||
extern char options[];
|
||||
struct declarator null_declarator;
|
||||
|
||||
struct type *declare_type(struct type *tp, struct declarator *dc)
|
||||
struct type *
|
||||
declare_type(tp, dc)
|
||||
struct type *tp;
|
||||
struct declarator *dc;
|
||||
{
|
||||
/* Applies the decl_unary list starting at dc->dc_decl_unary
|
||||
to the type tp and returns the result.
|
||||
@ -35,7 +35,7 @@ struct type *declare_type(struct type *tp, struct declarator *dc)
|
||||
are purely prototypes. Simply add the type list to the
|
||||
function node.
|
||||
*/
|
||||
struct decl_unary *du = dc->dc_decl_unary;
|
||||
register struct decl_unary *du = dc->dc_decl_unary;
|
||||
|
||||
while (du) {
|
||||
tp = construct_type(du->du_fund, tp, du->du_typequal,
|
||||
@ -45,13 +45,18 @@ struct type *declare_type(struct type *tp, struct declarator *dc)
|
||||
return tp;
|
||||
}
|
||||
|
||||
void add_decl_unary(struct declarator *dc, int fund, int qual, arith count, struct formal *fm, struct proto *pl)
|
||||
add_decl_unary(dc, fund, qual, count, fm, pl)
|
||||
register struct declarator *dc;
|
||||
int qual;
|
||||
arith count;
|
||||
struct formal *fm;
|
||||
struct proto *pl;
|
||||
{
|
||||
/* A decl_unary describing a constructor with fundamental
|
||||
type fund and with size count is inserted in front of the
|
||||
declarator dc.
|
||||
*/
|
||||
struct decl_unary *new = new_decl_unary();
|
||||
register struct decl_unary *new = new_decl_unary();
|
||||
|
||||
new->next = dc->dc_decl_unary;
|
||||
new->du_fund = fund;
|
||||
@ -72,12 +77,13 @@ void add_decl_unary(struct declarator *dc, int fund, int qual, arith count, stru
|
||||
dc->dc_decl_unary = new;
|
||||
}
|
||||
|
||||
void remove_declarator(struct declarator *dc)
|
||||
remove_declarator(dc)
|
||||
struct declarator *dc;
|
||||
{
|
||||
/* The decl_unary list starting at dc->dc_decl_unary is
|
||||
removed.
|
||||
*/
|
||||
struct decl_unary *du = dc->dc_decl_unary;
|
||||
register struct decl_unary *du = dc->dc_decl_unary;
|
||||
|
||||
while (du) {
|
||||
struct decl_unary *old_du = du;
|
||||
@ -87,14 +93,15 @@ void remove_declarator(struct declarator *dc)
|
||||
}
|
||||
}
|
||||
|
||||
void reject_params(struct declarator *dc)
|
||||
reject_params(dc)
|
||||
register struct declarator *dc;
|
||||
{
|
||||
/* The declarator is checked to have no parameters, if it
|
||||
is an old-style function. If it is a new-style function,
|
||||
the identifiers are removed. The function is not called in
|
||||
case of a function definition.
|
||||
*/
|
||||
struct decl_unary *du = dc->dc_decl_unary;
|
||||
register struct decl_unary *du = dc->dc_decl_unary;
|
||||
int err_given = 0;
|
||||
|
||||
if (dc->dc_formal) {
|
||||
@ -115,7 +122,8 @@ void reject_params(struct declarator *dc)
|
||||
}
|
||||
}
|
||||
|
||||
void check_array_subscript(struct expr *expr)
|
||||
check_array_subscript(expr)
|
||||
register struct expr *expr;
|
||||
{
|
||||
arith size = expr->VL_VALUE;
|
||||
|
||||
|
||||
@ -1,16 +0,0 @@
|
||||
/*
|
||||
* The Amsterdam Compiler Kit
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
#ifndef LANG_CEM_CEMCOM_ANSI_DECLARATOR_H
|
||||
#define LANG_CEM_CEMCOM_ANSI_DECLARATOR_H
|
||||
|
||||
/* lang/cem/cemcom.ansi/declarator.c */
|
||||
struct type *declare_type(struct type *tp, struct declarator *dc);
|
||||
void add_decl_unary(struct declarator *dc, int fund, int qual, arith count, struct formal *fm, struct proto *pl);
|
||||
void remove_declarator(struct declarator *dc);
|
||||
void reject_params(struct declarator *dc);
|
||||
void check_array_subscript(struct expr *expr);
|
||||
|
||||
#endif /* LANG_CEM_CEMCOM_ANSI_DECLARATOR_H */
|
||||
|
||||
@ -12,21 +12,21 @@
|
||||
#include "type.h"
|
||||
#include "level.h"
|
||||
#include "def.h"
|
||||
#include "error.h"
|
||||
|
||||
#include <symbol2str.h>
|
||||
|
||||
extern char options[];
|
||||
extern int level;
|
||||
extern char *symbol2str();
|
||||
extern struct type *qualifier_type();
|
||||
|
||||
struct decspecs null_decspecs;
|
||||
|
||||
void do_decspecs(struct decspecs *ds)
|
||||
do_decspecs(ds)
|
||||
register struct decspecs *ds;
|
||||
{
|
||||
/* The provisional decspecs ds as obtained from the program
|
||||
is turned into a legal consistent decspecs.
|
||||
*/
|
||||
struct type *tp = ds->ds_type;
|
||||
register struct type *tp = ds->ds_type;
|
||||
|
||||
ASSERT(level != L_FORMAL1);
|
||||
|
||||
@ -67,7 +67,7 @@ void do_decspecs(struct decspecs *ds)
|
||||
tp = int_type;
|
||||
}
|
||||
if (ds->ds_size) {
|
||||
int ds_isshort = (ds->ds_size == SHORT);
|
||||
register int ds_isshort = (ds->ds_size == SHORT);
|
||||
|
||||
if (ds->ds_typedef) goto SIZE_ERROR; /* yes */
|
||||
if (tp == int_type) {
|
||||
@ -82,7 +82,7 @@ void do_decspecs(struct decspecs *ds)
|
||||
ds->ds_notypegiven = 0;
|
||||
}
|
||||
if (ds->ds_unsigned) {
|
||||
int ds_isunsigned = (ds->ds_unsigned == UNSIGNED);
|
||||
register int ds_isunsigned = (ds->ds_unsigned == UNSIGNED);
|
||||
|
||||
if (ds->ds_typedef) goto SIGN_ERROR; /* yes */
|
||||
/*
|
||||
@ -113,10 +113,13 @@ void do_decspecs(struct decspecs *ds)
|
||||
In case of a complex type the top of the type list will be
|
||||
replaced by a qualified version.
|
||||
*/
|
||||
struct type *qualifier_type(struct type *tp, int typequal)
|
||||
struct type *
|
||||
qualifier_type(tp, typequal)
|
||||
register struct type *tp;
|
||||
int typequal;
|
||||
{
|
||||
struct type *dtp = tp;
|
||||
int fund = tp->tp_fund;
|
||||
register struct type *dtp = tp;
|
||||
register int fund = tp->tp_fund;
|
||||
|
||||
while (dtp && dtp->tp_typequal != typequal)
|
||||
dtp = dtp->next;
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
#ifndef LANG_CEM_CEMCOM_ANSI_DECSPECS_H
|
||||
#define LANG_CEM_CEMCOM_ANSI_DECSPECS_H
|
||||
/*
|
||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
@ -19,11 +17,5 @@ struct decspecs {
|
||||
int ds_typequal; /* type qualifiers - see type.str */
|
||||
};
|
||||
|
||||
extern struct type *qualifier_type();
|
||||
extern struct decspecs null_decspecs;
|
||||
|
||||
/* lang/cem/cemcom.ansi/decspecs.c */
|
||||
void do_decspecs(struct decspecs *ds);
|
||||
struct type *qualifier_type(struct type *tp, int typequal);
|
||||
|
||||
#endif /* LANG_CEM_CEMCOM_ANSI_DECSPECS_H */
|
||||
|
||||
|
||||
@ -4,8 +4,6 @@
|
||||
*/
|
||||
/* $Id$ */
|
||||
/* IDENTIFIER DEFINITION DESCRIPTOR */
|
||||
#ifndef LANG_CEM_CEMCOM_ANSI_DEF_STR
|
||||
#define LANG_CEM_CEMCOM_ANSI_DEF_STR
|
||||
|
||||
#include "lint.h"
|
||||
|
||||
@ -40,6 +38,3 @@ struct def { /* for ordinary tags */
|
||||
#define REG_BONUS 10 /* register candidate, declared as such */
|
||||
|
||||
/* ALLOCDEF "def" 50 */
|
||||
|
||||
|
||||
#endif /* LANG_CEM_CEMCOM_ANSI_DEF_STR */
|
||||
@ -5,11 +5,7 @@
|
||||
/* $Id$ */
|
||||
/* PREPROCESSOR: CONTROLLINE INTERPRETER */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "debug.h"
|
||||
#include "specials.h"
|
||||
#include "arith.h"
|
||||
#include "LLlex.h"
|
||||
#include "Lpars.h"
|
||||
@ -17,13 +13,6 @@
|
||||
#include "input.h"
|
||||
#include "nopp.h"
|
||||
#include "lint.h"
|
||||
#include "skip.h"
|
||||
#include "domacro.h"
|
||||
#include "error.h"
|
||||
#include "pragma.h"
|
||||
#include "program.h"
|
||||
#include "main.h"
|
||||
#include "replace_loc.h"
|
||||
|
||||
#ifndef NOPP
|
||||
#include "ifdepth.h"
|
||||
@ -47,15 +36,16 @@ int IncludeLevel = 0;
|
||||
|
||||
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. */
|
||||
|
||||
int nestlevel = -1;
|
||||
extern char *getwdir();
|
||||
|
||||
/* skiponerr -> skip the rest of the line on error */
|
||||
struct idf *GetIdentifier(int skiponerr)
|
||||
struct idf *
|
||||
GetIdentifier(skiponerr)
|
||||
int skiponerr; /* skip the rest of the line on error */
|
||||
{
|
||||
/* returns a pointer to the descriptor of the identifier that is
|
||||
read from the input stream. When the input doe not contain
|
||||
@ -86,7 +76,7 @@ struct idf *GetIdentifier(int skiponerr)
|
||||
An error message is produced when the token is not recognized,
|
||||
i.e. it is not one of "define" .. "undef" , integer or newline.
|
||||
*/
|
||||
void domacro()
|
||||
domacro()
|
||||
{
|
||||
struct token tk; /* the token itself */
|
||||
int toknum;
|
||||
@ -136,9 +126,6 @@ void domacro()
|
||||
case K_ERROR: /* "error" */
|
||||
do_error();
|
||||
break;
|
||||
case K_WARNING: /* "warning" */
|
||||
do_warning();
|
||||
break;
|
||||
case K_PRAGMA: /* "pragma" */
|
||||
do_pragma();
|
||||
break;
|
||||
@ -167,7 +154,8 @@ void domacro()
|
||||
int lint_skip_comment;
|
||||
#endif
|
||||
|
||||
void skip_block(int to_endif)
|
||||
skip_block(to_endif)
|
||||
int to_endif;
|
||||
{
|
||||
/* skip_block() skips the input from
|
||||
1) a false #if, #ifdef, #ifndef or #elif until the
|
||||
@ -177,8 +165,8 @@ void skip_block(int to_endif)
|
||||
#ifndef or #elif until the corresponding #endif is
|
||||
seen.
|
||||
*/
|
||||
int ch;
|
||||
int skiplevel = nestlevel; /* current nesting level */
|
||||
register int ch;
|
||||
register int skiplevel = nestlevel; /* current nesting level */
|
||||
struct token tk;
|
||||
int toknum;
|
||||
|
||||
@ -301,7 +289,7 @@ void skip_block(int to_endif)
|
||||
}
|
||||
|
||||
|
||||
int ifexpr()
|
||||
ifexpr()
|
||||
{
|
||||
/* ifexpr() returns whether the restricted constant
|
||||
expression following #if or #elif evaluates to true. This
|
||||
@ -323,7 +311,7 @@ int ifexpr()
|
||||
return (errors == err_occurred) && (ifval != (arith)0);
|
||||
}
|
||||
|
||||
void do_include()
|
||||
do_include()
|
||||
{
|
||||
/* do_include() performs the inclusion of a file.
|
||||
*/
|
||||
@ -368,7 +356,7 @@ void do_include()
|
||||
}
|
||||
}
|
||||
|
||||
void do_define()
|
||||
do_define()
|
||||
{
|
||||
/* do_define() interprets a #define control line.
|
||||
*/
|
||||
@ -407,7 +395,7 @@ void do_define()
|
||||
LineNumber++;
|
||||
}
|
||||
|
||||
void push_if()
|
||||
push_if()
|
||||
{
|
||||
if (nestlevel >= IFDEPTH)
|
||||
fatal("too many nested #if/#ifdef/#ifndef");
|
||||
@ -415,7 +403,7 @@ void push_if()
|
||||
ifstack[++nestlevel] = 0;
|
||||
}
|
||||
|
||||
void do_elif()
|
||||
do_elif()
|
||||
{
|
||||
if (nestlevel <= nestlow) {
|
||||
lexerror("#elif without corresponding #if");
|
||||
@ -432,7 +420,7 @@ void do_elif()
|
||||
}
|
||||
}
|
||||
|
||||
void do_else()
|
||||
do_else()
|
||||
{
|
||||
if (SkipToNewLine())
|
||||
if (!options['o'])
|
||||
@ -448,7 +436,7 @@ void do_else()
|
||||
}
|
||||
}
|
||||
|
||||
void do_endif()
|
||||
do_endif()
|
||||
{
|
||||
if (SkipToNewLine()) {
|
||||
if (!options['o'])
|
||||
@ -460,16 +448,16 @@ void do_endif()
|
||||
else nestlevel--;
|
||||
}
|
||||
|
||||
void do_if()
|
||||
do_if()
|
||||
{
|
||||
push_if();
|
||||
if (!ifexpr()) /* a false #if/#elif expression */
|
||||
skip_block(0);
|
||||
}
|
||||
|
||||
void do_ifdef(how)
|
||||
do_ifdef(how)
|
||||
{
|
||||
struct idf *id;
|
||||
register struct idf *id;
|
||||
|
||||
/* how == 1 : ifdef; how == 0 : ifndef
|
||||
*/
|
||||
@ -489,9 +477,10 @@ void do_ifdef(how)
|
||||
}
|
||||
|
||||
/* argidf != NULL when the undef came from a -U option */
|
||||
void do_undef(struct idf *argidf)
|
||||
do_undef(argidf)
|
||||
struct idf *argidf;
|
||||
{
|
||||
struct idf *id = argidf;
|
||||
register struct idf *id = argidf;
|
||||
|
||||
/* Forget a macro definition. */
|
||||
if (id || (id = GetIdentifier(1))) {
|
||||
@ -514,7 +503,7 @@ void do_undef(struct idf *argidf)
|
||||
lexerror("illegal #undef construction");
|
||||
}
|
||||
|
||||
void do_error()
|
||||
do_error()
|
||||
{
|
||||
int len;
|
||||
char *get_text();
|
||||
@ -525,18 +514,10 @@ void do_error()
|
||||
LineNumber++;
|
||||
}
|
||||
|
||||
void do_warning()
|
||||
{
|
||||
int len;
|
||||
char *get_text();
|
||||
char *bp = get_text((char **) 0, &len);
|
||||
|
||||
lexwarning("user warning: %s", bp);
|
||||
free(bp);
|
||||
LineNumber++;
|
||||
}
|
||||
|
||||
int getparams(char *buf[], char parbuf[])
|
||||
int
|
||||
getparams(buf, parbuf)
|
||||
char *buf[];
|
||||
char parbuf[];
|
||||
{
|
||||
/* getparams() reads the formal parameter list of a macro
|
||||
definition.
|
||||
@ -548,10 +529,10 @@ int getparams(char *buf[], char parbuf[])
|
||||
Note that the '(' has already been eaten.
|
||||
The names of the formal parameters are stored into parbuf.
|
||||
*/
|
||||
char **pbuf = &buf[0];
|
||||
int c;
|
||||
char *ptr = &parbuf[0];
|
||||
char **pbuf2;
|
||||
register char **pbuf = &buf[0];
|
||||
register int c;
|
||||
register char *ptr = &parbuf[0];
|
||||
register char **pbuf2;
|
||||
|
||||
c = GetChar();
|
||||
c = skipspaces(c,0);
|
||||
@ -602,9 +583,11 @@ int getparams(char *buf[], char parbuf[])
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
|
||||
void macro_def(struct idf *id, char *text, int nformals, int length, int flags)
|
||||
macro_def(id, text, nformals, length, flags)
|
||||
register struct idf *id;
|
||||
char *text;
|
||||
{
|
||||
struct macro *newdef = id->id_macro;
|
||||
register struct macro *newdef = id->id_macro;
|
||||
|
||||
/* macro_def() puts the contents and information of a macro
|
||||
definition into a structure and stores it into the symbol
|
||||
@ -626,13 +609,15 @@ void macro_def(struct idf *id, char *text, int nformals, int length, int flags)
|
||||
newdef->mc_flag = flags; /* special flags */
|
||||
}
|
||||
|
||||
int find_name(char *nm, char *index[])
|
||||
int
|
||||
find_name(nm, index)
|
||||
char *nm, *index[];
|
||||
{
|
||||
/* find_name() returns the index of "nm" in the namelist
|
||||
"index" if it can be found there. 0 is returned if it is
|
||||
not there.
|
||||
*/
|
||||
char **ip = &index[0];
|
||||
register char **ip = &index[0];
|
||||
|
||||
while (*ip)
|
||||
if (strcmp(nm, *ip++) == 0)
|
||||
@ -643,7 +628,10 @@ int find_name(char *nm, char *index[])
|
||||
|
||||
#define BLANK(ch) ((ch == ' ') || (ch == '\t'))
|
||||
|
||||
char *get_text(char *formals[], int *length)
|
||||
char *
|
||||
get_text(formals, length)
|
||||
char *formals[];
|
||||
int *length;
|
||||
{
|
||||
/* get_text() copies the replacement text of a macro
|
||||
definition with zero, one or more parameters, thereby
|
||||
@ -667,9 +655,9 @@ char *get_text(char *formals[], int *length)
|
||||
4- comment, same as for 1
|
||||
Other tokens will not be seen as such.
|
||||
*/
|
||||
int c;
|
||||
register int c;
|
||||
struct repl repls;
|
||||
struct repl *repl = &repls;
|
||||
register struct repl *repl = &repls;
|
||||
int blank = 0;
|
||||
|
||||
c = GetChar();
|
||||
@ -684,7 +672,7 @@ char *get_text(char *formals[], int *length)
|
||||
}
|
||||
|
||||
if (c == '\'' || c == '"') {
|
||||
int delim = c;
|
||||
register int delim = c;
|
||||
|
||||
if (blank) {
|
||||
blank = 0;
|
||||
@ -717,7 +705,7 @@ char *get_text(char *formals[], int *length)
|
||||
} else if (formals
|
||||
&& (class(c) == STIDF || class(c) == STELL)) {
|
||||
char id_buf[IDFSIZE + 1];
|
||||
char *idp = id_buf;
|
||||
register char *idp = id_buf;
|
||||
int n;
|
||||
|
||||
/* read identifier: it may be a formal parameter */
|
||||
@ -734,7 +722,7 @@ char *get_text(char *formals[], int *length)
|
||||
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;
|
||||
@ -783,7 +771,8 @@ char *get_text(char *formals[], int *length)
|
||||
as strings, without taking care of the leading and trailing
|
||||
blanks (spaces and tabs).
|
||||
*/
|
||||
int macroeq(char *s, char *t)
|
||||
macroeq(s, t)
|
||||
register char *s, *t;
|
||||
{
|
||||
|
||||
/* skip leading spaces */
|
||||
@ -806,8 +795,9 @@ int macroeq(char *s, char *t)
|
||||
}
|
||||
#else /* NOPP */
|
||||
|
||||
/* skiponerr -> skip the rest of the line on error */
|
||||
struct idf *GetIdentifier(int skiponerr)
|
||||
struct idf *
|
||||
GetIdentifier(skiponerr)
|
||||
int skiponerr; /* skip the rest of the line on error */
|
||||
{
|
||||
/* returns a pointer to the descriptor of the identifier that is
|
||||
read from the input stream. When the input does not contain
|
||||
@ -826,7 +816,7 @@ struct idf *GetIdentifier(int skiponerr)
|
||||
return tk.tk_idf;
|
||||
}
|
||||
|
||||
void domacro()
|
||||
domacro()
|
||||
{
|
||||
int tok;
|
||||
struct token tk;
|
||||
@ -850,7 +840,8 @@ void domacro()
|
||||
#endif /* NOPP */
|
||||
|
||||
|
||||
void do_line(unsigned int l)
|
||||
do_line(l)
|
||||
unsigned int l;
|
||||
{
|
||||
struct token tk;
|
||||
int t = GetToken(&tk);
|
||||
|
||||
@ -1,31 +0,0 @@
|
||||
/*
|
||||
* The Amsterdam Compiler Kit
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
#ifndef LANG_CEM_CEMCOM_ANSI_DOMACRO_H
|
||||
#define LANG_CEM_CEMCOM_ANSI_DOMACRO_H
|
||||
|
||||
/* lang/cem/cemcom.ansi/domacro.c */
|
||||
struct idf *GetIdentifier(int skiponerr);
|
||||
void domacro(void);
|
||||
void skip_block(int to_endif);
|
||||
int ifexpr(void);
|
||||
void do_include(void);
|
||||
void do_define(void);
|
||||
void push_if(void);
|
||||
void do_elif(void);
|
||||
void do_else(void);
|
||||
void do_endif(void);
|
||||
void do_if(void);
|
||||
void do_ifdef(int how);
|
||||
void do_undef(struct idf *argidf);
|
||||
void do_error(void);
|
||||
void do_warning(void);
|
||||
int getparams(char *buf[], char parbuf[]);
|
||||
void macro_def(struct idf *id, char *text, int nformals, int length, int flags);
|
||||
int find_name(char *nm, char *index[]);
|
||||
char *get_text(char *formals[], int *length);
|
||||
int macroeq(char *s, char *t);
|
||||
void do_line(unsigned int l);
|
||||
|
||||
#endif /* LANG_CEM_CEMCOM_ANSI_DOMACRO_H */
|
||||
@ -7,7 +7,6 @@
|
||||
|
||||
#include "lint.h"
|
||||
#if __STDC__
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#else
|
||||
#include <varargs.h>
|
||||
@ -23,7 +22,6 @@
|
||||
#include "lint.h"
|
||||
#include "nopp.h"
|
||||
#include "errout.h"
|
||||
#include "print.h"
|
||||
|
||||
#include "tokenname.h"
|
||||
#include <flt_arith.h>
|
||||
@ -32,13 +30,11 @@
|
||||
#include "expr.h"
|
||||
#include "def.h"
|
||||
#include "LLlex.h"
|
||||
#include "error.h"
|
||||
|
||||
/* This file contains the error-message and diagnostic
|
||||
functions. Beware, they are called with a variable number of
|
||||
arguments!
|
||||
*/
|
||||
static void _error(int class, char *fn, unsigned int ln, char *fmt, va_list ap);
|
||||
|
||||
/* error classes */
|
||||
#define STRICT 1
|
||||
@ -66,9 +62,11 @@ extern char loptions[];
|
||||
expression, whereas other errors use the information in the token.
|
||||
*/
|
||||
|
||||
static _error();
|
||||
|
||||
#if __STDC__
|
||||
/*VARARGS*/
|
||||
void error(char *fmt, ...)
|
||||
error(char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
@ -80,7 +78,7 @@ void error(char *fmt, ...)
|
||||
}
|
||||
|
||||
/*VARARGS*/
|
||||
void expr_error(struct expr *expr, char *fmt, ...)
|
||||
expr_error(struct expr *expr, char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
@ -96,7 +94,7 @@ void expr_error(struct expr *expr, char *fmt, ...)
|
||||
}
|
||||
|
||||
/*VARARGS*/
|
||||
void lexstrict(char *fmt, ...)
|
||||
lexstrict(char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
@ -108,7 +106,7 @@ void lexstrict(char *fmt, ...)
|
||||
}
|
||||
|
||||
/*VARARGS*/
|
||||
void strict(char *fmt, ...)
|
||||
strict(char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
@ -120,7 +118,7 @@ void strict(char *fmt, ...)
|
||||
}
|
||||
|
||||
/*VARARGS*/
|
||||
void expr_strict(struct expr *expr, char *fmt, ...)
|
||||
expr_strict(struct expr *expr, char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
@ -136,7 +134,7 @@ void expr_strict(struct expr *expr, char *fmt, ...)
|
||||
|
||||
#ifdef DEBUG
|
||||
/*VARARGS*/
|
||||
void debug(char *fmt, ...)
|
||||
debug(char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
@ -149,7 +147,7 @@ void debug(char *fmt, ...)
|
||||
#endif /* DEBUG */
|
||||
|
||||
/*VARARGS*/
|
||||
void warning(char *fmt, ...)
|
||||
warning(char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
@ -161,7 +159,7 @@ void warning(char *fmt, ...)
|
||||
}
|
||||
|
||||
/*VARARGS*/
|
||||
void expr_warning(struct expr *expr, char *fmt, ...)
|
||||
expr_warning(struct expr *expr, char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
@ -178,7 +176,7 @@ void expr_warning(struct expr *expr, char *fmt, ...)
|
||||
#ifdef LINT
|
||||
|
||||
/*VARARGS*/
|
||||
void def_warning(struct def *def, char *fmt, ...)
|
||||
def_warning(struct def *def, char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
@ -191,7 +189,7 @@ void def_warning(struct def *def, char *fmt, ...)
|
||||
|
||||
|
||||
/*VARARGS*/
|
||||
void hwarning(char *fmt, ...)
|
||||
hwarning(char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
@ -204,7 +202,7 @@ void hwarning(char *fmt, ...)
|
||||
}
|
||||
|
||||
/*VARARGS*/
|
||||
void awarning(char *fmt, ...)
|
||||
awarning(char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
@ -219,7 +217,7 @@ void awarning(char *fmt, ...)
|
||||
#endif /* LINT */
|
||||
|
||||
/*VARARGS*/
|
||||
void lexerror(char *fmt, ...)
|
||||
lexerror(char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
@ -231,7 +229,7 @@ void lexerror(char *fmt, ...)
|
||||
}
|
||||
|
||||
/*VARARGS*/
|
||||
void lexwarning(char *fmt, ...)
|
||||
lexwarning(char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
@ -243,7 +241,7 @@ void lexwarning(char *fmt, ...)
|
||||
}
|
||||
|
||||
/*VARARGS*/
|
||||
void crash(char *fmt, ...)
|
||||
crash(char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
@ -263,7 +261,7 @@ void crash(char *fmt, ...)
|
||||
}
|
||||
|
||||
/*VARARGS*/
|
||||
void fatal(char *fmt, ...)
|
||||
fatal(char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
@ -528,9 +526,15 @@ fatal(va_alist) /* fmt, args */
|
||||
}
|
||||
#endif
|
||||
|
||||
static void _error(int class, char *fn, unsigned int ln, char *fmt, va_list ap)
|
||||
static
|
||||
_error(class, fn, ln, fmt, ap)
|
||||
int class;
|
||||
char *fn;
|
||||
unsigned int ln;
|
||||
char *fmt;
|
||||
va_list ap;
|
||||
{
|
||||
char *remark = NULL;
|
||||
char *remark;
|
||||
|
||||
/* check visibility of message */
|
||||
switch (class) {
|
||||
@ -615,9 +619,9 @@ static void _error(int class, char *fn, unsigned int ln, char *fmt, va_list ap)
|
||||
#endif /* LINT */
|
||||
|
||||
if (fn)
|
||||
fprintf(stderr, "\"%s\", line %u: ", fn, ln);
|
||||
fprint(ERROUT, "\"%s\", line %u: ", fn, ln);
|
||||
if (remark)
|
||||
fprintf(stderr, "%s ", remark);
|
||||
fprint(ERROUT, "%s ", remark);
|
||||
doprnt(ERROUT, fmt, ap); /* contents of error */
|
||||
fprintf(stderr, "\n");
|
||||
fprint(ERROUT, "\n");
|
||||
}
|
||||
|
||||
@ -1,22 +0,0 @@
|
||||
/*
|
||||
* The Amsterdam Compiler Kit
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
#ifndef LANG_CEM_CEMCOM_ANSI_ERROR_H
|
||||
#define LANG_CEM_CEMCOM_ANSI_ERROR_H
|
||||
|
||||
/* lang/cem/cemcom.ansi/error.c */
|
||||
void error(char *fmt, ...);
|
||||
void expr_error(struct expr *expr, char *fmt, ...);
|
||||
void lexstrict(char *fmt, ...);
|
||||
void strict(char *fmt, ...);
|
||||
void expr_strict(struct expr *expr, char *fmt, ...);
|
||||
void warning(char *fmt, ...);
|
||||
void expr_warning(struct expr *expr, char *fmt, ...);
|
||||
void lexerror(char *fmt, ...);
|
||||
void lexwarning(char *fmt, ...);
|
||||
void crash(char *fmt, ...);
|
||||
void fatal(char *fmt, ...);
|
||||
|
||||
#endif /* LANG_CEM_CEMCOM_ANSI_ERROR_H */
|
||||
|
||||
@ -5,10 +5,6 @@
|
||||
/* $Id$ */
|
||||
/* EXPRESSION STACK */
|
||||
/* Used for global initializations */
|
||||
|
||||
#ifndef LANG_CEM_CEMCOM_ANSI_ESTACK_STR
|
||||
#define LANG_CEM_CEMCOM_ANSI_ESTACK_STR
|
||||
|
||||
struct e_stack {
|
||||
struct e_stack *next;
|
||||
arith s_cnt1, s_cnt2;
|
||||
@ -23,5 +19,3 @@ struct e_stack {
|
||||
#define last_offset s_cnt2
|
||||
#define elem_count s_cnt1
|
||||
#define nelem s_cnt2
|
||||
|
||||
#endif /* LANG_CEM_CEMCOM_ANSI_ESTACK_STR */
|
||||
|
||||
@ -15,8 +15,6 @@
|
||||
#include "nobitfield.h"
|
||||
#include "dataflow.h"
|
||||
#include <flt_arith.h>
|
||||
#include <system.h>
|
||||
#include "print.h"
|
||||
#include "arith.h"
|
||||
#include "type.h"
|
||||
#include "idf.h"
|
||||
@ -32,20 +30,13 @@
|
||||
#include "align.h"
|
||||
#include "mes.h"
|
||||
#include "atw.h"
|
||||
#include "blocks.h"
|
||||
#include "conversion.h"
|
||||
#include "specials.h"
|
||||
#include "ch3.h"
|
||||
#include "eval.h"
|
||||
#include "error.h"
|
||||
#include "field_loc.h"
|
||||
#include "struct_loc.h"
|
||||
#include "util_loc.h"
|
||||
|
||||
#include <symbol2str.h>
|
||||
|
||||
#define CRASH() crash("EVAL: CRASH at line %u", __LINE__)
|
||||
|
||||
char *symbol2str();
|
||||
char *long2str();
|
||||
arith NewLocal(); /* util.c */
|
||||
#define LocalPtrVar() NewLocal(pointer_size, pointer_align, reg_pointer, REGISTER)
|
||||
extern int err_occurred; /* error.c */
|
||||
|
||||
@ -75,10 +66,13 @@ extern int err_occurred; /* error.c */
|
||||
labels, in case they are specified (i.e. are non-zero)
|
||||
*/
|
||||
|
||||
void EVAL(struct expr *expr, int val, int code, label true_label, label false_label)
|
||||
EVAL(expr, val, code, true_label, false_label)
|
||||
register struct expr *expr;
|
||||
int val, code;
|
||||
label true_label, false_label;
|
||||
{
|
||||
int vol = (code != TRUE && recurqual(expr->ex_type, TQ_VOLATILE));
|
||||
int gencode = code == TRUE;
|
||||
register int gencode = code == TRUE;
|
||||
|
||||
if (err_occurred) return;
|
||||
switch (expr->ex_class) {
|
||||
@ -120,9 +114,9 @@ void EVAL(struct expr *expr, int val, int code, label true_label, label false_la
|
||||
case Oper: /* compound expression */
|
||||
{
|
||||
int oper = expr->OP_OPER;
|
||||
struct expr *left = expr->OP_LEFT;
|
||||
struct expr *right = expr->OP_RIGHT;
|
||||
struct type *tp = expr->OP_TYPE;
|
||||
register struct expr *left = expr->OP_LEFT;
|
||||
register struct expr *right = expr->OP_RIGHT;
|
||||
register struct type *tp = expr->OP_TYPE;
|
||||
|
||||
switch (oper) {
|
||||
case '+':
|
||||
@ -261,44 +255,26 @@ void EVAL(struct expr *expr, int val, int code, label true_label, label false_la
|
||||
operands(expr, gencode);
|
||||
ASSERT(tp->tp_fund==INT || tp->tp_fund==LONG);
|
||||
if (gencode)
|
||||
{
|
||||
if (tp->tp_unsigned)
|
||||
{
|
||||
C_rmu(tp->tp_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
C_rmi(tp->tp_size);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case LEFT:
|
||||
operands(expr, gencode);
|
||||
if (gencode)
|
||||
{
|
||||
if (tp->tp_unsigned)
|
||||
{
|
||||
C_slu(tp->tp_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
C_sli(tp->tp_size);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case RIGHT:
|
||||
operands(expr, gencode);
|
||||
if (gencode)
|
||||
{
|
||||
if (tp->tp_unsigned)
|
||||
{
|
||||
C_sru(tp->tp_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
C_sri(tp->tp_size);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '<':
|
||||
case LESSEQ:
|
||||
@ -496,7 +472,7 @@ void EVAL(struct expr *expr, int val, int code, label true_label, label false_la
|
||||
}
|
||||
case '(':
|
||||
{
|
||||
struct expr *ex;
|
||||
register struct expr *ex;
|
||||
arith ParSize = (arith)0;
|
||||
label setjmp_label = 0;
|
||||
arith retspace = 0;
|
||||
@ -682,7 +658,9 @@ void EVAL(struct expr *expr, int val, int code, label true_label, label false_la
|
||||
}
|
||||
|
||||
/* compare() serves as an auxiliary function of EVAL */
|
||||
void compare(int relop, label lbl)
|
||||
compare(relop, lbl)
|
||||
int relop;
|
||||
label lbl;
|
||||
{
|
||||
switch (relop) {
|
||||
case '<':
|
||||
@ -709,7 +687,8 @@ void compare(int relop, label lbl)
|
||||
}
|
||||
|
||||
/* truthvalue() serves as an auxiliary function of EVAL */
|
||||
void truthvalue(int relop)
|
||||
truthvalue(relop)
|
||||
int relop;
|
||||
{
|
||||
switch (relop) {
|
||||
case '<':
|
||||
@ -737,10 +716,12 @@ void truthvalue(int relop)
|
||||
|
||||
|
||||
/* assop() generates the opcode of an assignment operators op= */
|
||||
void assop(struct type *type, int oper)
|
||||
assop(type, oper)
|
||||
register struct type *type;
|
||||
int oper;
|
||||
{
|
||||
arith size;
|
||||
int uns = type->tp_unsigned;
|
||||
register arith size;
|
||||
register uns = type->tp_unsigned;
|
||||
|
||||
if ((int)(size = type->tp_size) < (int)word_size)
|
||||
size = word_size;
|
||||
@ -840,7 +821,8 @@ void assop(struct type *type, int oper)
|
||||
}
|
||||
}
|
||||
|
||||
void ptr_add(arith size)
|
||||
ptr_add(size)
|
||||
arith size;
|
||||
{
|
||||
if (size != pointer_size) {
|
||||
C_loc(size);
|
||||
@ -857,10 +839,12 @@ void ptr_add(arith size)
|
||||
- into a local static variable
|
||||
- absolute addressing
|
||||
*/
|
||||
void store_val(struct value *vl, struct type *tp)
|
||||
store_val(vl, tp)
|
||||
register struct value *vl;
|
||||
register struct type *tp;
|
||||
{
|
||||
int inword = 0;
|
||||
int indword = 0;
|
||||
register int inword = 0;
|
||||
register int indword = 0;
|
||||
arith val = vl->vl_value;
|
||||
|
||||
if (vl->vl_class == Const) { /* absolute addressing */
|
||||
@ -873,8 +857,8 @@ void store_val(struct value *vl, struct type *tp)
|
||||
else if (tp->tp_size == dword_size) indword = 1;
|
||||
}
|
||||
if (vl->vl_class == Name) {
|
||||
struct idf *id = vl->vl_data.vl_idf;
|
||||
struct def *df = id->id_def;
|
||||
register struct idf *id = vl->vl_data.vl_idf;
|
||||
register struct def *df = id->id_def;
|
||||
|
||||
/* if (df->df_level == L_GLOBAL) { // } ??? re-examine */
|
||||
if (df->df_sc == GLOBAL
|
||||
@ -926,15 +910,14 @@ void store_val(struct value *vl, struct type *tp)
|
||||
- static variable
|
||||
- local variable
|
||||
*/
|
||||
/* expr -> expression containing the value
|
||||
rlval -> generate either LVAL or RVAL
|
||||
*/
|
||||
void load_val(struct expr *expr, int rlval)
|
||||
load_val(expr, rlval)
|
||||
register struct expr *expr; /* expression containing the value */
|
||||
int rlval; /* generate either LVAL or RVAL */
|
||||
{
|
||||
struct type *tp = expr->ex_type;
|
||||
register struct type *tp = expr->ex_type;
|
||||
int rvalue = (rlval == RVAL && expr->ex_lvalue != 0);
|
||||
int inword = 0, indword = 0;
|
||||
arith val = expr->VL_VALUE;
|
||||
register int inword = 0, indword = 0;
|
||||
register arith val = expr->VL_VALUE;
|
||||
|
||||
if (expr->ex_type->tp_fund == FLOAT
|
||||
|| expr->ex_type->tp_fund == DOUBLE
|
||||
@ -974,8 +957,8 @@ void load_val(struct expr *expr, int rlval)
|
||||
}
|
||||
}
|
||||
else {
|
||||
struct idf *id = expr->VL_IDF;
|
||||
struct def *df = id->id_def;
|
||||
register struct idf *id = expr->VL_IDF;
|
||||
register struct def *df = id->id_def;
|
||||
int fund = df->df_type->tp_fund;
|
||||
|
||||
ASSERT(ISNAME(expr));
|
||||
@ -1026,7 +1009,8 @@ void load_val(struct expr *expr, int rlval)
|
||||
}
|
||||
}
|
||||
|
||||
void load_cst(arith val, arith siz)
|
||||
load_cst(val, siz)
|
||||
arith val, siz;
|
||||
{
|
||||
if ((int)siz <= (int)word_size)
|
||||
C_loc(val);
|
||||
@ -1043,7 +1027,8 @@ void load_cst(arith val, arith siz)
|
||||
}
|
||||
}
|
||||
|
||||
void operands(struct expr *expr, int gencode)
|
||||
operands(expr, gencode)
|
||||
register struct expr *expr;
|
||||
{
|
||||
EVAL(expr->OP_LEFT, RVAL, gencode, NO_LABEL, NO_LABEL);
|
||||
EVAL(expr->OP_RIGHT, RVAL, gencode, NO_LABEL, NO_LABEL);
|
||||
|
||||
@ -1,20 +0,0 @@
|
||||
/*
|
||||
* The Amsterdam Compiler Kit
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
#ifndef LANG_CEM_CEMCOM_ANSI_EVAL_H
|
||||
#define LANG_CEM_CEMCOM_ANSI_EVAL_H
|
||||
|
||||
/* lang/cem/cemcom.ansi/eval.c */
|
||||
void EVAL(struct expr *expr, int val, int code, label true_label, label false_label);
|
||||
void compare(int relop, label lbl);
|
||||
void truthvalue(int relop);
|
||||
void assop(struct type *type, int oper);
|
||||
void ptr_add(arith size);
|
||||
void store_val(struct value *vl, struct type *tp);
|
||||
void load_val(struct expr *expr, int rlval);
|
||||
void load_cst(arith val, arith siz);
|
||||
void operands(struct expr *expr, int gencode);
|
||||
|
||||
#endif /* LANG_CEM_CEMCOM_ANSI_EVAL_H */
|
||||
|
||||
@ -5,8 +5,6 @@
|
||||
/* $Id$ */
|
||||
/* EXPRESSION TREE HANDLING */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "lint.h"
|
||||
#include "debug.h"
|
||||
#include "assert.h"
|
||||
@ -26,16 +24,14 @@
|
||||
#include "sizes.h"
|
||||
#include "level.h"
|
||||
#include "use_tmp.h"
|
||||
#include "cstoper.h"
|
||||
#include "idf_loc.h"
|
||||
#include "expr_loc.h"
|
||||
#include "error.h"
|
||||
#include <symbol2str.h>
|
||||
|
||||
extern char *symbol2str();
|
||||
extern char options[];
|
||||
extern int InSizeof;
|
||||
|
||||
int rank_of(int oper)
|
||||
int
|
||||
rank_of(oper)
|
||||
int oper;
|
||||
{
|
||||
/* The rank of the operator oper is returned.
|
||||
*/
|
||||
@ -104,12 +100,13 @@ int rank_of(int oper)
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
|
||||
void dot2expr(struct expr **expp)
|
||||
dot2expr(expp)
|
||||
struct expr **expp;
|
||||
{
|
||||
/* The token in dot is converted into an expression, a
|
||||
pointer to which is stored in *expp.
|
||||
*/
|
||||
struct expr *ex = new_expr();
|
||||
register struct expr *ex = new_expr();
|
||||
|
||||
*expp = ex;
|
||||
ex->ex_file = dot.tk_file;
|
||||
@ -130,15 +127,16 @@ void dot2expr(struct expr **expp)
|
||||
}
|
||||
}
|
||||
|
||||
void idf2expr(struct expr *expr)
|
||||
idf2expr(expr)
|
||||
register struct expr *expr;
|
||||
{
|
||||
/* Dot contains an identifier which is turned into an
|
||||
expression.
|
||||
Note that this constitutes an applied occurrence of
|
||||
the identifier.
|
||||
*/
|
||||
struct idf *idf = dot.tk_idf; /* != 0*/
|
||||
struct def *def = idf->id_def;
|
||||
register struct idf *idf = dot.tk_idf; /* != 0*/
|
||||
register struct def *def = idf->id_def;
|
||||
|
||||
if (def == 0) {
|
||||
if (AHEAD == '(') {
|
||||
@ -199,12 +197,15 @@ void idf2expr(struct expr *expr)
|
||||
}
|
||||
}
|
||||
|
||||
void string2expr(struct expr **expp, char *str, int len)
|
||||
string2expr(expp, str, len)
|
||||
register struct expr **expp;
|
||||
int len;
|
||||
char *str;
|
||||
{
|
||||
/* The string in the argument is converted into an expression,
|
||||
a pointer to which is stored in *expp.
|
||||
*/
|
||||
struct expr *ex = new_expr();
|
||||
register struct expr *ex = new_expr();
|
||||
|
||||
*expp = ex;
|
||||
ex->ex_file = dot.tk_file;
|
||||
@ -218,7 +219,8 @@ void string2expr(struct expr **expp, char *str, int len)
|
||||
ex->SG_LEN = len;
|
||||
}
|
||||
|
||||
void int2expr(struct expr *expr)
|
||||
int2expr(expr)
|
||||
struct expr *expr;
|
||||
{
|
||||
/* Dot contains an integer constant which is turned
|
||||
into an expression.
|
||||
@ -226,12 +228,13 @@ void int2expr(struct expr *expr)
|
||||
fill_int_expr(expr, dot.tk_ival, dot.tk_fund);
|
||||
}
|
||||
|
||||
void float2expr(struct expr *expr)
|
||||
float2expr(expr)
|
||||
register struct expr *expr;
|
||||
{
|
||||
/* Dot contains a floating point constant which is turned
|
||||
into an expression.
|
||||
*/
|
||||
int fund;
|
||||
register int fund;
|
||||
|
||||
fund = dot.tk_fund;
|
||||
switch (fund) {
|
||||
@ -255,12 +258,15 @@ void float2expr(struct expr *expr)
|
||||
expr_warning(expr,"internal floating point overflow");
|
||||
}
|
||||
|
||||
struct expr *intexpr(arith ivalue, int fund)
|
||||
struct expr*
|
||||
intexpr(ivalue, fund)
|
||||
arith ivalue;
|
||||
int fund;
|
||||
{
|
||||
/* The value ivalue is turned into an integer expression of
|
||||
the size indicated by fund.
|
||||
*/
|
||||
struct expr *expr = new_expr();
|
||||
register struct expr *expr = new_expr();
|
||||
|
||||
expr->ex_file = dot.tk_file;
|
||||
expr->ex_line = dot.tk_line;
|
||||
@ -268,7 +274,10 @@ struct expr *intexpr(arith ivalue, int fund)
|
||||
return expr;
|
||||
}
|
||||
|
||||
void fill_int_expr(struct expr *ex, arith ivalue, int fund)
|
||||
fill_int_expr(ex, ivalue, fund)
|
||||
register struct expr *ex;
|
||||
arith ivalue;
|
||||
int fund;
|
||||
{
|
||||
/* Details derived from ivalue and fund are put into the
|
||||
constant integer expression ex.
|
||||
@ -296,7 +305,10 @@ void fill_int_expr(struct expr *ex, arith ivalue, int fund)
|
||||
cut_size(ex);
|
||||
}
|
||||
|
||||
struct expr *new_oper(struct type *tp, struct expr *e1, int oper, struct expr *e2)
|
||||
struct expr *
|
||||
new_oper(tp, e1, oper, e2)
|
||||
struct type *tp;
|
||||
register struct expr *e1, *e2;
|
||||
{
|
||||
/* A new expression is constructed which consists of the
|
||||
operator oper which has e1 and e2 as operands; for a
|
||||
@ -304,11 +316,11 @@ struct expr *new_oper(struct type *tp, struct expr *e1, int oper, struct expr *e
|
||||
During the construction of the right recursive initialisation
|
||||
tree it is possible for e2 to be NILEXPR.
|
||||
*/
|
||||
struct expr *expr = new_expr();
|
||||
struct oper *op;
|
||||
register struct expr *expr = new_expr();
|
||||
register struct oper *op;
|
||||
|
||||
if (e2) {
|
||||
struct expr *e = e2;
|
||||
register struct expr *e = e2;
|
||||
|
||||
while (e->ex_class == Oper && e->OP_LEFT)
|
||||
e = e->OP_LEFT;
|
||||
@ -317,7 +329,7 @@ struct expr *new_oper(struct type *tp, struct expr *e1, int oper, struct expr *e
|
||||
}
|
||||
else
|
||||
if (e1) {
|
||||
struct expr *e = e1;
|
||||
register struct expr *e = e1;
|
||||
|
||||
while (e->ex_class == Oper && e->OP_RIGHT)
|
||||
e = e->OP_RIGHT;
|
||||
@ -359,7 +371,8 @@ struct expr *new_oper(struct type *tp, struct expr *e1, int oper, struct expr *e
|
||||
return expr;
|
||||
}
|
||||
|
||||
void chk_cst_expr(struct expr **expp)
|
||||
chk_cst_expr(expp)
|
||||
struct expr **expp;
|
||||
{
|
||||
/* The expression expr is checked for constancy.
|
||||
|
||||
@ -381,7 +394,7 @@ void chk_cst_expr(struct expr **expp)
|
||||
Special problems (of which there is only one, sizeof in
|
||||
Preprocessor #if) have to be dealt with locally
|
||||
*/
|
||||
struct expr *expr = *expp;
|
||||
register struct expr *expr = *expp;
|
||||
|
||||
#ifdef DEBUG
|
||||
print_expr("constant_expression", expr);
|
||||
@ -404,7 +417,9 @@ void chk_cst_expr(struct expr **expp)
|
||||
erroneous2int(expp);
|
||||
}
|
||||
|
||||
void init_expression(struct expr ***eppp, struct expr *expr)
|
||||
init_expression(eppp, expr)
|
||||
register struct expr ***eppp;
|
||||
struct expr *expr;
|
||||
{
|
||||
/* The expression expr is added to the tree designated
|
||||
indirectly by **eppp.
|
||||
@ -422,7 +437,9 @@ void init_expression(struct expr ***eppp, struct expr *expr)
|
||||
*eppp = &(**eppp)->OP_RIGHT;
|
||||
}
|
||||
|
||||
int is_ld_cst(struct expr *expr)
|
||||
int
|
||||
is_ld_cst(expr)
|
||||
register struct expr *expr;
|
||||
{
|
||||
/* An expression is a `load-time constant' if it is of the form
|
||||
<idf> +/- <integral> or <integral>.
|
||||
@ -434,7 +451,9 @@ int is_ld_cst(struct expr *expr)
|
||||
return expr->ex_lvalue == 0 && expr->ex_class == Value;
|
||||
}
|
||||
|
||||
int is_cp_cst(struct expr *expr)
|
||||
int
|
||||
is_cp_cst(expr)
|
||||
struct expr *expr;
|
||||
{
|
||||
/* An expression is a `compile-time constant' if it is a
|
||||
load-time constant, and the idf is not there.
|
||||
@ -442,7 +461,9 @@ int is_cp_cst(struct expr *expr)
|
||||
return is_ld_cst(expr) && expr->VL_CLASS == Const;
|
||||
}
|
||||
|
||||
int is_fp_cst(struct expr *expr)
|
||||
int
|
||||
is_fp_cst(expr)
|
||||
struct expr *expr;
|
||||
{
|
||||
/* An expression is a `floating-point constant' if it consists
|
||||
of the float only.
|
||||
@ -450,7 +471,9 @@ int is_fp_cst(struct expr *expr)
|
||||
return expr->ex_class == Float;
|
||||
}
|
||||
|
||||
int is_zero_cst(struct expr *expr)
|
||||
int
|
||||
is_zero_cst(expr)
|
||||
register struct expr *expr;
|
||||
{
|
||||
flt_arith var;
|
||||
|
||||
@ -462,10 +485,10 @@ int is_zero_cst(struct expr *expr)
|
||||
return flt_cmp(&var, &(expr->FL_ARITH)) == 0;
|
||||
}
|
||||
/*NOTREACHED*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
void free_expression(struct expr *expr)
|
||||
free_expression(expr)
|
||||
register struct expr *expr;
|
||||
{
|
||||
/* The expression expr is freed recursively.
|
||||
*/
|
||||
|
||||
@ -9,14 +9,6 @@
|
||||
a union of various goodies, we define them first; so be patient.
|
||||
*/
|
||||
|
||||
#ifndef LANG_CEM_CEMCOM_ANSI_EXPR_STR
|
||||
#define LANG_CEM_CEMCOM_ANSI_EXPR_STR
|
||||
|
||||
#include "idf.h"
|
||||
#include "arith.h"
|
||||
#include <em_label.h>
|
||||
#include <flt_arith.h>
|
||||
|
||||
/* classes of value */
|
||||
#define Const 1
|
||||
#define Name 2
|
||||
@ -105,4 +97,3 @@ extern struct expr *intexpr(), *new_oper();
|
||||
|
||||
/* ALLOCDEF "expr" 20 */
|
||||
|
||||
#endif /* LANG_CEM_CEMCOM_ANSI_EXPR_STR */
|
||||
@ -1,27 +0,0 @@
|
||||
/*
|
||||
* The Amsterdam Compiler Kit
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
#ifndef LANG_CEM_CEMCOM_ANSI_EXPR_H
|
||||
#define LANG_CEM_CEMCOM_ANSI_EXPR_H
|
||||
|
||||
/* lang/cem/cemcom.ansi/expr.c */
|
||||
int rank_of(int oper);
|
||||
void dot2expr(struct expr **expp);
|
||||
void idf2expr(struct expr *expr);
|
||||
void string2expr(struct expr **expp, char *str, int len);
|
||||
void int2expr(struct expr *expr);
|
||||
void float2expr(struct expr *expr);
|
||||
struct expr *intexpr(arith ivalue, int fund);
|
||||
void fill_int_expr(struct expr *ex, arith ivalue, int fund);
|
||||
struct expr *new_oper(struct type *tp, struct expr *e1, int oper, struct expr *e2);
|
||||
void chk_cst_expr(struct expr **expp);
|
||||
void init_expression(struct expr ***eppp, struct expr *expr);
|
||||
int is_ld_cst(struct expr *expr);
|
||||
int is_cp_cst(struct expr *expr);
|
||||
int is_fp_cst(struct expr *expr);
|
||||
int is_zero_cst(struct expr *expr);
|
||||
void free_expression(struct expr *expr);
|
||||
|
||||
#endif /* LANG_CEM_CEMCOM_ANSI_EXPR_H */
|
||||
|
||||
@ -14,20 +14,12 @@
|
||||
#include "LLlex.h"
|
||||
#include "type.h"
|
||||
#include "idf.h"
|
||||
#include "decspecs.h"
|
||||
#include "declar.h"
|
||||
#include "declarator.h"
|
||||
#include "label.h"
|
||||
#include "expr.h"
|
||||
#include "expr_loc.h"
|
||||
#include "proto_loc.h"
|
||||
#include "code.h"
|
||||
#include "sizes.h"
|
||||
#include "ch3.h"
|
||||
#include "ch3bin.h"
|
||||
#include "ch3mon.h"
|
||||
#include "error.h"
|
||||
|
||||
extern struct expr *intexpr();
|
||||
int InSizeof = 0; /* inside a sizeof- expression */
|
||||
int ResultKnown = 0; /* result of the expression is already known */
|
||||
|
||||
@ -39,7 +31,7 @@ int ResultKnown = 0; /* result of the expression is already known */
|
||||
}
|
||||
|
||||
/* 3.3.1 */
|
||||
primary(struct expr **expp;) :
|
||||
primary(register struct expr **expp;) :
|
||||
IDENTIFIER
|
||||
{dot2expr(expp);}
|
||||
|
|
||||
@ -56,10 +48,10 @@ primary(struct expr **expp;) :
|
||||
* are concatenated into a single character string
|
||||
* literal.
|
||||
*/
|
||||
string(struct expr **expp;)
|
||||
{ int i, len;
|
||||
char *str;
|
||||
int fund;
|
||||
string(register struct expr **expp;)
|
||||
{ register int i, len;
|
||||
register char *str;
|
||||
register int fund;
|
||||
}
|
||||
:
|
||||
STRING
|
||||
@ -86,7 +78,7 @@ string(struct expr **expp;)
|
||||
;
|
||||
|
||||
/* 3.3.2 */
|
||||
postfix_expression(struct expr **expp;)
|
||||
postfix_expression(register struct expr **expp;)
|
||||
{ int oper;
|
||||
struct expr *e1 = 0;
|
||||
struct idf *idf;
|
||||
@ -128,7 +120,7 @@ parameter_list(struct expr **expp;)
|
||||
%first first_of_type_specifier, type_specifier;
|
||||
|
||||
/* 3.3.3 & 3.3.4 */
|
||||
unary(struct expr **expp;)
|
||||
unary(register struct expr **expp;)
|
||||
{struct type *tp; int oper;}
|
||||
:
|
||||
%if (first_of_type_specifier(AHEAD) && AHEAD != IDENTIFIER)
|
||||
@ -151,7 +143,7 @@ unary(struct expr **expp;)
|
||||
* mark it as used.
|
||||
* extern int i; .... sizeof(i) .... need not have a definition for i
|
||||
*/
|
||||
size_of(struct expr **expp;)
|
||||
size_of(register struct expr **expp;)
|
||||
{struct type *tp;}
|
||||
:
|
||||
SIZEOF { InSizeof++; } /* handle (sizeof(sizeof(int))) too */
|
||||
@ -330,7 +322,7 @@ binop(int *oper;) :
|
||||
{*oper = DOT;}
|
||||
;
|
||||
|
||||
asgnop(int *oper;):
|
||||
asgnop(register int *oper;):
|
||||
[ '=' | PLUSAB | MINAB | TIMESAB | DIVAB | MODAB
|
||||
| LEFTAB | RIGHTAB | ANDAB | XORAB | ORAB ]
|
||||
{ *oper = DOT; }
|
||||
|
||||
@ -26,11 +26,8 @@
|
||||
#include "align.h"
|
||||
#include "Lpars.h"
|
||||
#include "field.h"
|
||||
#include "field_loc.h"
|
||||
#include "eval.h"
|
||||
#include "util_loc.h"
|
||||
#include "conversion.h"
|
||||
|
||||
arith NewLocal(); /* util.c */
|
||||
extern arith full_mask[]; /* cstoper.c */
|
||||
|
||||
/* Eval_field() evaluates expressions involving bit fields.
|
||||
@ -45,12 +42,14 @@ extern arith full_mask[]; /* cstoper.c */
|
||||
[3] atype: the type in which the bitfield arithmetic is done;
|
||||
and in which bitfields are stored!
|
||||
*/
|
||||
void eval_field(struct expr *expr, int code)
|
||||
eval_field(expr, code)
|
||||
struct expr *expr;
|
||||
int code;
|
||||
{
|
||||
int op = expr->OP_OPER;
|
||||
struct expr *leftop = expr->OP_LEFT;
|
||||
struct expr *rightop = expr->OP_RIGHT;
|
||||
struct field *fd = leftop->ex_type->tp_field;
|
||||
register struct expr *leftop = expr->OP_LEFT;
|
||||
register struct expr *rightop = expr->OP_RIGHT;
|
||||
register struct field *fd = leftop->ex_type->tp_field;
|
||||
struct type *tp = leftop->ex_type->tp_up;
|
||||
arith tmpvar = 0;
|
||||
struct type *atype = ( tp->tp_unsigned
|
||||
@ -119,7 +118,7 @@ void eval_field(struct expr *expr, int code)
|
||||
retrieval) is on top of stack.
|
||||
*/
|
||||
if (tp->tp_unsigned == 0) { /* sign extension */
|
||||
arith shift = (int)word_size * 8 - fd->fd_width;
|
||||
register arith shift = (int)word_size * 8 - fd->fd_width;
|
||||
|
||||
C_loc(shift);
|
||||
C_sli(word_size);
|
||||
@ -130,7 +129,12 @@ void eval_field(struct expr *expr, int code)
|
||||
}
|
||||
}
|
||||
|
||||
void store_field(struct field *fd, int uns, int code, struct expr *leftop, arith tmpvar)
|
||||
store_field(fd, uns, code, leftop, tmpvar)
|
||||
register struct field *fd;
|
||||
int uns;
|
||||
int code;
|
||||
register struct expr *leftop;
|
||||
arith tmpvar;
|
||||
{
|
||||
C_loc(fd->fd_mask);
|
||||
C_and(word_size);
|
||||
|
||||
@ -1,13 +0,0 @@
|
||||
/*
|
||||
* The Amsterdam Compiler Kit
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
#ifndef LANG_CEM_CEMCOM_ANSI_FIELD_H
|
||||
#define LANG_CEM_CEMCOM_ANSI_FIELD_H
|
||||
|
||||
/* lang/cem/cemcom.ansi/field.c */
|
||||
void eval_field(struct expr *expr, int code);
|
||||
void store_field(struct field *fd, int uns, int code, struct expr *leftop, arith tmpvar);
|
||||
|
||||
#endif /* LANG_CEM_CEMCOM_ANSI_FIELD_H */
|
||||
|
||||
@ -18,16 +18,12 @@
|
||||
#include "expr.h"
|
||||
#include "sizes.h"
|
||||
#include "Lpars.h"
|
||||
#include "cstoper.h"
|
||||
#include "fltcstoper.h"
|
||||
#include "error.h"
|
||||
#include "expr_loc.h"
|
||||
|
||||
#include <symbol2str.h>
|
||||
|
||||
extern int ResultKnown;
|
||||
extern char *symbol2str();
|
||||
|
||||
void fltcstbin(struct expr **expp, int oper, struct expr *expr)
|
||||
fltcstbin(expp, oper, expr)
|
||||
register struct expr **expp, *expr;
|
||||
{
|
||||
/* The operation oper is performed on the constant
|
||||
expressions *expp(ld) and expr(ct), and the result restored in
|
||||
|
||||
@ -1,12 +0,0 @@
|
||||
/*
|
||||
* The Amsterdam Compiler Kit
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
#ifndef LANG_CEM_CEMCOM_ANSI_FLTCSTOPER_H
|
||||
#define LANG_CEM_CEMCOM_ANSI_FLTCSTOPER_H
|
||||
|
||||
/* lang/cem/cemcom.ansi/fltcstoper.c */
|
||||
void fltcstbin(register struct expr **expp, int oper, register struct expr *expr);
|
||||
|
||||
#endif /* LANG_CEM_CEMCOM_ANSI_FLTCSTOPER_H */
|
||||
|
||||
@ -7,7 +7,6 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "system.h"
|
||||
#include "lint.h"
|
||||
#include <em_reg.h>
|
||||
#include "debug.h"
|
||||
@ -32,21 +31,10 @@
|
||||
#include "sizes.h"
|
||||
#include "Lpars.h"
|
||||
#include "assert.h"
|
||||
#include "ch3.h"
|
||||
#include "code_c.h"
|
||||
#include "conversion.h"
|
||||
#include "print.h"
|
||||
#include "idf_loc.h"
|
||||
#include "struct_loc.h"
|
||||
#include "proto_loc.h"
|
||||
#include "util_loc.h"
|
||||
#include "error.h"
|
||||
#include "stab.h"
|
||||
#include "stack_loc.h"
|
||||
|
||||
#include <symbol2str.h>
|
||||
|
||||
extern char options[];
|
||||
extern arith NewLocal();
|
||||
extern char *symbol2str();
|
||||
|
||||
#ifdef DEBUG
|
||||
#define IDF_DEBUG
|
||||
@ -54,7 +42,8 @@ extern char options[];
|
||||
|
||||
#include <idf_pkg.body>
|
||||
|
||||
struct idf *gen_idf()
|
||||
struct idf *
|
||||
gen_idf()
|
||||
{
|
||||
/* A new idf is created out of nowhere, to serve as an
|
||||
anonymous name.
|
||||
@ -68,12 +57,16 @@ struct idf *gen_idf()
|
||||
return str2idf(s, 0);
|
||||
}
|
||||
|
||||
int is_anon_idf(struct idf *idf)
|
||||
int
|
||||
is_anon_idf(idf)
|
||||
struct idf *idf;
|
||||
{
|
||||
return idf->id_text[0] == '#';
|
||||
}
|
||||
|
||||
void declare_idf(struct decspecs *ds, struct declarator *dc, int lvl)
|
||||
declare_idf(ds, dc, lvl)
|
||||
struct decspecs *ds;
|
||||
struct declarator *dc;
|
||||
{
|
||||
/* The identifier inside dc is declared on the level lvl, with
|
||||
properties deduced from the decspecs ds and the declarator
|
||||
@ -83,14 +76,14 @@ void declare_idf(struct decspecs *ds, struct declarator *dc, int lvl)
|
||||
This routine implements the rich semantics of C
|
||||
declarations.
|
||||
*/
|
||||
struct idf *idf = dc->dc_idf;
|
||||
int sc = ds->ds_sc;
|
||||
register struct idf *idf = dc->dc_idf;
|
||||
register int sc = ds->ds_sc;
|
||||
/* This local copy is essential:
|
||||
char b(), c;
|
||||
makes b GLOBAL and c AUTO.
|
||||
*/
|
||||
struct def *def = idf->id_def; /* may be NULL */
|
||||
struct type *type;
|
||||
register struct def *def = idf->id_def; /* may be NULL */
|
||||
register struct type *type;
|
||||
struct stack_level *stl = stack_level_of(lvl);
|
||||
char formal_array = 0;
|
||||
|
||||
@ -104,8 +97,8 @@ void declare_idf(struct decspecs *ds, struct declarator *dc, int lvl)
|
||||
else {
|
||||
/* combine the decspecs and the declarator into one type */
|
||||
type = declare_type(ds->ds_type, dc);
|
||||
if ( (type->tp_size <= (arith)0) &&
|
||||
actual_declaration(sc, type)) {
|
||||
if (type->tp_size <= (arith)0 &&
|
||||
actual_declaration(sc, type)) {
|
||||
if (type->tp_size == (arith) -1) {
|
||||
/* the type is not yet known,
|
||||
but it has to be:
|
||||
@ -211,7 +204,7 @@ void declare_idf(struct decspecs *ds, struct declarator *dc, int lvl)
|
||||
def->df_line = idf->id_line;
|
||||
}
|
||||
else { /* fill in the def block */
|
||||
struct def *newdef = new_def();
|
||||
register struct def *newdef = new_def();
|
||||
|
||||
newdef->next = def;
|
||||
newdef->df_level = lvl;
|
||||
@ -260,11 +253,13 @@ void declare_idf(struct decspecs *ds, struct declarator *dc, int lvl)
|
||||
}
|
||||
}
|
||||
|
||||
int actual_declaration(int sc, struct type *tp)
|
||||
actual_declaration(sc, tp)
|
||||
int sc;
|
||||
struct type *tp;
|
||||
{
|
||||
/* An actual_declaration needs space, right here and now.
|
||||
*/
|
||||
int fund = tp->tp_fund;
|
||||
register int fund = tp->tp_fund;
|
||||
|
||||
if (sc == ENUM || sc == TYPEDEF) /* virtual declarations */
|
||||
return 0;
|
||||
@ -279,7 +274,9 @@ int actual_declaration(int sc, struct type *tp)
|
||||
return 1;
|
||||
}
|
||||
|
||||
void global_redecl(struct idf *idf, int new_sc, struct type *tp)
|
||||
global_redecl(idf, new_sc, tp)
|
||||
register struct idf *idf;
|
||||
struct type *tp;
|
||||
{
|
||||
/* A global identifier may be declared several times,
|
||||
provided the declarations do not conflict; they might
|
||||
@ -287,7 +284,7 @@ void global_redecl(struct idf *idf, int new_sc, struct type *tp)
|
||||
an array) or they might conflict or supplement each other
|
||||
in storage class.
|
||||
*/
|
||||
struct def *def = idf->id_def;
|
||||
register struct def *def = idf->id_def;
|
||||
|
||||
while (def->df_level != L_GLOBAL) def = def->next;
|
||||
if (!equal_type(tp, def->df_type, 0, 1)) {
|
||||
@ -371,7 +368,10 @@ void global_redecl(struct idf *idf, int new_sc, struct type *tp)
|
||||
}
|
||||
}
|
||||
|
||||
int good_formal(struct def *def, struct idf *idf)
|
||||
int
|
||||
good_formal(def, idf)
|
||||
register struct def *def;
|
||||
register struct idf *idf;
|
||||
{
|
||||
/* Succeeds if def is a proper L_FORMAL1 definition and
|
||||
gives an error message otherwise.
|
||||
@ -385,11 +385,12 @@ int good_formal(struct def *def, struct idf *idf)
|
||||
return 1;
|
||||
}
|
||||
|
||||
void declare_params(struct declarator *dc)
|
||||
declare_params(dc)
|
||||
struct declarator *dc;
|
||||
{
|
||||
/* Declares the formal parameters if they exist.
|
||||
*/
|
||||
struct formal *fm = dc->dc_formal;
|
||||
register struct formal *fm = dc->dc_formal;
|
||||
|
||||
while (fm) {
|
||||
declare_parameter(fm->fm_idf);
|
||||
@ -397,11 +398,12 @@ void declare_params(struct declarator *dc)
|
||||
}
|
||||
}
|
||||
|
||||
void idf_initialized(struct idf *idf)
|
||||
idf_initialized(idf)
|
||||
register struct idf *idf;
|
||||
{
|
||||
/* The topmost definition of idf is set to initialized.
|
||||
*/
|
||||
struct def *def = idf->id_def; /* the topmost */
|
||||
register struct def *def = idf->id_def; /* the topmost */
|
||||
|
||||
while (def->df_level <= L_PROTO) def = def->next;
|
||||
if (def->df_initialized)
|
||||
@ -413,14 +415,18 @@ void idf_initialized(struct idf *idf)
|
||||
def->df_initialized = 1;
|
||||
}
|
||||
|
||||
void declare_parameter(struct idf *idf)
|
||||
declare_parameter(idf)
|
||||
struct idf *idf;
|
||||
{
|
||||
/* idf is declared as a formal.
|
||||
*/
|
||||
add_def(idf, FORMAL, int_type, level);
|
||||
}
|
||||
|
||||
void declare_enum(struct type *tp, struct idf *idf, arith l)
|
||||
declare_enum(tp, idf, l)
|
||||
struct type *tp;
|
||||
struct idf *idf;
|
||||
arith l;
|
||||
{
|
||||
/* idf is declared as an enum constant with value l.
|
||||
*/
|
||||
@ -428,11 +434,13 @@ void declare_enum(struct type *tp, struct idf *idf, arith l)
|
||||
idf->id_def->df_address = l;
|
||||
}
|
||||
|
||||
void check_formals(struct idf *idf, struct declarator *dc)
|
||||
check_formals(idf, dc)
|
||||
struct idf *idf;
|
||||
struct declarator *dc;
|
||||
{
|
||||
struct formal *fm = dc->dc_formal;
|
||||
struct proto *pl = idf->id_def->df_type->tp_proto;
|
||||
struct decl_unary *du = dc->dc_decl_unary;
|
||||
register struct formal *fm = dc->dc_formal;
|
||||
register struct proto *pl = idf->id_def->df_type->tp_proto;
|
||||
register struct decl_unary *du = dc->dc_decl_unary;
|
||||
|
||||
if (!du) { /* error or typdef'ed function */
|
||||
error("illegal definition of %s", idf->id_text);
|
||||
@ -475,7 +483,7 @@ void check_formals(struct idf *idf, struct declarator *dc)
|
||||
error("incorrect number of parameters");
|
||||
}
|
||||
} else { /* make a pseudo-prototype */
|
||||
struct proto *lpl = new_proto();
|
||||
register struct proto *lpl = new_proto();
|
||||
|
||||
if (!options['o'])
|
||||
warning("'%s' old-fashioned function definition"
|
||||
@ -504,16 +512,18 @@ void check_formals(struct idf *idf, struct declarator *dc)
|
||||
dc->dc_formal = 0;
|
||||
}
|
||||
|
||||
void declare_formals(struct idf *idf, arith *fp)
|
||||
declare_formals(idf, fp)
|
||||
struct idf *idf;
|
||||
arith *fp;
|
||||
{
|
||||
/* Declares those formals as int that haven't been declared
|
||||
by the user.
|
||||
An address is assigned to each formal parameter.
|
||||
The total size of the formals is returned in *fp;
|
||||
*/
|
||||
struct stack_entry *se = stack_level_of(L_FORMAL1)->sl_entry;
|
||||
register struct stack_entry *se = stack_level_of(L_FORMAL1)->sl_entry;
|
||||
arith f_offset = (arith)0;
|
||||
int nparams = 0;
|
||||
register int nparams = 0;
|
||||
int hasproto;
|
||||
struct def *df = idf->id_def;
|
||||
|
||||
@ -580,7 +590,9 @@ void declare_formals(struct idf *idf, arith *fp)
|
||||
*fp = f_offset;
|
||||
}
|
||||
|
||||
int regtype(struct type *tp)
|
||||
int
|
||||
regtype(tp)
|
||||
struct type *tp;
|
||||
{
|
||||
switch(tp->tp_fund) {
|
||||
case INT:
|
||||
@ -596,7 +608,11 @@ int regtype(struct type *tp)
|
||||
return -1;
|
||||
}
|
||||
|
||||
void add_def(struct idf *idf, int sc, struct type *tp, int lvl)
|
||||
add_def(idf, sc, tp, lvl)
|
||||
struct idf *idf;
|
||||
struct type *tp;
|
||||
int lvl;
|
||||
int sc;
|
||||
{
|
||||
/* The identifier idf is declared on level lvl with storage
|
||||
class sc and type tp, through a faked C declaration.
|
||||
@ -613,12 +629,13 @@ void add_def(struct idf *idf, int sc, struct type *tp, int lvl)
|
||||
declare_idf(&Ds, &Dc, lvl);
|
||||
}
|
||||
|
||||
void update_ahead(struct idf *idf)
|
||||
update_ahead(idf)
|
||||
register struct idf *idf;
|
||||
{
|
||||
/* The tk_symb of the token ahead is updated in the light of new
|
||||
information about the identifier idf.
|
||||
*/
|
||||
int tk_symb = AHEAD;
|
||||
register int tk_symb = AHEAD;
|
||||
|
||||
if ( (tk_symb == IDENTIFIER || tk_symb == TYPE_IDENTIFIER) &&
|
||||
ahead.tk_idf == idf
|
||||
@ -627,7 +644,8 @@ void update_ahead(struct idf *idf)
|
||||
TYPE_IDENTIFIER : IDENTIFIER;
|
||||
}
|
||||
|
||||
void free_formals(struct formal *fm)
|
||||
free_formals(fm)
|
||||
register struct formal *fm;
|
||||
{
|
||||
while (fm) {
|
||||
struct formal *tmp = fm->next;
|
||||
|
||||
@ -4,8 +4,6 @@
|
||||
*/
|
||||
/* $Id$ */
|
||||
/* IDENTIFIER DESCRIPTOR */
|
||||
#ifndef LANG_CEM_CEMCOM_ANSI_IDF_STR
|
||||
#define LANG_CEM_CEMCOM_ANSI_IDF_STR
|
||||
|
||||
#include "nopp.h"
|
||||
|
||||
@ -49,5 +47,3 @@ struct dependency {
|
||||
|
||||
extern int level;
|
||||
extern struct idf *gen_idf();
|
||||
|
||||
#endif /* LANG_CEM_CEMCOM_ANSI_IDF_STR */
|
||||
@ -1,33 +0,0 @@
|
||||
/*
|
||||
* The Amsterdam Compiler Kit
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
#ifndef LANG_CEM_CEMCOM_ANSI_IDF_H
|
||||
#define LANG_CEM_CEMCOM_ANSI_IDF_H
|
||||
|
||||
#include "declar.h"
|
||||
#include "decspecs.h"
|
||||
#include "def.h"
|
||||
|
||||
/* lang/cem/cemcom.ansi/idf.c */
|
||||
void init_idf(void);
|
||||
struct idf *str2idf(char tg[], int cpy);
|
||||
struct idf *gen_idf(void);
|
||||
int is_anon_idf(struct idf *idf);
|
||||
void declare_idf(struct decspecs *ds, struct declarator *dc, int lvl);
|
||||
int actual_declaration(int sc, struct type *tp);
|
||||
void global_redecl(struct idf *idf, int new_sc, struct type *tp);
|
||||
int good_formal(struct def *def, struct idf *idf);
|
||||
void declare_params(struct declarator *dc);
|
||||
void idf_initialized(struct idf *idf);
|
||||
void declare_parameter(struct idf *idf);
|
||||
void declare_enum(struct type *tp, struct idf *idf, arith l);
|
||||
void check_formals(struct idf *idf, struct declarator *dc);
|
||||
void declare_formals(struct idf *idf, arith *fp);
|
||||
int regtype(struct type *tp);
|
||||
void add_def(struct idf *idf, int sc, struct type *tp, int lvl);
|
||||
void update_ahead(struct idf *idf);
|
||||
void free_formals(struct formal *fm);
|
||||
|
||||
#endif /* LANG_CEM_CEMCOM_ANSI_IDF_H */
|
||||
|
||||
@ -13,17 +13,11 @@
|
||||
#include <system.h>
|
||||
#include <alloc.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <flt_arith.h>
|
||||
#include <em_label.h>
|
||||
#include "class.h"
|
||||
#include "macro.h"
|
||||
#include "idf.h"
|
||||
#include "arith.h"
|
||||
#include "print.h"
|
||||
#include "expr.h"
|
||||
#include "error.h"
|
||||
#include "domacro.h"
|
||||
|
||||
extern char *sprint();
|
||||
|
||||
struct mkey {
|
||||
char *mk_reserved;
|
||||
@ -34,7 +28,6 @@ struct mkey {
|
||||
{"else", K_ELSE},
|
||||
{"endif", K_ENDIF},
|
||||
{"error", K_ERROR},
|
||||
{"warning", K_WARNING},
|
||||
{"if", K_IF},
|
||||
{"ifdef", K_IFDEF},
|
||||
{"ifndef", K_IFNDEF},
|
||||
@ -45,7 +38,7 @@ struct mkey {
|
||||
{0, K_UNKNOWN}
|
||||
};
|
||||
|
||||
void init_pp()
|
||||
init_pp()
|
||||
{
|
||||
static char *months[12] = {
|
||||
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
||||
@ -62,10 +55,10 @@ void init_pp()
|
||||
id_resmac field of the identifier.
|
||||
*/
|
||||
{
|
||||
struct mkey *mk = &mkey[0];
|
||||
register struct mkey *mk = &mkey[0];
|
||||
|
||||
while (mk->mk_reserved) {
|
||||
struct idf *idf = str2idf(mk->mk_reserved, 0);
|
||||
register struct idf *idf = str2idf(mk->mk_reserved, 0);
|
||||
|
||||
if (idf->id_resmac)
|
||||
fatal("maximum identifier length insufficient");
|
||||
|
||||
@ -1,12 +0,0 @@
|
||||
/*
|
||||
* The Amsterdam Compiler Kit
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
#ifndef LANG_CEM_CEMCOM_ANSI_INIT_H
|
||||
#define LANG_CEM_CEMCOM_ANSI_INIT_H
|
||||
|
||||
/* lang/cem/cemcom.ansi/init.c */
|
||||
void init_pp();
|
||||
|
||||
#endif /* LANG_CEM_CEMCOM_ANSI_INIT_H */
|
||||
|
||||
@ -7,16 +7,9 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "idf.h"
|
||||
#include "arith.h"
|
||||
#include <em_label.h>
|
||||
#include <flt_arith.h>
|
||||
#include "expr.h"
|
||||
#include "inputtype.h"
|
||||
#include "file_info.h"
|
||||
#include "input.h"
|
||||
#include "replace_loc.h"
|
||||
#include "error.h"
|
||||
|
||||
#define INP_PUSHBACK 3
|
||||
#define INP_TYPE struct file_info
|
||||
|
||||
@ -3,9 +3,6 @@
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
/* $Id$ */
|
||||
#ifndef LANG_CEM_CEMCOM_ANSI_INPUT_H
|
||||
#define LANG_CEM_CEMCOM_ANSI_INPUT_H
|
||||
|
||||
#define INP_PUSHBACK 3
|
||||
|
||||
#include <inp_pkg.spec>
|
||||
@ -16,5 +13,3 @@
|
||||
|
||||
extern int LexSave; /* last character read by GetChar */
|
||||
extern int GetChar(); /* character input, with trigraph parsing */
|
||||
|
||||
#endif /* LANG_CEM_CEMCOM_ANSI_INPUT_H */
|
||||
@ -14,8 +14,6 @@
|
||||
#include "l_lint.h"
|
||||
#endif /* LINT */
|
||||
#include "debug.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <alloc.h>
|
||||
#include <assert.h>
|
||||
#include "nobitfield.h"
|
||||
@ -23,36 +21,30 @@
|
||||
#include "arith.h"
|
||||
#include "label.h"
|
||||
#include "expr.h"
|
||||
#include "expr_loc.h"
|
||||
#include "type.h"
|
||||
#include "proto.h"
|
||||
#include "struct.h"
|
||||
#include "struct_loc.h"
|
||||
#include "field.h"
|
||||
#include "assert.h"
|
||||
#include "Lpars.h"
|
||||
#include "sizes.h"
|
||||
#include "align.h"
|
||||
#include "idf.h"
|
||||
#include "idf_loc.h"
|
||||
#include "level.h"
|
||||
#include "def.h"
|
||||
#include "ch3.h"
|
||||
#include "ival.h"
|
||||
#include "LLlex.h"
|
||||
#include "estack.h"
|
||||
#include "conversion.h"
|
||||
#include "cstoper.h"
|
||||
#include "error.h"
|
||||
|
||||
#define con_nullbyte() C_con_ucon("0", (arith)1)
|
||||
#define aggregate_type(tp) ((tp)->tp_fund == ARRAY || (tp)->tp_fund == STRUCT)
|
||||
|
||||
char *long2str();
|
||||
|
||||
char *strncpy();
|
||||
extern char options[];
|
||||
static int gen_error;
|
||||
static int pack_level;
|
||||
struct type **gen_tphead(), **gen_tpmiddle();
|
||||
struct sdef *gen_align_to_next();
|
||||
struct e_stack *p_stack;
|
||||
}
|
||||
|
||||
@ -60,7 +52,7 @@ struct e_stack *p_stack;
|
||||
*/
|
||||
/* 3.5 */
|
||||
|
||||
initial_value(struct type **tpp; struct expr **expp;) :
|
||||
initial_value(register struct type **tpp; register struct expr **expp;) :
|
||||
{ if (tpp) gen_tpcheck(tpp); }
|
||||
[
|
||||
{ if (pack_level == 0) gen_error = 0; }
|
||||
@ -130,9 +122,10 @@ initial_value_list(register struct type **tpp; struct expr **expp;)
|
||||
;
|
||||
|
||||
{
|
||||
void gen_tpcheck(struct type **tpp)
|
||||
gen_tpcheck(tpp)
|
||||
struct type **tpp;
|
||||
{
|
||||
struct type *tp;
|
||||
register struct type *tp;
|
||||
|
||||
if (gen_error) return;
|
||||
switch((tp = *tpp)->tp_fund) {
|
||||
@ -154,9 +147,11 @@ void gen_tpcheck(struct type **tpp)
|
||||
}
|
||||
}
|
||||
|
||||
void gen_simple_exp(struct type **tpp, struct expr **expp)
|
||||
gen_simple_exp(tpp, expp)
|
||||
struct type **tpp;
|
||||
struct expr **expp;
|
||||
{
|
||||
struct type *tp;
|
||||
register struct type *tp;
|
||||
|
||||
if (gen_error) return;
|
||||
tp = *tpp;
|
||||
@ -182,9 +177,12 @@ void gen_simple_exp(struct type **tpp, struct expr **expp)
|
||||
}
|
||||
}
|
||||
|
||||
struct type **arr_elem(struct type **tpp, struct e_stack *p)
|
||||
struct type **
|
||||
arr_elem(tpp, p)
|
||||
struct type **tpp;
|
||||
struct e_stack *p;
|
||||
{
|
||||
struct type *tp = *tpp;
|
||||
register struct type *tp = *tpp;
|
||||
|
||||
if (tp->tp_up->tp_fund == CHAR && AHEAD == STRING && p->elem_count == 1) {
|
||||
p->nelem = 1;
|
||||
@ -195,7 +193,10 @@ struct type **arr_elem(struct type **tpp, struct e_stack *p)
|
||||
return gen_tphead(&(tp->tp_up), 1);
|
||||
}
|
||||
|
||||
struct sdef *next_field(struct sdef *sd, struct e_stack *p)
|
||||
struct sdef *
|
||||
next_field(sd, p)
|
||||
register struct sdef *sd;
|
||||
register struct e_stack *p;
|
||||
{
|
||||
if (sd->sd_sdef)
|
||||
p->bytes_upto_here += zero_bytes(sd);
|
||||
@ -205,11 +206,13 @@ struct sdef *next_field(struct sdef *sd, struct e_stack *p)
|
||||
return sd->sd_sdef;
|
||||
}
|
||||
|
||||
struct type **gen_tphead(struct type **tpp, int nest)
|
||||
struct type **
|
||||
gen_tphead(tpp, nest)
|
||||
struct type **tpp;
|
||||
{
|
||||
struct type *tp = *tpp;
|
||||
struct e_stack *p;
|
||||
struct sdef *sd;
|
||||
register struct type *tp = *tpp;
|
||||
register struct e_stack *p;
|
||||
register struct sdef *sd;
|
||||
|
||||
if (tpp && *tpp == error_type) {
|
||||
gen_error = pack_level;
|
||||
@ -280,11 +283,12 @@ struct type **gen_tphead(struct type **tpp, int nest)
|
||||
}
|
||||
}
|
||||
|
||||
struct type **gen_tpmiddle()
|
||||
struct type **
|
||||
gen_tpmiddle()
|
||||
{
|
||||
struct type *tp;
|
||||
struct sdef *sd;
|
||||
struct e_stack *p = p_stack;
|
||||
register struct type *tp;
|
||||
register struct sdef *sd;
|
||||
register struct e_stack *p = p_stack;
|
||||
|
||||
if (gen_error) {
|
||||
if (p) return p->s_tpp;
|
||||
@ -338,9 +342,11 @@ again:
|
||||
}
|
||||
}
|
||||
|
||||
struct sdef *gen_align_to_next(struct e_stack *p)
|
||||
struct sdef *
|
||||
gen_align_to_next(p)
|
||||
register struct e_stack *p;
|
||||
{
|
||||
struct sdef *sd = p->s_def;
|
||||
register struct sdef *sd = p->s_def;
|
||||
|
||||
if (! sd) return sd;
|
||||
#ifndef NOBITFIELD
|
||||
@ -355,11 +361,11 @@ struct sdef *gen_align_to_next(struct e_stack *p)
|
||||
return sd;
|
||||
}
|
||||
|
||||
void gen_tpend()
|
||||
gen_tpend()
|
||||
{
|
||||
struct e_stack *p = p_stack;
|
||||
struct type *tp;
|
||||
struct sdef *sd;
|
||||
register struct e_stack *p = p_stack;
|
||||
register struct type *tp;
|
||||
register struct sdef *sd;
|
||||
int getout = 0;
|
||||
|
||||
while (!getout && p) {
|
||||
@ -411,9 +417,11 @@ void gen_tpend()
|
||||
In the latter case, only the first member is initialised and
|
||||
the rest is zeroed.
|
||||
*/
|
||||
void check_and_pad(struct expr **expp, struct type **tpp)
|
||||
check_and_pad(expp, tpp)
|
||||
struct type **tpp;
|
||||
struct expr **expp;
|
||||
{
|
||||
struct type *tp = *tpp;
|
||||
register struct type *tp = *tpp;
|
||||
|
||||
if (tp->tp_fund == ARRAY) {
|
||||
check_and_pad(expp, &(tp->tp_up)); /* first member */
|
||||
@ -424,7 +432,7 @@ void check_and_pad(struct expr **expp, struct type **tpp)
|
||||
tp = *tpp = construct_type(ARRAY, tp->tp_up,
|
||||
0, (arith)1, NO_PROTO);
|
||||
else {
|
||||
int dim = tp->tp_size / tp->tp_up->tp_size;
|
||||
register int dim = tp->tp_size / tp->tp_up->tp_size;
|
||||
/* pad remaining members with zeroes */
|
||||
while (--dim > 0)
|
||||
pad(tp->tp_up);
|
||||
@ -432,13 +440,13 @@ void check_and_pad(struct expr **expp, struct type **tpp)
|
||||
}
|
||||
else
|
||||
if (tp->tp_fund == STRUCT) {
|
||||
struct sdef *sd = tp->tp_sdef;
|
||||
register struct sdef *sd = tp->tp_sdef;
|
||||
|
||||
check_and_pad(expp, &(sd->sd_type));
|
||||
/* next selector is aligned by adding extra zeroes */
|
||||
if (sd->sd_sdef)
|
||||
zero_bytes(sd);
|
||||
while ( (sd = sd->sd_sdef) ) { /* pad remaining selectors */
|
||||
while (sd = sd->sd_sdef) { /* pad remaining selectors */
|
||||
pad(sd->sd_type);
|
||||
if (sd->sd_sdef)
|
||||
zero_bytes(sd);
|
||||
@ -446,7 +454,7 @@ void check_and_pad(struct expr **expp, struct type **tpp)
|
||||
}
|
||||
else if (tp->tp_fund == UNION) {
|
||||
/* only the first selector can be initialized */
|
||||
struct sdef *sd = tp->tp_sdef;
|
||||
register struct sdef *sd = tp->tp_sdef;
|
||||
|
||||
check_and_pad(expp, &(sd->sd_type));
|
||||
}
|
||||
@ -457,10 +465,11 @@ void check_and_pad(struct expr **expp, struct type **tpp)
|
||||
/* pad() fills an element of type tp with zeroes.
|
||||
If the element is an aggregate, pad() is called recursively.
|
||||
*/
|
||||
void pad(struct type *tpx)
|
||||
pad(tpx)
|
||||
struct type *tpx;
|
||||
{
|
||||
struct type *tp = tpx;
|
||||
arith sz = tp->tp_size;
|
||||
register struct type *tp = tpx;
|
||||
register arith sz = tp->tp_size;
|
||||
|
||||
gen_tpcheck(&tpx);
|
||||
if (gen_error) return;
|
||||
@ -487,14 +496,16 @@ void pad(struct type *tpx)
|
||||
No further comment is needed to explain the internal structure
|
||||
of this straightforward function.
|
||||
*/
|
||||
void check_ival(struct expr **expp, struct type *tp)
|
||||
check_ival(expp, tp)
|
||||
register struct type *tp;
|
||||
struct expr **expp;
|
||||
{
|
||||
/* The philosophy here is that ch3cast puts an explicit
|
||||
conversion node in front of the expression if the types
|
||||
are not compatible. In this case, the initialisation
|
||||
expression is no longer a constant.
|
||||
*/
|
||||
struct expr *expr = *expp;
|
||||
register struct expr *expr = *expp;
|
||||
|
||||
switch (tp->tp_fund) {
|
||||
case CHAR:
|
||||
@ -598,13 +609,13 @@ and also to prevent runtime coercions for compile-time constants.
|
||||
a string constant.
|
||||
Alignment is taken care of.
|
||||
*/
|
||||
|
||||
/* tpp -> type tp = array of characters */
|
||||
void ch_array(struct type **tpp, struct expr *ex)
|
||||
ch_array(tpp, ex)
|
||||
struct type **tpp; /* type tp = array of characters */
|
||||
struct expr *ex;
|
||||
{
|
||||
struct type *tp = *tpp;
|
||||
int length = ex->SG_LEN, i;
|
||||
char *to, *from, *s;
|
||||
register struct type *tp = *tpp;
|
||||
register int length = ex->SG_LEN, i;
|
||||
register char *to, *from, *s;
|
||||
|
||||
ASSERT(ex->ex_class == String);
|
||||
if (tp->tp_size == (arith)-1) {
|
||||
@ -640,7 +651,10 @@ void ch_array(struct type **tpp, struct expr *ex)
|
||||
/* As long as some parts of the pipeline cannot handle very long string
|
||||
constants, string constants are written out in chunks
|
||||
*/
|
||||
void str_cst(char *str, int len, int inrom)
|
||||
str_cst(str, len, inrom)
|
||||
register char *str;
|
||||
register int len;
|
||||
int inrom;
|
||||
{
|
||||
int chunksize = ((127 + (int) word_size) / (int) word_size) * (int) word_size;
|
||||
|
||||
@ -664,7 +678,9 @@ void str_cst(char *str, int len, int inrom)
|
||||
"throws" the result of "field" out if the current selector
|
||||
is the last of this number of fields stored at the same address.
|
||||
*/
|
||||
void put_bf(struct type *tp, arith val)
|
||||
put_bf(tp, val)
|
||||
struct type *tp;
|
||||
arith val;
|
||||
{
|
||||
static long field = (arith)0;
|
||||
static arith offset = (arith)-1;
|
||||
@ -692,7 +708,9 @@ void put_bf(struct type *tp, arith val)
|
||||
}
|
||||
#endif /* NOBITFIELD */
|
||||
|
||||
int zero_bytes(struct sdef *sd)
|
||||
int
|
||||
zero_bytes(sd)
|
||||
register struct sdef *sd;
|
||||
{
|
||||
/* fills the space between a selector of a struct
|
||||
and the next selector of that struct with zero-bytes.
|
||||
@ -706,7 +724,10 @@ int zero_bytes(struct sdef *sd)
|
||||
return count;
|
||||
}
|
||||
|
||||
int valid_type(struct type *tp, char *str)
|
||||
int
|
||||
valid_type(tp, str)
|
||||
struct type *tp;
|
||||
char *str;
|
||||
{
|
||||
ASSERT(tp!=(struct type *)0);
|
||||
if (tp->tp_size < 0) {
|
||||
@ -716,9 +737,10 @@ int valid_type(struct type *tp, char *str)
|
||||
return 1;
|
||||
}
|
||||
|
||||
void con_int(struct expr *ex)
|
||||
con_int(ex)
|
||||
register struct expr *ex;
|
||||
{
|
||||
struct type *tp = ex->ex_type;
|
||||
register struct type *tp = ex->ex_type;
|
||||
|
||||
ASSERT(is_cp_cst(ex));
|
||||
if (tp->tp_unsigned)
|
||||
@ -729,13 +751,14 @@ void con_int(struct expr *ex)
|
||||
C_con_icon(long2str((long)ex->VL_VALUE, 10), tp->tp_size);
|
||||
}
|
||||
|
||||
void illegal_init_cst(struct expr *ex)
|
||||
illegal_init_cst(ex)
|
||||
struct expr *ex;
|
||||
{
|
||||
expr_error(ex, "illegal initialization constant");
|
||||
gen_error = pack_level;
|
||||
}
|
||||
|
||||
void too_many_initialisers()
|
||||
too_many_initialisers()
|
||||
{
|
||||
error("too many initializers");
|
||||
gen_error = pack_level;
|
||||
|
||||
@ -1,66 +0,0 @@
|
||||
/*
|
||||
* The Amsterdam Compiler Kit
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
#ifndef LANG_CEM_CEMCOM_ANSI_IVAL_H
|
||||
#define LANG_CEM_CEMCOM_ANSI_IVAL_H
|
||||
|
||||
#include "estack.h"
|
||||
|
||||
/* lang/cem/cemcom.ansi/ival.g */
|
||||
void gen_tpcheck(struct type **tpp);
|
||||
void gen_simple_exp(struct type **tpp, struct expr **expp);
|
||||
struct type **arr_elem(struct type **tpp, struct e_stack *p);
|
||||
struct sdef *next_field(struct sdef *sd, struct e_stack *p);
|
||||
struct type **gen_tphead(struct type **tpp, int nest);
|
||||
struct type **gen_tpmiddle();
|
||||
struct sdef *gen_align_to_next(struct e_stack *p);
|
||||
void gen_tpend();
|
||||
/* check_and_pad() is given a simple initialisation expression
|
||||
where the type can be either a simple or an aggregate type.
|
||||
In the latter case, only the first member is initialised and
|
||||
the rest is zeroed.
|
||||
*/
|
||||
void check_and_pad(struct expr **expp, struct type **tpp);
|
||||
/* pad() fills an element of type tp with zeroes.
|
||||
If the element is an aggregate, pad() is called recursively.
|
||||
*/
|
||||
void pad(struct type *tpx);
|
||||
/* check_ival() checks whether the initialisation of an element
|
||||
of a fundamental type is legal and, if so, performs the initialisation
|
||||
by directly generating the necessary code.
|
||||
No further comment is needed to explain the internal structure
|
||||
of this straightforward function.
|
||||
*/
|
||||
void check_ival(struct expr **expp, struct type *tp);
|
||||
/* ch_array() initialises an array of characters when given
|
||||
a string constant.
|
||||
Alignment is taken care of.
|
||||
*/
|
||||
|
||||
/* tpp -> type tp = array of characters */
|
||||
void ch_array(struct type **tpp, struct expr *ex);
|
||||
/* As long as some parts of the pipeline cannot handle very long string
|
||||
constants, string constants are written out in chunks
|
||||
*/
|
||||
void str_cst(char *str, int len, int inrom);
|
||||
#ifndef NOBITFIELD
|
||||
/* put_bf() takes care of the initialisation of (bit-)field
|
||||
selectors of a struct: each time such an initialisation takes place,
|
||||
put_bf() is called instead of the normal code generating routines.
|
||||
Put_bf() stores the given integral value into "field" and
|
||||
"throws" the result of "field" out if the current selector
|
||||
is the last of this number of fields stored at the same address.
|
||||
*/
|
||||
void put_bf(struct type *tp, arith val);
|
||||
#endif /* NOBITFIELD */
|
||||
|
||||
int zero_bytes(struct sdef *sd);
|
||||
int valid_type(struct type *tp, char *str);
|
||||
void con_int(struct expr *ex);
|
||||
void illegal_init_cst(struct expr *ex);
|
||||
void too_many_initialisers();
|
||||
|
||||
|
||||
#endif /* LANG_CEM_CEMCOM_ANSI_IVAL_H */
|
||||
|
||||
@ -14,8 +14,6 @@
|
||||
* to terminate the compilation process.
|
||||
*/
|
||||
|
||||
#include "blocks.h"
|
||||
|
||||
#define store_block(sz, al)
|
||||
#define load_block(sz, al)
|
||||
|
||||
|
||||
@ -26,9 +26,8 @@
|
||||
#include "type.h"
|
||||
#include "level.h"
|
||||
#include "l_state.h"
|
||||
#include "conversion.h"
|
||||
#include <symbol2str.h>
|
||||
|
||||
extern char *symbol2str();
|
||||
extern struct type *func_type;
|
||||
|
||||
PRIVATE lint_enum_arith();
|
||||
|
||||
@ -13,20 +13,18 @@
|
||||
#include "def.h"
|
||||
#include "type.h"
|
||||
#include "stack.h"
|
||||
#include "error.h"
|
||||
#include "idf_loc.h"
|
||||
#include "stack_loc.h"
|
||||
|
||||
extern char options[];
|
||||
|
||||
void enter_label(struct idf *idf, int defining)
|
||||
enter_label(idf, defining)
|
||||
register struct idf *idf;
|
||||
{
|
||||
/* The identifier idf is entered as a label. If it is new,
|
||||
it is entered into the idf list with the largest possible
|
||||
scope, i.e., on the lowest possible level.
|
||||
If defining, the label comes from a label statement.
|
||||
*/
|
||||
struct def *def = idf->id_label;
|
||||
register struct def *def = idf->id_label;
|
||||
|
||||
if (def) {
|
||||
if (defining && def->df_initialized)
|
||||
@ -46,7 +44,8 @@ void enter_label(struct idf *idf, int defining)
|
||||
def->df_initialized = 1;
|
||||
}
|
||||
|
||||
void unstack_label(struct idf *idf)
|
||||
unstack_label(idf)
|
||||
register struct idf *idf;
|
||||
{
|
||||
/* The scope in which the label idf occurred is left.
|
||||
*/
|
||||
|
||||
@ -4,8 +4,6 @@
|
||||
*/
|
||||
/* $Id$ */
|
||||
/* L A B E L D E F I N I T I O N */
|
||||
#ifndef LANG_CEM_CEMCOM_ANSI_LABEL_H
|
||||
#define LANG_CEM_CEMCOM_ANSI_LABEL_H
|
||||
|
||||
#include <em_label.h> /* obtain definition of "label" */
|
||||
|
||||
@ -28,10 +26,3 @@ extern label datlab_count;
|
||||
not be there, and if it is there, it may be from a
|
||||
declaration or another application.
|
||||
*/
|
||||
|
||||
struct idf;
|
||||
|
||||
void enter_label(struct idf *idf, int defining);
|
||||
void unstack_label(struct idf *idf);
|
||||
|
||||
#endif /* LANG_CEM_CEMCOM_ANSI_LABEL_H */
|
||||
@ -48,6 +48,5 @@ struct macro {
|
||||
#define K_LINE 10
|
||||
#define K_PRAGMA 11
|
||||
#define K_UNDEF 12
|
||||
#define K_WARNING 13
|
||||
#define K_FILE 100 /* for dependency generator */
|
||||
#endif /* NOPP */
|
||||
|
||||
@ -5,13 +5,10 @@
|
||||
/* $Id$ */
|
||||
/* MAIN PROGRAM */
|
||||
|
||||
#include <string.h>
|
||||
#include "lint.h"
|
||||
#include <system.h>
|
||||
#include "print.h"
|
||||
#include "debug.h"
|
||||
#include "nopp.h"
|
||||
#include "label.h"
|
||||
#include "trgt_sizes.h"
|
||||
#include "use_tmp.h"
|
||||
#include "inputtype.h"
|
||||
@ -32,21 +29,9 @@
|
||||
#include "align.h"
|
||||
#include "macro.h"
|
||||
#include "assert.h"
|
||||
#include "code_c.h"
|
||||
#include "cstoper.h"
|
||||
#include "init.h"
|
||||
#include "options.h"
|
||||
#include "main.h"
|
||||
#include "error.h"
|
||||
#include "stack.h"
|
||||
#include "stack_loc.h"
|
||||
#include "idf_loc.h"
|
||||
#include "program.h"
|
||||
#include "tokenname.h"
|
||||
|
||||
#include <symbol2str.h>
|
||||
|
||||
extern struct tokenname tkidf[];
|
||||
extern char *symbol2str();
|
||||
extern char options[128];
|
||||
|
||||
#ifndef NOPP
|
||||
@ -98,7 +83,8 @@ arith ifval; /* ifval will contain the result of the #if expression */
|
||||
|
||||
char *prog_name;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
main(argc, argv)
|
||||
char *argv[];
|
||||
{
|
||||
/* parse and interpret the command line options */
|
||||
prog_name = argv[0];
|
||||
@ -153,13 +139,15 @@ int main(int argc, char *argv[])
|
||||
#ifndef NOPP
|
||||
|
||||
struct dependency *file_head;
|
||||
extern char *strrchr();
|
||||
|
||||
void list_dependencies(char *source)
|
||||
list_dependencies(source)
|
||||
char *source;
|
||||
{
|
||||
struct dependency *p = file_head;
|
||||
register struct dependency *p = file_head;
|
||||
|
||||
if (source) {
|
||||
char *s = strrchr(source, '.');
|
||||
register char *s = strrchr(source, '.');
|
||||
|
||||
if (s && *(s+1)) {
|
||||
s++;
|
||||
@ -169,7 +157,7 @@ void list_dependencies(char *source)
|
||||
* object generated, so don't include the pathname
|
||||
* leading to it.
|
||||
*/
|
||||
if ( (s = strrchr(source, '/')) ) {
|
||||
if (s = strrchr(source, '/')) {
|
||||
source = s + 1;
|
||||
}
|
||||
}
|
||||
@ -184,12 +172,13 @@ void list_dependencies(char *source)
|
||||
}
|
||||
}
|
||||
|
||||
void add_dependency(char *s)
|
||||
add_dependency(s)
|
||||
char *s;
|
||||
{
|
||||
struct idf *p = str2idf(s, 1);
|
||||
register struct idf *p = str2idf(s, 1);
|
||||
|
||||
if (! p->id_resmac) {
|
||||
struct dependency *q = new_dependency();
|
||||
register struct dependency *q = new_dependency();
|
||||
|
||||
p->id_resmac = K_FILE;
|
||||
q->dep_idf = p;
|
||||
@ -198,7 +187,8 @@ void add_dependency(char *s)
|
||||
}
|
||||
}
|
||||
|
||||
void dependency(char *s, char *source)
|
||||
dependency(s, source)
|
||||
char *s, *source;
|
||||
{
|
||||
if (options['i'] && !strncmp(s, "/usr/include/", 13)) {
|
||||
return;
|
||||
@ -217,11 +207,12 @@ char *source = 0;
|
||||
char *nmlist = 0;
|
||||
#endif /* GEN_NM_LIST */
|
||||
|
||||
void compile(int argc, char *argv[])
|
||||
compile(argc, argv)
|
||||
char *argv[];
|
||||
{
|
||||
char *result;
|
||||
#ifndef LINT
|
||||
char *destination = 0;
|
||||
register char *destination = 0;
|
||||
#endif /* LINT */
|
||||
|
||||
#ifdef DEBUG
|
||||
@ -327,7 +318,7 @@ void compile(int argc, char *argv[])
|
||||
#endif /* NOPP */
|
||||
}
|
||||
|
||||
void init()
|
||||
init()
|
||||
{
|
||||
init_cst(); /* initialize variables of "cstoper.c" */
|
||||
reserve(tkidf); /* mark the C reserved words as such */
|
||||
@ -392,7 +383,8 @@ void init()
|
||||
stack_level();
|
||||
}
|
||||
|
||||
void init_specials(struct sp_id *si)
|
||||
init_specials(si)
|
||||
register struct sp_id *si;
|
||||
{
|
||||
while (si->si_identifier) {
|
||||
struct idf *idf = str2idf(si->si_identifier, 0);
|
||||
@ -406,7 +398,7 @@ void init_specials(struct sp_id *si)
|
||||
|
||||
#ifdef DEBUG
|
||||
#ifndef NOPP
|
||||
void preprocess()
|
||||
preprocess()
|
||||
{
|
||||
/* preprocess() is the "stand-alone" preprocessor which
|
||||
consecutively calls the lexical analyzer LLlex() to get
|
||||
@ -476,7 +468,7 @@ void preprocess()
|
||||
}
|
||||
#endif /* NOPP */
|
||||
|
||||
void Info()
|
||||
Info()
|
||||
{
|
||||
extern int cnt_string_cst, cnt_formal,
|
||||
cnt_decl_unary, cnt_def, cnt_expr, cnt_field,
|
||||
@ -508,12 +500,14 @@ void Info()
|
||||
}
|
||||
#endif /* DEBUG */
|
||||
|
||||
void No_Mem() /* called by alloc package */
|
||||
void
|
||||
No_Mem() /* called by alloc package */
|
||||
{
|
||||
fatal("out of memory");
|
||||
}
|
||||
|
||||
void C_failed() /* called by EM_code module */
|
||||
void
|
||||
C_failed() /* called by EM_code module */
|
||||
{
|
||||
fatal("write failed");
|
||||
}
|
||||
|
||||
@ -1,20 +0,0 @@
|
||||
/*
|
||||
* The Amsterdam Compiler Kit
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
#ifndef LANG_CEM_CEMCOM_ANSI_MAIN_H
|
||||
#define LANG_CEM_CEMCOM_ANSI_MAIN_H
|
||||
|
||||
/* lang/cem/cemcom.ansi/main.c */
|
||||
int main(int argc, char *argv[]);
|
||||
void list_dependencies(char *source);
|
||||
void add_dependency(char *s);
|
||||
void dependency(char *s, char *source);
|
||||
void compile(int argc, char *argv[]);
|
||||
void init(void);
|
||||
void init_specials(struct sp_id *si);
|
||||
void No_Mem(void);
|
||||
void C_failed(void);
|
||||
|
||||
#endif /* LANG_CEM_CEMCOM_ANSI_MAIN_H */
|
||||
|
||||
@ -3,11 +3,11 @@
|
||||
sed -e '
|
||||
s:^.*[ ]ALLOCDEF[ ].*"\(.*\)"[ ]*\([0-9][0-9]*\).*$:\
|
||||
/* allocation definitions of struct \1 */\
|
||||
extern char *st_alloc(char **, unsigned int, int);\
|
||||
extern char *st_alloc();\
|
||||
extern struct \1 *h_\1;\
|
||||
#ifdef DEBUG\
|
||||
extern int cnt_\1;\
|
||||
extern char *std_alloc(char **, unsigned int, int, int *);\
|
||||
extern char *std_alloc();\
|
||||
#define new_\1() ((struct \1 *) std_alloc((char **)\&h_\1, sizeof(struct \1), \2, \&cnt_\1))\
|
||||
#else\
|
||||
#define new_\1() ((struct \1 *) st_alloc((char **)\&h_\1, sizeof(struct \1), \2))\
|
||||
|
||||
@ -5,7 +5,9 @@ cat <<'--EOT--'
|
||||
/* $Id$ */
|
||||
#include "Lpars.h"
|
||||
|
||||
char *symbol2str(int tok)
|
||||
char *
|
||||
symbol2str(tok)
|
||||
int tok;
|
||||
{
|
||||
#define SIZBUF 8
|
||||
/* allow for a few invocations in f.i. an argument list */
|
||||
|
||||
@ -22,9 +22,6 @@
|
||||
#include "use_tmp.h"
|
||||
#include "dataflow.h"
|
||||
#include "dbsymtab.h"
|
||||
#include "conversion.h"
|
||||
#include "error.h"
|
||||
#include "domacro.h"
|
||||
|
||||
#ifndef NOPP
|
||||
extern char **inctable;
|
||||
@ -44,11 +41,12 @@ char loptions[128]; /* one for every char */
|
||||
extern int idfsize;
|
||||
extern int density;
|
||||
|
||||
static int txt2int(char **tp);
|
||||
static int txt2int();
|
||||
|
||||
void do_option(char *text)
|
||||
do_option(text)
|
||||
char *text;
|
||||
{
|
||||
char opt;
|
||||
register char opt;
|
||||
|
||||
next_option: /* to allow combined one-char options */
|
||||
switch (opt = *text++) {
|
||||
@ -65,7 +63,7 @@ next_option: /* to allow combined one-char options */
|
||||
break;
|
||||
|
||||
case '-':
|
||||
options[*(unsigned char *)text++] = 1; /* flags, debug options etc. */
|
||||
options[*text++] = 1; /* flags, debug options etc. */
|
||||
goto next_option;
|
||||
|
||||
#ifndef LINT
|
||||
@ -78,7 +76,7 @@ next_option: /* to allow combined one-char options */
|
||||
break;
|
||||
case 'i':
|
||||
case 'm':
|
||||
options[(unsigned char)opt] = 1;
|
||||
options[opt] = 1;
|
||||
break;
|
||||
#endif /* NOPP */
|
||||
#endif /* LINT */
|
||||
@ -99,7 +97,7 @@ next_option: /* to allow combined one-char options */
|
||||
case 'w': /* no warnings will be given */
|
||||
case 's': /* no stricts will be given */
|
||||
case 'o': /* no complaints about old-style */
|
||||
options[(unsigned char)opt] = 1;
|
||||
options[opt] = 1;
|
||||
goto next_option;
|
||||
case 'a': /* suppress all but errors diagnostics */
|
||||
options['w'] = 1; /* implies -a */
|
||||
@ -121,17 +119,17 @@ next_option: /* to allow combined one-char options */
|
||||
|
||||
#ifndef NOPP
|
||||
case 'D' : { /* -Dname : predefine name */
|
||||
char *cp = text, *name, *mactext;
|
||||
register char *cp = text, *name, *mactext;
|
||||
unsigned maclen;
|
||||
|
||||
if (class(*(unsigned char *)cp) != STIDF && class(*(unsigned char *)cp) != STELL) {
|
||||
if (class(*cp) != STIDF && class(*cp) != STELL) {
|
||||
error("identifier missing in -D%s", text);
|
||||
break;
|
||||
}
|
||||
|
||||
name = cp;
|
||||
|
||||
while (*cp && in_idf(*(unsigned char *)cp)) {
|
||||
while (*cp && in_idf(*cp)) {
|
||||
++cp;
|
||||
}
|
||||
|
||||
@ -157,7 +155,7 @@ next_option: /* to allow combined one-char options */
|
||||
case 'I' : /* -Ipath : insert "path" into include list */
|
||||
if (*text) {
|
||||
int i;
|
||||
char *new = text;
|
||||
register char *new = text;
|
||||
|
||||
if (inc_total >= inc_max) {
|
||||
inctable = (char **)
|
||||
@ -216,10 +214,10 @@ next_option: /* to allow combined one-char options */
|
||||
#ifndef NOCROSS
|
||||
case 'V' : /* set object sizes and alignment requirements */
|
||||
{
|
||||
arith sz, algn;
|
||||
register arith sz, algn;
|
||||
char c;
|
||||
|
||||
while ( (c = *text++) ) {
|
||||
while (c = *text++) {
|
||||
sz = txt2int(&text);
|
||||
algn = 0;
|
||||
if (*text == '.') {
|
||||
@ -304,7 +302,9 @@ next_option: /* to allow combined one-char options */
|
||||
}
|
||||
}
|
||||
|
||||
static int txt2int(char **tp)
|
||||
static int
|
||||
txt2int(tp)
|
||||
register char **tp;
|
||||
{
|
||||
/* the integer pointed to by *tp is read, while increasing
|
||||
*tp; the resulting value is yielded.
|
||||
|
||||
@ -1,12 +0,0 @@
|
||||
/*
|
||||
* The Amsterdam Compiler Kit
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
#ifndef LANG_CEM_CEMCOM_ANSI_OPTIONS_H
|
||||
#define LANG_CEM_CEMCOM_ANSI_OPTIONS_H
|
||||
|
||||
/* lang/cem/cemcom.ansi/options.c */
|
||||
void do_option(char *text);
|
||||
|
||||
#endif /* LANG_CEM_CEMCOM_ANSI_OPTIONS_H */
|
||||
|
||||
@ -7,8 +7,6 @@
|
||||
|
||||
#include "debug.h"
|
||||
#include "idf.h"
|
||||
#include "skip.h"
|
||||
#include "domacro.h"
|
||||
|
||||
#define P_UNKNOWN 0
|
||||
#define NR_PRAGMAS 0
|
||||
@ -20,12 +18,14 @@ struct pkey {
|
||||
{0, P_UNKNOWN}
|
||||
};
|
||||
|
||||
void do_pragma()
|
||||
extern struct idf *GetIdentifier();
|
||||
|
||||
do_pragma()
|
||||
{
|
||||
#if NR_PRAGMAS
|
||||
struct pkey *pkp = &pragmas[0];
|
||||
register struct pkey *pkp = &pragmas[0];
|
||||
#endif
|
||||
struct idf *id = GetIdentifier(1);
|
||||
register struct idf *id = GetIdentifier(1);
|
||||
|
||||
if (id != (struct idf *)0) {
|
||||
#if NR_PRAGMAS
|
||||
|
||||
@ -1,12 +0,0 @@
|
||||
/*
|
||||
* The Amsterdam Compiler Kit
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
#ifndef LANG_CEM_CEMCOM_ANSI_PRAGMA_H
|
||||
#define LANG_CEM_CEMCOM_ANSI_PRAGMA_H
|
||||
|
||||
/* lang/cem/cemcom.ansi/pragma.c */
|
||||
int do_pragma(void);
|
||||
|
||||
#endif /* LANG_CEM_CEMCOM_ANSI_PRAGMA_H */
|
||||
|
||||
@ -52,22 +52,13 @@
|
||||
#include "arith.h"
|
||||
#include "LLlex.h"
|
||||
#include "idf.h"
|
||||
#include "idf_loc.h"
|
||||
#include "label.h"
|
||||
#include "type.h"
|
||||
#include "declar.h"
|
||||
#include "decspecs.h"
|
||||
#include "code.h"
|
||||
#include "expr.h"
|
||||
#include "expr_loc.h"
|
||||
#include "def.h"
|
||||
#include "code_c.h"
|
||||
#include "error.h"
|
||||
#include "stack.h"
|
||||
#include "stack_loc.h"
|
||||
#include "declarator.h"
|
||||
#include "proto_loc.h"
|
||||
|
||||
#ifdef LINT
|
||||
#include "l_lint.h"
|
||||
#endif /* LINT */
|
||||
@ -76,6 +67,7 @@
|
||||
extern arith ifval;
|
||||
#endif /* NOPP */
|
||||
|
||||
extern error();
|
||||
}
|
||||
|
||||
control_if_expression
|
||||
|
||||
@ -1,16 +0,0 @@
|
||||
/*
|
||||
* The Amsterdam Compiler Kit
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
#ifndef LANG_CEM_CEMCOM_ANSI_PROGRAM_H
|
||||
#define LANG_CEM_CEMCOM_ANSI_PROGRAM_H
|
||||
|
||||
/* lang/cem/cemcom.ansi/program.g */
|
||||
|
||||
void If_expr(void);
|
||||
void C_program(void);
|
||||
|
||||
void LL1_control_if_expression(void);
|
||||
void LL0_program(void);
|
||||
|
||||
#endif /* LANG_CEM_CEMCOM_ANSI_PROGRAM_H */
|
||||
@ -17,28 +17,23 @@
|
||||
#include "arith.h"
|
||||
#include "align.h"
|
||||
#include "stack.h"
|
||||
#include "stack_loc.h"
|
||||
#include "idf.h"
|
||||
#include "idf_loc.h"
|
||||
#include "def.h"
|
||||
#include "type.h"
|
||||
#include "ch3.h"
|
||||
#include "struct.h"
|
||||
#include "label.h"
|
||||
#include "expr.h"
|
||||
#include "declar.h"
|
||||
#include "decspecs.h"
|
||||
#include "proto.h"
|
||||
#include "proto_loc.h"
|
||||
#include "assert.h"
|
||||
#include "conversion.h"
|
||||
#include "error.h"
|
||||
|
||||
extern char options[];
|
||||
|
||||
void check_for_void(struct proto *pl)
|
||||
check_for_void(pl)
|
||||
register struct proto *pl;
|
||||
{
|
||||
int errcnt = 0;
|
||||
register int errcnt = 0;
|
||||
|
||||
if (!pl) return;
|
||||
if ((pl->pl_flag & PL_VOID) && !(pl->next)) return;
|
||||
@ -54,7 +49,11 @@ void check_for_void(struct proto *pl)
|
||||
}
|
||||
}
|
||||
|
||||
void add_proto(struct proto *pl, struct decspecs *ds, struct declarator *dc, int lvl)
|
||||
add_proto(pl, ds, dc, lvl)
|
||||
struct proto *pl;
|
||||
struct decspecs *ds;
|
||||
struct declarator *dc;
|
||||
int lvl;
|
||||
{
|
||||
/* The full typed identifier or abstract type, described
|
||||
by the structures decspecs and declarator are turned
|
||||
@ -63,10 +62,10 @@ void add_proto(struct proto *pl, struct decspecs *ds, struct declarator *dc, int
|
||||
later on it's decided whether they were prototypes
|
||||
or actual declarations.
|
||||
*/
|
||||
struct idf *idf = dc->dc_idf;
|
||||
struct def *def = idf ? idf->id_def : (struct def *)0;
|
||||
int sc = ds->ds_sc;
|
||||
struct type *type;
|
||||
register struct idf *idf = dc->dc_idf;
|
||||
register struct def *def = idf ? idf->id_def : (struct def *)0;
|
||||
register int sc = ds->ds_sc;
|
||||
register struct type *type;
|
||||
char formal_array = 0;
|
||||
|
||||
ASSERT(ds->ds_type != (struct type *)0);
|
||||
@ -123,7 +122,7 @@ void add_proto(struct proto *pl, struct decspecs *ds, struct declarator *dc, int
|
||||
} else if (idf != (struct idf *)0) {
|
||||
/* New definition, redefinition hides earlier one
|
||||
*/
|
||||
struct def *newdef = new_def();
|
||||
register struct def *newdef = new_def();
|
||||
|
||||
newdef->next = def;
|
||||
newdef->df_level = lvl;
|
||||
@ -173,7 +172,7 @@ struct type *tp;
|
||||
struct idf **idpp;
|
||||
{
|
||||
struct tag *tg = (struct tag *)0;
|
||||
int fund = tp->tp_fund;
|
||||
register int fund = tp->tp_fund;
|
||||
|
||||
while (fund == FIELD || fund == POINTER
|
||||
|| fund == ARRAY || fund == FUNCTION) {
|
||||
@ -190,16 +189,17 @@ struct idf **idpp;
|
||||
}
|
||||
|
||||
|
||||
void declare_protos(struct declarator *dc)
|
||||
declare_protos(dc)
|
||||
register struct declarator *dc;
|
||||
{
|
||||
/* At this points we know that the idf's in protolist are formal
|
||||
parameters. So it's time to declare them at level L_FORMAL2.
|
||||
*/
|
||||
struct stack_level *stl = stack_level_of(L_FORMAL1);
|
||||
struct decl_unary *du;
|
||||
struct type *type;
|
||||
struct proto *pl;
|
||||
struct def *def;
|
||||
register struct decl_unary *du;
|
||||
register struct type *type;
|
||||
register struct proto *pl;
|
||||
register struct def *def;
|
||||
|
||||
#ifdef DEBUG
|
||||
if (options['t'])
|
||||
@ -265,7 +265,8 @@ void declare_protos(struct declarator *dc)
|
||||
}
|
||||
|
||||
|
||||
void update_proto(struct type *tp, struct type *otp)
|
||||
update_proto(tp, otp)
|
||||
register struct type *tp, *otp;
|
||||
{
|
||||
/* This routine performs the proto type updates.
|
||||
Consider the following code:
|
||||
@ -278,7 +279,7 @@ void update_proto(struct type *tp, struct type *otp)
|
||||
This routine will silently update all lists,
|
||||
and removes the redundant occupied space.
|
||||
*/
|
||||
struct proto *pl, *opl;
|
||||
register struct proto *pl, *opl;
|
||||
|
||||
if (tp == otp) return;
|
||||
if (!tp || !otp) return;
|
||||
@ -315,11 +316,12 @@ void update_proto(struct type *tp, struct type *otp)
|
||||
/* struct/union and enum tags can be declared inside prototypes
|
||||
* remove them from the symbol-table
|
||||
*/
|
||||
void remove_proto_tag(struct type *tp)
|
||||
remove_proto_tag(tp)
|
||||
struct type *tp;
|
||||
{
|
||||
struct idf *ident;
|
||||
struct tag *tgp, **tgpp;
|
||||
int fund = tp->tp_fund;
|
||||
register struct idf *ident;
|
||||
register struct tag *tgp, **tgpp;
|
||||
register int fund = tp->tp_fund;
|
||||
|
||||
while (fund == FIELD || fund == POINTER
|
||||
|| fund == ARRAY || fund == FUNCTION) {
|
||||
@ -353,12 +355,13 @@ void remove_proto_tag(struct type *tp)
|
||||
free_tag(tgp);
|
||||
}
|
||||
|
||||
void remove_proto_idfs(struct proto *pl)
|
||||
remove_proto_idfs(pl)
|
||||
register struct proto *pl;
|
||||
{
|
||||
/* Remove all the identifier definitions from the
|
||||
prototype list.
|
||||
*/
|
||||
struct def *def;
|
||||
register struct def *def;
|
||||
|
||||
while (pl) {
|
||||
if (pl->pl_idf) {
|
||||
@ -381,7 +384,8 @@ void remove_proto_idfs(struct proto *pl)
|
||||
}
|
||||
}
|
||||
|
||||
void call_proto(struct expr **expp)
|
||||
call_proto(expp)
|
||||
register struct expr **expp;
|
||||
{
|
||||
/* If the function specified by (*expp)->OP_LEFT has a prototype,
|
||||
the parameters are converted according the rules specified in
|
||||
@ -390,13 +394,13 @@ void call_proto(struct expr **expp)
|
||||
under ellipsis clause the old parameters conversion stuff
|
||||
applies.
|
||||
*/
|
||||
struct expr *left = (*expp)->OP_LEFT;
|
||||
struct expr *right = (*expp)->OP_RIGHT;
|
||||
struct proto *pl = NO_PROTO;
|
||||
register struct expr *left = (*expp)->OP_LEFT;
|
||||
register struct expr *right = (*expp)->OP_RIGHT;
|
||||
register struct proto *pl = NO_PROTO;
|
||||
static struct proto ellipsis = { 0, 0, 0, PL_ELLIPSIS };
|
||||
|
||||
if (left != NILEXPR) { /* in case of an error */
|
||||
struct type *tp = left->ex_type;
|
||||
register struct type *tp = left->ex_type;
|
||||
|
||||
while (tp && tp->tp_fund != FUNCTION && tp != error_type)
|
||||
tp = tp->tp_up;
|
||||
@ -405,8 +409,8 @@ void call_proto(struct expr **expp)
|
||||
}
|
||||
|
||||
if (right != NILEXPR) { /* function call with parameters */
|
||||
struct expr **ep = &((*expp)->OP_RIGHT);
|
||||
int ecnt = 0, pcnt = 0;
|
||||
register struct expr **ep = &((*expp)->OP_RIGHT);
|
||||
register int ecnt = 0, pcnt = 0;
|
||||
struct expr **estack[NPARAMS];
|
||||
struct proto *pstack[NPARAMS];
|
||||
|
||||
@ -445,7 +449,7 @@ void call_proto(struct expr **expp)
|
||||
pstack[0] = &ellipsis;
|
||||
}
|
||||
|
||||
for (; ecnt >= 0; ecnt--) {
|
||||
for (ecnt; ecnt >= 0; ecnt--) {
|
||||
/* Only the parameters specified in the prototype
|
||||
are checked and converted. The parameters that
|
||||
fall under the ellipsis clause are neither
|
||||
|
||||
@ -1,19 +0,0 @@
|
||||
/*
|
||||
* The Amsterdam Compiler Kit
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
#ifndef LANG_CEM_CEMCOM_ANSI_PROTO_H
|
||||
#define LANG_CEM_CEMCOM_ANSI_PROTO_H
|
||||
|
||||
/* lang/cem/cemcom.ansi/proto.c */
|
||||
void check_for_void(register struct proto *pl);
|
||||
void add_proto(struct proto *pl, struct decspecs *ds, struct declarator *dc, int lvl);
|
||||
struct tag *gettag(struct type *tp, struct idf **idpp);
|
||||
void declare_protos(register struct declarator *dc);
|
||||
void update_proto(register struct type *tp, register struct type *otp);
|
||||
void remove_proto_tag(struct type *tp);
|
||||
void remove_proto_idfs(register struct proto *pl);
|
||||
void call_proto(register struct expr **expp);
|
||||
|
||||
#endif /* LANG_CEM_CEMCOM_ANSI_PROTO_H */
|
||||
|
||||
@ -17,28 +17,26 @@
|
||||
#include "nparams.h"
|
||||
#include "idfsize.h"
|
||||
#include "numsize.h"
|
||||
#include "arith.h"
|
||||
#include <alloc.h>
|
||||
#include "idf.h"
|
||||
#include "idf_loc.h"
|
||||
#include "input.h"
|
||||
#include "macro.h"
|
||||
#include "arith.h"
|
||||
#include "LLlex.h"
|
||||
#include "class.h"
|
||||
#include "assert.h"
|
||||
#include "static.h"
|
||||
#include "macbuf.h"
|
||||
#include "replace.h"
|
||||
#include "replace_loc.h"
|
||||
#include "error.h"
|
||||
#include "skip.h"
|
||||
#include "domacro.h"
|
||||
#include "replace_loc.h"
|
||||
|
||||
extern struct idf *GetIdentifier();
|
||||
extern int InputLevel;
|
||||
struct repl *ReplaceList; /* list of currently active macros */
|
||||
extern char *strcat(), *strcpy();
|
||||
|
||||
int replace(struct idf *idf)
|
||||
int
|
||||
replace(idf)
|
||||
register struct idf *idf;
|
||||
{
|
||||
/* replace is called by the lexical analyzer to perform
|
||||
macro replacement. The routine actualy functions as a
|
||||
@ -64,14 +62,15 @@ int replace(struct idf *idf)
|
||||
return 1;
|
||||
}
|
||||
|
||||
void unstackrepl()
|
||||
unstackrepl()
|
||||
{
|
||||
Unstacked++;
|
||||
}
|
||||
|
||||
void freeargs(struct args *args)
|
||||
freeargs(args)
|
||||
struct args *args;
|
||||
{
|
||||
int i;
|
||||
register int i;
|
||||
|
||||
/* We must don't know how many parameters were specified, so be
|
||||
* prepared to free all NPARAMS parameters.
|
||||
@ -87,9 +86,9 @@ void freeargs(struct args *args)
|
||||
free_args(args);
|
||||
}
|
||||
|
||||
void EnableMacros()
|
||||
EnableMacros()
|
||||
{
|
||||
struct repl *r = ReplaceList, *prev = 0;
|
||||
register struct repl *r = ReplaceList, *prev = 0;
|
||||
|
||||
ASSERT(Unstacked > 0);
|
||||
while(r) {
|
||||
@ -109,7 +108,9 @@ void EnableMacros()
|
||||
Unstacked = 0;
|
||||
}
|
||||
|
||||
int expand_macro(struct repl *repl, struct idf *idf)
|
||||
expand_macro(repl, idf)
|
||||
register struct repl *repl;
|
||||
register struct idf *idf;
|
||||
{
|
||||
/* expand_macro() does the actual macro replacement.
|
||||
"idf" is a description of the identifier which
|
||||
@ -128,9 +129,9 @@ int expand_macro(struct repl *repl, struct idf *idf)
|
||||
on a single, unexpanded identifier, which may be surrounded
|
||||
by parenthesis. The function expand_defined() handles this.
|
||||
*/
|
||||
struct macro *mac = idf->id_macro;
|
||||
register struct macro *mac = idf->id_macro;
|
||||
struct args *args = repl->r_args;
|
||||
int ch;
|
||||
register int ch;
|
||||
|
||||
if (mac->mc_nps != -1) { /* with parameter list */
|
||||
if (mac->mc_flag & FUNC) {
|
||||
@ -179,9 +180,10 @@ int expand_macro(struct repl *repl, struct idf *idf)
|
||||
return 1;
|
||||
}
|
||||
|
||||
void expand_defined(struct repl *repl)
|
||||
expand_defined(repl)
|
||||
register struct repl *repl;
|
||||
{
|
||||
int ch = GetChar();
|
||||
register int ch = GetChar();
|
||||
struct idf *id;
|
||||
int parens = 0;
|
||||
|
||||
@ -210,22 +212,25 @@ void expand_defined(struct repl *repl)
|
||||
add2repl(repl, ' ');
|
||||
}
|
||||
|
||||
void newarg(struct args *args)
|
||||
newarg(args)
|
||||
struct args *args;
|
||||
{
|
||||
args->a_expptr = args->a_expbuf = Malloc(args->a_expsize = ARGBUF);
|
||||
args->a_rawptr = args->a_rawbuf = Malloc(args->a_rawsize = ARGBUF);
|
||||
}
|
||||
|
||||
void getactuals(struct repl *repl, struct idf *idf)
|
||||
getactuals(repl, idf)
|
||||
struct repl *repl;
|
||||
register struct idf *idf;
|
||||
{
|
||||
/* Get the actual parameters from the input stream.
|
||||
The hard part is done by actual(), only comma's and
|
||||
other syntactic trivialities are checked here.
|
||||
*/
|
||||
struct args *args = repl->r_args;
|
||||
int nps = idf->id_macro->mc_nps;
|
||||
int argcnt;
|
||||
int ch;
|
||||
register struct args *args = repl->r_args;
|
||||
register int nps = idf->id_macro->mc_nps;
|
||||
register int argcnt;
|
||||
register int ch;
|
||||
|
||||
argcnt = 0;
|
||||
newarg(args);
|
||||
@ -257,11 +262,12 @@ void getactuals(struct repl *repl, struct idf *idf)
|
||||
lexerror("too many macro arguments");
|
||||
}
|
||||
|
||||
void saveraw(struct repl *repl)
|
||||
saveraw(repl)
|
||||
struct repl *repl;
|
||||
{
|
||||
struct repl *nrepl = ReplaceList;
|
||||
struct args *ap = nrepl->r_args;
|
||||
char *p;
|
||||
register struct repl *nrepl = ReplaceList;
|
||||
register struct args *ap = nrepl->r_args;
|
||||
register char *p;
|
||||
|
||||
/* stash identifier name */
|
||||
for (p = nrepl->r_idf->id_text; *p != '\0'; p++)
|
||||
@ -282,7 +288,7 @@ void saveraw(struct repl *repl)
|
||||
*/
|
||||
if (ap->a_rawvec[0]) {
|
||||
/* stash arguments */
|
||||
int i;
|
||||
register int i;
|
||||
|
||||
for (i = 0; ap->a_rawvec[i] != (char *)0; i++) {
|
||||
if (i == 0) stash(repl, '(', -1);
|
||||
@ -294,14 +300,16 @@ void saveraw(struct repl *repl)
|
||||
}
|
||||
}
|
||||
|
||||
int actual(struct repl *repl)
|
||||
int
|
||||
actual(repl)
|
||||
struct repl *repl;
|
||||
{
|
||||
/* This routine deals with the scanning of an actual parameter.
|
||||
It keeps in account the opening and closing brackets,
|
||||
preprocessor numbers, strings and character constants.
|
||||
*/
|
||||
int ch = 0;
|
||||
int level = 0, nostashraw = 0;
|
||||
register int ch = 0;
|
||||
register int level = 0, nostashraw = 0;
|
||||
int lastch;
|
||||
static int Unstacked_missed;
|
||||
|
||||
@ -327,9 +335,9 @@ int actual(struct repl *repl)
|
||||
token is a macro, it is expanded first.
|
||||
*/
|
||||
char buf[(IDFSIZE > NUMSIZE ? IDFSIZE : NUMSIZE) + 1];
|
||||
char *p = buf;
|
||||
struct idf *idef;
|
||||
int pos = -1;
|
||||
register char *p = buf;
|
||||
register struct idf *idef;
|
||||
register int pos = -1;
|
||||
extern int idfsize;
|
||||
int NoExpandMacro;
|
||||
|
||||
@ -470,7 +478,7 @@ a_new_line: ch = GetChar();
|
||||
/* Strings are considered as ONE token, thus no
|
||||
replacement within strings.
|
||||
*/
|
||||
int match = ch;
|
||||
register int match = ch;
|
||||
|
||||
stash(repl, ch, !nostashraw);
|
||||
while ((ch = GetChar()) != EOI) {
|
||||
@ -499,14 +507,15 @@ a_new_line: ch = GetChar();
|
||||
}
|
||||
}
|
||||
|
||||
void macro_func(struct idf *idef)
|
||||
macro_func(idef)
|
||||
register struct idf *idef;
|
||||
{
|
||||
/* macro_func() performs the special actions needed with some
|
||||
macros. These macros are __FILE__ and __LINE__ which
|
||||
replacement texts must be evaluated at the time they are
|
||||
used.
|
||||
*/
|
||||
struct macro *mac = idef->id_macro;
|
||||
register struct macro *mac = idef->id_macro;
|
||||
static char FilNamBuf[PATHLENGTH];
|
||||
char *long2str();
|
||||
|
||||
@ -528,7 +537,10 @@ void macro_func(struct idf *idef)
|
||||
}
|
||||
}
|
||||
|
||||
void macro2buffer(struct repl *repl, struct idf *idf, struct args *args)
|
||||
macro2buffer(repl, idf, args)
|
||||
register struct repl *repl;
|
||||
register struct idf *idf;
|
||||
register struct args *args;
|
||||
{
|
||||
/* macro2buffer expands the replacement list and places the
|
||||
result onto the replacement buffer. It deals with the #
|
||||
@ -556,14 +568,15 @@ void macro2buffer(struct repl *repl, struct idf *idf, struct args *args)
|
||||
linear fashion. This is VERY expensive, something
|
||||
smarter should be done (but even a DFA is O(|s|)).
|
||||
*/
|
||||
char *ptr = idf->id_macro->mc_text;
|
||||
register char *ptr = idf->id_macro->mc_text;
|
||||
int err = 0;
|
||||
int func = idf->id_macro->mc_nps != -1;
|
||||
char *stringify();
|
||||
|
||||
ASSERT(ptr[idf->id_macro->mc_length] == '\0');
|
||||
while (*ptr) {
|
||||
if (*ptr == '\'' || *ptr == '"') {
|
||||
int delim = *ptr;
|
||||
register int delim = *ptr;
|
||||
|
||||
do {
|
||||
add2repl(repl, *ptr);
|
||||
@ -578,14 +591,14 @@ void macro2buffer(struct repl *repl, struct idf *idf, struct args *args)
|
||||
add2repl(repl, *ptr++);
|
||||
} else if (*ptr == '#' && (func || *(ptr+1) == '#')) {
|
||||
if (*++ptr == '#') {
|
||||
int tmpindex;
|
||||
register int tmpindex;
|
||||
/* ## - paste operator */
|
||||
ptr++;
|
||||
|
||||
/* trim the actual replacement list */
|
||||
--repl->r_ptr;
|
||||
while (repl->r_ptr >= repl->r_text
|
||||
&& is_wsp(*(unsigned char *)repl->r_ptr))
|
||||
&& is_wsp(*repl->r_ptr))
|
||||
--repl->r_ptr;
|
||||
|
||||
/* ## occurred at the beginning of the replacement list.
|
||||
@ -604,25 +617,25 @@ void macro2buffer(struct repl *repl, struct idf *idf, struct args *args)
|
||||
/* tmpindex can be 0 */
|
||||
|
||||
/* skip space in macro replacement list */
|
||||
while ((*ptr & FORMALP) == 0 && is_wsp(*(unsigned char *)ptr))
|
||||
while ((*ptr & FORMALP) == 0 && is_wsp(*ptr))
|
||||
ptr++;
|
||||
|
||||
/* ## occurred at the end of the replacement list.
|
||||
*/
|
||||
if (*ptr & FORMALP) {
|
||||
int n = *ptr++ & 0177;
|
||||
char *p;
|
||||
register int n = *ptr++ & 0177;
|
||||
register char *p;
|
||||
|
||||
ASSERT(n > 0);
|
||||
p = args->a_rawvec[n-1];
|
||||
if (p) { /* else macro argument missing */
|
||||
while (is_wsp(*(unsigned char *)p)) p++;
|
||||
while (is_wsp(*p)) p++;
|
||||
if (*p == NOEXPM) p++;
|
||||
while (*p)
|
||||
add2repl(repl, *p++);
|
||||
}
|
||||
while (tmpindex > 0
|
||||
&& in_idf((unsigned char)repl->r_text[tmpindex]))
|
||||
&& in_idf(repl->r_text[tmpindex]))
|
||||
tmpindex--;
|
||||
if (tmpindex >= 0
|
||||
&& repl->r_text[tmpindex] == NOEXPM)
|
||||
@ -631,10 +644,10 @@ void macro2buffer(struct repl *repl, struct idf *idf, struct args *args)
|
||||
err = 1;
|
||||
break;
|
||||
} else {
|
||||
if (in_idf(*(unsigned char *)ptr)) {
|
||||
if (in_idf(*ptr)) {
|
||||
tmpindex--;
|
||||
while (tmpindex > 0
|
||||
&& in_idf((unsigned char)repl->r_text[tmpindex]))
|
||||
&& in_idf(repl->r_text[tmpindex]))
|
||||
tmpindex--;
|
||||
if (tmpindex >= 0
|
||||
&& repl->r_text[tmpindex] == NOEXPM)
|
||||
@ -646,8 +659,8 @@ void macro2buffer(struct repl *repl, struct idf *idf, struct args *args)
|
||||
}
|
||||
} else if (*ptr & FORMALP) {
|
||||
/* insert actual parameter */
|
||||
int n = *ptr++ & 0177;
|
||||
char *p, *q;
|
||||
register int n = *ptr++ & 0177;
|
||||
register char *p, *q;
|
||||
|
||||
ASSERT(n > 0);
|
||||
|
||||
@ -656,7 +669,7 @@ void macro2buffer(struct repl *repl, struct idf *idf, struct args *args)
|
||||
argument buffer instead of the expanded
|
||||
one.
|
||||
*/
|
||||
for (p = ptr; (*p & FORMALP) == 0 && is_wsp(*(unsigned char *)p); p++)
|
||||
for (p = ptr; (*p & FORMALP) == 0 && is_wsp(*p); p++)
|
||||
/* EMPTY */;
|
||||
if (*p == '#' && p[1] == '#')
|
||||
q = args->a_rawvec[n-1];
|
||||
@ -677,7 +690,11 @@ void macro2buffer(struct repl *repl, struct idf *idf, struct args *args)
|
||||
lexerror("illegal use of the ## operator");
|
||||
}
|
||||
|
||||
char *stringify(struct repl *repl, char *ptr, struct args *args)
|
||||
char *
|
||||
stringify(repl, ptr, args)
|
||||
register struct repl *repl;
|
||||
register char *ptr;
|
||||
register struct args *args;
|
||||
{
|
||||
/* If a parameter is immediately preceded by a # token
|
||||
both are replaced by a single string literal that
|
||||
@ -691,23 +708,23 @@ char *stringify(struct repl *repl, char *ptr, struct args *args)
|
||||
as appropriate. We only escape backslashes if they
|
||||
occure within string tokens.
|
||||
*/
|
||||
int space = 1; /* skip leading spaces */
|
||||
int delim = 0; /* string or character constant delim */
|
||||
int backslash = 0; /* last character was a \ */
|
||||
register int space = 1; /* skip leading spaces */
|
||||
register int delim = 0; /* string or character constant delim */
|
||||
register int backslash = 0; /* last character was a \ */
|
||||
|
||||
/* skip spaces macro replacement list */
|
||||
while ((*ptr & FORMALP) == 0 && is_wsp(*(unsigned char *)ptr))
|
||||
while ((*ptr & FORMALP) == 0 && is_wsp(*ptr))
|
||||
ptr++;
|
||||
|
||||
if (*ptr & FORMALP) {
|
||||
int n = *ptr++ & 0177;
|
||||
char *p;
|
||||
register int n = *ptr++ & 0177;
|
||||
register char *p;
|
||||
|
||||
ASSERT(n != 0);
|
||||
p = args->a_rawvec[n-1];
|
||||
add2repl(repl, '"');
|
||||
while (*p) {
|
||||
if (is_wsp(*(unsigned char *)p)) {
|
||||
if (is_wsp(*p)) {
|
||||
if (!space) {
|
||||
space = 1;
|
||||
add2repl(repl, ' ');
|
||||
@ -729,7 +746,7 @@ char *stringify(struct repl *repl, char *ptr, struct args *args)
|
||||
}
|
||||
|
||||
/* trim spaces in the replacement list */
|
||||
for (--repl->r_ptr; is_wsp(*(unsigned char *)repl->r_ptr); repl->r_ptr--)
|
||||
for (--repl->r_ptr; is_wsp(*repl->r_ptr); repl->r_ptr--)
|
||||
/* EMPTY */;
|
||||
++repl->r_ptr; /* oops, one to far */
|
||||
add2repl(repl, '"');
|
||||
@ -740,9 +757,11 @@ char *stringify(struct repl *repl, char *ptr, struct args *args)
|
||||
|
||||
/* The following routine is also called from domacro.c.
|
||||
*/
|
||||
void add2repl(struct repl *repl, int ch)
|
||||
add2repl(repl, ch)
|
||||
register struct repl *repl;
|
||||
int ch;
|
||||
{
|
||||
int index = repl->r_ptr - repl->r_text;
|
||||
register int index = repl->r_ptr - repl->r_text;
|
||||
|
||||
ASSERT(index < repl->r_size);
|
||||
if (index + 2 >= repl->r_size) {
|
||||
@ -757,12 +776,15 @@ void add2repl(struct repl *repl, int ch)
|
||||
* buffer. If the variable is zero, we must only stash into the expanded
|
||||
* buffer. Otherwise, we must use both buffers.
|
||||
*/
|
||||
void stash(struct repl *repl ,int ch, int stashraw)
|
||||
stash(repl, ch, stashraw)
|
||||
struct repl *repl;
|
||||
register int ch;
|
||||
int stashraw;
|
||||
{
|
||||
/* Stash characters into the macro expansion buffer.
|
||||
*/
|
||||
struct args *args = repl->r_args;
|
||||
int index = args->a_expptr - args->a_expbuf;
|
||||
register struct args *args = repl->r_args;
|
||||
register int index = args->a_expptr - args->a_expbuf;
|
||||
|
||||
if (stashraw >= 0) {
|
||||
ASSERT(index < args->a_expsize);
|
||||
|
||||
@ -1,29 +0,0 @@
|
||||
/*
|
||||
* The Amsterdam Compiler Kit
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
#ifndef LANG_CEM_CEMCOM_ANSI_REPLACE_H
|
||||
#define LANG_CEM_CEMCOM_ANSI_REPLACE_H
|
||||
|
||||
struct args;
|
||||
struct repl;
|
||||
|
||||
/* lang/cem/cemcom.ansi/replace.c */
|
||||
int replace(register struct idf *idf);
|
||||
void unstackrepl(void);
|
||||
void freeargs(struct args *args);
|
||||
void EnableMacros(void);
|
||||
int expand_macro(register struct repl *repl, register struct idf *idf);
|
||||
void expand_defined(register struct repl *repl);
|
||||
void newarg(struct args *args);
|
||||
void getactuals(struct repl *repl, register struct idf *idf);
|
||||
void saveraw(struct repl *repl);
|
||||
int actual(struct repl *repl);
|
||||
void macro_func(register struct idf *idef);
|
||||
void macro2buffer(register struct repl *repl, register struct idf *idf, register struct args *args);
|
||||
char *stringify(register struct repl *repl, register char *ptr, register struct args *args);
|
||||
void add2repl(register struct repl *repl, int ch);
|
||||
void stash(struct repl *repl, register int ch, int stashraw);
|
||||
|
||||
#endif /* LANG_CEM_CEMCOM_ANSI_REPLACE_H */
|
||||
|
||||
@ -10,18 +10,18 @@
|
||||
#include "LLlex.h"
|
||||
#include "class.h"
|
||||
#include "input.h"
|
||||
#include "domacro.h"
|
||||
#include "error.h"
|
||||
|
||||
#ifndef NOPP
|
||||
extern int InputLevel;
|
||||
|
||||
int skipspaces(int ch, int skipnl)
|
||||
int
|
||||
skipspaces(ch, skipnl)
|
||||
register int ch;
|
||||
{
|
||||
/* skipspaces() skips any white space and returns the first
|
||||
non-space character.
|
||||
*/
|
||||
int nlseen = 0;
|
||||
register int nlseen = 0;
|
||||
|
||||
for (;;) {
|
||||
while (class(ch) == STSKIP)
|
||||
@ -59,12 +59,12 @@ int skipspaces(int ch, int skipnl)
|
||||
}
|
||||
#endif /* NOPP */
|
||||
|
||||
int SkipToNewLine()
|
||||
SkipToNewLine()
|
||||
{
|
||||
int ch;
|
||||
int garbage = 0;
|
||||
register int ch;
|
||||
register int garbage = 0;
|
||||
#ifndef NOPP
|
||||
int delim = 0;
|
||||
register int delim = 0;
|
||||
#endif
|
||||
|
||||
while ((ch = GetChar()) != '\n') {
|
||||
|
||||
@ -1,13 +0,0 @@
|
||||
/*
|
||||
* The Amsterdam Compiler Kit
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
#ifndef LANG_CEM_CEMCOM_ANSI_SKIP_H
|
||||
#define LANG_CEM_CEMCOM_ANSI_SKIP_H
|
||||
|
||||
/* lang/cem/cemcom.ansi/skip.c */
|
||||
int skipspaces(register int ch, int skipnl);
|
||||
int SkipToNewLine(void);
|
||||
|
||||
#endif /* LANG_CEM_CEMCOM_ANSI_SKIP_H */
|
||||
|
||||
@ -41,7 +41,8 @@ static struct db_str {
|
||||
char *currpos;
|
||||
} db_str;
|
||||
|
||||
static void create_db_str()
|
||||
static
|
||||
create_db_str()
|
||||
{
|
||||
if (! db_str.base) {
|
||||
db_str.base = Malloc(INCR_SIZE);
|
||||
@ -50,7 +51,9 @@ static void create_db_str()
|
||||
db_str.currpos = db_str.base;
|
||||
}
|
||||
|
||||
static void addc_db_str(int c)
|
||||
static
|
||||
addc_db_str(c)
|
||||
int c;
|
||||
{
|
||||
int df = db_str.currpos - db_str.base;
|
||||
if (df >= db_str.sz-1) {
|
||||
@ -62,12 +65,16 @@ static void addc_db_str(int c)
|
||||
*db_str.currpos = '\0';
|
||||
}
|
||||
|
||||
static void adds_db_str(char *s)
|
||||
static
|
||||
adds_db_str(s)
|
||||
char *s;
|
||||
{
|
||||
while (*s) addc_db_str(*s++);
|
||||
}
|
||||
|
||||
static void stb_type(struct type *tp)
|
||||
static
|
||||
stb_type(tp)
|
||||
register struct type *tp;
|
||||
{
|
||||
char buf[128];
|
||||
static int stb_count;
|
||||
@ -142,10 +149,10 @@ static void stb_type(struct type *tp)
|
||||
}
|
||||
addc_db_str('e');
|
||||
{
|
||||
struct stack_entry *se = local_level->sl_entry;
|
||||
register struct stack_entry *se = local_level->sl_entry;
|
||||
|
||||
while (se) {
|
||||
struct def *edef = se->se_idf->id_def;
|
||||
register struct def *edef = se->se_idf->id_def;
|
||||
while (edef) {
|
||||
if (edef->df_type == tp &&
|
||||
edef->df_sc == ENUM) {
|
||||
@ -176,7 +183,7 @@ static void stb_type(struct type *tp)
|
||||
tp->tp_fund == STRUCT ? 's' : 'u',
|
||||
tp->tp_size));
|
||||
{
|
||||
struct sdef *sdef = tp->tp_sdef;
|
||||
register struct sdef *sdef = tp->tp_sdef;
|
||||
|
||||
while (sdef) {
|
||||
adds_db_str(sdef->sd_idf->id_text);
|
||||
@ -206,7 +213,9 @@ static void stb_type(struct type *tp)
|
||||
}
|
||||
}
|
||||
|
||||
void stb_tag(struct tag *tg, char *str)
|
||||
stb_tag(tg, str)
|
||||
register struct tag *tg;
|
||||
char *str;
|
||||
{
|
||||
create_db_str();
|
||||
adds_db_str(str);
|
||||
@ -221,7 +230,9 @@ void stb_tag(struct tag *tg, char *str)
|
||||
(arith) 0);
|
||||
}
|
||||
|
||||
void stb_typedef(struct type *tp, char *str)
|
||||
stb_typedef(tp, str)
|
||||
register struct type *tp;
|
||||
char *str;
|
||||
{
|
||||
create_db_str();
|
||||
adds_db_str(str);
|
||||
@ -236,9 +247,11 @@ void stb_typedef(struct type *tp, char *str)
|
||||
(arith) 0);
|
||||
}
|
||||
|
||||
void stb_string(struct def *df, int kind, char *str)
|
||||
stb_string(df, kind, str)
|
||||
register struct def *df;
|
||||
char *str;
|
||||
{
|
||||
struct type *tp = df->df_type;
|
||||
register struct type *tp = df->df_type;
|
||||
|
||||
create_db_str();
|
||||
adds_db_str(str);
|
||||
|
||||
@ -1,14 +0,0 @@
|
||||
/*
|
||||
* The Amsterdam Compiler Kit
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
#ifndef LANG_CEM_CEMCOM_ANSI_STAB_H
|
||||
#define LANG_CEM_CEMCOM_ANSI_STAB_H
|
||||
|
||||
/* lang/cem/cemcom.ansi/stab.c */
|
||||
void stb_tag(register struct tag *tg, char *str);
|
||||
void stb_typedef(register struct type *tp, char *str);
|
||||
void stb_string(register struct def *df, int kind, char *str);
|
||||
|
||||
#endif /* LANG_CEM_CEMCOM_ANSI_STAB_H */
|
||||
|
||||
@ -18,18 +18,12 @@
|
||||
#include "Lpars.h"
|
||||
#include "arith.h"
|
||||
#include "stack.h"
|
||||
#include "stack_loc.h"
|
||||
#include "type.h"
|
||||
#include "idf.h"
|
||||
#include "idf_loc.h"
|
||||
#include "def.h"
|
||||
#include "struct.h"
|
||||
#include "level.h"
|
||||
#include "mes.h"
|
||||
#include "code_c.h"
|
||||
#include "error.h"
|
||||
#include "label.h"
|
||||
#include "util_loc.h"
|
||||
|
||||
/* #include <em_reg.h> */
|
||||
|
||||
@ -49,12 +43,11 @@ struct stack_level *local_level = &UniversalLevel;
|
||||
|
||||
int level; /* Always equal to local_level->sl_level. */
|
||||
|
||||
void stack_level()
|
||||
{
|
||||
stack_level() {
|
||||
/* A new level is added on top of the identifier stack.
|
||||
*/
|
||||
struct stack_level *stl = new_stack_level();
|
||||
struct stack_level *loclev = local_level;
|
||||
register struct stack_level *stl = new_stack_level();
|
||||
register struct stack_level *loclev = local_level;
|
||||
|
||||
loclev->sl_next = stl;
|
||||
stl->sl_previous = loclev;
|
||||
@ -66,12 +59,14 @@ void stack_level()
|
||||
#endif /* LINT */
|
||||
}
|
||||
|
||||
void stack_idf(struct idf *idf, struct stack_level *stl)
|
||||
stack_idf(idf, stl)
|
||||
struct idf *idf;
|
||||
register struct stack_level *stl;
|
||||
{
|
||||
/* The identifier idf is inserted in the stack on level stl,
|
||||
but only if it is not already present at this level.
|
||||
*/
|
||||
struct stack_entry *se;
|
||||
register struct stack_entry *se;
|
||||
|
||||
se = stl->sl_entry;
|
||||
while (se) {
|
||||
@ -87,13 +82,14 @@ void stack_idf(struct idf *idf, struct stack_level *stl)
|
||||
stl->sl_entry = se;
|
||||
}
|
||||
|
||||
struct stack_level *stack_level_of(int lvl)
|
||||
struct stack_level *
|
||||
stack_level_of(lvl)
|
||||
{
|
||||
/* The stack_level corresponding to level lvl is returned.
|
||||
The stack should probably be an array, to be extended with
|
||||
realloc where needed.
|
||||
*/
|
||||
struct stack_level *stl;
|
||||
register struct stack_level *stl;
|
||||
|
||||
if (lvl == level)
|
||||
return local_level;
|
||||
@ -105,7 +101,7 @@ struct stack_level *stack_level_of(int lvl)
|
||||
return stl;
|
||||
}
|
||||
|
||||
void unstack_level()
|
||||
unstack_level()
|
||||
{
|
||||
/* The top level of the identifier stack is removed.
|
||||
*/
|
||||
@ -124,11 +120,11 @@ void unstack_level()
|
||||
necessary. Optimists may optimize it afterwards.
|
||||
*/
|
||||
while (local_level->sl_entry) {
|
||||
struct stack_entry *se = local_level->sl_entry;
|
||||
struct idf *idf = se->se_idf;
|
||||
struct def *def;
|
||||
struct sdef *sdef;
|
||||
struct tag *tag;
|
||||
register struct stack_entry *se = local_level->sl_entry;
|
||||
register struct idf *idf = se->se_idf;
|
||||
register struct def *def;
|
||||
register struct sdef *sdef;
|
||||
register struct tag *tag;
|
||||
|
||||
/* unlink it from the local stack level */
|
||||
local_level->sl_entry = se->next;
|
||||
@ -179,7 +175,7 @@ void unstack_level()
|
||||
#endif /* DEBUG */
|
||||
}
|
||||
|
||||
void unstack_world()
|
||||
unstack_world()
|
||||
{
|
||||
/* The global level of identifiers is scanned, and final
|
||||
decisions are taken about such issues as
|
||||
@ -188,7 +184,7 @@ void unstack_world()
|
||||
have already been encoded while the uninitialised ones
|
||||
are not and have to be encoded at this moment.
|
||||
*/
|
||||
struct stack_entry *se = local_level->sl_entry;
|
||||
register struct stack_entry *se = local_level->sl_entry;
|
||||
|
||||
#ifdef LINT
|
||||
lint_end_global(local_level);
|
||||
@ -199,8 +195,8 @@ void unstack_world()
|
||||
#endif /* GEN_NM_LIST */
|
||||
|
||||
while (se) {
|
||||
struct idf *idf = se->se_idf;
|
||||
struct def *def = idf->id_def;
|
||||
register struct idf *idf = se->se_idf;
|
||||
register struct def *def = idf->id_def;
|
||||
|
||||
if (!def) {
|
||||
/* global selectors, etc. */
|
||||
@ -268,13 +264,14 @@ void unstack_world()
|
||||
extern char *nmlist; /* BAH! -- main.c */
|
||||
static File *nfp = 0;
|
||||
|
||||
void open_name_list()
|
||||
open_name_list()
|
||||
{
|
||||
if (nmlist && sys_open(nmlist, OP_WRITE, &nfp) == 0)
|
||||
fatal("cannot create namelist %s", nmlist);
|
||||
}
|
||||
|
||||
void namelist(char *nm)
|
||||
namelist(nm)
|
||||
char *nm;
|
||||
{
|
||||
if (nmlist) {
|
||||
sys_write(nfp, nm, strlen(nm));
|
||||
|
||||
@ -4,8 +4,6 @@
|
||||
*/
|
||||
/* $Id$ */
|
||||
/* IDENTIFIER STACK DEFINITIONS */
|
||||
#ifndef LANG_CEM_CEMCOM_ANSI_STACK_STR
|
||||
#define LANG_CEM_CEMCOM_ANSI_STACK_STR
|
||||
|
||||
/* The identifier stack is implemented as a stack of sets.
|
||||
The stack is implemented by a doubly linked list,
|
||||
@ -34,5 +32,3 @@ struct stack_entry {
|
||||
extern struct stack_level *local_level;
|
||||
extern struct stack_level *stack_level_of();
|
||||
extern int level;
|
||||
|
||||
#endif /* LANG_CEM_CEMCOM_ANSI_STACK_STR */
|
||||
@ -1,16 +0,0 @@
|
||||
/*
|
||||
* The Amsterdam Compiler Kit
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
#ifndef LANG_CEM_CEMCOM_ANSI_STACK_H
|
||||
#define LANG_CEM_CEMCOM_ANSI_STACK_H
|
||||
|
||||
/* lang/cem/cemcom.ansi/stack.c */
|
||||
void stack_level(void);
|
||||
void stack_idf(struct idf *idf, struct stack_level *stl);
|
||||
struct stack_level *stack_level_of(int lvl);
|
||||
void unstack_level(void);
|
||||
void unstack_world(void);
|
||||
|
||||
#endif /* LANG_CEM_CEMCOM_ANSI_STACK_H */
|
||||
|
||||
@ -22,19 +22,12 @@
|
||||
#include "arith.h"
|
||||
#include "LLlex.h"
|
||||
#include "type.h"
|
||||
#include "type_loc.h"
|
||||
#include "idf.h"
|
||||
#include "idf_loc.h"
|
||||
#include "label.h"
|
||||
#include "expr.h"
|
||||
#include "expr_loc.h"
|
||||
#include "code.h"
|
||||
#include "stack.h"
|
||||
#include "stack_loc.h"
|
||||
#include "def.h"
|
||||
#include "code_c.h"
|
||||
#include "switch_loc.h"
|
||||
|
||||
#ifdef DBSYMTAB
|
||||
#include <stb.h>
|
||||
#endif /* DBSYMTAB */
|
||||
|
||||
@ -11,14 +11,11 @@
|
||||
#include <alloc.h>
|
||||
#include "arith.h"
|
||||
#include "stack.h"
|
||||
#include "stack_loc.h"
|
||||
#include "idf.h"
|
||||
#include "idf_loc.h"
|
||||
#include "def.h"
|
||||
#include "type.h"
|
||||
#include "proto.h"
|
||||
#include "struct.h"
|
||||
#include "struct_loc.h"
|
||||
#include "field.h"
|
||||
#include "LLlex.h"
|
||||
#include "Lpars.h"
|
||||
@ -26,10 +23,6 @@
|
||||
#include "level.h"
|
||||
#include "assert.h"
|
||||
#include "sizes.h"
|
||||
#include "error.h"
|
||||
#include "ch3.h"
|
||||
|
||||
#include <symbol2str.h>
|
||||
|
||||
/* Type of previous selector declared with a field width specified,
|
||||
if any. If a selector is declared with no field with it is set to 0.
|
||||
@ -37,6 +30,8 @@
|
||||
static field_busy = 0;
|
||||
|
||||
extern char options[];
|
||||
char *symbol2str();
|
||||
int lcm();
|
||||
|
||||
/* The semantics of the identification of structure/union tags is
|
||||
obscure. Some highly regarded compilers are found out to accept,
|
||||
@ -58,16 +53,14 @@ extern char options[];
|
||||
If below struct is mentioned, union is implied (and sometimes enum
|
||||
as well).
|
||||
*/
|
||||
/*
|
||||
struct type *stp; type of the structure
|
||||
struct type *tp; type of the selector
|
||||
struct idf *idf; idf of the selector
|
||||
struct sdef ***sdefpp; address of hook to selector definition
|
||||
arith *szp; pointer to struct size upto here
|
||||
|
||||
add_sel(stp, tp, idf, sdefpp, szp, fd) /* this is horrible */
|
||||
register struct type *stp; /* type of the structure */
|
||||
struct type *tp; /* type of the selector */
|
||||
register struct idf *idf; /* idf of the selector */
|
||||
struct sdef ***sdefpp; /* address of hook to selector definition */
|
||||
arith *szp; /* pointer to struct size upto here */
|
||||
struct field *fd;
|
||||
*/
|
||||
void add_sel(struct type *stp, struct type *tp, struct idf *idf,
|
||||
struct sdef ***sdefpp, arith *szp, struct field *fd) /* this is horrible */
|
||||
{
|
||||
/* The selector idf with type tp is added to two chains: the
|
||||
selector identification chain starting at idf->id_sdef,
|
||||
@ -82,7 +75,7 @@ void add_sel(struct type *stp, struct type *tp, struct idf *idf,
|
||||
|
||||
struct tag *tg = stp->tp_idf->id_tag; /* or union */
|
||||
struct sdef *sdef = idf->id_sdef;
|
||||
struct sdef *newsdef;
|
||||
register struct sdef *newsdef;
|
||||
int lvl = tg->tg_level;
|
||||
|
||||
if (stp->tp_fund == STRUCT) {
|
||||
@ -156,13 +149,15 @@ void add_sel(struct type *stp, struct type *tp, struct idf *idf,
|
||||
stp->tp_align = lcm(stp->tp_align, tp->tp_align);
|
||||
}
|
||||
}
|
||||
/* stp: the type of the struct */
|
||||
void check_selector(struct idf *idf, struct type *stp)
|
||||
|
||||
check_selector(idf, stp)
|
||||
register struct idf *idf;
|
||||
struct type *stp; /* the type of the struct */
|
||||
{
|
||||
/* checks if idf occurs already as a selector in
|
||||
struct or union *stp.
|
||||
*/
|
||||
struct sdef *sdef = stp->tp_sdef;
|
||||
register struct sdef *sdef = stp->tp_sdef;
|
||||
|
||||
while (sdef) {
|
||||
if (sdef->sd_idf == idf)
|
||||
@ -171,7 +166,9 @@ void check_selector(struct idf *idf, struct type *stp)
|
||||
}
|
||||
}
|
||||
|
||||
void declare_struct(int fund, struct idf *idf, struct type **tpp)
|
||||
declare_struct(fund, idf, tpp)
|
||||
register struct idf *idf;
|
||||
struct type **tpp;
|
||||
{
|
||||
/* A struct, union or enum (depending on fund) with tag (!)
|
||||
idf is declared, and its type (incomplete as it may be) is
|
||||
@ -179,8 +176,8 @@ void declare_struct(int fund, struct idf *idf, struct type **tpp)
|
||||
The idf may be missing (i.e. idf == 0), in which case an
|
||||
anonymous struct etc. is defined.
|
||||
*/
|
||||
struct tag **tgp;
|
||||
struct tag *tg;
|
||||
register struct tag **tgp;
|
||||
register struct tag *tg;
|
||||
|
||||
|
||||
if (*tpp) error("multiple types in declaration");
|
||||
@ -238,14 +235,16 @@ void declare_struct(int fund, struct idf *idf, struct type **tpp)
|
||||
}
|
||||
}
|
||||
|
||||
void apply_struct(int fund, struct idf *idf, struct type **tpp)
|
||||
apply_struct(fund, idf, tpp)
|
||||
register struct idf *idf;
|
||||
struct type **tpp;
|
||||
{
|
||||
/* The occurrence of a struct, union or enum (depending on
|
||||
fund) with tag idf is noted. It may or may not have been
|
||||
declared before. Its type (complete or incomplete) is
|
||||
returned in *tpp.
|
||||
*/
|
||||
struct tag **tgp;
|
||||
register struct tag **tgp;
|
||||
|
||||
tgp = &idf->id_tag;
|
||||
|
||||
@ -262,7 +261,10 @@ void apply_struct(int fund, struct idf *idf, struct type **tpp)
|
||||
declare_struct(fund, idf, tpp);
|
||||
}
|
||||
|
||||
struct sdef *idf2sdef(struct idf *idf, struct type *tp)
|
||||
struct sdef *
|
||||
idf2sdef(idf, tp)
|
||||
register struct idf *idf;
|
||||
struct type *tp;
|
||||
{
|
||||
/* The identifier idf is identified as a selector
|
||||
in the struct tp.
|
||||
@ -271,17 +273,17 @@ struct sdef *idf2sdef(struct idf *idf, struct type *tp)
|
||||
If this fails too, a selector of type error_type is
|
||||
created.
|
||||
*/
|
||||
struct sdef **sdefp = &idf->id_sdef, *sdef;
|
||||
register struct sdef **sdefp = &idf->id_sdef, *sdef;
|
||||
|
||||
/* Follow chain from idf, to meet tp. */
|
||||
while ( (sdef = *sdefp) ) {
|
||||
while ((sdef = *sdefp)) {
|
||||
if (equal_type(sdef->sd_stype, tp, -999, 0)) /* ??? hack */
|
||||
return sdef;
|
||||
sdefp = &(*sdefp)->next;
|
||||
}
|
||||
|
||||
/* Tp not met; take an identification. */
|
||||
if ( (sdef = idf->id_sdef) ) {
|
||||
if (sdef = idf->id_sdef) {
|
||||
/* There is an identification */
|
||||
error("illegal use of selector %s", idf->id_text);
|
||||
return sdef;
|
||||
@ -297,7 +299,9 @@ struct sdef *idf2sdef(struct idf *idf, struct type *tp)
|
||||
}
|
||||
|
||||
#if 0
|
||||
int uniq_selector(struct sdef *idf_sdef)
|
||||
int
|
||||
uniq_selector(idf_sdef)
|
||||
register struct sdef *idf_sdef;
|
||||
{
|
||||
/* Returns true if idf_sdef (which is guaranteed to exist)
|
||||
is unique for this level, i.e there is no other selector
|
||||
@ -307,7 +311,7 @@ int uniq_selector(struct sdef *idf_sdef)
|
||||
case!
|
||||
*/
|
||||
|
||||
struct sdef *sdef = idf_sdef->next;
|
||||
register struct sdef *sdef = idf_sdef->next;
|
||||
|
||||
while (sdef && sdef->sd_level == idf_sdef->sd_level) {
|
||||
if ( sdef->sd_type != idf_sdef->sd_type
|
||||
@ -322,15 +326,13 @@ int uniq_selector(struct sdef *idf_sdef)
|
||||
#endif
|
||||
|
||||
#ifndef NOBITFIELD
|
||||
|
||||
/*
|
||||
arith *szp; size of struct upto here
|
||||
struct field *fd; bitfield, containing width
|
||||
struct type **fdtpp; type of selector
|
||||
struct idf *idf; name of selector
|
||||
struct type *stp; current struct descripton
|
||||
*/
|
||||
arith add_field(arith *szp, struct field *fd, struct type **fdtpp, struct idf *idf, struct type *stp)
|
||||
arith
|
||||
add_field(szp, fd, fdtpp, idf, stp)
|
||||
arith *szp; /* size of struct upto here */
|
||||
register struct field *fd; /* bitfield, containing width */
|
||||
register struct type **fdtpp; /* type of selector */
|
||||
struct idf *idf; /* name of selector */
|
||||
register struct type *stp; /* current struct descriptor */
|
||||
{
|
||||
/* The address where this selector is put is returned. If the
|
||||
selector with specified width does not fit in the word, or
|
||||
@ -439,16 +441,20 @@ arith add_field(arith *szp, struct field *fd, struct type **fdtpp, struct idf *i
|
||||
#endif /* NOBITFIELD */
|
||||
|
||||
/* some utilities */
|
||||
int is_struct_or_union(int fund)
|
||||
int
|
||||
is_struct_or_union(fund)
|
||||
register int fund;
|
||||
{
|
||||
return fund == STRUCT || fund == UNION;
|
||||
}
|
||||
|
||||
/* Greatest Common Divisor
|
||||
*/
|
||||
int gcd(int m, int n)
|
||||
int
|
||||
gcd(m, n)
|
||||
register int m, n;
|
||||
{
|
||||
int r;
|
||||
register int r;
|
||||
|
||||
while (n) {
|
||||
r = m % n;
|
||||
@ -460,7 +466,9 @@ int gcd(int m, int n)
|
||||
|
||||
/* Least Common Multiple
|
||||
*/
|
||||
int lcm(int m, int n)
|
||||
int
|
||||
lcm(m, n)
|
||||
register int m, n;
|
||||
{
|
||||
return m * (n / gcd(m, n));
|
||||
}
|
||||
|
||||
@ -1,20 +0,0 @@
|
||||
/*
|
||||
* The Amsterdam Compiler Kit
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
#ifndef LANG_CEM_CEMCOM_ANSI_STRUCT_H
|
||||
#define LANG_CEM_CEMCOM_ANSI_STRUCT_H
|
||||
|
||||
/* lang/cem/cemcom.ansi/struct.c */
|
||||
void add_sel(struct type *stp, struct type *tp, struct idf *idf, struct sdef ***sdefpp, arith *szp, struct field *fd);
|
||||
void check_selector(struct idf *idf, struct type *stp);
|
||||
void declare_struct(int fund, struct idf *idf, struct type **tpp);
|
||||
void apply_struct(int fund, struct idf *idf, struct type **tpp);
|
||||
struct sdef *idf2sdef(struct idf *idf, struct type *tp);
|
||||
arith add_field(arith *szp, struct field *fd, struct type **fdtpp, struct idf *idf, struct type *stp);
|
||||
int is_struct_or_union(register int fund);
|
||||
int gcd(register int m, register int n);
|
||||
int lcm(register int m, register int n);
|
||||
|
||||
#endif /* LANG_CEM_CEMCOM_ANSI_STRUCT_H */
|
||||
|
||||
@ -26,17 +26,13 @@
|
||||
#include "expr.h"
|
||||
#include "type.h"
|
||||
#include "sizes.h"
|
||||
#include "code_c.h"
|
||||
#include "eval.h"
|
||||
#include "ch3.h"
|
||||
#include <system.h>
|
||||
#include "print.h"
|
||||
|
||||
extern char options[];
|
||||
|
||||
int density = DENSITY;
|
||||
|
||||
int compact(int nr, arith low, arith up)
|
||||
compact(nr, low, up)
|
||||
arith low, up;
|
||||
{
|
||||
/* Careful! up - low might not fit in an arith. And then,
|
||||
the test "up-low < 0" might also not work to detect this
|
||||
@ -56,14 +52,15 @@ static struct switch_hdr *switch_stack = 0;
|
||||
For simplicity, we suppose int_size == word_size.
|
||||
*/
|
||||
|
||||
void code_startswitch(struct expr **expp)
|
||||
code_startswitch(expp)
|
||||
struct expr **expp;
|
||||
{
|
||||
/* Check the expression, stack a new case header and
|
||||
fill in the necessary fields.
|
||||
*/
|
||||
label l_table = text_label();
|
||||
label l_break = text_label();
|
||||
struct switch_hdr *sh = new_switch_hdr();
|
||||
register label l_table = text_label();
|
||||
register label l_break = text_label();
|
||||
register struct switch_hdr *sh = new_switch_hdr();
|
||||
int fund = any2arith(expp, SWITCH);
|
||||
/* INT, LONG, FLOAT, DOUBLE or LNGDBL */
|
||||
|
||||
@ -91,11 +88,13 @@ void code_startswitch(struct expr **expp)
|
||||
C_bra(l_table); /* goto start of switch_table */
|
||||
}
|
||||
|
||||
void code_endswitch()
|
||||
extern char *long2str();
|
||||
|
||||
code_endswitch()
|
||||
{
|
||||
struct switch_hdr *sh = switch_stack;
|
||||
label tablabel;
|
||||
struct case_entry *ce;
|
||||
register struct switch_hdr *sh = switch_stack;
|
||||
register label tablabel;
|
||||
register struct case_entry *ce;
|
||||
arith size = sh->sh_type->tp_size;
|
||||
|
||||
if (sh->sh_default == 0) /* no default occurred yet */
|
||||
@ -121,7 +120,7 @@ void code_endswitch()
|
||||
C_rom_ilb(sh->sh_default);
|
||||
if (compact(sh->sh_nrofentries, sh->sh_lowerbd, sh->sh_upperbd)) {
|
||||
/* CSA */
|
||||
arith val;
|
||||
register arith val;
|
||||
|
||||
C_rom_icon(long2str((long)sh->sh_lowerbd,10), size);
|
||||
C_rom_icon(long2str((long)(sh->sh_upperbd - sh->sh_lowerbd),10),
|
||||
@ -155,7 +154,7 @@ void code_endswitch()
|
||||
|
||||
switch_stack = sh->next; /* unstack the switch descriptor */
|
||||
for (ce = sh->sh_entries; ce;) { /* free allocated switch structure */
|
||||
struct case_entry *tmp = ce->next;
|
||||
register struct case_entry *tmp = ce->next;
|
||||
|
||||
free_case_entry(ce);
|
||||
ce = tmp;
|
||||
@ -164,11 +163,12 @@ void code_endswitch()
|
||||
unstack_stmt();
|
||||
}
|
||||
|
||||
void code_case(struct expr *expr)
|
||||
code_case(expr)
|
||||
struct expr *expr;
|
||||
{
|
||||
arith val;
|
||||
struct case_entry *ce;
|
||||
struct switch_hdr *sh = switch_stack;
|
||||
register arith val;
|
||||
register struct case_entry *ce;
|
||||
register struct switch_hdr *sh = switch_stack;
|
||||
|
||||
ASSERT(is_cp_cst(expr));
|
||||
if (sh == 0) {
|
||||
@ -188,7 +188,7 @@ void code_case(struct expr *expr)
|
||||
sh->sh_nrofentries = 1;
|
||||
}
|
||||
else { /* second etc. case entry; put ce into proper place */
|
||||
struct case_entry *c1 = sh->sh_entries, *c2 = 0;
|
||||
register struct case_entry *c1 = sh->sh_entries, *c2 = 0;
|
||||
|
||||
if (val < sh->sh_lowerbd)
|
||||
sh->sh_lowerbd = val;
|
||||
@ -231,9 +231,9 @@ void code_case(struct expr *expr)
|
||||
}
|
||||
}
|
||||
|
||||
void code_default()
|
||||
code_default()
|
||||
{
|
||||
struct switch_hdr *sh = switch_stack;
|
||||
register struct switch_hdr *sh = switch_stack;
|
||||
|
||||
if (sh == 0) {
|
||||
error("default statement not in switch");
|
||||
|
||||
@ -1,16 +0,0 @@
|
||||
/*
|
||||
* The Amsterdam Compiler Kit
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
#ifndef LANG_CEM_CEMCOM_ANSI_SWITCH_H
|
||||
#define LANG_CEM_CEMCOM_ANSI_SWITCH_H
|
||||
|
||||
/* lang/cem/cemcom.ansi/switch.c */
|
||||
int compact(int nr, arith low, arith up);
|
||||
void code_startswitch(struct expr **expp);
|
||||
void code_endswitch(void);
|
||||
void code_case(struct expr *expr);
|
||||
void code_default(void);
|
||||
|
||||
#endif /* LANG_CEM_CEMCOM_ANSI_SWITCH_H */
|
||||
|
||||
@ -10,7 +10,6 @@
|
||||
#include "LLlex.h"
|
||||
#include "tokenname.h"
|
||||
#include "Lpars.h"
|
||||
#include "error.h"
|
||||
|
||||
/* To centralize the declaration of %tokens, their presence in this
|
||||
file is taken as their declaration. The Makefile will produce
|
||||
@ -132,7 +131,8 @@ struct tokenname tkfunny[] = { /* internal keywords */
|
||||
};
|
||||
#endif /* ____ */
|
||||
|
||||
void reserve(struct tokenname resv[])
|
||||
reserve(resv)
|
||||
register struct tokenname resv[];
|
||||
{
|
||||
/* The names of the tokens described in resv are entered
|
||||
as reserved words.
|
||||
|
||||
@ -4,8 +4,6 @@
|
||||
*/
|
||||
/* $Id$ */
|
||||
/* TOKENNAME DEFINITION */
|
||||
#ifndef LANG_CEM_CEMCOM_ANSI_TOCKENNAME_H
|
||||
#define LANG_CEM_CEMCOM_ANSI_TOCKENNAME_H
|
||||
|
||||
struct tokenname { /* Used for defining the name of a
|
||||
token as identified by its symbol
|
||||
@ -13,7 +11,3 @@ struct tokenname { /* Used for defining the name of a
|
||||
int tn_symbol;
|
||||
char *tn_name;
|
||||
};
|
||||
|
||||
void reserve(struct tokenname resv[]);
|
||||
|
||||
#endif /* LANG_CEM_CEMCOM_ANSI_TOCKENNAME_H */
|
||||
|
||||
@ -9,8 +9,6 @@
|
||||
#include "debug.h"
|
||||
#include "botch_free.h"
|
||||
#include <alloc.h>
|
||||
#include "arith.h"
|
||||
#include "util.h"
|
||||
#include "Lpars.h"
|
||||
#include "arith.h"
|
||||
#include "type.h"
|
||||
@ -20,7 +18,11 @@
|
||||
#include "sizes.h"
|
||||
#include "align.h"
|
||||
#include "decspecs.h"
|
||||
#include "error.h"
|
||||
|
||||
extern struct type *function_of(), *array_of();
|
||||
#ifndef NOBITFIELD
|
||||
extern struct type *field_of();
|
||||
#endif /* NOBITFIELD */
|
||||
|
||||
/* To be created dynamically in main() from defaults or from command
|
||||
line parameters.
|
||||
@ -37,12 +39,14 @@ struct type
|
||||
|
||||
struct type *pa_type; /* Pointer-Arithmetic type */
|
||||
|
||||
struct type *create_type(int fund)
|
||||
struct type *
|
||||
create_type(fund)
|
||||
int fund;
|
||||
{
|
||||
/* A brand new struct type is created, and its tp_fund set
|
||||
to fund.
|
||||
*/
|
||||
struct type *ntp = new_type();
|
||||
register struct type *ntp = new_type();
|
||||
|
||||
ntp->tp_fund = fund;
|
||||
ntp->tp_size = (arith)-1;
|
||||
@ -50,34 +54,30 @@ struct type *create_type(int fund)
|
||||
return ntp;
|
||||
}
|
||||
|
||||
struct type *promoted_type(struct type *tp)
|
||||
struct type *
|
||||
promoted_type(tp)
|
||||
struct type *tp;
|
||||
{
|
||||
if (tp->tp_fund == CHAR || tp->tp_fund == SHORT)
|
||||
{
|
||||
if (tp->tp_fund == CHAR || tp->tp_fund == SHORT) {
|
||||
if (tp->tp_unsigned && (int) tp->tp_size == (int) int_size)
|
||||
{
|
||||
return uint_type;
|
||||
}
|
||||
else
|
||||
{
|
||||
return int_type;
|
||||
}
|
||||
}
|
||||
else if (tp->tp_fund == FLOAT)
|
||||
{
|
||||
else return int_type;
|
||||
} else if (tp->tp_fund == FLOAT)
|
||||
return double_type;
|
||||
}
|
||||
return tp;
|
||||
else return tp;
|
||||
}
|
||||
|
||||
|
||||
/* count: for fund == ARRAY only */
|
||||
struct type *construct_type(int fund, struct type *tp, int qual, arith count, struct proto *pl)
|
||||
struct type *
|
||||
construct_type(fund, tp, qual, count, pl)
|
||||
register struct type *tp;
|
||||
register struct proto *pl;
|
||||
arith count; /* for fund == ARRAY only */
|
||||
int qual;
|
||||
{
|
||||
/* fund must be a type constructor: FIELD, FUNCTION, POINTER or
|
||||
ARRAY. The pointer to the constructed type is returned.
|
||||
*/
|
||||
struct type *dtp = NULL;
|
||||
register struct type *dtp;
|
||||
|
||||
switch (fund) {
|
||||
#ifndef NOBITFIELD
|
||||
@ -115,13 +115,17 @@ struct type *construct_type(int fund, struct type *tp, int qual, arith count, st
|
||||
return dtp;
|
||||
}
|
||||
|
||||
struct type *function_of(struct type *tp, struct proto *pl, int qual)
|
||||
struct type *
|
||||
function_of(tp, pl, qual)
|
||||
register struct type *tp;
|
||||
struct proto *pl;
|
||||
int qual;
|
||||
{
|
||||
#if 0
|
||||
/* See comment below */
|
||||
struct type *dtp = tp->tp_function;
|
||||
register struct type *dtp = tp->tp_function;
|
||||
#else
|
||||
struct type *dtp;
|
||||
register struct type *dtp;
|
||||
#endif
|
||||
|
||||
/* look for a type with the right qualifier */
|
||||
@ -157,9 +161,12 @@ struct type *function_of(struct type *tp, struct proto *pl, int qual)
|
||||
return dtp;
|
||||
}
|
||||
|
||||
struct type *pointer_to(struct type *tp, int qual)
|
||||
struct type *
|
||||
pointer_to(tp, qual)
|
||||
register struct type *tp;
|
||||
int qual;
|
||||
{
|
||||
struct type *dtp = tp->tp_pointer;
|
||||
register struct type *dtp = tp->tp_pointer;
|
||||
|
||||
/* look for a type with the right qualifier */
|
||||
while (dtp && dtp->tp_typequal != qual)
|
||||
@ -178,9 +185,13 @@ struct type *pointer_to(struct type *tp, int qual)
|
||||
return dtp;
|
||||
}
|
||||
|
||||
struct type *array_of(struct type *tp, arith count, int qual)
|
||||
struct type *
|
||||
array_of(tp, count, qual)
|
||||
register struct type *tp;
|
||||
arith count;
|
||||
int qual;
|
||||
{
|
||||
struct type *dtp = tp->tp_array;
|
||||
register struct type *dtp = tp->tp_array;
|
||||
|
||||
/* look for a type with the right size */
|
||||
while (dtp && (dtp->tp_nel != count || dtp->tp_typequal != qual))
|
||||
@ -203,9 +214,12 @@ struct type *array_of(struct type *tp, arith count, int qual)
|
||||
}
|
||||
|
||||
#ifndef NOBITFIELD
|
||||
struct type *field_of(struct type *tp, int qual)
|
||||
struct type *
|
||||
field_of(tp, qual)
|
||||
register struct type *tp;
|
||||
int qual;
|
||||
{
|
||||
struct type *dtp = create_type(FIELD);
|
||||
register struct type *dtp = create_type(FIELD);
|
||||
|
||||
dtp->tp_up = tp;
|
||||
dtp->tp_align = tp->tp_align;
|
||||
@ -215,7 +229,10 @@ struct type *field_of(struct type *tp, int qual)
|
||||
}
|
||||
#endif /* NOBITFIELD */
|
||||
|
||||
arith size_of_type(struct type *tp, char nm[])
|
||||
arith
|
||||
size_of_type(tp, nm)
|
||||
struct type *tp;
|
||||
char nm[];
|
||||
{
|
||||
arith sz = tp->tp_size;
|
||||
|
||||
@ -226,14 +243,16 @@ arith size_of_type(struct type *tp, char nm[])
|
||||
return sz;
|
||||
}
|
||||
|
||||
void idf2type(struct idf *idf, struct type **tpp)
|
||||
idf2type(idf, tpp)
|
||||
struct idf *idf;
|
||||
struct type **tpp;
|
||||
{
|
||||
/* Decoding a typedef-ed identifier or basic type: if the
|
||||
size is yet unknown we have to make copy of the type
|
||||
descriptor to prevent garbage at the initialisation of
|
||||
arrays with unknown size.
|
||||
*/
|
||||
struct type *tp = idf->id_def->df_type;
|
||||
register struct type *tp = idf->id_def->df_type;
|
||||
|
||||
if (*tpp) error("multiple types in declaration");
|
||||
if ( tp->tp_size < (arith)0 && tp->tp_fund == ARRAY) {
|
||||
@ -246,14 +265,19 @@ void idf2type(struct idf *idf, struct type **tpp)
|
||||
}
|
||||
}
|
||||
|
||||
arith align(arith pos, int al)
|
||||
arith
|
||||
align(pos, al)
|
||||
arith pos;
|
||||
int al;
|
||||
{
|
||||
return ((pos + al - 1) / al) * al;
|
||||
}
|
||||
|
||||
struct type *standard_type(int fund, int sgn, int algn, arith sz)
|
||||
struct type *
|
||||
standard_type(fund, sgn, algn, sz)
|
||||
int algn; arith sz;
|
||||
{
|
||||
struct type *tp = create_type(fund);
|
||||
register struct type *tp = create_type(fund);
|
||||
|
||||
tp->tp_unsigned = sgn != 0;
|
||||
tp->tp_align = algn;
|
||||
@ -262,16 +286,17 @@ struct type *standard_type(int fund, int sgn, int algn, arith sz)
|
||||
return tp;
|
||||
}
|
||||
|
||||
void completed(struct type *tp)
|
||||
completed(tp)
|
||||
struct type *tp;
|
||||
{
|
||||
struct type *atp = tp->tp_array;
|
||||
struct type *etp = tp;
|
||||
register struct type *atp = tp->tp_array;
|
||||
register struct type *etp = tp;
|
||||
|
||||
switch(etp->tp_fund) {
|
||||
case STRUCT:
|
||||
case UNION:
|
||||
case ENUM:
|
||||
while ( (etp = etp->next) ) {
|
||||
while (etp = etp->next) {
|
||||
if (! etp->tp_sdef) etp->tp_sdef = tp->tp_sdef;
|
||||
etp->tp_size = tp->tp_size;
|
||||
etp->tp_align = tp->tp_align;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user