Another batch especially on C ANSI frontend

This commit is contained in:
Godzil 2013-03-18 02:25:39 +01:00 committed by Manoël Trapier
parent 369ec26b03
commit c0cd8650a6
42 changed files with 413 additions and 310 deletions

View File

@ -27,15 +27,15 @@
#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"
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 +44,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 +53,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 +82,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 +179,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 +188,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 +211,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 +242,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 +297,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 +311,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 +325,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 +363,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 +382,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 +408,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 +424,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 +434,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 +443,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 +457,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 +469,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 +505,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 +529,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 +540,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 +563,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 +576,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 +607,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

@ -30,3 +30,13 @@
#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;
void erroneous2int(struct expr **expp);
int int2int(struct expr **expp, struct type *tp);
void int2float(struct expr **expp, struct type *tp);
void float2float(struct expr**expp, struct type *tp);
void field2arith(struct expr **expp);
void ch3pointer(struct expr **expp, int oper, struct type *tp);

View File

@ -18,9 +18,11 @@
#include "label.h" #include "label.h"
#include "stack.h" #include "stack.h"
#include "Lpars.h" #include "Lpars.h"
extern arith NewLocal();
#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 +54,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 +64,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 +100,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 +134,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 +161,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,32 @@
#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 <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 +168,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 +176,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 +413,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 +474,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 +517,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 +558,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 +580,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 +602,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 +617,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 +677,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 +695,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,19 @@
#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 <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 +45,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 +303,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 +334,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 +345,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 +369,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 +389,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,15 @@
#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 <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(int tok);
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,12 @@
#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 <symbol2str.h>
#ifdef LINT #ifdef LINT
#include "l_lint.h" #include "l_lint.h"
#endif /* LINT */ #endif /* LINT */
@ -51,7 +57,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 +71,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 +115,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 +129,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 +143,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 +152,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 +167,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 +192,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 +223,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 +234,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 +321,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 +391,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 +404,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 +419,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 +445,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 +532,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 +608,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 +638,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 +668,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 +701,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 +719,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 +736,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 +746,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 +758,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 +769,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 +779,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,39 @@
/*
* 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();
#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

@ -27,13 +27,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 +125,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,7 @@
#include "sizes.h" #include "sizes.h"
#include "Lpars.h" #include "Lpars.h"
#include "assert.h" #include "assert.h"
#include "cstoper.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 +25,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 +205,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 +240,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

@ -28,6 +28,7 @@
#include "expr.h" #include "expr.h"
#include "sizes.h" #include "sizes.h"
#include "level.h" #include "level.h"
#include "code_c.h"
#ifdef LINT #ifdef LINT
#include "l_lint.h" #include "l_lint.h"
#endif /* LINT */ #endif /* LINT */

View File

@ -20,13 +20,12 @@ 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 +66,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 +81,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 +112,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

@ -17,5 +17,8 @@ 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;
void do_decspecs(struct decspecs *ds);
struct type *qualifier_type(struct type *tp, int typequal);

View File

@ -30,6 +30,8 @@
#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"
#define CRASH() crash("EVAL: CRASH at line %u", __LINE__) #define CRASH() crash("EVAL: CRASH at line %u", __LINE__)

View File

@ -24,8 +24,10 @@
#include "sizes.h" #include "sizes.h"
#include "level.h" #include "level.h"
#include "use_tmp.h" #include "use_tmp.h"
#include "cstoper.h"
#include <symbol2str.h>
extern char *symbol2str();
extern char options[]; extern char options[];
extern int InSizeof; extern int InSizeof;

View File

@ -18,8 +18,9 @@
#include "expr.h" #include "expr.h"
#include "code.h" #include "code.h"
#include "sizes.h" #include "sizes.h"
#include "ch3.h"
extern struct expr *intexpr(); #include "ch3bin.h"
#include "ch3mon.h"
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 +32,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 +49,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 +79,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 +121,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 +144,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 +323,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,6 +26,7 @@
#include "align.h" #include "align.h"
#include "Lpars.h" #include "Lpars.h"
#include "field.h" #include "field.h"
#include "conversion.h"
arith NewLocal(); /* util.c */ arith NewLocal(); /* util.c */
extern arith full_mask[]; /* cstoper.c */ extern arith full_mask[]; /* cstoper.c */

