Compare commits

...

80 Commits

Author SHA1 Message Date
Godzil
ffe13a4583 Update README 2015-06-24 23:41:49 +01:00
George Koehler
c602379db9 Some fixes for aelflod and aslod.
Copy rhead() and rsect() from aslod to aelflod, so aelflod can work
for machine with 64-bit long.

In aelflod, fix ELF header so file(1) no longer reports "corrupted
section header size".

Signed-off-by: Manoel Trapier <godzil@godzil.net>
2015-06-24 23:41:49 +01:00
Godzil
9da790283e Remove/change bad prototypes
In modules/system/time, a bad prototype for "time" was left. There is too some problem with filno under OpenBSD. Currently, the only known OS that don't want to export fileno with c89/c99 standard, is linux, so #ifdef/#endif the prototypes only for linux. (OpenBSD seems to define them as MACROs, that led to errors)
2015-06-24 23:41:49 +01:00
Godzil
0ba3023570 Add a missing header include. 2015-06-24 23:41:49 +01:00
Godzil
06665f4624 Change sbrk definitions.
The prototypes difference between platform is really annoying, since it's hard to always match the system on, and prevent warning on bad types. I try now to always use BRK emulation on all platform that do not match the prototype used in ACK. the PM script should be changed to set this correctly during setup.
2015-06-24 23:41:49 +01:00
Godzil
0f10f91839 Surprisly clang started to tell me where variable may used uninitialized, correcting it!
That's a good point it tell me that, but was a bit unexpected ^^
2015-06-24 23:41:49 +01:00
Godzil
c59e2f03ab Augment the "template" buffer size, 50byte is too short for a path. 2015-06-24 23:41:49 +01:00
Manoel Trapier
5f00cd2e53 Make a brk/sbrk emulation.
Mac OS X seems to have some difficulties with brk/sbrk (maybe with the
4MB heap limit), and replace all the allocation logic will be prone to
errors, I'll add a new define and lib to emulate brk/sbrk using more
standard allocation methods. By default the heap is 64MB, it should be
enough.
2015-06-24 23:41:49 +01:00
Manoel Trapier
e92393d6f3 Correcting a nasty bug introduced in commit 6204c6b6416dfe4d3a0f0b0b7d6d8b5be81acefb 2015-06-24 23:41:49 +01:00
Manoel Trapier
b21aede758 Correct a bad change. 2015-06-24 23:41:49 +01:00
Manoel Trapier
3f6a9560c5 Correct assert definition to correctly display the faulty text instead of "x" 2015-06-24 23:41:49 +01:00
Manoel Trapier
93f542eb7a Add #warning to cemcom.ansi 2015-06-24 23:41:49 +01:00
Manoel Trapier
2071a7dbb0 Correct bad changes 2015-06-24 23:41:48 +01:00
Manoel Trapier
4cb35a7d72 OUPS! printing text here was really not good idea! 2015-06-24 23:41:48 +01:00
Manoel Trapier
d853b7f2fb Converting mach ncg... 2015-06-24 23:41:48 +01:00
Manoel Trapier
ca57bb617b Correct some Linux/clang missing parts. 2015-06-24 23:41:48 +01:00
Godzil
ee6e8bdfc3 Correct comment errors. 2015-06-24 23:41:48 +01:00
Godzil
595e5258aa Update i86 as part. 2015-06-24 23:41:48 +01:00
Godzil
d627b11b98 Do not use ACK cpp (even ANSI one) to compile for the host. 2015-06-24 23:41:48 +01:00
Godzil
da1cb44497 Currently deactivate all language expect ANSI C. 2015-06-24 23:41:48 +01:00
Godzil
a39e88ecca Update generic part of the AS 2015-06-24 23:41:48 +01:00
Godzil
b31c94cf32 cpp.ansi: Add missing "#warning" directive 2015-06-24 23:41:48 +01:00
Manoel Trapier
5c73826e4c Remove unwanted files 2015-06-24 23:41:48 +01:00
Manoel Trapier
46f101f4dd Update makeheader.sh 2015-06-24 23:41:48 +01:00
Manoel Trapier
2830ec90b1 Finishing ANSI C frontend 2015-06-24 23:41:47 +01:00
Manoel Trapier
60b5f91561 More incoherency between MacOSX and Linux... 2015-06-24 23:41:47 +01:00
Godzil
b2d6e23b5f Add small too to generate headers.
(Need cproto)
2015-06-24 23:41:47 +01:00
Godzil
6e6d9c26b5 Working on ANSI C frontend... 2015-06-24 23:41:47 +01:00
Godzil
1c4e04de3a Next batch of changes! 2015-06-24 23:41:47 +01:00
Godzil
a05a174f40 MacOS X/clang found a new batch of warnings :) 2015-06-24 23:41:47 +01:00
Manoel Trapier
1b34c8cc9f Warning hunt on ego. 2015-06-24 23:41:47 +01:00
Manoel Trapier
25c717d9b3 Next batch of warning hunt... 2015-06-24 23:41:47 +01:00
Manoel Trapier
1ed1edf94d Correct an incoherency with arith and label types. 2015-06-24 23:41:47 +01:00
Manoel Trapier
08d1784f95 Remove more warns on ncgg
!! Maybe a bug found in ncgg cgg.y with n_coerc call atline 612
2015-06-24 23:41:47 +01:00
Manoel Trapier
e3b4856beb As suspected clang/Linux have it's own sort of warns ^^ 2015-06-24 23:41:47 +01:00
Godzil
0f7eaacc5f Now CGG compile without warns ;) 2015-06-24 23:41:46 +01:00
Godzil
97bb7d9316 Remove bad prototypes 2015-06-24 23:41:46 +01:00
Manoel Trapier
20d58dea19 Another batch.. 2015-06-24 23:41:46 +01:00
Manoel Trapier
2bbd5a38de More strict checks... 2015-06-24 23:41:46 +01:00
Manoel Trapier
a8d9183e25 Reordonate modules in a more logical way.
(some modules have dependencies on other especially with header files)
2015-06-24 23:41:46 +01:00
Manoel Trapier
a262a916dc Being a bit more strict on warnings (-Wall). 2015-06-24 23:41:46 +01:00
Manoel Trapier
74fb1cff61 Make GCC happy with current patchs and compilation flags. 2015-06-24 23:41:46 +01:00
Godzil
c0cd8650a6 Another batch especially on C ANSI frontend 2015-06-24 23:41:46 +01:00
Godzil
369ec26b03 Add a global symbol2str header 2015-06-24 23:41:46 +01:00
Godzil
2a5ab5b856 Update .gitignore 2015-06-24 23:41:46 +01:00
Godzil
350e569c2c Correct printf with 64bit pointer 2015-06-24 23:41:45 +01:00
Godzil
d87b482eac Correct some error on static function declaration. 2015-06-24 23:41:45 +01:00
Manoel Trapier
b31ac47714 A bit of missing corections. 2015-06-24 23:41:45 +01:00
Manoel Trapier
03763cbbf0 Starting ANSI C frontend 2015-06-24 23:41:45 +01:00
Manoel Trapier
452127650a Next batch 2015-06-24 23:41:45 +01:00
Godzil
bd3e7b87e6 Getting sync. 2015-06-24 23:41:45 +01:00
Godzil
6093a51511 Add missing stdarg (funnily, linux/clang does not complain about this miss) 2015-06-24 23:41:45 +01:00
Manoel Trapier
41f96d5169 Next batch... 2015-06-24 23:41:45 +01:00
Manoel Trapier
c5bfc89269 Update README. 2015-06-24 23:41:45 +01:00
Manoel Trapier
22c8f3ac10 Add transtyping for support of 64bit cpu and 32cpu (or the printf verification for %d/%ld will fail) 2015-06-24 23:41:45 +01:00
Godzil
674eb61908 Another batch... 2015-06-24 23:41:45 +01:00
Godzil
653bd13b40 Correct printf, and minor changes 2015-06-24 23:41:44 +01:00
Godzil
7b8e3edd43 Add missing function prototype. 2015-06-24 23:41:44 +01:00
Godzil
5362498c1c Change arith type to force it to be 32bit. 2015-06-24 23:41:44 +01:00
Manoel Trapier
f6d58a0d04 Another batch... 2015-06-24 23:41:44 +01:00
Manoel Trapier
36a59de862 Change from yacc to byacc (yacc build code that generate warnings...) 2015-06-24 23:41:44 +01:00
Manoel Trapier
0946773758 ANSIfication] Another batch. 2015-06-24 23:41:44 +01:00
Manoel Trapier
3d1d1277b7 Next batch. 2015-06-24 23:41:44 +01:00
Manoel Trapier
60330b05cd Update a bit of module em_code. 2015-06-24 23:41:44 +01:00
Manoel Trapier
e54911f642 Update module assert 2015-06-24 23:41:44 +01:00
Manoel Trapier
71df09d022 Update tokens.g and regenerate tokens.c with it. 2015-06-24 23:41:44 +01:00
Manoel Trapier
498d867bc3 Update LLgen.g and regenerate LLgen.c with it. 2015-06-24 23:41:44 +01:00
Manoel Trapier
f1cd17c51e Next batch, LLgen no longuer have warning under linux/clang. 2015-06-24 23:41:44 +01:00
Manoel Trapier
d28368333a Next batch of Ansi-ification 2015-06-24 23:41:43 +01:00
Manoel Trapier
9f7ae734db Part 1 of warning/old k&r inconsistency correction. 2015-06-24 23:41:43 +01:00
Manoel Trapier
7eff32c40d Force C89 and error on all warnings. 2015-06-24 23:41:43 +01:00
Manoel Trapier
d3715f3ca4 Add missing Copyright file 2015-06-24 23:41:43 +01:00
Manoel Trapier
659f26136a exchange LICENSE and Copyright file 2015-06-24 23:41:43 +01:00
Godzil
33af50ea26 Start k&r to ansi modification 2015-06-24 23:41:43 +01:00
Manoel Trapier
cb89c679ec Update README to display better in markdown 2015-06-24 23:41:43 +01:00
Manoel Trapier
d78a72a6e2 Add markdown and license file 2015-06-24 23:41:43 +01:00
Manoel Trapier
a551523b22 Add gitignore file. 2015-06-24 23:41:43 +01:00
Manoel Trapier
b907b15d4f Add NES platform to default build. (Still more to go to compile correctly) and re-enabling the "k&r" cpp 2015-06-24 23:41:43 +01:00
Manoel Trapier
45e01dcd3e Correct mach cg pmfile that incorrectly reference PLATFORM where it should reference ARCH 2015-06-24 23:41:43 +01:00
Manoel Trapier
cc534493fd Copy pc86 platform to nes platform, and make change accordingly. 2015-06-24 23:41:43 +01:00
590 changed files with 11186 additions and 9422 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
*~
*.o
.*
-.gitignore
/pattern.c

View File

@ -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.

1
Copyright Symbolic link
View File

@ -0,0 +1 @@
LICENSE

32
LICENSE Normal file
View 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.

37
README
View File

@ -1,9 +1,8 @@
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 INTRODUCTION
============ ============
@ -18,6 +17,23 @@ 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 probably broken. However, what's there should be sufficient to get things
done and to evaluate how the full 6.0 release should work. 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 SUPPORT
======= =======
@ -155,16 +171,19 @@ more welcome.
The ACK is licensed under a BSD-like license. Please see the 'Copyright' file The ACK is licensed under a BSD-like license. Please see the 'Copyright' file
for the full text. for the full text.
You can find the mailing list on the project's web site: 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:
http://tack.sourceforge.net/ http://tack.sourceforge.net/
Please enjoy. Please enjoy.
Manoel Trapier (aka godzil) for the ANSI-fication port
David Given (dtrg on Sourceforge) David Given (dtrg on Sourceforge)
dg@cowlark.com dg@cowlark.com
2010-08-08 2010-08-08
# $Source$
# $State$
# $Revision$

1
README.md Symbolic link
View File

@ -0,0 +1 @@
README

View File

@ -25,7 +25,7 @@ CXXPROGRAM = "%CXXCOMPILER% %CBUILDFLAGS% %CLINKFLAGS% %CEXTRAFLAGS% -o %out% %i
CLIBRARY = "rm -f %out% && ar cr %out% %in% && ranlib %out%" CLIBRARY = "rm -f %out% && ar cr %out% %in% && ranlib %out%"
CBUILDFLAGS = {"-g"} CBUILDFLAGS = {"-g", "-Werror", "-std=c89"}
CINCLUDES = EMPTY CINCLUDES = EMPTY
CDEFINES = EMPTY CDEFINES = EMPTY
CEXTRAFLAGS = EMPTY CEXTRAFLAGS = EMPTY

View File

@ -3,7 +3,7 @@ yacc = simple {
outputs = {"%U%/%I%.c"}, outputs = {"%U%/%I%.c"},
command = { command = {
"yacc -t -b %out[1]:dirname%/y -d %in%", "byacc -t -b %out[1]:dirname%/y -d %in%",
"mv %out[1]:dirname%/y.tab.c %out[1]%" "mv %out[1]:dirname%/y.tab.c %out[1]%"
} }
} }

View File

