1987-03-10 17:51:10 +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".
|
|
|
|
*/
|
1986-03-10 13:07:55 +00:00
|
|
|
/* $Header$ */
|
|
|
|
/* EXPRESSION-CODE GENERATOR */
|
|
|
|
|
1986-09-24 13:53:16 +00:00
|
|
|
#include "nofloat.h"
|
1986-03-25 16:40:43 +00:00
|
|
|
#include <em.h>
|
1987-07-16 13:27:37 +00:00
|
|
|
#include <em_reg.h>
|
1986-03-10 13:07:55 +00:00
|
|
|
#include "debug.h"
|
|
|
|
#include "nobitfield.h"
|
|
|
|
#include "dataflow.h"
|
|
|
|
#include "arith.h"
|
|
|
|
#include "type.h"
|
|
|
|
#include "idf.h"
|
|
|
|
#include "label.h"
|
|
|
|
#include "code.h"
|
|
|
|
#include "assert.h"
|
|
|
|
#include "def.h"
|
|
|
|
#include "expr.h"
|
|
|
|
#include "sizes.h"
|
|
|
|
#include "Lpars.h"
|
|
|
|
#include "level.h"
|
|
|
|
#include "stack.h"
|
|
|
|
#include "align.h"
|
|
|
|
#include "mes.h"
|
|
|
|
#include "atw.h"
|
|
|
|
|
|
|
|
#define CRASH() crash("EVAL: CRASH at line %u", __LINE__)
|
1986-09-10 10:23:26 +00:00
|
|
|
#define toword(n) ((n) < word_size ? word_size : (n))
|
1986-03-10 13:07:55 +00:00
|
|
|
|
|
|
|
char *symbol2str();
|
1986-03-26 16:58:43 +00:00
|
|
|
char *long2str();
|
1987-07-16 13:27:37 +00:00
|
|
|
arith NewLocal(); /* util.c */
|
|
|
|
#define LocalPtrVar() NewLocal(pointer_size, pointer_align, reg_pointer, 0)
|
1986-03-10 13:07:55 +00:00
|
|
|
|
1986-09-29 14:01:34 +00:00
|
|
|
/* EVAL() is the main expression-tree evaluator, which turns
|
|
|
|
any legal expression tree into EM code. Parameters:
|
1986-03-10 13:07:55 +00:00
|
|
|
|
1986-09-29 14:01:34 +00:00
|
|
|
struct expr *expr
|
|
|
|
pointer to root of the expression tree to be evaluated
|
1986-03-10 13:07:55 +00:00
|
|
|
|
1986-09-29 14:01:34 +00:00
|
|
|
int val
|
|
|
|
indicates whether the resulting expression is to be
|
|
|
|
dereferenced (if val == RVAL and expr->ex_lvalue == 1)
|
|
|
|
or not (val == LVAL). The latter case indicates that
|
|
|
|
the resulting expression is an lvalue expression which
|
|
|
|
should not be dereferenced by EVAL
|
1986-03-10 13:07:55 +00:00
|
|
|
|
1986-09-29 14:01:34 +00:00
|
|
|
int code
|
|
|
|
indicates whether the expression tree must be turned
|
|
|
|
into EM code or not. E.g. the expression statement "12;"
|
|
|
|
delivers the expression "12" to EVAL while this should
|
|
|
|
not result in any EM code
|
1986-03-10 13:07:55 +00:00
|
|
|
|
1986-09-29 14:01:34 +00:00
|
|
|
label false_label, label true_label
|
|
|
|
if the expression is a logical or relational expression
|
|
|
|
and if the loop of the program depends on the resulting
|
|
|
|
value then EVAL generates jumps to the specified program
|
|
|
|
labels, in case they are specified (i.e. are non-zero)
|
1986-03-10 13:07:55 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
EVAL(expr, val, code, true_label, false_label)
|
1986-09-29 14:01:34 +00:00
|
|
|
register struct expr *expr;
|
|
|
|
int val, code;
|
|
|
|
label true_label, false_label;
|
1986-03-10 13:07:55 +00:00
|
|
|
{
|
1986-09-24 13:53:16 +00:00
|
|
|
register int gencode = (code == TRUE);
|
1986-03-10 13:07:55 +00:00
|
|
|
|
1986-09-29 14:01:34 +00:00
|
|
|
switch (expr->ex_class) {
|
1986-03-10 13:07:55 +00:00
|
|
|
case Value: /* just a simple value */
|
|
|
|
if (gencode)
|
|
|
|
load_val(expr, val);
|
|
|
|
break;
|
|
|
|
case String: /* a string constant */
|
|
|
|
if (gencode) {
|
1987-03-25 23:14:43 +00:00
|
|
|
string2pointer(expr);
|
1986-04-02 08:37:17 +00:00
|
|
|
C_lae_dlb(expr->VL_LBL, expr->VL_VALUE);
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
|
|
|
break;
|
1986-09-12 09:16:07 +00:00
|
|
|
#ifndef NOFLOAT
|
1986-03-10 13:07:55 +00:00
|
|
|
case Float: /* a floating constant */
|
|
|
|
if (gencode) {
|
|
|
|
label datlab = data_label();
|
|
|
|
|
1986-03-11 15:21:30 +00:00
|
|
|
C_df_dlb(datlab);
|
1986-03-13 13:27:44 +00:00
|
|
|
C_rom_fcon(expr->FL_VALUE, expr->ex_type->tp_size);
|
1986-03-11 15:21:30 +00:00
|
|
|
C_lae_dlb(datlab, (arith)0);
|
1986-03-10 13:07:55 +00:00
|
|
|
C_loi(expr->ex_type->tp_size);
|
|
|
|
}
|
|
|
|
break;
|
1986-09-12 09:16:07 +00:00
|
|
|
#endif NOFLOAT
|
1986-03-10 13:07:55 +00:00
|
|
|
case Oper: /* compound expression */
|
|
|
|
{
|
1986-09-24 13:53:16 +00:00
|
|
|
int oper = expr->OP_OPER;
|
1986-09-29 14:01:34 +00:00
|
|
|
register struct expr *left = expr->OP_LEFT;
|
|
|
|
register struct expr *right = expr->OP_RIGHT;
|
1986-03-10 13:07:55 +00:00
|
|
|
register struct type *tp = expr->OP_TYPE;
|
|
|
|
|
1987-01-14 09:58:51 +00:00
|
|
|
if (tp->tp_fund == ERRONEOUS || (expr->ex_flags & EX_ERROR)) {
|
|
|
|
/* stop immediately */
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
1987-01-14 09:58:51 +00:00
|
|
|
}
|
1986-12-01 10:00:23 +00:00
|
|
|
if (tp->tp_fund == VOID)
|
|
|
|
gencode = 0;
|
1986-09-29 14:01:34 +00:00
|
|
|
switch (oper) {
|
1986-03-10 13:07:55 +00:00
|
|
|
case '+':
|
|
|
|
/* We have the following possibilities :
|
|
|
|
int + int, pointer + int, pointer + long,
|
|
|
|
long + long, double + double
|
|
|
|
*/
|
1986-12-01 10:00:23 +00:00
|
|
|
EVAL(left, RVAL, gencode, NO_LABEL, NO_LABEL);
|
|
|
|
EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL);
|
1986-03-10 13:07:55 +00:00
|
|
|
if (gencode) {
|
1986-09-29 14:01:34 +00:00
|
|
|
switch (tp->tp_fund) {
|
1986-03-10 13:07:55 +00:00
|
|
|
case INT:
|
|
|
|
case LONG:
|
|
|
|
if (tp->tp_unsigned)
|
|
|
|
C_adu(tp->tp_size);
|
|
|
|
else
|
|
|
|
C_adi(tp->tp_size);
|
|
|
|
break;
|
|
|
|
case POINTER:
|
1987-10-20 09:36:34 +00:00
|
|
|
C_loc(right->ex_type->tp_size);
|
|
|
|
C_loc(pointer_size);
|
1987-11-02 17:59:18 +00:00
|
|
|
C_cuu();
|
1987-10-20 09:36:34 +00:00
|
|
|
C_ads(pointer_size);
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
1986-09-12 09:16:07 +00:00
|
|
|
#ifndef NOFLOAT
|
1986-03-10 13:07:55 +00:00
|
|
|
case DOUBLE:
|
|
|
|
C_adf(tp->tp_size);
|
|
|
|
break;
|
1986-09-12 09:16:07 +00:00
|
|
|
#endif NOFLOAT
|
1986-03-10 13:07:55 +00:00
|
|
|
default:
|
|
|
|
crash("bad type +");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '-':
|
1986-09-29 14:01:34 +00:00
|
|
|
if (left == 0) { /* unary */
|
1986-12-01 10:00:23 +00:00
|
|
|
EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL);
|
1986-03-10 13:07:55 +00:00
|
|
|
if (gencode) {
|
1986-09-29 14:01:34 +00:00
|
|
|
switch (tp->tp_fund) {
|
1986-03-10 13:07:55 +00:00
|
|
|
case INT:
|
|
|
|
case LONG:
|
|
|
|
case POINTER:
|
|
|
|
C_ngi(tp->tp_size);
|
|
|
|
break;
|
1986-09-12 09:16:07 +00:00
|
|
|
#ifndef NOFLOAT
|
|
|
|
case DOUBLE:
|
|
|
|
C_ngf(tp->tp_size);
|
|
|
|
break;
|
|
|
|
#endif NOFLOAT
|
1986-03-10 13:07:55 +00:00
|
|
|
default:
|
|
|
|
CRASH();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
1986-09-29 14:01:34 +00:00
|
|
|
/* else binary; we have the following flavours:
|
1986-03-10 13:07:55 +00:00
|
|
|
int - int, pointer - int, pointer - long,
|
|
|
|
pointer - pointer, long - long, double - double
|
|
|
|
*/
|
1986-12-01 10:00:23 +00:00
|
|
|
EVAL(left, RVAL, gencode, NO_LABEL, NO_LABEL);
|
|
|
|
EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL);
|
1986-03-10 13:07:55 +00:00
|
|
|
if (!gencode)
|
|
|
|
break;
|
1986-09-29 14:01:34 +00:00
|
|
|
switch (tp->tp_fund) {
|
1986-03-10 13:07:55 +00:00
|
|
|
case INT:
|
|
|
|
case LONG:
|
|
|
|
if (tp->tp_unsigned)
|
|
|
|
C_sbu(tp->tp_size);
|
|
|
|
else
|
|
|
|
C_sbi(tp->tp_size);
|
|
|
|
break;
|
|
|
|
case POINTER:
|
1986-09-29 14:01:34 +00:00
|
|
|
if (right->ex_type->tp_fund == POINTER)
|
1986-03-10 13:07:55 +00:00
|
|
|
C_sbs(pointer_size);
|
1986-09-29 14:01:34 +00:00
|
|
|
else {
|
|
|
|
C_ngi(right->ex_type->tp_size);
|
1987-10-20 09:36:34 +00:00
|
|
|
C_loc(right->ex_type->tp_size);
|
|
|
|
C_loc(pointer_size);
|
1987-11-02 17:59:18 +00:00
|
|
|
C_cuu();
|
1987-10-20 09:36:34 +00:00
|
|
|
C_ads(pointer_size);
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
|
|
|
break;
|
1986-09-12 09:16:07 +00:00
|
|
|
#ifndef NOFLOAT
|
1986-03-10 13:07:55 +00:00
|
|
|
case DOUBLE:
|
|
|
|
C_sbf(tp->tp_size);
|
|
|
|
break;
|
1986-09-12 09:16:07 +00:00
|
|
|
#endif NOFLOAT
|
1986-03-10 13:07:55 +00:00
|
|
|
default:
|
|
|
|
crash("bad type -");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '*':
|
1986-09-29 14:01:34 +00:00
|
|
|
if (left == 0) /* unary */
|
1986-12-01 10:00:23 +00:00
|
|
|
EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL);
|
1986-09-29 14:01:34 +00:00
|
|
|
else { /* binary */
|
1986-12-01 10:00:23 +00:00
|
|
|
EVAL(left, RVAL, gencode, NO_LABEL, NO_LABEL);
|
|
|
|
EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL);
|
1986-03-10 13:07:55 +00:00
|
|
|
if (gencode)
|
1986-09-29 14:01:34 +00:00
|
|
|
switch (tp->tp_fund) {
|
1986-03-10 13:07:55 +00:00
|
|
|
case INT:
|
|
|
|
case LONG:
|
|
|
|
case POINTER:
|
|
|
|
if (tp->tp_unsigned)
|
|
|
|
C_mlu(tp->tp_size);
|
|
|
|
else
|
|
|
|
C_mli(tp->tp_size);
|
|
|
|
break;
|
1986-09-12 09:16:07 +00:00
|
|
|
#ifndef NOFLOAT
|
1986-03-10 13:07:55 +00:00
|
|
|
case DOUBLE:
|
|
|
|
C_mlf(double_size);
|
|
|
|
break;
|
1986-09-12 09:16:07 +00:00
|
|
|
#endif NOFLOAT
|
1986-03-10 13:07:55 +00:00
|
|
|
default:
|
|
|
|
crash("bad type *");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '/':
|
1986-12-01 10:00:23 +00:00
|
|
|
EVAL(left, RVAL, gencode, NO_LABEL, NO_LABEL);
|
|
|
|
EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL);
|
1986-03-10 13:07:55 +00:00
|
|
|
if (gencode)
|
1986-09-29 14:01:34 +00:00
|
|
|
switch (tp->tp_fund) {
|
1986-03-10 13:07:55 +00:00
|
|
|
case INT:
|
|
|
|
case LONG:
|
|
|
|
case POINTER:
|
|
|
|
if (tp->tp_unsigned)
|
|
|
|
C_dvu(tp->tp_size);
|
|
|
|
else
|
|
|
|
C_dvi(tp->tp_size);
|
|
|
|
break;
|
1986-09-12 09:16:07 +00:00
|
|
|
#ifndef NOFLOAT
|
1986-03-10 13:07:55 +00:00
|
|
|
case DOUBLE:
|
|
|
|
C_dvf(double_size);
|
|
|
|
break;
|
1986-09-12 09:16:07 +00:00
|
|
|
#endif NOFLOAT
|
1986-03-10 13:07:55 +00:00
|
|
|
default:
|
|
|
|
crash("bad type /");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '%':
|
1986-12-01 10:00:23 +00:00
|
|
|
EVAL(left, RVAL, gencode, NO_LABEL, NO_LABEL);
|
|
|
|
EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL);
|
1986-09-12 09:16:07 +00:00
|
|
|
ASSERT(tp->tp_fund==INT || tp->tp_fund==LONG);
|
1986-09-24 13:53:16 +00:00
|
|
|
if (gencode)
|
1986-09-12 09:16:07 +00:00
|
|
|
if (tp->tp_unsigned)
|
|
|
|
C_rmu(tp->tp_size);
|
1986-03-10 13:07:55 +00:00
|
|
|
else
|
1986-09-12 09:16:07 +00:00
|
|
|
C_rmi(tp->tp_size);
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
|
|
|
case LEFT:
|
1986-12-01 10:00:23 +00:00
|
|
|
EVAL(left, RVAL, gencode, NO_LABEL, NO_LABEL);
|
|
|
|
EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL);
|
1986-03-10 13:07:55 +00:00
|
|
|
if (gencode)
|
|
|
|
if (tp->tp_unsigned)
|
|
|
|
C_slu(tp->tp_size);
|
|
|
|
else
|
|
|
|
C_sli(tp->tp_size);
|
|
|
|
break;
|
|
|
|
case RIGHT:
|
1986-12-01 10:00:23 +00:00
|
|
|
EVAL(left, RVAL, gencode, NO_LABEL, NO_LABEL);
|
|
|
|
EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL);
|
1986-03-10 13:07:55 +00:00
|
|
|
if (gencode)
|
|
|
|
if (tp->tp_unsigned)
|
|
|
|
C_sru(tp->tp_size);
|
|
|
|
else
|
|
|
|
C_sri(tp->tp_size);
|
|
|
|
break;
|
|
|
|
case '<':
|
|
|
|
case LESSEQ:
|
|
|
|
case '>':
|
|
|
|
case GREATEREQ:
|
|
|
|
case EQUAL:
|
|
|
|
case NOTEQUAL:
|
1986-12-01 10:00:23 +00:00
|
|
|
EVAL(left, RVAL, gencode, NO_LABEL, NO_LABEL);
|
|
|
|
EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL);
|
1986-03-10 13:07:55 +00:00
|
|
|
if (gencode) {
|
|
|
|
/* The operands have the same type */
|
1986-09-29 14:01:34 +00:00
|
|
|
arith size = left->ex_type->tp_size;
|
1986-03-17 17:47:04 +00:00
|
|
|
|
1986-09-29 14:01:34 +00:00
|
|
|
switch (tp->tp_fund) {
|
1986-03-10 13:07:55 +00:00
|
|
|
case INT:
|
|
|
|
case LONG:
|
1986-09-29 14:01:34 +00:00
|
|
|
if (left->ex_type->tp_unsigned)
|
1986-03-17 17:47:04 +00:00
|
|
|
C_cmu(size);
|
1986-03-10 13:07:55 +00:00
|
|
|
else
|
1986-03-17 17:47:04 +00:00
|
|
|
C_cmi(size);
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
1986-09-12 09:16:07 +00:00
|
|
|
#ifndef NOFLOAT
|
|
|
|
case FLOAT: /* thought they were converted??? */
|
1986-03-10 13:07:55 +00:00
|
|
|
case DOUBLE:
|
1986-03-17 17:47:04 +00:00
|
|
|
C_cmf(size);
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
1986-09-12 09:16:07 +00:00
|
|
|
#endif NOFLOAT
|
1986-03-10 13:07:55 +00:00
|
|
|
case POINTER:
|
|
|
|
C_cmp();
|
|
|
|
break;
|
|
|
|
case ENUM:
|
1986-03-17 17:47:04 +00:00
|
|
|
C_cmi(size);
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
CRASH();
|
|
|
|
}
|
1986-09-29 14:01:34 +00:00
|
|
|
if (true_label != 0) {
|
1986-03-10 13:07:55 +00:00
|
|
|
compare(oper, true_label);
|
|
|
|
C_bra(false_label);
|
|
|
|
}
|
1986-09-29 14:01:34 +00:00
|
|
|
else {
|
1987-01-14 09:58:51 +00:00
|
|
|
truthvalue(oper);
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '&':
|
|
|
|
case '|':
|
|
|
|
case '^':
|
|
|
|
/* both operands should have type int */
|
1986-12-01 10:00:23 +00:00
|
|
|
EVAL(left, RVAL, gencode, NO_LABEL, NO_LABEL);
|
|
|
|
EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL);
|
1986-03-10 13:07:55 +00:00
|
|
|
if (gencode) {
|
|
|
|
arith size = tp->tp_size;
|
|
|
|
|
|
|
|
if (size < word_size)
|
|
|
|
size = word_size;
|
1986-09-29 14:01:34 +00:00
|
|
|
switch (oper) {
|
1986-03-10 13:07:55 +00:00
|
|
|
case '&':
|
|
|
|
C_and(size);
|
|
|
|
break;
|
|
|
|
case '|':
|
|
|
|
C_ior(size);
|
|
|
|
break;
|
|
|
|
case '^':
|
|
|
|
C_xor(size);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
1986-12-01 10:00:23 +00:00
|
|
|
case '=': {
|
|
|
|
int newcode = tp->tp_size > 0; /* CJ */
|
1986-03-10 13:07:55 +00:00
|
|
|
#ifndef NOBITFIELD
|
1986-09-29 14:01:34 +00:00
|
|
|
if (left->ex_type->tp_fund == FIELD) {
|
1986-12-01 10:00:23 +00:00
|
|
|
eval_field(expr, gencode);
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif NOBITFIELD
|
1986-12-01 10:00:23 +00:00
|
|
|
EVAL(right, RVAL, newcode, NO_LABEL, NO_LABEL);
|
1986-03-10 13:07:55 +00:00
|
|
|
if (gencode)
|
|
|
|
C_dup(ATW(tp->tp_size));
|
1986-09-29 14:01:34 +00:00
|
|
|
if (left->ex_class != Value) {
|
1986-12-01 10:00:23 +00:00
|
|
|
EVAL(left, LVAL, newcode, NO_LABEL, NO_LABEL);
|
|
|
|
if (newcode)
|
|
|
|
store_block(tp->tp_size, tp->tp_align);
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
1986-12-01 10:00:23 +00:00
|
|
|
else if (newcode)
|
1986-09-29 14:01:34 +00:00
|
|
|
store_val(&(left->ex_object.ex_value),
|
|
|
|
left->ex_type);
|
1986-12-01 10:00:23 +00:00
|
|
|
}
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
|
|
|
case PLUSAB:
|
|
|
|
case MINAB:
|
|
|
|
case TIMESAB:
|
|
|
|
case DIVAB:
|
|
|
|
case MODAB:
|
|
|
|
case LEFTAB:
|
|
|
|
case RIGHTAB:
|
|
|
|
case ANDAB:
|
|
|
|
case XORAB:
|
|
|
|
case ORAB:
|
1986-09-29 14:01:34 +00:00
|
|
|
case POSTINCR:
|
|
|
|
case POSTDECR:
|
|
|
|
case PLUSPLUS:
|
|
|
|
case MINMIN:
|
1986-09-10 10:23:26 +00:00
|
|
|
{
|
1987-07-16 13:27:37 +00:00
|
|
|
arith tmp;
|
1986-09-29 14:01:34 +00:00
|
|
|
int compl; /* Complexity of left operand */
|
1986-12-01 10:00:23 +00:00
|
|
|
int newcode = left->ex_type->tp_size > 0; /* CJ */
|
1986-03-10 13:07:55 +00:00
|
|
|
#ifndef NOBITFIELD
|
1986-09-29 14:01:34 +00:00
|
|
|
if (left->ex_type->tp_fund == FIELD) {
|
1986-12-01 10:00:23 +00:00
|
|
|
eval_field(expr, gencode);
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif NOBITFIELD
|
1986-12-01 10:00:23 +00:00
|
|
|
if (newcode && left->ex_class == Value) {
|
1986-09-29 14:01:34 +00:00
|
|
|
compl = 0; /* Value */
|
|
|
|
load_val(left, RVAL);
|
|
|
|
}
|
|
|
|
else
|
1987-01-14 09:58:51 +00:00
|
|
|
if (left->ex_depth == 1 &&
|
|
|
|
!(left->ex_flags & EX_SIDEEFFECTS)) {
|
|
|
|
compl = 1;
|
1986-12-01 10:00:23 +00:00
|
|
|
EVAL(left, RVAL, newcode, NO_LABEL, NO_LABEL);
|
1986-09-10 10:23:26 +00:00
|
|
|
}
|
1986-09-29 14:01:34 +00:00
|
|
|
else {
|
|
|
|
compl = 2; /* otherwise */
|
1986-12-01 10:00:23 +00:00
|
|
|
EVAL(left, LVAL, newcode, NO_LABEL, NO_LABEL);
|
|
|
|
if (newcode) {
|
1987-07-16 13:27:37 +00:00
|
|
|
tmp = LocalPtrVar();
|
1986-12-01 10:00:23 +00:00
|
|
|
C_dup(pointer_size);
|
1987-07-16 13:27:37 +00:00
|
|
|
StoreLocal(tmp, pointer_size);
|
1986-12-01 10:00:23 +00:00
|
|
|
C_loi(left->ex_type->tp_size);
|
|
|
|
}
|
1986-09-10 10:23:26 +00:00
|
|
|
}
|
1986-12-01 10:00:23 +00:00
|
|
|
if (newcode) {
|
|
|
|
if (gencode && (oper == POSTINCR ||
|
|
|
|
oper == POSTDECR))
|
1987-02-23 13:08:54 +00:00
|
|
|
C_dup(ATW(left->ex_type->tp_size));
|
|
|
|
conversion(left->ex_type, tp);
|
1986-12-01 10:00:23 +00:00
|
|
|
}
|
|
|
|
EVAL(right, RVAL, newcode, NO_LABEL, NO_LABEL);
|
|
|
|
if (newcode) {
|
1987-02-23 13:08:54 +00:00
|
|
|
int dupval = gencode && oper != POSTINCR &&
|
|
|
|
oper != POSTDECR;
|
1986-12-01 10:00:23 +00:00
|
|
|
assop(tp, oper);
|
|
|
|
conversion(tp, left->ex_type);
|
1987-02-23 13:08:54 +00:00
|
|
|
if (compl == 0) {
|
|
|
|
store_val(&(left->ex_object.ex_value),
|
|
|
|
left->ex_type);
|
|
|
|
if (dupval) load_val(left, RVAL);
|
|
|
|
}
|
|
|
|
else if (compl == 1) {
|
|
|
|
EVAL(left, LVAL,1, NO_LABEL, NO_LABEL);
|
|
|
|
C_sti(left->ex_type->tp_size);
|
|
|
|
if (dupval) {
|
|
|
|
EVAL(left, LVAL, 1, NO_LABEL,
|
|
|
|
NO_LABEL);
|
|
|
|
C_loi(left->ex_type->tp_size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
1987-07-16 13:27:37 +00:00
|
|
|
LoadLocal(tmp, pointer_size);
|
1987-02-23 13:08:54 +00:00
|
|
|
C_sti(left->ex_type->tp_size);
|
|
|
|
if (dupval) {
|
1987-07-16 13:27:37 +00:00
|
|
|
LoadLocal(tmp, pointer_size);
|
1987-02-23 13:08:54 +00:00
|
|
|
C_loi(left->ex_type->tp_size);
|
|
|
|
}
|
1987-07-16 13:27:37 +00:00
|
|
|
FreeLocal(tmp);
|
1987-02-23 13:08:54 +00:00
|
|
|
}
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
|
|
|
break;
|
1986-09-10 10:23:26 +00:00
|
|
|
}
|
1986-03-10 13:07:55 +00:00
|
|
|
case '(':
|
|
|
|
{
|
1986-09-24 13:53:16 +00:00
|
|
|
register struct expr *ex;
|
1986-03-10 13:07:55 +00:00
|
|
|
arith ParSize = (arith)0;
|
|
|
|
|
1986-09-29 14:01:34 +00:00
|
|
|
if ((ex = right) != NILEXPR) {
|
1986-03-10 13:07:55 +00:00
|
|
|
/* function call with parameters*/
|
1986-09-24 13:53:16 +00:00
|
|
|
while ( ex->ex_class == Oper &&
|
|
|
|
ex->OP_OPER == PARCOMMA
|
|
|
|
) {
|
1986-12-01 10:00:23 +00:00
|
|
|
EVAL(ex->OP_RIGHT, RVAL,
|
|
|
|
ex->ex_type->tp_size > 0,
|
1986-03-10 13:07:55 +00:00
|
|
|
NO_LABEL, NO_LABEL);
|
1986-09-24 13:53:16 +00:00
|
|
|
ParSize += ATW(ex->ex_type->tp_size);
|
|
|
|
ex = ex->OP_LEFT;
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
1986-12-01 10:00:23 +00:00
|
|
|
EVAL(ex, RVAL, ex->ex_type->tp_size > 0,
|
|
|
|
NO_LABEL, NO_LABEL);
|
1986-09-24 13:53:16 +00:00
|
|
|
ParSize += ATW(ex->ex_type->tp_size);
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
1986-09-29 14:01:34 +00:00
|
|
|
if (left->ex_class == Value && left->VL_CLASS == Name) {
|
|
|
|
/* e.g., main() { (*((int (*)())0))(); } */
|
|
|
|
C_cal(left->VL_IDF->id_text);
|
1986-03-10 13:07:55 +00:00
|
|
|
#ifdef DATAFLOW
|
|
|
|
{ extern char options[];
|
|
|
|
if (options['d'])
|
|
|
|
DfaCallFunction(
|
1986-09-29 14:01:34 +00:00
|
|
|
left->VL_IDF->id_text);
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
|
|
|
#endif DATAFLOW
|
|
|
|
}
|
1986-09-29 14:01:34 +00:00
|
|
|
else {
|
|
|
|
EVAL(left, LVAL, TRUE, NO_LABEL, NO_LABEL);
|
1986-03-10 13:07:55 +00:00
|
|
|
C_cai();
|
|
|
|
}
|
|
|
|
/* remove parameters from stack */
|
|
|
|
if (ParSize > (arith)0)
|
|
|
|
C_asp(ParSize);
|
1986-09-24 13:53:16 +00:00
|
|
|
if (gencode) {
|
|
|
|
if (is_struct_or_union(tp->tp_fund)) {
|
|
|
|
C_lfr(pointer_size);
|
1988-02-17 14:29:57 +00:00
|
|
|
load_block(tp->tp_size, (int) word_size);
|
1986-09-24 13:53:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
C_lfr(ATW(tp->tp_size));
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case '.':
|
1986-12-01 10:00:23 +00:00
|
|
|
EVAL(left, LVAL, gencode, NO_LABEL, NO_LABEL);
|
1986-09-29 14:01:34 +00:00
|
|
|
ASSERT(is_cp_cst(right));
|
1986-03-10 13:07:55 +00:00
|
|
|
if (gencode)
|
1986-09-29 14:01:34 +00:00
|
|
|
C_adp(right->VL_VALUE);
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
|
|
|
case ARROW:
|
1986-12-01 10:00:23 +00:00
|
|
|
EVAL(left, RVAL, gencode, NO_LABEL, NO_LABEL);
|
1986-09-29 14:01:34 +00:00
|
|
|
ASSERT(is_cp_cst(right));
|
1986-03-10 13:07:55 +00:00
|
|
|
if (gencode)
|
1986-09-29 14:01:34 +00:00
|
|
|
C_adp(right->VL_VALUE);
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
|
|
|
case ',':
|
1986-09-29 14:01:34 +00:00
|
|
|
EVAL(left, RVAL, FALSE, NO_LABEL, NO_LABEL);
|
1986-12-01 10:00:23 +00:00
|
|
|
EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL);
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
|
|
|
case '~':
|
1986-12-01 10:00:23 +00:00
|
|
|
EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL);
|
1986-03-10 13:07:55 +00:00
|
|
|
if (gencode)
|
|
|
|
C_com(tp->tp_size);
|
|
|
|
break;
|
|
|
|
case '?': /* must be followed by ':' */
|
|
|
|
{
|
|
|
|
label l_true = text_label();
|
|
|
|
label l_false = text_label();
|
|
|
|
label l_end = text_label();
|
|
|
|
|
1986-09-29 14:01:34 +00:00
|
|
|
EVAL(left, RVAL, TRUE, l_true, l_false);
|
1986-03-11 15:21:30 +00:00
|
|
|
C_df_ilb(l_true);
|
1986-12-01 10:00:23 +00:00
|
|
|
EVAL(right->OP_LEFT, RVAL, gencode, NO_LABEL, NO_LABEL);
|
1986-03-10 13:07:55 +00:00
|
|
|
C_bra(l_end);
|
1986-03-11 15:21:30 +00:00
|
|
|
C_df_ilb(l_false);
|
1986-12-01 10:00:23 +00:00
|
|
|
EVAL(right->OP_RIGHT, RVAL, gencode, NO_LABEL, NO_LABEL);
|
1986-03-11 15:21:30 +00:00
|
|
|
C_df_ilb(l_end);
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
|
|
|
}
|
1987-03-25 23:14:43 +00:00
|
|
|
case OR:
|
|
|
|
case AND: {
|
|
|
|
label l_false, l_true, l_maybe;
|
1986-03-10 13:07:55 +00:00
|
|
|
|
1987-03-25 23:14:43 +00:00
|
|
|
l_maybe = text_label();
|
|
|
|
if (true_label) {
|
|
|
|
l_false = false_label;
|
|
|
|
l_true = true_label;
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
1986-09-29 14:01:34 +00:00
|
|
|
else {
|
1987-03-25 23:14:43 +00:00
|
|
|
l_false = text_label();
|
|
|
|
l_true = gencode ? text_label(): l_false;
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
1987-03-25 23:14:43 +00:00
|
|
|
|
|
|
|
EVAL(left, RVAL, TRUE, oper == AND ? l_maybe : l_true,
|
|
|
|
oper == AND ? l_false : l_maybe);
|
|
|
|
C_df_ilb(l_maybe);
|
|
|
|
EVAL(right, RVAL, gencode, l_true, l_false);
|
|
|
|
if (gencode && !true_label) {
|
1986-03-10 13:07:55 +00:00
|
|
|
label l_end = text_label();
|
|
|
|
|
1987-03-25 23:14:43 +00:00
|
|
|
C_df_ilb(l_true);
|
|
|
|
C_loc((arith)1);
|
|
|
|
C_bra(l_end);
|
|
|
|
C_df_ilb(l_false);
|
|
|
|
C_loc((arith)0);
|
|
|
|
C_df_ilb(l_end);
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
1986-09-29 14:01:34 +00:00
|
|
|
else {
|
1987-03-25 23:14:43 +00:00
|
|
|
if (! true_label) C_df_ilb(l_false);
|
|
|
|
}
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '!':
|
1986-09-29 14:01:34 +00:00
|
|
|
if (true_label == 0) {
|
1987-02-09 23:19:42 +00:00
|
|
|
EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL);
|
1986-09-29 14:01:34 +00:00
|
|
|
if (gencode) {
|
1987-02-09 23:19:42 +00:00
|
|
|
C_teq();
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
1986-12-01 10:00:23 +00:00
|
|
|
EVAL(right, RVAL, gencode, false_label,
|
1986-03-10 13:07:55 +00:00
|
|
|
true_label);
|
|
|
|
break;
|
|
|
|
case INT2INT:
|
1986-09-12 09:16:07 +00:00
|
|
|
#ifndef NOFLOAT
|
1986-03-10 13:07:55 +00:00
|
|
|
case INT2FLOAT:
|
|
|
|
case FLOAT2INT:
|
|
|
|
case FLOAT2FLOAT:
|
1986-09-12 09:16:07 +00:00
|
|
|
#endif NOFLOAT
|
1986-12-01 10:00:23 +00:00
|
|
|
EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL);
|
1986-03-10 13:07:55 +00:00
|
|
|
if (gencode)
|
1986-09-29 14:01:34 +00:00
|
|
|
conversion(right->ex_type, left->ex_type);
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
|
|
|
default:
|
1986-03-14 16:15:16 +00:00
|
|
|
crash("(EVAL) bad operator %s\n", symbol2str(oper));
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
|
|
|
/* If the rvalue of the expression is required but
|
|
|
|
only its lvalue is evaluated, its rvalue is
|
|
|
|
loaded by the following statements:
|
|
|
|
*/
|
|
|
|
if (gencode && val == RVAL && expr->ex_lvalue == 1)
|
|
|
|
load_block(expr->ex_type->tp_size,
|
|
|
|
expr->ex_type->tp_align);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
crash("(EVAL) bad expression class");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* compare() serves as an auxiliary function of EVAL */
|
|
|
|
compare(relop, lbl)
|
|
|
|
int relop;
|
|
|
|
label lbl;
|
|
|
|
{
|
1986-09-29 14:01:34 +00:00
|
|
|
switch (relop) {
|
1986-03-10 13:07:55 +00:00
|
|
|
case '<':
|
|
|
|
C_zlt(lbl);
|
|
|
|
break;
|
|
|
|
case LESSEQ:
|
|
|
|
C_zle(lbl);
|
|
|
|
break;
|
|
|
|
case '>':
|
|
|
|
C_zgt(lbl);
|
|
|
|
break;
|
|
|
|
case GREATEREQ:
|
|
|
|
C_zge(lbl);
|
|
|
|
break;
|
|
|
|
case EQUAL:
|
|
|
|
C_zeq(lbl);
|
|
|
|
break;
|
|
|
|
case NOTEQUAL:
|
|
|
|
C_zne(lbl);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
CRASH();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1987-01-14 09:58:51 +00:00
|
|
|
/* truthvalue() serves as an auxiliary function of EVAL */
|
|
|
|
truthvalue(relop)
|
|
|
|
int relop;
|
|
|
|
{
|
|
|
|
switch (relop) {
|
|
|
|
case '<':
|
|
|
|
C_tlt();
|
|
|
|
break;
|
|
|
|
case LESSEQ:
|
|
|
|
C_tle();
|
|
|
|
break;
|
|
|
|
case '>':
|
|
|
|
C_tgt();
|
|
|
|
break;
|
|
|
|
case GREATEREQ:
|
|
|
|
C_tge();
|
|
|
|
break;
|
|
|
|
case EQUAL:
|
|
|
|
C_teq();
|
|
|
|
break;
|
|
|
|
case NOTEQUAL:
|
|
|
|
C_tne();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
CRASH();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1986-03-10 13:07:55 +00:00
|
|
|
/* assop() generates the opcode of an assignment operators op= */
|
|
|
|
assop(type, oper)
|
1986-09-24 13:53:16 +00:00
|
|
|
register struct type *type;
|
1986-03-10 13:07:55 +00:00
|
|
|
int oper;
|
|
|
|
{
|
1986-09-24 13:53:16 +00:00
|
|
|
register arith size;
|
1986-03-10 13:07:55 +00:00
|
|
|
register uns = type->tp_unsigned;
|
|
|
|
|
1986-09-24 13:53:16 +00:00
|
|
|
if ((size = type->tp_size) < word_size)
|
1986-03-10 13:07:55 +00:00
|
|
|
size = word_size;
|
1986-09-29 14:01:34 +00:00
|
|
|
switch (type->tp_fund) {
|
1986-03-10 13:07:55 +00:00
|
|
|
case CHAR:
|
|
|
|
case SHORT:
|
|
|
|
case INT:
|
|
|
|
case LONG:
|
|
|
|
case ENUM:
|
1986-09-29 14:01:34 +00:00
|
|
|
switch (oper) {
|
1986-03-10 13:07:55 +00:00
|
|
|
case PLUSAB:
|
|
|
|
case PLUSPLUS:
|
|
|
|
case POSTINCR:
|
|
|
|
if (uns)
|
|
|
|
C_adu(size);
|
|
|
|
else
|
|
|
|
C_adi(size);
|
|
|
|
break;
|
|
|
|
case MINAB:
|
|
|
|
case MINMIN:
|
|
|
|
case POSTDECR:
|
|
|
|
if (uns)
|
|
|
|
C_sbu(size);
|
|
|
|
else
|
|
|
|
C_sbi(size);
|
|
|
|
break;
|
|
|
|
case TIMESAB:
|
|
|
|
if (uns)
|
|
|
|
C_mlu(size);
|
|
|
|
else
|
|
|
|
C_mli(size);
|
|
|
|
break;
|
|
|
|
case DIVAB:
|
|
|
|
if (uns)
|
|
|
|
C_dvu(size);
|
|
|
|
else
|
|
|
|
C_dvi(size);
|
|
|
|
break;
|
|
|
|
case MODAB:
|
|
|
|
if (uns)
|
|
|
|
C_rmu(size);
|
|
|
|
else
|
|
|
|
C_rmi(size);
|
|
|
|
break;
|
|
|
|
case LEFTAB:
|
|
|
|
if (uns)
|
|
|
|
C_slu(size);
|
|
|
|
else
|
|
|
|
C_sli(size);
|
|
|
|
break;
|
|
|
|
case RIGHTAB:
|
|
|
|
if (uns)
|
|
|
|
C_sru(size);
|
|
|
|
else
|
|
|
|
C_sri(size);
|
|
|
|
break;
|
|
|
|
case ANDAB:
|
|
|
|
C_and(size);
|
|
|
|
break;
|
|
|
|
case XORAB:
|
|
|
|
C_xor(size);
|
|
|
|
break;
|
|
|
|
case ORAB:
|
|
|
|
C_ior(size);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
1986-09-12 09:16:07 +00:00
|
|
|
#ifndef NOFLOAT
|
1986-03-10 13:07:55 +00:00
|
|
|
case FLOAT:
|
|
|
|
case DOUBLE:
|
1986-09-29 14:01:34 +00:00
|
|
|
switch (oper) {
|
1986-03-10 13:07:55 +00:00
|
|
|
case PLUSAB:
|
|
|
|
case PLUSPLUS:
|
|
|
|
case POSTINCR:
|
|
|
|
C_adf(size);
|
|
|
|
break;
|
|
|
|
case MINAB:
|
|
|
|
case MINMIN:
|
|
|
|
case POSTDECR:
|
|
|
|
C_sbf(size);
|
|
|
|
break;
|
|
|
|
case TIMESAB:
|
|
|
|
C_mlf(size);
|
|
|
|
break;
|
|
|
|
case DIVAB:
|
|
|
|
C_dvf(size);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
1986-09-12 09:16:07 +00:00
|
|
|
#endif NOFLOAT
|
1986-03-10 13:07:55 +00:00
|
|
|
case POINTER:
|
|
|
|
if (oper == MINAB || oper == MINMIN || oper == POSTDECR)
|
|
|
|
C_ngi(size);
|
1987-10-20 09:36:34 +00:00
|
|
|
C_loc(size);
|
|
|
|
C_loc(pointer_size);
|
1987-11-02 17:59:18 +00:00
|
|
|
C_cuu();
|
1987-10-20 09:36:34 +00:00
|
|
|
C_ads(pointer_size);
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
|
|
|
case ERRONEOUS:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
crash("(assop) bad type %s\n", symbol2str(type->tp_fund));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* store_val() generates code for a store operation.
|
|
|
|
There are four ways of storing data:
|
|
|
|
- into a global variable
|
|
|
|
- into an automatic local variable
|
|
|
|
- into a local static variable
|
|
|
|
- absolute addressing
|
|
|
|
*/
|
1986-04-02 08:37:17 +00:00
|
|
|
store_val(vl, tp)
|
|
|
|
register struct value *vl;
|
1986-03-10 13:07:55 +00:00
|
|
|
struct type *tp;
|
|
|
|
{
|
|
|
|
arith size = tp->tp_size;
|
|
|
|
int tpalign = tp->tp_align;
|
1986-04-02 08:37:17 +00:00
|
|
|
int al_on_word;
|
|
|
|
register int inword;
|
|
|
|
register int indword;
|
|
|
|
arith val = vl->vl_value;
|
|
|
|
|
1986-09-29 14:01:34 +00:00
|
|
|
if (vl->vl_class == Const) { /* absolute addressing */
|
1986-04-02 08:37:17 +00:00
|
|
|
load_cst(val, pointer_size);
|
|
|
|
store_block(size, tpalign);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
al_on_word = (tpalign % word_align == 0);
|
|
|
|
if (!(inword = (size == word_size && al_on_word)))
|
|
|
|
indword = (size == dword_size && al_on_word);
|
1986-09-29 14:01:34 +00:00
|
|
|
if (vl->vl_class == Name) {
|
1986-04-02 08:37:17 +00:00
|
|
|
register struct idf *id = vl->vl_data.vl_idf;
|
1986-03-10 13:07:55 +00:00
|
|
|
register struct def *df = id->id_def;
|
|
|
|
|
1986-09-29 14:01:34 +00:00
|
|
|
if (df->df_level == L_GLOBAL) {
|
1986-03-10 13:07:55 +00:00
|
|
|
if (inword)
|
1986-04-02 08:37:17 +00:00
|
|
|
C_ste_dnam(id->id_text, val);
|
1986-03-10 13:07:55 +00:00
|
|
|
else
|
|
|
|
if (indword)
|
1986-04-02 08:37:17 +00:00
|
|
|
C_sde_dnam(id->id_text, val);
|
1986-03-10 13:07:55 +00:00
|
|
|
else {
|
1986-04-02 08:37:17 +00:00
|
|
|
C_lae_dnam(id->id_text, val);
|
1986-03-10 13:07:55 +00:00
|
|
|
store_block(size, tpalign);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
1986-04-02 08:37:17 +00:00
|
|
|
ASSERT(df->df_sc != STATIC);
|
1987-07-16 13:27:37 +00:00
|
|
|
if (inword || indword)
|
|
|
|
StoreLocal(df->df_address + val, size);
|
1986-09-29 14:01:34 +00:00
|
|
|
else {
|
1987-07-16 13:27:37 +00:00
|
|
|
AddrLocal(df->df_address + val);
|
1986-03-10 13:07:55 +00:00
|
|
|
store_block(size, tpalign);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1986-04-02 08:37:17 +00:00
|
|
|
else {
|
|
|
|
label dlb = vl->vl_data.vl_lbl;
|
|
|
|
|
|
|
|
ASSERT(vl->vl_class == Label);
|
|
|
|
if (inword)
|
|
|
|
C_ste_dlb(dlb, val);
|
|
|
|
else
|
|
|
|
if (indword)
|
|
|
|
C_sde_dlb(dlb, val);
|
|
|
|
else {
|
|
|
|
C_lae_dlb(dlb, val);
|
|
|
|
store_block(size, tpalign);
|
|
|
|
}
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* load_val() generates code for stacking a certain value (from ex),
|
|
|
|
which can be obtained in one of the following ways:
|
|
|
|
- value from absolute addressed memory
|
|
|
|
- constant value
|
|
|
|
- function result
|
|
|
|
- global variable
|
|
|
|
- static variable
|
|
|
|
- local variable
|
|
|
|
*/
|
1987-02-24 15:41:16 +00:00
|
|
|
load_val(expr, rlval)
|
1986-09-24 13:53:16 +00:00
|
|
|
register struct expr *expr; /* expression containing the value */
|
1987-02-24 15:41:16 +00:00
|
|
|
int rlval; /* generate either LVAL or RVAL */
|
1986-03-10 13:07:55 +00:00
|
|
|
{
|
|
|
|
register struct type *tp = expr->ex_type;
|
1987-02-24 15:41:16 +00:00
|
|
|
int rvalue = (rlval == RVAL && expr->ex_lvalue != 0);
|
1986-09-24 13:53:16 +00:00
|
|
|
arith size = tp->tp_size;
|
|
|
|
int tpalign = tp->tp_align;
|
|
|
|
int al_on_word;
|
1986-04-02 08:37:17 +00:00
|
|
|
register int inword, indword;
|
1987-02-24 15:41:16 +00:00
|
|
|
register arith val = expr->VL_VALUE;
|
1986-03-10 13:07:55 +00:00
|
|
|
|
1986-09-29 14:01:34 +00:00
|
|
|
if (expr->VL_CLASS == Const) {
|
|
|
|
if (rvalue) { /* absolute addressing */
|
1986-04-02 08:37:17 +00:00
|
|
|
load_cst(val, pointer_size);
|
1986-03-10 13:07:55 +00:00
|
|
|
load_block(size, tpalign);
|
|
|
|
}
|
|
|
|
else /* integer, unsigned, long, enum etc */
|
1986-04-02 08:37:17 +00:00
|
|
|
load_cst(val, size);
|
|
|
|
return;
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
1986-04-02 08:37:17 +00:00
|
|
|
if (rvalue) {
|
|
|
|
al_on_word = (tpalign % word_align == 0);
|
|
|
|
if (!(inword = (size == word_size && al_on_word)))
|
|
|
|
indword = (size == dword_size && al_on_word);
|
|
|
|
}
|
|
|
|
if (expr->VL_CLASS == Label) {
|
1986-09-29 14:01:34 +00:00
|
|
|
if (rvalue) {
|
1986-04-02 08:37:17 +00:00
|
|
|
if (inword)
|
|
|
|
C_loe_dlb(expr->VL_LBL, val);
|
1986-03-10 13:07:55 +00:00
|
|
|
else
|
1986-04-02 08:37:17 +00:00
|
|
|
if (indword)
|
|
|
|
C_lde_dlb(expr->VL_LBL, val);
|
1986-03-10 13:07:55 +00:00
|
|
|
else {
|
1986-04-02 08:37:17 +00:00
|
|
|
C_lae_dlb(expr->VL_LBL, val);
|
1986-03-10 13:07:55 +00:00
|
|
|
load_block(size, tpalign);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
1986-09-29 14:01:34 +00:00
|
|
|
else {
|
1986-04-02 08:37:17 +00:00
|
|
|
C_lae_dlb(expr->VL_LBL, (arith)0);
|
|
|
|
C_adp(val);
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
|
|
|
}
|
1986-04-02 08:37:17 +00:00
|
|
|
else {
|
|
|
|
register struct idf *id = expr->VL_IDF;
|
|
|
|
register struct def *df;
|
|
|
|
|
|
|
|
ASSERT(expr->VL_CLASS == Name);
|
|
|
|
if ((df = id->id_def)->df_type->tp_fund == FUNCTION)
|
|
|
|
/* the previous statement tried to catch a function
|
|
|
|
identifier, which may be cast to a pointer to a
|
|
|
|
function.
|
|
|
|
ASSERT(!(rvalue)); ???
|
|
|
|
*/
|
|
|
|
C_lpi(id->id_text);
|
|
|
|
else
|
1986-09-29 14:01:34 +00:00
|
|
|
if (df->df_level == L_GLOBAL) {
|
|
|
|
if (rvalue) {
|
1986-04-02 08:37:17 +00:00
|
|
|
if (inword)
|
|
|
|
C_loe_dnam(id->id_text, val);
|
|
|
|
else
|
|
|
|
if (indword)
|
|
|
|
C_lde_dnam(id->id_text, val);
|
|
|
|
else {
|
|
|
|
C_lae_dnam(id->id_text, val);
|
|
|
|
load_block(size, tpalign);
|
|
|
|
}
|
|
|
|
}
|
1986-09-29 14:01:34 +00:00
|
|
|
else {
|
1986-04-02 08:37:17 +00:00
|
|
|
C_lae_dnam(id->id_text, (arith)0);
|
|
|
|
C_adp(val);
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
|
|
|
}
|
1986-09-29 14:01:34 +00:00
|
|
|
else {
|
1986-04-02 08:37:17 +00:00
|
|
|
ASSERT(df->df_sc != STATIC);
|
1986-09-29 14:01:34 +00:00
|
|
|
if (rvalue) {
|
1987-07-16 13:27:37 +00:00
|
|
|
if (inword || indword)
|
|
|
|
LoadLocal(df->df_address + val, size);
|
1986-04-02 08:37:17 +00:00
|
|
|
else {
|
1987-07-16 13:27:37 +00:00
|
|
|
AddrLocal(df->df_address + val);
|
1986-04-02 08:37:17 +00:00
|
|
|
load_block(size, tpalign);
|
|
|
|
}
|
|
|
|
}
|
1986-09-29 14:01:34 +00:00
|
|
|
else {
|
1987-07-16 13:27:37 +00:00
|
|
|
AddrLocal(df->df_address);
|
1986-04-02 08:37:17 +00:00
|
|
|
C_adp(val);
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
load_cst(val, siz)
|
|
|
|
arith val, siz;
|
|
|
|
{
|
|
|
|
if (siz <= word_size)
|
|
|
|
C_loc(val);
|
|
|
|
else
|
|
|
|
if (siz == dword_size)
|
|
|
|
C_ldc(val);
|
|
|
|
else {
|
|
|
|
label datlab;
|
|
|
|
|
1986-03-11 15:21:30 +00:00
|
|
|
C_df_dlb(datlab = data_label());
|
1986-03-26 16:58:43 +00:00
|
|
|
C_rom_icon(long2str((long)val, 10), siz);
|
1986-03-11 15:21:30 +00:00
|
|
|
C_lae_dlb(datlab, (arith)0);
|
1986-03-10 13:07:55 +00:00
|
|
|
C_loi(siz);
|
|
|
|
}
|
|
|
|
}
|