1987-04-29 10:22:07 +00:00
|
|
|
/*
|
|
|
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
|
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
|
|
*
|
|
|
|
* Author: Ceriel J.H. Jacobs
|
|
|
|
*/
|
|
|
|
|
1986-04-21 17:27:06 +00:00
|
|
|
/* P A R S E T R E E W A L K E R */
|
|
|
|
|
1994-06-24 14:02:31 +00:00
|
|
|
/* $Id$ */
|
1987-04-29 10:22:07 +00:00
|
|
|
|
1986-04-21 17:27:06 +00:00
|
|
|
/* Routines to walk through parts of the parse tree, and generate
|
|
|
|
code for these parts.
|
|
|
|
*/
|
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2013-05-14 21:24:38 +00:00
|
|
|
#include "parameters.h"
|
2017-01-08 10:23:56 +00:00
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
#include <em_arith.h>
|
|
|
|
#include <em_label.h>
|
|
|
|
#include <em_reg.h>
|
|
|
|
#include <em_code.h>
|
|
|
|
#include <m2_traps.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <alloc.h>
|
|
|
|
#include <stb.h>
|
|
|
|
|
|
|
|
#include "LLlex.h"
|
|
|
|
#include "def.h"
|
|
|
|
#include "type.h"
|
|
|
|
#include "scope.h"
|
|
|
|
#include "main.h"
|
|
|
|
#include "node.h"
|
|
|
|
#include "Lpars.h"
|
|
|
|
#include "desig.h"
|
|
|
|
#include "f_info.h"
|
|
|
|
#include "idf.h"
|
|
|
|
#include "chk_expr.h"
|
|
|
|
#include "walk.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "warning.h"
|
|
|
|
|
|
|
|
extern arith NewPtr();
|
|
|
|
extern arith NewInt();
|
|
|
|
extern arith TmpSpace();
|
|
|
|
|
|
|
|
extern int proclevel;
|
|
|
|
extern int gdb_flag;
|
|
|
|
|
|
|
|
label text_label;
|
|
|
|
label data_label = 1;
|
|
|
|
struct withdesig* WithDesigs;
|
|
|
|
t_node* Modules;
|
|
|
|
|
|
|
|
static t_type* func_type;
|
|
|
|
static t_node* priority;
|
|
|
|
static int oldlineno;
|
|
|
|
|
|
|
|
static int RegisterMessage();
|
|
|
|
static int WalkDef();
|
1993-11-10 12:44:24 +00:00
|
|
|
#ifdef DBSYMTAB
|
2017-01-08 10:23:56 +00:00
|
|
|
static int stabdef();
|
1993-11-10 12:44:24 +00:00
|
|
|
#endif
|
2017-01-08 10:23:56 +00:00
|
|
|
static int MkCalls();
|
|
|
|
static void UseWarnings();
|
1987-10-19 11:28:37 +00:00
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
#define NO_EXIT_LABEL ((label)0)
|
|
|
|
#define RETURN_LABEL ((label)1)
|
1986-09-25 19:39:06 +00:00
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
#define REACH_FLAG 1
|
|
|
|
#define EXIT_FLAG 2
|
1989-03-20 13:32:06 +00:00
|
|
|
|
2016-11-10 21:04:18 +00:00
|
|
|
void DoAssign();
|
|
|
|
|
1989-03-20 13:32:06 +00:00
|
|
|
int
|
2017-01-08 10:23:56 +00:00
|
|
|
LblWalkNode(lbl, nd, exit, reach)
|
|
|
|
label lbl,
|
|
|
|
exit;
|
|
|
|
t_node* nd;
|
1987-09-23 16:39:43 +00:00
|
|
|
{
|
|
|
|
/* Generate code for node "nd", after generating instruction
|
|
|
|
label "lbl". "exit" is the exit label for the closest
|
|
|
|
enclosing LOOP.
|
|
|
|
*/
|
|
|
|
|
1988-01-28 16:15:16 +00:00
|
|
|
def_ilb(lbl);
|
1989-03-20 13:32:06 +00:00
|
|
|
return WalkNode(nd, exit, reach);
|
1987-09-23 16:39:43 +00:00
|
|
|
}
|
|
|
|
|
1988-03-23 17:44:25 +00:00
|
|
|
static arith tmpprio;
|
|
|
|
|
1986-12-01 10:06:53 +00:00
|
|
|
STATIC
|
|
|
|
DoPriority()
|
|
|
|
{
|
1987-04-29 10:22:07 +00:00
|
|
|
/* For the time being (???), handle priorities by calls to
|
|
|
|
the runtime system
|
|
|
|
*/
|
2017-01-08 10:23:56 +00:00
|
|
|
if (priority)
|
|
|
|
{
|
1988-03-23 17:44:25 +00:00
|
|
|
tmpprio = NewInt();
|
|
|
|
C_loc(priority->nd_INT);
|
2017-01-08 10:23:56 +00:00
|
|
|
CAL("stackprio", (int)word_size);
|
1988-03-23 17:44:25 +00:00
|
|
|
C_lfr(word_size);
|
|
|
|
C_stl(tmpprio);
|
1986-12-01 10:06:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
STATIC
|
|
|
|
EndPriority()
|
|
|
|
{
|
2017-01-08 10:23:56 +00:00
|
|
|
if (priority)
|
|
|
|
{
|
1988-03-23 17:44:25 +00:00
|
|
|
C_lol(tmpprio);
|
2017-01-08 10:23:56 +00:00
|
|
|
CAL("unstackprio", (int)word_size);
|
1988-03-23 17:44:25 +00:00
|
|
|
FreeInt(tmpprio);
|
1986-12-01 10:06:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1988-01-28 16:15:16 +00:00
|
|
|
def_ilb(l)
|
2017-01-08 10:23:56 +00:00
|
|
|
label l;
|
1988-01-28 16:15:16 +00:00
|
|
|
{
|
1989-03-20 13:32:06 +00:00
|
|
|
/* Instruction label definition. Forget about line number.
|
|
|
|
*/
|
1988-01-28 16:15:16 +00:00
|
|
|
C_df_ilb(l);
|
|
|
|
oldlineno = 0;
|
|
|
|
}
|
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
DoLineno(nd) register t_node* nd;
|
1988-01-28 16:15:16 +00:00
|
|
|
{
|
1989-03-20 13:32:06 +00:00
|
|
|
/* Generate line number information, if necessary.
|
|
|
|
*/
|
2017-01-08 10:23:56 +00:00
|
|
|
if ((!options['L']
|
1991-03-13 13:49:56 +00:00
|
|
|
#ifdef DBSYMTAB
|
2017-01-08 10:23:56 +00:00
|
|
|
|| options['g']
|
1991-03-13 13:49:56 +00:00
|
|
|
#endif /* DBSYMTAB */
|
2017-01-08 10:23:56 +00:00
|
|
|
)
|
|
|
|
&& nd->nd_lineno && nd->nd_lineno != oldlineno)
|
|
|
|
{
|
1988-01-28 16:15:16 +00:00
|
|
|
oldlineno = nd->nd_lineno;
|
2017-01-08 10:23:56 +00:00
|
|
|
if (!options['L'])
|
|
|
|
C_lin((arith)nd->nd_lineno);
|
1991-02-18 17:18:36 +00:00
|
|
|
#ifdef DBSYMTAB
|
2017-01-08 10:23:56 +00:00
|
|
|
if (options['g'])
|
|
|
|
{
|
|
|
|
static int ms_lineno;
|
1990-07-30 15:56:25 +00:00
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
if (ms_lineno != nd->nd_lineno)
|
|
|
|
{
|
1990-07-30 15:56:25 +00:00
|
|
|
ms_lineno = nd->nd_lineno;
|
2017-01-08 10:23:56 +00:00
|
|
|
C_ms_std((char*)0, N_SLINE, ms_lineno);
|
1990-07-30 15:56:25 +00:00
|
|
|
}
|
|
|
|
}
|
1991-02-18 17:18:36 +00:00
|
|
|
#endif /* DBSYMTAB */
|
1988-01-28 16:15:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1988-10-25 17:43:19 +00:00
|
|
|
DoFilename(needed)
|
1986-05-23 09:46:31 +00:00
|
|
|
{
|
1989-03-20 13:32:06 +00:00
|
|
|
/* Generate filename information, when needed.
|
|
|
|
This routine is called at the generation of a
|
|
|
|
procedure entry, and after generating a call to
|
|
|
|
another procedure.
|
|
|
|
*/
|
2017-01-08 10:23:56 +00:00
|
|
|
static label filename_label = 0;
|
1986-05-23 09:46:31 +00:00
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
oldlineno = 0; /* always invalidate remembered line number */
|
|
|
|
if (needed && !options['L'])
|
|
|
|
{
|
1986-11-26 16:40:45 +00:00
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
if (!filename_label)
|
|
|
|
{
|
1987-07-30 13:37:39 +00:00
|
|
|
filename_label = 1;
|
2017-01-08 10:23:56 +00:00
|
|
|
C_df_dlb((label)1);
|
|
|
|
C_rom_scon(FileName, (arith)(strlen(FileName) + 1));
|
1986-05-23 09:46:31 +00:00
|
|
|
}
|
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
C_fil_dlb((label)1, (arith)0);
|
1986-05-23 09:46:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
WalkModule(module) register t_def* module;
|
1986-04-21 17:27:06 +00:00
|
|
|
{
|
|
|
|
/* Walk through a module, and all its local definitions.
|
|
|
|
Also generate code for its body.
|
1986-09-25 19:39:06 +00:00
|
|
|
This code is collected in an initialization routine.
|
1986-04-21 17:27:06 +00:00
|
|
|
*/
|
2017-01-08 10:23:56 +00:00
|
|
|
register t_scope* sc;
|
|
|
|
t_scopelist* savevis = CurrVis;
|
1986-04-21 17:27:06 +00:00
|
|
|
|
1986-04-28 18:06:58 +00:00
|
|
|
CurrVis = module->mod_vis;
|
1988-03-08 10:18:58 +00:00
|
|
|
priority = module->mod_priority;
|
1986-05-23 19:25:21 +00:00
|
|
|
sc = CurrentScope;
|
1986-04-22 22:36:16 +00:00
|
|
|
|
1986-06-26 09:39:36 +00:00
|
|
|
/* Walk through it's local definitions
|
1986-04-21 17:27:06 +00:00
|
|
|
*/
|
1987-10-19 11:28:37 +00:00
|
|
|
WalkDefList(sc->sc_def, WalkDef);
|
1986-04-21 17:27:06 +00:00
|
|
|
|
|
|
|
/* Now, generate initialization code for this module.
|
|
|
|
First call initialization routines for modules defined within
|
|
|
|
this module.
|
|
|
|
*/
|
2017-01-08 10:23:56 +00:00
|
|
|
sc->sc_off = 0; /* no locals (yet) */
|
|
|
|
text_label = 1; /* label at end of initialization routine */
|
|
|
|
TmpOpen(sc); /* Initialize for temporaries */
|
1986-06-26 09:39:36 +00:00
|
|
|
C_pro_narg(sc->sc_name);
|
1993-11-10 12:44:24 +00:00
|
|
|
#ifdef DBSYMTAB
|
2017-01-08 10:23:56 +00:00
|
|
|
if (options['g'])
|
|
|
|
{
|
1993-11-10 12:44:24 +00:00
|
|
|
stb_string(module, D_MODULE);
|
|
|
|
WalkDefList(sc->sc_def, stabdef);
|
2017-01-08 10:23:56 +00:00
|
|
|
if (state == PROGRAM && module == Defined)
|
|
|
|
{
|
1993-11-10 12:44:24 +00:00
|
|
|
C_ms_stb_cst(module->df_idf->id_text,
|
2017-01-08 10:23:56 +00:00
|
|
|
N_MAIN,
|
|
|
|
0,
|
|
|
|
(arith)0);
|
1993-11-10 12:44:24 +00:00
|
|
|
}
|
|
|
|
stb_string(module, D_END);
|
|
|
|
}
|
|
|
|
#endif
|
1986-12-01 10:06:53 +00:00
|
|
|
DoPriority();
|
2017-01-08 10:23:56 +00:00
|
|
|
if (module == Defined)
|
|
|
|
{
|
1986-05-28 18:36:51 +00:00
|
|
|
/* Body of implementation or program module.
|
|
|
|
Call initialization routines of imported modules.
|
|
|
|
Also prevent recursive calls of this one.
|
|
|
|
*/
|
2017-01-08 10:23:56 +00:00
|
|
|
register t_node* nd = Modules;
|
1986-05-28 18:36:51 +00:00
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
if (state == IMPLEMENTATION)
|
|
|
|
{
|
1987-04-29 10:22:07 +00:00
|
|
|
/* We don't actually prevent recursive calls,
|
1986-06-04 09:01:48 +00:00
|
|
|
but do nothing if called recursively
|
|
|
|
*/
|
1987-05-18 15:57:33 +00:00
|
|
|
C_df_dlb(++data_label);
|
2017-01-08 10:23:56 +00:00
|
|
|
C_con_cst((arith)0);
|
1986-09-25 19:39:06 +00:00
|
|
|
/* if this one is set to non-zero, the initialization
|
|
|
|
was already done.
|
|
|
|
*/
|
2017-01-08 10:23:56 +00:00
|
|
|
C_loe_dlb(data_label, (arith)0);
|
1986-09-25 19:39:06 +00:00
|
|
|
C_zne(RETURN_LABEL);
|
2017-01-08 10:23:56 +00:00
|
|
|
C_ine_dlb(data_label, (arith)0);
|
1986-06-04 09:01:48 +00:00
|
|
|
}
|
2017-01-08 10:23:56 +00:00
|
|
|
else if (!options['R'])
|
|
|
|
{
|
1989-03-20 13:32:06 +00:00
|
|
|
/* put funny value in BSS, in an attempt to detect
|
|
|
|
uninitialized variables
|
|
|
|
*/
|
1988-11-28 12:54:38 +00:00
|
|
|
C_cal("killbss");
|
|
|
|
}
|
1986-05-28 18:36:51 +00:00
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
for (; nd; nd = nd->nd_NEXT)
|
|
|
|
{
|
1988-03-23 17:44:25 +00:00
|
|
|
C_cal(nd->nd_def->mod_vis->sc_scope->sc_name);
|
1986-05-28 18:36:51 +00:00
|
|
|
}
|
1988-10-25 17:43:19 +00:00
|
|
|
DoFilename(1);
|
1986-05-28 18:36:51 +00:00
|
|
|
}
|
1987-10-19 11:28:37 +00:00
|
|
|
WalkDefList(sc->sc_def, MkCalls);
|
1986-05-28 18:36:51 +00:00
|
|
|
proclevel++;
|
1991-02-18 17:18:36 +00:00
|
|
|
#ifdef DBSYMTAB
|
2017-01-08 10:23:56 +00:00
|
|
|
if (options['g'])
|
|
|
|
{
|
|
|
|
C_ms_std((char*)0, N_LBRAC, gdb_flag ? 0 : proclevel);
|
1990-07-30 15:56:25 +00:00
|
|
|
}
|
1991-02-18 17:18:36 +00:00
|
|
|
#endif /* DBSYMTAB */
|
1989-03-20 13:32:06 +00:00
|
|
|
WalkNode(module->mod_body, NO_EXIT_LABEL, REACH_FLAG);
|
1987-05-27 10:16:03 +00:00
|
|
|
DO_DEBUG(options['X'], PrNode(module->mod_body, 0));
|
1988-01-28 16:15:16 +00:00
|
|
|
def_ilb(RETURN_LABEL);
|
1986-12-01 10:06:53 +00:00
|
|
|
EndPriority();
|
2017-01-08 10:23:56 +00:00
|
|
|
C_ret((arith)0);
|
1991-02-18 17:18:36 +00:00
|
|
|
#ifdef DBSYMTAB
|
2017-01-08 10:23:56 +00:00
|
|
|
if (options['g'])
|
|
|
|
{
|
|
|
|
C_ms_std((char*)0, N_RBRAC, gdb_flag ? 0 : proclevel);
|
1990-07-30 15:56:25 +00:00
|
|
|
}
|
1991-02-18 17:18:36 +00:00
|
|
|
#endif /* DBSYMTAB */
|
1986-05-23 19:25:21 +00:00
|
|
|
C_end(-sc->sc_off);
|
1986-05-28 18:36:51 +00:00
|
|
|
proclevel--;
|
1986-05-23 09:46:31 +00:00
|
|
|
TmpClose();
|
1986-04-21 17:27:06 +00:00
|
|
|
|
1986-06-26 09:39:36 +00:00
|
|
|
CurrVis = savevis;
|
1987-10-19 11:28:37 +00:00
|
|
|
WalkDefList(sc->sc_def, UseWarnings);
|
1986-04-21 17:27:06 +00:00
|
|
|
}
|
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
WalkProcedure(procedure) register t_def* procedure;
|
1986-04-21 17:27:06 +00:00
|
|
|
{
|
|
|
|
/* Walk through the definition of a procedure and all its
|
1986-06-26 09:39:36 +00:00
|
|
|
local definitions, checking and generating code.
|
1986-04-21 17:27:06 +00:00
|
|
|
*/
|
2017-01-08 10:23:56 +00:00
|
|
|
t_scopelist* savevis = CurrVis;
|
|
|
|
register t_type* tp;
|
|
|
|
register t_param* param;
|
|
|
|
register t_scope* procscope = procedure->prc_vis->sc_scope;
|
|
|
|
label too_big = 0; /* returnsize larger than returnarea */
|
|
|
|
arith StackAdjustment = 0; /* space for conformant arrays */
|
|
|
|
arith retsav = 0; /* temporary space for return value */
|
1986-09-25 19:39:06 +00:00
|
|
|
arith func_res_size = 0;
|
1991-02-19 16:22:41 +00:00
|
|
|
#ifdef USE_INSERT
|
1989-03-20 13:32:06 +00:00
|
|
|
int partno = C_getid();
|
|
|
|
int partno2 = C_getid();
|
1991-02-19 16:22:41 +00:00
|
|
|
#else
|
|
|
|
label cd_init;
|
|
|
|
label cd_body;
|
|
|
|
#endif
|
1986-04-21 17:27:06 +00:00
|
|
|
|
1986-05-16 17:15:36 +00:00
|
|
|
proclevel++;
|
1986-04-28 18:06:58 +00:00
|
|
|
CurrVis = procedure->prc_vis;
|
1986-06-26 09:39:36 +00:00
|
|
|
|
1986-06-20 14:36:49 +00:00
|
|
|
/* Generate code for all local modules and procedures
|
|
|
|
*/
|
1988-03-08 10:18:58 +00:00
|
|
|
WalkDefList(procscope->sc_def, WalkDef);
|
1986-04-21 17:27:06 +00:00
|
|
|
|
1989-03-10 10:40:07 +00:00
|
|
|
func_type = tp = RemoveEqual(ResultType(procedure->df_type));
|
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
if (tp)
|
|
|
|
{
|
1989-03-10 10:40:07 +00:00
|
|
|
func_res_size = WA(tp->tp_size);
|
2017-01-08 10:23:56 +00:00
|
|
|
if (TooBigForReturnArea(tp))
|
|
|
|
{
|
1989-03-22 09:53:47 +00:00
|
|
|
#ifdef BIG_RESULT_ON_STACK
|
|
|
|
/* The result type of this procedure is too big.
|
1989-03-10 10:40:07 +00:00
|
|
|
The caller will have reserved space on its stack,
|
|
|
|
above the parameters, to store the result.
|
|
|
|
*/
|
|
|
|
too_big = 1;
|
1989-03-22 09:53:47 +00:00
|
|
|
#else
|
|
|
|
/* The result type of this procedure is too big.
|
|
|
|
The actual procedure will return a pointer to a
|
|
|
|
global data area in which the function result is
|
|
|
|
stored.
|
|
|
|
Notice that this makes the code non-reentrant.
|
|
|
|
Here, we create the data area for the function
|
|
|
|
result.
|
|
|
|
*/
|
|
|
|
too_big = ++data_label;
|
|
|
|
C_df_dlb(too_big);
|
|
|
|
C_bss_cst(func_res_size, (arith)0, 0);
|
1991-12-17 14:36:35 +00:00
|
|
|
#endif /* BIG_RESULT_ON_STACK */
|
1989-03-10 10:40:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1986-04-21 17:27:06 +00:00
|
|
|
/* Generate code for this procedure
|
|
|
|
*/
|
1988-03-31 16:09:53 +00:00
|
|
|
TmpOpen(procscope);
|
1991-02-19 16:22:41 +00:00
|
|
|
#ifdef USE_INSERT
|
2017-01-08 10:23:56 +00:00
|
|
|
C_insertpart(partno2); /* procedure header */
|
1991-02-19 16:22:41 +00:00
|
|
|
#else
|
1991-03-13 13:49:56 +00:00
|
|
|
C_pro_narg(procedure->prc_name);
|
1991-02-19 16:22:41 +00:00
|
|
|
#ifdef DBSYMTAB
|
2017-01-08 10:23:56 +00:00
|
|
|
if (options['g'])
|
|
|
|
{
|
1993-11-10 12:44:24 +00:00
|
|
|
stb_string(procedure, D_PROCEDURE);
|
|
|
|
WalkDefList(procscope->sc_def, stabdef);
|
|
|
|
stb_string(procedure, D_PEND);
|
2017-01-08 10:23:56 +00:00
|
|
|
C_ms_std((char*)0, N_LBRAC, gdb_flag ? 0 : proclevel);
|
1991-02-19 16:22:41 +00:00
|
|
|
}
|
|
|
|
#endif /* DBSYMTAB */
|
|
|
|
C_ms_par(procedure->df_type->prc_nbpar
|
|
|
|
#ifdef BIG_RESULT_ON_STACK
|
2017-01-08 10:23:56 +00:00
|
|
|
+ (too_big ? func_res_size : 0)
|
1991-02-19 16:22:41 +00:00
|
|
|
#endif
|
2017-01-08 10:23:56 +00:00
|
|
|
);
|
1991-02-19 16:22:41 +00:00
|
|
|
#endif
|
1989-04-14 18:25:39 +00:00
|
|
|
/* generate code for filename only when the procedure can be
|
|
|
|
exported, either directly or by taking the address.
|
|
|
|
This cannot be done if the level is bigger than one (because in
|
|
|
|
this case it is a nested procedure).
|
|
|
|
*/
|
|
|
|
DoFilename(procscope->sc_level == 1);
|
|
|
|
DoPriority();
|
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
text_label = 1; /* label at end of procedure */
|
1989-03-20 13:32:06 +00:00
|
|
|
|
1992-05-11 11:30:04 +00:00
|
|
|
/* Check if we must save the stack pointer */
|
|
|
|
for (param = ParamList(procedure->df_type);
|
|
|
|
param;
|
2017-01-08 10:23:56 +00:00
|
|
|
param = param->par_next)
|
|
|
|
{
|
|
|
|
if (!IsVarParam(param))
|
|
|
|
{
|
1992-05-11 11:30:04 +00:00
|
|
|
tp = TypeOfParam(param);
|
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
if (IsConformantArray(tp))
|
|
|
|
{
|
1992-05-11 11:30:04 +00:00
|
|
|
/* First time we get here
|
|
|
|
*/
|
2017-01-08 10:23:56 +00:00
|
|
|
if (func_type && !too_big)
|
|
|
|
{
|
1992-05-11 11:30:04 +00:00
|
|
|
/* Some local space, only
|
|
|
|
needed if the value itself
|
|
|
|
is returned
|
|
|
|
*/
|
2017-01-08 10:23:56 +00:00
|
|
|
retsav = TmpSpace(func_res_size, 1);
|
1992-05-11 11:30:04 +00:00
|
|
|
}
|
|
|
|
StackAdjustment = NewPtr();
|
2017-01-08 10:23:56 +00:00
|
|
|
C_lor((arith)1);
|
1992-05-11 11:30:04 +00:00
|
|
|
STL(StackAdjustment, pointer_size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1991-02-19 16:22:41 +00:00
|
|
|
#ifdef USE_INSERT
|
|
|
|
C_insertpart(partno);
|
|
|
|
#else
|
|
|
|
cd_init = ++text_label;
|
|
|
|
cd_body = ++text_label;
|
1993-11-19 09:53:47 +00:00
|
|
|
c_bra(cd_init);
|
1991-02-19 16:22:41 +00:00
|
|
|
def_ilb(cd_body);
|
|
|
|
#endif
|
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
if ((WalkNode(procedure->prc_body, NO_EXIT_LABEL, REACH_FLAG) & REACH_FLAG))
|
|
|
|
{
|
|
|
|
if (func_res_size)
|
|
|
|
{
|
1991-02-19 16:22:41 +00:00
|
|
|
node_warning(procscope->sc_end,
|
2017-01-08 10:23:56 +00:00
|
|
|
W_ORDINARY,
|
|
|
|
"function procedure \"%s\" does not always return a value",
|
|
|
|
procedure->df_idf->id_text);
|
1991-02-19 16:22:41 +00:00
|
|
|
c_loc(M2_NORESULT);
|
|
|
|
C_trp();
|
|
|
|
C_asp(-func_res_size);
|
|
|
|
}
|
|
|
|
#ifndef USE_INSERT
|
1993-11-19 09:53:47 +00:00
|
|
|
c_bra(RETURN_LABEL);
|
1991-02-19 16:22:41 +00:00
|
|
|
#endif
|
|
|
|
}
|
1989-03-20 13:32:06 +00:00
|
|
|
|
1991-02-19 16:22:41 +00:00
|
|
|
#ifdef USE_INSERT
|
1989-03-20 13:32:06 +00:00
|
|
|
C_beginpart(partno);
|
1991-02-19 16:22:41 +00:00
|
|
|
#else
|
|
|
|
def_ilb(cd_init);
|
|
|
|
#endif
|
1986-06-20 14:36:49 +00:00
|
|
|
|
|
|
|
/* Generate calls to initialization routines of modules defined within
|
1986-04-21 17:27:06 +00:00
|
|
|
this procedure
|
|
|
|
*/
|
1988-03-08 10:18:58 +00:00
|
|
|
WalkDefList(procscope->sc_def, MkCalls);
|
1986-06-20 14:36:49 +00:00
|
|
|
|
|
|
|
/* Make sure that arguments of size < word_size are on a
|
|
|
|
fixed place.
|
1989-03-20 13:32:06 +00:00
|
|
|
Also make copies of parameters when neccessary.
|
1986-06-20 14:36:49 +00:00
|
|
|
*/
|
|
|
|
for (param = ParamList(procedure->df_type);
|
|
|
|
param;
|
2017-01-08 10:23:56 +00:00
|
|
|
param = param->par_next)
|
|
|
|
{
|
|
|
|
if (!IsVarParam(param))
|
|
|
|
{
|
1987-07-30 13:37:39 +00:00
|
|
|
tp = TypeOfParam(param);
|
1986-06-20 14:36:49 +00:00
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
if (!IsConformantArray(tp))
|
|
|
|
{
|
|
|
|
if (tp->tp_size < word_size && (int)word_size % (int)tp->tp_size == 0)
|
|
|
|
{
|
1986-08-26 14:33:24 +00:00
|
|
|
C_lol(param->par_def->var_off);
|
1989-03-20 13:32:06 +00:00
|
|
|
STL(param->par_def->var_off,
|
|
|
|
tp->tp_size);
|
1986-08-26 14:33:24 +00:00
|
|
|
}
|
1989-03-20 13:32:06 +00:00
|
|
|
continue;
|
1986-08-26 14:33:24 +00:00
|
|
|
}
|
1991-03-13 13:49:56 +00:00
|
|
|
/* Here, we have to make a copy of the
|
|
|
|
array. We must also remember how much
|
|
|
|
room is reserved for copies, because
|
|
|
|
we have to adjust the stack pointer before
|
|
|
|
a RET is done. This is even more complicated
|
|
|
|
when the procedure returns a value.
|
|
|
|
Then, the value must be saved,
|
|
|
|
the stack adjusted, the return value pushed
|
|
|
|
again, and then RET
|
|
|
|
*/
|
|
|
|
/* First compute new stackpointer */
|
|
|
|
C_lal(param->par_def->var_off);
|
|
|
|
CAL("new_stackptr", (int)pointer_size);
|
|
|
|
C_lfr(pointer_size);
|
|
|
|
C_ass(pointer_size);
|
2017-01-08 10:23:56 +00:00
|
|
|
/* adjusted stack pointer */
|
1991-03-13 13:49:56 +00:00
|
|
|
LOL(param->par_def->var_off, pointer_size);
|
2017-01-08 10:23:56 +00:00
|
|
|
/* push source address */
|
1991-03-13 13:49:56 +00:00
|
|
|
CAL("copy_array", (int)pointer_size);
|
2017-01-08 10:23:56 +00:00
|
|
|
/* copy */
|
1986-06-20 14:36:49 +00:00
|
|
|
}
|
1986-05-28 18:36:51 +00:00
|
|
|
}
|
1991-02-19 16:22:41 +00:00
|
|
|
#ifdef USE_INSERT
|
1989-03-20 13:32:06 +00:00
|
|
|
C_endpart(partno);
|
1991-02-19 16:22:41 +00:00
|
|
|
#else
|
1993-11-19 09:53:47 +00:00
|
|
|
c_bra(cd_body);
|
1991-02-19 16:22:41 +00:00
|
|
|
#endif
|
1987-05-27 10:16:03 +00:00
|
|
|
DO_DEBUG(options['X'], PrNode(procedure->prc_body, 0));
|
2017-01-08 10:23:56 +00:00
|
|
|
def_ilb(RETURN_LABEL); /* label at end */
|
|
|
|
if (too_big)
|
|
|
|
{
|
|
|
|
/* Fill the data area reserved for the function result
|
1986-09-25 19:39:06 +00:00
|
|
|
with the result
|
|
|
|
*/
|
1989-03-22 09:53:47 +00:00
|
|
|
#ifdef BIG_RESULT_ON_STACK
|
1989-03-10 10:40:07 +00:00
|
|
|
C_lal(procedure->df_type->prc_nbpar);
|
1989-03-22 09:53:47 +00:00
|
|
|
#else
|
|
|
|
c_lae_dlb(too_big);
|
1991-12-17 14:36:35 +00:00
|
|
|
#endif /* BIG_RESULT_ON_STACK */
|
1987-07-13 10:30:37 +00:00
|
|
|
C_sti(func_res_size);
|
2017-01-08 10:23:56 +00:00
|
|
|
if (StackAdjustment)
|
|
|
|
{
|
1986-09-25 19:39:06 +00:00
|
|
|
/* Remove copies of conformant arrays
|
|
|
|
*/
|
1988-03-22 17:54:01 +00:00
|
|
|
LOL(StackAdjustment, pointer_size);
|
2017-01-08 10:23:56 +00:00
|
|
|
C_str((arith)1);
|
1986-05-14 09:03:51 +00:00
|
|
|
}
|
1989-03-22 09:53:47 +00:00
|
|
|
#ifdef BIG_RESULT_ON_STACK
|
1989-03-10 10:40:07 +00:00
|
|
|
func_res_size = 0;
|
1989-03-22 09:53:47 +00:00
|
|
|
#else
|
|
|
|
c_lae_dlb(too_big);
|
|
|
|
func_res_size = pointer_size;
|
1991-12-17 14:36:35 +00:00
|
|
|
#endif /* BIG_RESULT_ON_STACK */
|
1986-05-14 09:03:51 +00:00
|
|
|
}
|
2017-01-08 10:23:56 +00:00
|
|
|
else if (StackAdjustment)
|
|
|
|
{
|
1987-06-23 17:12:25 +00:00
|
|
|
/* First save the function result in a safe place.
|
|
|
|
Then remove copies of conformant arrays,
|
|
|
|
and put function result back on the stack
|
|
|
|
*/
|
2017-01-08 10:23:56 +00:00
|
|
|
if (func_type)
|
|
|
|
{
|
1988-03-22 17:54:01 +00:00
|
|
|
STL(retsav, func_res_size);
|
1987-06-23 17:12:25 +00:00
|
|
|
}
|
1988-03-22 17:54:01 +00:00
|
|
|
LOL(StackAdjustment, pointer_size);
|
2017-01-08 10:23:56 +00:00
|
|
|
C_str((arith)1);
|
|
|
|
if (func_type)
|
|
|
|
{
|
1988-03-22 17:54:01 +00:00
|
|
|
LOL(retsav, func_res_size);
|
1986-08-26 14:33:24 +00:00
|
|
|
}
|
|
|
|
}
|
1987-06-23 17:12:25 +00:00
|
|
|
EndPriority();
|
|
|
|
C_ret(func_res_size);
|
1991-02-19 16:22:41 +00:00
|
|
|
#ifdef USE_INSERT
|
1989-03-20 13:32:06 +00:00
|
|
|
C_beginpart(partno2);
|
1991-03-13 13:49:56 +00:00
|
|
|
C_pro(procedure->prc_name, -procscope->sc_off);
|
1991-02-18 17:18:36 +00:00
|
|
|
#ifdef DBSYMTAB
|
2017-01-08 10:23:56 +00:00
|
|
|
if (options['g'])
|
|
|
|
{
|
1993-11-10 12:44:24 +00:00
|
|
|
stb_string(procedure, D_PROCEDURE);
|
|
|
|
WalkDefList(procscope->sc_def, stabdef);
|
|
|
|
stb_string(procedure, D_PEND);
|
2017-01-08 10:23:56 +00:00
|
|
|
C_ms_std((char*)0, N_LBRAC, gdb_flag ? 0 : proclevel);
|
1990-07-30 15:56:25 +00:00
|
|
|
}
|
1991-02-18 17:18:36 +00:00
|
|
|
#endif /* DBSYMTAB */
|
1989-03-22 09:53:47 +00:00
|
|
|
C_ms_par(procedure->df_type->prc_nbpar
|
|
|
|
#ifdef BIG_RESULT_ON_STACK
|
2017-01-08 10:23:56 +00:00
|
|
|
+ (too_big ? func_res_size : 0)
|
1989-03-22 09:53:47 +00:00
|
|
|
#endif
|
2017-01-08 10:23:56 +00:00
|
|
|
);
|
1991-02-19 16:22:41 +00:00
|
|
|
#endif
|
2017-01-08 10:23:56 +00:00
|
|
|
if (!options['n'])
|
|
|
|
WalkDefList(procscope->sc_def, RegisterMessage);
|
1991-02-19 16:22:41 +00:00
|
|
|
#ifdef USE_INSERT
|
1989-03-20 13:32:06 +00:00
|
|
|
C_endpart(partno2);
|
1991-02-19 16:22:41 +00:00
|
|
|
#endif
|
1991-02-18 17:18:36 +00:00
|
|
|
#ifdef DBSYMTAB
|
2017-01-08 10:23:56 +00:00
|
|
|
if (options['g'])
|
|
|
|
{
|
|
|
|
C_ms_std((char*)0, N_RBRAC, gdb_flag ? 0 : proclevel);
|
1990-07-30 15:56:25 +00:00
|
|
|
}
|
1991-02-18 17:18:36 +00:00
|
|
|
#endif /* DBSYMTAB */
|
1988-03-08 10:18:58 +00:00
|
|
|
C_end(-procscope->sc_off);
|
2017-01-08 10:23:56 +00:00
|
|
|
if (!fit(procscope->sc_off, (int)word_size))
|
|
|
|
{
|
1989-03-20 13:32:06 +00:00
|
|
|
node_error(procedure->prc_body,
|
2017-01-08 10:23:56 +00:00
|
|
|
"maximum local byte count exceeded");
|
1987-11-24 14:21:35 +00:00
|
|
|
}
|
1986-05-23 09:46:31 +00:00
|
|
|
TmpClose();
|
1986-06-20 14:36:49 +00:00
|
|
|
CurrVis = savevis;
|
1986-05-16 17:15:36 +00:00
|
|
|
proclevel--;
|
1988-03-08 10:18:58 +00:00
|
|
|
WalkDefList(procscope->sc_def, UseWarnings);
|
1986-04-21 17:27:06 +00:00
|
|
|
}
|
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
static WalkDef(df) register t_def* df;
|
1986-04-21 17:27:06 +00:00
|
|
|
{
|
|
|
|
/* Walk through a list of definitions
|
|
|
|
*/
|
1986-04-28 18:06:58 +00:00
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
switch (df->df_kind)
|
|
|
|
{
|
|
|
|
case D_MODULE:
|
|
|
|
WalkModule(df);
|
|
|
|
break;
|
|
|
|
case D_PROCEDURE:
|
|
|
|
WalkProcedure(df);
|
|
|
|
break;
|
|
|
|
case D_VARIABLE:
|
|
|
|
if (!proclevel && !(df->df_flags & D_ADDRGIVEN))
|
|
|
|
{
|
|
|
|
C_df_dnam(df->var_name);
|
|
|
|
C_bss_cst(
|
|
|
|
WA(df->df_type->tp_size),
|
|
|
|
(arith)0, 0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* nothing */
|
|
|
|
;
|
1986-04-21 17:27:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
static MkCalls(df) register t_def* df;
|
1986-04-21 17:27:06 +00:00
|
|
|
{
|
|
|
|
/* Generate calls to initialization routines of modules
|
|
|
|
*/
|
1986-04-28 18:06:58 +00:00
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
if (df->df_kind == D_MODULE)
|
|
|
|
{
|
|
|
|
C_lxl((arith)0);
|
1988-06-13 10:29:36 +00:00
|
|
|
CAL(df->mod_vis->sc_scope->sc_name, (int)pointer_size);
|
1986-04-21 17:27:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
WalkLink(nd, exit_label, end_reached) register t_node* nd;
|
|
|
|
label exit_label;
|
1986-04-21 17:27:06 +00:00
|
|
|
{
|
1986-06-20 14:36:49 +00:00
|
|
|
/* Walk node "nd", which is a link.
|
1989-03-20 13:32:06 +00:00
|
|
|
"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).
|
1986-04-22 22:36:16 +00:00
|
|
|
*/
|
1986-04-28 18:06:58 +00:00
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
while (nd && nd->nd_class == Link)
|
|
|
|
{ /* statement list */
|
1991-03-12 16:52:00 +00:00
|
|
|
end_reached = WalkNode(nd->nd_LEFT, exit_label, end_reached);
|
|
|
|
nd = nd->nd_RIGHT;
|
1986-04-22 22:36:16 +00:00
|
|
|
}
|
|
|
|
|
1989-03-20 13:32:06 +00:00
|
|
|
return WalkNode(nd, exit_label, end_reached);
|
1986-06-20 14:36:49 +00:00
|
|
|
}
|
|
|
|
|
1987-08-10 21:43:47 +00:00
|
|
|
STATIC
|
2017-01-08 10:23:56 +00:00
|
|
|
ForLoopVarExpr(nd) register t_node* nd;
|
1987-08-10 21:43:47 +00:00
|
|
|
{
|
2017-01-08 10:23:56 +00:00
|
|
|
register t_type* tp = nd->nd_type;
|
1987-08-10 21:43:47 +00:00
|
|
|
|
|
|
|
CodePExpr(nd);
|
|
|
|
CodeCoercion(tp, BaseType(tp));
|
|
|
|
}
|
|
|
|
|
1989-03-20 13:32:06 +00:00
|
|
|
int
|
2017-01-08 10:23:56 +00:00
|
|
|
WalkStat(nd, exit_label, end_reached) register t_node* nd;
|
|
|
|
label exit_label;
|
1986-04-22 22:36:16 +00:00
|
|
|
{
|
|
|
|
/* Walk through a statement, generating code for it.
|
|
|
|
*/
|
2017-01-08 10:23:56 +00:00
|
|
|
register t_node* left = nd->nd_LEFT;
|
|
|
|
register t_node* right = nd->nd_RIGHT;
|
1986-05-23 09:46:31 +00:00
|
|
|
|
1986-04-22 22:36:16 +00:00
|
|
|
assert(nd->nd_class == Stat);
|
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
if (nd->nd_symb == ';')
|
|
|
|
return 1;
|
1988-11-23 13:10:57 +00:00
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
if (!end_reached & REACH_FLAG)
|
|
|
|
{
|
1989-03-20 13:32:06 +00:00
|
|
|
node_warning(nd, W_ORDINARY, "statement not reached");
|
|
|
|
}
|
2017-01-08 10:23:56 +00:00
|
|
|
if (nd->nd_symb != WHILE || nd->nd_lineno != left->nd_lineno)
|
|
|
|
{
|
1990-08-22 15:33:43 +00:00
|
|
|
/* Avoid double linenumber generation in while statements */
|
|
|
|
DoLineno(nd);
|
|
|
|
}
|
1988-03-23 17:44:25 +00:00
|
|
|
options['R'] = (nd->nd_flags & ROPTION);
|
|
|
|
options['A'] = (nd->nd_flags & AOPTION);
|
2017-01-08 10:23:56 +00:00
|
|
|
switch (nd->nd_symb)
|
|
|
|
{
|
|
|
|
case '(':
|
|
|
|
{
|
|
|
|
t_node* nd1 = nd;
|
|
|
|
if (ChkCall(&nd1))
|
|
|
|
{
|
|
|
|
assert(nd == nd1);
|
|
|
|
if (nd->nd_type != 0)
|
|
|
|
{
|
2017-01-08 10:25:57 +00:00
|
|
|
node_error(nd, "only proper procedures can be called from top-level "
|
|
|
|
"statement; this is a function procedure");
|
2017-01-08 10:23:56 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
CodeCall(nd);
|
1987-09-23 16:39:43 +00:00
|
|
|
}
|
1991-03-12 16:52:00 +00:00
|
|
|
}
|
1987-09-23 16:39:43 +00:00
|
|
|
break;
|
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
case BECOMES:
|
|
|
|
DoAssign(nd);
|
|
|
|
break;
|
1986-04-22 22:36:16 +00:00
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
case IF:
|
|
|
|
{
|
|
|
|
label l1 = ++text_label, l3 = ++text_label;
|
1989-03-20 13:32:06 +00:00
|
|
|
int end_r;
|
1986-04-22 22:36:16 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
ExpectBool(&(nd->nd_LEFT), l3, l1);
|
1986-04-22 22:36:16 +00:00
|
|
|
assert(right->nd_symb == THEN);
|
1991-03-12 16:52:00 +00:00
|
|
|
end_r = LblWalkNode(l3, right->nd_LEFT, exit_label, end_reached);
|
1986-04-22 22:36:16 +00:00
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
if (right->nd_RIGHT)
|
|
|
|
{ /* ELSE part */
|
1986-10-06 20:36:30 +00:00
|
|
|
label l2 = ++text_label;
|
|
|
|
|
1993-11-19 09:53:47 +00:00
|
|
|
c_bra(l2);
|
1991-03-12 16:52:00 +00:00
|
|
|
end_reached = end_r | LblWalkNode(l1, right->nd_RIGHT, exit_label, end_reached);
|
1987-08-10 21:43:47 +00:00
|
|
|
l1 = l2;
|
1986-04-22 22:36:16 +00:00
|
|
|
}
|
2017-01-08 10:23:56 +00:00
|
|
|
else
|
|
|
|
end_reached |= end_r;
|
1988-01-28 16:15:16 +00:00
|
|
|
def_ilb(l1);
|
1986-04-22 22:36:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
case CASE:
|
|
|
|
end_reached = CaseCode(nd, exit_label, end_reached);
|
|
|
|
break;
|
1986-04-22 22:36:16 +00:00
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
case WHILE:
|
|
|
|
{
|
|
|
|
label loop = ++text_label,
|
|
|
|
exit = ++text_label,
|
|
|
|
dummy = ++text_label;
|
1986-04-22 22:36:16 +00:00
|
|
|
|
1993-11-19 09:53:47 +00:00
|
|
|
c_bra(dummy);
|
1989-03-20 13:32:06 +00:00
|
|
|
end_reached |= LblWalkNode(loop, right, exit_label, end_reached);
|
|
|
|
def_ilb(dummy);
|
1991-03-12 16:52:00 +00:00
|
|
|
ExpectBool(&(nd->nd_LEFT), loop, exit);
|
1988-01-28 16:15:16 +00:00
|
|
|
def_ilb(exit);
|
1986-04-22 22:36:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
case REPEAT:
|
|
|
|
{
|
|
|
|
label loop = ++text_label, exit = ++text_label;
|
1986-04-22 22:36:16 +00:00
|
|
|
|
1989-03-20 13:32:06 +00:00
|
|
|
end_reached = LblWalkNode(loop, left, exit_label, end_reached);
|
1991-03-12 16:52:00 +00:00
|
|
|
ExpectBool(&(nd->nd_RIGHT), exit, loop);
|
1988-01-28 16:15:16 +00:00
|
|
|
def_ilb(exit);
|
1986-04-22 22:36:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
case LOOP:
|
|
|
|
{
|
|
|
|
label loop = ++text_label, exit = ++text_label;
|
1986-04-22 22:36:16 +00:00
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
if (LblWalkNode(loop, right, exit, end_reached) & EXIT_FLAG)
|
|
|
|
{
|
1989-03-20 13:32:06 +00:00
|
|
|
end_reached &= REACH_FLAG;
|
|
|
|
}
|
2017-01-08 10:23:56 +00:00
|
|
|
else
|
|
|
|
end_reached = 0;
|
1993-11-19 09:53:47 +00:00
|
|
|
c_bra(loop);
|
1988-01-28 16:15:16 +00:00
|
|
|
def_ilb(exit);
|
1986-04-22 22:36:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
case FOR:
|
1986-05-28 18:36:51 +00:00
|
|
|
{
|
1987-09-14 11:24:12 +00:00
|
|
|
arith tmp = NewInt();
|
1988-11-04 13:12:14 +00:00
|
|
|
arith tmp2 = NewInt();
|
1986-11-26 16:40:45 +00:00
|
|
|
int good_forvar;
|
1986-06-20 14:36:49 +00:00
|
|
|
label l1 = ++text_label;
|
|
|
|
label l2 = ++text_label;
|
1987-07-30 13:37:39 +00:00
|
|
|
int uns = 0;
|
1987-08-10 13:01:54 +00:00
|
|
|
arith stepsize;
|
2017-01-08 10:23:56 +00:00
|
|
|
t_type* bstp;
|
|
|
|
t_node* loopid;
|
1986-05-28 18:36:51 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
good_forvar = DoForInit(left);
|
|
|
|
loopid = left->nd_LEFT;
|
2017-01-08 10:23:56 +00:00
|
|
|
if ((stepsize = right->nd_LEFT->nd_INT) == 0)
|
|
|
|
{
|
1991-03-12 16:52:00 +00:00
|
|
|
node_warning(right->nd_LEFT,
|
2017-01-08 10:23:56 +00:00
|
|
|
W_ORDINARY,
|
|
|
|
"zero stepsize in FOR loop");
|
1987-08-10 13:01:54 +00:00
|
|
|
}
|
2017-01-08 10:23:56 +00:00
|
|
|
if (good_forvar)
|
|
|
|
{
|
1991-03-12 16:52:00 +00:00
|
|
|
bstp = BaseType(loopid->nd_type);
|
1987-08-10 21:43:47 +00:00
|
|
|
uns = bstp->tp_fund != T_INTEGER;
|
1991-03-12 16:52:00 +00:00
|
|
|
CodePExpr(left->nd_RIGHT->nd_RIGHT);
|
1987-08-10 13:01:54 +00:00
|
|
|
C_stl(tmp);
|
1991-03-12 16:52:00 +00:00
|
|
|
CodePExpr(left->nd_RIGHT->nd_LEFT);
|
1988-11-04 10:24:34 +00:00
|
|
|
C_dup(int_size);
|
1988-11-04 13:12:14 +00:00
|
|
|
C_stl(tmp2);
|
1987-08-10 13:01:54 +00:00
|
|
|
C_lol(tmp);
|
2017-01-08 10:23:56 +00:00
|
|
|
if (uns)
|
|
|
|
C_cmu(int_size);
|
|
|
|
else
|
|
|
|
C_cmi(int_size);
|
|
|
|
if (stepsize >= 0)
|
|
|
|
C_zgt(l2);
|
|
|
|
else
|
|
|
|
C_zlt(l2);
|
1988-11-04 13:12:14 +00:00
|
|
|
C_lol(tmp2);
|
1991-03-12 16:52:00 +00:00
|
|
|
RangeCheck(loopid->nd_type,
|
2017-01-08 10:23:56 +00:00
|
|
|
left->nd_RIGHT->nd_LEFT->nd_type);
|
1991-03-12 16:52:00 +00:00
|
|
|
CodeDStore(loopid);
|
2017-01-08 10:23:56 +00:00
|
|
|
if (stepsize >= 0)
|
|
|
|
{
|
1989-03-14 15:36:33 +00:00
|
|
|
C_lol(tmp);
|
1991-03-12 16:52:00 +00:00
|
|
|
ForLoopVarExpr(loopid);
|
1987-07-30 13:37:39 +00:00
|
|
|
}
|
2017-01-08 10:23:56 +00:00
|
|
|
else
|
|
|
|
{
|
1987-08-19 18:07:41 +00:00
|
|
|
stepsize = -stepsize;
|
1991-03-12 16:52:00 +00:00
|
|
|
ForLoopVarExpr(loopid);
|
1989-03-14 15:36:33 +00:00
|
|
|
C_lol(tmp);
|
1987-08-10 13:01:54 +00:00
|
|
|
}
|
|
|
|
C_sbu(int_size);
|
2017-01-08 10:23:56 +00:00
|
|
|
if (stepsize)
|
|
|
|
{
|
1987-08-10 13:01:54 +00:00
|
|
|
C_loc(stepsize);
|
|
|
|
C_dvu(int_size);
|
|
|
|
}
|
1987-08-11 08:58:20 +00:00
|
|
|
C_stl(tmp);
|
1991-03-12 16:52:00 +00:00
|
|
|
loopid->nd_def->df_flags |= D_FORLOOP;
|
1988-01-28 16:15:16 +00:00
|
|
|
def_ilb(l1);
|
2017-01-08 10:23:56 +00:00
|
|
|
if (!options['R'])
|
|
|
|
{
|
1991-03-12 16:52:00 +00:00
|
|
|
ForLoopVarExpr(loopid);
|
1987-09-14 12:41:08 +00:00
|
|
|
C_stl(tmp2);
|
1991-03-13 13:49:56 +00:00
|
|
|
}
|
|
|
|
end_reached |= WalkNode(right->nd_RIGHT, exit_label, end_reached);
|
2017-01-08 10:23:56 +00:00
|
|
|
if (!options['R'])
|
|
|
|
{
|
1991-03-13 13:49:56 +00:00
|
|
|
label x = ++text_label;
|
1987-09-14 12:41:08 +00:00
|
|
|
C_lol(tmp2);
|
1991-03-12 16:52:00 +00:00
|
|
|
ForLoopVarExpr(loopid);
|
1987-11-09 10:17:20 +00:00
|
|
|
C_beq(x);
|
|
|
|
c_loc(M2_FORCH);
|
|
|
|
C_trp();
|
1988-01-28 16:15:16 +00:00
|
|
|
def_ilb(x);
|
1987-09-14 12:41:08 +00:00
|
|
|
}
|
1991-03-12 16:52:00 +00:00
|
|
|
loopid->nd_def->df_flags &= ~D_FORLOOP;
|
1988-11-04 13:12:14 +00:00
|
|
|
FreeInt(tmp2);
|
2017-01-08 10:23:56 +00:00
|
|
|
if (stepsize)
|
|
|
|
{
|
1987-09-14 12:41:08 +00:00
|
|
|
C_lol(tmp);
|
|
|
|
C_zeq(l2);
|
|
|
|
C_lol(tmp);
|
1987-09-23 16:39:43 +00:00
|
|
|
c_loc(1);
|
1987-09-14 12:41:08 +00:00
|
|
|
C_sbu(int_size);
|
|
|
|
C_stl(tmp);
|
1991-03-12 16:52:00 +00:00
|
|
|
C_loc(right->nd_LEFT->nd_INT);
|
|
|
|
ForLoopVarExpr(loopid);
|
1987-09-14 12:41:08 +00:00
|
|
|
C_adu(int_size);
|
1991-03-12 16:52:00 +00:00
|
|
|
RangeCheck(loopid->nd_type, bstp);
|
|
|
|
CodeDStore(loopid);
|
1987-09-14 12:41:08 +00:00
|
|
|
}
|
1986-11-26 16:40:45 +00:00
|
|
|
}
|
2017-01-08 10:23:56 +00:00
|
|
|
else
|
|
|
|
{
|
1991-03-12 16:52:00 +00:00
|
|
|
end_reached |= WalkNode(right->nd_RIGHT, exit_label, end_reached);
|
|
|
|
loopid->nd_def->df_flags &= ~D_FORLOOP;
|
1988-10-13 15:43:23 +00:00
|
|
|
}
|
1993-11-19 09:53:47 +00:00
|
|
|
c_bra(l1);
|
1988-01-28 16:15:16 +00:00
|
|
|
def_ilb(l2);
|
1987-08-10 13:01:54 +00:00
|
|
|
FreeInt(tmp);
|
1986-05-28 18:36:51 +00:00
|
|
|
}
|
1986-04-22 22:36:16 +00:00
|
|
|
break;
|
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
case WITH:
|
1986-04-28 18:06:58 +00:00
|
|
|
{
|
1987-09-24 13:07:31 +00:00
|
|
|
t_scopelist link;
|
1986-05-16 17:15:36 +00:00
|
|
|
struct withdesig wds;
|
1987-09-23 16:39:43 +00:00
|
|
|
t_desig ds;
|
1986-04-28 18:06:58 +00:00
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
if (!WalkDesignator(&(nd->nd_LEFT), &ds, D_USED))
|
|
|
|
break;
|
1991-03-12 16:52:00 +00:00
|
|
|
left = nd->nd_LEFT;
|
2017-01-08 10:23:56 +00:00
|
|
|
if (left->nd_type->tp_fund != T_RECORD)
|
|
|
|
{
|
1986-04-28 18:06:58 +00:00
|
|
|
node_error(left, "record variable expected");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1986-05-16 17:15:36 +00:00
|
|
|
wds.w_next = WithDesigs;
|
1989-03-20 13:32:06 +00:00
|
|
|
wds.w_flags = D_USED;
|
1986-05-16 17:15:36 +00:00
|
|
|
WithDesigs = &wds;
|
|
|
|
wds.w_scope = left->nd_type->rec_scope;
|
1986-07-08 14:59:02 +00:00
|
|
|
CodeAddress(&ds);
|
|
|
|
ds.dsg_kind = DSG_FIXED;
|
1986-09-25 19:39:06 +00:00
|
|
|
/* Create a designator structure for the temporary.
|
1986-07-08 14:59:02 +00:00
|
|
|
*/
|
1986-10-06 20:36:30 +00:00
|
|
|
ds.dsg_offset = NewPtr();
|
1986-07-08 14:59:02 +00:00
|
|
|
ds.dsg_name = 0;
|
1987-06-23 17:12:25 +00:00
|
|
|
CodeStore(&ds, address_type);
|
1986-07-08 14:59:02 +00:00
|
|
|
ds.dsg_kind = DSG_PFIXED;
|
|
|
|
/* the record is indirectly available */
|
1986-06-17 12:04:05 +00:00
|
|
|
wds.w_desig = ds;
|
1986-05-16 17:15:36 +00:00
|
|
|
link.sc_scope = wds.w_scope;
|
1987-07-16 19:51:40 +00:00
|
|
|
link.sc_next = CurrVis;
|
1986-04-28 18:06:58 +00:00
|
|
|
CurrVis = &link;
|
1989-03-20 13:32:06 +00:00
|
|
|
end_reached = WalkNode(right, exit_label, end_reached);
|
1987-07-16 19:51:40 +00:00
|
|
|
CurrVis = link.sc_next;
|
1986-05-16 17:15:36 +00:00
|
|
|
WithDesigs = wds.w_next;
|
1986-10-06 20:36:30 +00:00
|
|
|
FreePtr(ds.dsg_offset);
|
2017-01-08 10:23:56 +00:00
|
|
|
ChkDesig(&(nd->nd_LEFT), wds.w_flags & (D_USED | D_DEFINED));
|
1986-04-28 18:06:58 +00:00
|
|
|
break;
|
|
|
|
}
|
1986-04-22 22:36:16 +00:00
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
case EXIT:
|
|
|
|
assert(exit_label != 0);
|
1986-04-22 22:36:16 +00:00
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
if (end_reached & REACH_FLAG)
|
|
|
|
end_reached = EXIT_FLAG;
|
|
|
|
c_bra(exit_label);
|
|
|
|
break;
|
1986-04-22 22:36:16 +00:00
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
case RETURN:
|
|
|
|
end_reached &= ~REACH_FLAG;
|
|
|
|
if (right)
|
|
|
|
{
|
|
|
|
if (!ChkExpression(&(nd->nd_RIGHT)))
|
|
|
|
break;
|
|
|
|
/* The type of the return-expression must be
|
1986-06-20 14:36:49 +00:00
|
|
|
assignment compatible with the result type of the
|
|
|
|
function procedure (See Rep. 9.11).
|
1986-04-28 18:06:58 +00:00
|
|
|
*/
|
2017-01-08 10:23:56 +00:00
|
|
|
if (!ChkAssCompat(&(nd->nd_RIGHT), func_type, "RETURN"))
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
right = nd->nd_RIGHT;
|
|
|
|
if (right->nd_type->tp_fund == T_STRING)
|
|
|
|
{
|
|
|
|
CodePString(right, func_type);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
CodePExpr(right);
|
1986-11-26 16:40:45 +00:00
|
|
|
}
|
2017-01-08 10:23:56 +00:00
|
|
|
c_bra(RETURN_LABEL);
|
|
|
|
break;
|
1986-04-22 22:36:16 +00:00
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
default:
|
|
|
|
crash("(WalkStat)");
|
1986-04-22 22:36:16 +00:00
|
|
|
}
|
1989-03-20 13:32:06 +00:00
|
|
|
return end_reached;
|
1986-04-22 22:36:16 +00:00
|
|
|
}
|
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
extern int NodeCrash();
|
1986-06-20 14:36:49 +00:00
|
|
|
|
|
|
|
int (*WalkTable[])() = {
|
|
|
|
NodeCrash,
|
|
|
|
NodeCrash,
|
|
|
|
NodeCrash,
|
|
|
|
NodeCrash,
|
|
|
|
NodeCrash,
|
1987-09-23 16:39:43 +00:00
|
|
|
NodeCrash,
|
1986-06-20 14:36:49 +00:00
|
|
|
NodeCrash,
|
|
|
|
NodeCrash,
|
|
|
|
NodeCrash,
|
|
|
|
NodeCrash,
|
|
|
|
WalkStat,
|
1991-03-12 16:52:00 +00:00
|
|
|
NodeCrash,
|
1986-06-20 14:36:49 +00:00
|
|
|
WalkLink,
|
|
|
|
};
|
|
|
|
|
1991-03-14 11:10:40 +00:00
|
|
|
extern t_desig null_desig;
|
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
ExpectBool(pnd, true_label, false_label) register t_node** pnd;
|
|
|
|
label true_label, false_label;
|
1986-04-22 22:36:16 +00:00
|
|
|
{
|
1991-03-12 16:52:00 +00:00
|
|
|
/* "pnd" must indicate a boolean expression. Check this and
|
1986-04-22 22:36:16 +00:00
|
|
|
generate code to evaluate the expression.
|
|
|
|
*/
|
1991-03-14 11:10:40 +00:00
|
|
|
t_desig ds;
|
1986-04-22 22:36:16 +00:00
|
|
|
|
1991-03-14 11:10:40 +00:00
|
|
|
ds = null_desig;
|
2017-01-08 10:23:56 +00:00
|
|
|
if (ChkExpression(pnd))
|
|
|
|
{
|
|
|
|
if ((*pnd)->nd_type != bool_type && (*pnd)->nd_type != error_type)
|
|
|
|
{
|
1991-03-12 16:52:00 +00:00
|
|
|
node_error(*pnd, "boolean expression expected");
|
1987-07-30 13:37:39 +00:00
|
|
|
}
|
1986-04-22 22:36:16 +00:00
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
CodeExpr(*pnd, &ds, true_label, false_label);
|
1986-04-22 22:36:16 +00:00
|
|
|
}
|
1986-04-23 22:12:22 +00:00
|
|
|
}
|
|
|
|
|
1986-08-26 14:33:24 +00:00
|
|
|
int
|
2017-01-08 10:23:56 +00:00
|
|
|
WalkDesignator(pnd, ds, flags)
|
|
|
|
t_node** pnd;
|
|
|
|
t_desig* ds;
|
1986-04-25 10:14:08 +00:00
|
|
|
{
|
|
|
|
/* Check designator and generate code for it
|
|
|
|
*/
|
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
if (!ChkVariable(pnd, flags))
|
|
|
|
return 0;
|
1986-05-01 19:06:53 +00:00
|
|
|
|
1991-03-14 11:10:40 +00:00
|
|
|
*ds = null_desig;
|
1991-03-12 16:52:00 +00:00
|
|
|
CodeDesig(*pnd, ds);
|
1986-08-26 14:33:24 +00:00
|
|
|
return 1;
|
1986-05-30 18:48:00 +00:00
|
|
|
}
|
|
|
|
|
1987-08-10 13:01:54 +00:00
|
|
|
DoForInit(nd)
|
2017-01-08 10:23:56 +00:00
|
|
|
t_node* nd;
|
1986-05-30 18:48:00 +00:00
|
|
|
{
|
2017-01-08 10:23:56 +00:00
|
|
|
register t_node* right = nd->nd_RIGHT;
|
|
|
|
register t_def* df;
|
|
|
|
t_type* base_tp;
|
1987-09-23 16:39:43 +00:00
|
|
|
t_type *tpl, *tpr;
|
1991-04-25 16:47:47 +00:00
|
|
|
int r;
|
1986-05-28 18:36:51 +00:00
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
r = ChkVariable(&(nd->nd_LEFT), D_USED | D_DEFINED);
|
1991-04-25 16:47:47 +00:00
|
|
|
r &= ChkExpression(&(right->nd_LEFT));
|
|
|
|
r &= ChkExpression(&(right->nd_RIGHT));
|
2017-01-08 10:23:56 +00:00
|
|
|
if (!r)
|
|
|
|
return 0;
|
1986-05-30 18:48:00 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
df = nd->nd_LEFT->nd_def;
|
2017-01-08 10:23:56 +00:00
|
|
|
if (df->df_kind == D_FIELD)
|
|
|
|
{
|
1986-10-06 20:36:30 +00:00
|
|
|
node_error(nd,
|
2017-01-08 10:23:56 +00:00
|
|
|
"FOR-loop variable may not be a field of a record");
|
1986-11-26 16:40:45 +00:00
|
|
|
return 1;
|
1986-06-20 14:36:49 +00:00
|
|
|
}
|
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
if (!df->var_name && df->var_off >= 0)
|
|
|
|
{
|
1986-06-20 14:36:49 +00:00
|
|
|
node_error(nd, "FOR-loop variable may not be a parameter");
|
1986-11-26 16:40:45 +00:00
|
|
|
return 1;
|
1986-06-20 14:36:49 +00:00
|
|
|
}
|
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
if (df->df_scope != CurrentScope)
|
|
|
|
{
|
|
|
|
register t_scopelist* sc = CurrVis;
|
1986-06-20 14:36:49 +00:00
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if (!sc)
|
|
|
|
{
|
1986-10-06 20:36:30 +00:00
|
|
|
node_error(nd,
|
2017-01-08 10:23:56 +00:00
|
|
|
"FOR-loop variable may not be imported");
|
1986-11-26 16:40:45 +00:00
|
|
|
return 1;
|
1986-10-06 20:36:30 +00:00
|
|
|
}
|
2017-01-08 10:23:56 +00:00
|
|
|
if (sc->sc_scope == df->df_scope)
|
|
|
|
break;
|
1986-06-20 14:36:49 +00:00
|
|
|
sc = nextvisible(sc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
if (df->df_type->tp_size > word_size || !(df->df_type->tp_fund & T_DISCRETE))
|
|
|
|
{
|
1986-05-30 18:48:00 +00:00
|
|
|
node_error(nd, "illegal type of FOR loop variable");
|
1986-11-26 16:40:45 +00:00
|
|
|
return 1;
|
1986-05-30 18:48:00 +00:00
|
|
|
}
|
|
|
|
|
1988-11-15 14:45:59 +00:00
|
|
|
base_tp = BaseType(df->df_type);
|
1991-03-12 16:52:00 +00:00
|
|
|
tpl = right->nd_LEFT->nd_type;
|
|
|
|
tpr = right->nd_RIGHT->nd_type;
|
1987-10-19 11:28:37 +00:00
|
|
|
#ifndef STRICT_3RD_ED
|
2017-01-08 10:23:56 +00:00
|
|
|
if (!options['3'])
|
|
|
|
{
|
|
|
|
if (!ChkAssCompat(&(right->nd_LEFT), base_tp, "FOR statement") || !ChkAssCompat(&(right->nd_RIGHT), base_tp, "FOR statement"))
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (!TstCompat(df->df_type, tpl) || !TstCompat(df->df_type, tpr))
|
|
|
|
{
|
|
|
|
node_warning(nd, W_OLDFASHIONED, "compatibility required in FOR statement");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
1987-10-19 11:28:37 +00:00
|
|
|
#endif
|
2017-01-08 10:23:56 +00:00
|
|
|
if (!ChkCompat(&(right->nd_LEFT), base_tp, "FOR statement") || !ChkCompat(&(right->nd_RIGHT), base_tp, "FOR statement"))
|
|
|
|
{
|
1987-10-19 11:28:37 +00:00
|
|
|
return 1;
|
1986-05-30 18:48:00 +00:00
|
|
|
}
|
|
|
|
|
1986-06-06 02:22:09 +00:00
|
|
|
return 1;
|
1986-05-28 18:36:51 +00:00
|
|
|
}
|
|
|
|
|
2016-11-10 21:04:18 +00:00
|
|
|
void
|
2017-01-08 10:23:56 +00:00
|
|
|
DoAssign(nd) register t_node* nd;
|
1986-05-28 18:36:51 +00:00
|
|
|
{
|
1986-09-25 19:39:06 +00:00
|
|
|
/* May we do it in this order (expression first) ???
|
|
|
|
The reference manual sais nothing about it, but the book does:
|
|
|
|
it sais that the left hand side is evaluated first.
|
1986-10-06 20:36:30 +00:00
|
|
|
DAMN THE BOOK!
|
1986-09-25 19:39:06 +00:00
|
|
|
*/
|
1991-03-14 11:10:40 +00:00
|
|
|
t_desig dsr;
|
2017-01-08 10:23:56 +00:00
|
|
|
register t_type* tp;
|
1986-05-28 18:36:51 +00:00
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
if (!(ChkExpression(&(nd->nd_RIGHT)) & ChkVariable(&(nd->nd_LEFT), D_DEFINED)))
|
|
|
|
return;
|
1991-03-12 16:52:00 +00:00
|
|
|
tp = nd->nd_LEFT->nd_type;
|
1986-10-06 20:36:30 +00:00
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
if (!ChkAssCompat(&(nd->nd_RIGHT), tp, "assignment"))
|
|
|
|
{
|
1986-05-28 18:36:51 +00:00
|
|
|
return;
|
|
|
|
}
|
1991-03-14 11:10:40 +00:00
|
|
|
dsr = null_desig;
|
1986-05-28 18:36:51 +00:00
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
#define StackNeededFor(ds) ((ds).dsg_kind == DSG_PLOADED \
|
|
|
|
|| (ds).dsg_kind == DSG_INDEXED)
|
1991-03-14 11:10:40 +00:00
|
|
|
CodeExpr(nd->nd_RIGHT, &dsr, NO_LABEL, NO_LABEL);
|
1991-03-12 16:52:00 +00:00
|
|
|
tp = nd->nd_RIGHT->nd_type;
|
2017-01-08 10:23:56 +00:00
|
|
|
if (complex(tp))
|
|
|
|
{
|
|
|
|
if (StackNeededFor(dsr))
|
|
|
|
CodeAddress(&dsr);
|
1986-11-28 11:59:08 +00:00
|
|
|
}
|
2017-01-08 10:23:56 +00:00
|
|
|
else
|
|
|
|
{
|
1991-03-14 11:10:40 +00:00
|
|
|
CodeValue(&dsr, tp);
|
1986-05-28 18:36:51 +00:00
|
|
|
}
|
1991-03-14 11:10:40 +00:00
|
|
|
CodeMove(&dsr, nd->nd_LEFT, tp);
|
1986-06-17 12:04:05 +00:00
|
|
|
}
|
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
static RegisterMessage(df) register t_def* df;
|
1986-06-17 12:04:05 +00:00
|
|
|
{
|
2017-01-08 10:23:56 +00:00
|
|
|
register t_type* tp;
|
1986-05-28 18:36:51 +00:00
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
if (df->df_kind == D_VARIABLE)
|
|
|
|
{
|
|
|
|
if (!(df->df_flags & D_NOREG))
|
|
|
|
{
|
1986-06-17 12:04:05 +00:00
|
|
|
/* Examine type and size
|
|
|
|
*/
|
1986-06-26 09:39:36 +00:00
|
|
|
tp = BaseType(df->df_type);
|
2017-01-08 10:23:56 +00:00
|
|
|
if ((df->df_flags & D_VARPAR) || (tp->tp_fund & (T_POINTER | T_HIDDEN | T_EQUAL)))
|
|
|
|
{
|
1988-10-13 15:43:23 +00:00
|
|
|
C_ms_reg(df->var_off,
|
2017-01-08 10:23:56 +00:00
|
|
|
pointer_size,
|
|
|
|
reg_pointer,
|
|
|
|
0);
|
1986-06-26 09:39:36 +00:00
|
|
|
}
|
2017-01-08 10:23:56 +00:00
|
|
|
else if (tp->tp_fund & T_NUMERIC)
|
|
|
|
{
|
1988-10-13 15:43:23 +00:00
|
|
|
C_ms_reg(df->var_off,
|
2017-01-08 10:23:56 +00:00
|
|
|
tp->tp_size,
|
|
|
|
tp->tp_fund == T_REAL ? reg_float : reg_any,
|
|
|
|
0);
|
1986-06-17 12:04:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1986-04-25 10:14:08 +00:00
|
|
|
}
|
1987-10-19 11:28:37 +00:00
|
|
|
|
2016-11-10 21:04:18 +00:00
|
|
|
static void
|
2017-01-08 10:23:56 +00:00
|
|
|
df_warning(nd, df, warning)
|
|
|
|
t_node* nd;
|
|
|
|
t_def* df;
|
|
|
|
char* warning;
|
1989-04-11 14:34:21 +00:00
|
|
|
{
|
2017-01-08 10:23:56 +00:00
|
|
|
if (!(df->df_kind & (D_VARIABLE | D_PROCEDURE | D_TYPE | D_CONST | D_PROCHEAD)))
|
|
|
|
{
|
1989-04-11 14:34:21 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-01-08 10:23:56 +00:00
|
|
|
if (warning)
|
|
|
|
{
|
1989-04-11 14:34:21 +00:00
|
|
|
node_warning(nd,
|
2017-01-08 10:23:56 +00:00
|
|
|
W_ORDINARY,
|
|
|
|
"%s \"%s\" %s",
|
|
|
|
(df->df_flags & D_VALPAR) ? "value parameter" : (df->df_flags & D_VARPAR) ? "variable parameter" : (df->df_kind == D_VARIABLE) ? "variable" : (df->df_kind == D_TYPE) ? "type" : (df->df_kind == D_CONST) ? "constant" : "procedure",
|
|
|
|
df->df_idf->id_text, warning);
|
1989-04-11 14:34:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-10 21:04:18 +00:00
|
|
|
static void
|
2017-01-08 10:23:56 +00:00
|
|
|
UseWarnings(df) register t_def* df;
|
1987-10-19 11:28:37 +00:00
|
|
|
{
|
2017-01-08 10:23:56 +00:00
|
|
|
t_node* nd = df->df_scope->sc_end;
|
1988-03-22 17:54:01 +00:00
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
if (is_anon_idf(df->df_idf) || !(df->df_kind & (D_IMPORTED | D_VARIABLE | D_PROCEDURE | D_CONST | D_TYPE)) || (df->df_flags & (D_EXPORTED | D_QEXPORTED)))
|
|
|
|
{
|
1988-03-22 17:54:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
if (df->df_kind & D_IMPORTED)
|
|
|
|
{
|
|
|
|
register t_def* df1 = df->imp_def;
|
1988-03-22 17:54:01 +00:00
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
df1->df_flags |= df->df_flags & (D_USED | D_DEFINED);
|
|
|
|
if (df->df_kind == D_INUSE)
|
|
|
|
return;
|
|
|
|
if (!(df->df_flags & D_IMP_BY_EXP))
|
|
|
|
{
|
|
|
|
if (df->df_flags & (D_USED | D_DEFINED))
|
|
|
|
{
|
1989-04-11 14:34:21 +00:00
|
|
|
return;
|
1987-10-21 11:29:52 +00:00
|
|
|
}
|
1989-04-11 14:34:21 +00:00
|
|
|
df_warning(nd,
|
2017-01-08 10:23:56 +00:00
|
|
|
df1,
|
|
|
|
df1->df_kind == D_VARIABLE ? "imported but not used/assigned" : "imported but not used");
|
1988-03-22 17:54:01 +00:00
|
|
|
return;
|
1987-10-19 11:28:37 +00:00
|
|
|
}
|
1988-03-22 17:54:01 +00:00
|
|
|
df = df1;
|
1989-04-11 14:34:21 +00:00
|
|
|
nd = df->df_scope->sc_end;
|
1988-03-22 17:54:01 +00:00
|
|
|
}
|
2017-01-08 10:23:56 +00:00
|
|
|
switch (df->df_flags & (D_USED | D_DEFINED | D_VALPAR | D_VARPAR))
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
case D_VARPAR:
|
|
|
|
df_warning(nd, df, "never used/assigned");
|
|
|
|
break;
|
|
|
|
case D_USED:
|
|
|
|
df_warning(nd, df, "never assigned");
|
|
|
|
break;
|
|
|
|
case D_VALPAR:
|
|
|
|
case D_DEFINED:
|
|
|
|
case D_DEFINED | D_VALPAR:
|
|
|
|
df_warning(nd, df, "never used");
|
|
|
|
break;
|
1987-10-19 11:28:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-08 10:23:56 +00:00
|
|
|
WalkDefList(df, proc) register t_def* df;
|
|
|
|
int (*proc)();
|
1987-10-19 11:28:37 +00:00
|
|
|
{
|
2017-01-08 10:23:56 +00:00
|
|
|
for (; df; df = df->df_nextinscope)
|
|
|
|
{
|
1987-10-19 11:28:37 +00:00
|
|
|
(*proc)(df);
|
|
|
|
}
|
|
|
|
}
|
1993-11-10 12:44:24 +00:00
|
|
|
|
|
|
|
#ifdef DBSYMTAB
|
|
|
|
static int
|
2017-01-08 10:23:56 +00:00
|
|
|
stabdef(df)
|
|
|
|
t_def* df;
|
1993-11-10 12:44:24 +00:00
|
|
|
{
|
2017-01-08 10:23:56 +00:00
|
|
|
switch (df->df_kind)
|
|
|
|
{
|
|
|
|
case D_CONST:
|
|
|
|
case D_VARIABLE:
|
|
|
|
stb_string(df, df->df_kind);
|
|
|
|
break;
|
1993-11-10 12:44:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|