View File

@ -18,9 +18,11 @@
#include "expr.h" #include "expr.h"
#include "sizes.h" #include "sizes.h"
#include "Lpars.h" #include "Lpars.h"
#include "cstoper.h"
#include <symbol2str.h>
extern int ResultKnown; extern int ResultKnown;
extern char *symbol2str();
fltcstbin(expp, oper, expr) fltcstbin(expp, oper, expr)
register struct expr **expp, *expr; register struct expr **expp, *expr;

View File

@ -31,6 +31,9 @@
#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"
extern char options[]; extern char options[];
extern arith NewLocal(); extern arith NewLocal();

View File

@ -34,6 +34,8 @@
#include "def.h" #include "def.h"
#include "LLlex.h" #include "LLlex.h"
#include "estack.h" #include "estack.h"
#include "conversion.h"
#include "cstopen.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)

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

@ -29,9 +29,12 @@
#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 <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

View File

@ -22,6 +22,7 @@
#include "use_tmp.h" #include "use_tmp.h"
#include "dataflow.h" #include "dataflow.h"
#include "dbsymtab.h" #include "dbsymtab.h"
#include "conversion.h"
#ifndef NOPP #ifndef NOPP
extern char **inctable; extern char **inctable;

View File

@ -59,6 +59,7 @@
#include "code.h" #include "code.h"
#include "expr.h" #include "expr.h"
#include "def.h" #include "def.h"
#include "code_c.h"
#ifdef LINT #ifdef LINT
#include "l_lint.h" #include "l_lint.h"
#endif /* LINT */ #endif /* LINT */

View File

@ -27,6 +27,7 @@
#include "decspecs.h" #include "decspecs.h"
#include "proto.h" #include "proto.h"
#include "assert.h" #include "assert.h"
#include "conversion.h"
extern char options[]; extern char options[];

View File

@ -24,7 +24,7 @@
#include "struct.h" #include "struct.h"
#include "level.h" #include "level.h"
#include "mes.h" #include "mes.h"
#include "code_c.h"
/* #include <em_reg.h> */ /* #include <em_reg.h> */
extern char options[]; extern char options[];

View File

@ -28,6 +28,7 @@
#include "code.h" #include "code.h"
#include "stack.h" #include "stack.h"
#include "def.h" #include "def.h"
#include "code_c.h"
#ifdef DBSYMTAB #ifdef DBSYMTAB
#include <stb.h> #include <stb.h>
#endif /* DBSYMTAB */ #endif /* DBSYMTAB */

View File

@ -26,6 +26,7 @@
#include "expr.h" #include "expr.h"
#include "type.h" #include "type.h"
#include "sizes.h" #include "sizes.h"
#include "code_c.h"
extern char options[]; extern char options[];

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

