+ M2 Compiler ISO C90 compatibility

* Fixing of potential crash issue with function tables in compiler.
+ SYSTEM.h is now renamed to SYSTEMM2.h to avoid conflicts on non case sensitive filesystems.
This commit is contained in:
carl 2019-03-02 01:39:25 +08:00
parent 5f9a199257
commit 3867cfdaca
51 changed files with 1368 additions and 1203 deletions

View file

@ -45,7 +45,7 @@
!File: debugcst.h !File: debugcst.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: inputtype.h !File: inputtype.h
@ -57,22 +57,22 @@
!File: squeeze.h !File: squeeze.h
/*#define SQUEEZE 1 /* define on "small" machines */ /*#define SQUEEZE 1 *//* define on "small" machines */
!File: strict3rd.h !File: strict3rd.h
/*#define STRICT_3RD_ED 1 /* define on "small" machines, and if you want /*#define STRICT_3RD_ED 1 *//* define on "small" machines, and if you want
a compiler that only implements "3rd edition" a compiler that only implements "3rd edition"
Modula-2 Modula-2
*/ */
!File: nocross.h !File: nocross.h
/*#define NOCROSS 1 /* define when cross-compiler not needed */ /*#define NOCROSS 1 *//* define when cross-compiler not needed */
!File: nostrict.h !File: nostrict.h
/*#define NOSTRICT 1 /* define when STRICT warnings disabled /*#define NOSTRICT 1 *//* define when STRICT warnings disabled
(yet another squeezing method) (yet another squeezing method)
*/ */

View file

@ -26,6 +26,7 @@
#include "f_info.h" #include "f_info.h"
#include "Lpars.h" #include "Lpars.h"
#include "class.h" #include "class.h"
#include "error.h"
#include "idf.h" #include "idf.h"
#include "def.h" #include "def.h"
#include "type.h" #include "type.h"
@ -48,8 +49,7 @@ int tk_nmb_at_last_syn_err = -ERR_SHADOW;
extern char options[]; extern char options[];
extern int flt_status; extern int flt_status;
STATIC static void SkipComment(void)
SkipComment()
{ {
/* Skip Modula-2 comments (* ... *). /* Skip Modula-2 comments (* ... *).
Note that comments may be nested (par. 3.5). Note that comments may be nested (par. 3.5).
@ -122,8 +122,7 @@ SkipComment()
} }
} }
STATIC struct string * static struct string *GetString(int upto)
GetString(upto)
{ {
/* Read a Modula-2 string, delimited by the character "upto". /* Read a Modula-2 string, delimited by the character "upto".
*/ */
@ -169,8 +168,7 @@ GetString(upto)
static char *s_error = "illegal line directive"; static char *s_error = "illegal line directive";
STATIC int static int getch(void)
getch()
{ {
register int ch; register int ch;
@ -180,8 +178,7 @@ getch()
return ch; return ch;
} }
void void CheckForLineDirective(void)
CheckForLineDirective()
{ {
register int ch = getch(); register int ch = getch();
register int i = 0; register int i = 0;
@ -242,8 +239,7 @@ CheckForLineDirective()
} }
} }
STATIC static void CheckForLet()
CheckForLet()
{ {
register int ch; register int ch;
@ -256,8 +252,7 @@ CheckForLet()
} }
} }
int int LLlex(void)
LLlex()
{ {
/* LLlex() is the Lexical Analyzer. /* LLlex() is the Lexical Analyzer.
The putting aside of tokens is taken into account. The putting aside of tokens is taken into account.

View file

@ -68,3 +68,5 @@ extern struct type *toktype;
extern int token_nmb; extern int token_nmb;
extern int tk_nmb_at_last_syn_err; extern int tk_nmb_at_last_syn_err;
void CheckForLineDirective(void);

View file

@ -21,14 +21,15 @@
#include "parameters.h" #include "parameters.h"
#include "idf.h" #include "idf.h"
#include "error.h"
#include "LLlex.h" #include "LLlex.h"
#include "Lpars.h" #include "Lpars.h"
#include "misc.h"
extern char *symbol2str(); extern char *symbol2str();
extern t_idf *gen_anon_idf();
LLmessage(tk)
register int tk; void LLmessage(register int tk)
{ {
if (tk > 0) { if (tk > 0) {
/* if (tk > 0), it represents the token to be inserted. /* if (tk > 0), it represents the token to be inserted.

View file

@ -19,18 +19,22 @@
#include "parameters.h" #include "parameters.h"
#include "debug.h" #include "debug.h"
#include <em_label.h>
#include <em_arith.h>
#include <em_code.h>
#include <alloc.h>
#include <assert.h> #include <assert.h>
#include "em_label.h"
#include "em_arith.h"
#include "em_code.h"
#include "alloc.h"
#include "Lpars.h" #include "Lpars.h"
#include "type.h" #include "type.h"
#include "error.h"
#include "LLlex.h" #include "LLlex.h"
#include "node.h" #include "node.h"
#include "desig.h" #include "desig.h"
#include "walk.h" #include "walk.h"
#include "code.h"
#include "typequiv.h"
#include "chk_expr.h" #include "chk_expr.h"
#include "def.h" #include "def.h"
@ -54,11 +58,12 @@ struct case_entry {
arith ce_low, ce_up; /* lower and upper bound of range */ arith ce_low, ce_up; /* lower and upper bound of range */
}; };
void AddCases();
void AddOneCase();
/* STATICALLOCDEF "case_entry" 20 */ /* STATICALLOCDEF "case_entry" 20 */
/* The constant DENSITY determines when CSA and when CSB instructions /* The constant DENSITY determines when CSA and when CSB instructions
are generated. Reasonable values are: 2, 3, 4. are generated. Reasonable values are: 2, 3, 4.
On machines that have lots of address space and memory, higher values On machines that have lots of address space and memory, higher values
@ -66,8 +71,7 @@ void AddOneCase();
may be lower. may be lower.
*/ */
compact(nr, low, up) static 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
@ -80,199 +84,7 @@ compact(nr, low, up)
} }
#define nd_lab nd_symb #define nd_lab nd_symb
int static void AddOneCase(struct switch_hdr *sh, t_node *lnode, t_node *rnode, label lbl)
CaseCode(nd, exitlabel, end_reached)
t_node *nd;
label exitlabel;
{
/* Check the expression, stack a new case header and
fill in the necessary fields.
"exitlabel" is the exit-label of the closest enclosing
LOOP-statement, or 0.
*/
register struct switch_hdr *sh = new_switch_hdr();
register t_node *pnode = nd;
register struct case_entry *ce;
register arith val;
label CaseDescrLab;
int rval;
assert(pnode->nd_class == Stat && pnode->nd_symb == CASE);
if (ChkExpression(&(pnode->nd_LEFT))) {
MkCoercion(&(pnode->nd_LEFT),BaseType(pnode->nd_LEFT->nd_type));
CodePExpr(pnode->nd_LEFT);
}
sh->sh_type = pnode->nd_LEFT->nd_type;
sh->sh_break = ++text_label;
/* Now, create case label list
*/
while (pnode = pnode->nd_RIGHT) {
if (pnode->nd_class == Link && pnode->nd_symb == '|') {
if (pnode->nd_LEFT) {
/* non-empty case
*/
pnode->nd_LEFT->nd_lab = ++text_label;
AddCases(sh, /* to descriptor */
pnode->nd_LEFT->nd_LEFT,
/* of case labels */
(label) pnode->nd_LEFT->nd_lab
/* and code label */
);
}
}
else {
/* Else part
*/
sh->sh_default = ++text_label;
break;
}
}
if (!sh->sh_nrofentries) {
/* There were no cases, so we have to check the case-expression
here
*/
if (! (sh->sh_type->tp_fund & T_DISCRETE)) {
node_error(nd, "illegal type in CASE-expression");
}
}
/* Now generate code for the switch itself
First the part that CSA and CSB descriptions have in common.
*/
CaseDescrLab = ++data_label; /* the rom must have a label */
C_df_dlb(CaseDescrLab);
if (sh->sh_default) C_rom_ilb(sh->sh_default);
else C_rom_ucon("0", pointer_size);
if (compact(sh->sh_nrofentries, sh->sh_lowerbd, sh->sh_upperbd)) {
/* CSA
*/
int gen = 1;
ce = sh->sh_entries;
while (! ce->ce_label) ce = ce->ce_next;
C_rom_cst((arith) 0);
C_rom_cst(sh->sh_upperbd - sh->sh_lowerbd);
for (val = sh->sh_lowerbd; val <= sh->sh_upperbd; val++) {
assert(ce);
if (gen || val == ce->ce_low) {
gen = 1;
C_rom_ilb(ce->ce_label);
if (val == ce->ce_up) {
gen = 0;
ce = ce->ce_next;
while (ce && ! ce->ce_label) ce = ce->ce_next;
}
}
else if (sh->sh_default) C_rom_ilb(sh->sh_default);
else C_rom_ucon("0", pointer_size);
}
C_loc(sh->sh_lowerbd);
C_sbu(word_size);
c_lae_dlb(CaseDescrLab); /* perform the switch */
C_csa(word_size);
}
else {
/* CSB
*/
C_rom_cst((arith)sh->sh_nrofentries);
for (ce = sh->sh_entries; ce; ce = ce->ce_next) {
/* generate the entries: value + prog.label
*/
if (! ce->ce_label) continue;
val = ce->ce_low;
do {
C_rom_cst(val);
C_rom_ilb(ce->ce_label);
} while (val++ != ce->ce_up);
}
c_lae_dlb(CaseDescrLab); /* perform the switch */
C_csb(word_size);
}
/* Now generate code for the cases
*/
pnode = nd;
rval = 0;
while (pnode = pnode->nd_RIGHT) {
if (pnode->nd_class == Link && pnode->nd_symb == '|') {
if (pnode->nd_LEFT) {
rval |= LblWalkNode((label) pnode->nd_LEFT->nd_lab,
pnode->nd_LEFT->nd_RIGHT,
exitlabel, end_reached);
c_bra(sh->sh_break);
}
}
else {
/* Else part
*/
assert(sh->sh_default != 0);
rval |= LblWalkNode(sh->sh_default,
pnode, exitlabel, end_reached);
break;
}
}
def_ilb(sh->sh_break);
FreeSh(sh);
return rval;
}
FreeSh(sh)
register struct switch_hdr *sh;
{
/* free the allocated switch structure
*/
register struct case_entry *ce;
ce = sh->sh_entries;
while (ce) {
struct case_entry *tmp = ce->ce_next;
free_case_entry(ce);
ce = tmp;
}
free_switch_hdr(sh);
}
void
AddCases(sh, node, lbl)
struct switch_hdr *sh;
register t_node *node;
label lbl;
{
/* Add case labels to the case label list
*/
if (node->nd_class == Link) {
if (node->nd_symb == UPTO) {
assert(node->nd_LEFT->nd_class == Value);
assert(node->nd_RIGHT->nd_class == Value);
AddOneCase(sh, node->nd_LEFT, node->nd_RIGHT, lbl);
return;
}
assert(node->nd_symb == ',');
AddCases(sh, node->nd_LEFT, lbl);
AddCases(sh, node->nd_RIGHT, lbl);
return;
}
assert(node->nd_class == Value);
AddOneCase(sh, node, node, lbl);
}
void
AddOneCase(sh, lnode, rnode, lbl)
register struct switch_hdr *sh;
t_node *lnode, *rnode;
label lbl;
{ {
register struct case_entry *ce = new_case_entry(); register struct case_entry *ce = new_case_entry();
register struct case_entry *c1 = sh->sh_entries, *c2 = 0; register struct case_entry *c1 = sh->sh_entries, *c2 = 0;
@ -387,3 +199,188 @@ node_error(rnode, "multiple case entry for value %ld", (long)(ce->ce_up));
} }
if (ce->ce_label) sh->sh_nrofentries += ce->ce_up - ce->ce_low + 1; if (ce->ce_label) sh->sh_nrofentries += ce->ce_up - ce->ce_low + 1;
} }
static void AddCases(struct switch_hdr *sh, register t_node *node, label lbl)
{
/* Add case labels to the case label list
*/
if (node->nd_class == Link) {
if (node->nd_symb == UPTO) {
assert(node->nd_LEFT->nd_class == Value);
assert(node->nd_RIGHT->nd_class == Value);
AddOneCase(sh, node->nd_LEFT, node->nd_RIGHT, lbl);
return;
}
assert(node->nd_symb == ',');
AddCases(sh, node->nd_LEFT, lbl);
AddCases(sh, node->nd_RIGHT, lbl);
return;
}
assert(node->nd_class == Value);
AddOneCase(sh, node, node, lbl);
}
static void FreeSh(struct switch_hdr *sh)
{
/* free the allocated switch structure
*/
register struct case_entry *ce;
ce = sh->sh_entries;
while (ce) {
struct case_entry *tmp = ce->ce_next;
free_case_entry(ce);
ce = tmp;
}
free_switch_hdr(sh);
}
int CaseCode(t_node *nd, label exitlabel, int end_reached)
{
/* Check the expression, stack a new case header and
fill in the necessary fields.
"exitlabel" is the exit-label of the closest enclosing
LOOP-statement, or 0.
*/
register struct switch_hdr *sh = new_switch_hdr();
register t_node *pnode = nd;
register struct case_entry *ce;
register arith val;
label CaseDescrLab;
int rval;
assert(pnode->nd_class == Stat && pnode->nd_symb == CASE);
if (ChkExpression(&(pnode->nd_LEFT))) {
MkCoercion(&(pnode->nd_LEFT),BaseType(pnode->nd_LEFT->nd_type));
CodePExpr(pnode->nd_LEFT);
}
sh->sh_type = pnode->nd_LEFT->nd_type;
sh->sh_break = ++text_label;
/* Now, create case label list
*/
while ( (pnode = pnode->nd_RIGHT) ) {
if (pnode->nd_class == Link && pnode->nd_symb == '|') {
if (pnode->nd_LEFT) {
/* non-empty case
*/
pnode->nd_LEFT->nd_lab = ++text_label;
AddCases(sh, /* to descriptor */
pnode->nd_LEFT->nd_LEFT,
/* of case labels */
(label) pnode->nd_LEFT->nd_lab
/* and code label */
);
}
}
else {
/* Else part
*/
sh->sh_default = ++text_label;
break;
}
}
if (!sh->sh_nrofentries) {
/* There were no cases, so we have to check the case-expression
here
*/
if (! (sh->sh_type->tp_fund & T_DISCRETE)) {
node_error(nd, "illegal type in CASE-expression");
}
}
/* Now generate code for the switch itself
First the part that CSA and CSB descriptions have in common.
*/
CaseDescrLab = ++data_label; /* the rom must have a label */
C_df_dlb(CaseDescrLab);
if (sh->sh_default) C_rom_ilb(sh->sh_default);
else C_rom_ucon("0", pointer_size);
if (compact(sh->sh_nrofentries, sh->sh_lowerbd, sh->sh_upperbd)) {
/* CSA
*/
int gen = 1;
ce = sh->sh_entries;
while (! ce->ce_label) ce = ce->ce_next;
C_rom_cst((arith) 0);
C_rom_cst(sh->sh_upperbd - sh->sh_lowerbd);
for (val = sh->sh_lowerbd; val <= sh->sh_upperbd; val++) {
assert(ce);
if (gen || val == ce->ce_low) {
gen = 1;
C_rom_ilb(ce->ce_label);
if (val == ce->ce_up) {
gen = 0;
ce = ce->ce_next;
while (ce && ! ce->ce_label) ce = ce->ce_next;
}
}
else if (sh->sh_default) C_rom_ilb(sh->sh_default);
else C_rom_ucon("0", pointer_size);
}
C_loc(sh->sh_lowerbd);
C_sbu(word_size);
c_lae_dlb(CaseDescrLab); /* perform the switch */
C_csa(word_size);
}
else {
/* CSB
*/
C_rom_cst((arith)sh->sh_nrofentries);
for (ce = sh->sh_entries; ce; ce = ce->ce_next) {
/* generate the entries: value + prog.label
*/
if (! ce->ce_label) continue;
val = ce->ce_low;
do {
C_rom_cst(val);
C_rom_ilb(ce->ce_label);
} while (val++ != ce->ce_up);
}
c_lae_dlb(CaseDescrLab); /* perform the switch */
C_csb(word_size);
}
/* Now generate code for the cases
*/
pnode = nd;
rval = 0;
while ( (pnode = pnode->nd_RIGHT) ) {
if (pnode->nd_class == Link && pnode->nd_symb == '|') {
if (pnode->nd_LEFT) {
rval |= LblWalkNode((label) pnode->nd_LEFT->nd_lab,
pnode->nd_LEFT->nd_RIGHT,
exitlabel, end_reached);
c_bra(sh->sh_break);
}
}
else {
/* Else part
*/
assert(sh->sh_default != 0);
rval |= LblWalkNode(sh->sh_default,
pnode, exitlabel, end_reached);
break;
}
}
def_ilb(sh->sh_break);
FreeSh(sh);
return rval;
}

View file