@ -4,6 +4,9 @@
*/ */
/* $Id$ */ /* $Id$ */
#ifndef H_CGG_CG_H
#define H_CGG_CG_H
/* offsets of interesting fields in EM-pattern */ /* offsets of interesting fields in EM-pattern */
#define PO_HASH 0 #define PO_HASH 0
@ -165,3 +168,5 @@ typedef struct { /* one to one coercions */
if ((a=((*(b)++)&BMASK)) >= 128) {\ if ((a=((*(b)++)&BMASK)) >= 128) {\
a = ((a-128)<<BSHIFT) | (*(b)++&BMASK); \ a = ((a-128)<<BSHIFT) | (*(b)++&BMASK); \
} }
#endif /* H_CGG_CG_H */

View File

@ -55,10 +55,7 @@
+ (FL_MSB_AT_LOW_ADDRESS ? 1 : 0)) + (FL_MSB_AT_LOW_ADDRESS ? 1 : 0))
#ifndef USE_FLT #ifndef USE_FLT
static int static int float_cst(char *str, int sz, char *buf)
float_cst(str, sz, buf)
char *str, *buf;
int sz;
{ {
int i; int i;
char *p; char *p;
@ -87,10 +84,7 @@ float_cst(str, sz, buf)
#include <ctype.h> #include <ctype.h>
#include <flt_arith.h> #include <flt_arith.h>
int int float_cst(char *str, int sz, char *buf)
float_cst(str, sz, buf)
char *str, *buf;
int sz;
{ {
int overflow = 0; int overflow = 0;
flt_arith e; flt_arith e;
@ -237,7 +231,7 @@ float_cst(str, sz, buf)
#endif /* USE_FLT */ #endif /* USE_FLT */
#ifdef CODE_GENERATOR #ifdef CODE_GENERATOR
con_float() void con_float()
{ {
char buf[8]; char buf[8];
int rval = float_cst(str, (int)argval, buf); int rval = float_cst(str, (int)argval, buf);
@ -260,9 +254,7 @@ con_float()
#endif /* CODE_GENERATOR */ #endif /* CODE_GENERATOR */
#ifdef CODE_EXPANDER #ifdef CODE_EXPANDER
con_float(str, argval) void con_float(char *str, arith argval)
char *str;
arith argval;
{ {
char buf[8]; char buf[8];
int rval = float_cst(str, (int)argval, buf); int rval = float_cst(str, (int)argval, buf);

29
h/missing_proto.h Normal file
View File

@ -0,0 +1,29 @@
#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 */

15
h/symbol2str.h Normal file
View File

@ -0,0 +1,15 @@
/*
* 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

View File

@ -1,5 +1,5 @@
!File: lint.h !File: lint.h
/*#define LINT 1 /* if defined, 'lint' is produced */ /*#define LINT 1*/ /* if defined, 'lint' is produced */
!File: pathlength.h !File: pathlength.h
@ -75,7 +75,7 @@
!File: botch_free.h !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 !File: dataflow.h
@ -83,7 +83,7 @@
!File: debug.h !File: debug.h
/*#define DEBUG 1 /* perform various self-tests */ /*#define DEBUG 1*/ /* perform various self-tests */
#define NDEBUG 1 /* disable assertions */ #define NDEBUG 1 /* disable assertions */
@ -112,17 +112,17 @@
!File: nopp.h !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 !File: nobitfield.h
/*#define NOBITFIELD 1 /* if NOT defined, implement bitfields */ /*#define NOBITFIELD 1*/ /* if NOT defined, implement bitfields */
!File: spec_arith.h !File: spec_arith.h
/* describes internal compiler arithmetics */ /* describes internal compiler arithmetics */
#undef SPECIAL_ARITHMETICS /* something different from native long */ #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 !File: static.h
@ -130,11 +130,11 @@
!File: nocross.h !File: nocross.h
/*#define NOCROSS 1 /* if NOT defined, cross compiler */ /*#define NOCROSS 1*/ /* if NOT defined, cross compiler */
!File: regcount.h !File: regcount.h
/*#define REGCOUNT 1 /* count occurrences for register messages */ /*#define REGCOUNT 1*/ /* count occurrences for register messages */
!File: dbsymtab.h !File: dbsymtab.h

View File

@ -22,6 +22,9 @@
#include "class.h" #include "class.h"
#include "assert.h" #include "assert.h"
#include "sizes.h" #include "sizes.h"
#include "error.h"
#include "domacro.h"
#include "replace_loc.h"
#include "specials.h" /* registration of special identifiers */ #include "specials.h" /* registration of special identifiers */
/* Data about the token yielded */ /* Data about the token yielded */
@ -62,7 +65,7 @@ static LexSP = 0;
E.g. at the invocation of a sub-parser that uses LLlex(), the E.g. at the invocation of a sub-parser that uses LLlex(), the
state of the current parser should be saved. state of the current parser should be saved.
*/ */
PushLex() void PushLex()
{ {
ASSERT(LexSP < MAX_LL_DEPTH); ASSERT(LexSP < MAX_LL_DEPTH);
ASSERT(ASIDE == 0); /* ASIDE = 0; */ ASSERT(ASIDE == 0); /* ASIDE = 0; */
@ -70,15 +73,14 @@ PushLex()
LexStack[LexSP++] = dot; LexStack[LexSP++] = dot;
} }
PopLex() void PopLex()
{ {
ASSERT(LexSP > 0); ASSERT(LexSP > 0);
dot = LexStack[--LexSP]; dot = LexStack[--LexSP];
} }
#endif /* NOPP */ #endif /* NOPP */
int int LLlex()
LLlex()
{ {
/* LLlex() plays the role of Lexical Analyzer for the C parser. /* LLlex() plays the role of Lexical Analyzer for the C parser.
The look-ahead and putting aside of tokens are taken into The look-ahead and putting aside of tokens are taken into
@ -108,12 +110,13 @@ LLlex()
} }
char *string_token(); char *string_token(char *nm, int stop_char, int *plen);
arith char_constant(); arith char_constant(char *nm);
void skipcomment();
void strint2tok(char intbuf[], struct token *ptok);
void strflt2tok(char fltbuf[], struct token *ptok);
int int GetToken(struct token *ptok)
GetToken(ptok)
register struct token *ptok;
{ {
/* GetToken() is the actual token recognizer. It calls the /* GetToken() is the actual token recognizer. It calls the
control line interpreter if it encounters a "\n{w}*#" control line interpreter if it encounters a "\n{w}*#"
@ -121,7 +124,7 @@ GetToken(ptok)
needed. needed.
*/ */
char buf[(IDFSIZE > NUMSIZE ? IDFSIZE : NUMSIZE) + 1]; char buf[(IDFSIZE > NUMSIZE ? IDFSIZE : NUMSIZE) + 1];
register int ch, nch; int ch, nch;
token_nmb++; token_nmb++;
@ -227,8 +230,7 @@ garbage:
case '<': case '<':
if (AccFileSpecifier) { if (AccFileSpecifier) {
UnGetChar(); /* pushback nch */ UnGetChar(); /* pushback nch */
ptok->tk_bts = string_token("file specifier", ptok->tk_bts = string_token("file specifier", '>', &(ptok->tk_len));
'>', &(ptok->tk_len));
return ptok->tk_symb = FILESPECIFIER; return ptok->tk_symb = FILESPECIFIER;
} }
if (nch == '<') { if (nch == '<') {
@ -312,10 +314,10 @@ garbage:
/* fallthrough */ /* fallthrough */
case STIDF: case STIDF:
{ {
register char *tg = &buf[0]; char *tg = &buf[0];
register int pos = -1; int pos = -1;
register struct idf *idef; struct idf *idef;
extern int idfsize; /* ??? */ extern int idfsize;
#ifndef NOPP #ifndef NOPP
int NoExpandNext = 0; int NoExpandNext = 0;
@ -361,8 +363,8 @@ garbage:
} }
case STNUM: /* a numeric constant */ case STNUM: /* a numeric constant */
{ {
register int siz_left = NUMSIZE - 1; int siz_left = NUMSIZE - 1;
register char *np = &buf[0]; char *np = &buf[0];
int flags = 0; int flags = 0;
#define store(ch) if (--siz_left >= 0) \ #define store(ch) if (--siz_left >= 0) \
@ -444,10 +446,11 @@ garbage:
crash("bad class for char 0%o", ch); crash("bad class for char 0%o", ch);
} }
/*NOTREACHED*/ /*NOTREACHED*/
return 0;
} }
#ifndef NOPP #ifndef NOPP
skipcomment() void skipcomment()
{ {
/* The last character read has been the '*' of '/_*'. The /* The last character read has been the '*' of '/_*'. The
characters, except NL and EOI, between '/_*' and the first characters, except NL and EOI, between '/_*' and the first
@ -459,7 +462,7 @@ skipcomment()
EOI is returned by LoadChar only on encountering EOF of the EOI is returned by LoadChar only on encountering EOF of the
top-level file... top-level file...
*/ */
register int c, oldc = '\0'; int c, oldc = '\0';
NoUnstack++; NoUnstack++;
c = GetChar(); c = GetChar();
@ -501,12 +504,10 @@ skipcomment()
} }
#endif /* NOPP */ #endif /* NOPP */
arith arith char_constant(char *nm)
char_constant(nm)
char *nm;
{ {
register arith val = 0; arith val = 0;
register int ch; int ch;
int size = 0; int size = 0;
ch = GetChar(); ch = GetChar();
@ -534,15 +535,12 @@ char_constant(nm)
return val; return val;
} }
char * char *string_token(char *nm, int stop_char, int *plen)
string_token(nm, stop_char, plen)
char *nm;
int *plen;
{ {
register int ch; int ch;
register int str_size; int str_size;
register char *str = Malloc((unsigned) (str_size = ISTRSIZE)); char *str = Malloc((unsigned) (str_size = ISTRSIZE));
register int pos = 0; int pos = 0;
ch = GetChar(); ch = GetChar();
while (ch != stop_char) { while (ch != stop_char) {
@ -567,9 +565,7 @@ string_token(nm, stop_char, plen)
return str; return str;
} }
int int quoted(int ch)
quoted(ch)
register int ch;
{ {
/* quoted() replaces an escaped character sequence by the /* quoted() replaces an escaped character sequence by the
character meant. character meant.
@ -628,9 +624,7 @@ quoted(ch)
} }
int int hex_val(int ch)
hex_val(ch)
register int ch;
{ {
return is_dig(ch) ? ch - '0' return is_dig(ch) ? ch - '0'
: is_hex(ch) ? (ch - 'a' + 10) & 017 : is_hex(ch) ? (ch - 'a' + 10) & 017
@ -638,13 +632,12 @@ hex_val(ch)
} }
int int GetChar()
GetChar()
{ {
/* The routines GetChar and trigraph parses the trigraph /* The routines GetChar and trigraph parses the trigraph
sequences and removes occurences of \\\n. sequences and removes occurences of \\\n.
*/ */
register int ch; int ch;
#ifndef NOPP #ifndef NOPP
again: again:
@ -671,10 +664,9 @@ again:
} }
#ifndef NOPP #ifndef NOPP
int int trigraph()
trigraph()
{ {
register int ch; int ch;
LoadChar(ch); LoadChar(ch);
if (ch == '?') { if (ch == '?') {
@ -718,24 +710,22 @@ trigraph()
/* strflt2tok only checks the syntax of the floating-point number and /* strflt2tok only checks the syntax of the floating-point number and
* selects the right type for the number. * selects the right type for the number.
*/ */
strflt2tok(fltbuf, ptok) void strflt2tok(char fltbuf[], struct token *ptok)
char fltbuf[];
struct token *ptok;
{ {
register char *cp = fltbuf; char *cp = fltbuf;
int malformed = 0; int malformed = 0;
while (is_dig(*cp)) cp++; while (is_dig(*(unsigned char *)cp)) cp++;
if (*cp == '.') { if (*cp == '.') {
cp++; cp++;
while (is_dig(*cp)) cp++; while (is_dig(*(unsigned char *)cp)) cp++;
} }
if (*cp == 'e' || *cp == 'E') { if (*cp == 'e' || *cp == 'E') {
cp++; cp++;
if (*cp == '+' || *cp == '-') if (*cp == '+' || *cp == '-')
cp++; cp++;
if (!is_dig(*cp)) malformed++; if (!is_dig(*(unsigned char *)cp)) malformed++;
while (is_dig(*cp)) cp++; while (is_dig(*(unsigned char *)cp)) cp++;
} }
if (*cp == 'f' || *cp == 'F') { if (*cp == 'f' || *cp == 'F') {
if (*(cp + 1)) malformed++; if (*(cp + 1)) malformed++;
@ -757,11 +747,9 @@ struct token *ptok;
} }
} }
strint2tok(intbuf, ptok) void strint2tok(char intbuf[], struct token *ptok)
char intbuf[];
struct token *ptok;
{ {
register char *cp = intbuf; char *cp = intbuf;
int base = 10; int base = 10;
arith val = 0, dig, ubound; arith val = 0, dig, ubound;
int uns_flg = 0, lng_flg = 0, malformed = 0, ovfl = 0; int uns_flg = 0, lng_flg = 0, malformed = 0, ovfl = 0;
@ -781,8 +769,8 @@ struct token *ptok;
*/ */
ubound = max_arith / (base / 2); ubound = max_arith / (base / 2);
while (is_hex(*cp)) { while (is_hex(*(unsigned char *)cp)) {
dig = hex_val(*cp); dig = hex_val(*(unsigned char *)cp);
if (dig >= base) { if (dig >= base) {
malformed++; /* ignore */ malformed++; /* ignore */
} }

View File

@ -1,3 +1,5 @@
#ifndef LANG_CEM_CEMCOM_ANSI_LLLEX_H
#define LANG_CEM_CEMCOM_ANSI_LLLEX_H
/* /*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright". * See the copyright notice in the ACK home directory, in the file "Copyright".
@ -63,3 +65,21 @@ extern int err_occurred; /* "error.c" */
#define ASIDE aside.tk_symb #define ASIDE aside.tk_symb
#define EOF (-1) #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 */

View File

@ -10,10 +10,14 @@
#include "arith.h" #include "arith.h"
#include "LLlex.h" #include "LLlex.h"
#include "Lpars.h" #include "Lpars.h"
#include "error.h"
extern char *symbol2str(); #include <symbol2str.h>
LLmessage(tk) { void insert_token(int tk);
void LLmessage(tk)
{
err_occurred = 1; err_occurred = 1;
if (tk < 0) { if (tk < 0) {
error("end of file expected"); error("end of file expected");
@ -34,8 +38,7 @@ LLmessage(tk) {
tk_nmb_at_last_syn_err = token_nmb; tk_nmb_at_last_syn_err = token_nmb;
} }
insert_token(tk) void insert_token(int tk)
int tk;
{ {
aside = dot; aside = dot;

View File

@ -1,5 +1,5 @@
!File: lint.h !File: lint.h
/*#define LINT 1 /* if defined, 'lint' is produced */ /*#define LINT 1*/ /* if defined, 'lint' is produced */
!File: pathlength.h !File: pathlength.h
@ -75,24 +75,24 @@
!File: botch_free.h !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 !File: dataflow.h
/*#define DATAFLOW 1 /* produce some compile-time xref */ /*#define DATAFLOW 1*/ /* produce some compile-time xref */
!File: debug.h !File: debug.h
/*#define DEBUG 1 /* perform various self-tests */ /*#define DEBUG 1*/ /* perform various self-tests */
#define NDEBUG 1 /* disable assertions */ #define NDEBUG 1 /* disable assertions */
!File: use_tmp.h !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 and if USE_TMP is defined let them
precede the rest of the generated precede the rest of the generated
compact code */ 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 to generate EM-code in the order needed
for the code-generators. If not defined, for the code-generators. If not defined,
the old-style peephole optimizer is the old-style peephole optimizer is
@ -108,7 +108,7 @@
!File: inputtype.h !File: inputtype.h
/*#define INP_READ_IN_ONE 1 /* read input file in one */ /*#define INP_READ_IN_ONE 1*/ /* read input file in one */
!File: nopp.h !File: nopp.h
@ -116,13 +116,13 @@
!File: nobitfield.h !File: nobitfield.h
/*#define NOBITFIELD 1 /* if NOT defined, implement bitfields */ /*#define NOBITFIELD 1*/ /* if NOT defined, implement bitfields */
!File: spec_arith.h !File: spec_arith.h
/* describes internal compiler arithmetics */ /* describes internal compiler arithmetics */
#undef SPECIAL_ARITHMETICS /* something different from native long */ #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 !File: static.h
@ -130,14 +130,14 @@
!File: nocross.h !File: nocross.h
/*#define NOCROSS 1 /* if NOT defined, cross compiler */ /*#define NOCROSS 1*/ /* if NOT defined, cross compiler */
!File: regcount.h !File: regcount.h
/*#define REGCOUNT 1 /* count occurrences for register messages */ /*#define REGCOUNT 1*/ /* count occurrences for register messages */
!File: dbsymtab.h !File: dbsymtab.h
/*#define DBSYMTAB 1 /* ability to produce symbol table for debugger */ /*#define DBSYMTAB 1*/ /* ability to produce symbol table for debugger */

View File

@ -27,15 +27,19 @@
#include "field.h" #include "field.h"
#include "mes.h" #include "mes.h"
#include "assert.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 char options[];
extern arith flt_flt2arith();
extern label code_string();
arithbalance(e1p, oper, e2p) /* 3.1.2.5 */ void arithbalance(struct expr **e1p, int oper, struct expr **e2p) /* 3.1.2.5 */
register struct expr **e1p, **e2p;
int oper;
{ {
/* The expressions *e1p and *e2p are balanced to be operands /* The expressions *e1p and *e2p are balanced to be operands
of the arithmetic operator oper. of the arithmetic operator oper.
@ -44,7 +48,7 @@ arithbalance(e1p, oper, e2p) /* 3.1.2.5 */
have a floating type, in which case the flags shouldn't have a floating type, in which case the flags shouldn't
travel upward in the expression tree. travel upward in the expression tree.
*/ */
register int t1, t2, u1, u2; int t1, t2, u1, u2;
int shifting = (oper == LEFT || oper == RIGHT int shifting = (oper == LEFT || oper == RIGHT
|| oper == LEFTAB || oper == RIGHTAB); || oper == LEFTAB || oper == RIGHTAB);
int ptrdiff = 0; int ptrdiff = 0;
@ -53,7 +57,7 @@ arithbalance(e1p, oper, e2p) /* 3.1.2.5 */
t2 = any2arith(e2p, oper); t2 = any2arith(e2p, oper);
if (int_size != pointer_size) { if (int_size != pointer_size) {
if (ptrdiff = ((*e1p)->ex_flags & EX_PTRDIFF) if ((ptrdiff = ((*e1p)->ex_flags & EX_PTRDIFF))
|| ((*e2p)->ex_flags & EX_PTRDIFF)) { || ((*e2p)->ex_flags & EX_PTRDIFF)) {
if (!((*e1p)->ex_flags & EX_PTRDIFF) && t1 == LONG) if (!((*e1p)->ex_flags & EX_PTRDIFF) && t1 == LONG)
ptrdiff = 0; ptrdiff = 0;
@ -82,10 +86,16 @@ arithbalance(e1p, oper, e2p) /* 3.1.2.5 */
return; return;
} else if (t2 == LNGDBL) { } else if (t2 == LNGDBL) {
if (t1 != LNGDBL) if (t1 != LNGDBL)
{
if (t1 == DOUBLE || t1 == FLOAT) if (t1 == DOUBLE || t1 == FLOAT)
{
float2float(e1p, lngdbl_type); float2float(e1p, lngdbl_type);
}
else else
{
int2float(e1p, lngdbl_type); int2float(e1p, lngdbl_type);
}
}
return; return;
} }
@ -173,8 +183,7 @@ arithbalance(e1p, oper, e2p) /* 3.1.2.5 */
} }
} }
relbalance(e1p, oper, e2p) void relbalance(struct expr **e1p, int oper, struct expr **e2p)
register struct expr **e1p, **e2p;
{ {
/* The expressions *e1p and *e2p are balanced to be operands /* The expressions *e1p and *e2p are balanced to be operands
of the relational operator oper, or the ':'. of the relational operator oper, or the ':'.
@ -183,7 +192,7 @@ relbalance(e1p, oper, e2p)
allows assignments of a null-pointer to a function allows assignments of a null-pointer to a function
pointer. pointer.
*/ */
register struct expr *e1 = *e1p, *e2 = *e2p; struct expr *e1 = *e1p, *e2 = *e2p;
struct expr *tmpexpr; struct expr *tmpexpr;
if (e1->ex_type->tp_fund == POINTER if (e1->ex_type->tp_fund == POINTER
@ -206,15 +215,13 @@ relbalance(e1p, oper, e2p)
arithbalance(e1p, oper, e2p); arithbalance(e1p, oper, e2p);
} }
ch3pointer(expp, oper, tp) void ch3pointer(struct expr **expp, int oper, struct type *tp)
struct expr **expp;
register struct type *tp;
{ {
/* Checks whether *expp may be compared to tp using oper, /* Checks whether *expp may be compared to tp using oper,
as described in chapter 3.3.8 and 3.3.9. as described in chapter 3.3.8 and 3.3.9.
tp is known to be a pointer. tp is known to be a pointer.
*/ */
register struct expr *exp = *expp; struct expr *exp = *expp;
if (exp->ex_type->tp_fund == POINTER) { if (exp->ex_type->tp_fund == POINTER) {
if (exp->ex_type != tp) if (exp->ex_type != tp)
@ -239,10 +246,7 @@ ch3pointer(expp, oper, tp)
} }
} }
int int any2arith(struct expr **expp, int oper)
any2arith(expp, oper)
register struct expr **expp;
register int oper;
{ {
/* Turns any expression into int_type, long_type, /* Turns any expression into int_type, long_type,
float_type, double_type or lngdbl_type. float_type, double_type or lngdbl_type.
@ -297,8 +301,7 @@ any2arith(expp, oper)
return (*expp)->ex_type->tp_fund; return (*expp)->ex_type->tp_fund;
} }
erroneous2int(expp) void erroneous2int(struct expr **expp)
struct expr **expp;
{ {
/* the (erroneous) expression *expp is replaced by an /* the (erroneous) expression *expp is replaced by an
int expression int expression
@ -312,16 +315,12 @@ erroneous2int(expp)
*expp = exp; *expp = exp;
} }
struct expr * struct expr *arith2arith(struct type *tp, int oper, struct expr *expr)
arith2arith(tp, oper, expr)
struct type *tp;
int oper;
register struct expr *expr;
{ {
/* arith2arith constructs a new expression containing a /* arith2arith constructs a new expression containing a
run-time conversion between some arithmetic types. run-time conversion between some arithmetic types.
*/ */
register struct expr *new = new_expr(); struct expr *new = new_expr();
new->ex_file = expr->ex_file; new->ex_file = expr->ex_file;
new->ex_line = expr->ex_line; new->ex_line = expr->ex_line;
@ -330,18 +329,15 @@ arith2arith(tp, oper, expr)
return new_oper(tp, new, oper, expr); return new_oper(tp, new, oper, expr);
} }
int int int2int(struct expr **expp, struct type *tp)
int2int(expp, tp)
struct expr **expp;
register struct type *tp;
{ {
/* The expression *expp, which is of some integral type, is /* The expression *expp, which is of some integral type, is
converted to the integral type tp. converted to the integral type tp.
*/ */
register struct expr *exp = *expp; struct expr *exp = *expp;
if (is_cp_cst(exp)) { if (is_cp_cst(exp)) {
register struct type *tp1 = exp->ex_type; struct type *tp1 = exp->ex_type;
exp->ex_type = tp; exp->ex_type = tp;
if (! tp1->tp_unsigned && tp->tp_unsigned) { if (! tp1->tp_unsigned && tp->tp_unsigned) {
@ -371,14 +367,12 @@ int2int(expp, tp)
/* With compile-time constants, we don't set fp_used, since this is done /* With compile-time constants, we don't set fp_used, since this is done
* only when necessary in eval.c. * only when necessary in eval.c.
*/ */
int2float(expp, tp) void int2float(struct expr **expp, struct type *tp)
register struct expr **expp;
struct type *tp;
{ {
/* The expression *expp, which is of some integral type, is /* The expression *expp, which is of some integral type, is
converted to the floating type tp. converted to the floating type tp.
*/ */
register struct expr *exp = *expp; struct expr *exp = *expp;
int uns = exp->ex_type->tp_unsigned; int uns = exp->ex_type->tp_unsigned;
if (is_cp_cst(exp)) { if (is_cp_cst(exp)) {
@ -392,14 +386,12 @@ int2float(expp, tp)
} }
} }
float2int(expp, tp) void float2int(struct expr **expp, struct type *tp)
struct expr **expp;
struct type *tp;
{ {
/* The expression *expp, which is of some floating type, is /* The expression *expp, which is of some floating type, is
converted to the integral type tp. converted to the integral type tp.
*/ */
register struct expr *ex = *expp; struct expr *ex = *expp;
if (is_fp_cst(ex)) { if (is_fp_cst(ex)) {
arith ar = flt_flt2arith(&ex->FL_ARITH, tp->tp_unsigned); arith ar = flt_flt2arith(&ex->FL_ARITH, tp->tp_unsigned);
@ -420,9 +412,7 @@ float2int(expp, tp)
} }
} }
float2float(expp, tp) void float2float(struct expr**expp, struct type *tp)
register struct expr **expp;
struct type *tp;
{ {
/* The expression *expp, which is of some floating type, is /* The expression *expp, which is of some floating type, is
converted to the floating type tp. converted to the floating type tp.
@ -438,8 +428,7 @@ float2float(expp, tp)
} }
} }
array2pointer(exp) void array2pointer(struct expr *exp)
register struct expr *exp;
{ {
/* The expression, which must be an array, is converted /* The expression, which must be an array, is converted
to a pointer. to a pointer.
@ -449,8 +438,7 @@ array2pointer(exp)
, (arith)0, NO_PROTO); , (arith)0, NO_PROTO);
} }
function2pointer(exp) void function2pointer(struct expr *exp)
register struct expr *exp;
{ {
/* The expression, which must be a function, is converted /* The expression, which must be a function, is converted
to a pointer to the function. to a pointer to the function.
@ -459,8 +447,7 @@ function2pointer(exp)
(arith)0, NO_PROTO); (arith)0, NO_PROTO);
} }
string2pointer(ex) void string2pointer(struct expr *ex)
register struct expr *ex;
{ {
/* The expression, which must be a string constant, is converted /* The expression, which must be a string constant, is converted
to a pointer to the string-containing area. to a pointer to the string-containing area.
@ -474,11 +461,9 @@ string2pointer(ex)
ex->VL_VALUE = (arith)0; ex->VL_VALUE = (arith)0;
} }
opnd2integral(expp, oper) void opnd2integral(struct expr **expp, int oper)
register struct expr **expp;
int oper;
{ {
register int fund = (*expp)->ex_type->tp_fund; int fund = (*expp)->ex_type->tp_fund;
if (fund != INT && fund != LONG) { if (fund != INT && fund != LONG) {
expr_error(*expp, "%s operand to %s", expr_error(*expp, "%s operand to %s",
@ -488,9 +473,7 @@ opnd2integral(expp, oper)
} }
} }
opnd2logical(expp, oper) void opnd2logical(struct expr **expp, int oper)
register struct expr **expp;
int oper;
{ {
int fund = (*expp)->ex_type->tp_fund; int fund = (*expp)->ex_type->tp_fund;
@ -526,8 +509,7 @@ opnd2logical(expp, oper)
} }
} }
opnd2test(expp, oper) void opnd2test(struct expr **expp, int oper)
register struct expr **expp;
{ {
opnd2logical(expp, oper); opnd2logical(expp, oper);
if ((*expp)->ex_class == Oper) { if ((*expp)->ex_class == Oper) {
@ -551,8 +533,7 @@ opnd2test(expp, oper)
ch3bin(expp, NOTEQUAL, intexpr((arith)0, INT)); ch3bin(expp, NOTEQUAL, intexpr((arith)0, INT));
} }
any2opnd(expp, oper) void any2opnd(struct expr **expp, int oper)
register struct expr **expp;
{ {
if (!*expp) if (!*expp)
return; return;
@ -563,7 +544,9 @@ any2opnd(expp, oper)
case CHAR: case CHAR:
case SHORT: case SHORT:
case ENUM: case ENUM:
/* case FLOAT: /* not necessary anymore */ #if 0
case FLOAT: /* not necessary anymore */
#endif
any2arith(expp, oper); any2arith(expp, oper);
break; break;
case ARRAY: case ARRAY:
@ -584,8 +567,7 @@ any2opnd(expp, oper)
} }
} }
any2parameter(expp) void any2parameter(struct expr **expp)
register struct expr **expp;
{ {
/* To handle default argument promotions /* To handle default argument promotions
*/ */
@ -598,14 +580,13 @@ any2parameter(expp)
} }
#ifndef NOBITFIELD #ifndef NOBITFIELD
field2arith(expp) void field2arith(struct expr **expp)
register struct expr **expp;
{ {
/* The expression to extract the bitfield value from the /* The expression to extract the bitfield value from the
memory word is put in the tree. memory word is put in the tree.
*/ */
register struct type *tp = (*expp)->ex_type->tp_up; struct type *tp = (*expp)->ex_type->tp_up;
register struct field *fd = (*expp)->ex_type->tp_field; struct field *fd = (*expp)->ex_type->tp_field;
(*expp)->ex_type = word_type; (*expp)->ex_type = word_type;
@ -630,8 +611,7 @@ field2arith(expp)
/* switch_sign_fp() negates the given floating constant expression, /* switch_sign_fp() negates the given floating constant expression,
* and frees the string representing the old value. * and frees the string representing the old value.
*/ */
switch_sign_fp(expr) void switch_sign_fp(struct expr *expr)
register struct expr *expr;
{ {
flt_umin(&(expr->FL_ARITH)); flt_umin(&(expr->FL_ARITH));
} }

View File

@ -1,3 +1,5 @@
#ifndef LANG_CEM_CEMCOM_ANSI_ARITH_H
#define LANG_CEM_CEMCOM_ANSI_ARITH_H
/* /*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright". * See the copyright notice in the ACK home directory, in the file "Copyright".
@ -23,10 +25,40 @@
/* All preprocessor arithmetic should be done in longs. /* All preprocessor arithmetic should be done in longs.
*/ */
#define arith long /* dummy */ #include <stdint.h>
typedef int32_t arith; /* dummy */
#endif /* SPECIAL_ARITHMETICS */ #endif /* SPECIAL_ARITHMETICS */
#define arith_size (sizeof(arith)) #define arith_size (sizeof(arith))
#define arith_sign ((arith) 1 << (arith_size * 8 - 1)) #define arith_sign ((arith) 1 << (arith_size * 8 - 1))
#define max_arith (~arith_sign) #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 */

View File

@ -18,9 +18,16 @@
#include "label.h" #include "label.h"
#include "stack.h" #include "stack.h"
#include "Lpars.h" #include "Lpars.h"
extern arith NewLocal(); #include "util_loc.h"
#include "error.h"
#include "idf_loc.h"
#include "def.h"
#define LocalPtrVar() NewLocal(pointer_size, pointer_align, reg_pointer, REGISTER) #define LocalPtrVar() NewLocal(pointer_size, pointer_align, reg_pointer, REGISTER)
#define LocalIntVar() NewLocal(int_size, int_align, reg_any, REGISTER) #define LocalIntVar() NewLocal(int_size, int_align, reg_any, REGISTER)
static void copy_loop(arith sz, arith src, arith dst);
#endif /* STB */ #endif /* STB */
/* Because EM does not support the loading and storing of /* Because EM does not support the loading and storing of
@ -52,9 +59,7 @@ extern arith NewLocal();
while we need a loop to store the stack block into a memory object. while we need a loop to store the stack block into a memory object.
*/ */
suitable_sz(sz, al) static int suitable_sz(arith sz, int al)
arith sz;
int al;
{ {
return ((int)sz % (int)word_size == 0 && al % word_align == 0) || return ((int)sz % (int)word_size == 0 && al % word_align == 0) ||
( (
@ -64,9 +69,7 @@ suitable_sz(sz, al)
); );
} }
store_block(sz, al) void store_block(arith sz, int al)
arith sz;
int al;
{ {
if (suitable_sz(sz, al)) if (suitable_sz(sz, al))
C_sti(sz); C_sti(sz);
@ -102,9 +105,7 @@ store_block(sz, al)
} }
} }
load_block(sz, al) void load_block(arith sz, int al)
arith sz;
int al;
{ {
if (suitable_sz(sz, al)) if (suitable_sz(sz, al))
@ -138,9 +139,7 @@ load_block(sz, al)
} }
} }
copy_block(sz, al) void copy_block(arith sz, int al)
arith sz;
int al;
{ {
if (suitable_sz(sz, al)) if (suitable_sz(sz, al))
@ -167,8 +166,7 @@ copy_block(sz, al)
} }
#ifndef STB #ifndef STB
copy_loop(sz, src, dst) static void copy_loop(arith sz, arith src, arith dst)
arith sz, src, dst;
{ {
/* generate inline byte-copy loop */ /* generate inline byte-copy loop */
label l_cont = text_label(), l_stop = text_label(); label l_cont = text_label(), l_stop = text_label();

View File

@ -0,0 +1,8 @@
#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

View File

@ -20,26 +20,35 @@
#include "Lpars.h" #include "Lpars.h"
#include "assert.h" #include "assert.h"
#include "file_info.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[]; extern char options[];
extern char *symbol2str();
extern struct type *qualifier_type(); 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);
/* Most expression-handling routines have a pointer to a /* Most expression-handling routines have a pointer to a
(struct type *) as first parameter. The object under the pointer (struct type *) as first parameter. The object under the pointer
gets updated in the process. gets updated in the process.
*/ */
ch3sel(expp, oper, idf) void ch3sel(struct expr **expp, int oper, struct idf *idf)
struct expr **expp;
struct idf *idf;
{ {
/* The selector idf is applied to *expp; oper may be '.' or /* The selector idf is applied to *expp; oper may be '.' or
ARROW. ARROW.
*/ */
register struct expr *exp; struct expr *exp;
register struct type *tp; struct type *tp;
register struct sdef *sd; struct sdef *sd;
any2opnd(expp, oper); any2opnd(expp, oper);
exp = *expp; exp = *expp;
@ -162,8 +171,7 @@ ch3sel(expp, oper, idf)
*expp = exp; *expp = exp;
} }
ch3incr(expp, oper) void ch3incr(struct expr **expp, int oper)
struct expr **expp;
{ {
/* The monadic prefix/postfix incr/decr operator oper is /* The monadic prefix/postfix incr/decr operator oper is
applied to *expp. applied to *expp.
@ -171,17 +179,15 @@ ch3incr(expp, oper)
ch3asgn(expp, oper, intexpr((arith)1, INT)); ch3asgn(expp, oper, intexpr((arith)1, INT));
} }
ch3cast(expp, oper, tp) void ch3cast(struct expr **expp, int oper, struct type *tp)
register struct expr **expp;
register struct type *tp;
{ {
/* The expression *expp is cast to type tp; the cast is /* The expression *expp is cast to type tp; the cast is
caused by the operator oper. If the cast has caused by the operator oper. If the cast has
to be passed on to run time, its left operand will be an to be passed on to run time, its left operand will be an
expression of class Type. expression of class Type.
*/ */
register struct type *oldtp; struct type *oldtp;
register struct expr *exp = *expp; struct expr *exp = *expp;
int qual_lev, ascompat = 0; int qual_lev, ascompat = 0;
if (oper == RETURN && tp->tp_fund == VOID) { if (oper == RETURN && tp->tp_fund == VOID) {
@ -410,9 +416,7 @@ ch3cast(expp, oper, tp)
/* Determine whether two types are equal. /* Determine whether two types are equal.
*/ */
equal_type(tp, otp, qual_lev, diag) int equal_type(struct type *tp, struct type *otp, int qual_lev, int diag)
register struct type *tp, *otp;
int qual_lev, diag;
{ {
if (tp == otp) if (tp == otp)
return 1; return 1;
@ -473,8 +477,7 @@ equal_type(tp, otp, qual_lev, diag)
} }
} }
check_pseudoproto(pl, opl, diag) static int check_pseudoproto(struct proto *pl, struct proto *opl, int diag)
register struct proto *pl, *opl;
{ {
int retval = 1; int retval = 1;
@ -517,13 +520,11 @@ check_pseudoproto(pl, opl, diag)
return retval; return retval;
} }
legal_mixture(tp, otp, diag) static int legal_mixture(struct type *tp, struct type *otp, int diag)
struct type *tp, *otp;
int diag;
{ {
struct proto *pl = tp->tp_proto, *opl = otp->tp_proto; struct proto *pl = tp->tp_proto, *opl = otp->tp_proto;
int retval = 1; int retval = 1;
register struct proto *prot; struct proto *prot;
int fund; int fund;
ASSERT( (pl != 0) ^ (opl != 0)); ASSERT( (pl != 0) ^ (opl != 0));
@ -560,9 +561,7 @@ legal_mixture(tp, otp, diag)
return retval; return retval;
} }
equal_proto(pl, opl, diag) static int equal_proto(struct proto *pl, struct proto *opl, int diag)
register struct proto *pl, *opl;
int diag;
{ {
if (pl == opl) if (pl == opl)
return 1; return 1;
@ -584,11 +583,9 @@ equal_proto(pl, opl, diag)
} }
/* check if a type has a consqualified member */ /* check if a type has a consqualified member */
recurqual(tp, qual) int recurqual(struct type *tp, int qual)
struct type *tp;
int qual;
{ {
register struct sdef *sdf; struct sdef *sdf;
ASSERT(tp); ASSERT(tp);
@ -608,9 +605,7 @@ int qual;
return 0; return 0;
} }
ch3asgn(expp, oper, expr) void ch3asgn(struct expr **expp, int oper, struct expr *expr)
struct expr **expp;
struct expr *expr;
{ {
/* The assignment operators. /* The assignment operators.
"f op= e" should be interpreted as "f op= e" should be interpreted as
@ -625,7 +620,7 @@ ch3asgn(expp, oper, expr)
f (typeof (f op e))e f (typeof (f op e))e
EVAL should however take care of evaluating (typeof (f op e))f EVAL should however take care of evaluating (typeof (f op e))f
*/ */
register struct expr *exp = *expp; struct expr *exp = *expp;
int fund = exp->ex_type->tp_fund; int fund = exp->ex_type->tp_fund;
struct type *tp; struct type *tp;
char *oper_string = symbol2str(oper); char *oper_string = symbol2str(oper);
@ -685,9 +680,7 @@ ch3asgn(expp, oper, expr)
/* Some interesting (?) questions answered. /* Some interesting (?) questions answered.
*/ */
int int is_integral_type(struct type *tp)
is_integral_type(tp)
register struct type *tp;
{ {
switch (tp->tp_fund) { switch (tp->tp_fund) {
case CHAR: case CHAR:
@ -705,9 +698,7 @@ is_integral_type(tp)
} }
} }
int static int is_arith_type(struct type *tp)
is_arith_type(tp)
register struct type *tp;
{ {
switch (tp->tp_fund) { switch (tp->tp_fund) {
case CHAR: case CHAR:

View File

@ -0,0 +1,17 @@
/*
* 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

View File

@ -18,9 +18,24 @@
#include "expr.h" #include "expr.h"
#include "Lpars.h" #include "Lpars.h"
#include "sizes.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[]; extern char options[];
extern char *symbol2str();
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);
/* This chapter asks for the repeated application of code to handle /* This chapter asks for the repeated application of code to handle
an operation that may be executed at compile time or at run time, an operation that may be executed at compile time or at run time,
@ -35,9 +50,7 @@ extern char *symbol2str();
#define commutative_binop(expp, oper, expr) mk_binop(expp, oper, expr, 1) #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) #define non_commutative_relop(expp, oper, expr) mk_binop(expp, oper, expr, 1)
ch3bin(expp, oper, expr) void ch3bin(struct expr **expp, int oper, struct expr *expr)
register struct expr **expp;
struct expr *expr;
{ {
/* apply binary operator oper between *expp and expr. /* apply binary operator oper between *expp and expr.
NB: don't swap operands if op is one of the op= operators!!! NB: don't swap operands if op is one of the op= operators!!!
@ -295,8 +308,7 @@ ch3bin(expp, oper, expr)
} }
} }
pntminuspnt(expp, oper, expr) static void pntminuspnt(struct expr **expp, int oper, struct expr *expr)
register struct expr **expp, *expr;
{ {
/* Subtracting two pointers is so complicated it merits a /* Subtracting two pointers is so complicated it merits a
routine of its own. routine of its own.
@ -327,8 +339,7 @@ pntminuspnt(expp, oper, expr)
* when the arguments are switched. This is special for some relational * when the arguments are switched. This is special for some relational
* operators. * operators.
*/ */
int static int arg_switched(int oper)
arg_switched(oper)
{ {
switch (oper) { switch (oper) {
case '<': return '>'; case '<': return '>';
@ -339,9 +350,7 @@ arg_switched(oper)
} }
} }
mk_binop(expp, oper, expr, commutative) static void mk_binop(struct expr **expp, int oper, struct expr *expr, int commutative)
struct expr **expp;
register struct expr *expr;
{ {
/* Constructs in *expp the operation indicated by the operands. /* Constructs in *expp the operation indicated by the operands.
"commutative" indicates whether "oper" is a commutative "commutative" indicates whether "oper" is a commutative
@ -365,8 +374,7 @@ mk_binop(expp, oper, expr, commutative)
} }
} }
pointer_arithmetic(expp1, oper, expp2) static void pointer_arithmetic(struct expr **expp1, int oper, struct expr **expp2)
register struct expr **expp1, **expp2;
{ {
int typ; int typ;
/* prepares the integral expression expp2 in order to /* prepares the integral expression expp2 in order to
@ -386,8 +394,7 @@ pointer_arithmetic(expp1, oper, expp2)
); );
} }
pointer_binary(expp, oper, expr) static void pointer_binary(struct expr **expp, int oper, struct expr *expr)
register struct expr **expp, *expr;
{ {
/* constructs the pointer arithmetic expression out of /* constructs the pointer arithmetic expression out of
a pointer expression, a binary operator and an integral a pointer expression, a binary operator and an integral

View File

@ -0,0 +1,11 @@
/*
* 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

View File

@ -18,13 +18,22 @@
#include "idf.h" #include "idf.h"
#include "def.h" #include "def.h"
#include "sizes.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 char options[];
extern arith full_mask[/*MAXSIZE + 1*/]; /* cstoper.c */ extern arith full_mask[/*MAXSIZE + 1*/]; /* cstoper.c */
char *symbol2str();
ch3mon(oper, expp)
register struct expr **expp; void ch3mon(int oper, struct expr **expp)
{ {
/* The monadic prefix operator oper is applied to *expp. /* The monadic prefix operator oper is applied to *expp.
*/ */

View File

@ -0,0 +1,11 @@
/*
* 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

View File

@ -40,6 +40,21 @@
#include "assert.h" #include "assert.h"
#include "LLlex.h" #include "LLlex.h"
#include "align.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 #ifdef LINT
#include "l_lint.h" #include "l_lint.h"
#endif /* LINT */ #endif /* LINT */
@ -51,7 +66,6 @@ label lab_count = 1;
label datlab_count = 1; label datlab_count = 1;
int fp_used; int fp_used;
extern arith NewLocal(); /* util.c */
/* global function info */ /* global function info */
char *func_name; char *func_name;
@ -66,12 +80,14 @@ static int pro_id;
#endif /* USE_TMP */ #endif /* USE_TMP */
extern char options[]; extern char options[];
extern char *symbol2str();
extern char *source; extern char *source;
static void def_strings(struct string_cst *sc);
static void prc_entry(char *name);
static void prc_exit();
#ifndef LINT #ifndef LINT
init_code(dst_file) void init_code(char *dst_file)
char *dst_file;
{ {
/* init_code() initialises the output file on which the /* init_code() initialises the output file on which the
compact EM code is written compact EM code is written
@ -108,10 +124,7 @@ init_code(dst_file)
struct string_cst *str_list = 0; struct string_cst *str_list = 0;
label label code_string(char *val, int len)
code_string(val, len)
char *val;
int len;
{ {
register struct string_cst *sc = new_string_cst(); register struct string_cst *sc = new_string_cst();
label dlb = data_label(); label dlb = data_label();
@ -125,8 +138,7 @@ code_string(val, len)
return dlb; return dlb;
} }
def_strings(sc) static void def_strings(struct string_cst *sc)
register struct string_cst *sc;
{ {
while (sc) { while (sc) {
struct string_cst *sc1 = sc; struct string_cst *sc1 = sc;
@ -140,7 +152,8 @@ def_strings(sc)
} }
/* flush_strings() is called from program.g after each external definition */ /* flush_strings() is called from program.g after each external definition */
flush_strings() { void flush_strings()
{
if (str_list) { if (str_list) {
def_strings(str_list); def_strings(str_list);
str_list = 0; str_list = 0;
@ -148,7 +161,7 @@ flush_strings() {
} }
#ifndef LINT #ifndef LINT
end_code() void end_code()
{ {
/* end_code() performs the actions to be taken when closing /* end_code() performs the actions to be taken when closing
the output stream. the output stream.
@ -163,19 +176,19 @@ end_code()
#endif /* LINT */ #endif /* LINT */
#ifdef PREPEND_SCOPES #ifdef PREPEND_SCOPES
prepend_scopes() void prepend_scopes()
{ {
/* prepend_scopes() runs down the list of global idf's /* prepend_scopes() runs down the list of global idf's
and generates those exa's, exp's, ina's and inp's and generates those exa's, exp's, ina's and inp's
that superior hindsight has provided. that superior hindsight has provided.
*/ */
register struct stack_entry *se = local_level->sl_entry; struct stack_entry *se = local_level->sl_entry;
#ifdef USE_TMP #ifdef USE_TMP
C_beginpart(tmp_id); C_beginpart(tmp_id);
#endif /* USE_TMP */ #endif /* USE_TMP */
while (se != 0) { while (se != 0) {
register struct def *df = se->se_idf->id_def; struct def *df = se->se_idf->id_def;
if (df && (df->df_initialized || df->df_used || df->df_alloc)) { if (df && (df->df_initialized || df->df_used || df->df_alloc)) {
code_scope(se->se_idf->id_text, df); code_scope(se->se_idf->id_text, df);
@ -188,9 +201,7 @@ prepend_scopes()
} }
#endif /* PREPEND_SCOPES */ #endif /* PREPEND_SCOPES */
code_scope(text, def) void code_scope(char *text, struct def *def)
char *text;
register struct def *def;
{ {
/* generates code for one name, text, of the storage class /* generates code for one name, text, of the storage class
as given by def, if meaningful. as given by def, if meaningful.
@ -221,9 +232,8 @@ static int struct_return;
static char *last_fn_given = (char *)0; static char *last_fn_given = (char *)0;
static label file_name_label; static label file_name_label;
begin_proc(ds, idf) /* to be called when entering a procedure */ /* to be called when entering a procedure */
struct decspecs *ds; void begin_proc(struct decspecs *ds, struct idf *idf)
struct idf *idf;
{ {
/* begin_proc() is called at the entrance of a new function /* begin_proc() is called at the entrance of a new function
and performs the necessary code generation: and performs the necessary code generation:
@ -233,8 +243,8 @@ begin_proc(ds, idf) /* to be called when entering a procedure */
does not fit in the return area does not fit in the return area
- a fil pseudo instruction - a fil pseudo instruction
*/ */
register char *name = idf->id_text; char *name = idf->id_text;
register struct def *def = idf->id_def; struct def *def = idf->id_def;
/* idf->id_def does not indicate the right def structure /* idf->id_def does not indicate the right def structure
* when the function being defined has a parameter of the * when the function being defined has a parameter of the
@ -320,8 +330,7 @@ begin_proc(ds, idf) /* to be called when entering a procedure */
#endif #endif
} }
end_proc(fbytes) void end_proc(arith fbytes)
arith fbytes;
{ {
/* end_proc() deals with the code to be generated at the end of /* end_proc() deals with the code to be generated at the end of
a function, as there is: a function, as there is:
@ -391,7 +400,7 @@ end_proc(fbytes)
options['n'] = optionsn; options['n'] = optionsn;
} }
do_return() void do_return()
{ {
/* do_return handles the case of a return without expression. /* do_return handles the case of a return without expression.
This version branches to the return label, which is This version branches to the return label, which is
@ -404,8 +413,7 @@ do_return()
C_bra(return2_label); C_bra(return2_label);
} }
do_return_expr(expr) void do_return_expr(struct expr *expr)
struct expr *expr;
{ {
/* do_return_expr() generates the expression and the jump for /* do_return_expr() generates the expression and the jump for
a return statement with an expression. a return statement with an expression.
@ -420,11 +428,12 @@ do_return_expr(expr)
return_expr_occurred = 1; return_expr_occurred = 1;
} }
code_declaration(idf, expr, lvl, sc) /* struct idf *idf idf to be declared
register struct idf *idf; /* idf to be declared */ * struct expr *expr initialisation; NULL if absent
struct expr *expr; /* initialisation; NULL if absent */ * int lvl declaration level
int lvl; /* declaration level */ * int sc storage class, as in the declaration
int sc; /* storage class, as in the declaration */ */
void code_declaration(struct idf *idf, struct expr *expr, int lvl, int sc)
{ {
/* code_declaration() does the actual declaration of the /* code_declaration() does the actual declaration of the
variable indicated by "idf" on declaration level "lvl". variable indicated by "idf" on declaration level "lvl".
@ -445,8 +454,8 @@ code_declaration(idf, expr, lvl, sc)
The sc is the actual storage class, as given in the The sc is the actual storage class, as given in the
declaration. declaration.
*/ */
register struct def *def = idf->id_def; struct def *def = idf->id_def;
register arith size = def->df_type->tp_size; arith size = def->df_type->tp_size;
int fund = def->df_type->tp_fund; int fund = def->df_type->tp_fund;
int def_sc = def->df_sc; int def_sc = def->df_sc;
@ -532,17 +541,15 @@ code_declaration(idf, expr, lvl, sc)
} }
} }
loc_init(expr, id) void loc_init(struct expr *expr, struct idf *id)
struct expr *expr;
struct idf *id;
{ {
/* loc_init() generates code for the assignment of /* loc_init() generates code for the assignment of
expression expr to the local variable described by id. expression expr to the local variable described by id.
It frees the expression afterwards. It frees the expression afterwards.
*/ */
register struct expr *e = expr; struct expr *e = expr;
register struct def *df = id->id_def; struct def *df = id->id_def;
register struct type *tp = df->df_type; struct type *tp = df->df_type;
static arith tmpoffset = 0; static arith tmpoffset = 0;
static arith unknownsize = 0; static arith unknownsize = 0;
@ -610,12 +617,11 @@ loc_init(expr, id)
} }
} }
bss(idf) void bss(struct idf *idf)
register struct idf *idf;
{ {
/* bss() allocates bss space for the global idf. /* bss() allocates bss space for the global idf.
*/ */
register struct def *df = idf->id_def; struct def *df = idf->id_def;
#ifndef PREPEND_SCOPES #ifndef PREPEND_SCOPES
code_scope(idf->id_text, df); code_scope(idf->id_text, df);
@ -641,15 +647,13 @@ bss(idf)
} }
} }
formal_cvt(hasproto,df) void formal_cvt(int hasproto, struct def *df)
int hasproto;
register struct def *df;
{ {
/* formal_cvt() converts a formal parameter of type char or /* formal_cvt() converts a formal parameter of type char or
short from int to that type. It also converts a formal short from int to that type. It also converts a formal
parameter of type float from a double to a float. parameter of type float from a double to a float.
*/ */
register struct type *tp = df->df_type; struct type *tp = df->df_type;
if (tp->tp_size != int_size && if (tp->tp_size != int_size &&
(tp->tp_fund == CHAR || tp->tp_fund == SHORT) (tp->tp_fund == CHAR || tp->tp_fund == SHORT)
@ -673,9 +677,7 @@ formal_cvt(hasproto,df)
#ifdef LINT #ifdef LINT
/*ARGSUSED*/ /*ARGSUSED*/
#endif /* LINT */ #endif /* LINT */
code_expr(expr, val, code, tlbl, flbl) void code_expr(struct expr *expr, int val, int code, label tlbl, label flbl)
struct expr *expr;
label tlbl, flbl;
{ {
/* code_expr() is the parser's interface to the expression code /* code_expr() is the parser's interface to the expression code
generator. If line number trace is wanted, it generates a generator. If line number trace is wanted, it generates a
@ -708,9 +710,9 @@ static struct stmt_block *stmt_stack; /* top of statement stack */
which are the only ones that are stacked, only the top of which are the only ones that are stacked, only the top of
the stack is interesting. the stack is interesting.
*/ */
code_break() void code_break()
{ {
register struct stmt_block *stmt_block = stmt_stack; struct stmt_block *stmt_block = stmt_stack;
#ifdef DBSYMTAB #ifdef DBSYMTAB
if (options['g']) db_line(dot.tk_file, dot.tk_line); if (options['g']) db_line(dot.tk_file, dot.tk_line);
@ -726,9 +728,9 @@ code_break()
it generates a branch instruction to the continue label of the it generates a branch instruction to the continue label of the
innermost statement in which continue has a meaning. innermost statement in which continue has a meaning.
*/ */
code_continue() void code_continue()
{ {
register struct stmt_block *stmt_block = stmt_stack; struct stmt_block *stmt_block = stmt_stack;
while (stmt_block) { while (stmt_block) {
if (stmt_block->st_continue) { if (stmt_block->st_continue) {
@ -743,10 +745,9 @@ code_continue()
error("continue not inside for, while or do"); error("continue not inside for, while or do");
} }
stack_stmt(break_label, cont_label) void stack_stmt(label break_label, label cont_label)
label break_label, cont_label;
{ {
register struct stmt_block *stmt_block = new_stmt_block(); struct stmt_block *stmt_block = new_stmt_block();
stmt_block->next = stmt_stack; stmt_block->next = stmt_stack;
stmt_block->st_break = break_label; stmt_block->st_break = break_label;
@ -754,7 +755,7 @@ stack_stmt(break_label, cont_label)
stmt_stack = stmt_block; stmt_stack = stmt_block;
} }
unstack_stmt() void unstack_stmt()
{ {
/* unstack_stmt() unstacks the data of a statement /* unstack_stmt() unstacks the data of a statement
which may contain break or continue which may contain break or continue
@ -766,8 +767,7 @@ unstack_stmt()
static label prc_name; static label prc_name;
prc_entry(name) static void prc_entry(char *name)
char *name;
{ {
if (options['p']) { if (options['p']) {
C_df_dlb(prc_name = data_label()); C_df_dlb(prc_name = data_label());
@ -778,7 +778,7 @@ prc_entry(name)
} }
} }
prc_exit() static void prc_exit()
{ {
if (options['p']) { if (options['p']) {
C_lae_dlb(prc_name, (arith) 0); C_lae_dlb(prc_name, (arith) 0);
@ -788,9 +788,7 @@ prc_exit()
} }
#ifdef DBSYMTAB #ifdef DBSYMTAB
db_line(file, line) void db_line(char *file, unsigned int line)
char *file;
unsigned int line;
{ {
static unsigned oldline; static unsigned oldline;
static char *oldfile; static char *oldfile;

View File

@ -0,0 +1,42 @@
/*
* 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

View File

@ -13,6 +13,7 @@
#include "type.h" #include "type.h"
#include "sizes.h" #include "sizes.h"
#include "Lpars.h" #include "Lpars.h"
#include "error.h"
#define T_SIGNED 1 #define T_SIGNED 1
#define T_UNSIGNED 2 #define T_UNSIGNED 2
@ -27,13 +28,12 @@
C?? C??
*/ */
static int convtype(); static int convtype(struct type *tp);
conversion(from_type, to_type) void conversion(struct type *from_type, struct type *to_type)
register struct type *from_type, *to_type;
{ {
register arith from_size = from_type->tp_size; arith from_size = from_type->tp_size;
register arith to_size = to_type->tp_size; arith to_size = to_type->tp_size;
int from_cnvtype = convtype(from_type); int from_cnvtype = convtype(from_type);
int to_cnvtype = convtype(to_type); int to_cnvtype = convtype(to_type);
@ -126,9 +126,7 @@ conversion(from_type, to_type)
/* convtype() returns in which category a given type falls: /* convtype() returns in which category a given type falls:
signed, unsigned or floating signed, unsigned or floating
*/ */
static int static int convtype(struct type *tp)
convtype(tp)
register struct type *tp;
{ {
switch (tp->tp_fund) { switch (tp->tp_fund) {
case CHAR: case CHAR:

View File

@ -0,0 +1,8 @@
#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

View File

@ -15,6 +15,9 @@
#include "sizes.h" #include "sizes.h"
#include "Lpars.h" #include "Lpars.h"
#include "assert.h" #include "assert.h"
#include "cstoper.h"
#include "error.h"
#include "expr_loc.h"
/* full_mask[1] == 0XFF, full_mask[2] == 0XFFFF, .. */ /* full_mask[1] == 0XFF, full_mask[2] == 0XFFFF, .. */
arith full_mask[MAXSIZE + 1]; arith full_mask[MAXSIZE + 1];
@ -24,15 +27,14 @@ arith max_unsigned; /* maximum unsigned on target machine */
#endif /* NOCROSS */ #endif /* NOCROSS */
extern int ResultKnown; extern int ResultKnown;
cstbin(expp, oper, expr) void cstbin(struct expr **expp, int oper, struct expr *expr)
register struct expr **expp, *expr;
{ {
/* The operation oper is performed on the constant /* The operation oper is performed on the constant
expressions *expp(ld) and expr(ct), and the result restored in expressions *expp(ld) and expr(ct), and the result restored in
*expp. *expp.
*/ */
register arith o1 = (*expp)->VL_VALUE; arith o1 = (*expp)->VL_VALUE;
register arith o2 = expr->VL_VALUE; arith o2 = expr->VL_VALUE;
int uns = (*expp)->ex_type->tp_unsigned; int uns = (*expp)->ex_type->tp_unsigned;
ASSERT(is_ld_cst(*expp) && is_cp_cst(expr)); ASSERT(is_ld_cst(*expp) && is_cp_cst(expr));
@ -205,13 +207,12 @@ cstbin(expp, oper, expr)
free_expression(expr); free_expression(expr);
} }
cut_size(expr) void cut_size(struct expr *expr)
register struct expr *expr;
{ {
/* The constant value of the expression expr is made to /* The constant value of the expression expr is made to
conform to the size of the type of the expression. conform to the size of the type of the expression.
*/ */
register arith o1 = expr->VL_VALUE; arith o1 = expr->VL_VALUE;
int uns = expr->ex_type->tp_unsigned; int uns = expr->ex_type->tp_unsigned;
int size = (int) expr->ex_type->tp_size; int size = (int) expr->ex_type->tp_size;
@ -241,10 +242,10 @@ cut_size(expr)
expr->VL_VALUE = o1; expr->VL_VALUE = o1;
} }
init_cst() void init_cst()
{ {
register int i = 0; int i = 0;
register arith bt = (arith)0; arith bt = (arith)0;
while (!(bt < 0)) { while (!(bt < 0)) {
bt = (bt << 8) + 0377, i++; bt = (bt << 8) + 0377, i++;

View File

@ -0,0 +1,8 @@
#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

View File

@ -0,0 +1,11 @@
/*
* 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 */

View File

@ -17,17 +17,27 @@
#include "label.h" #include "label.h"
#include "code.h" #include "code.h"
#include "idf.h" #include "idf.h"
#include "idf_loc.h"
#include "type.h" #include "type.h"
#include "type_loc.h"
#include "proto.h" #include "proto.h"
#include "proto_loc.h"
#include "struct.h" #include "struct.h"
#include "struct_loc.h"
#include "field.h" #include "field.h"
#include "decspecs.h" #include "decspecs.h"
#include "def.h" #include "def.h"
#include "declar.h" #include "declar.h"
#include "label.h" #include "label.h"
#include "expr.h" #include "expr.h"
#include "expr_loc.h"
#include "sizes.h" #include "sizes.h"
#include "level.h" #include "level.h"
#include "code_c.h"
#include "error.h"
#include "stab.h"
#include "declarator.h"
#ifdef LINT #ifdef LINT
#include "l_lint.h" #include "l_lint.h"
#endif /* LINT */ #endif /* LINT */
@ -712,7 +722,7 @@ parameter_declarator(register struct declarator *dc;)
primary_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)) && (AHEAD != IDENTIFIER))
/* empty */ /* empty */
| |

View File

@ -4,6 +4,8 @@
*/ */
/* $Id$ */ /* $Id$ */
/* DEFINITION OF DECLARATOR DESCRIPTORS */ /* 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 /* A 'declarator' consists of an idf and a linked list of
language-defined unary operations: *, [] and (), called language-defined unary operations: *, [] and (), called
@ -39,3 +41,5 @@ struct decl_unary {
extern struct type *declare_type(); extern struct type *declare_type();
extern struct declarator null_declarator; extern struct declarator null_declarator;
#endif /* LANG_CEM_CEMCOM_ANSI_DECLARE_STR */

View File

@ -20,14 +20,14 @@
#include "expr.h" #include "expr.h"
#include "sizes.h" #include "sizes.h"
#include "level.h" #include "level.h"
#include "error.h"
#include "idf_loc.h"
#include "proto_loc.h"
extern char options[]; extern char options[];
struct declarator null_declarator; struct declarator null_declarator;
struct type * struct type *declare_type(struct type *tp, struct declarator *dc)
declare_type(tp, dc)
struct type *tp;
struct declarator *dc;
{ {
/* Applies the decl_unary list starting at dc->dc_decl_unary /* Applies the decl_unary list starting at dc->dc_decl_unary
to the type tp and returns the result. to the type tp and returns the result.
@ -35,7 +35,7 @@ declare_type(tp, dc)
are purely prototypes. Simply add the type list to the are purely prototypes. Simply add the type list to the
function node. function node.
*/ */
register struct decl_unary *du = dc->dc_decl_unary; struct decl_unary *du = dc->dc_decl_unary;
while (du) { while (du) {
tp = construct_type(du->du_fund, tp, du->du_typequal, tp = construct_type(du->du_fund, tp, du->du_typequal,
@ -45,18 +45,13 @@ declare_type(tp, dc)
return tp; return tp;
} }
add_decl_unary(dc, fund, qual, count, fm, pl) void add_decl_unary(struct declarator *dc, int fund, int qual, arith count, struct formal *fm, struct proto *pl)
register struct declarator *dc;
int qual;
arith count;
struct formal *fm;
struct proto *pl;
{ {
/* A decl_unary describing a constructor with fundamental /* A decl_unary describing a constructor with fundamental
type fund and with size count is inserted in front of the type fund and with size count is inserted in front of the
declarator dc. declarator dc.
*/ */
register struct decl_unary *new = new_decl_unary(); struct decl_unary *new = new_decl_unary();
new->next = dc->dc_decl_unary; new->next = dc->dc_decl_unary;
new->du_fund = fund; new->du_fund = fund;
@ -77,13 +72,12 @@ add_decl_unary(dc, fund, qual, count, fm, pl)
dc->dc_decl_unary = new; dc->dc_decl_unary = new;
} }
remove_declarator(dc) void remove_declarator(struct declarator *dc)
struct declarator *dc;
{ {
/* The decl_unary list starting at dc->dc_decl_unary is /* The decl_unary list starting at dc->dc_decl_unary is
removed. removed.
*/ */
register struct decl_unary *du = dc->dc_decl_unary; struct decl_unary *du = dc->dc_decl_unary;
while (du) { while (du) {
struct decl_unary *old_du = du; struct decl_unary *old_du = du;
@ -93,15 +87,14 @@ remove_declarator(dc)
} }
} }
reject_params(dc) void reject_params(struct declarator *dc)
register struct declarator *dc;
{ {
/* The declarator is checked to have no parameters, if it /* The declarator is checked to have no parameters, if it
is an old-style function. If it is a new-style function, is an old-style function. If it is a new-style function,
the identifiers are removed. The function is not called in the identifiers are removed. The function is not called in
case of a function definition. case of a function definition.
*/ */
register struct decl_unary *du = dc->dc_decl_unary; struct decl_unary *du = dc->dc_decl_unary;
int err_given = 0; int err_given = 0;
if (dc->dc_formal) { if (dc->dc_formal) {
@ -122,8 +115,7 @@ reject_params(dc)
} }
} }
check_array_subscript(expr) void check_array_subscript(struct expr *expr)
register struct expr *expr;
{ {
arith size = expr->VL_VALUE; arith size = expr->VL_VALUE;

View File

@ -0,0 +1,16 @@
/*
* 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 */

View File

@ -12,21 +12,21 @@
#include "type.h" #include "type.h"
#include "level.h" #include "level.h"
#include "def.h" #include "def.h"
#include "error.h"
#include <symbol2str.h>
extern char options[]; extern char options[];
extern int level; extern int level;
extern char *symbol2str();
extern struct type *qualifier_type();
struct decspecs null_decspecs; struct decspecs null_decspecs;
do_decspecs(ds) void do_decspecs(struct decspecs *ds)
register struct decspecs *ds;
{ {
/* The provisional decspecs ds as obtained from the program /* The provisional decspecs ds as obtained from the program
is turned into a legal consistent decspecs. is turned into a legal consistent decspecs.
*/ */
register struct type *tp = ds->ds_type; struct type *tp = ds->ds_type;
ASSERT(level != L_FORMAL1); ASSERT(level != L_FORMAL1);
@ -67,7 +67,7 @@ do_decspecs(ds)
tp = int_type; tp = int_type;
} }
if (ds->ds_size) { if (ds->ds_size) {
register int ds_isshort = (ds->ds_size == SHORT); int ds_isshort = (ds->ds_size == SHORT);
if (ds->ds_typedef) goto SIZE_ERROR; /* yes */ if (ds->ds_typedef) goto SIZE_ERROR; /* yes */
if (tp == int_type) { if (tp == int_type) {
@ -82,7 +82,7 @@ do_decspecs(ds)
ds->ds_notypegiven = 0; ds->ds_notypegiven = 0;
} }
if (ds->ds_unsigned) { if (ds->ds_unsigned) {
register int ds_isunsigned = (ds->ds_unsigned == UNSIGNED); int ds_isunsigned = (ds->ds_unsigned == UNSIGNED);
if (ds->ds_typedef) goto SIGN_ERROR; /* yes */ if (ds->ds_typedef) goto SIGN_ERROR; /* yes */
/* /*
@ -113,13 +113,10 @@ do_decspecs(ds)
In case of a complex type the top of the type list will be In case of a complex type the top of the type list will be
replaced by a qualified version. replaced by a qualified version.
*/ */
struct type * struct type *qualifier_type(struct type *tp, int typequal)
qualifier_type(tp, typequal)
register struct type *tp;
int typequal;
{ {
register struct type *dtp = tp; struct type *dtp = tp;
register int fund = tp->tp_fund; int fund = tp->tp_fund;
while (dtp && dtp->tp_typequal != typequal) while (dtp && dtp->tp_typequal != typequal)
dtp = dtp->next; dtp = dtp->next;

View File

@ -1,3 +1,5 @@
#ifndef LANG_CEM_CEMCOM_ANSI_DECSPECS_H
#define LANG_CEM_CEMCOM_ANSI_DECSPECS_H
/* /*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright". * See the copyright notice in the ACK home directory, in the file "Copyright".
@ -17,5 +19,11 @@ struct decspecs {
int ds_typequal; /* type qualifiers - see type.str */ int ds_typequal; /* type qualifiers - see type.str */
}; };
extern struct type *qualifier_type();
extern struct decspecs null_decspecs; 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 */

View File

@ -4,6 +4,8 @@
*/ */
/* $Id$ */ /* $Id$ */
/* IDENTIFIER DEFINITION DESCRIPTOR */ /* IDENTIFIER DEFINITION DESCRIPTOR */
#ifndef LANG_CEM_CEMCOM_ANSI_DEF_STR
#define LANG_CEM_CEMCOM_ANSI_DEF_STR
#include "lint.h" #include "lint.h"
@ -38,3 +40,6 @@ struct def { /* for ordinary tags */
#define REG_BONUS 10 /* register candidate, declared as such */ #define REG_BONUS 10 /* register candidate, declared as such */
/* ALLOCDEF "def" 50 */ /* ALLOCDEF "def" 50 */
#endif /* LANG_CEM_CEMCOM_ANSI_DEF_STR */

View File

@ -5,7 +5,11 @@
/* $Id$ */ /* $Id$ */
/* PREPROCESSOR: CONTROLLINE INTERPRETER */ /* PREPROCESSOR: CONTROLLINE INTERPRETER */
#include <stdlib.h>
#include <string.h>
#include "debug.h" #include "debug.h"
#include "specials.h"
#include "arith.h" #include "arith.h"
#include "LLlex.h" #include "LLlex.h"
#include "Lpars.h" #include "Lpars.h"
@ -13,6 +17,13 @@
#include "input.h" #include "input.h"
#include "nopp.h" #include "nopp.h"
#include "lint.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 #ifndef NOPP
#include "ifdepth.h" #include "ifdepth.h"
@ -36,16 +47,15 @@ int IncludeLevel = 0;
extern char options[]; extern char options[];
extern char **inctable; /* list of include directories */ extern char **inctable; /* list of include directories */
extern char *getwdir();
char ifstack[IFDEPTH]; /* if-stack: the content of an entry is */ char ifstack[IFDEPTH]; /* if-stack: the content of an entry is */
/* 1 if a corresponding ELSE has been */ /* 1 if a corresponding ELSE has been */
/* encountered. */ /* encountered. */
int nestlevel = -1; int nestlevel = -1;
extern char *getwdir();
struct idf * /* skiponerr -> skip the rest of the line on error */
GetIdentifier(skiponerr) struct idf *GetIdentifier(int skiponerr)
int skiponerr; /* skip the rest of the line on error */
{ {
/* returns a pointer to the descriptor of the identifier that is /* returns a pointer to the descriptor of the identifier that is
read from the input stream. When the input doe not contain read from the input stream. When the input doe not contain
@ -76,7 +86,7 @@ GetIdentifier(skiponerr)
An error message is produced when the token is not recognized, An error message is produced when the token is not recognized,
i.e. it is not one of "define" .. "undef" , integer or newline. i.e. it is not one of "define" .. "undef" , integer or newline.
*/ */
domacro() void domacro()
{ {
struct token tk; /* the token itself */ struct token tk; /* the token itself */
int toknum; int toknum;
@ -126,6 +136,9 @@ domacro()
case K_ERROR: /* "error" */ case K_ERROR: /* "error" */
do_error(); do_error();
break; break;
case K_WARNING: /* "warning" */
do_warning();
break;
case K_PRAGMA: /* "pragma" */ case K_PRAGMA: /* "pragma" */
do_pragma(); do_pragma();
break; break;
@ -154,8 +167,7 @@ domacro()
int lint_skip_comment; int lint_skip_comment;
#endif #endif
skip_block(to_endif) void skip_block(int to_endif)
int to_endif;
{ {
/* skip_block() skips the input from /* skip_block() skips the input from
1) a false #if, #ifdef, #ifndef or #elif until the 1) a false #if, #ifdef, #ifndef or #elif until the
@ -165,8 +177,8 @@ int to_endif;
#ifndef or #elif until the corresponding #endif is #ifndef or #elif until the corresponding #endif is
seen. seen.
*/ */
register int ch; int ch;
register int skiplevel = nestlevel; /* current nesting level */ int skiplevel = nestlevel; /* current nesting level */
struct token tk; struct token tk;
int toknum; int toknum;
@ -289,7 +301,7 @@ int to_endif;
} }
ifexpr() int ifexpr()
{ {
/* ifexpr() returns whether the restricted constant /* ifexpr() returns whether the restricted constant
expression following #if or #elif evaluates to true. This expression following #if or #elif evaluates to true. This
@ -311,7 +323,7 @@ ifexpr()
return (errors == err_occurred) && (ifval != (arith)0); return (errors == err_occurred) && (ifval != (arith)0);
} }
do_include() void do_include()
{ {
/* do_include() performs the inclusion of a file. /* do_include() performs the inclusion of a file.
*/ */
@ -356,7 +368,7 @@ do_include()
} }
} }
do_define() void do_define()
{ {
/* do_define() interprets a #define control line. /* do_define() interprets a #define control line.
*/ */
@ -395,7 +407,7 @@ do_define()
LineNumber++; LineNumber++;
} }
push_if() void push_if()
{ {
if (nestlevel >= IFDEPTH) if (nestlevel >= IFDEPTH)
fatal("too many nested #if/#ifdef/#ifndef"); fatal("too many nested #if/#ifdef/#ifndef");
@ -403,7 +415,7 @@ push_if()
ifstack[++nestlevel] = 0; ifstack[++nestlevel] = 0;
} }
do_elif() void do_elif()
{ {
if (nestlevel <= nestlow) { if (nestlevel <= nestlow) {
lexerror("#elif without corresponding #if"); lexerror("#elif without corresponding #if");
@ -420,7 +432,7 @@ do_elif()
} }
} }
do_else() void do_else()
{ {
if (SkipToNewLine()) if (SkipToNewLine())
if (!options['o']) if (!options['o'])
@ -436,7 +448,7 @@ do_else()
} }
} }
do_endif() void do_endif()
{ {
if (SkipToNewLine()) { if (SkipToNewLine()) {
if (!options['o']) if (!options['o'])
@ -448,16 +460,16 @@ do_endif()
else nestlevel--; else nestlevel--;
} }
do_if() void do_if()
{ {
push_if(); push_if();
if (!ifexpr()) /* a false #if/#elif expression */ if (!ifexpr()) /* a false #if/#elif expression */
skip_block(0); skip_block(0);
} }
do_ifdef(how) void do_ifdef(how)
{ {
register struct idf *id; struct idf *id;
/* how == 1 : ifdef; how == 0 : ifndef /* how == 1 : ifdef; how == 0 : ifndef
*/ */
@ -477,10 +489,9 @@ do_ifdef(how)
} }
/* argidf != NULL when the undef came from a -U option */ /* argidf != NULL when the undef came from a -U option */
do_undef(argidf) void do_undef(struct idf *argidf)
struct idf *argidf;
{ {
register struct idf *id = argidf; struct idf *id = argidf;
/* Forget a macro definition. */ /* Forget a macro definition. */
if (id || (id = GetIdentifier(1))) { if (id || (id = GetIdentifier(1))) {
@ -503,7 +514,7 @@ do_undef(argidf)
lexerror("illegal #undef construction"); lexerror("illegal #undef construction");
} }
do_error() void do_error()
{ {
int len; int len;
char *get_text(); char *get_text();
@ -514,10 +525,18 @@ do_error()
LineNumber++; LineNumber++;
} }
int void do_warning()
getparams(buf, parbuf) {
char *buf[]; int len;
char parbuf[]; char *get_text();
char *bp = get_text((char **) 0, &len);
lexwarning("user warning: %s", bp);
free(bp);
LineNumber++;
}
int getparams(char *buf[], char parbuf[])
{ {
/* getparams() reads the formal parameter list of a macro /* getparams() reads the formal parameter list of a macro
definition. definition.
@ -529,10 +548,10 @@ getparams(buf, parbuf)
Note that the '(' has already been eaten. Note that the '(' has already been eaten.
The names of the formal parameters are stored into parbuf. The names of the formal parameters are stored into parbuf.
*/ */
register char **pbuf = &buf[0]; char **pbuf = &buf[0];
register int c; int c;
register char *ptr = &parbuf[0]; char *ptr = &parbuf[0];
register char **pbuf2; char **pbuf2;
c = GetChar(); c = GetChar();
c = skipspaces(c,0); c = skipspaces(c,0);
@ -583,11 +602,9 @@ getparams(buf, parbuf)
/*NOTREACHED*/ /*NOTREACHED*/
} }
macro_def(id, text, nformals, length, flags) void macro_def(struct idf *id, char *text, int nformals, int length, int flags)
register struct idf *id;
char *text;
{ {
register struct macro *newdef = id->id_macro; struct macro *newdef = id->id_macro;
/* macro_def() puts the contents and information of a macro /* macro_def() puts the contents and information of a macro
definition into a structure and stores it into the symbol definition into a structure and stores it into the symbol
@ -609,15 +626,13 @@ macro_def(id, text, nformals, length, flags)
newdef->mc_flag = flags; /* special flags */ newdef->mc_flag = flags; /* special flags */
} }
int int find_name(char *nm, char *index[])
find_name(nm, index)
char *nm, *index[];
{ {
/* find_name() returns the index of "nm" in the namelist /* find_name() returns the index of "nm" in the namelist
"index" if it can be found there. 0 is returned if it is "index" if it can be found there. 0 is returned if it is
not there. not there.
*/ */
register char **ip = &index[0]; char **ip = &index[0];
while (*ip) while (*ip)
if (strcmp(nm, *ip++) == 0) if (strcmp(nm, *ip++) == 0)
@ -628,10 +643,7 @@ find_name(nm, index)
#define BLANK(ch) ((ch == ' ') || (ch == '\t')) #define BLANK(ch) ((ch == ' ') || (ch == '\t'))
char * char *get_text(char *formals[], int *length)
get_text(formals, length)
char *formals[];
int *length;
{ {
/* get_text() copies the replacement text of a macro /* get_text() copies the replacement text of a macro
definition with zero, one or more parameters, thereby definition with zero, one or more parameters, thereby
@ -655,9 +667,9 @@ get_text(formals, length)
4- comment, same as for 1 4- comment, same as for 1
Other tokens will not be seen as such. Other tokens will not be seen as such.
*/ */
register int c; int c;
struct repl repls; struct repl repls;
register struct repl *repl = &repls; struct repl *repl = &repls;
int blank = 0; int blank = 0;
c = GetChar(); c = GetChar();
@ -672,7 +684,7 @@ get_text(formals, length)
} }
if (c == '\'' || c == '"') { if (c == '\'' || c == '"') {
register int delim = c; int delim = c;
if (blank) { if (blank) {
blank = 0; blank = 0;
@ -705,7 +717,7 @@ get_text(formals, length)
} else if (formals } else if (formals
&& (class(c) == STIDF || class(c) == STELL)) { && (class(c) == STIDF || class(c) == STELL)) {
char id_buf[IDFSIZE + 1]; char id_buf[IDFSIZE + 1];
register char *idp = id_buf; char *idp = id_buf;
int n; int n;
/* read identifier: it may be a formal parameter */ /* read identifier: it may be a formal parameter */
@ -722,7 +734,7 @@ get_text(formals, length)
add2repl(repl, ' '); add2repl(repl, ' ');
} }
/* construct the formal parameter mark or identifier */ /* construct the formal parameter mark or identifier */
if (n = find_name(id_buf, formals)) if ((n = find_name(id_buf, formals)))
add2repl(repl, FORMALP | (char) n); add2repl(repl, FORMALP | (char) n);
else { else {
idp = id_buf; idp = id_buf;
@ -771,8 +783,7 @@ get_text(formals, length)
as strings, without taking care of the leading and trailing as strings, without taking care of the leading and trailing
blanks (spaces and tabs). blanks (spaces and tabs).
*/ */
macroeq(s, t) int macroeq(char *s, char *t)
register char *s, *t;
{ {
/* skip leading spaces */ /* skip leading spaces */
@ -795,9 +806,8 @@ macroeq(s, t)
} }
#else /* NOPP */ #else /* NOPP */
struct idf * /* skiponerr -> skip the rest of the line on error */
GetIdentifier(skiponerr) struct idf *GetIdentifier(int skiponerr)
int skiponerr; /* skip the rest of the line on error */
{ {
/* returns a pointer to the descriptor of the identifier that is /* returns a pointer to the descriptor of the identifier that is
read from the input stream. When the input does not contain read from the input stream. When the input does not contain
@ -816,7 +826,7 @@ GetIdentifier(skiponerr)
return tk.tk_idf; return tk.tk_idf;
} }
domacro() void domacro()
{ {
int tok; int tok;
struct token tk; struct token tk;
@ -840,8 +850,7 @@ domacro()
#endif /* NOPP */ #endif /* NOPP */
do_line(l) void do_line(unsigned int l)
unsigned int l;
{ {
struct token tk; struct token tk;
int t = GetToken(&tk); int t = GetToken(&tk);

View File

@ -0,0 +1,31 @@
/*
* 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 */

View File

@ -7,6 +7,7 @@
#include "lint.h" #include "lint.h"
#if __STDC__ #if __STDC__
#include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#else #else
#include <varargs.h> #include <varargs.h>
@ -22,6 +23,7 @@
#include "lint.h" #include "lint.h"
#include "nopp.h" #include "nopp.h"
#include "errout.h" #include "errout.h"
#include "print.h"
#include "tokenname.h" #include "tokenname.h"
#include <flt_arith.h> #include <flt_arith.h>
@ -30,11 +32,13 @@
#include "expr.h" #include "expr.h"
#include "def.h" #include "def.h"
#include "LLlex.h" #include "LLlex.h"
#include "error.h"
/* This file contains the error-message and diagnostic /* This file contains the error-message and diagnostic
functions. Beware, they are called with a variable number of functions. Beware, they are called with a variable number of
arguments! arguments!
*/ */
static void _error(int class, char *fn, unsigned int ln, char *fmt, va_list ap);
/* error classes */ /* error classes */
#define STRICT 1 #define STRICT 1
@ -62,11 +66,9 @@ extern char loptions[];
expression, whereas other errors use the information in the token. expression, whereas other errors use the information in the token.
*/ */
static _error();
#if __STDC__ #if __STDC__
/*VARARGS*/ /*VARARGS*/
error(char *fmt, ...) void error(char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -78,7 +80,7 @@ error(char *fmt, ...)
} }
/*VARARGS*/ /*VARARGS*/
expr_error(struct expr *expr, char *fmt, ...) void expr_error(struct expr *expr, char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -94,7 +96,7 @@ expr_error(struct expr *expr, char *fmt, ...)
} }
/*VARARGS*/ /*VARARGS*/
lexstrict(char *fmt, ...) void lexstrict(char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -106,7 +108,7 @@ lexstrict(char *fmt, ...)
} }
/*VARARGS*/ /*VARARGS*/
strict(char *fmt, ...) void strict(char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -118,7 +120,7 @@ strict(char *fmt, ...)
} }
/*VARARGS*/ /*VARARGS*/
expr_strict(struct expr *expr, char *fmt, ...) void expr_strict(struct expr *expr, char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -134,7 +136,7 @@ expr_strict(struct expr *expr, char *fmt, ...)
#ifdef DEBUG #ifdef DEBUG
/*VARARGS*/ /*VARARGS*/
debug(char *fmt, ...) void debug(char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -147,7 +149,7 @@ debug(char *fmt, ...)
#endif /* DEBUG */ #endif /* DEBUG */
/*VARARGS*/ /*VARARGS*/
warning(char *fmt, ...) void warning(char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -159,7 +161,7 @@ warning(char *fmt, ...)
} }
/*VARARGS*/ /*VARARGS*/
expr_warning(struct expr *expr, char *fmt, ...) void expr_warning(struct expr *expr, char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -176,7 +178,7 @@ expr_warning(struct expr *expr, char *fmt, ...)
#ifdef LINT #ifdef LINT
/*VARARGS*/ /*VARARGS*/
def_warning(struct def *def, char *fmt, ...) void def_warning(struct def *def, char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -189,7 +191,7 @@ def_warning(struct def *def, char *fmt, ...)
/*VARARGS*/ /*VARARGS*/
hwarning(char *fmt, ...) void hwarning(char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -202,7 +204,7 @@ hwarning(char *fmt, ...)
} }
/*VARARGS*/ /*VARARGS*/
awarning(char *fmt, ...) void awarning(char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -217,7 +219,7 @@ awarning(char *fmt, ...)
#endif /* LINT */ #endif /* LINT */
/*VARARGS*/ /*VARARGS*/
lexerror(char *fmt, ...) void lexerror(char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -229,7 +231,7 @@ lexerror(char *fmt, ...)
} }
/*VARARGS*/ /*VARARGS*/
lexwarning(char *fmt, ...) void lexwarning(char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -241,7 +243,7 @@ lexwarning(char *fmt, ...)
} }
/*VARARGS*/ /*VARARGS*/
crash(char *fmt, ...) void crash(char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -261,7 +263,7 @@ crash(char *fmt, ...)
} }
/*VARARGS*/ /*VARARGS*/
fatal(char *fmt, ...) void fatal(char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -526,15 +528,9 @@ fatal(va_alist) /* fmt, args */
} }
#endif #endif
static static void _error(int class, char *fn, unsigned int ln, char *fmt, va_list ap)
_error(class, fn, ln, fmt, ap)
int class;
char *fn;
unsigned int ln;
char *fmt;
va_list ap;
{ {
char *remark; char *remark = NULL;
/* check visibility of message */ /* check visibility of message */
switch (class) { switch (class) {
@ -619,9 +615,9 @@ _error(class, fn, ln, fmt, ap)
#endif /* LINT */ #endif /* LINT */
if (fn) if (fn)
fprint(ERROUT, "\"%s\", line %u: ", fn, ln); fprintf(stderr, "\"%s\", line %u: ", fn, ln);
if (remark) if (remark)
fprint(ERROUT, "%s ", remark); fprintf(stderr, "%s ", remark);
doprnt(ERROUT, fmt, ap); /* contents of error */ doprnt(ERROUT, fmt, ap); /* contents of error */
fprint(ERROUT, "\n"); fprintf(stderr, "\n");
} }

View File

@ -0,0 +1,22 @@
/*
* 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 */

View File

@ -5,6 +5,10 @@
/* $Id$ */ /* $Id$ */
/* EXPRESSION STACK */ /* EXPRESSION STACK */
/* Used for global initializations */ /* Used for global initializations */
#ifndef LANG_CEM_CEMCOM_ANSI_ESTACK_STR
#define LANG_CEM_CEMCOM_ANSI_ESTACK_STR
struct e_stack { struct e_stack {
struct e_stack *next; struct e_stack *next;
arith s_cnt1, s_cnt2; arith s_cnt1, s_cnt2;
@ -19,3 +23,5 @@ struct e_stack {
#define last_offset s_cnt2 #define last_offset s_cnt2
#define elem_count s_cnt1 #define elem_count s_cnt1
#define nelem s_cnt2 #define nelem s_cnt2
#endif /* LANG_CEM_CEMCOM_ANSI_ESTACK_STR */

View File

@ -15,6 +15,8 @@
#include "nobitfield.h" #include "nobitfield.h"
#include "dataflow.h" #include "dataflow.h"
#include <flt_arith.h> #include <flt_arith.h>
#include <system.h>
#include "print.h"
#include "arith.h" #include "arith.h"
#include "type.h" #include "type.h"
#include "idf.h" #include "idf.h"
@ -30,13 +32,20 @@
#include "align.h" #include "align.h"
#include "mes.h" #include "mes.h"
#include "atw.h" #include "atw.h"
#include "blocks.h"
#include "conversion.h"
#include "specials.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__) #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) #define LocalPtrVar() NewLocal(pointer_size, pointer_align, reg_pointer, REGISTER)
extern int err_occurred; /* error.c */ extern int err_occurred; /* error.c */
@ -66,13 +75,10 @@ extern int err_occurred; /* error.c */
labels, in case they are specified (i.e. are non-zero) labels, in case they are specified (i.e. are non-zero)
*/ */
EVAL(expr, val, code, true_label, false_label) void EVAL(struct expr *expr, int val, int code, label true_label, 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 vol = (code != TRUE && recurqual(expr->ex_type, TQ_VOLATILE));
register int gencode = code == TRUE; int gencode = code == TRUE;
if (err_occurred) return; if (err_occurred) return;
switch (expr->ex_class) { switch (expr->ex_class) {
@ -114,9 +120,9 @@ EVAL(expr, val, code, true_label, false_label)
case Oper: /* compound expression */ case Oper: /* compound expression */
{ {
int oper = expr->OP_OPER; int oper = expr->OP_OPER;
register struct expr *left = expr->OP_LEFT; struct expr *left = expr->OP_LEFT;
register struct expr *right = expr->OP_RIGHT; struct expr *right = expr->OP_RIGHT;
register struct type *tp = expr->OP_TYPE; struct type *tp = expr->OP_TYPE;
switch (oper) { switch (oper) {
case '+': case '+':
@ -255,26 +261,44 @@ EVAL(expr, val, code, true_label, false_label)
operands(expr, gencode); operands(expr, gencode);
ASSERT(tp->tp_fund==INT || tp->tp_fund==LONG); ASSERT(tp->tp_fund==INT || tp->tp_fund==LONG);
if (gencode) if (gencode)
{
if (tp->tp_unsigned) if (tp->tp_unsigned)
{
C_rmu(tp->tp_size); C_rmu(tp->tp_size);
}
else else
{
C_rmi(tp->tp_size); C_rmi(tp->tp_size);
}
}
break; break;
case LEFT: case LEFT:
operands(expr, gencode); operands(expr, gencode);
if (gencode) if (gencode)
{
if (tp->tp_unsigned) if (tp->tp_unsigned)
{
C_slu(tp->tp_size); C_slu(tp->tp_size);
}
else else
{
C_sli(tp->tp_size); C_sli(tp->tp_size);
}
}
break; break;
case RIGHT: case RIGHT:
operands(expr, gencode); operands(expr, gencode);
if (gencode) if (gencode)
{
if (tp->tp_unsigned) if (tp->tp_unsigned)
{
C_sru(tp->tp_size); C_sru(tp->tp_size);
}
else else
{
C_sri(tp->tp_size); C_sri(tp->tp_size);
}
}
break; break;
case '<': case '<':
case LESSEQ: case LESSEQ:
@ -472,7 +496,7 @@ EVAL(expr, val, code, true_label, false_label)
} }
case '(': case '(':
{ {
register struct expr *ex; struct expr *ex;
arith ParSize = (arith)0; arith ParSize = (arith)0;
label setjmp_label = 0; label setjmp_label = 0;
arith retspace = 0; arith retspace = 0;
@ -658,9 +682,7 @@ EVAL(expr, val, code, true_label, false_label)
} }
/* compare() serves as an auxiliary function of EVAL */ /* compare() serves as an auxiliary function of EVAL */
compare(relop, lbl) void compare(int relop, label lbl)
int relop;
label lbl;
{ {
switch (relop) { switch (relop) {
case '<': case '<':
@ -687,8 +709,7 @@ compare(relop, lbl)
} }
/* truthvalue() serves as an auxiliary function of EVAL */ /* truthvalue() serves as an auxiliary function of EVAL */
truthvalue(relop) void truthvalue(int relop)
int relop;
{ {
switch (relop) { switch (relop) {
case '<': case '<':
@ -716,12 +737,10 @@ truthvalue(relop)
/* assop() generates the opcode of an assignment operators op= */ /* assop() generates the opcode of an assignment operators op= */
assop(type, oper) void assop(struct type *type, int oper)
register struct type *type;
int oper;
{ {
register arith size; arith size;
register uns = type->tp_unsigned; int uns = type->tp_unsigned;
if ((int)(size = type->tp_size) < (int)word_size) if ((int)(size = type->tp_size) < (int)word_size)
size = word_size; size = word_size;
@ -821,8 +840,7 @@ assop(type, oper)
} }
} }
ptr_add(size) void ptr_add(arith size)
arith size;
{ {
if (size != pointer_size) { if (size != pointer_size) {
C_loc(size); C_loc(size);
@ -839,12 +857,10 @@ ptr_add(size)
- into a local static variable - into a local static variable
- absolute addressing - absolute addressing
*/ */
store_val(vl, tp) void store_val(struct value *vl, struct type *tp)
register struct value *vl;
register struct type *tp;
{ {
register int inword = 0; int inword = 0;
register int indword = 0; int indword = 0;
arith val = vl->vl_value; arith val = vl->vl_value;
if (vl->vl_class == Const) { /* absolute addressing */ if (vl->vl_class == Const) { /* absolute addressing */
@ -857,8 +873,8 @@ store_val(vl, tp)
else if (tp->tp_size == dword_size) indword = 1; else if (tp->tp_size == dword_size) indword = 1;
} }
if (vl->vl_class == Name) { if (vl->vl_class == Name) {
register struct idf *id = vl->vl_data.vl_idf; struct idf *id = vl->vl_data.vl_idf;
register struct def *df = id->id_def; struct def *df = id->id_def;
/* if (df->df_level == L_GLOBAL) { // } ??? re-examine */ /* if (df->df_level == L_GLOBAL) { // } ??? re-examine */
if (df->df_sc == GLOBAL if (df->df_sc == GLOBAL
@ -910,14 +926,15 @@ store_val(vl, tp)
- static variable - static variable
- local variable - local variable
*/ */
load_val(expr, rlval) /* expr -> expression containing the value
register struct expr *expr; /* expression containing the value */ rlval -> generate either LVAL or RVAL
int rlval; /* generate either LVAL or RVAL */ */
void load_val(struct expr *expr, int rlval)
{ {
register struct type *tp = expr->ex_type; struct type *tp = expr->ex_type;
int rvalue = (rlval == RVAL && expr->ex_lvalue != 0); int rvalue = (rlval == RVAL && expr->ex_lvalue != 0);
register int inword = 0, indword = 0; int inword = 0, indword = 0;
register arith val = expr->VL_VALUE; arith val = expr->VL_VALUE;
if (expr->ex_type->tp_fund == FLOAT if (expr->ex_type->tp_fund == FLOAT
|| expr->ex_type->tp_fund == DOUBLE || expr->ex_type->tp_fund == DOUBLE
@ -957,8 +974,8 @@ load_val(expr, rlval)
} }
} }
else { else {
register struct idf *id = expr->VL_IDF; struct idf *id = expr->VL_IDF;
register struct def *df = id->id_def; struct def *df = id->id_def;
int fund = df->df_type->tp_fund; int fund = df->df_type->tp_fund;
ASSERT(ISNAME(expr)); ASSERT(ISNAME(expr));
@ -1009,8 +1026,7 @@ load_val(expr, rlval)
} }
} }
load_cst(val, siz) void load_cst(arith val, arith siz)
arith val, siz;
{ {
if ((int)siz <= (int)word_size) if ((int)siz <= (int)word_size)
C_loc(val); C_loc(val);
@ -1027,8 +1043,7 @@ load_cst(val, siz)
} }
} }
operands(expr, gencode) void operands(struct expr *expr, int gencode)
register struct expr *expr;
{ {
EVAL(expr->OP_LEFT, RVAL, gencode, NO_LABEL, NO_LABEL); EVAL(expr->OP_LEFT, RVAL, gencode, NO_LABEL, NO_LABEL);
EVAL(expr->OP_RIGHT, RVAL, gencode, NO_LABEL, NO_LABEL); EVAL(expr->OP_RIGHT, RVAL, gencode, NO_LABEL, NO_LABEL);

View File

@ -0,0 +1,20 @@
/*
* 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 */

View File

@ -5,6 +5,8 @@
/* $Id$ */ /* $Id$ */
/* EXPRESSION TREE HANDLING */ /* EXPRESSION TREE HANDLING */
#include <stdlib.h>
#include "lint.h" #include "lint.h"
#include "debug.h" #include "debug.h"
#include "assert.h" #include "assert.h"
@ -24,14 +26,16 @@
#include "sizes.h" #include "sizes.h"
#include "level.h" #include "level.h"
#include "use_tmp.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 char options[];
extern int InSizeof; extern int InSizeof;
int int rank_of(int oper)
rank_of(oper)
int oper;
{ {
/* The rank of the operator oper is returned. /* The rank of the operator oper is returned.
*/ */
@ -100,13 +104,12 @@ rank_of(oper)
/*NOTREACHED*/ /*NOTREACHED*/
} }
dot2expr(expp) void dot2expr(struct expr **expp)
struct expr **expp;
{ {
/* The token in dot is converted into an expression, a /* The token in dot is converted into an expression, a
pointer to which is stored in *expp. pointer to which is stored in *expp.
*/ */
register struct expr *ex = new_expr(); struct expr *ex = new_expr();
*expp = ex; *expp = ex;
ex->ex_file = dot.tk_file; ex->ex_file = dot.tk_file;
@ -127,16 +130,15 @@ dot2expr(expp)
} }
} }
idf2expr(expr) void idf2expr(struct expr *expr)
register struct expr *expr;
{ {
/* Dot contains an identifier which is turned into an /* Dot contains an identifier which is turned into an
expression. expression.
Note that this constitutes an applied occurrence of Note that this constitutes an applied occurrence of
the identifier. the identifier.
*/ */
register struct idf *idf = dot.tk_idf; /* != 0*/ struct idf *idf = dot.tk_idf; /* != 0*/
register struct def *def = idf->id_def; struct def *def = idf->id_def;
if (def == 0) { if (def == 0) {
if (AHEAD == '(') { if (AHEAD == '(') {
@ -197,15 +199,12 @@ idf2expr(expr)
} }
} }
string2expr(expp, str, len) void string2expr(struct expr **expp, char *str, int len)
register struct expr **expp;
int len;
char *str;
{ {
/* The string in the argument is converted into an expression, /* The string in the argument is converted into an expression,
a pointer to which is stored in *expp. a pointer to which is stored in *expp.
*/ */
register struct expr *ex = new_expr(); struct expr *ex = new_expr();
*expp = ex; *expp = ex;
ex->ex_file = dot.tk_file; ex->ex_file = dot.tk_file;
@ -219,8 +218,7 @@ string2expr(expp, str, len)
ex->SG_LEN = len; ex->SG_LEN = len;
} }
int2expr(expr) void int2expr(struct expr *expr)
struct expr *expr;
{ {
/* Dot contains an integer constant which is turned /* Dot contains an integer constant which is turned
into an expression. into an expression.
@ -228,13 +226,12 @@ int2expr(expr)
fill_int_expr(expr, dot.tk_ival, dot.tk_fund); fill_int_expr(expr, dot.tk_ival, dot.tk_fund);
} }
float2expr(expr) void float2expr(struct expr *expr)
register struct expr *expr;
{ {
/* Dot contains a floating point constant which is turned /* Dot contains a floating point constant which is turned
into an expression. into an expression.
*/ */
register int fund; int fund;
fund = dot.tk_fund; fund = dot.tk_fund;
switch (fund) { switch (fund) {
@ -258,15 +255,12 @@ float2expr(expr)
expr_warning(expr,"internal floating point overflow"); expr_warning(expr,"internal floating point overflow");
} }
struct expr* struct expr *intexpr(arith ivalue, int fund)
intexpr(ivalue, fund)
arith ivalue;
int fund;
{ {
/* The value ivalue is turned into an integer expression of /* The value ivalue is turned into an integer expression of
the size indicated by fund. the size indicated by fund.
*/ */
register struct expr *expr = new_expr(); struct expr *expr = new_expr();
expr->ex_file = dot.tk_file; expr->ex_file = dot.tk_file;
expr->ex_line = dot.tk_line; expr->ex_line = dot.tk_line;
@ -274,10 +268,7 @@ intexpr(ivalue, fund)
return expr; return expr;
} }
fill_int_expr(ex, ivalue, fund) void fill_int_expr(struct expr *ex, arith ivalue, int fund)
register struct expr *ex;
arith ivalue;
int fund;
{ {
/* Details derived from ivalue and fund are put into the /* Details derived from ivalue and fund are put into the
constant integer expression ex. constant integer expression ex.
@ -305,10 +296,7 @@ fill_int_expr(ex, ivalue, fund)
cut_size(ex); cut_size(ex);
} }
struct expr * struct expr *new_oper(struct type *tp, struct expr *e1, int oper, struct expr *e2)
new_oper(tp, e1, oper, e2)
struct type *tp;
register struct expr *e1, *e2;
{ {
/* A new expression is constructed which consists of the /* A new expression is constructed which consists of the
operator oper which has e1 and e2 as operands; for a operator oper which has e1 and e2 as operands; for a
@ -316,11 +304,11 @@ new_oper(tp, e1, oper, e2)
During the construction of the right recursive initialisation During the construction of the right recursive initialisation
tree it is possible for e2 to be NILEXPR. tree it is possible for e2 to be NILEXPR.
*/ */
register struct expr *expr = new_expr(); struct expr *expr = new_expr();
register struct oper *op; struct oper *op;
if (e2) { if (e2) {
register struct expr *e = e2; struct expr *e = e2;
while (e->ex_class == Oper && e->OP_LEFT) while (e->ex_class == Oper && e->OP_LEFT)
e = e->OP_LEFT; e = e->OP_LEFT;
@ -329,7 +317,7 @@ new_oper(tp, e1, oper, e2)
} }
else else
if (e1) { if (e1) {
register struct expr *e = e1; struct expr *e = e1;
while (e->ex_class == Oper && e->OP_RIGHT) while (e->ex_class == Oper && e->OP_RIGHT)
e = e->OP_RIGHT; e = e->OP_RIGHT;
@ -371,8 +359,7 @@ new_oper(tp, e1, oper, e2)
return expr; return expr;
} }
chk_cst_expr(expp) void chk_cst_expr(struct expr **expp)
struct expr **expp;
{ {
/* The expression expr is checked for constancy. /* The expression expr is checked for constancy.
@ -394,7 +381,7 @@ chk_cst_expr(expp)
Special problems (of which there is only one, sizeof in Special problems (of which there is only one, sizeof in
Preprocessor #if) have to be dealt with locally Preprocessor #if) have to be dealt with locally
*/ */
register struct expr *expr = *expp; struct expr *expr = *expp;
#ifdef DEBUG #ifdef DEBUG
print_expr("constant_expression", expr); print_expr("constant_expression", expr);
@ -417,9 +404,7 @@ chk_cst_expr(expp)
erroneous2int(expp); erroneous2int(expp);
} }
init_expression(eppp, expr) void init_expression(struct expr ***eppp, struct expr *expr)
register struct expr ***eppp;
struct expr *expr;
{ {
/* The expression expr is added to the tree designated /* The expression expr is added to the tree designated
indirectly by **eppp. indirectly by **eppp.
@ -437,9 +422,7 @@ init_expression(eppp, expr)
*eppp = &(**eppp)->OP_RIGHT; *eppp = &(**eppp)->OP_RIGHT;
} }
int int is_ld_cst(struct expr *expr)
is_ld_cst(expr)
register struct expr *expr;
{ {
/* An expression is a `load-time constant' if it is of the form /* An expression is a `load-time constant' if it is of the form
<idf> +/- <integral> or <integral>. <idf> +/- <integral> or <integral>.
@ -451,9 +434,7 @@ is_ld_cst(expr)
return expr->ex_lvalue == 0 && expr->ex_class == Value; return expr->ex_lvalue == 0 && expr->ex_class == Value;
} }
int int is_cp_cst(struct expr *expr)
is_cp_cst(expr)
struct expr *expr;
{ {
/* An expression is a `compile-time constant' if it is a /* An expression is a `compile-time constant' if it is a
load-time constant, and the idf is not there. load-time constant, and the idf is not there.
@ -461,9 +442,7 @@ is_cp_cst(expr)
return is_ld_cst(expr) && expr->VL_CLASS == Const; return is_ld_cst(expr) && expr->VL_CLASS == Const;
} }
int int is_fp_cst(struct expr *expr)
is_fp_cst(expr)
struct expr *expr;
{ {
/* An expression is a `floating-point constant' if it consists /* An expression is a `floating-point constant' if it consists
of the float only. of the float only.
@ -471,9 +450,7 @@ is_fp_cst(expr)
return expr->ex_class == Float; return expr->ex_class == Float;
} }
int int is_zero_cst(struct expr *expr)
is_zero_cst(expr)
register struct expr *expr;
{ {
flt_arith var; flt_arith var;
@ -485,10 +462,10 @@ is_zero_cst(expr)
return flt_cmp(&var, &(expr->FL_ARITH)) == 0; return flt_cmp(&var, &(expr->FL_ARITH)) == 0;
} }
/*NOTREACHED*/ /*NOTREACHED*/
return 0;
} }
free_expression(expr) void free_expression(struct expr *expr)
register struct expr *expr;
{ {
/* The expression expr is freed recursively. /* The expression expr is freed recursively.
*/ */

View File

@ -9,6 +9,14 @@
a union of various goodies, we define them first; so be patient. 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 */ /* classes of value */
#define Const 1 #define Const 1
#define Name 2 #define Name 2
@ -97,3 +105,4 @@ extern struct expr *intexpr(), *new_oper();
/* ALLOCDEF "expr" 20 */ /* ALLOCDEF "expr" 20 */
#endif /* LANG_CEM_CEMCOM_ANSI_EXPR_STR */

View File

@ -0,0 +1,27 @@
/*
* 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 */

View File

@ -14,12 +14,20 @@
#include "LLlex.h" #include "LLlex.h"
#include "type.h" #include "type.h"
#include "idf.h" #include "idf.h"
#include "decspecs.h"
#include "declar.h"
#include "declarator.h"
#include "label.h" #include "label.h"
#include "expr.h" #include "expr.h"
#include "expr_loc.h"
#include "proto_loc.h"
#include "code.h" #include "code.h"
#include "sizes.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 InSizeof = 0; /* inside a sizeof- expression */
int ResultKnown = 0; /* result of the expression is already known */ int ResultKnown = 0; /* result of the expression is already known */
@ -31,7 +39,7 @@ int ResultKnown = 0; /* result of the expression is already known */
} }
/* 3.3.1 */ /* 3.3.1 */
primary(register struct expr **expp;) : primary(struct expr **expp;) :
IDENTIFIER IDENTIFIER
{dot2expr(expp);} {dot2expr(expp);}
| |
@ -48,10 +56,10 @@ primary(register struct expr **expp;) :
* are concatenated into a single character string * are concatenated into a single character string
* literal. * literal.
*/ */
string(register struct expr **expp;) string(struct expr **expp;)
{ register int i, len; { int i, len;
register char *str; char *str;
register int fund; int fund;
} }
: :
STRING STRING
@ -78,7 +86,7 @@ string(register struct expr **expp;)
; ;
/* 3.3.2 */ /* 3.3.2 */
postfix_expression(register struct expr **expp;) postfix_expression(struct expr **expp;)
{ int oper; { int oper;
struct expr *e1 = 0; struct expr *e1 = 0;
struct idf *idf; struct idf *idf;
@ -120,7 +128,7 @@ parameter_list(struct expr **expp;)
%first first_of_type_specifier, type_specifier; %first first_of_type_specifier, type_specifier;
/* 3.3.3 & 3.3.4 */ /* 3.3.3 & 3.3.4 */
unary(register struct expr **expp;) unary(struct expr **expp;)
{struct type *tp; int oper;} {struct type *tp; int oper;}
: :
%if (first_of_type_specifier(AHEAD) && AHEAD != IDENTIFIER) %if (first_of_type_specifier(AHEAD) && AHEAD != IDENTIFIER)
@ -143,7 +151,7 @@ unary(register struct expr **expp;)
* mark it as used. * mark it as used.
* extern int i; .... sizeof(i) .... need not have a definition for i * extern int i; .... sizeof(i) .... need not have a definition for i
*/ */
size_of(register struct expr **expp;) size_of(struct expr **expp;)
{struct type *tp;} {struct type *tp;}
: :
SIZEOF { InSizeof++; } /* handle (sizeof(sizeof(int))) too */ SIZEOF { InSizeof++; } /* handle (sizeof(sizeof(int))) too */
@ -322,7 +330,7 @@ binop(int *oper;) :
{*oper = DOT;} {*oper = DOT;}
; ;
asgnop(register int *oper;): asgnop(int *oper;):
[ '=' | PLUSAB | MINAB | TIMESAB | DIVAB | MODAB [ '=' | PLUSAB | MINAB | TIMESAB | DIVAB | MODAB
| LEFTAB | RIGHTAB | ANDAB | XORAB | ORAB ] | LEFTAB | RIGHTAB | ANDAB | XORAB | ORAB ]
{ *oper = DOT; } { *oper = DOT; }

View File

@ -26,8 +26,11 @@
#include "align.h" #include "align.h"
#include "Lpars.h" #include "Lpars.h"
#include "field.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 */ extern arith full_mask[]; /* cstoper.c */
/* Eval_field() evaluates expressions involving bit fields. /* Eval_field() evaluates expressions involving bit fields.
@ -42,14 +45,12 @@ extern arith full_mask[]; /* cstoper.c */
[3] atype: the type in which the bitfield arithmetic is done; [3] atype: the type in which the bitfield arithmetic is done;
and in which bitfields are stored! and in which bitfields are stored!
*/ */
eval_field(expr, code) void eval_field(struct expr *expr, int code)
struct expr *expr;
int code;
{ {
int op = expr->OP_OPER; int op = expr->OP_OPER;
register struct expr *leftop = expr->OP_LEFT; struct expr *leftop = expr->OP_LEFT;
register struct expr *rightop = expr->OP_RIGHT; struct expr *rightop = expr->OP_RIGHT;
register struct field *fd = leftop->ex_type->tp_field; struct field *fd = leftop->ex_type->tp_field;
struct type *tp = leftop->ex_type->tp_up; struct type *tp = leftop->ex_type->tp_up;
arith tmpvar = 0; arith tmpvar = 0;
struct type *atype = ( tp->tp_unsigned struct type *atype = ( tp->tp_unsigned
@ -118,7 +119,7 @@ eval_field(expr, code)
retrieval) is on top of stack. retrieval) is on top of stack.
*/ */
if (tp->tp_unsigned == 0) { /* sign extension */ if (tp->tp_unsigned == 0) { /* sign extension */
register arith shift = (int)word_size * 8 - fd->fd_width; arith shift = (int)word_size * 8 - fd->fd_width;
C_loc(shift); C_loc(shift);
C_sli(word_size); C_sli(word_size);
@ -129,12 +130,7 @@ eval_field(expr, code)
} }
} }
store_field(fd, uns, code, leftop, tmpvar) void store_field(struct field *fd, int uns, int code, struct expr *leftop, arith tmpvar)
register struct field *fd;
int uns;
int code;
register struct expr *leftop;
arith tmpvar;
{ {
C_loc(fd->fd_mask); C_loc(fd->fd_mask);
C_and(word_size); C_and(word_size);

View File

@ -0,0 +1,13 @@
/*
* 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 */

View File

@ -18,12 +18,16 @@
#include "expr.h" #include "expr.h"
#include "sizes.h" #include "sizes.h"
#include "Lpars.h" #include "Lpars.h"
#include "cstoper.h"
#include "fltcstoper.h"
#include "error.h"
#include "expr_loc.h"
#include <symbol2str.h>
extern int ResultKnown; extern int ResultKnown;
extern char *symbol2str();
fltcstbin(expp, oper, expr) void fltcstbin(struct expr **expp, int oper, struct expr *expr)
register struct expr **expp, *expr;
{ {
/* The operation oper is performed on the constant /* The operation oper is performed on the constant
expressions *expp(ld) and expr(ct), and the result restored in expressions *expp(ld) and expr(ct), and the result restored in

View File

@ -0,0 +1,12 @@
/*
* 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 */

View File

@ -7,6 +7,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "system.h"
#include "lint.h" #include "lint.h"
#include <em_reg.h> #include <em_reg.h>
#include "debug.h" #include "debug.h"
@ -31,10 +32,21 @@
#include "sizes.h" #include "sizes.h"
#include "Lpars.h" #include "Lpars.h"
#include "assert.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 char options[];
extern arith NewLocal();
extern char *symbol2str();
#ifdef DEBUG #ifdef DEBUG
#define IDF_DEBUG #define IDF_DEBUG
@ -42,8 +54,7 @@ extern char *symbol2str();
#include <idf_pkg.body> #include <idf_pkg.body>
struct idf * struct idf *gen_idf()
gen_idf()
{ {
/* A new idf is created out of nowhere, to serve as an /* A new idf is created out of nowhere, to serve as an
anonymous name. anonymous name.
@ -57,16 +68,12 @@ gen_idf()
return str2idf(s, 0); return str2idf(s, 0);
} }
int int is_anon_idf(struct idf *idf)
is_anon_idf(idf)
struct idf *idf;
{ {
return idf->id_text[0] == '#'; return idf->id_text[0] == '#';
} }
declare_idf(ds, dc, lvl) void declare_idf(struct decspecs *ds, struct declarator *dc, int lvl)
struct decspecs *ds;
struct declarator *dc;
{ {
/* The identifier inside dc is declared on the level lvl, with /* The identifier inside dc is declared on the level lvl, with
properties deduced from the decspecs ds and the declarator properties deduced from the decspecs ds and the declarator
@ -76,14 +83,14 @@ declare_idf(ds, dc, lvl)
This routine implements the rich semantics of C This routine implements the rich semantics of C
declarations. declarations.
*/ */
register struct idf *idf = dc->dc_idf; struct idf *idf = dc->dc_idf;
register int sc = ds->ds_sc; int sc = ds->ds_sc;
/* This local copy is essential: /* This local copy is essential:
char b(), c; char b(), c;
makes b GLOBAL and c AUTO. makes b GLOBAL and c AUTO.
*/ */
register struct def *def = idf->id_def; /* may be NULL */ struct def *def = idf->id_def; /* may be NULL */
register struct type *type; struct type *type;
struct stack_level *stl = stack_level_of(lvl); struct stack_level *stl = stack_level_of(lvl);
char formal_array = 0; char formal_array = 0;
@ -97,7 +104,7 @@ declare_idf(ds, dc, lvl)
else { else {
/* combine the decspecs and the declarator into one type */ /* combine the decspecs and the declarator into one type */
type = declare_type(ds->ds_type, dc); type = declare_type(ds->ds_type, dc);
if (type->tp_size <= (arith)0 && if ( (type->tp_size <= (arith)0) &&
actual_declaration(sc, type)) { actual_declaration(sc, type)) {
if (type->tp_size == (arith) -1) { if (type->tp_size == (arith) -1) {
/* the type is not yet known, /* the type is not yet known,
@ -204,7 +211,7 @@ declare_idf(ds, dc, lvl)
def->df_line = idf->id_line; def->df_line = idf->id_line;
} }
else { /* fill in the def block */ else { /* fill in the def block */
register struct def *newdef = new_def(); struct def *newdef = new_def();
newdef->next = def; newdef->next = def;
newdef->df_level = lvl; newdef->df_level = lvl;
@ -253,13 +260,11 @@ declare_idf(ds, dc, lvl)
} }
} }
actual_declaration(sc, tp) int actual_declaration(int sc, struct type *tp)
int sc;
struct type *tp;
{ {
/* An actual_declaration needs space, right here and now. /* An actual_declaration needs space, right here and now.
*/ */
register int fund = tp->tp_fund; int fund = tp->tp_fund;
if (sc == ENUM || sc == TYPEDEF) /* virtual declarations */ if (sc == ENUM || sc == TYPEDEF) /* virtual declarations */
return 0; return 0;
@ -274,9 +279,7 @@ actual_declaration(sc, tp)
return 1; return 1;
} }
global_redecl(idf, new_sc, tp) void global_redecl(struct idf *idf, int new_sc, struct type *tp)
register struct idf *idf;
struct type *tp;
{ {
/* A global identifier may be declared several times, /* A global identifier may be declared several times,
provided the declarations do not conflict; they might provided the declarations do not conflict; they might
@ -284,7 +287,7 @@ global_redecl(idf, new_sc, tp)
an array) or they might conflict or supplement each other an array) or they might conflict or supplement each other
in storage class. in storage class.
*/ */
register struct def *def = idf->id_def; struct def *def = idf->id_def;
while (def->df_level != L_GLOBAL) def = def->next; while (def->df_level != L_GLOBAL) def = def->next;
if (!equal_type(tp, def->df_type, 0, 1)) { if (!equal_type(tp, def->df_type, 0, 1)) {
@ -368,10 +371,7 @@ global_redecl(idf, new_sc, tp)
} }
} }
int int good_formal(struct def *def, struct idf *idf)
good_formal(def, idf)
register struct def *def;
register struct idf *idf;
{ {
/* Succeeds if def is a proper L_FORMAL1 definition and /* Succeeds if def is a proper L_FORMAL1 definition and
gives an error message otherwise. gives an error message otherwise.
@ -385,12 +385,11 @@ good_formal(def, idf)
return 1; return 1;
} }
declare_params(dc) void declare_params(struct declarator *dc)
struct declarator *dc;
{ {
/* Declares the formal parameters if they exist. /* Declares the formal parameters if they exist.
*/ */
register struct formal *fm = dc->dc_formal; struct formal *fm = dc->dc_formal;
while (fm) { while (fm) {
declare_parameter(fm->fm_idf); declare_parameter(fm->fm_idf);
@ -398,12 +397,11 @@ declare_params(dc)
} }
} }
idf_initialized(idf) void idf_initialized(struct idf *idf)
register struct idf *idf;
{ {
/* The topmost definition of idf is set to initialized. /* The topmost definition of idf is set to initialized.
*/ */
register struct def *def = idf->id_def; /* the topmost */ struct def *def = idf->id_def; /* the topmost */
while (def->df_level <= L_PROTO) def = def->next; while (def->df_level <= L_PROTO) def = def->next;
if (def->df_initialized) if (def->df_initialized)
@ -415,18 +413,14 @@ idf_initialized(idf)
def->df_initialized = 1; def->df_initialized = 1;
} }
declare_parameter(idf) void declare_parameter(struct idf *idf)
struct idf *idf;
{ {
/* idf is declared as a formal. /* idf is declared as a formal.
*/ */
add_def(idf, FORMAL, int_type, level); add_def(idf, FORMAL, int_type, level);
} }
declare_enum(tp, idf, l) void declare_enum(struct type *tp, struct idf *idf, arith l)
struct type *tp;
struct idf *idf;
arith l;
{ {
/* idf is declared as an enum constant with value l. /* idf is declared as an enum constant with value l.
*/ */
@ -434,13 +428,11 @@ declare_enum(tp, idf, l)
idf->id_def->df_address = l; idf->id_def->df_address = l;
} }
check_formals(idf, dc) void check_formals(struct idf *idf, struct declarator *dc)
struct idf *idf;
struct declarator *dc;
{ {
register struct formal *fm = dc->dc_formal; struct formal *fm = dc->dc_formal;
register struct proto *pl = idf->id_def->df_type->tp_proto; struct proto *pl = idf->id_def->df_type->tp_proto;
register struct decl_unary *du = dc->dc_decl_unary; struct decl_unary *du = dc->dc_decl_unary;
if (!du) { /* error or typdef'ed function */ if (!du) { /* error or typdef'ed function */
error("illegal definition of %s", idf->id_text); error("illegal definition of %s", idf->id_text);
@ -483,7 +475,7 @@ check_formals(idf, dc)
error("incorrect number of parameters"); error("incorrect number of parameters");
} }
} else { /* make a pseudo-prototype */ } else { /* make a pseudo-prototype */
register struct proto *lpl = new_proto(); struct proto *lpl = new_proto();
if (!options['o']) if (!options['o'])
warning("'%s' old-fashioned function definition" warning("'%s' old-fashioned function definition"
@ -512,18 +504,16 @@ check_formals(idf, dc)
dc->dc_formal = 0; dc->dc_formal = 0;
} }
declare_formals(idf, fp) void declare_formals(struct idf *idf, arith *fp)
struct idf *idf;
arith *fp;
{ {
/* Declares those formals as int that haven't been declared /* Declares those formals as int that haven't been declared
by the user. by the user.
An address is assigned to each formal parameter. An address is assigned to each formal parameter.
The total size of the formals is returned in *fp; The total size of the formals is returned in *fp;
*/ */
register struct stack_entry *se = stack_level_of(L_FORMAL1)->sl_entry; struct stack_entry *se = stack_level_of(L_FORMAL1)->sl_entry;
arith f_offset = (arith)0; arith f_offset = (arith)0;
register int nparams = 0; int nparams = 0;
int hasproto; int hasproto;
struct def *df = idf->id_def; struct def *df = idf->id_def;
@ -590,9 +580,7 @@ declare_formals(idf, fp)
*fp = f_offset; *fp = f_offset;
} }
int int regtype(struct type *tp)
regtype(tp)
struct type *tp;
{ {
switch(tp->tp_fund) { switch(tp->tp_fund) {
case INT: case INT:
@ -608,11 +596,7 @@ regtype(tp)
return -1; return -1;
} }
add_def(idf, sc, tp, lvl) void add_def(struct idf *idf, int sc, struct type *tp, int lvl)
struct idf *idf;
struct type *tp;
int lvl;
int sc;
{ {
/* The identifier idf is declared on level lvl with storage /* The identifier idf is declared on level lvl with storage
class sc and type tp, through a faked C declaration. class sc and type tp, through a faked C declaration.
@ -629,13 +613,12 @@ add_def(idf, sc, tp, lvl)
declare_idf(&Ds, &Dc, lvl); declare_idf(&Ds, &Dc, lvl);
} }
update_ahead(idf) void update_ahead(struct idf *idf)
register struct idf *idf;
{ {
/* The tk_symb of the token ahead is updated in the light of new /* The tk_symb of the token ahead is updated in the light of new
information about the identifier idf. information about the identifier idf.
*/ */
register int tk_symb = AHEAD; int tk_symb = AHEAD;
if ( (tk_symb == IDENTIFIER || tk_symb == TYPE_IDENTIFIER) && if ( (tk_symb == IDENTIFIER || tk_symb == TYPE_IDENTIFIER) &&
ahead.tk_idf == idf ahead.tk_idf == idf
@ -644,8 +627,7 @@ update_ahead(idf)
TYPE_IDENTIFIER : IDENTIFIER; TYPE_IDENTIFIER : IDENTIFIER;
} }
free_formals(fm) void free_formals(struct formal *fm)
register struct formal *fm;
{ {
while (fm) { while (fm) {
struct formal *tmp = fm->next; struct formal *tmp = fm->next;

View File

@ -4,6 +4,8 @@
*/ */
/* $Id$ */ /* $Id$ */
/* IDENTIFIER DESCRIPTOR */ /* IDENTIFIER DESCRIPTOR */
#ifndef LANG_CEM_CEMCOM_ANSI_IDF_STR
#define LANG_CEM_CEMCOM_ANSI_IDF_STR
#include "nopp.h" #include "nopp.h"
@ -47,3 +49,5 @@ struct dependency {
extern int level; extern int level;
extern struct idf *gen_idf(); extern struct idf *gen_idf();
#endif /* LANG_CEM_CEMCOM_ANSI_IDF_STR */

View File

@ -0,0 +1,33 @@
/*
* 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 */

View File

@ -13,11 +13,17 @@
#include <system.h> #include <system.h>
#include <alloc.h> #include <alloc.h>
#include <time.h> #include <time.h>
#include <flt_arith.h>
#include <em_label.h>
#include "class.h" #include "class.h"
#include "macro.h" #include "macro.h"
#include "idf.h" #include "idf.h"
#include "arith.h"
extern char *sprint(); #include "print.h"
#include "expr.h"
#include "error.h"
#include "domacro.h"
struct mkey { struct mkey {
char *mk_reserved; char *mk_reserved;
@ -28,6 +34,7 @@ struct mkey {
{"else", K_ELSE}, {"else", K_ELSE},
{"endif", K_ENDIF}, {"endif", K_ENDIF},
{"error", K_ERROR}, {"error", K_ERROR},
{"warning", K_WARNING},
{"if", K_IF}, {"if", K_IF},
{"ifdef", K_IFDEF}, {"ifdef", K_IFDEF},
{"ifndef", K_IFNDEF}, {"ifndef", K_IFNDEF},
@ -38,7 +45,7 @@ struct mkey {
{0, K_UNKNOWN} {0, K_UNKNOWN}
}; };
init_pp() void init_pp()
{ {
static char *months[12] = { static char *months[12] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jan", "Feb", "Mar", "Apr", "May", "Jun",
@ -55,10 +62,10 @@ init_pp()
id_resmac field of the identifier. id_resmac field of the identifier.
*/ */
{ {
register struct mkey *mk = &mkey[0]; struct mkey *mk = &mkey[0];
while (mk->mk_reserved) { while (mk->mk_reserved) {
register struct idf *idf = str2idf(mk->mk_reserved, 0); struct idf *idf = str2idf(mk->mk_reserved, 0);
if (idf->id_resmac) if (idf->id_resmac)
fatal("maximum identifier length insufficient"); fatal("maximum identifier length insufficient");

View File

@ -0,0 +1,12 @@
/*
* 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 */

View File

@ -7,9 +7,16 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.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 "inputtype.h"
#include "file_info.h" #include "file_info.h"
#include "input.h" #include "input.h"
#include "replace_loc.h"
#include "error.h"
#define INP_PUSHBACK 3 #define INP_PUSHBACK 3
#define INP_TYPE struct file_info #define INP_TYPE struct file_info

View File

@ -3,6 +3,9 @@
* See the copyright notice in the ACK home directory, in the file "Copyright". * See the copyright notice in the ACK home directory, in the file "Copyright".
*/ */
/* $Id$ */ /* $Id$ */
#ifndef LANG_CEM_CEMCOM_ANSI_INPUT_H
#define LANG_CEM_CEMCOM_ANSI_INPUT_H
#define INP_PUSHBACK 3 #define INP_PUSHBACK 3
#include <inp_pkg.spec> #include <inp_pkg.spec>
@ -13,3 +16,5 @@
extern int LexSave; /* last character read by GetChar */ extern int LexSave; /* last character read by GetChar */
extern int GetChar(); /* character input, with trigraph parsing */ extern int GetChar(); /* character input, with trigraph parsing */
#endif /* LANG_CEM_CEMCOM_ANSI_INPUT_H */

View File

@ -14,6 +14,8 @@
#include "l_lint.h" #include "l_lint.h"
#endif /* LINT */ #endif /* LINT */
#include "debug.h" #include "debug.h"
#include <stdio.h>
#include <stdlib.h>
#include <alloc.h> #include <alloc.h>
#include <assert.h> #include <assert.h>
#include "nobitfield.h" #include "nobitfield.h"
@ -21,30 +23,36 @@
#include "arith.h" #include "arith.h"
#include "label.h" #include "label.h"
#include "expr.h" #include "expr.h"
#include "expr_loc.h"
#include "type.h" #include "type.h"
#include "proto.h" #include "proto.h"
#include "struct.h" #include "struct.h"
#include "struct_loc.h"
#include "field.h" #include "field.h"
#include "assert.h" #include "assert.h"
#include "Lpars.h" #include "Lpars.h"
#include "sizes.h" #include "sizes.h"
#include "align.h" #include "align.h"
#include "idf.h" #include "idf.h"
#include "idf_loc.h"
#include "level.h" #include "level.h"
#include "def.h" #include "def.h"
#include "ch3.h"
#include "ival.h"
#include "LLlex.h" #include "LLlex.h"
#include "estack.h" #include "estack.h"
#include "conversion.h"
#include "cstoper.h"
#include "error.h"
#define con_nullbyte() C_con_ucon("0", (arith)1) #define con_nullbyte() C_con_ucon("0", (arith)1)
#define aggregate_type(tp) ((tp)->tp_fund == ARRAY || (tp)->tp_fund == STRUCT) #define aggregate_type(tp) ((tp)->tp_fund == ARRAY || (tp)->tp_fund == STRUCT)
char *long2str(); char *long2str();
char *strncpy();
extern char options[]; extern char options[];
static int gen_error; static int gen_error;
static int pack_level; static int pack_level;
struct type **gen_tphead(), **gen_tpmiddle();
struct sdef *gen_align_to_next();
struct e_stack *p_stack; struct e_stack *p_stack;
} }
@ -52,7 +60,7 @@ struct e_stack *p_stack;
*/ */
/* 3.5 */ /* 3.5 */
initial_value(register struct type **tpp; register struct expr **expp;) : initial_value(struct type **tpp; struct expr **expp;) :
{ if (tpp) gen_tpcheck(tpp); } { if (tpp) gen_tpcheck(tpp); }
[ [
{ if (pack_level == 0) gen_error = 0; } { if (pack_level == 0) gen_error = 0; }
@ -122,10 +130,9 @@ initial_value_list(register struct type **tpp; struct expr **expp;)
; ;
{ {
gen_tpcheck(tpp) void gen_tpcheck(struct type **tpp)
struct type **tpp;
{ {
register struct type *tp; struct type *tp;
if (gen_error) return; if (gen_error) return;
switch((tp = *tpp)->tp_fund) { switch((tp = *tpp)->tp_fund) {
@ -147,11 +154,9 @@ gen_tpcheck(tpp)
} }
} }
gen_simple_exp(tpp, expp) void gen_simple_exp(struct type **tpp, struct expr **expp)
struct type **tpp;
struct expr **expp;
{ {
register struct type *tp; struct type *tp;
if (gen_error) return; if (gen_error) return;
tp = *tpp; tp = *tpp;
@ -177,12 +182,9 @@ gen_simple_exp(tpp, expp)
} }
} }
struct type ** struct type **arr_elem(struct type **tpp, struct e_stack *p)
arr_elem(tpp, p)
struct type **tpp;
struct e_stack *p;
{ {
register struct type *tp = *tpp; struct type *tp = *tpp;
if (tp->tp_up->tp_fund == CHAR && AHEAD == STRING && p->elem_count == 1) { if (tp->tp_up->tp_fund == CHAR && AHEAD == STRING && p->elem_count == 1) {
p->nelem = 1; p->nelem = 1;
@ -193,10 +195,7 @@ arr_elem(tpp, p)
return gen_tphead(&(tp->tp_up), 1); return gen_tphead(&(tp->tp_up), 1);
} }
struct sdef * struct sdef *next_field(struct sdef *sd, struct e_stack *p)
next_field(sd, p)
register struct sdef *sd;
register struct e_stack *p;
{ {
if (sd->sd_sdef) if (sd->sd_sdef)
p->bytes_upto_here += zero_bytes(sd); p->bytes_upto_here += zero_bytes(sd);
@ -206,13 +205,11 @@ next_field(sd, p)
return sd->sd_sdef; return sd->sd_sdef;
} }
struct type ** struct type **gen_tphead(struct type **tpp, int nest)
gen_tphead(tpp, nest)
struct type **tpp;
{ {
register struct type *tp = *tpp; struct type *tp = *tpp;
register struct e_stack *p; struct e_stack *p;
register struct sdef *sd; struct sdef *sd;
if (tpp && *tpp == error_type) { if (tpp && *tpp == error_type) {
gen_error = pack_level; gen_error = pack_level;
@ -283,12 +280,11 @@ gen_tphead(tpp, nest)
} }
} }
struct type ** struct type **gen_tpmiddle()
gen_tpmiddle()
{ {
register struct type *tp; struct type *tp;
register struct sdef *sd; struct sdef *sd;
register struct e_stack *p = p_stack; struct e_stack *p = p_stack;
if (gen_error) { if (gen_error) {
if (p) return p->s_tpp; if (p) return p->s_tpp;
@ -342,11 +338,9 @@ again:
} }
} }
struct sdef * struct sdef *gen_align_to_next(struct e_stack *p)
gen_align_to_next(p)
register struct e_stack *p;
{ {
register struct sdef *sd = p->s_def; struct sdef *sd = p->s_def;
if (! sd) return sd; if (! sd) return sd;
#ifndef NOBITFIELD #ifndef NOBITFIELD
@ -361,11 +355,11 @@ gen_align_to_next(p)
return sd; return sd;
} }
gen_tpend() void gen_tpend()
{ {
register struct e_stack *p = p_stack; struct e_stack *p = p_stack;
register struct type *tp; struct type *tp;
register struct sdef *sd; struct sdef *sd;
int getout = 0; int getout = 0;
while (!getout && p) { while (!getout && p) {
@ -417,11 +411,9 @@ gen_tpend()
In the latter case, only the first member is initialised and In the latter case, only the first member is initialised and
the rest is zeroed. the rest is zeroed.
*/ */
check_and_pad(expp, tpp) void check_and_pad(struct expr **expp, struct type **tpp)
struct type **tpp;
struct expr **expp;
{ {
register struct type *tp = *tpp; struct type *tp = *tpp;
if (tp->tp_fund == ARRAY) { if (tp->tp_fund == ARRAY) {
check_and_pad(expp, &(tp->tp_up)); /* first member */ check_and_pad(expp, &(tp->tp_up)); /* first member */
@ -432,7 +424,7 @@ check_and_pad(expp, tpp)
tp = *tpp = construct_type(ARRAY, tp->tp_up, tp = *tpp = construct_type(ARRAY, tp->tp_up,
0, (arith)1, NO_PROTO); 0, (arith)1, NO_PROTO);
else { else {
register int dim = tp->tp_size / tp->tp_up->tp_size; int dim = tp->tp_size / tp->tp_up->tp_size;
/* pad remaining members with zeroes */ /* pad remaining members with zeroes */
while (--dim > 0) while (--dim > 0)
pad(tp->tp_up); pad(tp->tp_up);
@ -440,13 +432,13 @@ check_and_pad(expp, tpp)
} }
else else
if (tp->tp_fund == STRUCT) { if (tp->tp_fund == STRUCT) {
register struct sdef *sd = tp->tp_sdef; struct sdef *sd = tp->tp_sdef;
check_and_pad(expp, &(sd->sd_type)); check_and_pad(expp, &(sd->sd_type));
/* next selector is aligned by adding extra zeroes */ /* next selector is aligned by adding extra zeroes */
if (sd->sd_sdef) if (sd->sd_sdef)
zero_bytes(sd); zero_bytes(sd);
while (sd = sd->sd_sdef) { /* pad remaining selectors */ while ( (sd = sd->sd_sdef) ) { /* pad remaining selectors */
pad(sd->sd_type); pad(sd->sd_type);
if (sd->sd_sdef) if (sd->sd_sdef)
zero_bytes(sd); zero_bytes(sd);
@ -454,7 +446,7 @@ check_and_pad(expp, tpp)
} }
else if (tp->tp_fund == UNION) { else if (tp->tp_fund == UNION) {
/* only the first selector can be initialized */ /* only the first selector can be initialized */
register struct sdef *sd = tp->tp_sdef; struct sdef *sd = tp->tp_sdef;
check_and_pad(expp, &(sd->sd_type)); check_and_pad(expp, &(sd->sd_type));
} }
@ -465,11 +457,10 @@ check_and_pad(expp, tpp)
/* pad() fills an element of type tp with zeroes. /* pad() fills an element of type tp with zeroes.
If the element is an aggregate, pad() is called recursively. If the element is an aggregate, pad() is called recursively.
*/ */
pad(tpx) void pad(struct type *tpx)
struct type *tpx;
{ {
register struct type *tp = tpx; struct type *tp = tpx;
register arith sz = tp->tp_size; arith sz = tp->tp_size;
gen_tpcheck(&tpx); gen_tpcheck(&tpx);
if (gen_error) return; if (gen_error) return;
@ -496,16 +487,14 @@ pad(tpx)
No further comment is needed to explain the internal structure No further comment is needed to explain the internal structure
of this straightforward function. of this straightforward function.
*/ */
check_ival(expp, tp) void check_ival(struct expr **expp, struct type *tp)
register struct type *tp;
struct expr **expp;
{ {
/* The philosophy here is that ch3cast puts an explicit /* The philosophy here is that ch3cast puts an explicit
conversion node in front of the expression if the types conversion node in front of the expression if the types
are not compatible. In this case, the initialisation are not compatible. In this case, the initialisation
expression is no longer a constant. expression is no longer a constant.
*/ */
register struct expr *expr = *expp; struct expr *expr = *expp;
switch (tp->tp_fund) { switch (tp->tp_fund) {
case CHAR: case CHAR:
@ -609,13 +598,13 @@ and also to prevent runtime coercions for compile-time constants.
a string constant. a string constant.
Alignment is taken care of. Alignment is taken care of.
*/ */
ch_array(tpp, ex)
struct type **tpp; /* type tp = array of characters */ /* tpp -> type tp = array of characters */
struct expr *ex; void ch_array(struct type **tpp, struct expr *ex)
{ {
register struct type *tp = *tpp; struct type *tp = *tpp;
register int length = ex->SG_LEN, i; int length = ex->SG_LEN, i;
register char *to, *from, *s; char *to, *from, *s;
ASSERT(ex->ex_class == String); ASSERT(ex->ex_class == String);
if (tp->tp_size == (arith)-1) { if (tp->tp_size == (arith)-1) {
@ -651,10 +640,7 @@ ch_array(tpp, ex)
/* As long as some parts of the pipeline cannot handle very long string /* As long as some parts of the pipeline cannot handle very long string
constants, string constants are written out in chunks constants, string constants are written out in chunks
*/ */
str_cst(str, len, inrom) void str_cst(char *str, int len, int inrom)
register char *str;
register int len;
int inrom;
{ {
int chunksize = ((127 + (int) word_size) / (int) word_size) * (int) word_size; int chunksize = ((127 + (int) word_size) / (int) word_size) * (int) word_size;
@ -678,9 +664,7 @@ str_cst(str, len, inrom)
"throws" the result of "field" out if the current selector "throws" the result of "field" out if the current selector
is the last of this number of fields stored at the same address. is the last of this number of fields stored at the same address.
*/ */
put_bf(tp, val) void put_bf(struct type *tp, arith val)
struct type *tp;
arith val;
{ {
static long field = (arith)0; static long field = (arith)0;
static arith offset = (arith)-1; static arith offset = (arith)-1;
@ -708,9 +692,7 @@ put_bf(tp, val)
} }
#endif /* NOBITFIELD */ #endif /* NOBITFIELD */
int int zero_bytes(struct sdef *sd)
zero_bytes(sd)
register struct sdef *sd;
{ {
/* fills the space between a selector of a struct /* fills the space between a selector of a struct
and the next selector of that struct with zero-bytes. and the next selector of that struct with zero-bytes.
@ -724,10 +706,7 @@ zero_bytes(sd)
return count; return count;
} }
int int valid_type(struct type *tp, char *str)
valid_type(tp, str)
struct type *tp;
char *str;
{ {
ASSERT(tp!=(struct type *)0); ASSERT(tp!=(struct type *)0);
if (tp->tp_size < 0) { if (tp->tp_size < 0) {
@ -737,10 +716,9 @@ valid_type(tp, str)
return 1; return 1;
} }
con_int(ex) void con_int(struct expr *ex)
register struct expr *ex;
{ {
register struct type *tp = ex->ex_type; struct type *tp = ex->ex_type;
ASSERT(is_cp_cst(ex)); ASSERT(is_cp_cst(ex));
if (tp->tp_unsigned) if (tp->tp_unsigned)
@ -751,14 +729,13 @@ con_int(ex)
C_con_icon(long2str((long)ex->VL_VALUE, 10), tp->tp_size); C_con_icon(long2str((long)ex->VL_VALUE, 10), tp->tp_size);
} }
illegal_init_cst(ex) void illegal_init_cst(struct expr *ex)
struct expr *ex;
{ {
expr_error(ex, "illegal initialization constant"); expr_error(ex, "illegal initialization constant");
gen_error = pack_level; gen_error = pack_level;
} }
too_many_initialisers() void too_many_initialisers()
{ {
error("too many initializers"); error("too many initializers");
gen_error = pack_level; gen_error = pack_level;

View File

@ -0,0 +1,66 @@
/*
* 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 */

View File

@ -14,6 +14,8 @@
* to terminate the compilation process. * to terminate the compilation process.
*/ */
#include "blocks.h"
#define store_block(sz, al) #define store_block(sz, al)
#define load_block(sz, al) #define load_block(sz, al)

View File

@ -26,8 +26,9 @@
#include "type.h" #include "type.h"
#include "level.h" #include "level.h"
#include "l_state.h" #include "l_state.h"
#include "conversion.h"
#include <symbol2str.h>
extern char *symbol2str();
extern struct type *func_type; extern struct type *func_type;
PRIVATE lint_enum_arith(); PRIVATE lint_enum_arith();

View File

@ -13,18 +13,20 @@
#include "def.h" #include "def.h"
#include "type.h" #include "type.h"
#include "stack.h" #include "stack.h"
#include "error.h"
#include "idf_loc.h"
#include "stack_loc.h"
extern char options[]; extern char options[];
enter_label(idf, defining) void enter_label(struct idf *idf, int defining)
register struct idf *idf;
{ {
/* The identifier idf is entered as a label. If it is new, /* The identifier idf is entered as a label. If it is new,
it is entered into the idf list with the largest possible it is entered into the idf list with the largest possible
scope, i.e., on the lowest possible level. scope, i.e., on the lowest possible level.
If defining, the label comes from a label statement. If defining, the label comes from a label statement.
*/ */
register struct def *def = idf->id_label; struct def *def = idf->id_label;
if (def) { if (def) {
if (defining && def->df_initialized) if (defining && def->df_initialized)
@ -44,8 +46,7 @@ enter_label(idf, defining)
def->df_initialized = 1; def->df_initialized = 1;
} }
unstack_label(idf) void unstack_label(struct idf *idf)
register struct idf *idf;
{ {
/* The scope in which the label idf occurred is left. /* The scope in which the label idf occurred is left.
*/ */

View File

@ -4,6 +4,8 @@
*/ */
/* $Id$ */ /* $Id$ */
/* L A B E L D E F I N I T I O N */ /* 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" */ #include <em_label.h> /* obtain definition of "label" */
@ -26,3 +28,10 @@ extern label datlab_count;
not be there, and if it is there, it may be from a not be there, and if it is there, it may be from a
declaration or another application. 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 */

View File

@ -48,5 +48,6 @@ struct macro {
#define K_LINE 10 #define K_LINE 10
#define K_PRAGMA 11 #define K_PRAGMA 11
#define K_UNDEF 12 #define K_UNDEF 12
#define K_WARNING 13
#define K_FILE 100 /* for dependency generator */ #define K_FILE 100 /* for dependency generator */
#endif /* NOPP */ #endif /* NOPP */

View File

@ -5,10 +5,13 @@
/* $Id$ */ /* $Id$ */
/* MAIN PROGRAM */ /* MAIN PROGRAM */
#include <string.h>
#include "lint.h" #include "lint.h"
#include <system.h> #include <system.h>
#include "print.h"
#include "debug.h" #include "debug.h"
#include "nopp.h" #include "nopp.h"
#include "label.h"
#include "trgt_sizes.h" #include "trgt_sizes.h"
#include "use_tmp.h" #include "use_tmp.h"
#include "inputtype.h" #include "inputtype.h"
@ -29,9 +32,21 @@
#include "align.h" #include "align.h"
#include "macro.h" #include "macro.h"
#include "assert.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 struct tokenname tkidf[];
extern char *symbol2str();
extern char options[128]; extern char options[128];
#ifndef NOPP #ifndef NOPP
@ -83,8 +98,7 @@ arith ifval; /* ifval will contain the result of the #if expression */
char *prog_name; char *prog_name;
main(argc, argv) int main(int argc, char *argv[])
char *argv[];
{ {
/* parse and interpret the command line options */ /* parse and interpret the command line options */
prog_name = argv[0]; prog_name = argv[0];
@ -139,15 +153,13 @@ main(argc, argv)
#ifndef NOPP #ifndef NOPP
struct dependency *file_head; struct dependency *file_head;
extern char *strrchr();
list_dependencies(source) void list_dependencies(char *source)
char *source;
{ {
register struct dependency *p = file_head; struct dependency *p = file_head;
if (source) { if (source) {
register char *s = strrchr(source, '.'); char *s = strrchr(source, '.');
if (s && *(s+1)) { if (s && *(s+1)) {
s++; s++;
@ -157,7 +169,7 @@ char *source;
* object generated, so don't include the pathname * object generated, so don't include the pathname
* leading to it. * leading to it.
*/ */
if (s = strrchr(source, '/')) { if ( (s = strrchr(source, '/')) ) {
source = s + 1; source = s + 1;
} }
} }
@ -172,13 +184,12 @@ char *source;
} }
} }
add_dependency(s) void add_dependency(char *s)
char *s;
{ {
register struct idf *p = str2idf(s, 1); struct idf *p = str2idf(s, 1);
if (! p->id_resmac) { if (! p->id_resmac) {
register struct dependency *q = new_dependency(); struct dependency *q = new_dependency();
p->id_resmac = K_FILE; p->id_resmac = K_FILE;
q->dep_idf = p; q->dep_idf = p;
@ -187,8 +198,7 @@ char *s;
} }
} }
dependency(s, source) void dependency(char *s, char *source)
char *s, *source;
{ {
if (options['i'] && !strncmp(s, "/usr/include/", 13)) { if (options['i'] && !strncmp(s, "/usr/include/", 13)) {
return; return;
@ -207,12 +217,11 @@ char *source = 0;
char *nmlist = 0; char *nmlist = 0;
#endif /* GEN_NM_LIST */ #endif /* GEN_NM_LIST */
compile(argc, argv) void compile(int argc, char *argv[])
char *argv[];
{ {
char *result; char *result;
#ifndef LINT #ifndef LINT
register char *destination = 0; char *destination = 0;
#endif /* LINT */ #endif /* LINT */
#ifdef DEBUG #ifdef DEBUG
@ -318,7 +327,7 @@ compile(argc, argv)
#endif /* NOPP */ #endif /* NOPP */
} }
init() void init()
{ {
init_cst(); /* initialize variables of "cstoper.c" */ init_cst(); /* initialize variables of "cstoper.c" */
reserve(tkidf); /* mark the C reserved words as such */ reserve(tkidf); /* mark the C reserved words as such */
@ -383,8 +392,7 @@ init()
stack_level(); stack_level();
} }
init_specials(si) void init_specials(struct sp_id *si)
register struct sp_id *si;
{ {
while (si->si_identifier) { while (si->si_identifier) {
struct idf *idf = str2idf(si->si_identifier, 0); struct idf *idf = str2idf(si->si_identifier, 0);
@ -398,7 +406,7 @@ init_specials(si)
#ifdef DEBUG #ifdef DEBUG
#ifndef NOPP #ifndef NOPP
preprocess() void preprocess()
{ {
/* preprocess() is the "stand-alone" preprocessor which /* preprocess() is the "stand-alone" preprocessor which
consecutively calls the lexical analyzer LLlex() to get consecutively calls the lexical analyzer LLlex() to get
@ -468,7 +476,7 @@ preprocess()
} }
#endif /* NOPP */ #endif /* NOPP */
Info() void Info()
{ {
extern int cnt_string_cst, cnt_formal, extern int cnt_string_cst, cnt_formal,
cnt_decl_unary, cnt_def, cnt_expr, cnt_field, cnt_decl_unary, cnt_def, cnt_expr, cnt_field,
@ -500,14 +508,12 @@ Info()
} }
#endif /* DEBUG */ #endif /* DEBUG */
void void No_Mem() /* called by alloc package */
No_Mem() /* called by alloc package */
{ {
fatal("out of memory"); fatal("out of memory");
} }
void void C_failed() /* called by EM_code module */
C_failed() /* called by EM_code module */
{ {
fatal("write failed"); fatal("write failed");
} }

View File

@ -0,0 +1,20 @@
/*
* 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 */

View File

@ -3,11 +3,11 @@
sed -e ' sed -e '
s:^.*[ ]ALLOCDEF[ ].*"\(.*\)"[ ]*\([0-9][0-9]*\).*$:\ s:^.*[ ]ALLOCDEF[ ].*"\(.*\)"[ ]*\([0-9][0-9]*\).*$:\
/* allocation definitions of struct \1 */\ /* allocation definitions of struct \1 */\
extern char *st_alloc();\ extern char *st_alloc(char **, unsigned int, int);\
extern struct \1 *h_\1;\ extern struct \1 *h_\1;\
#ifdef DEBUG\ #ifdef DEBUG\
extern int cnt_\1;\ extern int cnt_\1;\
extern char *std_alloc();\ extern char *std_alloc(char **, unsigned int, int, int *);\
#define new_\1() ((struct \1 *) std_alloc((char **)\&h_\1, sizeof(struct \1), \2, \&cnt_\1))\ #define new_\1() ((struct \1 *) std_alloc((char **)\&h_\1, sizeof(struct \1), \2, \&cnt_\1))\
#else\ #else\
#define new_\1() ((struct \1 *) st_alloc((char **)\&h_\1, sizeof(struct \1), \2))\ #define new_\1() ((struct \1 *) st_alloc((char **)\&h_\1, sizeof(struct \1), \2))\

View File

@ -5,9 +5,7 @@ cat <<'--EOT--'
/* $Id$ */ /* $Id$ */
#include "Lpars.h" #include "Lpars.h"
char * char *symbol2str(int tok)
symbol2str(tok)
int tok;
{ {
#define SIZBUF 8 #define SIZBUF 8
/* allow for a few invocations in f.i. an argument list */ /* allow for a few invocations in f.i. an argument list */

View File

@ -22,6 +22,9 @@
#include "use_tmp.h" #include "use_tmp.h"
#include "dataflow.h" #include "dataflow.h"
#include "dbsymtab.h" #include "dbsymtab.h"
#include "conversion.h"
#include "error.h"
#include "domacro.h"
#ifndef NOPP #ifndef NOPP
extern char **inctable; extern char **inctable;
@ -41,12 +44,11 @@ char loptions[128]; /* one for every char */
extern int idfsize; extern int idfsize;
extern int density; extern int density;
static int txt2int(); static int txt2int(char **tp);
do_option(text) void do_option(char *text)
char *text;
{ {
register char opt; char opt;
next_option: /* to allow combined one-char options */ next_option: /* to allow combined one-char options */
switch (opt = *text++) { switch (opt = *text++) {
@ -63,7 +65,7 @@ next_option: /* to allow combined one-char options */
break; break;
case '-': case '-':
options[*text++] = 1; /* flags, debug options etc. */ options[*(unsigned char *)text++] = 1; /* flags, debug options etc. */
goto next_option; goto next_option;
#ifndef LINT #ifndef LINT
@ -76,7 +78,7 @@ next_option: /* to allow combined one-char options */
break; break;
case 'i': case 'i':
case 'm': case 'm':
options[opt] = 1; options[(unsigned char)opt] = 1;
break; break;
#endif /* NOPP */ #endif /* NOPP */
#endif /* LINT */ #endif /* LINT */
@ -97,7 +99,7 @@ next_option: /* to allow combined one-char options */
case 'w': /* no warnings will be given */ case 'w': /* no warnings will be given */
case 's': /* no stricts will be given */ case 's': /* no stricts will be given */
case 'o': /* no complaints about old-style */ case 'o': /* no complaints about old-style */
options[opt] = 1; options[(unsigned char)opt] = 1;
goto next_option; goto next_option;
case 'a': /* suppress all but errors diagnostics */ case 'a': /* suppress all but errors diagnostics */
options['w'] = 1; /* implies -a */ options['w'] = 1; /* implies -a */
@ -119,17 +121,17 @@ next_option: /* to allow combined one-char options */
#ifndef NOPP #ifndef NOPP
case 'D' : { /* -Dname : predefine name */ case 'D' : { /* -Dname : predefine name */
register char *cp = text, *name, *mactext; char *cp = text, *name, *mactext;
unsigned maclen; unsigned maclen;
if (class(*cp) != STIDF && class(*cp) != STELL) { if (class(*(unsigned char *)cp) != STIDF && class(*(unsigned char *)cp) != STELL) {
error("identifier missing in -D%s", text); error("identifier missing in -D%s", text);
break; break;
} }
name = cp; name = cp;
while (*cp && in_idf(*cp)) { while (*cp && in_idf(*(unsigned char *)cp)) {
++cp; ++cp;
} }
@ -155,7 +157,7 @@ next_option: /* to allow combined one-char options */
case 'I' : /* -Ipath : insert "path" into include list */ case 'I' : /* -Ipath : insert "path" into include list */
if (*text) { if (*text) {
int i; int i;
register char *new = text; char *new = text;
if (inc_total >= inc_max) { if (inc_total >= inc_max) {
inctable = (char **) inctable = (char **)
@ -214,10 +216,10 @@ next_option: /* to allow combined one-char options */
#ifndef NOCROSS #ifndef NOCROSS
case 'V' : /* set object sizes and alignment requirements */ case 'V' : /* set object sizes and alignment requirements */
{ {
register arith sz, algn; arith sz, algn;
char c; char c;
while (c = *text++) { while ( (c = *text++) ) {
sz = txt2int(&text); sz = txt2int(&text);
algn = 0; algn = 0;
if (*text == '.') { if (*text == '.') {
@ -302,9 +304,7 @@ next_option: /* to allow combined one-char options */
} }
} }
static int static int txt2int(char **tp)
txt2int(tp)
register char **tp;
{ {
/* the integer pointed to by *tp is read, while increasing /* the integer pointed to by *tp is read, while increasing
*tp; the resulting value is yielded. *tp; the resulting value is yielded.

View File

@ -0,0 +1,12 @@
/*
* 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 */

View File

@ -7,6 +7,8 @@
#include "debug.h" #include "debug.h"
#include "idf.h" #include "idf.h"
#include "skip.h"
#include "domacro.h"
#define P_UNKNOWN 0 #define P_UNKNOWN 0
#define NR_PRAGMAS 0 #define NR_PRAGMAS 0
@ -18,14 +20,12 @@ struct pkey {
{0, P_UNKNOWN} {0, P_UNKNOWN}
}; };
extern struct idf *GetIdentifier(); void do_pragma()
do_pragma()
{ {
#if NR_PRAGMAS #if NR_PRAGMAS
register struct pkey *pkp = &pragmas[0]; struct pkey *pkp = &pragmas[0];
#endif #endif
register struct idf *id = GetIdentifier(1); struct idf *id = GetIdentifier(1);
if (id != (struct idf *)0) { if (id != (struct idf *)0) {
#if NR_PRAGMAS #if NR_PRAGMAS

View File

@ -0,0 +1,12 @@
/*
* 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 */

View File

@ -52,13 +52,22 @@
#include "arith.h" #include "arith.h"
#include "LLlex.h" #include "LLlex.h"
#include "idf.h" #include "idf.h"
#include "idf_loc.h"
#include "label.h" #include "label.h"
#include "type.h" #include "type.h"
#include "declar.h" #include "declar.h"
#include "decspecs.h" #include "decspecs.h"
#include "code.h" #include "code.h"
#include "expr.h" #include "expr.h"
#include "expr_loc.h"
#include "def.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 #ifdef LINT
#include "l_lint.h" #include "l_lint.h"
#endif /* LINT */ #endif /* LINT */
@ -67,7 +76,6 @@
extern arith ifval; extern arith ifval;
#endif /* NOPP */ #endif /* NOPP */
extern error();
} }
control_if_expression control_if_expression

View File

@ -0,0 +1,16 @@
/*
* 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 */

View File

@ -17,23 +17,28 @@
#include "arith.h" #include "arith.h"
#include "align.h" #include "align.h"
#include "stack.h" #include "stack.h"
#include "stack_loc.h"
#include "idf.h" #include "idf.h"
#include "idf_loc.h"
#include "def.h" #include "def.h"
#include "type.h" #include "type.h"
#include "ch3.h"
#include "struct.h" #include "struct.h"
#include "label.h" #include "label.h"
#include "expr.h" #include "expr.h"
#include "declar.h" #include "declar.h"
#include "decspecs.h" #include "decspecs.h"
#include "proto.h" #include "proto.h"
#include "proto_loc.h"
#include "assert.h" #include "assert.h"
#include "conversion.h"
#include "error.h"
extern char options[]; extern char options[];
check_for_void(pl) void check_for_void(struct proto *pl)
register struct proto *pl;
{ {
register int errcnt = 0; int errcnt = 0;
if (!pl) return; if (!pl) return;
if ((pl->pl_flag & PL_VOID) && !(pl->next)) return; if ((pl->pl_flag & PL_VOID) && !(pl->next)) return;
@ -49,11 +54,7 @@ check_for_void(pl)
} }
} }
add_proto(pl, ds, dc, lvl) void add_proto(struct proto *pl, struct decspecs *ds, struct declarator *dc, int lvl)
struct proto *pl;
struct decspecs *ds;
struct declarator *dc;
int lvl;
{ {
/* The full typed identifier or abstract type, described /* The full typed identifier or abstract type, described
by the structures decspecs and declarator are turned by the structures decspecs and declarator are turned
@ -62,10 +63,10 @@ add_proto(pl, ds, dc, lvl)
later on it's decided whether they were prototypes later on it's decided whether they were prototypes
or actual declarations. or actual declarations.
*/ */
register struct idf *idf = dc->dc_idf; struct idf *idf = dc->dc_idf;
register struct def *def = idf ? idf->id_def : (struct def *)0; struct def *def = idf ? idf->id_def : (struct def *)0;
register int sc = ds->ds_sc; int sc = ds->ds_sc;
register struct type *type; struct type *type;
char formal_array = 0; char formal_array = 0;
ASSERT(ds->ds_type != (struct type *)0); ASSERT(ds->ds_type != (struct type *)0);
@ -122,7 +123,7 @@ add_proto(pl, ds, dc, lvl)
} else if (idf != (struct idf *)0) { } else if (idf != (struct idf *)0) {
/* New definition, redefinition hides earlier one /* New definition, redefinition hides earlier one
*/ */
register struct def *newdef = new_def(); struct def *newdef = new_def();
newdef->next = def; newdef->next = def;
newdef->df_level = lvl; newdef->df_level = lvl;
@ -172,7 +173,7 @@ struct type *tp;
struct idf **idpp; struct idf **idpp;
{ {
struct tag *tg = (struct tag *)0; struct tag *tg = (struct tag *)0;
register int fund = tp->tp_fund; int fund = tp->tp_fund;
while (fund == FIELD || fund == POINTER while (fund == FIELD || fund == POINTER
|| fund == ARRAY || fund == FUNCTION) { || fund == ARRAY || fund == FUNCTION) {
@ -189,17 +190,16 @@ struct idf **idpp;
} }
declare_protos(dc) void declare_protos(struct declarator *dc)
register struct declarator *dc;
{ {
/* At this points we know that the idf's in protolist are formal /* 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. parameters. So it's time to declare them at level L_FORMAL2.
*/ */
struct stack_level *stl = stack_level_of(L_FORMAL1); struct stack_level *stl = stack_level_of(L_FORMAL1);
register struct decl_unary *du; struct decl_unary *du;
register struct type *type; struct type *type;
register struct proto *pl; struct proto *pl;
register struct def *def; struct def *def;
#ifdef DEBUG #ifdef DEBUG
if (options['t']) if (options['t'])
@ -265,8 +265,7 @@ declare_protos(dc)
} }
update_proto(tp, otp) void update_proto(struct type *tp, struct type *otp)
register struct type *tp, *otp;
{ {
/* This routine performs the proto type updates. /* This routine performs the proto type updates.
Consider the following code: Consider the following code:
@ -279,7 +278,7 @@ update_proto(tp, otp)
This routine will silently update all lists, This routine will silently update all lists,
and removes the redundant occupied space. and removes the redundant occupied space.
*/ */
register struct proto *pl, *opl; struct proto *pl, *opl;
if (tp == otp) return; if (tp == otp) return;
if (!tp || !otp) return; if (!tp || !otp) return;
@ -316,12 +315,11 @@ update_proto(tp, otp)
/* struct/union and enum tags can be declared inside prototypes /* struct/union and enum tags can be declared inside prototypes
* remove them from the symbol-table * remove them from the symbol-table
*/ */
remove_proto_tag(tp) void remove_proto_tag(struct type *tp)
struct type *tp;
{ {
register struct idf *ident; struct idf *ident;
register struct tag *tgp, **tgpp; struct tag *tgp, **tgpp;
register int fund = tp->tp_fund; int fund = tp->tp_fund;
while (fund == FIELD || fund == POINTER while (fund == FIELD || fund == POINTER
|| fund == ARRAY || fund == FUNCTION) { || fund == ARRAY || fund == FUNCTION) {
@ -355,13 +353,12 @@ struct type *tp;
free_tag(tgp); free_tag(tgp);
} }
remove_proto_idfs(pl) void remove_proto_idfs(struct proto *pl)
register struct proto *pl;
{ {
/* Remove all the identifier definitions from the /* Remove all the identifier definitions from the
prototype list. prototype list.
*/ */
register struct def *def; struct def *def;
while (pl) { while (pl) {
if (pl->pl_idf) { if (pl->pl_idf) {
@ -384,8 +381,7 @@ remove_proto_idfs(pl)
} }
} }
call_proto(expp) void call_proto(struct expr **expp)
register struct expr **expp;
{ {
/* If the function specified by (*expp)->OP_LEFT has a prototype, /* If the function specified by (*expp)->OP_LEFT has a prototype,
the parameters are converted according the rules specified in the parameters are converted according the rules specified in
@ -394,13 +390,13 @@ call_proto(expp)
under ellipsis clause the old parameters conversion stuff under ellipsis clause the old parameters conversion stuff
applies. applies.
*/ */
register struct expr *left = (*expp)->OP_LEFT; struct expr *left = (*expp)->OP_LEFT;
register struct expr *right = (*expp)->OP_RIGHT; struct expr *right = (*expp)->OP_RIGHT;
register struct proto *pl = NO_PROTO; struct proto *pl = NO_PROTO;
static struct proto ellipsis = { 0, 0, 0, PL_ELLIPSIS }; static struct proto ellipsis = { 0, 0, 0, PL_ELLIPSIS };
if (left != NILEXPR) { /* in case of an error */ if (left != NILEXPR) { /* in case of an error */
register struct type *tp = left->ex_type; struct type *tp = left->ex_type;
while (tp && tp->tp_fund != FUNCTION && tp != error_type) while (tp && tp->tp_fund != FUNCTION && tp != error_type)
tp = tp->tp_up; tp = tp->tp_up;
@ -409,8 +405,8 @@ call_proto(expp)
} }
if (right != NILEXPR) { /* function call with parameters */ if (right != NILEXPR) { /* function call with parameters */
register struct expr **ep = &((*expp)->OP_RIGHT); struct expr **ep = &((*expp)->OP_RIGHT);
register int ecnt = 0, pcnt = 0; int ecnt = 0, pcnt = 0;
struct expr **estack[NPARAMS]; struct expr **estack[NPARAMS];
struct proto *pstack[NPARAMS]; struct proto *pstack[NPARAMS];
@ -449,7 +445,7 @@ call_proto(expp)
pstack[0] = &ellipsis; pstack[0] = &ellipsis;
} }
for (ecnt; ecnt >= 0; ecnt--) { for (; ecnt >= 0; ecnt--) {
/* Only the parameters specified in the prototype /* Only the parameters specified in the prototype
are checked and converted. The parameters that are checked and converted. The parameters that
fall under the ellipsis clause are neither fall under the ellipsis clause are neither

View File

@ -0,0 +1,19 @@
/*
* 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 */

View File

@ -17,26 +17,28 @@
#include "nparams.h" #include "nparams.h"
#include "idfsize.h" #include "idfsize.h"
#include "numsize.h" #include "numsize.h"
#include "arith.h"
#include <alloc.h> #include <alloc.h>
#include "idf.h" #include "idf.h"
#include "idf_loc.h"
#include "input.h" #include "input.h"
#include "macro.h" #include "macro.h"
#include "arith.h"
#include "LLlex.h" #include "LLlex.h"
#include "class.h" #include "class.h"
#include "assert.h" #include "assert.h"
#include "static.h" #include "static.h"
#include "macbuf.h" #include "macbuf.h"
#include "replace.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; extern int InputLevel;
struct repl *ReplaceList; /* list of currently active macros */ struct repl *ReplaceList; /* list of currently active macros */
extern char *strcat(), *strcpy();
int int replace(struct idf *idf)
replace(idf)
register struct idf *idf;
{ {
/* replace is called by the lexical analyzer to perform /* replace is called by the lexical analyzer to perform
macro replacement. The routine actualy functions as a macro replacement. The routine actualy functions as a
@ -62,15 +64,14 @@ replace(idf)
return 1; return 1;
} }
unstackrepl() void unstackrepl()
{ {
Unstacked++; Unstacked++;
} }
freeargs(args) void freeargs(struct args *args)
struct args *args;
{ {
register int i; int i;
/* We must don't know how many parameters were specified, so be /* We must don't know how many parameters were specified, so be
* prepared to free all NPARAMS parameters. * prepared to free all NPARAMS parameters.
@ -86,9 +87,9 @@ freeargs(args)
free_args(args); free_args(args);
} }
EnableMacros() void EnableMacros()
{ {
register struct repl *r = ReplaceList, *prev = 0; struct repl *r = ReplaceList, *prev = 0;
ASSERT(Unstacked > 0); ASSERT(Unstacked > 0);
while(r) { while(r) {
@ -108,9 +109,7 @@ EnableMacros()
Unstacked = 0; Unstacked = 0;
} }
expand_macro(repl, idf) int expand_macro(struct repl *repl, struct idf *idf)
register struct repl *repl;
register struct idf *idf;
{ {
/* expand_macro() does the actual macro replacement. /* expand_macro() does the actual macro replacement.
"idf" is a description of the identifier which "idf" is a description of the identifier which
@ -129,9 +128,9 @@ expand_macro(repl, idf)
on a single, unexpanded identifier, which may be surrounded on a single, unexpanded identifier, which may be surrounded
by parenthesis. The function expand_defined() handles this. by parenthesis. The function expand_defined() handles this.
*/ */
register struct macro *mac = idf->id_macro; struct macro *mac = idf->id_macro;
struct args *args = repl->r_args; struct args *args = repl->r_args;
register int ch; int ch;
if (mac->mc_nps != -1) { /* with parameter list */ if (mac->mc_nps != -1) { /* with parameter list */
if (mac->mc_flag & FUNC) { if (mac->mc_flag & FUNC) {
@ -180,10 +179,9 @@ expand_macro(repl, idf)
return 1; return 1;
} }
expand_defined(repl) void expand_defined(struct repl *repl)
register struct repl *repl;
{ {
register int ch = GetChar(); int ch = GetChar();
struct idf *id; struct idf *id;
int parens = 0; int parens = 0;
@ -212,25 +210,22 @@ expand_defined(repl)
add2repl(repl, ' '); add2repl(repl, ' ');
} }
newarg(args) void newarg(struct args *args)
struct args *args;
{ {
args->a_expptr = args->a_expbuf = Malloc(args->a_expsize = ARGBUF); args->a_expptr = args->a_expbuf = Malloc(args->a_expsize = ARGBUF);
args->a_rawptr = args->a_rawbuf = Malloc(args->a_rawsize = ARGBUF); args->a_rawptr = args->a_rawbuf = Malloc(args->a_rawsize = ARGBUF);
} }
getactuals(repl, idf) void getactuals(struct repl *repl, struct idf *idf)
struct repl *repl;
register struct idf *idf;
{ {
/* Get the actual parameters from the input stream. /* Get the actual parameters from the input stream.
The hard part is done by actual(), only comma's and The hard part is done by actual(), only comma's and
other syntactic trivialities are checked here. other syntactic trivialities are checked here.
*/ */
register struct args *args = repl->r_args; struct args *args = repl->r_args;
register int nps = idf->id_macro->mc_nps; int nps = idf->id_macro->mc_nps;
register int argcnt; int argcnt;
register int ch; int ch;
argcnt = 0; argcnt = 0;
newarg(args); newarg(args);
@ -262,12 +257,11 @@ getactuals(repl, idf)
lexerror("too many macro arguments"); lexerror("too many macro arguments");
} }
saveraw(repl) void saveraw(struct repl *repl)
struct repl *repl;
{ {
register struct repl *nrepl = ReplaceList; struct repl *nrepl = ReplaceList;
register struct args *ap = nrepl->r_args; struct args *ap = nrepl->r_args;
register char *p; char *p;
/* stash identifier name */ /* stash identifier name */
for (p = nrepl->r_idf->id_text; *p != '\0'; p++) for (p = nrepl->r_idf->id_text; *p != '\0'; p++)
@ -288,7 +282,7 @@ struct repl *repl;
*/ */
if (ap->a_rawvec[0]) { if (ap->a_rawvec[0]) {
/* stash arguments */ /* stash arguments */
register int i; int i;
for (i = 0; ap->a_rawvec[i] != (char *)0; i++) { for (i = 0; ap->a_rawvec[i] != (char *)0; i++) {
if (i == 0) stash(repl, '(', -1); if (i == 0) stash(repl, '(', -1);
@ -300,16 +294,14 @@ struct repl *repl;
} }
} }
int int actual(struct repl *repl)
actual(repl)
struct repl *repl;
{ {
/* This routine deals with the scanning of an actual parameter. /* This routine deals with the scanning of an actual parameter.
It keeps in account the opening and closing brackets, It keeps in account the opening and closing brackets,
preprocessor numbers, strings and character constants. preprocessor numbers, strings and character constants.
*/ */
register int ch = 0; int ch = 0;
register int level = 0, nostashraw = 0; int level = 0, nostashraw = 0;
int lastch; int lastch;
static int Unstacked_missed; static int Unstacked_missed;
@ -335,9 +327,9 @@ actual(repl)
token is a macro, it is expanded first. token is a macro, it is expanded first.
*/ */
char buf[(IDFSIZE > NUMSIZE ? IDFSIZE : NUMSIZE) + 1]; char buf[(IDFSIZE > NUMSIZE ? IDFSIZE : NUMSIZE) + 1];
register char *p = buf; char *p = buf;
register struct idf *idef; struct idf *idef;
register int pos = -1; int pos = -1;
extern int idfsize; extern int idfsize;
int NoExpandMacro; int NoExpandMacro;
@ -478,7 +470,7 @@ a_new_line: ch = GetChar();
/* Strings are considered as ONE token, thus no /* Strings are considered as ONE token, thus no
replacement within strings. replacement within strings.
*/ */
register int match = ch; int match = ch;
stash(repl, ch, !nostashraw); stash(repl, ch, !nostashraw);
while ((ch = GetChar()) != EOI) { while ((ch = GetChar()) != EOI) {
@ -507,15 +499,14 @@ a_new_line: ch = GetChar();
} }
} }
macro_func(idef) void macro_func(struct idf *idef)
register struct idf *idef;
{ {
/* macro_func() performs the special actions needed with some /* macro_func() performs the special actions needed with some
macros. These macros are __FILE__ and __LINE__ which macros. These macros are __FILE__ and __LINE__ which
replacement texts must be evaluated at the time they are replacement texts must be evaluated at the time they are
used. used.
*/ */
register struct macro *mac = idef->id_macro; struct macro *mac = idef->id_macro;
static char FilNamBuf[PATHLENGTH]; static char FilNamBuf[PATHLENGTH];
char *long2str(); char *long2str();
@ -537,10 +528,7 @@ macro_func(idef)
} }
} }
macro2buffer(repl, idf, args) void macro2buffer(struct repl *repl, struct idf *idf, struct args *args)
register struct repl *repl;
register struct idf *idf;
register struct args *args;
{ {
/* macro2buffer expands the replacement list and places the /* macro2buffer expands the replacement list and places the
result onto the replacement buffer. It deals with the # result onto the replacement buffer. It deals with the #
@ -568,15 +556,14 @@ macro2buffer(repl, idf, args)
linear fashion. This is VERY expensive, something linear fashion. This is VERY expensive, something
smarter should be done (but even a DFA is O(|s|)). smarter should be done (but even a DFA is O(|s|)).
*/ */
register char *ptr = idf->id_macro->mc_text; char *ptr = idf->id_macro->mc_text;
int err = 0; int err = 0;
int func = idf->id_macro->mc_nps != -1; int func = idf->id_macro->mc_nps != -1;
char *stringify();
ASSERT(ptr[idf->id_macro->mc_length] == '\0'); ASSERT(ptr[idf->id_macro->mc_length] == '\0');
while (*ptr) { while (*ptr) {
if (*ptr == '\'' || *ptr == '"') { if (*ptr == '\'' || *ptr == '"') {
register int delim = *ptr; int delim = *ptr;
do { do {
add2repl(repl, *ptr); add2repl(repl, *ptr);
@ -591,14 +578,14 @@ macro2buffer(repl, idf, args)
add2repl(repl, *ptr++); add2repl(repl, *ptr++);
} else if (*ptr == '#' && (func || *(ptr+1) == '#')) { } else if (*ptr == '#' && (func || *(ptr+1) == '#')) {
if (*++ptr == '#') { if (*++ptr == '#') {
register int tmpindex; int tmpindex;
/* ## - paste operator */ /* ## - paste operator */
ptr++; ptr++;
/* trim the actual replacement list */ /* trim the actual replacement list */
--repl->r_ptr; --repl->r_ptr;
while (repl->r_ptr >= repl->r_text while (repl->r_ptr >= repl->r_text
&& is_wsp(*repl->r_ptr)) && is_wsp(*(unsigned char *)repl->r_ptr))
--repl->r_ptr; --repl->r_ptr;
/* ## occurred at the beginning of the replacement list. /* ## occurred at the beginning of the replacement list.
@ -617,25 +604,25 @@ macro2buffer(repl, idf, args)
/* tmpindex can be 0 */ /* tmpindex can be 0 */
/* skip space in macro replacement list */ /* skip space in macro replacement list */
while ((*ptr & FORMALP) == 0 && is_wsp(*ptr)) while ((*ptr & FORMALP) == 0 && is_wsp(*(unsigned char *)ptr))
ptr++; ptr++;
/* ## occurred at the end of the replacement list. /* ## occurred at the end of the replacement list.
*/ */
if (*ptr & FORMALP) { if (*ptr & FORMALP) {
register int n = *ptr++ & 0177; int n = *ptr++ & 0177;
register char *p; char *p;
ASSERT(n > 0); ASSERT(n > 0);
p = args->a_rawvec[n-1]; p = args->a_rawvec[n-1];
if (p) { /* else macro argument missing */ if (p) { /* else macro argument missing */
while (is_wsp(*p)) p++; while (is_wsp(*(unsigned char *)p)) p++;
if (*p == NOEXPM) p++; if (*p == NOEXPM) p++;
while (*p) while (*p)
add2repl(repl, *p++); add2repl(repl, *p++);
} }
while (tmpindex > 0 while (tmpindex > 0
&& in_idf(repl->r_text[tmpindex])) && in_idf((unsigned char)repl->r_text[tmpindex]))
tmpindex--; tmpindex--;
if (tmpindex >= 0 if (tmpindex >= 0
&& repl->r_text[tmpindex] == NOEXPM) && repl->r_text[tmpindex] == NOEXPM)
@ -644,10 +631,10 @@ macro2buffer(repl, idf, args)
err = 1; err = 1;
break; break;
} else { } else {
if (in_idf(*ptr)) { if (in_idf(*(unsigned char *)ptr)) {
tmpindex--; tmpindex--;
while (tmpindex > 0 while (tmpindex > 0
&& in_idf(repl->r_text[tmpindex])) && in_idf((unsigned char)repl->r_text[tmpindex]))
tmpindex--; tmpindex--;
if (tmpindex >= 0 if (tmpindex >= 0
&& repl->r_text[tmpindex] == NOEXPM) && repl->r_text[tmpindex] == NOEXPM)
@ -659,8 +646,8 @@ macro2buffer(repl, idf, args)
} }
} else if (*ptr & FORMALP) { } else if (*ptr & FORMALP) {
/* insert actual parameter */ /* insert actual parameter */
register int n = *ptr++ & 0177; int n = *ptr++ & 0177;
register char *p, *q; char *p, *q;
ASSERT(n > 0); ASSERT(n > 0);
@ -669,7 +656,7 @@ macro2buffer(repl, idf, args)
argument buffer instead of the expanded argument buffer instead of the expanded
one. one.
*/ */
for (p = ptr; (*p & FORMALP) == 0 && is_wsp(*p); p++) for (p = ptr; (*p & FORMALP) == 0 && is_wsp(*(unsigned char *)p); p++)
/* EMPTY */; /* EMPTY */;
if (*p == '#' && p[1] == '#') if (*p == '#' && p[1] == '#')
q = args->a_rawvec[n-1]; q = args->a_rawvec[n-1];
@ -690,11 +677,7 @@ macro2buffer(repl, idf, args)
lexerror("illegal use of the ## operator"); lexerror("illegal use of the ## operator");
} }
char * char *stringify(struct repl *repl, char *ptr, struct args *args)
stringify(repl, ptr, args)
register struct repl *repl;
register char *ptr;
register struct args *args;
{ {
/* If a parameter is immediately preceded by a # token /* If a parameter is immediately preceded by a # token
both are replaced by a single string literal that both are replaced by a single string literal that
@ -708,23 +691,23 @@ stringify(repl, ptr, args)
as appropriate. We only escape backslashes if they as appropriate. We only escape backslashes if they
occure within string tokens. occure within string tokens.
*/ */
register int space = 1; /* skip leading spaces */ int space = 1; /* skip leading spaces */
register int delim = 0; /* string or character constant delim */ int delim = 0; /* string or character constant delim */
register int backslash = 0; /* last character was a \ */ int backslash = 0; /* last character was a \ */
/* skip spaces macro replacement list */ /* skip spaces macro replacement list */
while ((*ptr & FORMALP) == 0 && is_wsp(*ptr)) while ((*ptr & FORMALP) == 0 && is_wsp(*(unsigned char *)ptr))
ptr++; ptr++;
if (*ptr & FORMALP) { if (*ptr & FORMALP) {
register int n = *ptr++ & 0177; int n = *ptr++ & 0177;
register char *p; char *p;
ASSERT(n != 0); ASSERT(n != 0);
p = args->a_rawvec[n-1]; p = args->a_rawvec[n-1];
add2repl(repl, '"'); add2repl(repl, '"');
while (*p) { while (*p) {
if (is_wsp(*p)) { if (is_wsp(*(unsigned char *)p)) {
if (!space) { if (!space) {
space = 1; space = 1;
add2repl(repl, ' '); add2repl(repl, ' ');
@ -746,7 +729,7 @@ stringify(repl, ptr, args)
} }
/* trim spaces in the replacement list */ /* trim spaces in the replacement list */
for (--repl->r_ptr; is_wsp(*repl->r_ptr); repl->r_ptr--) for (--repl->r_ptr; is_wsp(*(unsigned char *)repl->r_ptr); repl->r_ptr--)
/* EMPTY */; /* EMPTY */;
++repl->r_ptr; /* oops, one to far */ ++repl->r_ptr; /* oops, one to far */
add2repl(repl, '"'); add2repl(repl, '"');
@ -757,11 +740,9 @@ stringify(repl, ptr, args)
/* The following routine is also called from domacro.c. /* The following routine is also called from domacro.c.
*/ */
add2repl(repl, ch) void add2repl(struct repl *repl, int ch)
register struct repl *repl;
int ch;
{ {
register int index = repl->r_ptr - repl->r_text; int index = repl->r_ptr - repl->r_text;
ASSERT(index < repl->r_size); ASSERT(index < repl->r_size);
if (index + 2 >= repl->r_size) { if (index + 2 >= repl->r_size) {
@ -776,15 +757,12 @@ add2repl(repl, ch)
* buffer. If the variable is zero, we must only stash into the expanded * buffer. If the variable is zero, we must only stash into the expanded
* buffer. Otherwise, we must use both buffers. * buffer. Otherwise, we must use both buffers.
*/ */
stash(repl, ch, stashraw) void stash(struct repl *repl ,int ch, int stashraw)
struct repl *repl;
register int ch;
int stashraw;
{ {
/* Stash characters into the macro expansion buffer. /* Stash characters into the macro expansion buffer.
*/ */
register struct args *args = repl->r_args; struct args *args = repl->r_args;
register int index = args->a_expptr - args->a_expbuf; int index = args->a_expptr - args->a_expbuf;
if (stashraw >= 0) { if (stashraw >= 0) {
ASSERT(index < args->a_expsize); ASSERT(index < args->a_expsize);

View File

@ -0,0 +1,29 @@
/*
* 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 */

View File

@ -10,18 +10,18 @@
#include "LLlex.h" #include "LLlex.h"
#include "class.h" #include "class.h"
#include "input.h" #include "input.h"
#include "domacro.h"
#include "error.h"
#ifndef NOPP #ifndef NOPP
extern int InputLevel; extern int InputLevel;
int int skipspaces(int ch, int skipnl)
skipspaces(ch, skipnl)
register int ch;
{ {
/* skipspaces() skips any white space and returns the first /* skipspaces() skips any white space and returns the first
non-space character. non-space character.
*/ */
register int nlseen = 0; int nlseen = 0;
for (;;) { for (;;) {
while (class(ch) == STSKIP) while (class(ch) == STSKIP)
@ -59,12 +59,12 @@ skipspaces(ch, skipnl)
} }
#endif /* NOPP */ #endif /* NOPP */
SkipToNewLine() int SkipToNewLine()
{ {
register int ch; int ch;
register int garbage = 0; int garbage = 0;
#ifndef NOPP #ifndef NOPP
register int delim = 0; int delim = 0;
#endif #endif
while ((ch = GetChar()) != '\n') { while ((ch = GetChar()) != '\n') {

View File

@ -0,0 +1,13 @@
/*
* 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 */

View File

@ -41,8 +41,7 @@ static struct db_str {
char *currpos; char *currpos;
} db_str; } db_str;
static static void create_db_str()
create_db_str()
{ {
if (! db_str.base) { if (! db_str.base) {
db_str.base = Malloc(INCR_SIZE); db_str.base = Malloc(INCR_SIZE);
@ -51,9 +50,7 @@ create_db_str()
db_str.currpos = db_str.base; db_str.currpos = db_str.base;
} }
static static void addc_db_str(int c)
addc_db_str(c)
int c;
{ {
int df = db_str.currpos - db_str.base; int df = db_str.currpos - db_str.base;
if (df >= db_str.sz-1) { if (df >= db_str.sz-1) {
@ -65,16 +62,12 @@ addc_db_str(c)
*db_str.currpos = '\0'; *db_str.currpos = '\0';
} }
static static void adds_db_str(char *s)
adds_db_str(s)
char *s;
{ {
while (*s) addc_db_str(*s++); while (*s) addc_db_str(*s++);
} }
static static void stb_type(struct type *tp)
stb_type(tp)
register struct type *tp;
{ {
char buf[128]; char buf[128];
static int stb_count; static int stb_count;
@ -149,10 +142,10 @@ stb_type(tp)
} }
addc_db_str('e'); addc_db_str('e');
{ {
register struct stack_entry *se = local_level->sl_entry; struct stack_entry *se = local_level->sl_entry;
while (se) { while (se) {
register struct def *edef = se->se_idf->id_def; struct def *edef = se->se_idf->id_def;
while (edef) { while (edef) {
if (edef->df_type == tp && if (edef->df_type == tp &&
edef->df_sc == ENUM) { edef->df_sc == ENUM) {
@ -183,7 +176,7 @@ stb_type(tp)
tp->tp_fund == STRUCT ? 's' : 'u', tp->tp_fund == STRUCT ? 's' : 'u',
tp->tp_size)); tp->tp_size));
{ {
register struct sdef *sdef = tp->tp_sdef; struct sdef *sdef = tp->tp_sdef;
while (sdef) { while (sdef) {
adds_db_str(sdef->sd_idf->id_text); adds_db_str(sdef->sd_idf->id_text);
@ -213,9 +206,7 @@ stb_type(tp)
} }
} }
stb_tag(tg, str) void stb_tag(struct tag *tg, char *str)
register struct tag *tg;
char *str;
{ {
create_db_str(); create_db_str();
adds_db_str(str); adds_db_str(str);
@ -230,9 +221,7 @@ stb_tag(tg, str)
(arith) 0); (arith) 0);
} }
stb_typedef(tp, str) void stb_typedef(struct type *tp, char *str)
register struct type *tp;
char *str;
{ {
create_db_str(); create_db_str();
adds_db_str(str); adds_db_str(str);
@ -247,11 +236,9 @@ stb_typedef(tp, str)
(arith) 0); (arith) 0);
} }
stb_string(df, kind, str) void stb_string(struct def *df, int kind, char *str)
register struct def *df;
char *str;
{ {
register struct type *tp = df->df_type; struct type *tp = df->df_type;
create_db_str(); create_db_str();
adds_db_str(str); adds_db_str(str);

View File

@ -0,0 +1,14 @@
/*
* 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 */

View File

@ -18,12 +18,18 @@
#include "Lpars.h" #include "Lpars.h"
#include "arith.h" #include "arith.h"
#include "stack.h" #include "stack.h"
#include "stack_loc.h"
#include "type.h" #include "type.h"
#include "idf.h" #include "idf.h"
#include "idf_loc.h"
#include "def.h" #include "def.h"
#include "struct.h" #include "struct.h"
#include "level.h" #include "level.h"
#include "mes.h" #include "mes.h"
#include "code_c.h"
#include "error.h"
#include "label.h"
#include "util_loc.h"
/* #include <em_reg.h> */ /* #include <em_reg.h> */
@ -43,11 +49,12 @@ struct stack_level *local_level = &UniversalLevel;
int level; /* Always equal to local_level->sl_level. */ int level; /* Always equal to local_level->sl_level. */
stack_level() { void stack_level()
{
/* A new level is added on top of the identifier stack. /* A new level is added on top of the identifier stack.
*/ */
register struct stack_level *stl = new_stack_level(); struct stack_level *stl = new_stack_level();
register struct stack_level *loclev = local_level; struct stack_level *loclev = local_level;
loclev->sl_next = stl; loclev->sl_next = stl;
stl->sl_previous = loclev; stl->sl_previous = loclev;
@ -59,14 +66,12 @@ stack_level() {
#endif /* LINT */ #endif /* LINT */
} }
stack_idf(idf, stl) void stack_idf(struct idf *idf, struct stack_level *stl)
struct idf *idf;
register struct stack_level *stl;
{ {
/* The identifier idf is inserted in the stack on level stl, /* The identifier idf is inserted in the stack on level stl,
but only if it is not already present at this level. but only if it is not already present at this level.
*/ */
register struct stack_entry *se; struct stack_entry *se;
se = stl->sl_entry; se = stl->sl_entry;
while (se) { while (se) {
@ -82,14 +87,13 @@ stack_idf(idf, stl)
stl->sl_entry = se; stl->sl_entry = se;
} }
struct stack_level * struct stack_level *stack_level_of(int lvl)
stack_level_of(lvl)
{ {
/* The stack_level corresponding to level lvl is returned. /* The stack_level corresponding to level lvl is returned.
The stack should probably be an array, to be extended with The stack should probably be an array, to be extended with
realloc where needed. realloc where needed.
*/ */
register struct stack_level *stl; struct stack_level *stl;
if (lvl == level) if (lvl == level)
return local_level; return local_level;
@ -101,7 +105,7 @@ stack_level_of(lvl)
return stl; return stl;
} }
unstack_level() void unstack_level()
{ {
/* The top level of the identifier stack is removed. /* The top level of the identifier stack is removed.
*/ */
@ -120,11 +124,11 @@ unstack_level()
necessary. Optimists may optimize it afterwards. necessary. Optimists may optimize it afterwards.
*/ */
while (local_level->sl_entry) { while (local_level->sl_entry) {
register struct stack_entry *se = local_level->sl_entry; struct stack_entry *se = local_level->sl_entry;
register struct idf *idf = se->se_idf; struct idf *idf = se->se_idf;
register struct def *def; struct def *def;
register struct sdef *sdef; struct sdef *sdef;
register struct tag *tag; struct tag *tag;
/* unlink it from the local stack level */ /* unlink it from the local stack level */
local_level->sl_entry = se->next; local_level->sl_entry = se->next;
@ -175,7 +179,7 @@ unstack_level()
#endif /* DEBUG */ #endif /* DEBUG */
} }
unstack_world() void unstack_world()
{ {
/* The global level of identifiers is scanned, and final /* The global level of identifiers is scanned, and final
decisions are taken about such issues as decisions are taken about such issues as
@ -184,7 +188,7 @@ unstack_world()
have already been encoded while the uninitialised ones have already been encoded while the uninitialised ones
are not and have to be encoded at this moment. are not and have to be encoded at this moment.
*/ */
register struct stack_entry *se = local_level->sl_entry; struct stack_entry *se = local_level->sl_entry;
#ifdef LINT #ifdef LINT
lint_end_global(local_level); lint_end_global(local_level);
@ -195,8 +199,8 @@ unstack_world()
#endif /* GEN_NM_LIST */ #endif /* GEN_NM_LIST */
while (se) { while (se) {
register struct idf *idf = se->se_idf; struct idf *idf = se->se_idf;
register struct def *def = idf->id_def; struct def *def = idf->id_def;
if (!def) { if (!def) {
/* global selectors, etc. */ /* global selectors, etc. */
@ -264,14 +268,13 @@ unstack_world()
extern char *nmlist; /* BAH! -- main.c */ extern char *nmlist; /* BAH! -- main.c */
static File *nfp = 0; static File *nfp = 0;
open_name_list() void open_name_list()
{ {
if (nmlist && sys_open(nmlist, OP_WRITE, &nfp) == 0) if (nmlist && sys_open(nmlist, OP_WRITE, &nfp) == 0)
fatal("cannot create namelist %s", nmlist); fatal("cannot create namelist %s", nmlist);
} }
namelist(nm) void namelist(char *nm)
char *nm;
{ {
if (nmlist) { if (nmlist) {
sys_write(nfp, nm, strlen(nm)); sys_write(nfp, nm, strlen(nm));

View File

@ -4,6 +4,8 @@
*/ */
/* $Id$ */ /* $Id$ */
/* IDENTIFIER STACK DEFINITIONS */ /* 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 identifier stack is implemented as a stack of sets.
The stack is implemented by a doubly linked list, The stack is implemented by a doubly linked list,
@ -32,3 +34,5 @@ struct stack_entry {
extern struct stack_level *local_level; extern struct stack_level *local_level;
extern struct stack_level *stack_level_of(); extern struct stack_level *stack_level_of();
extern int level; extern int level;
#endif /* LANG_CEM_CEMCOM_ANSI_STACK_STR */

View File

@ -0,0 +1,16 @@
/*
* 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 */

View File

@ -22,12 +22,19 @@
#include "arith.h" #include "arith.h"
#include "LLlex.h" #include "LLlex.h"
#include "type.h" #include "type.h"
#include "type_loc.h"
#include "idf.h" #include "idf.h"
#include "idf_loc.h"
#include "label.h" #include "label.h"
#include "expr.h" #include "expr.h"
#include "expr_loc.h"
#include "code.h" #include "code.h"
#include "stack.h" #include "stack.h"
#include "stack_loc.h"
#include "def.h" #include "def.h"
#include "code_c.h"
#include "switch_loc.h"
#ifdef DBSYMTAB #ifdef DBSYMTAB
#include <stb.h> #include <stb.h>
#endif /* DBSYMTAB */ #endif /* DBSYMTAB */

View File

@ -11,11 +11,14 @@
#include <alloc.h> #include <alloc.h>
#include "arith.h" #include "arith.h"
#include "stack.h" #include "stack.h"
#include "stack_loc.h"
#include "idf.h" #include "idf.h"
#include "idf_loc.h"
#include "def.h" #include "def.h"
#include "type.h" #include "type.h"
#include "proto.h" #include "proto.h"
#include "struct.h" #include "struct.h"
#include "struct_loc.h"
#include "field.h" #include "field.h"
#include "LLlex.h" #include "LLlex.h"
#include "Lpars.h" #include "Lpars.h"
@ -23,6 +26,10 @@
#include "level.h" #include "level.h"
#include "assert.h" #include "assert.h"
#include "sizes.h" #include "sizes.h"
#include "error.h"
#include "ch3.h"
#include <symbol2str.h>
/* Type of previous selector declared with a field width specified, /* 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. if any. If a selector is declared with no field with it is set to 0.
@ -30,8 +37,6 @@
static field_busy = 0; static field_busy = 0;
extern char options[]; extern char options[];
char *symbol2str();
int lcm();
/* The semantics of the identification of structure/union tags is /* The semantics of the identification of structure/union tags is
obscure. Some highly regarded compilers are found out to accept, obscure. Some highly regarded compilers are found out to accept,
@ -53,14 +58,16 @@ int lcm();
If below struct is mentioned, union is implied (and sometimes enum If below struct is mentioned, union is implied (and sometimes enum
as well). as well).
*/ */
/*
add_sel(stp, tp, idf, sdefpp, szp, fd) /* this is horrible */ struct type *stp; type of the structure
register struct type *stp; /* type of the structure */ struct type *tp; type of the selector
struct type *tp; /* type of the selector */ struct idf *idf; idf of the selector
register struct idf *idf; /* idf of the selector */ struct sdef ***sdefpp; address of hook to selector definition
struct sdef ***sdefpp; /* address of hook to selector definition */ arith *szp; pointer to struct size upto here
arith *szp; /* pointer to struct size upto here */
struct field *fd; 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 /* The selector idf with type tp is added to two chains: the
selector identification chain starting at idf->id_sdef, selector identification chain starting at idf->id_sdef,
@ -75,7 +82,7 @@ add_sel(stp, tp, idf, sdefpp, szp, fd) /* this is horrible */
struct tag *tg = stp->tp_idf->id_tag; /* or union */ struct tag *tg = stp->tp_idf->id_tag; /* or union */
struct sdef *sdef = idf->id_sdef; struct sdef *sdef = idf->id_sdef;
register struct sdef *newsdef; struct sdef *newsdef;
int lvl = tg->tg_level; int lvl = tg->tg_level;
if (stp->tp_fund == STRUCT) { if (stp->tp_fund == STRUCT) {
@ -149,15 +156,13 @@ add_sel(stp, tp, idf, sdefpp, szp, fd) /* this is horrible */
stp->tp_align = lcm(stp->tp_align, tp->tp_align); stp->tp_align = lcm(stp->tp_align, tp->tp_align);
} }
} }
/* stp: the type of the struct */
check_selector(idf, stp) void check_selector(struct idf *idf, struct type *stp)
register struct idf *idf;
struct type *stp; /* the type of the struct */
{ {
/* checks if idf occurs already as a selector in /* checks if idf occurs already as a selector in
struct or union *stp. struct or union *stp.
*/ */
register struct sdef *sdef = stp->tp_sdef; struct sdef *sdef = stp->tp_sdef;
while (sdef) { while (sdef) {
if (sdef->sd_idf == idf) if (sdef->sd_idf == idf)
@ -166,9 +171,7 @@ check_selector(idf, stp)
} }
} }
declare_struct(fund, idf, tpp) void declare_struct(int fund, struct idf *idf, struct type **tpp)
register struct idf *idf;
struct type **tpp;
{ {
/* A struct, union or enum (depending on fund) with tag (!) /* A struct, union or enum (depending on fund) with tag (!)
idf is declared, and its type (incomplete as it may be) is idf is declared, and its type (incomplete as it may be) is
@ -176,8 +179,8 @@ declare_struct(fund, idf, tpp)
The idf may be missing (i.e. idf == 0), in which case an The idf may be missing (i.e. idf == 0), in which case an
anonymous struct etc. is defined. anonymous struct etc. is defined.
*/ */
register struct tag **tgp; struct tag **tgp;
register struct tag *tg; struct tag *tg;
if (*tpp) error("multiple types in declaration"); if (*tpp) error("multiple types in declaration");
@ -235,16 +238,14 @@ declare_struct(fund, idf, tpp)
} }
} }
apply_struct(fund, idf, tpp) void apply_struct(int fund, struct idf *idf, struct type **tpp)
register struct idf *idf;
struct type **tpp;
{ {
/* The occurrence of a struct, union or enum (depending on /* The occurrence of a struct, union or enum (depending on
fund) with tag idf is noted. It may or may not have been fund) with tag idf is noted. It may or may not have been
declared before. Its type (complete or incomplete) is declared before. Its type (complete or incomplete) is
returned in *tpp. returned in *tpp.
*/ */
register struct tag **tgp; struct tag **tgp;
tgp = &idf->id_tag; tgp = &idf->id_tag;
@ -261,10 +262,7 @@ apply_struct(fund, idf, tpp)
declare_struct(fund, idf, tpp); declare_struct(fund, idf, tpp);
} }
struct sdef * struct sdef *idf2sdef(struct idf *idf, struct type *tp)
idf2sdef(idf, tp)
register struct idf *idf;
struct type *tp;
{ {
/* The identifier idf is identified as a selector /* The identifier idf is identified as a selector
in the struct tp. in the struct tp.
@ -273,17 +271,17 @@ idf2sdef(idf, tp)
If this fails too, a selector of type error_type is If this fails too, a selector of type error_type is
created. created.
*/ */
register struct sdef **sdefp = &idf->id_sdef, *sdef; struct sdef **sdefp = &idf->id_sdef, *sdef;
/* Follow chain from idf, to meet tp. */ /* Follow chain from idf, to meet tp. */
while ((sdef = *sdefp)) { while ( (sdef = *sdefp) ) {
if (equal_type(sdef->sd_stype, tp, -999, 0)) /* ??? hack */ if (equal_type(sdef->sd_stype, tp, -999, 0)) /* ??? hack */
return sdef; return sdef;
sdefp = &(*sdefp)->next; sdefp = &(*sdefp)->next;
} }
/* Tp not met; take an identification. */ /* Tp not met; take an identification. */
if (sdef = idf->id_sdef) { if ( (sdef = idf->id_sdef) ) {
/* There is an identification */ /* There is an identification */
error("illegal use of selector %s", idf->id_text); error("illegal use of selector %s", idf->id_text);
return sdef; return sdef;
@ -299,9 +297,7 @@ idf2sdef(idf, tp)
} }
#if 0 #if 0
int int uniq_selector(struct sdef *idf_sdef)
uniq_selector(idf_sdef)
register struct sdef *idf_sdef;
{ {
/* Returns true if idf_sdef (which is guaranteed to exist) /* Returns true if idf_sdef (which is guaranteed to exist)
is unique for this level, i.e there is no other selector is unique for this level, i.e there is no other selector
@ -311,7 +307,7 @@ uniq_selector(idf_sdef)
case! case!
*/ */
register struct sdef *sdef = idf_sdef->next; struct sdef *sdef = idf_sdef->next;
while (sdef && sdef->sd_level == idf_sdef->sd_level) { while (sdef && sdef->sd_level == idf_sdef->sd_level) {
if ( sdef->sd_type != idf_sdef->sd_type if ( sdef->sd_type != idf_sdef->sd_type
@ -326,13 +322,15 @@ uniq_selector(idf_sdef)
#endif #endif
#ifndef NOBITFIELD #ifndef NOBITFIELD
arith
add_field(szp, fd, fdtpp, idf, stp) /*
arith *szp; /* size of struct upto here */ arith *szp; size of struct upto here
register struct field *fd; /* bitfield, containing width */ struct field *fd; bitfield, containing width
register struct type **fdtpp; /* type of selector */ struct type **fdtpp; type of selector
struct idf *idf; /* name of selector */ struct idf *idf; name of selector
register struct type *stp; /* current struct descriptor */ struct type *stp; current struct descripton
*/
arith add_field(arith *szp, struct field *fd, struct type **fdtpp, struct idf *idf, struct type *stp)
{ {
/* The address where this selector is put is returned. If the /* The address where this selector is put is returned. If the
selector with specified width does not fit in the word, or selector with specified width does not fit in the word, or
@ -441,20 +439,16 @@ add_field(szp, fd, fdtpp, idf, stp)
#endif /* NOBITFIELD */ #endif /* NOBITFIELD */
/* some utilities */ /* some utilities */
int int is_struct_or_union(int fund)
is_struct_or_union(fund)
register int fund;
{ {
return fund == STRUCT || fund == UNION; return fund == STRUCT || fund == UNION;
} }
/* Greatest Common Divisor /* Greatest Common Divisor
*/ */
int int gcd(int m, int n)
gcd(m, n)
register int m, n;
{ {
register int r; int r;
while (n) { while (n) {
r = m % n; r = m % n;
@ -466,9 +460,7 @@ gcd(m, n)
/* Least Common Multiple /* Least Common Multiple
*/ */
int int lcm(int m, int n)
lcm(m, n)
register int m, n;
{ {
return m * (n / gcd(m, n)); return m * (n / gcd(m, n));
} }

View File

@ -0,0 +1,20 @@
/*
* 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 */

View File

@ -26,13 +26,17 @@
#include "expr.h" #include "expr.h"
#include "type.h" #include "type.h"
#include "sizes.h" #include "sizes.h"
#include "code_c.h"
#include "eval.h"
#include "ch3.h"
#include <system.h>
#include "print.h"
extern char options[]; extern char options[];
int density = DENSITY; int density = DENSITY;
compact(nr, low, up) int compact(int nr, arith low, arith up)
arith low, up;
{ {
/* Careful! up - low might not fit in an arith. And then, /* Careful! up - low might not fit in an arith. And then,
the test "up-low < 0" might also not work to detect this the test "up-low < 0" might also not work to detect this
@ -52,15 +56,14 @@ static struct switch_hdr *switch_stack = 0;
For simplicity, we suppose int_size == word_size. For simplicity, we suppose int_size == word_size.
*/ */
code_startswitch(expp) void code_startswitch(struct expr **expp)
struct expr **expp;
{ {
/* Check the expression, stack a new case header and /* Check the expression, stack a new case header and
fill in the necessary fields. fill in the necessary fields.
*/ */
register label l_table = text_label(); label l_table = text_label();
register label l_break = text_label(); label l_break = text_label();
register struct switch_hdr *sh = new_switch_hdr(); struct switch_hdr *sh = new_switch_hdr();
int fund = any2arith(expp, SWITCH); int fund = any2arith(expp, SWITCH);
/* INT, LONG, FLOAT, DOUBLE or LNGDBL */ /* INT, LONG, FLOAT, DOUBLE or LNGDBL */
@ -88,13 +91,11 @@ code_startswitch(expp)
C_bra(l_table); /* goto start of switch_table */ C_bra(l_table); /* goto start of switch_table */
} }
extern char *long2str(); void code_endswitch()
code_endswitch()
{ {
register struct switch_hdr *sh = switch_stack; struct switch_hdr *sh = switch_stack;
register label tablabel; label tablabel;
register struct case_entry *ce; struct case_entry *ce;
arith size = sh->sh_type->tp_size; arith size = sh->sh_type->tp_size;
if (sh->sh_default == 0) /* no default occurred yet */ if (sh->sh_default == 0) /* no default occurred yet */
@ -120,7 +121,7 @@ code_endswitch()
C_rom_ilb(sh->sh_default); C_rom_ilb(sh->sh_default);
if (compact(sh->sh_nrofentries, sh->sh_lowerbd, sh->sh_upperbd)) { if (compact(sh->sh_nrofentries, sh->sh_lowerbd, sh->sh_upperbd)) {
/* CSA */ /* CSA */
register arith val; arith val;
C_rom_icon(long2str((long)sh->sh_lowerbd,10), size); C_rom_icon(long2str((long)sh->sh_lowerbd,10), size);
C_rom_icon(long2str((long)(sh->sh_upperbd - sh->sh_lowerbd),10), C_rom_icon(long2str((long)(sh->sh_upperbd - sh->sh_lowerbd),10),
@ -154,7 +155,7 @@ code_endswitch()
switch_stack = sh->next; /* unstack the switch descriptor */ switch_stack = sh->next; /* unstack the switch descriptor */
for (ce = sh->sh_entries; ce;) { /* free allocated switch structure */ for (ce = sh->sh_entries; ce;) { /* free allocated switch structure */
register struct case_entry *tmp = ce->next; struct case_entry *tmp = ce->next;
free_case_entry(ce); free_case_entry(ce);
ce = tmp; ce = tmp;
@ -163,12 +164,11 @@ code_endswitch()
unstack_stmt(); unstack_stmt();
} }
code_case(expr) void code_case(struct expr *expr)
struct expr *expr;
{ {
register arith val; arith val;
register struct case_entry *ce; struct case_entry *ce;
register struct switch_hdr *sh = switch_stack; struct switch_hdr *sh = switch_stack;
ASSERT(is_cp_cst(expr)); ASSERT(is_cp_cst(expr));
if (sh == 0) { if (sh == 0) {
@ -188,7 +188,7 @@ code_case(expr)
sh->sh_nrofentries = 1; sh->sh_nrofentries = 1;
} }
else { /* second etc. case entry; put ce into proper place */ else { /* second etc. case entry; put ce into proper place */
register struct case_entry *c1 = sh->sh_entries, *c2 = 0; struct case_entry *c1 = sh->sh_entries, *c2 = 0;
if (val < sh->sh_lowerbd) if (val < sh->sh_lowerbd)
sh->sh_lowerbd = val; sh->sh_lowerbd = val;
@ -231,9 +231,9 @@ code_case(expr)
} }
} }
code_default() void code_default()
{ {
register struct switch_hdr *sh = switch_stack; struct switch_hdr *sh = switch_stack;
if (sh == 0) { if (sh == 0) {
error("default statement not in switch"); error("default statement not in switch");

View File

@ -0,0 +1,16 @@
/*
* 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 */

View File

@ -10,6 +10,7 @@
#include "LLlex.h" #include "LLlex.h"
#include "tokenname.h" #include "tokenname.h"
#include "Lpars.h" #include "Lpars.h"
#include "error.h"
/* To centralize the declaration of %tokens, their presence in this /* To centralize the declaration of %tokens, their presence in this
file is taken as their declaration. The Makefile will produce file is taken as their declaration. The Makefile will produce
@ -131,8 +132,7 @@ struct tokenname tkfunny[] = { /* internal keywords */
}; };
#endif /* ____ */ #endif /* ____ */
reserve(resv) void reserve(struct tokenname resv[])
register struct tokenname resv[];
{ {
/* The names of the tokens described in resv are entered /* The names of the tokens described in resv are entered
as reserved words. as reserved words.

View File

@ -4,6 +4,8 @@
*/ */
/* $Id$ */ /* $Id$ */
/* TOKENNAME DEFINITION */ /* 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 struct tokenname { /* Used for defining the name of a
token as identified by its symbol token as identified by its symbol
@ -11,3 +13,7 @@ struct tokenname { /* Used for defining the name of a
int tn_symbol; int tn_symbol;
char *tn_name; char *tn_name;
}; };
void reserve(struct tokenname resv[]);
#endif /* LANG_CEM_CEMCOM_ANSI_TOCKENNAME_H */

View File

@ -9,6 +9,8 @@
#include "debug.h" #include "debug.h"
#include "botch_free.h" #include "botch_free.h"
#include <alloc.h> #include <alloc.h>
#include "arith.h"
#include "util.h"
#include "Lpars.h" #include "Lpars.h"
#include "arith.h" #include "arith.h"
#include "type.h" #include "type.h"
@ -18,11 +20,7 @@
#include "sizes.h" #include "sizes.h"
#include "align.h" #include "align.h"
#include "decspecs.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 /* To be created dynamically in main() from defaults or from command
line parameters. line parameters.
@ -39,14 +37,12 @@ struct type
struct type *pa_type; /* Pointer-Arithmetic type */ struct type *pa_type; /* Pointer-Arithmetic type */
struct type * struct type *create_type(int fund)
create_type(fund)
int fund;
{ {
/* A brand new struct type is created, and its tp_fund set /* A brand new struct type is created, and its tp_fund set
to fund. to fund.
*/ */
register struct type *ntp = new_type(); struct type *ntp = new_type();
ntp->tp_fund = fund; ntp->tp_fund = fund;
ntp->tp_size = (arith)-1; ntp->tp_size = (arith)-1;
@ -54,30 +50,34 @@ create_type(fund)
return ntp; return ntp;
} }
struct type * struct type *promoted_type(struct type *tp)
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) if (tp->tp_unsigned && (int) tp->tp_size == (int) int_size)
{
return uint_type; 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 double_type;
else return tp; }
return tp;
} }
struct type *
construct_type(fund, tp, qual, count, pl) /* count: for fund == ARRAY only */
register struct type *tp; struct type *construct_type(int fund, struct type *tp, int qual, arith count, struct proto *pl)
register struct proto *pl;
arith count; /* for fund == ARRAY only */
int qual;
{ {
/* fund must be a type constructor: FIELD, FUNCTION, POINTER or /* fund must be a type constructor: FIELD, FUNCTION, POINTER or
ARRAY. The pointer to the constructed type is returned. ARRAY. The pointer to the constructed type is returned.
*/ */
register struct type *dtp; struct type *dtp = NULL;
switch (fund) { switch (fund) {
#ifndef NOBITFIELD #ifndef NOBITFIELD
@ -115,17 +115,13 @@ construct_type(fund, tp, qual, count, pl)
return dtp; return dtp;
} }
struct type * struct type *function_of(struct type *tp, struct proto *pl, int qual)
function_of(tp, pl, qual)
register struct type *tp;
struct proto *pl;
int qual;
{ {
#if 0 #if 0
/* See comment below */ /* See comment below */
register struct type *dtp = tp->tp_function; struct type *dtp = tp->tp_function;
#else #else
register struct type *dtp; struct type *dtp;
#endif #endif
/* look for a type with the right qualifier */ /* look for a type with the right qualifier */
@ -161,12 +157,9 @@ function_of(tp, pl, qual)
return dtp; return dtp;
} }
struct type * struct type *pointer_to(struct type *tp, int qual)
pointer_to(tp, qual)
register struct type *tp;
int qual;
{ {
register struct type *dtp = tp->tp_pointer; struct type *dtp = tp->tp_pointer;
/* look for a type with the right qualifier */ /* look for a type with the right qualifier */
while (dtp && dtp->tp_typequal != qual) while (dtp && dtp->tp_typequal != qual)
@ -185,13 +178,9 @@ pointer_to(tp, qual)
return dtp; return dtp;
} }
struct type * struct type *array_of(struct type *tp, arith count, int qual)
array_of(tp, count, qual)
register struct type *tp;
arith count;
int qual;
{ {
register struct type *dtp = tp->tp_array; struct type *dtp = tp->tp_array;
/* look for a type with the right size */ /* look for a type with the right size */
while (dtp && (dtp->tp_nel != count || dtp->tp_typequal != qual)) while (dtp && (dtp->tp_nel != count || dtp->tp_typequal != qual))
@ -214,12 +203,9 @@ array_of(tp, count, qual)
} }
#ifndef NOBITFIELD #ifndef NOBITFIELD
struct type * struct type *field_of(struct type *tp, int qual)
field_of(tp, qual)
register struct type *tp;
int qual;
{ {
register struct type *dtp = create_type(FIELD); struct type *dtp = create_type(FIELD);
dtp->tp_up = tp; dtp->tp_up = tp;
dtp->tp_align = tp->tp_align; dtp->tp_align = tp->tp_align;
@ -229,10 +215,7 @@ field_of(tp, qual)
} }
#endif /* NOBITFIELD */ #endif /* NOBITFIELD */
arith arith size_of_type(struct type *tp, char nm[])
size_of_type(tp, nm)
struct type *tp;
char nm[];
{ {
arith sz = tp->tp_size; arith sz = tp->tp_size;
@ -243,16 +226,14 @@ size_of_type(tp, nm)
return sz; return sz;
} }
idf2type(idf, tpp) void idf2type(struct idf *idf, struct type **tpp)
struct idf *idf;
struct type **tpp;
{ {
/* Decoding a typedef-ed identifier or basic type: if the /* Decoding a typedef-ed identifier or basic type: if the
size is yet unknown we have to make copy of the type size is yet unknown we have to make copy of the type
descriptor to prevent garbage at the initialisation of descriptor to prevent garbage at the initialisation of
arrays with unknown size. arrays with unknown size.
*/ */
register struct type *tp = idf->id_def->df_type; struct type *tp = idf->id_def->df_type;
if (*tpp) error("multiple types in declaration"); if (*tpp) error("multiple types in declaration");
if ( tp->tp_size < (arith)0 && tp->tp_fund == ARRAY) { if ( tp->tp_size < (arith)0 && tp->tp_fund == ARRAY) {
@ -265,19 +246,14 @@ idf2type(idf, tpp)
} }
} }
arith arith align(arith pos, int al)
align(pos, al)
arith pos;
int al;
{ {
return ((pos + al - 1) / al) * al; return ((pos + al - 1) / al) * al;
} }
struct type * struct type *standard_type(int fund, int sgn, int algn, arith sz)
standard_type(fund, sgn, algn, sz)
int algn; arith sz;
{ {
register struct type *tp = create_type(fund); struct type *tp = create_type(fund);
tp->tp_unsigned = sgn != 0; tp->tp_unsigned = sgn != 0;
tp->tp_align = algn; tp->tp_align = algn;
@ -286,17 +262,16 @@ standard_type(fund, sgn, algn, sz)
return tp; return tp;
} }
completed(tp) void completed(struct type *tp)
struct type *tp;
{ {
register struct type *atp = tp->tp_array; struct type *atp = tp->tp_array;
register struct type *etp = tp; struct type *etp = tp;
switch(etp->tp_fund) { switch(etp->tp_fund) {
case STRUCT: case STRUCT:
case UNION: case UNION:
case ENUM: case ENUM:
while (etp = etp->next) { while ( (etp = etp->next) ) {
if (! etp->tp_sdef) etp->tp_sdef = tp->tp_sdef; if (! etp->tp_sdef) etp->tp_sdef = tp->tp_sdef;
etp->tp_size = tp->tp_size; etp->tp_size = tp->tp_size;
etp->tp_align = tp->tp_align; etp->tp_align = tp->tp_align;

View File

@ -0,0 +1,23 @@
/*
* The Amsterdam Compiler Kit
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
#ifndef LANG_CEM_CEMCOM_ANSI_TYPE_H
#define LANG_CEM_CEMCOM_ANSI_TYPE_H
/* lang/cem/cemcom.ansi/type.c */
struct type *create_type(int fund);
struct type *promoted_type(struct type *tp);
struct type *construct_type(int fund, struct type *tp, int qual, arith count, struct proto *pl);
struct type *function_of(struct type *tp, struct proto *pl, int qual);
struct type *pointer_to(struct type *tp, int qual);
struct type *array_of(struct type *tp, arith count, int qual);
struct type *field_of(struct type *tp, int qual);
arith size_of_type(struct type *tp, char nm[]);
void idf2type(struct idf *idf, struct type **tpp);
arith align(arith pos, int al);
struct type *standard_type(int fund, int sgn, int algn, arith sz);
void completed(struct type *tp);
#endif /* LANG_CEM_CEMCOM_ANSI_TYPE_H */

Some files were not shown because too many files have changed in this diff Show More