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-05-21 18:32:20 +00:00
|
|
|
/* C O D E G E N E R A T I O N R O U T I N E S */
|
|
|
|
|
1987-04-29 10:22:07 +00:00
|
|
|
/* $Header$ */
|
|
|
|
|
1986-05-21 18:32:20 +00:00
|
|
|
/* Code generation for expressions and coercions
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
#include <em_arith.h>
|
|
|
|
#include <em_label.h>
|
1986-07-08 14:59:02 +00:00
|
|
|
#include <em_code.h>
|
1987-06-18 17:42:47 +00:00
|
|
|
#include <em_abs.h>
|
1986-05-21 18:32:20 +00:00
|
|
|
#include <assert.h>
|
1987-07-30 13:37:39 +00:00
|
|
|
#include <alloc.h>
|
1986-05-21 18:32:20 +00:00
|
|
|
|
|
|
|
#include "type.h"
|
1987-07-30 13:37:39 +00:00
|
|
|
#include "LLlex.h"
|
1986-05-21 18:32:20 +00:00
|
|
|
#include "def.h"
|
|
|
|
#include "scope.h"
|
|
|
|
#include "desig.h"
|
|
|
|
#include "node.h"
|
|
|
|
#include "Lpars.h"
|
1986-05-30 18:48:00 +00:00
|
|
|
#include "standards.h"
|
1986-06-20 14:36:49 +00:00
|
|
|
#include "walk.h"
|
1989-03-22 09:53:47 +00:00
|
|
|
#include "bigresult.h"
|
1986-05-21 18:32:20 +00:00
|
|
|
|
|
|
|
extern char *long2str();
|
|
|
|
extern char *symbol2str();
|
|
|
|
extern int proclevel;
|
1987-08-11 10:50:30 +00:00
|
|
|
extern char options[];
|
1991-03-14 11:10:40 +00:00
|
|
|
extern t_desig null_desig;
|
1986-06-06 02:22:09 +00:00
|
|
|
int fp_used;
|
1986-05-21 18:32:20 +00:00
|
|
|
|
|
|
|
CodeConst(cst, size)
|
1987-07-21 13:54:33 +00:00
|
|
|
arith cst;
|
|
|
|
int size;
|
1986-05-21 18:32:20 +00:00
|
|
|
{
|
|
|
|
/* Generate code to push constant "cst" with size "size"
|
|
|
|
*/
|
|
|
|
|
1987-07-21 13:54:33 +00:00
|
|
|
if (size <= (int) word_size) {
|
1986-05-21 18:32:20 +00:00
|
|
|
C_loc(cst);
|
|
|
|
}
|
1987-07-21 13:54:33 +00:00
|
|
|
else if (size == (int) dword_size) {
|
1986-05-21 18:32:20 +00:00
|
|
|
C_ldc(cst);
|
|
|
|
}
|
|
|
|
else {
|
1986-10-06 20:36:30 +00:00
|
|
|
crash("(CodeConst)");
|
|
|
|
/*
|
1987-05-18 15:57:33 +00:00
|
|
|
C_df_dlb(++data_label);
|
1987-07-21 13:54:33 +00:00
|
|
|
C_rom_icon(long2str((long) cst), (arith) size);
|
1987-09-23 16:39:43 +00:00
|
|
|
c_lae_dlb(data_label);
|
1987-07-21 13:54:33 +00:00
|
|
|
C_loi((arith) size);
|
1986-10-06 20:36:30 +00:00
|
|
|
*/
|
1986-05-21 18:32:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CodeString(nd)
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_node *nd;
|
1986-05-21 18:32:20 +00:00
|
|
|
{
|
1986-09-25 19:39:06 +00:00
|
|
|
if (nd->nd_type->tp_fund != T_STRING) {
|
1987-05-18 15:57:33 +00:00
|
|
|
/* Character constant */
|
1986-05-23 09:46:31 +00:00
|
|
|
C_loc(nd->nd_INT);
|
1987-07-21 13:54:33 +00:00
|
|
|
return;
|
1986-05-23 09:46:31 +00:00
|
|
|
}
|
1987-07-21 13:54:33 +00:00
|
|
|
C_df_dlb(++data_label);
|
1988-04-13 18:37:45 +00:00
|
|
|
C_rom_scon(nd->nd_STR, WA((arith)(nd->nd_SLE + 1)));
|
1987-09-23 16:39:43 +00:00
|
|
|
c_lae_dlb(data_label);
|
1986-06-04 09:01:48 +00:00
|
|
|
}
|
|
|
|
|
1986-05-21 18:32:20 +00:00
|
|
|
CodeExpr(nd, ds, true_label, false_label)
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_node *nd;
|
|
|
|
register t_desig *ds;
|
1986-05-21 18:32:20 +00:00
|
|
|
label true_label, false_label;
|
|
|
|
{
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_type *tp = nd->nd_type;
|
1986-05-21 18:32:20 +00:00
|
|
|
|
1988-01-28 16:15:16 +00:00
|
|
|
DoLineno(nd);
|
1986-06-06 02:22:09 +00:00
|
|
|
if (tp->tp_fund == T_REAL) fp_used = 1;
|
1986-05-21 18:32:20 +00:00
|
|
|
switch(nd->nd_class) {
|
|
|
|
case Def:
|
1986-11-17 11:41:28 +00:00
|
|
|
if (nd->nd_def->df_kind & (D_PROCEDURE|D_PROCHEAD)) {
|
1991-03-12 16:52:00 +00:00
|
|
|
C_lpi(nd->nd_def->prc_name);
|
1986-05-30 18:48:00 +00:00
|
|
|
ds->dsg_kind = DSG_LOADED;
|
|
|
|
break;
|
|
|
|
}
|
1986-06-04 09:01:48 +00:00
|
|
|
/* Fall through */
|
|
|
|
|
|
|
|
case Link:
|
1986-06-10 13:18:52 +00:00
|
|
|
case Arrsel:
|
|
|
|
case Arrow:
|
1986-05-21 18:32:20 +00:00
|
|
|
CodeDesig(nd, ds);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Oper:
|
|
|
|
CodeOper(nd, true_label, false_label);
|
1987-05-18 15:57:33 +00:00
|
|
|
ds->dsg_kind = DSG_LOADED;
|
|
|
|
true_label = NO_LABEL;
|
1986-05-21 18:32:20 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Uoper:
|
|
|
|
CodeUoper(nd);
|
|
|
|
ds->dsg_kind = DSG_LOADED;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Value:
|
|
|
|
switch(nd->nd_symb) {
|
1987-05-18 15:57:33 +00:00
|
|
|
case REAL:
|
|
|
|
C_df_dlb(++data_label);
|
1991-03-06 10:52:34 +00:00
|
|
|
if (! nd->nd_RSTR) {
|
1989-12-19 09:40:25 +00:00
|
|
|
static char buf[FLT_STRLEN];
|
|
|
|
|
|
|
|
flt_flt2str(&nd->nd_RVAL, buf, FLT_STRLEN);
|
|
|
|
C_rom_fcon(buf, tp->tp_size);
|
|
|
|
}
|
1991-03-06 10:52:34 +00:00
|
|
|
else C_rom_fcon(nd->nd_RSTR, tp->tp_size);
|
1987-09-23 16:39:43 +00:00
|
|
|
c_lae_dlb(data_label);
|
1987-07-21 13:54:33 +00:00
|
|
|
C_loi(tp->tp_size);
|
1986-05-21 18:32:20 +00:00
|
|
|
break;
|
|
|
|
case STRING:
|
|
|
|
CodeString(nd);
|
|
|
|
break;
|
|
|
|
case INTEGER:
|
1987-07-21 13:54:33 +00:00
|
|
|
CodeConst(nd->nd_INT, (int) (tp->tp_size));
|
1986-05-21 18:32:20 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
crash("Value error");
|
|
|
|
}
|
|
|
|
ds->dsg_kind = DSG_LOADED;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Call:
|
|
|
|
CodeCall(nd);
|
|
|
|
ds->dsg_kind = DSG_LOADED;
|
|
|
|
break;
|
|
|
|
|
1986-05-23 19:25:21 +00:00
|
|
|
case Set: {
|
1987-07-21 13:54:33 +00:00
|
|
|
register unsigned i = (unsigned) (tp->tp_size) / (int) word_size;
|
1987-05-18 15:57:33 +00:00
|
|
|
register arith *st = nd->nd_set + i;
|
1986-05-23 19:25:21 +00:00
|
|
|
|
1986-05-28 18:36:51 +00:00
|
|
|
ds->dsg_kind = DSG_LOADED;
|
1987-07-21 13:54:33 +00:00
|
|
|
for (; i; i--) {
|
1986-05-23 19:25:21 +00:00
|
|
|
C_loc(*--st);
|
|
|
|
}
|
1987-09-23 16:39:43 +00:00
|
|
|
FreeSet(nd->nd_set);
|
1987-05-11 14:38:37 +00:00
|
|
|
CodeSet(nd);
|
1986-05-23 19:25:21 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1986-05-21 18:32:20 +00:00
|
|
|
default:
|
|
|
|
crash("(CodeExpr) bad node type");
|
|
|
|
}
|
|
|
|
|
1987-05-18 15:57:33 +00:00
|
|
|
if (true_label != NO_LABEL) {
|
1986-10-06 20:36:30 +00:00
|
|
|
/* Only for boolean expressions
|
|
|
|
*/
|
1987-06-23 17:12:25 +00:00
|
|
|
CodeValue(ds, tp);
|
1986-05-21 18:32:20 +00:00
|
|
|
C_zne(true_label);
|
|
|
|
C_bra(false_label);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CodeCoercion(t1, t2)
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_type *t1, *t2;
|
1986-05-21 18:32:20 +00:00
|
|
|
{
|
1986-06-04 09:01:48 +00:00
|
|
|
register int fund1, fund2;
|
1987-06-23 17:12:25 +00:00
|
|
|
arith sz1 = t1->tp_size;
|
1988-03-21 16:47:51 +00:00
|
|
|
arith sz2;
|
1986-05-28 18:36:51 +00:00
|
|
|
|
1986-06-26 09:39:36 +00:00
|
|
|
t1 = BaseType(t1);
|
|
|
|
t2 = BaseType(t2);
|
1988-03-21 16:47:51 +00:00
|
|
|
sz2 = t2->tp_size;
|
1987-06-23 17:12:25 +00:00
|
|
|
switch(fund1 = t1->tp_fund) {
|
|
|
|
case T_WORD:
|
|
|
|
fund1 = T_INTEGER;
|
|
|
|
break;
|
|
|
|
case T_CHAR:
|
|
|
|
case T_ENUMERATION:
|
1988-03-21 16:47:51 +00:00
|
|
|
case T_CARDINAL:
|
|
|
|
case T_INTORCARD:
|
1991-03-13 17:26:07 +00:00
|
|
|
if ((int) sz1 < (int) word_size) sz1 = word_size;
|
1988-03-21 16:47:51 +00:00
|
|
|
/* fall through */
|
|
|
|
case T_EQUAL:
|
1987-06-23 17:12:25 +00:00
|
|
|
case T_POINTER:
|
|
|
|
fund1 = T_CARDINAL;
|
|
|
|
break;
|
|
|
|
}
|
1987-06-29 12:46:00 +00:00
|
|
|
switch(fund2 = t2->tp_fund) {
|
1987-06-23 17:12:25 +00:00
|
|
|
case T_WORD:
|
|
|
|
fund2 = T_INTEGER;
|
|
|
|
break;
|
|
|
|
case T_CHAR:
|
|
|
|
case T_ENUMERATION:
|
1988-03-21 16:47:51 +00:00
|
|
|
sz2 = word_size;
|
|
|
|
/* fall through */
|
|
|
|
case T_EQUAL:
|
1987-06-23 17:12:25 +00:00
|
|
|
case T_POINTER:
|
|
|
|
fund2 = T_CARDINAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1986-05-28 18:36:51 +00:00
|
|
|
switch(fund1) {
|
|
|
|
case T_INTEGER:
|
1991-03-13 17:26:07 +00:00
|
|
|
if ((int) sz1 < (int) word_size) {
|
1987-11-09 10:17:20 +00:00
|
|
|
c_loc((int)sz1);
|
1987-09-23 16:39:43 +00:00
|
|
|
c_loc((int) word_size);
|
1987-06-23 17:12:25 +00:00
|
|
|
C_cii();
|
1988-03-21 16:47:51 +00:00
|
|
|
sz1 = word_size;
|
1987-06-23 17:12:25 +00:00
|
|
|
}
|
1988-03-21 16:47:51 +00:00
|
|
|
if (fund2 == T_REAL) {
|
|
|
|
c_loc((int)sz1);
|
|
|
|
c_loc((int)sz2);
|
|
|
|
C_cif();
|
1986-05-28 18:36:51 +00:00
|
|
|
break;
|
1988-03-21 16:47:51 +00:00
|
|
|
}
|
1991-03-13 17:26:07 +00:00
|
|
|
if ((int) sz2 != (int) sz1) {
|
1988-03-21 16:47:51 +00:00
|
|
|
c_loc((int)sz1);
|
|
|
|
c_loc((int)sz2);
|
|
|
|
switch(fund2) {
|
|
|
|
case T_INTEGER:
|
|
|
|
C_cii();
|
|
|
|
break;
|
|
|
|
case T_CARDINAL:
|
1986-05-28 18:36:51 +00:00
|
|
|
C_ciu();
|
1988-03-21 16:47:51 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
crash("Funny integer conversion");
|
1986-05-28 18:36:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_CARDINAL:
|
1986-08-26 14:33:24 +00:00
|
|
|
case T_INTORCARD:
|
1988-03-21 16:47:51 +00:00
|
|
|
if (fund2 == T_REAL) {
|
|
|
|
c_loc((int)sz1);
|
|
|
|
c_loc((int)sz2);
|
|
|
|
C_cuf();
|
1986-05-28 18:36:51 +00:00
|
|
|
break;
|
1988-03-21 16:47:51 +00:00
|
|
|
}
|
1991-03-13 17:26:07 +00:00
|
|
|
if ((int) sz1 != (int) sz2) {
|
1988-03-21 16:47:51 +00:00
|
|
|
c_loc((int)sz1);
|
|
|
|
c_loc((int)sz2);
|
|
|
|
switch(fund2) {
|
|
|
|
case T_CARDINAL:
|
|
|
|
case T_INTORCARD:
|
|
|
|
C_cuu();
|
|
|
|
break;
|
|
|
|
case T_INTEGER:
|
1987-06-23 17:12:25 +00:00
|
|
|
C_cui();
|
1988-03-21 16:47:51 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
crash("Funny cardinal conversion");
|
1987-06-23 17:12:25 +00:00
|
|
|
}
|
1986-05-28 18:36:51 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_REAL:
|
|
|
|
switch(fund2) {
|
|
|
|
case T_REAL:
|
1991-03-13 17:26:07 +00:00
|
|
|
if ((int) sz1 != (int) sz2) {
|
1988-03-21 16:47:51 +00:00
|
|
|
c_loc((int)sz1);
|
|
|
|
c_loc((int)sz2);
|
1986-05-28 18:36:51 +00:00
|
|
|
C_cff();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case T_INTEGER:
|
1988-03-21 16:47:51 +00:00
|
|
|
c_loc((int)sz1);
|
|
|
|
c_loc((int)sz2);
|
1986-05-28 18:36:51 +00:00
|
|
|
C_cfi();
|
|
|
|
break;
|
|
|
|
case T_CARDINAL:
|
1987-08-11 10:50:30 +00:00
|
|
|
if (! options['R']) {
|
|
|
|
label lb = ++text_label;
|
|
|
|
|
1988-03-21 16:47:51 +00:00
|
|
|
C_dup(sz1);
|
|
|
|
C_zrf(sz1);
|
|
|
|
C_cmf(sz1);
|
1987-08-11 10:50:30 +00:00
|
|
|
C_zge(lb);
|
1987-09-23 16:39:43 +00:00
|
|
|
c_loc(ECONV);
|
1987-08-11 10:50:30 +00:00
|
|
|
C_trp();
|
1988-01-28 16:15:16 +00:00
|
|
|
def_ilb(lb);
|
1987-08-11 10:50:30 +00:00
|
|
|
}
|
1988-03-21 16:47:51 +00:00
|
|
|
c_loc((int)sz1);
|
|
|
|
c_loc((int)sz2);
|
1986-05-28 18:36:51 +00:00
|
|
|
C_cfu();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
crash("Funny REAL conversion");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
1986-05-21 18:32:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CodeCall(nd)
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_node *nd;
|
1986-05-21 18:32:20 +00:00
|
|
|
{
|
|
|
|
/* Generate code for a procedure call. Checking of parameters
|
|
|
|
and result is already done.
|
|
|
|
*/
|
1991-03-12 16:52:00 +00:00
|
|
|
register t_node *left = nd->nd_LEFT;
|
1989-03-03 16:13:45 +00:00
|
|
|
t_type *result_tp;
|
1988-10-25 17:43:19 +00:00
|
|
|
int needs_fn;
|
1986-05-21 18:32:20 +00:00
|
|
|
|
|
|
|
if (left->nd_type == std_type) {
|
|
|
|
CodeStd(nd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1989-03-03 16:13:45 +00:00
|
|
|
assert(IsProc(left));
|
1986-05-21 18:32:20 +00:00
|
|
|
|
1989-03-22 09:53:47 +00:00
|
|
|
result_tp = ResultType(left->nd_type);
|
|
|
|
#ifdef BIG_RESULT_ON_STACK
|
|
|
|
if (result_tp && TooBigForReturnArea(result_tp)) {
|
|
|
|
C_asp(-WA(result_tp->tp_size));
|
1989-03-10 10:40:07 +00:00
|
|
|
}
|
1989-03-22 09:53:47 +00:00
|
|
|
#endif
|
1989-03-10 10:40:07 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
if (nd->nd_RIGHT) {
|
|
|
|
CodeParameters(ParamList(left->nd_type), nd->nd_RIGHT);
|
1986-05-21 18:32:20 +00:00
|
|
|
}
|
|
|
|
|
1986-08-26 14:33:24 +00:00
|
|
|
switch(left->nd_class) {
|
|
|
|
case Def: {
|
1989-03-03 16:13:45 +00:00
|
|
|
register t_def *df = left->nd_def;
|
|
|
|
|
|
|
|
if (df->df_kind == D_CONST) {
|
|
|
|
df = df->con_const.tk_data.tk_def;
|
|
|
|
}
|
|
|
|
if (df->df_kind & (D_PROCEDURE|D_PROCHEAD)) {
|
|
|
|
int level = df->df_scope->sc_level;
|
1986-08-26 14:33:24 +00:00
|
|
|
|
|
|
|
if (level > 0) {
|
1987-05-18 15:57:33 +00:00
|
|
|
C_lxl((arith) (proclevel - level));
|
1986-08-26 14:33:24 +00:00
|
|
|
}
|
1989-03-03 16:13:45 +00:00
|
|
|
needs_fn = df->df_scope->sc_defmodule;
|
1991-03-12 16:52:00 +00:00
|
|
|
C_cal(df->prc_name);
|
1986-08-26 14:33:24 +00:00
|
|
|
break;
|
|
|
|
}}
|
|
|
|
/* Fall through */
|
|
|
|
default:
|
1988-10-25 17:43:19 +00:00
|
|
|
needs_fn = 1;
|
1986-05-30 18:48:00 +00:00
|
|
|
CodePExpr(left);
|
1986-05-21 18:32:20 +00:00
|
|
|
C_cai();
|
|
|
|
}
|
1987-05-18 15:57:33 +00:00
|
|
|
C_asp(left->nd_type->prc_nbpar);
|
1989-03-10 10:40:07 +00:00
|
|
|
if (result_tp) {
|
1989-03-22 09:53:47 +00:00
|
|
|
arith sz = WA(result_tp->tp_size);
|
1989-03-10 10:40:07 +00:00
|
|
|
if (TooBigForReturnArea(result_tp)) {
|
1989-03-22 09:53:47 +00:00
|
|
|
#ifndef BIG_RESULT_ON_STACK
|
|
|
|
C_lfr(pointer_size);
|
|
|
|
C_loi(sz);
|
|
|
|
#endif
|
1986-06-20 14:36:49 +00:00
|
|
|
}
|
1989-03-22 09:53:47 +00:00
|
|
|
else C_lfr(sz);
|
1986-05-21 18:32:20 +00:00
|
|
|
}
|
1988-10-25 17:43:19 +00:00
|
|
|
DoFilename(needs_fn);
|
1988-03-23 17:44:25 +00:00
|
|
|
DoLineno(nd);
|
1986-05-21 18:32:20 +00:00
|
|
|
}
|
|
|
|
|
1986-06-17 12:04:05 +00:00
|
|
|
CodeParameters(param, arg)
|
1987-09-24 13:07:31 +00:00
|
|
|
t_param *param;
|
1991-03-12 16:52:00 +00:00
|
|
|
register t_node *arg;
|
1986-06-17 12:04:05 +00:00
|
|
|
{
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_type *tp;
|
1991-03-12 16:52:00 +00:00
|
|
|
register t_type *arg_type;
|
1986-09-25 19:39:06 +00:00
|
|
|
|
1986-06-17 12:04:05 +00:00
|
|
|
assert(param != 0 && arg != 0);
|
|
|
|
|
1987-07-16 19:51:40 +00:00
|
|
|
if (param->par_next) {
|
1991-03-12 16:52:00 +00:00
|
|
|
CodeParameters(param->par_next, arg->nd_RIGHT);
|
1986-06-17 12:04:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tp = TypeOfParam(param);
|
1991-03-12 16:52:00 +00:00
|
|
|
arg = arg->nd_LEFT;
|
|
|
|
arg_type = arg->nd_type;
|
1986-06-17 12:04:05 +00:00
|
|
|
if (IsConformantArray(tp)) {
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_type *elem = tp->arr_elem;
|
1986-11-26 16:40:45 +00:00
|
|
|
|
1986-06-17 12:04:05 +00:00
|
|
|
C_loc(tp->arr_elsize);
|
1991-03-12 16:52:00 +00:00
|
|
|
if (IsConformantArray(arg_type)) {
|
|
|
|
DoHIGH(arg->nd_def);
|
|
|
|
if (elem->tp_size != arg_type->arr_elem->tp_size) {
|
1986-06-17 12:04:05 +00:00
|
|
|
/* This can only happen if the formal type is
|
1986-11-26 16:40:45 +00:00
|
|
|
ARRAY OF (WORD|BYTE)
|
1986-06-17 12:04:05 +00:00
|
|
|
*/
|
1991-03-12 16:52:00 +00:00
|
|
|
C_loc(arg_type->arr_elem->tp_size);
|
1986-11-26 16:40:45 +00:00
|
|
|
C_mli(word_size);
|
|
|
|
if (elem == word_type) {
|
1987-09-23 16:39:43 +00:00
|
|
|
c_loc((int) word_size - 1);
|
1986-11-26 16:40:45 +00:00
|
|
|
C_adi(word_size);
|
1987-09-23 16:39:43 +00:00
|
|
|
c_loc((int) word_size);
|
1986-11-26 16:40:45 +00:00
|
|
|
C_dvi(word_size);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
assert(elem == byte_type);
|
|
|
|
}
|
1986-06-17 12:04:05 +00:00
|
|
|
}
|
|
|
|
}
|
1991-03-12 16:52:00 +00:00
|
|
|
else if (arg->nd_symb == STRING) {
|
1991-03-13 17:26:07 +00:00
|
|
|
c_loc((int) arg->nd_SLE - 1);
|
1986-06-17 12:04:05 +00:00
|
|
|
}
|
1986-11-26 16:40:45 +00:00
|
|
|
else if (elem == word_type) {
|
1991-03-12 16:52:00 +00:00
|
|
|
C_loc((arg_type->tp_size+word_size-1) / word_size - 1);
|
1986-06-17 12:04:05 +00:00
|
|
|
}
|
1986-11-26 16:40:45 +00:00
|
|
|
else if (elem == byte_type) {
|
1991-03-12 16:52:00 +00:00
|
|
|
C_loc(arg_type->tp_size - 1);
|
1986-11-26 16:40:45 +00:00
|
|
|
}
|
1986-06-17 12:04:05 +00:00
|
|
|
else {
|
1991-03-12 16:52:00 +00:00
|
|
|
C_loc(arg_type->arr_high - arg_type->arr_low);
|
1986-06-17 12:04:05 +00:00
|
|
|
}
|
1987-09-23 16:39:43 +00:00
|
|
|
c_loc(0);
|
1989-03-20 13:32:06 +00:00
|
|
|
}
|
1991-03-13 13:49:56 +00:00
|
|
|
if (IsConformantArray(tp) || IsVarParam(param)) {
|
1991-03-12 16:52:00 +00:00
|
|
|
if (arg->nd_symb == STRING) {
|
|
|
|
CodeString(arg);
|
1986-06-17 12:04:05 +00:00
|
|
|
}
|
1991-03-12 16:52:00 +00:00
|
|
|
else switch(arg->nd_class) {
|
1987-07-22 10:59:24 +00:00
|
|
|
case Arrsel:
|
|
|
|
case Arrow:
|
|
|
|
case Def:
|
1991-03-12 16:52:00 +00:00
|
|
|
CodeDAddress(arg, IsVarParam(param));
|
1987-07-22 10:59:24 +00:00
|
|
|
break;
|
|
|
|
default:{
|
1986-11-26 16:40:45 +00:00
|
|
|
arith tmp, TmpSpace();
|
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
CodePExpr(arg);
|
|
|
|
tmp = TmpSpace(arg->nd_type->tp_size, arg->nd_type->tp_align);
|
|
|
|
STL(tmp, WA(arg->nd_type->tp_size));
|
1986-11-26 16:40:45 +00:00
|
|
|
C_lal(tmp);
|
1987-07-22 10:59:24 +00:00
|
|
|
}
|
|
|
|
break;
|
1986-11-26 16:40:45 +00:00
|
|
|
}
|
|
|
|
return;
|
1986-06-17 12:04:05 +00:00
|
|
|
}
|
1991-03-12 16:52:00 +00:00
|
|
|
if (arg_type->tp_fund == T_STRING) {
|
|
|
|
CodePString(arg, tp);
|
1986-11-26 16:40:45 +00:00
|
|
|
return;
|
1986-06-17 12:04:05 +00:00
|
|
|
}
|
1991-03-12 16:52:00 +00:00
|
|
|
CodePExpr(arg);
|
1986-06-17 12:04:05 +00:00
|
|
|
}
|
|
|
|
|
1986-12-01 10:06:53 +00:00
|
|
|
CodePString(nd, tp)
|
1987-09-23 16:39:43 +00:00
|
|
|
t_node *nd;
|
|
|
|
t_type *tp;
|
1986-12-01 10:06:53 +00:00
|
|
|
{
|
|
|
|
arith szarg = WA(nd->nd_type->tp_size);
|
|
|
|
register arith zersz = WA(tp->tp_size) - szarg;
|
|
|
|
|
|
|
|
if (zersz) {
|
|
|
|
/* null padding required */
|
|
|
|
assert(zersz > 0);
|
|
|
|
C_zer(zersz);
|
|
|
|
}
|
|
|
|
CodeString(nd); /* push address of string */
|
|
|
|
C_loi(szarg);
|
|
|
|
}
|
|
|
|
|
1987-11-26 14:15:24 +00:00
|
|
|
static
|
|
|
|
subu(sz)
|
1991-03-13 17:26:07 +00:00
|
|
|
int sz;
|
1987-11-26 14:15:24 +00:00
|
|
|
{
|
1991-03-05 11:55:22 +00:00
|
|
|
if (! options['R']) {
|
1991-03-13 17:26:07 +00:00
|
|
|
C_cal(sz == (int) word_size ? "subuchk" : "subulchk");
|
1987-11-26 14:15:24 +00:00
|
|
|
}
|
1991-03-13 17:26:07 +00:00
|
|
|
C_sbu((arith) sz);
|
1987-11-26 14:15:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
addu(sz)
|
1991-03-13 17:26:07 +00:00
|
|
|
int sz;
|
1987-11-26 14:15:24 +00:00
|
|
|
{
|
1991-03-05 11:55:22 +00:00
|
|
|
if (! options['R']) {
|
1991-03-13 17:26:07 +00:00
|
|
|
C_cal(sz == (int) word_size ? "adduchk" : "addulchk");
|
1987-11-26 14:15:24 +00:00
|
|
|
}
|
1991-03-13 17:26:07 +00:00
|
|
|
C_adu((arith)sz);
|
1987-11-26 14:15:24 +00:00
|
|
|
}
|
|
|
|
|
1986-05-21 18:32:20 +00:00
|
|
|
CodeStd(nd)
|
1987-09-23 16:39:43 +00:00
|
|
|
t_node *nd;
|
1986-05-21 18:32:20 +00:00
|
|
|
{
|
1991-03-12 16:52:00 +00:00
|
|
|
register t_node *arg = nd->nd_RIGHT;
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_node *left = 0;
|
1988-10-13 15:43:23 +00:00
|
|
|
register t_type *tp = 0;
|
1991-03-12 16:52:00 +00:00
|
|
|
int std = nd->nd_LEFT->nd_def->df_value.df_stdname;
|
1986-05-30 18:48:00 +00:00
|
|
|
|
|
|
|
if (arg) {
|
1991-03-12 16:52:00 +00:00
|
|
|
left = arg->nd_LEFT;
|
1986-06-26 09:39:36 +00:00
|
|
|
tp = BaseType(left->nd_type);
|
1991-03-12 16:52:00 +00:00
|
|
|
arg = arg->nd_RIGHT;
|
1986-05-30 18:48:00 +00:00
|
|
|
}
|
|
|
|
|
1986-10-06 20:36:30 +00:00
|
|
|
switch(std) {
|
1988-04-06 18:14:50 +00:00
|
|
|
case S_ORD:
|
|
|
|
case S_VAL:
|
|
|
|
CodePExpr(left);
|
|
|
|
break;
|
|
|
|
|
1986-05-30 18:48:00 +00:00
|
|
|
case S_ABS:
|
|
|
|
CodePExpr(left);
|
|
|
|
if (tp->tp_fund == T_INTEGER) {
|
1988-06-13 10:29:36 +00:00
|
|
|
CAL((int)(tp->tp_size) == (int)int_size ? "absi" : "absl", (int)(tp->tp_size));
|
1986-05-30 18:48:00 +00:00
|
|
|
}
|
|
|
|
else if (tp->tp_fund == T_REAL) {
|
1988-06-13 10:29:36 +00:00
|
|
|
CAL((int)(tp->tp_size) == (int)float_size ? "absf" : "absd", (int)(tp->tp_size));
|
1986-05-30 18:48:00 +00:00
|
|
|
}
|
|
|
|
C_lfr(tp->tp_size);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_CAP:
|
|
|
|
CodePExpr(left);
|
1988-04-06 18:14:50 +00:00
|
|
|
C_cal("cap");
|
1986-05-30 18:48:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case S_HIGH:
|
|
|
|
assert(IsConformantArray(tp));
|
1987-05-18 15:57:33 +00:00
|
|
|
DoHIGH(left->nd_def);
|
1986-05-30 18:48:00 +00:00
|
|
|
break;
|
|
|
|
|
1986-11-28 11:59:08 +00:00
|
|
|
case S_SIZE:
|
|
|
|
case S_TSIZE:
|
|
|
|
assert(IsConformantArray(tp));
|
1987-05-18 15:57:33 +00:00
|
|
|
DoHIGH(left->nd_def);
|
1986-11-28 11:59:08 +00:00
|
|
|
C_inc();
|
|
|
|
C_loc(tp->arr_elem->tp_size);
|
|
|
|
C_mlu(word_size);
|
|
|
|
break;
|
|
|
|
|
1986-05-30 18:48:00 +00:00
|
|
|
case S_ODD:
|
1986-08-26 14:33:24 +00:00
|
|
|
CodePExpr(left);
|
1986-05-30 18:48:00 +00:00
|
|
|
if (tp->tp_size == word_size) {
|
1987-09-23 16:39:43 +00:00
|
|
|
c_loc(1);
|
1986-05-30 18:48:00 +00:00
|
|
|
C_and(word_size);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
assert(tp->tp_size == dword_size);
|
|
|
|
C_ldc((arith) 1);
|
|
|
|
C_and(dword_size);
|
|
|
|
C_ior(word_size);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_ADR:
|
1988-04-11 18:32:47 +00:00
|
|
|
CodeDAddress(left, 1);
|
1986-05-30 18:48:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case S_DEC:
|
1986-10-06 20:36:30 +00:00
|
|
|
case S_INC: {
|
1987-07-30 13:37:39 +00:00
|
|
|
register arith size;
|
1986-10-06 20:36:30 +00:00
|
|
|
|
1987-07-30 13:37:39 +00:00
|
|
|
size = left->nd_type->tp_size;
|
1991-03-13 17:26:07 +00:00
|
|
|
if ((int) size < (int) word_size) size = word_size;
|
1986-05-30 18:48:00 +00:00
|
|
|
CodePExpr(left);
|
1987-10-28 11:10:30 +00:00
|
|
|
CodeCoercion(left->nd_type, tp);
|
1987-06-23 17:12:25 +00:00
|
|
|
if (arg) {
|
1991-03-12 16:52:00 +00:00
|
|
|
CodePExpr(arg->nd_LEFT);
|
|
|
|
CodeCoercion(arg->nd_LEFT->nd_type, tp);
|
1987-06-23 17:12:25 +00:00
|
|
|
}
|
|
|
|
else {
|
1987-09-23 16:39:43 +00:00
|
|
|
c_loc(1);
|
1987-06-23 17:12:25 +00:00
|
|
|
CodeCoercion(intorcard_type, tp);
|
|
|
|
}
|
1986-10-06 20:36:30 +00:00
|
|
|
if (std == S_DEC) {
|
|
|
|
if (tp->tp_fund == T_INTEGER) C_sbi(size);
|
1991-03-13 17:26:07 +00:00
|
|
|
else subu((int) size);
|
1986-05-30 18:48:00 +00:00
|
|
|
}
|
|
|
|
else {
|
1986-10-06 20:36:30 +00:00
|
|
|
if (tp->tp_fund == T_INTEGER) C_adi(size);
|
1991-03-13 17:26:07 +00:00
|
|
|
else addu((int) size);
|
1986-05-30 18:48:00 +00:00
|
|
|
}
|
1991-03-13 17:26:07 +00:00
|
|
|
if ((int) size == (int) word_size) {
|
1987-07-30 13:37:39 +00:00
|
|
|
RangeCheck(left->nd_type, tp->tp_fund == T_INTEGER ?
|
1987-06-29 12:46:00 +00:00
|
|
|
int_type : card_type);
|
|
|
|
}
|
1986-05-30 18:48:00 +00:00
|
|
|
CodeDStore(left);
|
|
|
|
break;
|
1986-10-06 20:36:30 +00:00
|
|
|
}
|
1986-05-30 18:48:00 +00:00
|
|
|
|
|
|
|
case S_HALT:
|
1988-03-23 17:44:25 +00:00
|
|
|
C_cal("halt");
|
1986-05-30 18:48:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case S_INCL:
|
|
|
|
case S_EXCL:
|
|
|
|
CodePExpr(left);
|
1991-03-12 16:52:00 +00:00
|
|
|
CodePExpr(arg->nd_LEFT);
|
1987-10-28 16:03:56 +00:00
|
|
|
C_loc(tp->set_low);
|
|
|
|
C_sbi(word_size);
|
1986-05-30 18:48:00 +00:00
|
|
|
C_set(tp->tp_size);
|
|
|
|
if (std == S_INCL) {
|
|
|
|
C_ior(tp->tp_size);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
C_com(tp->tp_size);
|
|
|
|
C_and(tp->tp_size);
|
|
|
|
}
|
|
|
|
CodeDStore(left);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
crash("(CodeStd)");
|
|
|
|
}
|
1986-05-21 18:32:20 +00:00
|
|
|
}
|
|
|
|
|
1986-09-25 19:39:06 +00:00
|
|
|
RangeCheck(tpl, tpr)
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_type *tpl, *tpr;
|
1986-05-28 18:36:51 +00:00
|
|
|
{
|
|
|
|
/* Generate a range check if neccessary
|
|
|
|
*/
|
|
|
|
|
1988-04-13 18:37:45 +00:00
|
|
|
arith rlo, rhi;
|
1986-05-28 18:36:51 +00:00
|
|
|
|
1987-08-11 10:50:30 +00:00
|
|
|
if (options['R']) return;
|
|
|
|
|
1986-05-28 18:36:51 +00:00
|
|
|
if (bounded(tpl)) {
|
1988-04-13 18:37:45 +00:00
|
|
|
/* In this case we might need a range check.
|
|
|
|
If both types are restricted. check the bounds
|
1987-07-30 13:37:39 +00:00
|
|
|
to see wether we need a range check.
|
|
|
|
We don't need one if the range of values of the
|
|
|
|
right hand side is a subset of the range of values
|
|
|
|
of the left hand side.
|
|
|
|
*/
|
1988-04-13 18:37:45 +00:00
|
|
|
if (bounded(tpr)) {
|
|
|
|
getbounds(tpr, &rlo, &rhi);
|
|
|
|
if (in_range(rlo, tpl) && in_range(rhi, tpl)) {
|
|
|
|
return;
|
|
|
|
}
|
1986-05-28 18:36:51 +00:00
|
|
|
}
|
1988-04-13 18:37:45 +00:00
|
|
|
genrck(tpl);
|
1987-07-30 13:37:39 +00:00
|
|
|
return;
|
1986-05-28 18:36:51 +00:00
|
|
|
}
|
1989-08-21 17:08:54 +00:00
|
|
|
tpr = BaseType(tpr);
|
|
|
|
if ((tpl->tp_fund == T_INTEGER && tpr == card_type) ||
|
|
|
|
(tpr->tp_fund == T_INTEGER && tpl == card_type)) {
|
1987-06-18 17:42:47 +00:00
|
|
|
label lb = ++text_label;
|
|
|
|
|
1989-08-21 17:08:54 +00:00
|
|
|
C_dup(tpr->tp_size);
|
|
|
|
C_zer(tpr->tp_size);
|
|
|
|
C_cmi(tpr->tp_size);
|
1987-06-18 17:42:47 +00:00
|
|
|
C_zge(lb);
|
1987-09-23 16:39:43 +00:00
|
|
|
c_loc(ECONV);
|
1987-06-18 17:42:47 +00:00
|
|
|
C_trp();
|
1988-01-28 16:15:16 +00:00
|
|
|
def_ilb(lb);
|
1987-06-18 17:42:47 +00:00
|
|
|
}
|
1986-05-21 18:32:20 +00:00
|
|
|
}
|
|
|
|
|
1988-01-28 16:15:16 +00:00
|
|
|
Operands(nd)
|
|
|
|
register t_node *nd;
|
1986-05-21 18:32:20 +00:00
|
|
|
{
|
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
CodePExpr(nd->nd_LEFT);
|
|
|
|
CodePExpr(nd->nd_RIGHT);
|
1988-01-28 16:15:16 +00:00
|
|
|
DoLineno(nd);
|
1986-05-21 18:32:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CodeOper(expr, true_label, false_label)
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_node *expr; /* the expression tree itself */
|
1986-05-21 18:32:20 +00:00
|
|
|
label true_label;
|
|
|
|
label false_label; /* labels to jump to in logical expr's */
|
|
|
|
{
|
1991-03-12 16:52:00 +00:00
|
|
|
register t_node *leftop = expr->nd_LEFT;
|
|
|
|
register t_node *rightop = expr->nd_RIGHT;
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_type *tp = expr->nd_type;
|
1986-05-21 18:32:20 +00:00
|
|
|
|
1986-08-26 14:33:24 +00:00
|
|
|
switch (expr->nd_symb) {
|
1986-05-21 18:32:20 +00:00
|
|
|
case '+':
|
1988-01-28 16:15:16 +00:00
|
|
|
Operands(expr);
|
1986-05-21 18:32:20 +00:00
|
|
|
switch (tp->tp_fund) {
|
|
|
|
case T_INTEGER:
|
|
|
|
C_adi(tp->tp_size);
|
|
|
|
break;
|
|
|
|
case T_REAL:
|
|
|
|
C_adf(tp->tp_size);
|
|
|
|
break;
|
1986-08-26 14:33:24 +00:00
|
|
|
case T_POINTER:
|
1986-09-25 19:39:06 +00:00
|
|
|
case T_EQUAL:
|
1988-03-21 16:47:51 +00:00
|
|
|
C_ads(rightop->nd_type->tp_size);
|
|
|
|
break;
|
1986-05-21 18:32:20 +00:00
|
|
|
case T_CARDINAL:
|
1986-08-26 14:33:24 +00:00
|
|
|
case T_INTORCARD:
|
1991-03-13 17:26:07 +00:00
|
|
|
addu((int) tp->tp_size);
|
1986-05-21 18:32:20 +00:00
|
|
|
break;
|
|
|
|
case T_SET:
|
|
|
|
C_ior(tp->tp_size);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
crash("bad type +");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '-':
|
1988-01-28 16:15:16 +00:00
|
|
|
Operands(expr);
|
1986-05-21 18:32:20 +00:00
|
|
|
switch (tp->tp_fund) {
|
|
|
|
case T_INTEGER:
|
|
|
|
C_sbi(tp->tp_size);
|
|
|
|
break;
|
|
|
|
case T_REAL:
|
|
|
|
C_sbf(tp->tp_size);
|
|
|
|
break;
|
1988-04-06 18:14:50 +00:00
|
|
|
case T_POINTER:
|
|
|
|
case T_EQUAL:
|
1988-03-21 16:47:51 +00:00
|
|
|
if (rightop->nd_type == address_type) {
|
1988-04-06 18:14:50 +00:00
|
|
|
C_sbs(tp->tp_size);
|
1988-03-21 16:47:51 +00:00
|
|
|
break;
|
|
|
|
}
|
1988-04-06 18:14:50 +00:00
|
|
|
C_ngi(rightop->nd_type->tp_size);
|
|
|
|
C_ads(rightop->nd_type->tp_size);
|
|
|
|
break;
|
1986-08-26 14:33:24 +00:00
|
|
|
case T_INTORCARD:
|
1988-04-06 18:14:50 +00:00
|
|
|
case T_CARDINAL:
|
1991-03-13 17:26:07 +00:00
|
|
|
subu((int) tp->tp_size);
|
1986-05-21 18:32:20 +00:00
|
|
|
break;
|
|
|
|
case T_SET:
|
|
|
|
C_com(tp->tp_size);
|
|
|
|
C_and(tp->tp_size);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
crash("bad type -");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '*':
|
1988-01-28 16:15:16 +00:00
|
|
|
Operands(expr);
|
1986-05-21 18:32:20 +00:00
|
|
|
switch (tp->tp_fund) {
|
|
|
|
case T_INTEGER:
|
|
|
|
C_mli(tp->tp_size);
|
|
|
|
break;
|
|
|
|
case T_POINTER:
|
1986-09-25 19:39:06 +00:00
|
|
|
case T_EQUAL:
|
1986-05-21 18:32:20 +00:00
|
|
|
case T_CARDINAL:
|
1986-08-26 14:33:24 +00:00
|
|
|
case T_INTORCARD:
|
1991-03-05 11:55:22 +00:00
|
|
|
if (! options['R']) {
|
1991-03-06 10:52:34 +00:00
|
|
|
C_cal((int)(tp->tp_size) <= (int)word_size ?
|
|
|
|
"muluchk" :
|
|
|
|
"mululchk");
|
1987-11-26 14:15:24 +00:00
|
|
|
}
|
1991-03-05 11:55:22 +00:00
|
|
|
C_mlu(tp->tp_size);
|
1986-05-21 18:32:20 +00:00
|
|
|
break;
|
|
|
|
case T_REAL:
|
|
|
|
C_mlf(tp->tp_size);
|
|
|
|
break;
|
|
|
|
case T_SET:
|
|
|
|
C_and(tp->tp_size);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
crash("bad type *");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '/':
|
1988-01-28 16:15:16 +00:00
|
|
|
Operands(expr);
|
1986-05-21 18:32:20 +00:00
|
|
|
switch (tp->tp_fund) {
|
|
|
|
case T_REAL:
|
|
|
|
C_dvf(tp->tp_size);
|
|
|
|
break;
|
|
|
|
case T_SET:
|
|
|
|
C_xor(tp->tp_size);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
crash("bad type /");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DIV:
|
1988-01-28 16:15:16 +00:00
|
|
|
Operands(expr);
|
1986-05-21 18:32:20 +00:00
|
|
|
switch(tp->tp_fund) {
|
|
|
|
case T_INTEGER:
|
1990-07-16 09:05:19 +00:00
|
|
|
C_cal((int)(tp->tp_size) == (int)word_size
|
|
|
|
? "dvi"
|
|
|
|
: "dvil");
|
|
|
|
C_asp(2*tp->tp_size);
|
|
|
|
C_lfr(tp->tp_size);
|
1986-05-21 18:32:20 +00:00
|
|
|
break;
|
|
|
|
case T_POINTER:
|
1986-09-25 19:39:06 +00:00
|
|
|
case T_EQUAL:
|
1986-05-21 18:32:20 +00:00
|
|
|
case T_CARDINAL:
|
1986-08-26 14:33:24 +00:00
|
|
|
case T_INTORCARD:
|
1986-05-21 18:32:20 +00:00
|
|
|
C_dvu(tp->tp_size);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
crash("bad type DIV");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MOD:
|
1988-01-28 16:15:16 +00:00
|
|
|
Operands(expr);
|
1986-05-21 18:32:20 +00:00
|
|
|
switch(tp->tp_fund) {
|
|
|
|
case T_INTEGER:
|
1990-07-16 09:05:19 +00:00
|
|
|
C_cal((int)(tp->tp_size) == (int)word_size
|
|
|
|
? "rmi"
|
|
|
|
: "rmil");
|
|
|
|
C_asp(2*tp->tp_size);
|
|
|
|
C_lfr(tp->tp_size);
|
1986-05-21 18:32:20 +00:00
|
|
|
break;
|
|
|
|
case T_POINTER:
|
1986-09-25 19:39:06 +00:00
|
|
|
case T_EQUAL:
|
1986-05-21 18:32:20 +00:00
|
|
|
case T_CARDINAL:
|
1986-08-26 14:33:24 +00:00
|
|
|
case T_INTORCARD:
|
1986-05-21 18:32:20 +00:00
|
|
|
C_rmu(tp->tp_size);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
crash("bad type MOD");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '<':
|
|
|
|
case LESSEQUAL:
|
|
|
|
case '>':
|
|
|
|
case GREATEREQUAL:
|
|
|
|
case '=':
|
|
|
|
case '#':
|
1988-01-28 16:15:16 +00:00
|
|
|
Operands(expr);
|
1986-08-26 14:33:24 +00:00
|
|
|
tp = BaseType(leftop->nd_type);
|
|
|
|
if (tp == intorcard_type) tp = BaseType(rightop->nd_type);
|
1986-05-21 18:32:20 +00:00
|
|
|
switch (tp->tp_fund) {
|
|
|
|
case T_INTEGER:
|
1986-05-28 18:36:51 +00:00
|
|
|
C_cmi(tp->tp_size);
|
1986-05-21 18:32:20 +00:00
|
|
|
break;
|
|
|
|
case T_POINTER:
|
1986-09-25 19:39:06 +00:00
|
|
|
case T_HIDDEN:
|
1986-12-01 10:06:53 +00:00
|
|
|
case T_EQUAL:
|
1988-02-01 10:17:51 +00:00
|
|
|
C_cmp();
|
|
|
|
break;
|
1986-05-21 18:32:20 +00:00
|
|
|
case T_CARDINAL:
|
1986-08-26 14:33:24 +00:00
|
|
|
case T_INTORCARD:
|
1986-05-28 18:36:51 +00:00
|
|
|
C_cmu(tp->tp_size);
|
1986-05-21 18:32:20 +00:00
|
|
|
break;
|
|
|
|
case T_ENUMERATION:
|
|
|
|
case T_CHAR:
|
|
|
|
C_cmu(word_size);
|
|
|
|
break;
|
|
|
|
case T_REAL:
|
1986-05-28 18:36:51 +00:00
|
|
|
C_cmf(tp->tp_size);
|
1986-05-21 18:32:20 +00:00
|
|
|
break;
|
|
|
|
case T_SET:
|
1986-08-26 14:33:24 +00:00
|
|
|
if (expr->nd_symb == GREATEREQUAL) {
|
1986-05-28 18:36:51 +00:00
|
|
|
/* A >= B is the same as A equals A + B
|
|
|
|
*/
|
1988-04-11 18:32:47 +00:00
|
|
|
C_dup(tp->tp_size << 1);
|
1986-05-28 18:36:51 +00:00
|
|
|
C_asp(tp->tp_size);
|
1986-08-26 14:33:24 +00:00
|
|
|
C_ior(tp->tp_size);
|
1987-06-18 15:46:08 +00:00
|
|
|
expr->nd_symb = '=';
|
1986-05-28 18:36:51 +00:00
|
|
|
}
|
1986-08-26 14:33:24 +00:00
|
|
|
else if (expr->nd_symb == LESSEQUAL) {
|
1986-05-28 18:36:51 +00:00
|
|
|
/* A <= B is the same as A - B = {}
|
|
|
|
*/
|
|
|
|
C_com(tp->tp_size);
|
|
|
|
C_and(tp->tp_size);
|
1986-06-20 14:36:49 +00:00
|
|
|
C_zer(tp->tp_size);
|
1987-06-18 15:46:08 +00:00
|
|
|
expr->nd_symb = '=';
|
1986-05-28 18:36:51 +00:00
|
|
|
}
|
|
|
|
C_cms(tp->tp_size);
|
1986-05-21 18:32:20 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
crash("bad type COMPARE");
|
|
|
|
}
|
1987-05-18 15:57:33 +00:00
|
|
|
if (true_label != NO_LABEL) {
|
1986-08-26 14:33:24 +00:00
|
|
|
compare(expr->nd_symb, true_label);
|
1986-05-21 18:32:20 +00:00
|
|
|
C_bra(false_label);
|
1987-07-21 13:54:33 +00:00
|
|
|
break;
|
1986-05-21 18:32:20 +00:00
|
|
|
}
|
1987-07-21 13:54:33 +00:00
|
|
|
truthvalue(expr->nd_symb);
|
1986-05-21 18:32:20 +00:00
|
|
|
break;
|
1987-07-21 13:54:33 +00:00
|
|
|
|
1986-05-21 18:32:20 +00:00
|
|
|
case IN:
|
1986-05-28 18:36:51 +00:00
|
|
|
/* In this case, evaluate right hand side first! The
|
|
|
|
INN instruction expects the bit number on top of the
|
|
|
|
stack
|
|
|
|
*/
|
1986-08-26 14:33:24 +00:00
|
|
|
CodePExpr(rightop);
|
|
|
|
CodePExpr(leftop);
|
1987-10-28 16:03:56 +00:00
|
|
|
C_loc(rightop->nd_type->set_low);
|
1987-12-02 10:41:38 +00:00
|
|
|
C_sbu(word_size);
|
1986-05-28 18:36:51 +00:00
|
|
|
C_inn(rightop->nd_type->tp_size);
|
1987-05-18 15:57:33 +00:00
|
|
|
if (true_label != NO_LABEL) {
|
1986-06-10 13:18:52 +00:00
|
|
|
C_zne(true_label);
|
|
|
|
C_bra(false_label);
|
|
|
|
}
|
1986-05-21 18:32:20 +00:00
|
|
|
break;
|
1986-10-06 20:36:30 +00:00
|
|
|
case OR:
|
1987-07-30 13:37:39 +00:00
|
|
|
case AND: {
|
1988-10-13 15:43:23 +00:00
|
|
|
label l_maybe = ++text_label, l_end = NO_LABEL;
|
1991-03-14 11:10:40 +00:00
|
|
|
t_desig Des;
|
|
|
|
|
|
|
|
Des = null_desig;
|
1986-08-26 14:33:24 +00:00
|
|
|
|
1987-05-18 15:57:33 +00:00
|
|
|
if (true_label == NO_LABEL) {
|
1986-11-26 16:40:45 +00:00
|
|
|
true_label = ++text_label;
|
|
|
|
false_label = ++text_label;
|
1986-08-26 14:33:24 +00:00
|
|
|
l_end = ++text_label;
|
|
|
|
}
|
|
|
|
|
1986-10-06 20:36:30 +00:00
|
|
|
if (expr->nd_symb == OR) {
|
1991-03-14 11:10:40 +00:00
|
|
|
CodeExpr(leftop, &Des, true_label, l_maybe);
|
1986-10-06 20:36:30 +00:00
|
|
|
}
|
1991-03-14 11:10:40 +00:00
|
|
|
else CodeExpr(leftop, &Des, l_maybe, false_label);
|
1988-01-28 16:15:16 +00:00
|
|
|
def_ilb(l_maybe);
|
1991-03-14 11:10:40 +00:00
|
|
|
Des = null_desig;
|
|
|
|
CodeExpr(rightop, &Des, true_label, false_label);
|
1988-10-13 15:43:23 +00:00
|
|
|
if (l_end != NO_LABEL) {
|
1988-01-28 16:15:16 +00:00
|
|
|
def_ilb(true_label);
|
1987-09-23 16:39:43 +00:00
|
|
|
c_loc(1);
|
1986-05-21 18:32:20 +00:00
|
|
|
C_bra(l_end);
|
1988-01-28 16:15:16 +00:00
|
|
|
def_ilb(false_label);
|
1987-09-23 16:39:43 +00:00
|
|
|
c_loc(0);
|
1988-01-28 16:15:16 +00:00
|
|
|
def_ilb(l_end);
|
1986-05-21 18:32:20 +00:00
|
|
|
}
|
|
|
|
break;
|
1986-08-26 14:33:24 +00:00
|
|
|
}
|
1986-05-21 18:32:20 +00:00
|
|
|
default:
|
1986-08-26 14:33:24 +00:00
|
|
|
crash("(CodeOper) Bad operator %s\n",symbol2str(expr->nd_symb));
|
1986-05-21 18:32:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* compare() serves as an auxiliary function of CodeOper */
|
|
|
|
compare(relop, lbl)
|
|
|
|
int relop;
|
1986-05-23 19:25:21 +00:00
|
|
|
register label lbl;
|
1986-05-21 18:32:20 +00:00
|
|
|
{
|
|
|
|
switch (relop) {
|
|
|
|
case '<':
|
|
|
|
C_zlt(lbl);
|
|
|
|
break;
|
|
|
|
case LESSEQUAL:
|
|
|
|
C_zle(lbl);
|
|
|
|
break;
|
|
|
|
case '>':
|
|
|
|
C_zgt(lbl);
|
|
|
|
break;
|
|
|
|
case GREATEREQUAL:
|
|
|
|
C_zge(lbl);
|
|
|
|
break;
|
|
|
|
case '=':
|
|
|
|
C_zeq(lbl);
|
|
|
|
break;
|
|
|
|
case '#':
|
|
|
|
C_zne(lbl);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
crash("(compare)");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* truthvalue() serves as an auxiliary function of CodeOper */
|
|
|
|
truthvalue(relop)
|
|
|
|
int relop;
|
|
|
|
{
|
|
|
|
switch (relop) {
|
|
|
|
case '<':
|
|
|
|
C_tlt();
|
|
|
|
break;
|
|
|
|
case LESSEQUAL:
|
|
|
|
C_tle();
|
|
|
|
break;
|
|
|
|
case '>':
|
|
|
|
C_tgt();
|
|
|
|
break;
|
|
|
|
case GREATEREQUAL:
|
|
|
|
C_tge();
|
|
|
|
break;
|
|
|
|
case '=':
|
|
|
|
C_teq();
|
|
|
|
break;
|
|
|
|
case '#':
|
|
|
|
C_tne();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
crash("(truthvalue)");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CodeUoper(nd)
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_node *nd;
|
1986-05-21 18:32:20 +00:00
|
|
|
{
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_type *tp = nd->nd_type;
|
1986-05-21 18:32:20 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
CodePExpr(nd->nd_RIGHT);
|
1986-05-21 18:32:20 +00:00
|
|
|
switch(nd->nd_symb) {
|
|
|
|
case NOT:
|
|
|
|
C_teq();
|
|
|
|
break;
|
|
|
|
case '-':
|
|
|
|
switch(tp->tp_fund) {
|
|
|
|
case T_INTEGER:
|
1986-08-26 14:33:24 +00:00
|
|
|
case T_INTORCARD:
|
1986-05-21 18:32:20 +00:00
|
|
|
C_ngi(tp->tp_size);
|
|
|
|
break;
|
|
|
|
case T_REAL:
|
|
|
|
C_ngf(tp->tp_size);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
crash("Bad operand to unary -");
|
|
|
|
}
|
|
|
|
break;
|
1987-07-30 13:37:39 +00:00
|
|
|
case COERCION:
|
1991-03-12 16:52:00 +00:00
|
|
|
CodeCoercion(nd->nd_RIGHT->nd_type, tp);
|
|
|
|
RangeCheck(tp, nd->nd_RIGHT->nd_type);
|
1987-07-30 13:37:39 +00:00
|
|
|
break;
|
1988-04-06 18:14:50 +00:00
|
|
|
case CAST:
|
|
|
|
break;
|
1986-05-21 18:32:20 +00:00
|
|
|
default:
|
|
|
|
crash("Bad unary operator");
|
|
|
|
}
|
|
|
|
}
|
1986-05-23 19:25:21 +00:00
|
|
|
|
|
|
|
CodeSet(nd)
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_node *nd;
|
1986-05-23 19:25:21 +00:00
|
|
|
{
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_type *tp = nd->nd_type;
|
1986-05-23 19:25:21 +00:00
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
nd = nd->nd_NEXT;
|
1986-05-23 19:25:21 +00:00
|
|
|
while (nd) {
|
|
|
|
assert(nd->nd_class == Link && nd->nd_symb == ',');
|
|
|
|
|
1991-03-12 16:52:00 +00:00
|
|
|
if (nd->nd_LEFT) CodeEl(nd->nd_LEFT, tp);
|
|
|
|
nd = nd->nd_RIGHT;
|
1986-05-23 19:25:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CodeEl(nd, tp)
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_node *nd;
|
|
|
|
register t_type *tp;
|
1986-05-23 19:25:21 +00:00
|
|
|
{
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_type *eltype = ElementType(tp);
|
1986-05-23 19:25:21 +00:00
|
|
|
|
|
|
|
if (nd->nd_class == Link && nd->nd_symb == UPTO) {
|
1987-10-28 16:03:56 +00:00
|
|
|
C_loc(tp->set_low);
|
1986-06-06 02:22:09 +00:00
|
|
|
C_loc(tp->tp_size); /* push size */
|
1986-06-26 09:39:36 +00:00
|
|
|
if (eltype->tp_fund == T_SUBRANGE) {
|
|
|
|
C_loc(eltype->sub_ub);
|
1986-06-04 09:01:48 +00:00
|
|
|
}
|
1986-06-26 09:39:36 +00:00
|
|
|
else C_loc((arith) (eltype->enm_ncst - 1));
|
1988-01-28 16:15:16 +00:00
|
|
|
Operands(nd);
|
1988-06-13 10:29:36 +00:00
|
|
|
CAL("LtoUset", 5 * (int) word_size);
|
|
|
|
/* library routine to fill set */
|
1986-05-23 19:25:21 +00:00
|
|
|
}
|
|
|
|
else {
|
1986-05-30 18:48:00 +00:00
|
|
|
CodePExpr(nd);
|
1987-10-28 16:03:56 +00:00
|
|
|
C_loc(tp->set_low);
|
|
|
|
C_sbi(word_size);
|
1986-05-23 19:25:21 +00:00
|
|
|
C_set(tp->tp_size);
|
1986-06-06 02:22:09 +00:00
|
|
|
C_ior(tp->tp_size);
|
1986-05-23 19:25:21 +00:00
|
|
|
}
|
|
|
|
}
|
1986-05-30 18:48:00 +00:00
|
|
|
|
|
|
|
CodePExpr(nd)
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_node *nd;
|
1986-05-30 18:48:00 +00:00
|
|
|
{
|
|
|
|
/* Generate code to push the value of the expression "nd"
|
|
|
|
on the stack.
|
|
|
|
*/
|
1991-03-14 11:10:40 +00:00
|
|
|
t_desig designator;
|
1986-05-30 18:48:00 +00:00
|
|
|
|
1991-03-14 11:10:40 +00:00
|
|
|
designator = null_desig;
|
|
|
|
CodeExpr(nd, &designator, NO_LABEL, NO_LABEL);
|
|
|
|
CodeValue(&designator, nd->nd_type);
|
1986-05-30 18:48:00 +00:00
|
|
|
}
|
|
|
|
|
1988-04-11 18:32:47 +00:00
|
|
|
CodeDAddress(nd, chk_controlvar)
|
1987-09-23 16:39:43 +00:00
|
|
|
t_node *nd;
|
1986-05-30 18:48:00 +00:00
|
|
|
{
|
|
|
|
/* Generate code to push the address of the designator "nd"
|
|
|
|
on the stack.
|
|
|
|
*/
|
|
|
|
|
1991-03-14 11:10:40 +00:00
|
|
|
t_desig designator;
|
1988-04-11 18:32:47 +00:00
|
|
|
int chkptr;
|
1986-05-30 18:48:00 +00:00
|
|
|
|
1991-03-14 11:10:40 +00:00
|
|
|
designator = null_desig;
|
1988-04-11 18:32:47 +00:00
|
|
|
if (chk_controlvar) ChkForFOR(nd);
|
1991-03-14 11:10:40 +00:00
|
|
|
CodeDesig(nd, &designator);
|
|
|
|
chkptr = designator.dsg_kind==DSG_PLOADED ||
|
|
|
|
designator.dsg_kind==DSG_PFIXED;
|
|
|
|
CodeAddress(&designator);
|
1988-04-11 18:32:47 +00:00
|
|
|
|
|
|
|
/* Generate dummy use of pointer, to get possible error message
|
|
|
|
as soon as possible
|
|
|
|
*/
|
|
|
|
if (chkptr && ! options['R']) {
|
|
|
|
C_dup(pointer_size);
|
|
|
|
C_loi((arith) 1);
|
1988-06-13 10:29:36 +00:00
|
|
|
C_asp(word_size);
|
1988-04-11 18:32:47 +00:00
|
|
|
}
|
1986-05-30 18:48:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CodeDStore(nd)
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_node *nd;
|
1986-05-30 18:48:00 +00:00
|
|
|
{
|
|
|
|
/* Generate code to store the expression on the stack into the
|
|
|
|
designator "nd".
|
|
|
|
*/
|
|
|
|
|
1991-03-14 11:10:40 +00:00
|
|
|
t_desig designator;
|
1986-05-30 18:48:00 +00:00
|
|
|
|
1991-03-14 11:10:40 +00:00
|
|
|
designator = null_desig;
|
1987-08-10 13:01:54 +00:00
|
|
|
ChkForFOR(nd);
|
1991-03-14 11:10:40 +00:00
|
|
|
CodeDesig(nd, &designator);
|
|
|
|
CodeStore(&designator, nd->nd_type);
|
1986-05-30 18:48:00 +00:00
|
|
|
}
|
1986-06-04 09:01:48 +00:00
|
|
|
|
1987-05-18 15:57:33 +00:00
|
|
|
DoHIGH(df)
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_def *df;
|
1986-06-04 09:01:48 +00:00
|
|
|
{
|
1986-08-26 14:33:24 +00:00
|
|
|
/* Get the high index of a conformant array, indicated by "nd".
|
|
|
|
The high index is the second field in the descriptor of
|
|
|
|
the array, so it is easily found.
|
|
|
|
*/
|
1986-06-20 14:36:49 +00:00
|
|
|
register arith highoff;
|
1986-06-04 09:01:48 +00:00
|
|
|
|
|
|
|
assert(df->df_kind == D_VARIABLE);
|
1986-08-26 14:33:24 +00:00
|
|
|
assert(IsConformantArray(df->df_type));
|
1986-06-04 09:01:48 +00:00
|
|
|
|
1986-08-26 14:33:24 +00:00
|
|
|
highoff = df->var_off /* base address and descriptor */
|
1988-03-21 16:47:51 +00:00
|
|
|
+ word_size + pointer_size;
|
|
|
|
/* skip base and first field of
|
1986-11-28 11:59:08 +00:00
|
|
|
descriptor
|
|
|
|
*/
|
1986-06-04 09:01:48 +00:00
|
|
|
if (df->df_scope->sc_level < proclevel) {
|
1986-06-10 13:18:52 +00:00
|
|
|
C_lxa((arith) (proclevel - df->df_scope->sc_level));
|
1986-06-04 09:01:48 +00:00
|
|
|
C_lof(highoff);
|
|
|
|
}
|
|
|
|
else C_lol(highoff);
|
|
|
|
}
|
1987-09-23 16:39:43 +00:00
|
|
|
|
|
|
|
#ifdef SQUEEZE
|
|
|
|
c_loc(n)
|
|
|
|
{
|
|
|
|
C_loc((arith) n);
|
|
|
|
}
|
|
|
|
|
|
|
|
c_lae_dlb(l)
|
|
|
|
label l;
|
|
|
|
{
|
|
|
|
C_lae_dlb(l, (arith) 0);
|
|
|
|
}
|
1988-04-11 18:32:47 +00:00
|
|
|
|
1988-06-13 10:29:36 +00:00
|
|
|
CAL(name, ssp)
|
|
|
|
char *name;
|
|
|
|
int ssp;
|
1988-04-11 18:32:47 +00:00
|
|
|
{
|
1988-06-13 10:29:36 +00:00
|
|
|
C_cal(name);
|
|
|
|
C_asp((arith) ssp);
|
1988-04-11 18:32:47 +00:00
|
|
|
}
|
1987-09-23 16:39:43 +00:00
|
|
|
#endif
|