@ -21,6 +21,8 @@
#include <em_label.h> #include <em_label.h>
#include <assert.h> #include <assert.h>
#include <alloc.h> #include <alloc.h>
#include <flt_arith.h>
#include <system.h>
#include "Lpars.h" #include "Lpars.h"
#include "idf.h" #include "idf.h"
@ -29,21 +31,30 @@
#include "def.h" #include "def.h"
#include "node.h" #include "node.h"
#include "scope.h" #include "scope.h"
#include "error.h"
#include "standards.h" #include "standards.h"
#include "chk_expr.h" #include "chk_expr.h"
#include "cstoper.h"
#include "typequiv.h"
#include "misc.h" #include "misc.h"
#include "lookup.h"
#include "print.h"
#include "warning.h" #include "warning.h"
#include "main.h" #include "main.h"
extern char *symbol2str(); extern char *symbol2str();
extern char *sprint();
extern arith flt_flt2arith();
STATIC /* Forward file declarations */
df_error(nd, mess, edf) static int ChkStandard(t_node **);
t_node *nd; /* node on which error occurred */ static int ChkCast(t_node **);
char *mess; /* error message */
register t_def *edf; /* do we have a name? */
static void df_error(
t_node *nd, /* node on which error occurred */
char *mess, /* error message */
register t_def *edf) /* do we have a name? */
{ {
if (edf) { if (edf) {
if (edf->df_kind != D_ERROR) { if (edf->df_kind != D_ERROR) {
@ -53,10 +64,7 @@ df_error(nd, mess, edf)
else node_error(nd, mess); else node_error(nd, mess);
} }
void void MkCoercion(t_node **pnd, register t_type *tp)
MkCoercion(pnd, tp)
t_node **pnd;
register t_type *tp;
{ {
/* Make a coercion from the node indicated by *pnd to the /* Make a coercion from the node indicated by *pnd to the
type indicated by tp. If the node indicated by *pnd type indicated by tp. If the node indicated by *pnd
@ -162,9 +170,7 @@ MkCoercion(pnd, tp)
*pnd = nd; *pnd = nd;
} }
int int ChkVariable(register t_node **expp, int flags)
ChkVariable(expp, flags)
register t_node **expp;
{ {
/* Check that "expp" indicates an item that can be /* Check that "expp" indicates an item that can be
assigned to. assigned to.
@ -182,9 +188,7 @@ ChkVariable(expp, flags)
return 1; return 1;
} }
STATIC int static int ChkArrow(t_node **expp, int flags)
ChkArrow(expp)
t_node **expp;
{ {
/* Check an application of the '^' operator. /* Check an application of the '^' operator.
The operand must be a variable of a pointer type. The operand must be a variable of a pointer type.
@ -211,9 +215,7 @@ ChkArrow(expp)
return 1; return 1;
} }
STATIC int static int ChkArr(t_node **expp, int flags)
ChkArr(expp, flags)
t_node **expp;
{ {
/* Check an array selection. /* Check an array selection.
The left hand side must be a variable of an array type, The left hand side must be a variable of an array type,
@ -255,9 +257,7 @@ ChkArr(expp, flags)
} }
/*ARGSUSED*/ /*ARGSUSED*/
STATIC int static int ChkValue(t_node **expp, int flags)
ChkValue(expp)
t_node **expp;
{ {
#ifdef DEBUG #ifdef DEBUG
switch((*expp)->nd_symb) { switch((*expp)->nd_symb) {
@ -273,9 +273,7 @@ ChkValue(expp)
return 1; return 1;
} }
STATIC int static int ChkSelOrName(t_node **expp, int flags)
ChkSelOrName(expp, flags)
t_node **expp;
{ {
/* Check either an ID or a construction of the form /* Check either an ID or a construction of the form
ID.ID [ .ID ]* ID.ID [ .ID ]*
@ -348,9 +346,7 @@ ChkSelOrName(expp, flags)
return exp->nd_def->df_kind != D_ERROR; return exp->nd_def->df_kind != D_ERROR;
} }
STATIC int static int ChkExSelOrName(t_node **expp, int flags)
ChkExSelOrName(expp)
t_node **expp;
{ {
/* Check either an ID or an ID.ID [.ID]* occurring in an /* Check either an ID or an ID.ID [.ID]* occurring in an
expression. expression.
@ -422,20 +418,13 @@ ChkExSelOrName(expp)
return 1; return 1;
} }
STATIC int static int ChkEl(register t_node **expp, t_type *tp)
ChkEl(expp, tp)
register t_node **expp;
t_type *tp;
{ {
return ChkExpression(expp) && ChkCompat(expp, tp, "set element"); return ChkExpression(expp) && ChkCompat(expp, tp, "set element");
} }
STATIC int static int ChkElement(t_node **expp, t_type *tp, arith *set)
ChkElement(expp, tp, set)
t_node **expp;
t_type *tp;
arith *set;
{ {
/* Check elements of a set. This routine may call itself /* Check elements of a set. This routine may call itself
recursively. recursively.
@ -494,9 +483,7 @@ ChkElement(expp, tp, set)
return 1; return 1;
} }
arith * arith *MkSet(unsigned int size)
MkSet(size)
unsigned size;
{ {
register arith *s, *t; register arith *s, *t;
@ -508,8 +495,7 @@ MkSet(size)
return s; return s;
} }
FreeSet(s) void FreeSet(register arith *s)
register arith *s;
{ {
dec_refcount(s); dec_refcount(s);
if (refcount(s) <= 0) { if (refcount(s) <= 0) {
@ -518,9 +504,7 @@ FreeSet(s)
} }
} }
STATIC int static int ChkSet(t_node **expp, int flags)
ChkSet(expp)
t_node **expp;
{ {
/* Check the legality of a SET aggregate, and try to evaluate it /* Check the legality of a SET aggregate, and try to evaluate it
compile time. Unfortunately this is all rather complicated. compile time. Unfortunately this is all rather complicated.
@ -586,10 +570,7 @@ ChkSet(expp)
return retval; return retval;
} }
STATIC t_node * static t_node *nextarg(t_node **argp, t_def *edf)
nextarg(argp, edf)
t_node **argp;
t_def *edf;
{ {
register t_node *arg = (*argp)->nd_RIGHT; register t_node *arg = (*argp)->nd_RIGHT;
@ -602,10 +583,7 @@ nextarg(argp, edf)
return arg; return arg;
} }
STATIC t_node * static t_node *getarg(t_node **argp, int bases, int designator, t_def *edf)
getarg(argp, bases, designator, edf)
t_node **argp;
t_def *edf;
{ {
/* This routine is used to fetch the next argument from an /* This routine is used to fetch the next argument from an
argument list. The argument list is indicated by "argp". argument list. The argument list is indicated by "argp".
@ -643,10 +621,7 @@ getarg(argp, bases, designator, edf)
return left; return left;
} }
STATIC t_node * static t_node *getname(t_node **argp, int kinds, int bases, t_def *edf)
getname(argp, kinds, bases, edf)
t_node **argp;
t_def *edf;
{ {
/* Get the next argument from argument list "argp". /* Get the next argument from argument list "argp".
The argument must indicate a definition, and the The argument must indicate a definition, and the
@ -672,9 +647,7 @@ getname(argp, kinds, bases, edf)
return left; return left;
} }
STATIC int static int ChkProcCall(register t_node *exp)
ChkProcCall(exp)
register t_node *exp;
{ {
/* Check a procedure call /* Check a procedure call
*/ */
@ -735,9 +708,7 @@ ChkProcCall(exp)
return retval; return retval;
} }
STATIC int static int ChkFunCall(register t_node **expp, int flags)
ChkFunCall(expp)
register t_node **expp;
{ {
/* Check a call that must have a result /* Check a call that must have a result
*/ */
@ -750,12 +721,9 @@ ChkFunCall(expp)
return 0; return 0;
} }
STATIC int ChkStandard();
STATIC int ChkCast();
int
ChkCall(expp) int ChkCall(t_node **expp)
t_node **expp;
{ {
/* Check something that looks like a procedure or function call. /* Check something that looks like a procedure or function call.
Of course this does not have to be a call at all, Of course this does not have to be a call at all,
@ -795,9 +763,7 @@ ChkCall(expp)
return ChkProcCall(*expp); return ChkProcCall(*expp);
} }
STATIC t_type * static t_type *ResultOfOperation(int operator, t_type *tp)
ResultOfOperation(operator, tp)
t_type *tp;
{ {
/* Return the result type of the binary operation "operator", /* Return the result type of the binary operation "operator",
with operand type "tp". with operand type "tp".
@ -819,8 +785,7 @@ ResultOfOperation(operator, tp)
#define Boolean(operator) (operator == OR || operator == AND) #define Boolean(operator) (operator == OR || operator == AND)
STATIC int static int AllowedTypes(int operator)
AllowedTypes(operator)
{ {
/* Return a bit mask indicating the allowed operand types /* Return a bit mask indicating the allowed operand types
for binary operator "operator". for binary operator "operator".
@ -854,10 +819,10 @@ AllowedTypes(operator)
/*NOTREACHED*/ /*NOTREACHED*/
} }
STATIC int static int ChkAddressOper(
ChkAddressOper(tpl, tpr, expp) register t_type *tpl,
register t_type *tpl, *tpr; register t_type *tpr,
register t_node *expp; register t_node *expp)
{ {
/* Check that either "tpl" or "tpr" are both of type /* Check that either "tpl" or "tpr" are both of type
address_type, or that one of them is, but the other is address_type, or that one of them is, but the other is
@ -901,9 +866,7 @@ ChkAddressOper(tpl, tpr, expp)
return 0; return 0;
} }
STATIC int static int ChkBinOper(t_node **expp, int flags)
ChkBinOper(expp)
t_node **expp;
{ {
/* Check a binary operation. /* Check a binary operation.
*/ */
@ -1018,9 +981,7 @@ ChkBinOper(expp)
return 1; return 1;
} }
STATIC int static int ChkUnOper(t_node **expp, int flags)
ChkUnOper(expp)
t_node **expp;
{ {
/* Check an unary operation. /* Check an unary operation.
*/ */
@ -1093,10 +1054,7 @@ ChkUnOper(expp)
return 0; return 0;
} }
STATIC t_node * static t_node *getvariable(t_node **argp, t_def *edf, int flags)
getvariable(argp, edf, flags)
t_node **argp;
t_def *edf;
{ {
/* Get the next argument from argument list "argp". /* Get the next argument from argument list "argp".
It must obey the rules of "ChkVariable". It must obey the rules of "ChkVariable".
@ -1110,9 +1068,7 @@ getvariable(argp, edf, flags)
return arg->nd_LEFT; return arg->nd_LEFT;
} }
STATIC int static int ChkStandard(t_node **expp)
ChkStandard(expp)
t_node **expp;
{ {
/* Check a call of a standard procedure or function /* Check a call of a standard procedure or function
*/ */
@ -1326,7 +1282,7 @@ ChkStandard(expp)
#endif #endif
#ifndef STRICT_3RD_ED #ifndef STRICT_3RD_ED
if (! options['3'] && edf->df_value.df_stdname == S_TSIZE) { if (! options['3'] && edf->df_value.df_stdname == S_TSIZE) {
if (arg = arglink->nd_RIGHT) { if ( (arg = arglink->nd_RIGHT) ) {
node_warning(arg, node_warning(arg,
W_OLDFASHIONED, W_OLDFASHIONED,
"TSIZE with multiple parameters, only first parameter used"); "TSIZE with multiple parameters, only first parameter used");
@ -1442,9 +1398,7 @@ ChkStandard(expp)
return 1; return 1;
} }
STATIC int static int ChkCast(t_node **expp)
ChkCast(expp)
t_node **expp;
{ {
/* Check a cast and perform it if the argument is constant. /* Check a cast and perform it if the argument is constant.
If the sizes don't match, only complain if at least one of them If the sizes don't match, only complain if at least one of them
@ -1507,9 +1461,7 @@ ChkCast(expp)
return 1; return 1;
} }
TryToString(nd, tp) void TryToString(register t_node *nd, t_type *tp)
register t_node *nd;
t_type *tp;
{ {
/* Try a coercion from character constant to string. /* Try a coercion from character constant to string.
*/ */
@ -1527,25 +1479,20 @@ TryToString(nd, tp)
} }
} }
STATIC int static int no_desig(t_node **expp, int flags)
no_desig(expp)
t_node **expp;
{ {
node_error(*expp, "designator expected"); node_error(*expp, "designator expected");
return 0; return 0;
} }
STATIC int static int add_flags(t_node **expp, int flags)
add_flags(expp, flags)
t_node **expp;
{ {
(*expp)->nd_def->df_flags |= flags; (*expp)->nd_def->df_flags |= flags;
return 1; return 1;
} }
extern int PNodeCrash();
int (*ExprChkTable[])() = { int (*ExprChkTable[])(t_node **, int) = {
ChkValue, ChkValue,
ChkArr, ChkArr,
ChkBinOper, ChkBinOper,
@ -1561,7 +1508,7 @@ int (*ExprChkTable[])() = {
PNodeCrash, PNodeCrash,
}; };
int (*DesigChkTable[])() = { int (*DesigChkTable[])(t_node **, int) = {
no_desig, no_desig,
ChkArr, ChkArr,
no_desig, no_desig,

View file

@ -4,22 +4,38 @@
* *
* Author: Ceriel J.H. Jacobs * Author: Ceriel J.H. Jacobs
*/ */
#ifndef CHK_EXPR_H_
#define CHK_EXPR_H_
/* E X P R E S S I O N C H E C K I N G */ /* E X P R E S S I O N C H E C K I N G */
/* $Id$ */ /* $Id$ */
extern int (*ExprChkTable[])(); /* table of expression checking extern int (*ExprChkTable[])(t_node **, int); /* table of expression checking
functions, indexed by node class functions, indexed by node class
*/ */
extern int (*DesigChkTable[])(); /* table of designator checking extern int (*DesigChkTable[])(t_node **, int); /* table of designator checking
functions, indexed by node class functions, indexed by node class
*/ */
#define ChkExpression(expp) ((*ExprChkTable[(*expp)->nd_class])(expp,D_USED)) #define ChkExpression(expp) ((*ExprChkTable[(unsigned int)((*expp)->nd_class)])(expp,D_USED))
#define ChkDesig(expp, flags) ((*DesigChkTable[(*expp)->nd_class])(expp,flags)) #define ChkDesig(expp, flags) ((*DesigChkTable[(unsigned int)((*expp)->nd_class)])(expp,flags))
/* handle reference counts for sets */ /* handle reference counts for sets */
#define inc_refcount(s) (*((int *)(s) - 1) += 1) #define inc_refcount(s) (*((int *)(s) - 1) += 1)
#define dec_refcount(s) (*((int *)(s) - 1) -= 1) #define dec_refcount(s) (*((int *)(s) - 1) -= 1)
#define refcount(s) (*((int *)(s) - 1)) #define refcount(s) (*((int *)(s) - 1))
void MkCoercion(t_node **pnd, register t_type *tp);
int ChkVariable(register t_node **expp, int flags);
int ChkCall(t_node **expp);
void TryToString(register t_node *nd, t_type *tp);
/* Generates a set of "size" bytes and increments its reference count. */
arith *MkSet(unsigned int size);
/* Decrements the reference counter of set "s" and if reference count
* is zero, then it frees the memory associated with the set.
*/
void FreeSet(register arith *s);
#endif /* CHK_EXPR_H_ */

View file

@ -15,20 +15,24 @@
#include "parameters.h" #include "parameters.h"
#include "debug.h" #include "debug.h"
#include <em_arith.h>
#include <em_label.h>
#include <em_code.h>
#include <em_abs.h>
#include <assert.h> #include <assert.h>
#include <alloc.h> #include "em_arith.h"
#include "em_label.h"
#include "em_code.h"
#include "em_abs.h"
#include "alloc.h"
#include "code.h"
#include "type.h" #include "type.h"
#include "error.h"
#include "LLlex.h" #include "LLlex.h"
#include "def.h" #include "def.h"
#include "scope.h" #include "scope.h"
#include "desig.h" #include "desig.h"
#include "chk_expr.h"
#include "node.h" #include "node.h"
#include "Lpars.h" #include "Lpars.h"
#include "tmpvar.h"
#include "standards.h" #include "standards.h"
#include "walk.h" #include "walk.h"
@ -37,17 +41,19 @@ extern char options[];
extern t_desig null_desig; extern t_desig null_desig;
int fp_used; int fp_used;
void RangeCheck(); /* Forward declarations */
void CodeParameters(); static void CodeParameters(t_param *, register t_node *);
void CodeCall(); static void CodeStd(t_node *);
static void compare(int, label);
static void truthvalue(int);
static void CodeUoper(register t_node *);
static void CodeSet(register t_node *, int);
static void CodeEl(register t_node *, register t_type *, int);
static void CodeDAddress(t_node *, int);
static void DoHIGH(register t_def *);
CodeConst(cst, size) void CodeConst(arith cst, int size)
arith cst;
int size;
{ {
/* Generate code to push constant "cst" with size "size"
*/
if (size <= (int) word_size) { if (size <= (int) word_size) {
C_loc(cst); C_loc(cst);
} }
@ -59,9 +65,7 @@ CodeConst(cst, size)
} }
} }
void void CodeString(register t_node *nd)
CodeString(nd)
register t_node *nd;
{ {
if (nd->nd_type->tp_fund != T_STRING) { if (nd->nd_type->tp_fund != T_STRING) {
/* Character constant */ /* Character constant */
@ -73,10 +77,7 @@ CodeString(nd)
c_lae_dlb(data_label); c_lae_dlb(data_label);
} }
CodeExpr(nd, ds, true_label, false_label) void CodeExpr(t_node *nd, t_desig *ds, label true_label, label false_label)
register t_node *nd;
register t_desig *ds;
label true_label, false_label;
{ {
register t_type *tp = nd->nd_type; register t_type *tp = nd->nd_type;
@ -173,8 +174,7 @@ CodeExpr(nd, ds, true_label, false_label)
} }
} }
CodeCoercion(t1, t2) void CodeCoercion(t_type *t1, t_type *t2)
t_type *t1, *t2;
{ {
int fund1, fund2; int fund1, fund2;
int sz1 = t1->tp_size; int sz1 = t1->tp_size;
@ -293,13 +293,9 @@ CodeCoercion(t1, t2)
} }
} }
void void CodeCall(t_node *nd)
CodeCall(nd)
register t_node *nd;
{ {
/* Generate code for a procedure call. Checking of parameters
and result is already done.
*/
register t_node *left = nd->nd_LEFT; register t_node *left = nd->nd_LEFT;
t_type *result_tp; t_type *result_tp;
int needs_fn; int needs_fn;
@ -361,10 +357,8 @@ CodeCall(nd)
DoLineno(nd); DoLineno(nd);
} }
void /* Generates code to setup the parameters of a procedure call. */
CodeParameters(param, arg) static void CodeParameters(t_param *param, register t_node *arg)
t_param *param;
register t_node *arg;
{ {
register t_type *tp; register t_type *tp;
register t_type *arg_type; register t_type *arg_type;
@ -445,9 +439,7 @@ CodeParameters(param, arg)
CodePExpr(arg); CodePExpr(arg);
} }
CodePString(nd, tp) void CodePString(t_node *nd, t_type *tp)
t_node *nd;
t_type *tp;
{ {
arith szarg = WA(nd->nd_type->tp_size); arith szarg = WA(nd->nd_type->tp_size);
register arith zersz = WA(tp->tp_size) - szarg; register arith zersz = WA(tp->tp_size) - szarg;
@ -461,9 +453,9 @@ CodePString(nd, tp)
C_loi(szarg); C_loi(szarg);
} }
static
subu(sz)
int sz; static void subu(int sz)
{ {
if (! options['R']) { if (! options['R']) {
C_cal(sz == (int) word_size ? "subuchk" : "subulchk"); C_cal(sz == (int) word_size ? "subuchk" : "subulchk");
@ -471,9 +463,7 @@ subu(sz)
C_sbu((arith) sz); C_sbu((arith) sz);
} }
static static void addu(int sz)
addu(sz)
int sz;
{ {
if (! options['R']) { if (! options['R']) {
C_cal(sz == (int) word_size ? "adduchk" : "addulchk"); C_cal(sz == (int) word_size ? "adduchk" : "addulchk");
@ -481,9 +471,7 @@ addu(sz)
C_adu((arith)sz); C_adu((arith)sz);
} }
static int static int complex_lhs(register t_node *nd)
complex_lhs(nd)
register t_node *nd;
{ {
switch(nd->nd_class) { switch(nd->nd_class) {
case Value: case Value:
@ -498,8 +486,8 @@ complex_lhs(nd)
} }
} }
CodeStd(nd) /* Generate code for internal procedures */
t_node *nd; static void CodeStd(t_node *nd)
{ {
register t_node *arg = nd->nd_RIGHT; register t_node *arg = nd->nd_RIGHT;
register t_node *left = 0; register t_node *left = 0;
@ -654,9 +642,7 @@ CodeStd(nd)
} }
} }
int static int needs_rangecheck(register t_type *tpl, t_type *tpr)
needs_rangecheck(tpl, tpr)
register t_type *tpl, *tpr;
{ {
arith rlo, rhi; arith rlo, rhi;
@ -679,13 +665,8 @@ needs_rangecheck(tpl, tpr)
return 0; return 0;
} }
void void RangeCheck(register t_type *tpl, t_type *tpr)
RangeCheck(tpl, tpr)
register t_type *tpl, *tpr;
{ {
/* Generate a range check if neccessary
*/
arith rlo, rhi; arith rlo, rhi;
if (options['R']) return; if (options['R']) return;
@ -709,8 +690,7 @@ RangeCheck(tpl, tpr)
} }
} }
Operands(nd) void Operands(register t_node *nd)
register t_node *nd;
{ {
CodePExpr(nd->nd_LEFT); CodePExpr(nd->nd_LEFT);
@ -718,10 +698,11 @@ Operands(nd)
DoLineno(nd); DoLineno(nd);
} }
CodeOper(expr, true_label, false_label) void CodeOper(
register t_node *expr; /* the expression tree itself */ register t_node *expr, /* the expression tree itself */
label true_label; label true_label,
label false_label; /* labels to jump to in logical expr's */ label false_label /* labels to jump to in logical expr's */
)
{ {
register t_node *leftop = expr->nd_LEFT; register t_node *leftop = expr->nd_LEFT;
register t_node *rightop = expr->nd_RIGHT; register t_node *rightop = expr->nd_RIGHT;
@ -1019,10 +1000,8 @@ CodeOper(expr, true_label, false_label)
} }
} }
/* compare() serves as an auxiliary function of CodeOper */ /* Serves as an auxiliary function of CodeOper */
compare(relop, lbl) static void compare(int relop, label lbl)
int relop;
register label lbl;
{ {
switch (relop) { switch (relop) {
case '<': case '<':
@ -1048,9 +1027,8 @@ compare(relop, lbl)
} }
} }
/* truthvalue() serves as an auxiliary function of CodeOper */ /* Serves as an auxiliary function of CodeOper */
truthvalue(relop) static void truthvalue(int relop)
int relop;
{ {
switch (relop) { switch (relop) {
case '<': case '<':
@ -1076,8 +1054,9 @@ truthvalue(relop)
} }
} }
CodeUoper(nd)
register t_node *nd; /* Generates code for an unary expression */
void CodeUoper(register t_node *nd)
{ {
register t_type *tp = nd->nd_type; register t_type *tp = nd->nd_type;
@ -1110,8 +1089,7 @@ CodeUoper(nd)
} }
} }
CodeSet(nd, null_set) static void CodeSet(register t_node *nd, int null_set)
register t_node *nd;
{ {
register t_type *tp = nd->nd_type; register t_type *tp = nd->nd_type;
@ -1128,9 +1106,7 @@ CodeSet(nd, null_set)
if (null_set) C_zer(tp->tp_size); if (null_set) C_zer(tp->tp_size);
} }
CodeEl(nd, tp, null_set) static void CodeEl(register t_node *nd, register t_type *tp, int null_set)
register t_node *nd;
register t_type *tp;
{ {
register t_type *eltype = ElementType(tp); register t_type *eltype = ElementType(tp);
@ -1155,12 +1131,9 @@ CodeEl(nd, tp, null_set)
} }
} }
CodePExpr(nd) void CodePExpr(register t_node *nd)
register t_node *nd;
{ {
/* Generate code to push the value of the expression "nd"
on the stack.
*/
t_desig designator; t_desig designator;
designator = null_desig; designator = null_desig;
@ -1168,8 +1141,7 @@ CodePExpr(nd)
CodeValue(&designator, nd->nd_type); CodeValue(&designator, nd->nd_type);
} }
CodeDAddress(nd, chk_controlvar) static void CodeDAddress(t_node *nd, int chk_controlvar)
t_node *nd;
{ {
/* Generate code to push the address of the designator "nd" /* Generate code to push the address of the designator "nd"
on the stack. on the stack.
@ -1195,12 +1167,9 @@ CodeDAddress(nd, chk_controlvar)
} }
} }
CodeDStore(nd) void CodeDStore(register t_node *nd)
register t_node *nd;
{ {
/* Generate code to store the expression on the stack into the
designator "nd".
*/
t_desig designator; t_desig designator;
@ -1210,8 +1179,7 @@ CodeDStore(nd)
CodeStore(&designator, nd->nd_type); CodeStore(&designator, nd->nd_type);
} }
DoHIGH(df) static void DoHIGH(register t_def *df)
register t_def *df;
{ {
/* Get the high index of a conformant array, indicated by "nd". /* Get the high index of a conformant array, indicated by "nd".
The high index is the second field in the descriptor of The high index is the second field in the descriptor of
@ -1235,26 +1203,22 @@ DoHIGH(df)
} }
#ifdef SQUEEZE #ifdef SQUEEZE
c_bra(l) void c_bra(label l)
label l;
{ {
C_bra((label) l); C_bra((label) l);
} }
c_loc(n) void c_loc(int n)
{ {
C_loc((arith) n); C_loc((arith) n);
} }
c_lae_dlb(l) void c_lae_dlb(label l)
label l;
{ {
C_lae_dlb(l, (arith) 0); C_lae_dlb(l, (arith) 0);
} }
CAL(name, ssp) void CAL(char *name, int ssp)
char *name;
int ssp;
{ {
C_cal(name); C_cal(name);
C_asp((arith) ssp); C_asp((arith) ssp);

53
lang/m2/comp/code.h Normal file
View file

@ -0,0 +1,53 @@
/* Copyright (c) 2019 ACK Project.
* See the copyright notice in the ACK home directory,
* in the file "Copyright".
*
* Created on: 2019-02-26
*
*/
#ifndef CODE_H_
#define CODE_H_
#include "parameters.h"
#include <em_arith.h>
#include <em_label.h>
/* Forward declarations. */
typedef struct node t_node;
typedef struct desig t_desig;
typedef struct type t_type;
/* Generate code to push constant "cst" with size "size" bytes. */
void CodeConst(arith cst, int size);
/* Generate constant character or string. */
void CodeString(register t_node *nd);
/* Generate code for an expression contained in "nd". */
void CodeExpr(t_node *nd, t_desig *ds, label true_label, label false_label);
/* Generate implicit type conversion code. */
void CodeCoercion(t_type *t1, t_type *t2);
/* Generate code for a procedure call including parameter setup. Checking of parameters
and result is already done. */
void CodeCall(t_node *nd);
void CodePString(t_node *nd, t_type *tp);
/* Generate a range check if necessary */
void RangeCheck(register t_type *tpl, t_type *tpr);
void CodeOper(register t_node *expr, label true_label, label false_label);
/* Generate code to push the value of the expression "nd"
on the stack. */
void CodePExpr(register t_node *nd);
/* Generate code to store the expression on the stack into the
designator "nd".
*/
void CodeDStore(register t_node *nd);
#ifdef SQUEEZE
void c_bra(label l);
void c_loc(int n);
void c_lae_dlb(label l);
void CAL(char *name, int ssp);
#endif
#endif /* CODE_H_ */

View file

@ -24,7 +24,10 @@
#include "node.h" #include "node.h"
#include "Lpars.h" #include "Lpars.h"
#include "standards.h" #include "standards.h"
#include "cstoper.h"
#include "chk_expr.h"
#include "warning.h" #include "warning.h"
#include "error.h"
extern char *symbol2str(); extern char *symbol2str();
@ -45,19 +48,17 @@ arith min_int[] = { 0L, -128L, -32768L, 0L, -2147483647L-1 };
extern char options[]; extern char options[];
void CutSize(); static void CutSize(register t_node *);
overflow(expp)
t_node *expp; static void overflow(t_node *expp)
{ {
if (expp->nd_type != address_type) { if (expp->nd_type != address_type) {
node_warning(expp, W_ORDINARY, "overflow in constant expression"); node_warning(expp, W_ORDINARY, "overflow in constant expression");
} }
} }
STATIC static void commonbin(t_node **expp)
commonbin(expp)
t_node **expp;
{ {
register t_node *exp = *expp; register t_node *exp = *expp;
t_type *tp = exp->nd_type; t_type *tp = exp->nd_type;
@ -69,11 +70,10 @@ commonbin(expp)
right->nd_type = tp; right->nd_type = tp;
} }
cstunary(expp) void cstunary(t_node **expp)
t_node **expp;
{ {
/* The unary operation in "expp" is performed on the constant /* The unary operation in "expp" is performed on the constant
expression below it, and the result restored in expp. expression below it, and the result stored in expp.
*/ */
register t_node *exp = *expp; register t_node *exp = *expp;
register t_node *right = exp->nd_RIGHT; register t_node *right = exp->nd_RIGHT;
@ -107,9 +107,7 @@ cstunary(expp)
CutSize(*expp); CutSize(*expp);
} }
STATIC static void divide(arith *pdiv, arith *prem)
divide(pdiv, prem)
arith *pdiv, *prem;
{ {
/* Unsigned divide *pdiv by *prem, and store result in *pdiv, /* Unsigned divide *pdiv by *prem, and store result in *pdiv,
remainder in *prem remainder in *prem
@ -121,9 +119,7 @@ divide(pdiv, prem)
*prem = (unsigned arith) o1 % (unsigned arith) o2; *prem = (unsigned arith) o1 % (unsigned arith) o2;
} }
void void cstibin(t_node **expp)
cstibin(expp)
t_node **expp;
{ {
/* The binary operation in "expp" is performed on the constant /* The binary operation in "expp" is performed on the constant
expressions below it, and the result restored in expp. expressions below it, and the result restored in expp.
@ -232,8 +228,7 @@ cstibin(expp)
CutSize(*expp); CutSize(*expp);
} }
cstfbin(expp) void cstfbin(t_node **expp)
t_node **expp;
{ {
/* The binary operation in "expp" is performed on the constant /* The binary operation in "expp" is performed on the constant
expressions below it, and the result restored in expp. expressions below it, and the result restored in expp.
@ -320,9 +315,7 @@ cstfbin(expp)
CutSize(exp); CutSize(exp);
} }
void void cstubin(t_node **expp)
cstubin(expp)
t_node **expp;
{ {
/* The binary operation in "expp" is performed on the constant /* The binary operation in "expp" is performed on the constant
expressions below it, and the result restored in expressions below it, and the result restored in
@ -427,9 +420,7 @@ cstubin(expp)
CutSize(exp); CutSize(exp);
} }
void void cstset(t_node **expp)
cstset(expp)
t_node **expp;
{ {
extern arith *MkSet(); extern arith *MkSet();
register t_node *exp = *expp; register t_node *exp = *expp;
@ -544,8 +535,7 @@ cstset(expp)
FreeNode(exp); FreeNode(exp);
} }
cstcall(expp, call) void cstcall(t_node **expp, int call)
t_node **expp;
{ {
/* a standard procedure call is found that can be evaluated /* a standard procedure call is found that can be evaluated
compile time, so do so. compile time, so do so.
@ -619,9 +609,7 @@ cstcall(expp, call)
} }
} }
void static void CutSize(register t_node *expr)
CutSize(expr)
register t_node *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.
@ -640,7 +628,7 @@ CutSize(expr)
} }
} }
InitCst() void InitCst(void)
{ {
register int i = 0; register int i = 0;
#ifndef NOCROSS #ifndef NOCROSS

29
lang/m2/comp/cstoper.h Normal file
View file

@ -0,0 +1,29 @@
/* Copyright (c) 2019 ACK Project.
* See the copyright notice in the ACK home directory,
* in the file "Copyright".
*
* Created on: 2019-02-25
*
*/
#ifndef CSTOPER_H_
#define CSTOPER_H_
/* Compile time constant evaluations */
void cstunary(t_node **expp);
void cstibin(t_node **expp);
void cstfbin(t_node **expp);
void cstubin(t_node **expp);
/** Evaluates the constant set operators at compile time
* and returns the result in "expp".
*/
void cstset(t_node **expp);
/* Evaluates the result of internal procedures on constants
* at compile time, and returns the result in "expp".
*/
void cstcall(t_node **expp, int call);
/* Compile time constant evaluator system initialization. */
void InitCst(void);
#endif /* CSTOPER_H_ */

View file

@ -13,10 +13,10 @@
#include "parameters.h" #include "parameters.h"
#include "debug.h" #include "debug.h"
#include <em_arith.h>
#include <em_label.h>
#include <alloc.h>
#include <assert.h> #include <assert.h>
#include "em_arith.h"
#include "em_label.h"
#include "alloc.h"
#include "idf.h" #include "idf.h"
#include "LLlex.h" #include "LLlex.h"
@ -24,8 +24,11 @@
#include "type.h" #include "type.h"
#include "scope.h" #include "scope.h"
#include "node.h" #include "node.h"
#include "enter.h"
#include "error.h"
#include "misc.h" #include "misc.h"
#include "main.h" #include "main.h"
#include "typequiv.h"
#include "chk_expr.h" #include "chk_expr.h"
#include "warning.h" #include "warning.h"

View file

@ -14,37 +14,41 @@
#include "parameters.h" #include "parameters.h"
#include "debug.h" #include "debug.h"
#include <alloc.h>
#include <em_arith.h>
#include <em_label.h>
#include <em_code.h>
#include <assert.h> #include <assert.h>
#include "alloc.h"
#include "em_arith.h"
#include "em_label.h"
#include "em_code.h"
#include "typequiv.h"
#include "LLlex.h" #include "LLlex.h"
#include "main.h" #include "main.h"
#include "def.h" #include "def.h"
#include "type.h" #include "type.h"
#include "idf.h" #include "idf.h"
#include "print.h"
#include "scope.h" #include "scope.h"
#include "lookup.h"
#include "node.h" #include "node.h"
#include "misc.h"
#include "Lpars.h" #include "Lpars.h"
#include "warning.h" #include "warning.h"
#include "error.h"
extern char *sprint();
STATIC
internal(c) static void internal(register char *c)
register char *c;
{ {
if (options['x']) { if (options['x'])
{
C_exp(c); C_exp(c);
} }
else C_inp(c); else
C_inp(c);
} }
STATIC static void DefInFront(register t_def *df)
DefInFront(df)
register t_def *df;
{ {
/* Put definition "df" in front of the list of definitions /* Put definition "df" in front of the list of definitions
in its scope. in its scope.
@ -53,13 +57,16 @@ DefInFront(df)
*/ */
register t_def *df1 = df->df_scope->sc_def; register t_def *df1 = df->df_scope->sc_def;
if (df1 != df) { if (df1 != df)
{
/* Definition "df" is not in front of the list /* Definition "df" is not in front of the list
*/ */
while (df1) { while (df1)
{
/* Find definition "df" /* Find definition "df"
*/ */
if (df1->df_nextinscope == df) { if (df1->df_nextinscope == df)
{
/* It already was in the list. Remove it /* It already was in the list. Remove it
*/ */
df1->df_nextinscope = df->df_nextinscope; df1->df_nextinscope = df->df_nextinscope;
@ -75,10 +82,7 @@ DefInFront(df)
} }
} }
t_def * t_def *MkDef(register t_idf *id, register t_scope *scope, int kind)
MkDef(id, scope, kind)
register t_idf *id;
register t_scope *scope;
{ {
/* Create a new definition structure in scope "scope", with /* Create a new definition structure in scope "scope", with
id "id" and kind "kind". id "id" and kind "kind".
@ -91,8 +95,10 @@ MkDef(id, scope, kind)
df->df_kind = kind; df->df_kind = kind;
df->df_next = id->id_def; df->df_next = id->id_def;
id->id_def = df; id->id_def = df;
if (kind == D_ERROR || kind == D_FORWARD) df->df_type = error_type; if (kind == D_ERROR || kind == D_FORWARD)
if (kind & (D_TYPE|D_PROCEDURE|D_CONST)) { df->df_type = error_type;
if (kind & (D_TYPE | D_PROCEDURE | D_CONST))
{
df->df_flags = D_DEFINED; df->df_flags = D_DEFINED;
} }
@ -103,11 +109,7 @@ MkDef(id, scope, kind)
return df; return df;
} }
t_def * t_def *define(register t_idf *id, register t_scope *scope, int kind)
define(id, scope, kind)
register t_idf *id;
register t_scope *scope;
int kind;
{ {
/* Declare an identifier in a scope, but first check if it /* Declare an identifier in a scope, but first check if it
already has been defined. already has been defined.
@ -119,12 +121,16 @@ define(id, scope, kind)
DO_DEBUG(options['S'], print("define %s, %x\n", id->id_text, kind)); DO_DEBUG(options['S'], print("define %s, %x\n", id->id_text, kind));
df = lookup(id, scope, D_IMPORT, 0); df = lookup(id, scope, D_IMPORT, 0);
if ( /* Already in this scope */ if ( /* Already in this scope */
df df)
) { {
switch(df->df_kind) { switch (df->df_kind)
{
case D_INUSE: case D_INUSE:
if (kind != D_INUSE && kind != D_ERROR) { if (kind != D_INUSE && kind != D_ERROR)
error("identifier \"%s\" already used; may not be redefined in this scope", df->df_idf->id_text); {
error(
"identifier \"%s\" already used; may not be redefined in this scope",
df->df_idf->id_text);
df->df_kind = D_ERROR; df->df_kind = D_ERROR;
break; break;
} }
@ -134,8 +140,9 @@ define(id, scope, kind)
/* An opaque type. We may now have found the /* An opaque type. We may now have found the
definition of this type. definition of this type.
*/ */
if (kind == D_TYPE && df->df_scope == CurrentScope && if (kind == D_TYPE && df->df_scope == CurrentScope
!DefinitionModule) { && !DefinitionModule)
{
df->df_kind = D_TYPE; df->df_kind = D_TYPE;
return df; return df;
} }
@ -146,11 +153,13 @@ define(id, scope, kind)
another one, or we may have found the definition another one, or we may have found the definition
for this module. for this module.
*/ */
if (kind & (D_FORWMODULE|D_FORWARD)) { if (kind & (D_FORWMODULE | D_FORWARD))
{
return df; return df;
} }
if (kind == D_MODULE) { if (kind == D_MODULE)
{
FreeNode(df->for_node); FreeNode(df->for_node);
df->mod_vis = df->for_vis; df->mod_vis = df->for_vis;
df->df_kind = kind; df->df_kind = kind;
@ -160,10 +169,12 @@ define(id, scope, kind)
break; break;
case D_TYPE: case D_TYPE:
if (kind == D_FORWTYPE) return df; if (kind == D_FORWTYPE)
return df;
break; break;
case D_FORWTYPE: case D_FORWTYPE:
if (kind & (D_FORWTYPE|D_TYPE)) return df; if (kind & (D_FORWTYPE | D_TYPE))
return df;
error("identifier \"%s\" must be a type", id->id_text); error("identifier \"%s\" must be a type", id->id_text);
df->df_kind = D_ERROR; df->df_kind = D_ERROR;
break; break;
@ -171,22 +182,25 @@ define(id, scope, kind)
/* A forward reference, for which we may now have /* A forward reference, for which we may now have
found a definition. found a definition.
*/ */
if (! (kind & (D_FORWARD | D_FORWMODULE))) { if (!(kind & (D_FORWARD | D_FORWMODULE)))
{
FreeNode(df->for_node); FreeNode(df->for_node);
} }
df->df_kind = D_ERROR; /* avoiding error message */ df->df_kind = D_ERROR; /* avoiding error message */
break; break;
} }
if (kind != D_ERROR && df->df_kind != D_ERROR) { if (kind != D_ERROR && df->df_kind != D_ERROR)
{
/* Avoid spurious error messages /* Avoid spurious error messages
*/ */
error("identifier \"%s\" already declared", error("identifier \"%s\" already declared", id->id_text);
id->id_text);
} }
if (df->df_scope == scope || df->df_kind == D_ERROR) { if (df->df_scope == scope || df->df_kind == D_ERROR)
{
df->df_kind = kind; df->df_kind = kind;
if (kind & (D_TYPE|D_PROCEDURE|D_CONST)) { if (kind & (D_TYPE | D_PROCEDURE | D_CONST))
{
df->df_flags = D_DEFINED; df->df_flags = D_DEFINED;
} }
@ -197,8 +211,7 @@ define(id, scope, kind)
return MkDef(id, scope, kind); return MkDef(id, scope, kind);
} }
end_definition_list(pdf) void end_definition_list(register t_def **pdf)
register t_def **pdf;
{ {
/* Remove all imports from a definition module. This is /* Remove all imports from a definition module. This is
neccesary because the implementation module might import neccesary because the implementation module might import
@ -207,33 +220,40 @@ end_definition_list(pdf)
*/ */
register t_def *df; register t_def *df;
while (df = *pdf) { while ( (df = *pdf) )
if (df->df_kind & D_IMPORTED) { {
if (! (df->df_flags & D_USED)) { if (df->df_kind & D_IMPORTED)
warning(W_ORDINARY, "identifier \"%s\" imported but not used", df->df_idf->id_text); {
if (!(df->df_flags & D_USED))
{
warning(W_ORDINARY, "identifier \"%s\" imported but not used",
df->df_idf->id_text);
} }
RemoveFromIdList(df); RemoveFromIdList(df);
*pdf = df->df_nextinscope; *pdf = df->df_nextinscope;
free_def(df); free_def(df);
} }
else { else
{
df->df_flags |= D_QEXPORTED; df->df_flags |= D_QEXPORTED;
pdf = &(df->df_nextinscope); pdf = &(df->df_nextinscope);
} }
} }
} }
RemoveFromIdList(df) void RemoveFromIdList(register t_def *df)
register t_def *df;
{ {
/* Remove definition "df" from the definition list /* Remove definition "df" from the definition list
*/ */
register t_idf *id = df->df_idf; register t_idf *id = df->df_idf;
register t_def *df1; register t_def *df1;
if ((df1 = id->id_def) == df) id->id_def = df->df_next; if ((df1 = id->id_def) == df)
else { id->id_def = df->df_next;
while (df1->df_next != df) { else
{
while (df1->df_next != df)
{
assert(df1->df_next != 0); assert(df1->df_next != 0);
df1 = df1->df_next; df1 = df1->df_next;
} }
@ -241,9 +261,7 @@ RemoveFromIdList(df)
} }
} }
t_def * t_def * DeclProc(int type, register t_idf *id)
DeclProc(type, id)
register t_idf *id;
{ {
/* A procedure is declared, either in a definition or a program /* A procedure is declared, either in a definition or a program
module. Create a def structure for it (if neccessary). module. Create a def structure for it (if neccessary).
@ -256,38 +274,45 @@ DeclProc(type, id)
assert(type & (D_PROCEDURE | D_PROCHEAD)); assert(type & (D_PROCEDURE | D_PROCHEAD));
if (type == D_PROCHEAD) { if (type == D_PROCHEAD)
{
/* In a definition module /* In a definition module
*/ */
df = define(id, CurrentScope, type); df = define(id, CurrentScope, type);
df->for_node = dot2leaf(Name); df->for_node = dot2leaf(Name);
df->df_flags |= D_USED | D_DEFINED; df->df_flags |= D_USED | D_DEFINED;
if (CurrentScope->sc_definedby->df_flags & D_FOREIGN) { if (CurrentScope->sc_definedby->df_flags & D_FOREIGN)
{
df->prc_name = id->id_text; df->prc_name = id->id_text;
} }
else { else
sprint(buf,"%s_%s",CurrentScope->sc_name,id->id_text); {
df->prc_name = Salloc(buf, (unsigned) (strlen(buf)+1)); sprint(buf, "%s_%s", CurrentScope->sc_name, id->id_text);
df->prc_name = Salloc(buf, (unsigned) (strlen(buf) + 1));
} }
if (CurrVis == Defined->mod_vis) { if (CurrVis == Defined->mod_vis)
{
/* The current module will define this routine. /* The current module will define this routine.
make sure the name is exported. make sure the name is exported.
*/ */
C_exp(df->prc_name); C_exp(df->prc_name);
} }
} }
else { else
{
df = lookup(id, CurrentScope, D_IMPORTED, 0); df = lookup(id, CurrentScope, D_IMPORTED, 0);
if (df && df->df_kind == D_PROCHEAD) { if (df && df->df_kind == D_PROCHEAD)
{
/* C_exp already generated when we saw the definition /* C_exp already generated when we saw the definition
in the definition module in the definition module
*/ */
DefInFront(df); DefInFront(df);
} }
else { else
{
df = define(id, CurrentScope, type); df = define(id, CurrentScope, type);
sprint(buf,"_%d_%s",++nmcount,id->id_text); sprint(buf, "_%d_%s", ++nmcount, id->id_text);
df->prc_name = Salloc(buf, (unsigned)(strlen(buf)+1)); df->prc_name = Salloc(buf, (unsigned) (strlen(buf) + 1));
internal(buf); internal(buf);
df->df_flags |= D_DEFINED; df->df_flags |= D_DEFINED;
} }
@ -301,9 +326,7 @@ DeclProc(type, id)
return df; return df;
} }
EndProc(df, id) void EndProc(register t_def *df, t_idf *id)
register t_def *df;
t_idf *id;
{ {
/* The end of a procedure declaration. /* The end of a procedure declaration.
Check that the closing identifier matches the name of the Check that the closing identifier matches the name of the
@ -313,16 +336,15 @@ EndProc(df, id)
extern int return_occurred; extern int return_occurred;
match_id(id, df->df_idf); match_id(id, df->df_idf);
close_scope(SC_CHKFORW|SC_REVERSE); close_scope(SC_CHKFORW | SC_REVERSE);
if (! return_occurred && ResultType(df->df_type)) { if (!return_occurred && ResultType(df->df_type))
{
error("function procedure %s does not return a value", error("function procedure %s does not return a value",
df->df_idf->id_text); df->df_idf->id_text);
} }
} }
t_def * t_def * DefineLocalModule(t_idf *id)
DefineLocalModule(id)
t_idf *id;
{ {
/* Create a definition for a local module. Also give it /* Create a definition for a local module. Also give it
a name to be used for code generation. a name to be used for code generation.
@ -335,7 +357,8 @@ DefineLocalModule(id)
sprint(buf, "_%d%s_", ++modulecount, id->id_text); sprint(buf, "_%d%s_", ++modulecount, id->id_text);
if (!df->mod_vis) { if (!df->mod_vis)
{
/* We never saw the name of this module before. Create a /* We never saw the name of this module before. Create a
scope for it. scope for it.
*/ */
@ -362,22 +385,20 @@ DefineLocalModule(id)
return df; return df;
} }
CheckWithDef(df, tp) void CheckWithDef(register t_def *df, t_type *tp)
register t_def *df;
t_type *tp;
{ {
/* Check the header of a procedure declaration against a /* Check the header of a procedure declaration against a
possible earlier definition in the definition module. possible earlier definition in the definition module.
*/ */
if (df->df_kind == D_PROCHEAD && if (df->df_kind == D_PROCHEAD && df->df_type && df->df_type != error_type)
df->df_type && {
df->df_type != error_type) {
/* We already saw a definition of this type /* We already saw a definition of this type
in the definition module. in the definition module.
*/ */
if (!TstProcEquiv(tp, df->df_type)) { if (!TstProcEquiv(tp, df->df_type))
{
error("inconsistent procedure declaration for \"%s\"", error("inconsistent procedure declaration for \"%s\"",
df->df_idf->id_text); df->df_idf->id_text);
} }
@ -388,8 +409,7 @@ CheckWithDef(df, tp)
} }
#ifdef DEBUG #ifdef DEBUG
PrDef(df) void PrDef(register t_def *df)
register t_def *df;
{ {
print("n: %s, k: %d\n", df->df_idf->id_text, df->df_kind); print("n: %s, k: %d\n", df->df_idf->id_text, df->df_kind);
} }

View file

@ -4,6 +4,8 @@
* *
* Author: Ceriel J.H. Jacobs * Author: Ceriel J.H. Jacobs
*/ */
#ifndef DEF_H_
#define DEF_H_
/* I D E N T I F I E R D E S C R I P T O R S T R U C T U R E */ /* I D E N T I F I E R D E S C R I P T O R S T R U C T U R E */
@ -132,12 +134,20 @@ struct def { /* list of definitions for a name */
typedef struct def t_def; typedef struct def t_def;
/* ALLOCDEF "def" 50 */ /* ALLOCDEF "def" 50 */
extern t_def
*define(),
*DefineLocalModule(),
*MkDef(),
*DeclProc(),
*lookup(),
*lookfor();
#define NULLDEF ((t_def *) 0) #define NULLDEF ((t_def *) 0)
typedef struct scope t_scope;
typedef struct idf t_idf;
typedef struct type t_type;
t_def *MkDef(register t_idf *id, register t_scope *scope, int kind);
t_def *define(register t_idf *id, register t_scope *scope, int kind);
void RemoveFromIdList(register t_def *df);
t_def * DeclProc(int type, register t_idf *id);
void EndProc(register t_def *df, t_idf *id);
t_def * DefineLocalModule(t_idf *id);
void CheckWithDef(register t_def *df, t_type *tp);
void end_definition_list(register t_def **pdf);
#endif /* DEF_H_ */

View file

@ -26,9 +26,12 @@
#include "f_info.h" #include "f_info.h"
#include "idf.h" #include "idf.h"
#include "input.h" #include "input.h"
#include "error.h"
#include "main.h" #include "main.h"
#include "misc.h" #include "misc.h"
#include "node.h" #include "node.h"
#include "lookup.h"
#include "main.h"
#include "scope.h" #include "scope.h"
#include "type.h" #include "type.h"
@ -36,13 +39,13 @@
size_t sys_filesize(); size_t sys_filesize();
#endif #endif
extern void DefModule(void); /* Lpars */
t_idf* DefId; t_idf* DefId;
char* char* getwdir(register char *fn)
getwdir(fn) register char* fn;
{ {
register char* p; register char* p;
char* strrchr();
while ((p = strrchr(fn, '/')) && *(p + 1) == '\0') while ((p = strrchr(fn, '/')) && *(p + 1) == '\0')
{ {
@ -60,8 +63,7 @@ char*
return ""; return "";
} }
STATIC int static int GetFile(char *name)
GetFile(name) char* name;
{ {
/* Try to find a file with basename "name" and extension ".def", /* Try to find a file with basename "name" and extension ".def",
in the directories mentioned in "DEFPATH". in the directories mentioned in "DEFPATH".
@ -88,8 +90,7 @@ GetFile(name) char* name;
return 1; return 1;
} }
t_def* t_def* GetDefinitionModule(register t_idf* id, int incr)
GetDefinitionModule(id, incr) register t_idf* id;
{ {
/* Return a pointer to the "def" structure of the definition /* Return a pointer to the "def" structure of the definition
module indicated by "id". module indicated by "id".

View file

@ -19,11 +19,11 @@
#include "parameters.h" #include "parameters.h"
#include "debug.h" #include "debug.h"
#include <em_arith.h>
#include <em_label.h>
#include <em_code.h>
#include <assert.h> #include <assert.h>
#include <alloc.h> #include "em_arith.h"
#include "em_label.h"
#include "em_code.h"
#include "alloc.h"
#include "type.h" #include "type.h"
#include "LLlex.h" #include "LLlex.h"
@ -32,16 +32,15 @@
#include "desig.h" #include "desig.h"
#include "node.h" #include "node.h"
#include "warning.h" #include "warning.h"
#include "error.h"
#include "code.h"
#include "tmpvar.h"
#include "walk.h" #include "walk.h"
extern int proclevel; extern int proclevel;
extern arith NewPtr();
extern char options[]; extern char options[];
int static int WordOrDouble(t_desig *ds, arith size)
WordOrDouble(ds, size)
t_desig *ds;
arith size;
{ {
/* Check if designator is suitable for word or double-word /* Check if designator is suitable for word or double-word
operation operation
@ -53,8 +52,7 @@ WordOrDouble(ds, size)
return 0; return 0;
} }
LOL(offset, size) void LOL(arith offset, arith size)
arith offset, size;
{ {
if (size == word_size) { if (size == word_size) {
C_lol(offset); C_lol(offset);
@ -68,8 +66,7 @@ LOL(offset, size)
} }
} }
STL(offset, size) void STL(arith offset, arith size)
arith offset, size;
{ {
if (size == word_size) { if (size == word_size) {
C_stl(offset); C_stl(offset);
@ -83,10 +80,7 @@ STL(offset, size)
} }
} }
int int DoLoad(register t_desig *ds, arith size)
DoLoad(ds, size)
register t_desig *ds;
arith size;
{ {
/* Try to load designator with word or double-word operation. /* Try to load designator with word or double-word operation.
Return 0 if not done Return 0 if not done
@ -110,10 +104,7 @@ DoLoad(ds, size)
return 1; return 1;
} }
int int DoStore(register t_desig *ds, arith size)
DoStore(ds, size)
register t_desig *ds;
arith size;
{ {
/* Try to store designator with word or double-word operation. /* Try to store designator with word or double-word operation.
Return 0 if not done Return 0 if not done
@ -161,9 +152,7 @@ DoStore(ds, size)
multiple of word_size only multiple of word_size only
*/ */
STATIC int static int suitable_move(register t_type *tp)
suitable_move(tp)
register t_type *tp;
{ {
/* Find out how to load or store the value indicated by "ds". /* Find out how to load or store the value indicated by "ds".
There are four ways: There are four ways:
@ -181,9 +170,7 @@ suitable_move(tp)
return USE_BLM; return USE_BLM;
} }
CodeValue(ds, tp) void CodeValue(register t_desig *ds, register t_type *tp)
register t_desig *ds;
register t_type *tp;
{ {
/* Generate code to load the value of the designator described /* Generate code to load the value of the designator described
in "ds". in "ds".
@ -246,8 +233,7 @@ CodeValue(ds, tp)
ds->dsg_kind = DSG_LOADED; ds->dsg_kind = DSG_LOADED;
} }
ChkForFOR(nd) void ChkForFOR(register t_node *nd)
register t_node *nd;
{ {
/* Check for an assignment to a FOR-loop control variable /* Check for an assignment to a FOR-loop control variable
*/ */
@ -264,9 +250,7 @@ ChkForFOR(nd)
} }
} }
CodeStore(ds, tp) void CodeStore(register t_desig *ds, register t_type *tp)
register t_desig *ds;
register t_type *tp;
{ {
/* Generate code to store the value on the stack in the designator /* Generate code to store the value on the stack in the designator
described in "ds" described in "ds"
@ -311,9 +295,7 @@ CodeStore(ds, tp)
ds->dsg_kind = DSG_INIT; ds->dsg_kind = DSG_INIT;
} }
CodeCopy(lhs, rhs, sz, psize) void CodeCopy(register t_desig *lhs, register t_desig *rhs, arith sz, arith *psize)
register t_desig *lhs, *rhs;
arith sz, *psize;
{ {
/* Do part of a copy, which is assumed to be "reasonable", /* Do part of a copy, which is assumed to be "reasonable",
so that it can be done with LOI/STI or BLM. so that it can be done with LOI/STI or BLM.
@ -338,10 +320,7 @@ CodeCopy(lhs, rhs, sz, psize)
t_desig null_desig; t_desig null_desig;
CodeMove(rhs, left, rtp) void CodeMove(register t_desig *rhs, register t_node *left, t_type *rtp)
register t_desig *rhs;
register t_node *left;
t_type *rtp;
{ {
/* Generate code for an assignment. Testing of type /* Generate code for an assignment. Testing of type
compatibility and the like is already done. compatibility and the like is already done.
@ -440,8 +419,7 @@ CodeMove(rhs, left, rtp)
} }
} }
CodeAddress(ds) void CodeAddress(register t_desig *ds)
register t_desig *ds;
{ {
/* Generate code to load the address of the designator described /* Generate code to load the address of the designator described
in "ds" in "ds"
@ -481,9 +459,7 @@ CodeAddress(ds)
ds->dsg_kind = DSG_PLOADED; ds->dsg_kind = DSG_PLOADED;
} }
CodeFieldDesig(df, ds) void CodeFieldDesig(register t_def *df, register t_desig *ds)
register t_def *df;
register t_desig *ds;
{ {
/* Generate code for a field designator. Only the code common for /* Generate code for a field designator. Only the code common for
address as well as value computation is generated, and the address as well as value computation is generated, and the
@ -533,10 +509,7 @@ CodeFieldDesig(df, ds)
} }
} }
void void CodeVarDesig(register t_def *df, register t_desig *ds)
CodeVarDesig(df, ds)
register t_def *df;
register t_desig *ds;
{ {
/* Generate code for a variable represented by a "def" structure. /* Generate code for a variable represented by a "def" structure.
Of course, there are numerous cases: the variable is local, Of course, there are numerous cases: the variable is local,
@ -612,9 +585,7 @@ CodeVarDesig(df, ds)
ds->dsg_def = df; ds->dsg_def = df;
} }
CodeDesig(nd, ds) void CodeDesig(register t_node *nd, register t_desig *ds)
register t_node *nd;
register t_desig *ds;
{ {
/* Generate code for a designator. Use divide and conquer /* Generate code for a designator. Use divide and conquer
principle principle

View file

@ -4,11 +4,15 @@
* *
* Author: Ceriel J.H. Jacobs * Author: Ceriel J.H. Jacobs
*/ */
#ifndef DESIG_H_
#define DESIG_H_
/* D E S I G N A T O R D E S C R I P T I O N S */ /* D E S I G N A T O R D E S C R I P T I O N S */
/* $Id$ */ /* $Id$ */
#include <em_arith.h>
/* Generating code for designators is not particularly easy, especially if /* Generating code for designators is not particularly easy, especially if
you don't know wether you want the address or the value. you don't know wether you want the address or the value.
The next structure is used to generate code for designators. The next structure is used to generate code for designators.
@ -65,3 +69,21 @@ struct withdesig {
extern struct withdesig *WithDesigs; extern struct withdesig *WithDesigs;
#define NO_LABEL ((label) 0) #define NO_LABEL ((label) 0)
typedef struct type t_type;
typedef struct node t_node;
void LOL(arith offset, arith size);
void STL(arith offset, arith size);
void CodeValue(register t_desig *ds, register t_type *tp);
void ChkForFOR(register t_node *nd);
void CodeStore(register t_desig *ds, register t_type *tp);
void CodeCopy(register t_desig *lhs, register t_desig *rhs, arith sz, arith *psize);
void CodeMove(register t_desig *rhs, register t_node *left, t_type *rtp);
void CodeAddress(register t_desig *ds);
void CodeFieldDesig(register t_def *df, register t_desig *ds);
void CodeVarDesig(register t_def *df, register t_desig *ds);
void CodeDesig(register t_node *nd, register t_desig *ds);
#endif /* DESIG_H_ */

View file

@ -22,20 +22,24 @@
#include "em_code.h" #include "em_code.h"
#include "assert.h" #include "assert.h"
#include "enter.h"
#include "idf.h" #include "idf.h"
#include "LLlex.h" #include "LLlex.h"
#include "def.h" #include "def.h"
#include "type.h" #include "type.h"
#include "error.h"
#include "scope.h" #include "scope.h"
#include "node.h" #include "node.h"
#include "stab.h"
#include "main.h" #include "main.h"
#include "lookup.h"
#include "misc.h" #include "misc.h"
#include "f_info.h" #include "f_info.h"
t_def *
Enter(name, kind, type, pnam) static t_def *DoImport(register t_def *, t_scope *, int);
char *name;
t_type *type; t_def *Enter(char *name, int kind, t_type *type, int pnam)
{ {
/* Enter a definition for "name" with kind "kind" and type /* Enter a definition for "name" with kind "kind" and type
"type" in the Current Scope. If it is a standard name, also "type" in the Current Scope. If it is a standard name, also
@ -52,10 +56,7 @@ Enter(name, kind, type, pnam)
return df; return df;
} }
t_def * t_def *EnterType(char *name, t_type *type)
EnterType(name, type)
char *name;
t_type *type;
{ {
/* Enter a type definition for "name" and type /* Enter a type definition for "name" and type
"type" in the Current Scope. "type" in the Current Scope.
@ -64,9 +65,7 @@ EnterType(name, type)
return Enter(name, D_TYPE, type, 0); return Enter(name, D_TYPE, type, 0);
} }
EnterEnumList(Idlist, type) void EnterEnumList(t_node *Idlist, register t_type *type)
t_node *Idlist;
register t_type *type;
{ {
/* Put a list of enumeration literals in the symbol table. /* Put a list of enumeration literals in the symbol table.
They all have type "type". They all have type "type".
@ -92,11 +91,8 @@ EnterEnumList(Idlist, type)
FreeNode(Idlist); FreeNode(Idlist);
} }
EnterFieldList(Idlist, type, scope, addr) void EnterFieldList(t_node *Idlist, register t_type *type, t_scope *scope,
t_node *Idlist; arith *addr)
register t_type *type;
t_scope *scope;
arith *addr;
{ {
/* Put a list of fields in the symbol table. /* Put a list of fields in the symbol table.
They all have type "type", and are put in scope "scope". They all have type "type", and are put in scope "scope".
@ -116,15 +112,8 @@ EnterFieldList(Idlist, type, scope, addr)
FreeNode(Idlist); FreeNode(Idlist);
} }
EnterVarList(Idlist, type, local) void EnterVarList(t_node *Idlist, t_type *type, int local)
t_node *Idlist;
t_type *type;
{ {
/* Enter a list of identifiers representing variables into the
name list. "type" represents the type of the variables.
"local" is set if the variables are declared local to a
procedure.
*/
register t_def *df; register t_def *df;
register t_node *idlist = Idlist; register t_node *idlist = Idlist;
register t_scopelist *sc = CurrVis; register t_scopelist *sc = CurrVis;
@ -191,17 +180,12 @@ EnterVarList(Idlist, type, local)
FreeNode(Idlist); FreeNode(Idlist);
} }
EnterParamList(ppr, Idlist, type, VARp, off) void EnterParamList(t_param **ppr,
t_param **ppr; t_node *Idlist,
t_node *Idlist; t_type *type,
t_type *type; int VARp,
int VARp; arith *off)
arith *off;
{ {
/* Create (part of) a parameterlist of a procedure.
"ids" indicates the list of identifiers, "tp" their type, and
"VARp" indicates D_VARPAR or D_VALPAR.
*/
register t_param *pr; register t_param *pr;
register t_def *df; register t_def *df;
register t_node *idlist = Idlist; register t_node *idlist = Idlist;
@ -245,12 +229,8 @@ EnterParamList(ppr, Idlist, type, VARp, off)
FreeNode(Idlist); FreeNode(Idlist);
} }
STATIC t_def *DoImport();
void static void ImportEffects(register t_def *idef, t_scope *scope, int flag)
ImportEffects(idef, scope, flag)
register t_def *idef;
t_scope *scope;
{ {
/* Handle side effects of an import: /* Handle side effects of an import:
- a module could have unqualified exports ??? - a module could have unqualified exports ???
@ -316,10 +296,7 @@ ImportEffects(idef, scope, flag)
} }
} }
STATIC t_def * static t_def *DoImport(register t_def *df, t_scope *scope, int flag)
DoImport(df, scope, flag)
register t_def *df;
t_scope *scope;
{ {
/* Definition "df" is imported to scope "scope". /* Definition "df" is imported to scope "scope".
*/ */
@ -332,10 +309,7 @@ DoImport(df, scope, flag)
} }
STATIC static void ForwModule(register t_def *df, t_node *nd)
ForwModule(df, nd)
register t_def *df;
t_node *nd;
{ {
/* An import is done from a not yet defined module "df". /* An import is done from a not yet defined module "df".
We could also end up here for not found DEFINITION MODULES. We could also end up here for not found DEFINITION MODULES.
@ -360,10 +334,7 @@ ForwModule(df, nd)
df->for_node = nd; df->for_node = nd;
} }
STATIC t_def * static t_def *ForwDef(register t_node *ids, t_scope *scope)
ForwDef(ids, scope)
register t_node *ids;
t_scope *scope;
{ {
/* Enter a forward definition of "ids" in scope "scope", /* Enter a forward definition of "ids" in scope "scope",
if it is not already defined. if it is not already defined.
@ -379,14 +350,8 @@ ForwDef(ids, scope)
return df; return df;
} }
EnterExportList(Idlist, qualified) void EnterExportList(t_node *Idlist, int qualified)
t_node *Idlist;
{ {
/* From the current scope, the list of identifiers "ids" is
exported. Note this fact. If the export is not qualified, make
all the "ids" visible in the enclosing scope by defining them
in this scope as "imported".
*/
register t_node *idlist = Idlist; register t_node *idlist = Idlist;
register t_def *df, *df1; register t_def *df, *df1;
@ -461,8 +426,7 @@ EnterExportList(Idlist, qualified)
FreeNode(Idlist); FreeNode(Idlist);
} }
CheckForImports(df) void CheckForImports(t_def *df)
t_def *df;
{ {
/* We have a definition for "df"; check all imports of /* We have a definition for "df"; check all imports of
it for side-effects it for side-effects
@ -482,11 +446,7 @@ CheckForImports(df)
} }
} }
void void EnterFromImportList(t_node *idlist, t_def *FromDef, t_node *FromId)
EnterFromImportList(idlist, FromDef, FromId)
register t_node *idlist;
register t_def *FromDef;
t_node *FromId;
{ {
/* Import the list Idlist from the module indicated by Fromdef. /* Import the list Idlist from the module indicated by Fromdef.
*/ */
@ -544,9 +504,7 @@ node_error(FromId,"identifier \"%s\" does not represent a module",module_name);
FreeNode(FromId); FreeNode(FromId);
} }
EnterImportList(idlist, local, sc) void EnterImportList(t_node *idlist, int local, t_scope *sc)
register t_node *idlist;
t_scope *sc;
{ {
/* Import "idlist" from scope "sc". /* Import "idlist" from scope "sc".
If the import is not local, definition modules must be read If the import is not local, definition modules must be read

46
lang/m2/comp/enter.h Normal file
View file

@ -0,0 +1,46 @@
/* Copyright (c) 2019 ACK Project.
* See the copyright notice in the ACK home directory,
* in the file "Copyright".
*
* Created on: 2019-02-27
*
*/
#ifndef ENTER_H_
#define ENTER_H_
/* Forward declarations. */
typedef struct type t_type;
typedef struct def t_def;
typedef struct node t_node;
typedef struct scope t_scope;
typedef struct paramlist t_param;
t_def *Enter(char *name, int kind, t_type *type, int pnam);
t_def *EnterType(char *name, t_type *type);
void EnterEnumList(t_node *Idlist, register t_type *type);
void EnterFieldList(t_node *Idlist, register t_type *type, t_scope *scope,
arith *addr);
/* Enter a list of identifiers representing variables into the
name list. "type" represents the type of the variables.
"local" is set if the variables are declared local to a
procedure.
*/
void EnterVarList(t_node *Idlist, t_type *type, int local);
/* Create (part of) a parameterlist of a procedure.
"ids" indicates the list of identifiers, "tp" their type, and
"VARp" indicates D_VARPAR or D_VALPAR.
*/
void EnterParamList(t_param **ppr, t_node *Idlist, t_type *type,
int VARp, arith *off);
/* From the current scope, the list of identifiers "ids" is
exported. Note this fact. If the export is not qualified, make
all the "ids" visible in the enclosing scope by defining them
in this scope as "imported".
*/
void EnterExportList(t_node *Idlist, int qualified);
void CheckForImports(t_def *df);
void EnterFromImportList(t_node *idlist, t_def *FromDef, t_node *FromId);
void EnterImportList(t_node *idlist, int local, t_scope *sc);
#endif /* ENTER_H_ */

View file

@ -30,10 +30,12 @@
#include "input.h" #include "input.h"
#include "f_info.h" #include "f_info.h"
#include "print.h"
#include "LLlex.h" #include "LLlex.h"
#include "main.h" #include "main.h"
#include "node.h" #include "node.h"
#include "warning.h" #include "warning.h"
#include "error.h"
/* error classes */ /* error classes */
#define ERROR 1 #define ERROR 1
@ -60,13 +62,12 @@ extern char *symbol2str();
FileName, node errors get their information from the FileName, node errors get their information from the
node, whereas other errors use the information in the token. node, whereas other errors use the information in the token.
*/ */
static void _error(int, t_node *, char *, register va_list, int);
void _error();
#if __STDC__ #if __STDC__
#ifdef DEBUG #ifdef DEBUG
/*VARARGS*/ /*VARARGS*/
debug(char *fmt, ...) void debug(char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -79,7 +80,7 @@ debug(char *fmt, ...)
#endif /* DEBUG */ #endif /* DEBUG */
/*VARARGS*/ /*VARARGS*/
error(char *fmt, ...) void error(char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -91,7 +92,7 @@ error(char *fmt, ...)
} }
/*VARARGS*/ /*VARARGS*/
node_error(t_node *node, char *fmt, ...) void node_error(t_node *node, char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -103,7 +104,7 @@ node_error(t_node *node, char *fmt, ...)
} }
/*VARARGS*/ /*VARARGS*/
warning(int class, char *fmt, ...) void warning(int class, char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -115,7 +116,7 @@ warning(int class, char *fmt, ...)
} }
/*VARARGS*/ /*VARARGS*/
node_warning(t_node *node, int class, char *fmt, ...) void node_warning(t_node *node, int class, char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -127,7 +128,7 @@ node_warning(t_node *node, int class, char *fmt, ...)
} }
/*VARARGS*/ /*VARARGS*/
lexerror(char *fmt, ...) void lexerror(char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -139,7 +140,7 @@ lexerror(char *fmt, ...)
} }
/*VARARGS*/ /*VARARGS*/
lexwarning(int class, char *fmt, ...) void lexwarning(int class, char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -151,7 +152,7 @@ lexwarning(int class, char *fmt, ...)
} }
/*VARARGS*/ /*VARARGS*/
fatal(char *fmt, ...) void fatal(char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -164,7 +165,7 @@ fatal(char *fmt, ...)
} }
/*VARARGS*/ /*VARARGS*/
crash(char *fmt, ...) void crash(char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -182,7 +183,7 @@ crash(char *fmt, ...)
#else #else
#ifdef DEBUG #ifdef DEBUG
/*VARARGS*/ /*VARARGS*/
debug(va_alist) void debug(va_alist)
va_dcl va_dcl
{ {
va_list ap; va_list ap;
@ -197,7 +198,7 @@ debug(va_alist)
#endif /* DEBUG */ #endif /* DEBUG */
/*VARARGS*/ /*VARARGS*/
error(va_alist) void error(va_alist)
va_dcl va_dcl
{ {
va_list ap; va_list ap;
@ -211,7 +212,7 @@ error(va_alist)
} }
/*VARARGS*/ /*VARARGS*/
node_error(va_alist) void node_error(va_alist)
va_dcl va_dcl
{ {
va_list ap; va_list ap;
@ -226,7 +227,7 @@ node_error(va_alist)
} }
/*VARARGS*/ /*VARARGS*/
warning(va_alist) void warning(va_alist)
va_dcl va_dcl
{ {
va_list ap; va_list ap;
@ -241,7 +242,7 @@ warning(va_alist)
} }
/*VARARGS*/ /*VARARGS*/
node_warning(va_alist) void node_warning(va_alist)
va_dcl va_dcl
{ {
va_list ap; va_list ap;
@ -257,7 +258,7 @@ node_warning(va_alist)
} }
/*VARARGS*/ /*VARARGS*/
lexerror(va_alist) void lexerror(va_alist)
va_dcl va_dcl
{ {
va_list ap; va_list ap;
@ -271,7 +272,7 @@ lexerror(va_alist)
} }
/*VARARGS*/ /*VARARGS*/
lexwarning(va_alist) void lexwarning(va_alist)
va_dcl va_dcl
{ {
va_list ap; va_list ap;
@ -286,7 +287,7 @@ lexwarning(va_alist)
} }
/*VARARGS*/ /*VARARGS*/
fatal(va_alist) void fatal(va_alist)
va_dcl va_dcl
{ {
va_list ap; va_list ap;
@ -301,7 +302,7 @@ fatal(va_alist)
} }
/*VARARGS*/ /*VARARGS*/
crash(va_alist) void crash(va_alist)
va_dcl va_dcl
{ {
va_list ap; va_list ap;
@ -320,13 +321,7 @@ crash(va_alist)
} }
#endif #endif
void static void _error(int class, t_node *node, char *fmt, register va_list ap, int warn_class)
_error(class, node, fmt, ap, warn_class)
int class;
t_node *node;
char *fmt;
register va_list ap;
int warn_class;
{ {
/* _error attempts to limit the number of error messages /* _error attempts to limit the number of error messages
for a given line to MAXERR_LINE. for a given line to MAXERR_LINE.

60
lang/m2/comp/error.h Normal file
View file

@ -0,0 +1,60 @@
/* Copyright (c) 2019 ACK Project.
* See the copyright notice in the ACK home directory,
* in the file "Copyright".
*
* Created on: 2019-02-26
*
*/
#ifndef ERROR_H_
#define ERROR_H_
typedef struct node t_node;
#if __STDC__
#ifdef DEBUG
/*VARARGS*/
void debug(char *fmt, ...);
#endif /* DEBUG */
/*VARARGS*/
void error(char *fmt, ...);
/*VARARGS*/
void node_error(t_node *node, char *fmt, ...);
/*VARARGS*/
void warning(int class, char *fmt, ...);
/*VARARGS*/
void node_warning(t_node *node, int class, char *fmt, ...);
/*VARARGS*/
void lexerror(char *fmt, ...);
/*VARARGS*/
void lexwarning(int class, char *fmt, ...);
/*VARARGS*/
void fatal(char *fmt, ...);
/*VARARGS*/
void crash(char *fmt, ...);
#else
#ifdef DEBUG
/*VARARGS*/
void debug(va_alist);
#endif /* DEBUG */
/*VARARGS*/
void error(va_alist);
/*VARARGS*/
void node_error(va_alist);
/*VARARGS*/
void warning(va_alist);
/*VARARGS*/
void node_warning(va_alist);
/*VARARGS*/
void lexerror(va_alist);
/*VARARGS*/
void lexwarning(va_alist);
/*VARARGS*/
void fatal(va_alist);
/*VARARGS*/
void crash(va_alist);
#endif
#endif /* ERROR_H_ */

View file

@ -13,9 +13,9 @@
#include "parameters.h" #include "parameters.h"
#include "debug.h" #include "debug.h"
#include <alloc.h> #include "alloc.h"
#include <em_arith.h> #include "em_arith.h"
#include <em_label.h> #include "em_label.h"
#include <assert.h> #include <assert.h>
#include "LLlex.h" #include "LLlex.h"
@ -23,6 +23,7 @@
#include "def.h" #include "def.h"
#include "node.h" #include "node.h"
#include "type.h" #include "type.h"
#include "error.h"
#include "chk_expr.h" #include "chk_expr.h"
#include "warning.h" #include "warning.h"

View file

@ -16,6 +16,7 @@
#include <em_label.h> #include <em_label.h>
#include <assert.h> #include <assert.h>
#include "lookup.h"
#include "LLlex.h" #include "LLlex.h"
#include "def.h" #include "def.h"
#include "idf.h" #include "idf.h"
@ -29,10 +30,7 @@ extern int pass_1;
extern char options[]; extern char options[];
#endif #endif
t_def * t_def *lookup(register t_idf *id, t_scope *scope, int import, int flags)
lookup(id, scope, import, flags)
register t_idf *id;
t_scope *scope;
{ {
/* Look up a definition of an identifier in scope "scope". /* Look up a definition of an identifier in scope "scope".
Make the "def" list self-organizing. Make the "def" list self-organizing.
@ -74,10 +72,7 @@ lookup(id, scope, import, flags)
return df; return df;
} }
t_def * t_def *lookfor(register t_node *id, register t_scopelist *vis, int message, int flags)
lookfor(id, vis, message, flags)
register t_node *id;
register t_scopelist *vis;
{ {
/* Look for an identifier in the visibility range started by "vis". /* Look for an identifier in the visibility range started by "vis".
If it is not defined create a dummy definition and, If it is not defined create a dummy definition and,

21
lang/m2/comp/lookup.h Normal file
View file

@ -0,0 +1,21 @@
/* Copyright (c) 2019 ACK Project.
* See the copyright notice in the ACK home directory,
* in the file "Copyright".
*
* Created on: 2019-02-27
*
*/
#ifndef LOOKUP_H_
#define LOOKUP_H_
/* Forward declarations. */
typedef struct idf t_idf;
typedef struct scope t_scope;
typedef struct node t_node;
typedef struct def t_def;
typedef struct scopelist t_scopelist;
t_def *lookup(register t_idf *id, t_scope *scope, int import, int flags);
t_def *lookfor(register t_node *id, register t_scopelist *vis, int message, int flags);
#endif /* LOOKUP_H_ */

View file

@ -12,12 +12,14 @@
#include "parameters.h" #include "parameters.h"
#include "debug.h" #include "debug.h"
#include <system.h>
#include <em_arith.h>
#include <em_label.h>
#include <em_code.h>
#include <alloc.h>
#include <assert.h> #include <assert.h>
#include "system.h"
#include "em_arith.h"
#include "em_label.h"
#include "em_code.h"
#include "print.h"
#include "alloc.h"
#include <stb.h> #include <stb.h>
#include "input.h" #include "input.h"
@ -31,8 +33,12 @@
#include "standards.h" #include "standards.h"
#include "tokenname.h" #include "tokenname.h"
#include "node.h" #include "node.h"
#include "walk.h"
#include "cstoper.h"
#include "error.h"
#include "options.h"
#include "warning.h" #include "warning.h"
#include "SYSTEM.h" #include "SYSTEMM2.h"
int state; /* either IMPLEMENTATION or PROGRAM */ int state; /* either IMPLEMENTATION or PROGRAM */
char options[128]; char options[128];
@ -47,8 +53,19 @@ extern int fp_used; /* set if floating point used */
static t_node _emptystat = { Stat, 0, NULLTYPE, { ';' }}; static t_node _emptystat = { Stat, 0, NULLTYPE, { ';' }};
t_node *EmptyStatement = &_emptystat; t_node *EmptyStatement = &_emptystat;
main(argc, argv)
register char **argv; /* Forward declarations. */
struct stdproc;
int Compile(char *, char *);
static void AddProcs(register struct stdproc *);
static void AddStandards(void);
/* External function declarations */
extern void CompUnit(void);
extern void DefModule(void); /* Lpars */
extern void reserve(register struct tokenname *); /* tokenname */
char* getwdir(register char *); /* defmodule */
int main(int argc, char **argv)
{ {
register int Nargc = 1; register int Nargc = 1;
register char **Nargv = &argv[0]; register char **Nargv = &argv[0];
@ -72,11 +89,9 @@ main(argc, argv)
/*NOTREACHED*/ /*NOTREACHED*/
} }
Compile(src, dst) int Compile(char *src, char *dst)
char *src, *dst;
{ {
extern struct tokenname tkidf[]; extern struct tokenname tkidf[];
extern char *getwdir();
if (! InsertFile(src, (char **) 0, &src)) { if (! InsertFile(src, (char **) 0, &src)) {
fprint(STDERR,"%s: cannot open %s\n", ProgName, src); fprint(STDERR,"%s: cannot open %s\n", ProgName, src);
@ -126,7 +141,7 @@ Compile(src, dst)
} }
#ifdef DEBUG #ifdef DEBUG
LexScan() void LexScan(void)
{ {
register t_token *tkp = &dot; register t_token *tkp = &dot;
extern char *symbol2str(); extern char *symbol2str();
@ -198,8 +213,7 @@ static struct stdproc sysprocs[] = {
extern t_def *Enter(), *EnterType(); extern t_def *Enter(), *EnterType();
AddProcs(p) static void AddProcs(register struct stdproc *p)
register struct stdproc *p;
{ {
for (; p->st_nam != 0; p++) { for (; p->st_nam != 0; p++) {
if (! Enter(p->st_nam, D_PROCEDURE, std_type, p->st_con)) { if (! Enter(p->st_nam, D_PROCEDURE, std_type, p->st_con)) {
@ -208,7 +222,7 @@ AddProcs(p)
} }
} }
AddStandards() static void AddStandards(void)
{ {
register t_def *df; register t_def *df;
static t_token nilconst = { INTEGER, 0}; static t_token nilconst = { INTEGER, 0};
@ -238,7 +252,7 @@ AddStandards()
EnterType("BOOLEAN", bool_type); EnterType("BOOLEAN", bool_type);
} }
do_SYSTEM() void do_SYSTEM(void)
{ {
/* Simulate the reading of the SYSTEM definition module /* Simulate the reading of the SYSTEM definition module
*/ */
@ -258,7 +272,7 @@ do_SYSTEM()
int cntlines; int cntlines;
Info() void Info(void)
{ {
extern int cnt_def, cnt_node, cnt_paramlist, cnt_type, extern int cnt_def, cnt_node, cnt_paramlist, cnt_type,
cnt_switch_hdr, cnt_case_entry, cnt_switch_hdr, cnt_case_entry,
@ -274,14 +288,12 @@ print("\nNumber of lines read: %d\n", cntlines);
} }
#endif #endif
void void No_Mem(void)
No_Mem()
{ {
fatal("out of memory"); fatal("out of memory");
} }
void void C_failed(void)
C_failed()
{ {
fatal("write failed"); fatal("write failed");
} }

View file

@ -6,8 +6,8 @@
*/ */
/* S O M E G L O B A L V A R I A B L E S */ /* S O M E G L O B A L V A R I A B L E S */
#ifndef MAIN_H_
/* $Id$ */ #define MAIN_H_
extern char options[]; /* indicating which options were given */ extern char options[]; /* indicating which options were given */
@ -23,3 +23,7 @@ extern struct def *Defined;
extern char **DEFPATH; /* search path for DEFINITION MODULE's */ extern char **DEFPATH; /* search path for DEFINITION MODULE's */
extern int mDEF, nDEF; extern int mDEF, nDEF;
extern int state; /* either IMPLEMENTATION or PROGRAM */ extern int state; /* either IMPLEMENTATION or PROGRAM */
void do_SYSTEM(void);
#endif /* MAIN_H_ */

View file

@ -23,9 +23,9 @@
#include "LLlex.h" #include "LLlex.h"
#include "idf.h" #include "idf.h"
#include "node.h" #include "node.h"
#include "error.h"
match_id(id1, id2) void match_id(register t_idf *id1, t_idf *id2)
register t_idf *id1, *id2;
{ {
/* Check that identifiers id1 and id2 are equal. If they /* Check that identifiers id1 and id2 are equal. If they
are not, check that we did'nt generate them in the are not, check that we did'nt generate them in the
@ -39,8 +39,7 @@ match_id(id1, id2)
} }
} }
t_idf * t_idf *gen_anon_idf(void)
gen_anon_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.
@ -55,9 +54,7 @@ gen_anon_idf()
return str2idf(s, 0); return str2idf(s, 0);
} }
not_declared(what, id, where) void not_declared(char *what, t_node *id, char *where)
char *what, *where;
register t_node *id;
{ {
/* The identifier "id" is not declared. If it is not generated, /* The identifier "id" is not declared. If it is not generated,
give an error message give an error message

View file

@ -12,5 +12,10 @@
#define is_anon_idf(x) ((x)->id_text[0] == '#') #define is_anon_idf(x) ((x)->id_text[0] == '#')
#define id_not_declared(x) (not_declared("identifier", (x), "")) #define id_not_declared(x) (not_declared("identifier", (x), ""))
extern struct idf /* Forward declarations. */
*gen_anon_idf(); typedef struct idf t_idf;
typedef struct node t_node;
void match_id(register t_idf *id1, t_idf *id2);
t_idf *gen_anon_idf(void);
void not_declared(char *what, t_node *id, char *where);

1
lang/m2/comp/next.in Normal file
View file

@ -0,0 +1 @@
#include "parameters.h"

View file

@ -22,6 +22,7 @@
#include "type.h" #include "type.h"
#include "node.h" #include "node.h"
#include "main.h" #include "main.h"
#include "error.h"
static int nsubnodes[] = { static int nsubnodes[] = {
0, 0,
@ -39,8 +40,7 @@ static int nsubnodes[] = {
2 2
}; };
t_node * t_node *getnode(int class)
getnode(class)
{ {
register t_node *nd = new_node(); register t_node *nd = new_node();
@ -50,9 +50,7 @@ getnode(class)
return nd; return nd;
} }
t_node * t_node *dot2node(int class, t_node *left, t_node *right)
dot2node(class, left, right)
t_node *left, *right;
{ {
register t_node *nd = getnode(class); register t_node *nd = getnode(class);
@ -63,8 +61,7 @@ dot2node(class, left, right)
return nd; return nd;
} }
t_node * t_node *dot2leaf(int class)
dot2leaf(class)
{ {
register t_node *nd = getnode(class); register t_node *nd = getnode(class);
@ -81,15 +78,13 @@ dot2leaf(class)
return nd; return nd;
} }
void void FreeNode(register t_node *nd)
FreeNode(nd)
register t_node *nd;
{ {
/* Put nodes that are no longer needed back onto the free /* Put nodes that are no longer needed back onto the free
list list
*/ */
if (!nd) return; if (!nd) return;
switch(nsubnodes[nd->nd_class]) { switch(nsubnodes[(unsigned int)nd->nd_class]) {
case 2: case 2:
FreeNode(nd->nd_LEFT); FreeNode(nd->nd_LEFT);
FreeNode(nd->nd_RIGHT); FreeNode(nd->nd_RIGHT);
@ -102,15 +97,13 @@ FreeNode(nd)
} }
/*ARGSUSED*/ /*ARGSUSED*/
NodeCrash(expp) int NodeCrash(register t_node* expp, label exit_label, int end_reached)
t_node *expp;
{ {
crash("(NodeCrash) Illegal node"); crash("(NodeCrash) Illegal node");
} }
/*ARGSUSED*/ /*ARGSUSED*/
PNodeCrash(expp) int PNodeCrash(t_node **expp, int flags)
t_node **expp;
{ {
crash("(PNodeCrash) Illegal node"); crash("(PNodeCrash) Illegal node");
} }
@ -119,15 +112,14 @@ PNodeCrash(expp)
extern char *symbol2str(); extern char *symbol2str();
indnt(lvl) void indnt(int lvl)
{ {
while (lvl--) { while (lvl--) {
print(" "); print(" ");
} }
} }
printnode(nd, lvl) void printnode(register t_node *nd, int lvl)
register t_node *nd;
{ {
indnt(lvl); indnt(lvl);
print("Class: %d; Symbol: %s; Flags: %d\n", nd->nd_class, symbol2str(nd->nd_symb), nd->nd_flags); print("Class: %d; Symbol: %s; Flags: %d\n", nd->nd_class, symbol2str(nd->nd_symb), nd->nd_flags);
@ -139,8 +131,7 @@ printnode(nd, lvl)
} }
} }
PrNode(nd, lvl) void PrNode(register t_node *nd, int lvl)
register t_node *nd;
{ {
if (! nd) { if (! nd) {
indnt(lvl); print("<nilnode>\n"); indnt(lvl); print("<nilnode>\n");

View file

@ -61,3 +61,13 @@ extern t_node *dot2node(), *dot2leaf(), *getnode();
#define IsCast(lnd) ((lnd)->nd_class == Def && is_type((lnd)->nd_def)) #define IsCast(lnd) ((lnd)->nd_class == Def && is_type((lnd)->nd_def))
#define IsProc(lnd) ((lnd)->nd_type->tp_fund == T_PROCEDURE) #define IsProc(lnd) ((lnd)->nd_type->tp_fund == T_PROCEDURE)
t_node *getnode(int class);
t_node *dot2node(int class, t_node *left, t_node *right);
t_node *dot2leaf(int class);
void FreeNode(register t_node *nd);
int NodeCrash(register t_node* expp, label exit_label, int end_reached);
int PNodeCrash(t_node **expp, int flags);

View file

@ -19,6 +19,7 @@
#include "main.h" #include "main.h"
#include "warning.h" #include "warning.h"
#include "class.h" #include "class.h"
#include "error.h"
#define MINIDFSIZE 14 #define MINIDFSIZE 14
@ -32,13 +33,30 @@ static int ndirs = 1;
int warning_classes = W_INITIAL; int warning_classes = W_INITIAL;
int gdb_flag; int gdb_flag;
DoOption(text) #if (!SQUEEZE) | (!NOCROSS)
register char *text; static int txt2int(register char **tp)
{
/* the integer pointed to by *tp is read, while increasing
*tp; the resulting value is yielded.
*/
register int val = 0;
register int ch;
while (ch = **tp, ch >= '0' && ch <= '9') {
val = val * 10 + ch - '0';
(*tp)++;
}
return val;
}
#endif
void DoOption(register char *text)
{ {
switch(*text++) { switch(*text++) {
case '-': case '-':
options[*text]++; /* debug options etc. */ options[(unsigned int)*text]++; /* debug options etc. */
break; break;
case 'U': /* allow underscores in identifiers */ case 'U': /* allow underscores in identifiers */
@ -54,7 +72,7 @@ DoOption(text)
case 's': /* symmetric: MIN(INTEGER) = -MAX(INTEGER) */ case 's': /* symmetric: MIN(INTEGER) = -MAX(INTEGER) */
case '3': /* strict 3rd edition Modula-2 */ case '3': /* strict 3rd edition Modula-2 */
case 'l': /* local additions enabled */ case 'l': /* local additions enabled */
options[text[-1]]++; options[(unsigned int)text[-1]]++;
break; break;
#ifdef DBSYMTAB #ifdef DBSYMTAB
@ -162,7 +180,7 @@ DoOption(text)
char c; char c;
char *t; char *t;
while (c = *text++) { while ( (c = *text++) != 0) {
char *strchr(); char *strchr();
t = text; t = text;
@ -235,21 +253,3 @@ DoOption(text)
} }
} }
#if (!SQUEEZE) | (!NOCROSS)
int
txt2int(tp)
register char **tp;
{
/* the integer pointed to by *tp is read, while increasing
*tp; the resulting value is yielded.
*/
register int val = 0;
register int ch;
while (ch = **tp, ch >= '0' && ch <= '9') {
val = val * 10 + ch - '0';
(*tp)++;
}
return val;
}
#endif

13
lang/m2/comp/options.h Normal file
View file

@ -0,0 +1,13 @@
/* Copyright (c) 2019 ACK Project.
* See the copyright notice in the ACK home directory,
* in the file "Copyright".
*
* Created on: 2019-02-27
*
*/
#ifndef OPTIONS_H_
#define OPTIONS_H_
void DoOption(register char *text);
#endif /* OPTIONS_H_ */

View file

@ -15,11 +15,11 @@
#include "parameters.h" #include "parameters.h"
#include "debug.h" #include "debug.h"
#include <alloc.h> #include "alloc.h"
#include <em_arith.h> #include "em_arith.h"
#include <em_label.h> #include "em_label.h"
#include <em_code.h> #include "em_code.h"
#include <stb.h> #include "stb.h"
#include "main.h" #include "main.h"
#include "idf.h" #include "idf.h"
@ -27,6 +27,10 @@
#include "scope.h" #include "scope.h"
#include "def.h" #include "def.h"
#include "type.h" #include "type.h"
#include "lookup.h"
#include "error.h"
#include "stab.h"
#include "enter.h"
#include "node.h" #include "node.h"
#include "f_info.h" #include "f_info.h"
#include "warning.h" #include "warning.h"

View file

@ -6,8 +6,10 @@
*/ */
/* S C O P E M E C H A N I S M */ /* S C O P E M E C H A N I S M */
#ifndef SCOPE_H_
#define SCOPE_H_
/* $Id$ */
#define OPENSCOPE 0 /* Indicating an open scope */ #define OPENSCOPE 0 /* Indicating an open scope */
#define CLOSEDSCOPE 1 /* Indicating a closed scope (module) */ #define CLOSEDSCOPE 1 /* Indicating a closed scope (module) */
@ -58,4 +60,17 @@ extern t_scopelist
#define scopeclosed(x) ((x)->sc_scopeclosed) #define scopeclosed(x) ((x)->sc_scopeclosed)
#define nextvisible(x) ((x)->sc_next) /* use with scopelists */ #define nextvisible(x) ((x)->sc_next) /* use with scopelists */
t_scope *open_and_close_scope();
typedef struct def t_def;
void Reverse(t_def **pdf);
void open_scope(int scopetype);
t_scope * open_and_close_scope(int scopetype);
void InitScope(void);
void close_scope(int flag);
#ifdef DEBUG
void DumpScope(register t_def *df);
#endif
#endif /* SCOPE_H_ */

View file

@ -13,9 +13,9 @@
#include "debug.h" #include "debug.h"
#include <assert.h> #include <assert.h>
#include <alloc.h> #include "alloc.h"
#include <em_arith.h> #include "em_arith.h"
#include <em_label.h> #include "em_label.h"
#include "LLlex.h" #include "LLlex.h"
#include "idf.h" #include "idf.h"
@ -23,6 +23,8 @@
#include "type.h" #include "type.h"
#include "def.h" #include "def.h"
#include "node.h" #include "node.h"
#include "lookup.h"
#include "error.h"
t_scope *PervasiveScope; t_scope *PervasiveScope;
t_scopelist *CurrVis, *GlobalVis; t_scopelist *CurrVis, *GlobalVis;
@ -35,7 +37,7 @@ extern char options[];
static int sc_count; static int sc_count;
open_scope(scopetype) void open_scope(int scopetype)
{ {
/* Open a scope that is either open (automatic imports) or closed. /* Open a scope that is either open (automatic imports) or closed.
*/ */
@ -55,8 +57,7 @@ open_scope(scopetype)
CurrVis = ls; CurrVis = ls;
} }
t_scope * t_scope * open_and_close_scope(int scopetype)
open_and_close_scope(scopetype)
{ {
t_scope *sc; t_scope *sc;
@ -66,7 +67,7 @@ open_and_close_scope(scopetype)
return sc; return sc;
} }
InitScope() void InitScope(void)
{ {
register t_scope *sc = new_scope(); register t_scope *sc = new_scope();
register t_scopelist *ls = new_scopelist(); register t_scopelist *ls = new_scopelist();
@ -77,9 +78,7 @@ InitScope()
CurrVis = ls; CurrVis = ls;
} }
STATIC static void chk_proc(register t_def *df)
chk_proc(df)
register t_def *df;
{ {
/* Called at scope closing. Check all definitions, and if one /* Called at scope closing. Check all definitions, and if one
is a D_PROCHEAD, the procedure was not defined. is a D_PROCHEAD, the procedure was not defined.
@ -101,9 +100,7 @@ chk_proc(df)
} }
} }
STATIC static void chk_forw(t_def **pdf)
chk_forw(pdf)
t_def **pdf;
{ {
/* Called at scope close. Look for all forward definitions and /* Called at scope close. Look for all forward definitions and
if the scope was a closed scope, give an error message for if the scope was a closed scope, give an error message for
@ -111,7 +108,7 @@ chk_forw(pdf)
*/ */
register t_def *df; register t_def *df;
while (df = *pdf) { while ( (df = *pdf) ) {
if (df->df_kind == D_FORWTYPE) { if (df->df_kind == D_FORWTYPE) {
pdf = &df->df_nextinscope; pdf = &df->df_nextinscope;
ForceForwardTypeDef(df); /* removes df */ ForceForwardTypeDef(df); /* removes df */
@ -157,8 +154,7 @@ df->df_idf->id_text);
} }
} }
Reverse(pdf) void Reverse(t_def **pdf)
t_def **pdf;
{ {
/* Reverse the order in the list of definitions in a scope. /* Reverse the order in the list of definitions in a scope.
This is neccesary because this list is built in reverse. This is neccesary because this list is built in reverse.
@ -184,8 +180,7 @@ Reverse(pdf)
*pdf = df; *pdf = df;
} }
close_scope(flag) void close_scope(int flag)
register int flag;
{ {
/* Close a scope. If "flag" is set, check for forward declarations, /* Close a scope. If "flag" is set, check for forward declarations,
either POINTER declarations, or EXPORTs, or forward references either POINTER declarations, or EXPORTs, or forward references
@ -208,8 +203,7 @@ close_scope(flag)
} }
#ifdef DEBUG #ifdef DEBUG
DumpScope(df) void DumpScope(register t_def *df)
register t_def *df;
{ {
while (df) { while (df) {
PrDef(df); PrDef(df);

View file

@ -25,6 +25,8 @@
#include "type.h" #include "type.h"
#include "idf.h" #include "idf.h"
#include "scope.h" #include "scope.h"
#include "error.h"
#include "stab.h"
#include "main.h" #include "main.h"
extern int gdb_flag; extern int gdb_flag;
@ -40,8 +42,7 @@ static struct db_str {
char *currpos; char *currpos;
} db_str; } db_str;
static static void create_db_str(void)
create_db_str()
{ {
if (! db_str.base) { if (! db_str.base) {
db_str.base = Malloc(INCR_SIZE); db_str.base = Malloc(INCR_SIZE);
@ -50,9 +51,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) {
@ -64,16 +63,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 void static void stb_type(register t_type *tp, int assign_num)
stb_type(tp, assign_num)
register t_type *tp;
{ {
char buf[128]; char buf[128];
static int stb_count; static int stb_count;
@ -254,9 +249,7 @@ stb_type(tp, assign_num)
} }
} }
stb_addtp(s, tp) void stb_addtp(char *s, t_type *tp)
char *s;
t_type *tp;
{ {
create_db_str(); create_db_str();
adds_db_str(s); adds_db_str(s);
@ -272,8 +265,7 @@ stb_addtp(s, tp)
(arith) 0); (arith) 0);
} }
stb_string(df, kind) void stb_string(register t_def *df, int kind)
register t_def *df;
{ {
register t_type *tp = df->df_type; register t_type *tp = df->df_type;
char buf[64]; char buf[64];

19
lang/m2/comp/stab.h Normal file
View file

@ -0,0 +1,19 @@
/* Copyright (c) 2019 ACK Project.
* See the copyright notice in the ACK home directory,
* in the file "Copyright".
*
* Created on: 2019-02-27
*
*/
#ifndef STAB_H_
#define STAB_H_
/* D E B U G G E R S Y M B O L T A B L E */
typedef struct type t_type;
typedef struct def t_def;
void stb_addtp(char *s, t_type *tp);
void stb_string(register t_def *df, int kind);
#endif /* STAB_H_ */

View file

@ -11,8 +11,8 @@
{ {
#include <assert.h> #include <assert.h>
#include <em_arith.h> #include "em_arith.h"
#include <em_label.h> #include "em_label.h"
#include "parameters.h" #include "parameters.h"
#include "idf.h" #include "idf.h"
@ -20,6 +20,7 @@
#include "scope.h" #include "scope.h"
#include "def.h" #include "def.h"
#include "type.h" #include "type.h"
#include "error.h"
#include "node.h" #include "node.h"
static int loopcount = 0; /* Count nested loops */ static int loopcount = 0; /* Count nested loops */

26
lang/m2/comp/tmpvar.h Normal file
View file

@ -0,0 +1,26 @@
/* Copyright (c) 2019 ACK Project.
* See the copyright notice in the ACK home directory,
* in the file "Copyright".
*
* Created on: 2019-02-27
*
*/
/* T E M P O R A R Y V A R I A B L E S */
#ifndef TMPVAR_H_
#define TMPVAR_H_
#include "em_arith.h"
typedef struct scope t_scope;
void TmpOpen(t_scope *sc);
arith TmpSpace(arith sz, int al);
arith NewInt(void);
arith NewPtr(void);
void FreeInt(arith off);
void FreePtr(arith off);
void TmpClose(void);
#endif /* TMPVAR_H_ */

View file

@ -30,6 +30,7 @@
#include "def.h" #include "def.h"
#include "type.h" #include "type.h"
#include "scope.h" #include "scope.h"
#include "tmpvar.h"
#include "main.h" #include "main.h"
struct tmpvar { struct tmpvar {
@ -45,16 +46,14 @@ static t_scope *ProcScope; /* scope of procedure in which the
temporaries are allocated temporaries are allocated
*/ */
TmpOpen(sc) t_scope *sc; void TmpOpen(t_scope *sc)
{ {
/* Initialize for temporaries in scope "sc". /* Initialize for temporaries in scope "sc".
*/ */
ProcScope = sc; ProcScope = sc;
} }
arith arith TmpSpace(arith sz, int al)
TmpSpace(sz, al)
arith sz;
{ {
register t_scope *sc = ProcScope; register t_scope *sc = ProcScope;
@ -62,10 +61,7 @@ TmpSpace(sz, al)
return sc->sc_off; return sc->sc_off;
} }
STATIC arith static arith NewTmp(struct tmpvar **plist, arith sz, int al, int regtype)
NewTmp(plist, sz, al, regtype)
register struct tmpvar **plist;
arith sz;
{ {
register arith offset; register arith offset;
register struct tmpvar *tmp; register struct tmpvar *tmp;
@ -83,22 +79,18 @@ NewTmp(plist, sz, al, regtype)
return offset; return offset;
} }
arith arith NewInt(void)
NewInt()
{ {
return NewTmp(&TmpInts, int_size, int_align, reg_any); return NewTmp(&TmpInts, int_size, int_align, reg_any);
} }
arith arith NewPtr(void)
NewPtr()
{ {
return NewTmp(&TmpPtrs, pointer_size, pointer_align, reg_pointer); return NewTmp(&TmpPtrs, pointer_size, pointer_align, reg_pointer);
} }
STATIC
FreeTmp(plist, off) static void FreeTmp(struct tmpvar **plist, arith off)
struct tmpvar **plist;
arith off;
{ {
register struct tmpvar *tmp = new_tmpvar(); register struct tmpvar *tmp = new_tmpvar();
@ -107,19 +99,17 @@ FreeTmp(plist, off)
*plist = tmp; *plist = tmp;
} }
FreeInt(off) void FreeInt(arith off)
arith off;
{ {
FreeTmp(&TmpInts, off); FreeTmp(&TmpInts, off);
} }
FreePtr(off) void FreePtr(arith off)
arith off;
{ {
FreeTmp(&TmpPtrs, off); FreeTmp(&TmpPtrs, off);
} }
TmpClose() void TmpClose(void)
{ {
register struct tmpvar *tmp, *tmp1; register struct tmpvar *tmp, *tmp1;

View file

@ -13,6 +13,7 @@
#include "tokenname.h" #include "tokenname.h"
#include "Lpars.h" #include "Lpars.h"
#include "idf.h" #include "idf.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
@ -98,8 +99,7 @@ struct tokenname tkstandard[] = { /* standard identifiers */
/* Some routines to handle tokennames */ /* Some routines to handle tokennames */
reserve(resv) void reserve(register 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

@ -25,7 +25,12 @@
#include "idf.h" #include "idf.h"
#include "node.h" #include "node.h"
#include "scope.h" #include "scope.h"
#include "error.h"
#include "walk.h" #include "walk.h"
#include "lookup.h"
#include "stab.h"
#include "enter.h"
#include "typequiv.h"
#include "main.h" #include "main.h"
#include "chk_expr.h" #include "chk_expr.h"
#include "warning.h" #include "warning.h"
@ -73,12 +78,8 @@ t_type
*std_type, *std_type,
*error_type; *error_type;
void ArraySizes();
t_type * t_type *construct_type(int fund, register t_type *tp)
construct_type(fund, tp)
int fund;
register t_type *tp;
{ {
/* fund must be a type constructor. /* fund must be a type constructor.
The pointer to the constructed type is returned. The pointer to the constructed type is returned.
@ -117,10 +118,10 @@ construct_type(fund, tp)
return dtp; return dtp;
} }
arith /* Aligns "pos" to the specified alignment "al"
align(pos, al) * and returns the aligned "pos".
arith pos; */
int al; arith align(arith pos, int al)
{ {
int i = pos % al; int i = pos % al;
@ -128,11 +129,7 @@ align(pos, al)
return pos; return pos;
} }
t_type * t_type *standard_type(int fund, int algn, arith size)
standard_type(fund, algn, size)
int fund;
int algn;
arith size;
{ {
register t_type *tp = new_type(); register t_type *tp = new_type();
@ -146,10 +143,8 @@ standard_type(fund, algn, size)
return tp; return tp;
} }
InitTypes() void InitTypes(void)
{ {
/* Initialize the predefined types
*/
register t_type *tp; register t_type *tp;
/* first, do some checking /* first, do some checking
@ -221,17 +216,12 @@ InitTypes()
void_type = error_type; void_type = error_type;
} }
int int fit(arith sz, int nbytes)
fit(sz, nbytes)
arith sz;
{ {
return ((sz) + ((arith)0x80<<(((nbytes)-1)*8)) & ~full_mask[(nbytes)]) == 0; return ((sz) + ((arith)0x80<<(((nbytes)-1)*8)) & ~full_mask[(nbytes)]) == 0;
} }
STATIC static void u_small(register t_type *tp, arith n)
u_small(tp, n)
register t_type *tp;
arith n;
{ {
if (ufit(n, 1)) { if (ufit(n, 1)) {
tp->tp_size = 1; tp->tp_size = 1;
@ -243,9 +233,7 @@ u_small(tp, n)
} }
} }
t_type * t_type *enum_type(t_node *EnumList)
enum_type(EnumList)
t_node *EnumList;
{ {
register t_type *tp = register t_type *tp =
standard_type(T_ENUMERATION, int_align, int_size); standard_type(T_ENUMERATION, int_align, int_size);
@ -258,9 +246,7 @@ enum_type(EnumList)
return tp; return tp;
} }
t_type * t_type *qualified_type(t_node **pnd)
qualified_type(pnd)
t_node **pnd;
{ {
register t_def *df; register t_def *df;
@ -296,26 +282,18 @@ node_error(nd, "identifier \"%s\" is not a type", df->df_idf->id_text);
} }
int int chk_bounds(arith l1, arith l2, int fund)
chk_bounds(l1, l2, fund)
arith l1, l2;
{ {
/* compare to arith's, but be careful. They might be unsigned
*/
if (fund == T_INTEGER) { if (fund == T_INTEGER) {
return l2 >= l1; return l2 >= l1;
} }
return (unsigned arith) l2 >= (unsigned arith) l1; return (unsigned arith) l2 >= (unsigned arith) l1;
} }
int int in_range(arith i, register t_type *tp)
in_range(i, tp)
arith i;
register t_type *tp;
{ {
/* Check that the value i fits in the subrange or enumeration
type tp. Return 1 if so, 0 otherwise
*/
switch(tp->tp_fund) { switch(tp->tp_fund) {
case T_ENUMERATION: case T_ENUMERATION:
@ -330,16 +308,8 @@ in_range(i, tp)
/*NOTREACHED*/ /*NOTREACHED*/
} }
t_type * t_type *subr_type(t_node *lb, t_node *ub, t_type *base)
subr_type(lb, ub, base)
register t_node *lb;
t_node *ub;
t_type *base;
{ {
/* Construct a subrange type from the constant expressions
indicated by "lb" and "ub", but first perform some
checks. "base" is either a user-specified base-type, or NULL.
*/
register t_type *tp = BaseType(lb->nd_type); register t_type *tp = BaseType(lb->nd_type);
register t_type *res; register t_type *res;
@ -428,11 +398,7 @@ subr_type(lb, ub, base)
return res; return res;
} }
t_type * t_type *proc_type(t_type *result_type, t_param *parameters, arith n_bytes_params)
proc_type(result_type, parameters, n_bytes_params)
t_type *result_type;
t_param *parameters;
arith n_bytes_params;
{ {
register t_type *tp = construct_type(T_PROCEDURE, result_type); register t_type *tp = construct_type(T_PROCEDURE, result_type);
@ -447,8 +413,7 @@ proc_type(result_type, parameters, n_bytes_params)
return tp; return tp;
} }
genrck(tp) void genrck(register t_type *tp)
register t_type *tp;
{ {
/* generate a range check descriptor for type "tp" when /* generate a range check descriptor for type "tp" when
neccessary. Return its label. neccessary. Return its label.
@ -483,13 +448,8 @@ genrck(tp)
} }
} }
getbounds(tp, plo, phi) void getbounds(register t_type *tp, arith *plo, arith *phi)
register t_type *tp;
arith *plo, *phi;
{ {
/* Get the bounds of a bounded type
*/
assert(bounded(tp)); assert(bounded(tp));
if (tp->tp_fund == T_SUBRANGE) { if (tp->tp_fund == T_SUBRANGE) {
@ -502,13 +462,9 @@ getbounds(tp, plo, phi)
} }
} }
t_type * t_type *set_type(register t_type *tp)
set_type(tp)
register t_type *tp;
{ {
/* Construct a set type with base type "tp", but first
perform some checks
*/
arith lb, ub, diff, alloc_size; arith lb, ub, diff, alloc_size;
if (! bounded(tp) || tp->tp_size > word_size) { if (! bounded(tp) || tp->tp_size > word_size) {
@ -542,8 +498,7 @@ set_type(tp)
return tp; return tp;
} }
ArrayElSize(tp) void ArrayElSize(register t_type *tp)
register t_type *tp;
{ {
/* Align element size to alignment requirement of element type. /* Align element size to alignment requirement of element type.
Also make sure that its size is either a dividor of the word_size, Also make sure that its size is either a dividor of the word_size,
@ -569,9 +524,7 @@ ArrayElSize(tp)
} }
} }
void void ArraySizes(register t_type *tp)
ArraySizes(tp)
register t_type *tp;
{ {
/* Assign sizes to an array type, and check index type /* Assign sizes to an array type, and check index type
*/ */
@ -610,8 +563,7 @@ ArraySizes(tp)
C_rom_cst(tp->arr_elsize); C_rom_cst(tp->arr_elsize);
} }
FreeType(tp) void FreeType(register t_type *tp)
register t_type *tp;
{ {
/* Release type structures indicated by "tp". /* Release type structures indicated by "tp".
This procedure is only called for types, constructed with This procedure is only called for types, constructed with
@ -632,10 +584,7 @@ FreeType(tp)
free_type(tp); free_type(tp);
} }
DeclareType(nd, df, tp) void DeclareType(t_node *nd, register t_def *df, register t_type *tp)
register t_def *df;
register t_type *tp;
t_node *nd;
{ {
/* A type with type-description "tp" is declared and must /* A type with type-description "tp" is declared and must
be bound to definition "df". be bound to definition "df".
@ -677,8 +626,7 @@ DeclareType(nd, df, tp)
SolveForwardTypeRefs(df); SolveForwardTypeRefs(df);
} }
SolveForwardTypeRefs(df) void SolveForwardTypeRefs(register t_def *df)
register t_def *df;
{ {
register t_node *nd; register t_node *nd;
@ -700,8 +648,7 @@ SolveForwardTypeRefs(df)
} }
ForceForwardTypeDef(df) void ForceForwardTypeDef(register t_def *df)
register t_def *df;
{ {
register t_def *df1 = df, *df2; register t_def *df1 = df, *df2;
register t_node *nd = df->df_forw_node; register t_node *nd = df->df_forw_node;
@ -735,18 +682,14 @@ ForceForwardTypeDef(df)
} }
} }
t_type * t_type *RemoveEqual(register t_type *tpx)
RemoveEqual(tpx)
register t_type *tpx;
{ {
if (tpx) while (tpx->tp_fund == T_EQUAL) tpx = tpx->tp_next; if (tpx) while (tpx->tp_fund == T_EQUAL) tpx = tpx->tp_next;
return tpx; return tpx;
} }
int int type_or_forward(t_type *tp)
type_or_forward(tp)
t_type *tp;
{ {
/* POINTER TO IDENTIFIER construction. The IDENTIFIER resides /* POINTER TO IDENTIFIER construction. The IDENTIFIER resides
in "dot". This routine handles the different cases. in "dot". This routine handles the different cases.
@ -809,9 +752,7 @@ type_or_forward(tp)
return 0; return 0;
} }
int int gcd(int m, int n)
gcd(m, n)
register int m, n;
{ {
/* Greatest Common Divisor /* Greatest Common Divisor
*/ */
@ -825,18 +766,14 @@ gcd(m, n)
return m; return m;
} }
int int lcm(int m, int n)
lcm(m, n)
int m, n;
{ {
/* Least Common Multiple /* Least Common Multiple
*/ */
return m * (n / gcd(m, n)); return m * (n / gcd(m, n));
} }
t_type * t_type *intorcard(register t_type *left, register t_type *right)
intorcard(left, right)
register t_type *left, *right;
{ {
if (left->tp_fund == T_INTORCARD) { if (left->tp_fund == T_INTORCARD) {
t_type *tmp = left; t_type *tmp = left;
@ -852,8 +789,7 @@ intorcard(left, right)
} }
#ifdef DEBUG #ifdef DEBUG
DumpType(tp) void DumpType(register t_type *tp)
register t_type *tp;
{ {
if (!tp) return; if (!tp) return;

View file

@ -4,10 +4,17 @@
* *
* Author: Ceriel J.H. Jacobs * Author: Ceriel J.H. Jacobs
*/ */
#ifndef TYPE_H_
#define TYPE_H_
/* T Y P E D E S C R I P T O R S T R U C T U R E */ /* T Y P E D E S C R I P T O R S T R U C T U R E */
/* $Id$ */ #include "em_arith.h"
typedef struct def t_def;
typedef struct node t_node;
struct paramlist { /* structure for parameterlist of a PROCEDURE */ struct paramlist { /* structure for parameterlist of a PROCEDURE */
struct paramlist *par_next; struct paramlist *par_next;
@ -189,19 +196,7 @@ extern unsigned int
extern arith extern arith
ret_area_size; ret_area_size;
extern arith
align(); /* type.c */
extern t_type
*construct_type(),
*standard_type(),
*set_type(),
*subr_type(),
*proc_type(),
*enum_type(),
*qualified_type(),
*intorcard(),
*RemoveEqual(); /* All from type.c */
#define NULLTYPE ((t_type *) 0) #define NULLTYPE ((t_type *) 0)
@ -240,3 +235,59 @@ extern arith max_int[];
extern arith min_int[]; extern arith min_int[];
#define ufit(n, i) (((n) & ~full_mask[(i)]) == 0) #define ufit(n, i) (((n) & ~full_mask[(i)]) == 0)
/* Forward declarations. */
/* Initialize predefined types. */
void InitTypes(void);
/* Compare arith's, and return 1 if "l2" is
* greater or equal than "l1", otherwise returns 0.
* Takes into account that arith might be unsigned. */
int chk_bounds(arith l1, arith l2, int fund);
/* Aligns "pos" to the specified alignment "al" and returns the
aligned "pos".
*/
arith align(arith pos, int al);
/* Create a new standard type "fund" with specified
alignment "algn" and "size" bytes. */
t_type *standard_type(int fund, int algn, arith size);
t_type *enum_type(t_node *EnumList);
t_type *construct_type(int fund, register t_type *tp);
t_type *qualified_type(t_node **pnd);
/* Check that the value "i" fits in the subrange or enumeration
type "tp". Return 1 if so, 0 otherwise
*/
int in_range(arith i, register t_type *tp);
/* Construct a subrange type from the constant expressions
indicated by "lb" and "ub", but first perform some
checks. "base" is either a user-specified base-type, or NULL.
*/
t_type *subr_type(t_node *lb, t_node *ub, t_type *base);
t_type *proc_type(t_type *result_type, t_param *parameters, arith n_bytes_params);
void genrck(register t_type *tp);
/* Get the bounds of a bounded type. */
void getbounds(register t_type *tp, arith *plo, arith *phi);
/* Construct a set type with base type "tp", but first
* perform some checks */
t_type *set_type(register t_type *tp);
void ArrayElSize(register t_type *tp);
void ArraySizes(register t_type *tp);
void FreeType(register t_type *tp);
void DeclareType(t_node *nd, register t_def *df, register t_type *tp);
void SolveForwardTypeRefs(register t_def *df);
void ForceForwardTypeDef(register t_def *df);
t_type *RemoveEqual(register t_type *tpx);
int type_or_forward(t_type *tp);
t_type *intorcard(register t_type *left, register t_type *right);
#ifdef DEBUG
void DumpType(register t_type *tp);
#endif
int fit(arith sz, int nbytes);
/* Greatest common divisotr. */
int gcd(int m, int n);
/* Least common multiple. */
int lcm(int m, int n);
#endif /* TYPE_H_ */

View file

@ -19,34 +19,33 @@
#include <em_label.h> #include <em_label.h>
#include <assert.h> #include <assert.h>
#include "type.h" #include "type.h"
#include "LLlex.h" #include "LLlex.h"
#include "idf.h" #include "idf.h"
#include "def.h" #include "def.h"
#include "node.h" #include "node.h"
#include "error.h"
#include "typequiv.h"
#include "warning.h" #include "warning.h"
#include "main.h" #include "main.h"
#include "stab.h"
#include "Lpars.h" #include "Lpars.h"
#include "print.h"
#include "chk_expr.h"
extern char *sprint();
int static int TstTypeEquiv(t_type *tp1, t_type *tp2)
TstTypeEquiv(tp1, tp2)
t_type *tp1, *tp2;
{ {
/* test if two types are equivalent. /* test if two types are equivalent.
*/ */
return tp1 == tp2 return (tp1 == tp2) ||
|| (tp1 == error_type) ||
tp1 == error_type (tp2 == error_type);
||
tp2 == error_type;
} }
int static int TstParEquiv(register t_type *tp1, register t_type *tp2)
TstParEquiv(tp1, tp2)
register t_type *tp1, *tp2;
{ {
/* test if two parameter types are equivalent. This routine /* test if two parameter types are equivalent. This routine
is used to check if two different procedure declarations is used to check if two different procedure declarations
@ -67,9 +66,7 @@ TstParEquiv(tp1, tp2)
); );
} }
int int TstProcEquiv(t_type *tp1, t_type *tp2)
TstProcEquiv(tp1, tp2)
t_type *tp1, *tp2;
{ {
/* Test if two procedure types are equivalent. This routine /* Test if two procedure types are equivalent. This routine
may also be used for the testing of assignment compatibility may also be used for the testing of assignment compatibility
@ -99,9 +96,7 @@ TstProcEquiv(tp1, tp2)
return p1 == p2; return p1 == p2;
} }
int int TstCompat(register t_type *tp1, register t_type *tp2)
TstCompat(tp1, tp2)
register t_type *tp1, *tp2;
{ {
/* test if two types are compatible. See section 6.3 of the /* test if two types are compatible. See section 6.3 of the
Modula-2 Report for a definition of "compatible". Modula-2 Report for a definition of "compatible".
@ -138,9 +133,7 @@ TstCompat(tp1, tp2)
; ;
} }
int int TstAssCompat(register t_type *tp1, register t_type *tp2)
TstAssCompat(tp1, tp2)
register t_type *tp1, *tp2;
{ {
/* Test if two types are assignment compatible. /* Test if two types are assignment compatible.
See Def 9.1. See Def 9.1.
@ -177,9 +170,7 @@ TstAssCompat(tp1, tp2)
return 0; return 0;
} }
char * char *incompat(register t_type *tp1, register t_type *tp2)
incompat(tp1, tp2)
register t_type *tp1, *tp2;
{ {
if (tp1->tp_fund == T_HIDDEN || tp2->tp_fund == T_HIDDEN) { if (tp1->tp_fund == T_HIDDEN || tp2->tp_fund == T_HIDDEN) {
@ -188,11 +179,7 @@ incompat(tp1, tp2)
return "type incompatibility"; return "type incompatibility";
} }
int int TstParCompat(int parno, register t_type *formaltype, int VARflag, t_node **nd, t_def *edf)
TstParCompat(parno, formaltype, VARflag, nd, edf)
register t_type *formaltype;
t_node **nd;
t_def *edf;
{ {
/* Check type compatibility for a parameter in a procedure call. /* Check type compatibility for a parameter in a procedure call.
Assignment compatibility may do if the parameter is Assignment compatibility may do if the parameter is
@ -268,11 +255,7 @@ TstParCompat(parno, formaltype, VARflag, nd, edf)
return 0; return 0;
} }
CompatCheck(nd, tp, message, fc) int CompatCheck(register t_node **nd, t_type *tp, char *message, int (*fc)())
register t_node **nd;
t_type *tp;
char *message;
int (*fc)();
{ {
if (! (*fc)(tp, (*nd)->nd_type)) { if (! (*fc)(tp, (*nd)->nd_type)) {
if (message) { if (message) {
@ -286,10 +269,7 @@ CompatCheck(nd, tp, message, fc)
return 1; return 1;
} }
ChkAssCompat(nd, tp, message) int ChkAssCompat(t_node **nd, t_type *tp, char *message)
t_node **nd;
t_type *tp;
char *message;
{ {
/* Check assignment compatibility of node "nd" with type "tp". /* Check assignment compatibility of node "nd" with type "tp".
Give an error message when it fails Give an error message when it fails
@ -301,10 +281,7 @@ ChkAssCompat(nd, tp, message)
return CompatCheck(nd, tp, message, TstAssCompat); return CompatCheck(nd, tp, message, TstAssCompat);
} }
ChkCompat(nd, tp, message) int ChkCompat(t_node **nd, t_type *tp, char *message)
t_node **nd;
t_type *tp;
char *message;
{ {
/* Check compatibility of node "nd" with type "tp". /* Check compatibility of node "nd" with type "tp".
Give an error message when it fails Give an error message when it fails

25
lang/m2/comp/typequiv.h Normal file
View file

@ -0,0 +1,25 @@
/* Copyright (c) 2019 ACK Project.
* See the copyright notice in the ACK home directory,
* in the file "Copyright".
*
* Created on: 2019-02-25
*
*/
#ifndef TYPEQUIV_H_
#define TYPEQUIV_H_
typedef struct type t_type;
typedef struct node t_node;
typedef struct def t_def;
int TstProcEquiv(t_type *tp1, t_type *tp2);
int TstCompat(register t_type *tp1, register t_type *tp2);
int TstAssCompat(register t_type *tp1, register t_type *tp2);
int TstParCompat(int parno, register t_type *formaltype, int VARflag, t_node **nd, t_def *edf);
int ChkCompat(t_node **nd, t_type *tp, char *message);
int ChkAssCompat(t_node **nd, t_type *tp, char *message);
char *incompat(register t_type *tp1, register t_type *tp2);
#endif /* TYPEQUIV_H_ */

View file

@ -35,16 +35,19 @@
#include "node.h" #include "node.h"
#include "Lpars.h" #include "Lpars.h"
#include "desig.h" #include "desig.h"
#include "typequiv.h"
#include "f_info.h" #include "f_info.h"
#include "idf.h" #include "idf.h"
#include "chk_expr.h" #include "chk_expr.h"
#include "walk.h" #include "walk.h"
#include "misc.h" #include "misc.h"
#include "error.h"
#include "tmpvar.h"
#include "stab.h"
#include "code.h"
#include "warning.h" #include "warning.h"
extern arith NewPtr(); int CaseCode(t_node *, label, int);
extern arith NewInt();
extern arith TmpSpace();
extern int proclevel; extern int proclevel;
extern int gdb_flag; extern int gdb_flag;
@ -58,13 +61,8 @@ static t_type* func_type;
static t_node* priority; static t_node* priority;
static int oldlineno; static int oldlineno;
static int RegisterMessage();
static int WalkDef();
#ifdef DBSYMTAB
static int stabdef();
#endif
static int MkCalls();
static void UseWarnings();
#define NO_EXIT_LABEL ((label)0) #define NO_EXIT_LABEL ((label)0)
#define RETURN_LABEL ((label)1) #define RETURN_LABEL ((label)1)
@ -72,13 +70,18 @@ static void UseWarnings();
#define REACH_FLAG 1 #define REACH_FLAG 1
#define EXIT_FLAG 2 #define EXIT_FLAG 2
void DoAssign(); /* Forward declarations. */
static void WalkDef(register t_def*);
static void MkCalls(register t_def*);
static void UseWarnings(register t_def*);
static void RegisterMessage(register t_def*);
static void WalkDefList(register t_def*, void (*proc)(t_def*));
#ifdef DBSYMTAB
static void stabdef(t_def*);
#endif
int
LblWalkNode(lbl, nd, exit, reach) int LblWalkNode(label lbl, t_node *nd, int exit, int reach)
label lbl,
exit;
t_node* nd;
{ {
/* Generate code for node "nd", after generating instruction /* Generate code for node "nd", after generating instruction
label "lbl". "exit" is the exit label for the closest label "lbl". "exit" is the exit label for the closest
@ -91,8 +94,7 @@ t_node* nd;
static arith tmpprio; static arith tmpprio;
STATIC static void DoPriority(void)
DoPriority()
{ {
/* For the time being (???), handle priorities by calls to /* For the time being (???), handle priorities by calls to
the runtime system the runtime system
@ -107,8 +109,7 @@ DoPriority()
} }
} }
STATIC static void EndPriority(void)
EndPriority()
{ {
if (priority) if (priority)
{ {
@ -118,8 +119,7 @@ EndPriority()
} }
} }
def_ilb(l) void def_ilb(label l)
label l;
{ {
/* Instruction label definition. Forget about line number. /* Instruction label definition. Forget about line number.
*/ */
@ -127,10 +127,8 @@ def_ilb(l)
oldlineno = 0; oldlineno = 0;
} }
DoLineno(nd) register t_node* nd; void DoLineno(register t_node* nd)
{ {
/* Generate line number information, if necessary.
*/
if ((!options['L'] if ((!options['L']
#ifdef DBSYMTAB #ifdef DBSYMTAB
|| options['g'] || options['g']
@ -156,13 +154,8 @@ DoLineno(nd) register t_node* nd;
} }
} }
DoFilename(needed) void DoFilename(int needed)
{ {
/* Generate filename information, when needed.
This routine is called at the generation of a
procedure entry, and after generating a call to
another procedure.
*/
static label filename_label = 0; static label filename_label = 0;
oldlineno = 0; /* always invalidate remembered line number */ oldlineno = 0; /* always invalidate remembered line number */
@ -180,12 +173,8 @@ DoFilename(needed)
} }
} }
WalkModule(module) register t_def* module; void WalkModule(register t_def* module)
{ {
/* Walk through a module, and all its local definitions.
Also generate code for its body.
This code is collected in an initialization routine.
*/
register t_scope* sc; register t_scope* sc;
t_scopelist* savevis = CurrVis; t_scopelist* savevis = CurrVis;
@ -284,11 +273,9 @@ WalkModule(module) register t_def* module;
WalkDefList(sc->sc_def, UseWarnings); WalkDefList(sc->sc_def, UseWarnings);
} }
WalkProcedure(procedure) register t_def* procedure; void WalkProcedure(register t_def* procedure)
{ {
/* Walk through the definition of a procedure and all its
local definitions, checking and generating code.
*/
t_scopelist* savevis = CurrVis; t_scopelist* savevis = CurrVis;
register t_type* tp; register t_type* tp;
register t_param* param; register t_param* param;
@ -574,10 +561,10 @@ WalkProcedure(procedure) register t_def* procedure;
WalkDefList(procscope->sc_def, UseWarnings); WalkDefList(procscope->sc_def, UseWarnings);
} }
static WalkDef(df) register t_def* df; /* Walk through a list of definitions */
static void WalkDef(register t_def* df)
{ {
/* Walk through a list of definitions
*/
switch (df->df_kind) switch (df->df_kind)
{ {
@ -602,10 +589,10 @@ static WalkDef(df) register t_def* df;
} }
} }
static MkCalls(df) register t_def* df; /* Generate calls to initialization routines of modules */
static void MkCalls(register t_def* df)
{ {
/* Generate calls to initialization routines of modules
*/
if (df->df_kind == D_MODULE) if (df->df_kind == D_MODULE)
{ {
@ -614,14 +601,8 @@ static MkCalls(df) register t_def* df;
} }
} }
WalkLink(nd, exit_label, end_reached) register t_node* nd; int WalkLink(register t_node* nd, label exit_label, int end_reached)
label exit_label;
{ {
/* Walk node "nd", which is a link.
"exit_label" is set to a label number when inside a LOOP.
"end_reached" maintains info about reachability (REACH_FLAG),
and whether an EXIT statement was seen (EXIT_FLAG).
*/
while (nd && nd->nd_class == Link) while (nd && nd->nd_class == Link)
{ /* statement list */ { /* statement list */
@ -632,8 +613,7 @@ label exit_label;
return WalkNode(nd, exit_label, end_reached); return WalkNode(nd, exit_label, end_reached);
} }
STATIC static void ForLoopVarExpr(register t_node* nd)
ForLoopVarExpr(nd) register t_node* nd;
{ {
register t_type* tp = nd->nd_type; register t_type* tp = nd->nd_type;
@ -641,12 +621,9 @@ ForLoopVarExpr(nd) register t_node* nd;
CodeCoercion(tp, BaseType(tp)); CodeCoercion(tp, BaseType(tp));
} }
int int WalkStat(register t_node* nd, label exit_label, int end_reached)
WalkStat(nd, exit_label, end_reached) register t_node* nd;
label exit_label;
{ {
/* Walk through a statement, generating code for it.
*/
register t_node* left = nd->nd_LEFT; register t_node* left = nd->nd_LEFT;
register t_node* right = nd->nd_RIGHT; register t_node* right = nd->nd_RIGHT;
@ -940,9 +917,8 @@ label exit_label;
return end_reached; return end_reached;
} }
extern int NodeCrash();
int (*WalkTable[])() = { int (*WalkTable[])(t_node*, label, int) = {
NodeCrash, NodeCrash,
NodeCrash, NodeCrash,
NodeCrash, NodeCrash,
@ -960,12 +936,9 @@ int (*WalkTable[])() = {
extern t_desig null_desig; extern t_desig null_desig;
ExpectBool(pnd, true_label, false_label) register t_node** pnd; void ExpectBool(register t_node** pnd, label true_label, label false_label)
label true_label, false_label;
{ {
/* "pnd" must indicate a boolean expression. Check this and
generate code to evaluate the expression.
*/
t_desig ds; t_desig ds;
ds = null_desig; ds = null_desig;
@ -980,13 +953,8 @@ label true_label, false_label;
} }
} }
int int WalkDesignator(t_node** pnd, t_desig* ds, int flags)
WalkDesignator(pnd, ds, flags)
t_node** pnd;
t_desig* ds;
{ {
/* Check designator and generate code for it
*/
if (!ChkVariable(pnd, flags)) if (!ChkVariable(pnd, flags))
return 0; return 0;
@ -996,8 +964,7 @@ t_desig* ds;
return 1; return 1;
} }
DoForInit(nd) int DoForInit(t_node* nd)
t_node* nd;
{ {
register t_node* right = nd->nd_RIGHT; register t_node* right = nd->nd_RIGHT;
register t_def* df; register t_def* df;
@ -1074,8 +1041,8 @@ DoForInit(nd)
return 1; return 1;
} }
void
DoAssign(nd) register t_node* nd; void DoAssign(register t_node* nd)
{ {
/* May we do it in this order (expression first) ??? /* May we do it in this order (expression first) ???
The reference manual sais nothing about it, but the book does: The reference manual sais nothing about it, but the book does:
@ -1111,7 +1078,7 @@ void
CodeMove(&dsr, nd->nd_LEFT, tp); CodeMove(&dsr, nd->nd_LEFT, tp);
} }
static RegisterMessage(df) register t_def* df; static void RegisterMessage(register t_def* df)
{ {
register t_type* tp; register t_type* tp;
@ -1140,11 +1107,7 @@ static RegisterMessage(df) register t_def* df;
} }
} }
static void static void df_warning(t_node* nd, t_def* df, char* warning)
df_warning(nd, df, warning)
t_node* nd;
t_def* df;
char* warning;
{ {
if (!(df->df_kind & (D_VARIABLE | D_PROCEDURE | D_TYPE | D_CONST | D_PROCHEAD))) if (!(df->df_kind & (D_VARIABLE | D_PROCEDURE | D_TYPE | D_CONST | D_PROCHEAD)))
{ {
@ -1160,8 +1123,7 @@ char* warning;
} }
} }
static void static void UseWarnings(register t_def* df)
UseWarnings(df) register t_def* df;
{ {
t_node* nd = df->df_scope->sc_end; t_node* nd = df->df_scope->sc_end;
@ -1208,8 +1170,7 @@ static void
} }
} }
WalkDefList(df, proc) register t_def* df; static void WalkDefList(register t_def* df, void (*proc)(t_def*))
int (*proc)();
{ {
for (; df; df = df->df_nextinscope) for (; df; df = df->df_nextinscope)
{ {
@ -1218,9 +1179,7 @@ int (*proc)();
} }
#ifdef DBSYMTAB #ifdef DBSYMTAB
static int static void stabdef(t_def* df)
stabdef(df)
t_def* df;
{ {
switch (df->df_kind) switch (df->df_kind)
{ {

View file

@ -4,17 +4,22 @@
* *
* Author: Ceriel J.H. Jacobs * Author: Ceriel J.H. Jacobs
*/ */
/* P A R S E T R E E W A L K E R */ /* P A R S E T R E E W A L K E R */
#ifndef WALK_H_
#define WALK_H_
/* $Id$ */ #include "em_label.h"
/* Forward type declarations. */
typedef struct node t_node;
typedef struct def t_def;
typedef struct desig t_desig;
/* Definition of WalkNode macro /* Definition of WalkNode macro
*/ */
extern int (*WalkTable[])(t_node*, label, int);
extern int (*WalkTable[])(); #define WalkNode(xnd, xlab, rch) (*WalkTable[(unsigned int)((xnd)->nd_class)])((xnd), (xlab),(rch))
#define WalkNode(xnd, xlab, rch) (*WalkTable[(xnd)->nd_class])((xnd), (xlab),(rch))
extern label text_label; extern label text_label;
extern label data_label; extern label data_label;
@ -25,3 +30,46 @@ extern label data_label;
#define CAL(nm, sz) (C_cal(nm), C_asp((arith)(sz))) #define CAL(nm, sz) (C_cal(nm), C_asp((arith)(sz)))
#define c_bra(x) C_bra((label) (x)) #define c_bra(x) C_bra((label) (x))
#endif #endif
int LblWalkNode(label lbl, t_node *nd, int exit, int reach);
void def_ilb(label l);
/* Generate line information as necessary for "nd". */
void DoLineno(register t_node* nd);
/* Generate filename information, when needed.
This routine is called at the generation of a
procedure entry, and after generating a call to
another procedure. The current active filename
is used.
*/
void DoFilename(int needed);
/* Walk through a module, and all its local definitions.
Also generate code for its body.
This code is collected in an initialization routine.
*/
void WalkModule(register t_def* module);
/* Walk through the definition of a procedure and all its
local definitions, checking and generating code.
*/
void WalkProcedure(register t_def* procedure);
/* Walk node "nd", which is a link.
"exit_label" is set to a label number when inside a LOOP.
"end_reached" maintains info about reachability (REACH_FLAG),
and whether an EXIT statement was seen (EXIT_FLAG).
*/
int WalkLink(register t_node* nd, label exit_label, int end_reached);
/* Walk through a statement node "nd", generating code for it. */
int WalkStat(register t_node* nd, label exit_label, int end_reached);
/* Generate code to evaluate a boolean expression "pnd" */
void ExpectBool(register t_node** pnd, label true_label, label false_label);
/* Check designator and generate code for it */
int WalkDesignator(t_node** pnd, t_desig* ds, int flags);
void DoAssign(register t_node* nd);
int DoForInit(t_node* nd);
#endif /* WALK_H_ */