@ -1,34 +1,41 @@
#!/bin/sh
cat <<'--EOT--' cat <<'--EOT--'
/* Generated by make.tokcase */
/* $Id$ */
#include "Lpars.h" #include "Lpars.h"
char * char *symbol2str(int tok)
symbol2str(tok)
int tok;
{ {
static char buf[2] = { '\0', '\0' }; #define SIZBUF 8
/* allow for a few invocations in f.i. an argument list */
static char buf[SIZBUF];
static int index;
if (040 <= tok && tok < 0177) {
buf[0] = tok;
buf[1] = '\0';
return buf;
}
switch (tok) { switch (tok) {
--EOT-- --EOT--
sed ' sed '
/{[A-Z]/!d /{[A-Z]/!d
s/.*{\(.*\),.*\(".*"\).*$/ case \1 :\ s/.*{\(.*\),.*\(".*"\).*$/ case \1 :\
return \2;/ return \2;/
' '
cat <<'--EOT--' cat <<'--EOT--'
default:
if (tok <= 0) return "end of file";
if (tok < 040 || tok >= 0177) {
return "bad token";
}
/* fall through */
case '\n': case '\n':
case '\f': case '\f':
case '\v': case '\v':
case '\r': case '\r':
case '\t': case '\t':
buf[0] = tok; index = (index+2) & (SIZBUF-1);
return buf; buf[index] = tok;
default: return &buf[index];
return "bad token";
} }
} }
--EOT-- --EOT--

View File

@ -1,16 +1,16 @@
#!/bin/sh
cat <<'--EOT--' cat <<'--EOT--'
/* Generated by make.tokcase */ /* Generated by make.tokcase */
/* $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 */
static char buf[SIZBUF] = { '\'', 0, '\'', 0, '\'', 0, '\'', 0}; static char buf[SIZBUF];
static int index = 1; static int index;
switch (tok) { switch (tok) {
--EOT-- --EOT--
@ -27,9 +27,15 @@ cat <<'--EOT--'
if (tok < 040 || tok >= 0177) { if (tok < 040 || tok >= 0177) {
return "bad token"; return "bad token";
} }
index = (index+4) & (SIZBUF-1); /* fall through */
case '\n':
case '\f':
case '\v':
case '\r':
case '\t':
index = (index+2) & (SIZBUF-1);
buf[index] = tok; buf[index] = tok;
return &buf[index-1]; return &buf[index];
} }
} }
--EOT-- --EOT--

View File

@ -1,11 +1,11 @@
#!/bin/sh
cat <<'--EOT--' cat <<'--EOT--'
/* Generated by make.tokcase */ /* Generated by make.tokcase */
/* $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

@ -1,11 +1,11 @@
#!/bin/sh
cat <<'--EOT--' cat <<'--EOT--'
/* Generated by make.tokcase */ /* Generated by make.tokcase */
/* $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

@ -1,36 +1,41 @@
#!/bin/sh #!/bin/sh
cat <<'--EOT--' cat <<'--EOT--'
/* Generated by make.tokcase */
/* $Id$ */
#include "Lpars.h" #include "Lpars.h"
char * char *symbol2str(int tok)
symbol2str(tok)
int tok;
{ {
static char buf[2] = { '\0', '\0' }; #define SIZBUF 8
/* allow for a few invocations in f.i. an argument list */
static char buf[SIZBUF];
static int index;
if (040 <= tok && tok < 0177) {
buf[0] = tok;
buf[1] = '\0';
return buf;
}
switch (tok) { switch (tok) {
--EOT-- --EOT--
sed ' sed '
/{[A-Z]/!d /{[A-Z]/!d
s/.*{\(.*\),.*\(".*"\).*$/ case \1 :\ s/.*{\(.*\),.*\(".*"\).*$/ case \1 :\
return \2;/ return \2;/
' '
cat <<'--EOT--' cat <<'--EOT--'
default:
if (tok <= 0) return "end of file";
if (tok < 040 || tok >= 0177) {
return "bad token";
}
/* fall through */
case '\n': case '\n':
case '\f': case '\f':
case '\v': case '\v':
case '\r': case '\r':
case '\t': case '\t':
buf[0] = tok; index = (index+2) & (SIZBUF-1);
return buf; buf[index] = tok;
default: return &buf[index];
return "bad token";
} }
} }
--EOT-- --EOT--

View File

@ -1,16 +1,16 @@
#!/bin/sh
cat <<'--EOT--' cat <<'--EOT--'
/* Generated by make.tokcase */ /* Generated by make.tokcase */
/* $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 */
static char buf[SIZBUF] = { '\'', 0, '\'', 0, '\'', 0, '\'', 0}; static char buf[SIZBUF];
static int index = 1; static int index;
switch (tok) { switch (tok) {
--EOT-- --EOT--
@ -24,13 +24,18 @@ s/.*{\(.*\),.*\(".*"\).*$/ case \1 :\
cat <<'--EOT--' cat <<'--EOT--'
default: default:
if (tok <= 0) return "end of file"; if (tok <= 0) return "end of file";
if (tok == '\n') return "<newline>";
if (tok < 040 || tok >= 0177) { if (tok < 040 || tok >= 0177) {
return "bad token"; return "bad token";
} }
index = (index+4) & (SIZBUF-1); /* fall through */
case '\n':
case '\f':
case '\v':
case '\r':
case '\t':
index = (index+2) & (SIZBUF-1);
buf[index] = tok; buf[index] = tok;
return &buf[index-1]; return &buf[index];
} }
} }
--EOT-- --EOT--