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-16 17:15:36 +00:00
|
|
|
/* D E S I G N A T O R E V A L U A T I O N */
|
|
|
|
|
1987-04-29 10:22:07 +00:00
|
|
|
/* $Header$ */
|
|
|
|
|
1986-05-16 17:15:36 +00:00
|
|
|
/* Code generation for designators.
|
|
|
|
This file contains some routines that generate code common to address
|
|
|
|
as well as value computations, and leave a description in a "desig"
|
|
|
|
structure. It also contains routines to load an address, load a value
|
|
|
|
or perform a store.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
#include <em_arith.h>
|
|
|
|
#include <em_label.h>
|
1986-07-08 14:59:02 +00:00
|
|
|
#include <em_code.h>
|
1986-05-16 17:15:36 +00:00
|
|
|
#include <assert.h>
|
1987-07-30 13:37:39 +00:00
|
|
|
#include <alloc.h>
|
1986-05-16 17:15:36 +00:00
|
|
|
|
|
|
|
#include "type.h"
|
1987-07-30 13:37:39 +00:00
|
|
|
#include "LLlex.h"
|
1986-05-16 17:15:36 +00:00
|
|
|
#include "def.h"
|
|
|
|
#include "scope.h"
|
|
|
|
#include "desig.h"
|
|
|
|
#include "node.h"
|
1987-08-10 13:01:54 +00:00
|
|
|
#include "warning.h"
|
1987-09-23 16:39:43 +00:00
|
|
|
#include "walk.h"
|
1988-03-22 17:54:01 +00:00
|
|
|
#include "squeeze.h"
|
1986-05-16 17:15:36 +00:00
|
|
|
|
1986-05-21 18:32:20 +00:00
|
|
|
extern int proclevel;
|
1988-03-21 17:22:26 +00:00
|
|
|
extern arith NewPtr();
|
|
|
|
extern char options[];
|
1986-05-21 18:32:20 +00:00
|
|
|
|
1987-05-21 09:37:28 +00:00
|
|
|
int
|
1987-07-21 13:54:33 +00:00
|
|
|
WordOrDouble(ds, size)
|
1988-03-21 17:22:26 +00:00
|
|
|
t_desig *ds;
|
1987-05-27 10:16:03 +00:00
|
|
|
arith size;
|
1987-05-21 09:37:28 +00:00
|
|
|
{
|
1988-03-21 17:22:26 +00:00
|
|
|
/* Check if designator is suitable for word or double-word
|
|
|
|
operation
|
|
|
|
*/
|
|
|
|
if ((int) (ds->dsg_offset) % word_align == 0) {
|
1987-09-23 16:39:43 +00:00
|
|
|
if (size == word_size) return 1;
|
|
|
|
if (size == dword_size) return 2;
|
|
|
|
}
|
|
|
|
return 0;
|
1987-07-21 13:54:33 +00:00
|
|
|
}
|
1987-05-21 09:37:28 +00:00
|
|
|
|
1988-03-22 17:54:01 +00:00
|
|
|
LOL(offset, size)
|
|
|
|
arith offset, size;
|
|
|
|
{
|
|
|
|
if (size == word_size) {
|
|
|
|
C_lol(offset);
|
|
|
|
}
|
|
|
|
else if (size == dword_size) {
|
|
|
|
C_ldl(offset);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
C_lal(offset);
|
|
|
|
C_loi(size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
STL(offset, size)
|
|
|
|
arith offset, size;
|
|
|
|
{
|
|
|
|
if (size == word_size) {
|
|
|
|
C_stl(offset);
|
|
|
|
}
|
|
|
|
else if (size == dword_size) {
|
|
|
|
C_sdl(offset);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
C_lal(offset);
|
|
|
|
C_sti(size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1987-07-21 13:54:33 +00:00
|
|
|
int
|
|
|
|
DoLoad(ds, size)
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_desig *ds;
|
1987-07-21 13:54:33 +00:00
|
|
|
arith size;
|
|
|
|
{
|
1988-03-21 17:22:26 +00:00
|
|
|
/* Try to load designator with word or double-word operation.
|
|
|
|
Return 0 if not done
|
|
|
|
*/
|
1987-09-23 16:39:43 +00:00
|
|
|
switch (WordOrDouble(ds, size)) {
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
case 1:
|
|
|
|
if (ds->dsg_name) {
|
1987-07-21 13:54:33 +00:00
|
|
|
C_loe_dnam(ds->dsg_name, ds->dsg_offset);
|
|
|
|
}
|
1987-09-23 16:39:43 +00:00
|
|
|
else C_lol(ds->dsg_offset);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (ds->dsg_name) {
|
|
|
|
C_lde_dnam(ds->dsg_name, ds->dsg_offset);
|
1987-07-21 13:54:33 +00:00
|
|
|
}
|
|
|
|
else C_ldl(ds->dsg_offset);
|
1987-09-23 16:39:43 +00:00
|
|
|
break;
|
1987-07-21 13:54:33 +00:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
1987-05-21 09:37:28 +00:00
|
|
|
|
1987-07-21 13:54:33 +00:00
|
|
|
int
|
|
|
|
DoStore(ds, size)
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_desig *ds;
|
1987-07-21 13:54:33 +00:00
|
|
|
arith size;
|
|
|
|
{
|
1988-03-21 17:22:26 +00:00
|
|
|
/* Try to store designator with word or double-word operation.
|
|
|
|
Return 0 if not done
|
|
|
|
*/
|
1987-09-23 16:39:43 +00:00
|
|
|
switch (WordOrDouble(ds, size)) {
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
case 1:
|
|
|
|
if (ds->dsg_name) {
|
1987-07-21 13:54:33 +00:00
|
|
|
C_ste_dnam(ds->dsg_name, ds->dsg_offset);
|
|
|
|
}
|
1987-09-23 16:39:43 +00:00
|
|
|
else C_stl(ds->dsg_offset);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (ds->dsg_name) {
|
|
|
|
C_sde_dnam(ds->dsg_name, ds->dsg_offset);
|
1987-07-21 13:54:33 +00:00
|
|
|
}
|
|
|
|
else C_sdl(ds->dsg_offset);
|
1987-09-23 16:39:43 +00:00
|
|
|
break;
|
1987-05-21 09:37:28 +00:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1988-03-21 17:22:26 +00:00
|
|
|
/* Return 1 if the type indicated by tp has a size that is a
|
|
|
|
multiple of the word_size and is also word_aligned
|
1986-11-28 11:59:08 +00:00
|
|
|
*/
|
1988-03-22 17:54:01 +00:00
|
|
|
#define word_multiple(tp) \
|
|
|
|
( (int)(tp->tp_size) % (int)word_size == 0 && \
|
|
|
|
tp->tp_align >= word_align)
|
1986-11-28 11:59:08 +00:00
|
|
|
|
1988-03-21 17:22:26 +00:00
|
|
|
/* Return 1 if the type indicated by tp has a size that is a proper
|
|
|
|
dividor of the word_size, and has alignment >= size or
|
|
|
|
alignment >= word_align
|
|
|
|
*/
|
1988-03-22 17:54:01 +00:00
|
|
|
#define word_dividor(tp) \
|
|
|
|
( tp->tp_size < word_size && \
|
|
|
|
(int)word_size % (int)(tp->tp_size) == 0 && \
|
|
|
|
(tp->tp_align >= word_align || \
|
|
|
|
tp->tp_align >= (int)(tp->tp_size)))
|
1986-11-28 11:59:08 +00:00
|
|
|
|
1988-03-21 17:22:26 +00:00
|
|
|
#define USE_LOI_STI 0
|
|
|
|
#define USE_LOS_STS 1
|
|
|
|
#define USE_LOAD_STORE 2
|
|
|
|
#define USE_BLM 3 /* like USE_LOI_STI, but more restricted:
|
|
|
|
multiple of word_size only
|
|
|
|
*/
|
|
|
|
|
|
|
|
STATIC int
|
1988-03-22 17:54:01 +00:00
|
|
|
suitable_move(tp)
|
1988-03-21 17:22:26 +00:00
|
|
|
register t_type *tp;
|
|
|
|
{
|
|
|
|
/* Find out how to load or store the value indicated by "ds".
|
|
|
|
There are three ways:
|
1988-03-22 17:54:01 +00:00
|
|
|
- suitable for BLM/LOI/STI
|
|
|
|
- suitable for LOI/STI
|
|
|
|
- suitable for LOS/STS/BLS
|
|
|
|
- suitable for calls to load/store/blockmove
|
1988-03-21 17:22:26 +00:00
|
|
|
*/
|
1986-11-28 11:59:08 +00:00
|
|
|
|
1988-03-21 17:22:26 +00:00
|
|
|
if (! word_multiple(tp)) {
|
|
|
|
if (word_dividor(tp)) return USE_LOI_STI;
|
|
|
|
return USE_LOAD_STORE;
|
|
|
|
}
|
|
|
|
if (! fit(tp->tp_size, (int) word_size)) return USE_LOS_STS;
|
|
|
|
return USE_BLM;
|
1986-11-28 11:59:08 +00:00
|
|
|
}
|
|
|
|
|
1987-06-23 17:12:25 +00:00
|
|
|
CodeValue(ds, tp)
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_desig *ds;
|
|
|
|
register t_type *tp;
|
1986-05-16 17:15:36 +00:00
|
|
|
{
|
|
|
|
/* Generate code to load the value of the designator described
|
1988-03-21 17:22:26 +00:00
|
|
|
in "ds".
|
1986-05-16 17:15:36 +00:00
|
|
|
*/
|
1987-07-16 19:51:40 +00:00
|
|
|
arith sz;
|
1986-05-16 17:15:36 +00:00
|
|
|
|
|
|
|
switch(ds->dsg_kind) {
|
|
|
|
case DSG_LOADED:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DSG_FIXED:
|
1987-07-21 13:54:33 +00:00
|
|
|
if (DoLoad(ds, tp->tp_size)) break;
|
1986-05-16 17:15:36 +00:00
|
|
|
/* Fall through */
|
|
|
|
case DSG_PLOADED:
|
|
|
|
case DSG_PFIXED:
|
1988-03-22 17:54:01 +00:00
|
|
|
switch (suitable_move(tp)) {
|
1988-03-21 17:22:26 +00:00
|
|
|
case USE_BLM:
|
|
|
|
case USE_LOI_STI:
|
1988-03-22 17:54:01 +00:00
|
|
|
#ifndef SQUEEZE
|
1986-11-28 11:59:08 +00:00
|
|
|
CodeAddress(ds);
|
1987-06-23 17:12:25 +00:00
|
|
|
C_loi(tp->tp_size);
|
1986-11-28 11:59:08 +00:00
|
|
|
break;
|
1988-03-22 17:54:01 +00:00
|
|
|
#endif
|
1988-03-21 17:22:26 +00:00
|
|
|
case USE_LOS_STS:
|
|
|
|
CodeAddress(ds);
|
|
|
|
CodeConst(tp->tp_size, (int)pointer_size);
|
|
|
|
C_los(pointer_size);
|
|
|
|
break;
|
|
|
|
case USE_LOAD_STORE:
|
|
|
|
sz = WA(tp->tp_size);
|
1988-03-23 17:44:25 +00:00
|
|
|
#ifndef SQUEEZE
|
|
|
|
if (ds->dsg_kind != DSG_PFIXED)
|
|
|
|
#endif
|
|
|
|
{
|
1988-03-21 17:22:26 +00:00
|
|
|
arith tmp = NewPtr();
|
|
|
|
|
|
|
|
CodeAddress(ds);
|
1988-03-22 17:54:01 +00:00
|
|
|
STL(tmp, pointer_size);
|
1988-03-21 17:22:26 +00:00
|
|
|
CodeConst(-sz, (int) pointer_size);
|
|
|
|
C_ass(pointer_size);
|
1988-03-22 17:54:01 +00:00
|
|
|
LOL(tmp, pointer_size);
|
1988-03-21 17:22:26 +00:00
|
|
|
FreePtr(tmp);
|
|
|
|
}
|
1988-03-23 17:44:25 +00:00
|
|
|
#ifndef SQUEEZE
|
1988-03-21 17:22:26 +00:00
|
|
|
else {
|
|
|
|
CodeConst(-sz, (int) pointer_size);
|
|
|
|
C_ass(pointer_size);
|
|
|
|
}
|
1988-03-23 17:44:25 +00:00
|
|
|
#endif
|
1988-03-21 17:22:26 +00:00
|
|
|
CodeAddress(ds);
|
|
|
|
CodeConst(tp->tp_size, (int) pointer_size);
|
1988-03-23 17:44:25 +00:00
|
|
|
C_cal("load");
|
1988-03-21 17:22:26 +00:00
|
|
|
C_asp(pointer_size + pointer_size);
|
|
|
|
break;
|
1986-11-28 11:59:08 +00:00
|
|
|
}
|
1986-05-16 17:15:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DSG_INDEXED:
|
|
|
|
C_lar(word_size);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
1986-05-21 18:32:20 +00:00
|
|
|
crash("(CodeValue)");
|
1986-05-16 17:15:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ds->dsg_kind = DSG_LOADED;
|
|
|
|
}
|
|
|
|
|
1987-08-10 13:01:54 +00:00
|
|
|
ChkForFOR(nd)
|
1988-03-22 17:54:01 +00:00
|
|
|
register t_node *nd;
|
1987-08-10 13:01:54 +00:00
|
|
|
{
|
1988-03-21 17:22:26 +00:00
|
|
|
/* Check for an assignment to a FOR-loop control variable
|
|
|
|
*/
|
1987-08-10 13:01:54 +00:00
|
|
|
if (nd->nd_class == Def) {
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_def *df = nd->nd_def;
|
1987-08-10 13:01:54 +00:00
|
|
|
|
|
|
|
if (df->df_flags & D_FORLOOP) {
|
|
|
|
node_warning(nd,
|
|
|
|
W_ORDINARY,
|
|
|
|
"assignment to FOR-loop control variable");
|
|
|
|
df->df_flags &= ~D_FORLOOP;
|
1988-03-21 17:22:26 +00:00
|
|
|
/* only procude warning once */
|
1987-08-10 13:01:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1987-06-23 17:12:25 +00:00
|
|
|
CodeStore(ds, tp)
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_desig *ds;
|
|
|
|
register t_type *tp;
|
1986-05-23 09:46:31 +00:00
|
|
|
{
|
|
|
|
/* Generate code to store the value on the stack in the designator
|
|
|
|
described in "ds"
|
|
|
|
*/
|
1987-08-10 13:01:54 +00:00
|
|
|
|
1986-05-23 09:46:31 +00:00
|
|
|
switch(ds->dsg_kind) {
|
|
|
|
case DSG_FIXED:
|
1987-07-21 13:54:33 +00:00
|
|
|
if (DoStore(ds, tp->tp_size)) break;
|
1986-05-23 09:46:31 +00:00
|
|
|
/* Fall through */
|
|
|
|
case DSG_PLOADED:
|
|
|
|
case DSG_PFIXED:
|
1988-03-22 17:54:01 +00:00
|
|
|
CodeAddress(ds);
|
|
|
|
switch (suitable_move(tp)) {
|
1988-03-21 17:22:26 +00:00
|
|
|
case USE_BLM:
|
|
|
|
case USE_LOI_STI:
|
1988-03-22 17:54:01 +00:00
|
|
|
#ifndef SQUEEZE
|
1987-06-23 17:12:25 +00:00
|
|
|
C_sti(tp->tp_size);
|
1986-11-28 11:59:08 +00:00
|
|
|
break;
|
1988-03-22 17:54:01 +00:00
|
|
|
#endif
|
1988-03-21 17:22:26 +00:00
|
|
|
case USE_LOS_STS:
|
|
|
|
CodeConst(tp->tp_size, (int) pointer_size);
|
|
|
|
C_sts(pointer_size);
|
|
|
|
break;
|
|
|
|
case USE_LOAD_STORE:
|
|
|
|
CodeConst(tp->tp_size, (int) pointer_size);
|
1988-03-23 17:44:25 +00:00
|
|
|
C_cal("store");
|
1988-03-21 17:22:26 +00:00
|
|
|
CodeConst(pointer_size + pointer_size + WA(tp->tp_size),
|
|
|
|
(int) pointer_size);
|
|
|
|
C_ass(pointer_size);
|
|
|
|
break;
|
1986-11-28 11:59:08 +00:00
|
|
|
}
|
1986-05-23 09:46:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DSG_INDEXED:
|
|
|
|
C_sar(word_size);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
crash("(CodeStore)");
|
|
|
|
}
|
|
|
|
|
|
|
|
ds->dsg_kind = DSG_INIT;
|
|
|
|
}
|
|
|
|
|
1986-11-28 11:59:08 +00:00
|
|
|
CodeCopy(lhs, rhs, sz, psize)
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_desig *lhs, *rhs;
|
1986-11-28 11:59:08 +00:00
|
|
|
arith sz, *psize;
|
|
|
|
{
|
1988-03-21 17:22:26 +00:00
|
|
|
/* Do part of a copy, which is assumed to be "reasonable",
|
|
|
|
so that it can be done with LOI/STI or BLM.
|
|
|
|
*/
|
1987-09-23 16:39:43 +00:00
|
|
|
t_desig l, r;
|
1986-11-28 11:59:08 +00:00
|
|
|
|
|
|
|
l = *lhs; r = *rhs;
|
|
|
|
*psize -= sz;
|
|
|
|
lhs->dsg_offset += sz;
|
|
|
|
rhs->dsg_offset += sz;
|
|
|
|
CodeAddress(&r);
|
1988-03-21 17:22:26 +00:00
|
|
|
if (sz <= dword_size) {
|
|
|
|
C_loi(sz);
|
|
|
|
CodeAddress(&l);
|
|
|
|
C_sti(sz);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
CodeAddress(&l);
|
|
|
|
C_blm(sz);
|
|
|
|
}
|
1986-11-28 11:59:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CodeMove(rhs, left, rtp)
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_desig *rhs;
|
|
|
|
register t_node *left;
|
|
|
|
t_type *rtp;
|
1986-11-28 11:59:08 +00:00
|
|
|
{
|
|
|
|
/* Generate code for an assignment. Testing of type
|
|
|
|
compatibility and the like is already done.
|
|
|
|
Go through some (considerable) trouble to see if a BLM can be
|
|
|
|
generated.
|
|
|
|
*/
|
1988-03-21 17:22:26 +00:00
|
|
|
register t_desig *lhs = new_desig();
|
|
|
|
register t_type *tp = left->nd_type;
|
1988-03-22 17:54:01 +00:00
|
|
|
int loadedflag = 0;
|
1986-11-28 11:59:08 +00:00
|
|
|
|
1987-08-10 13:01:54 +00:00
|
|
|
ChkForFOR(left);
|
1986-11-28 11:59:08 +00:00
|
|
|
switch(rhs->dsg_kind) {
|
|
|
|
case DSG_LOADED:
|
|
|
|
CodeDesig(left, lhs);
|
|
|
|
if (rtp->tp_fund == T_STRING) {
|
1988-03-21 17:22:26 +00:00
|
|
|
/* size of a string literal fits in an
|
|
|
|
int of size word_size
|
|
|
|
*/
|
1987-05-27 10:16:03 +00:00
|
|
|
CodeAddress(lhs);
|
1986-11-28 11:59:08 +00:00
|
|
|
C_loc(rtp->tp_size);
|
|
|
|
C_loc(tp->tp_size);
|
1988-03-23 17:44:25 +00:00
|
|
|
C_cal("StringAssign");
|
1988-03-21 17:22:26 +00:00
|
|
|
C_asp(pointer_size + pointer_size + dword_size);
|
1987-07-30 13:37:39 +00:00
|
|
|
break;
|
1986-11-28 11:59:08 +00:00
|
|
|
}
|
1987-06-23 17:12:25 +00:00
|
|
|
CodeStore(lhs, tp);
|
1987-07-30 13:37:39 +00:00
|
|
|
break;
|
1986-11-28 11:59:08 +00:00
|
|
|
case DSG_FIXED:
|
1988-03-22 17:54:01 +00:00
|
|
|
CodeDesig(left, lhs);
|
1986-11-28 11:59:08 +00:00
|
|
|
if (lhs->dsg_kind == DSG_FIXED &&
|
1988-03-21 17:22:26 +00:00
|
|
|
fit(tp->tp_size, (int) word_size) &&
|
1988-03-22 17:54:01 +00:00
|
|
|
(int) (lhs->dsg_offset) % word_align ==
|
|
|
|
(int) (rhs->dsg_offset) % word_align) {
|
|
|
|
register int sz = 1;
|
1986-11-28 11:59:08 +00:00
|
|
|
arith size = tp->tp_size;
|
|
|
|
|
1988-03-22 17:54:01 +00:00
|
|
|
while (size && sz < word_align) {
|
1986-11-28 11:59:08 +00:00
|
|
|
/* First copy up to word-aligned
|
|
|
|
boundaries
|
|
|
|
*/
|
1988-03-22 17:54:01 +00:00
|
|
|
if (!((int)(lhs->dsg_offset)%(sz+sz))) {
|
|
|
|
sz += sz;
|
1986-11-28 11:59:08 +00:00
|
|
|
}
|
1988-03-22 17:54:01 +00:00
|
|
|
else CodeCopy(lhs, rhs, (arith) sz, &size);
|
1986-11-28 11:59:08 +00:00
|
|
|
}
|
1988-03-22 17:54:01 +00:00
|
|
|
/* Now copy the bulk
|
|
|
|
*/
|
|
|
|
sz = (int) size % (int) word_size;
|
|
|
|
size -= sz;
|
|
|
|
CodeCopy(lhs, rhs, size, &size);
|
|
|
|
size = sz;
|
1986-11-28 11:59:08 +00:00
|
|
|
sz = word_size;
|
1988-03-22 17:54:01 +00:00
|
|
|
while (size) {
|
1986-11-28 11:59:08 +00:00
|
|
|
/* And then copy remaining parts
|
|
|
|
*/
|
1988-03-22 17:54:01 +00:00
|
|
|
sz >>= 1;
|
|
|
|
if (size >= sz) {
|
1987-07-13 11:49:32 +00:00
|
|
|
CodeCopy(lhs, rhs, (arith) sz, &size);
|
1986-11-28 11:59:08 +00:00
|
|
|
}
|
|
|
|
}
|
1987-07-30 13:37:39 +00:00
|
|
|
break;
|
1986-11-28 11:59:08 +00:00
|
|
|
}
|
1988-03-22 17:54:01 +00:00
|
|
|
CodeAddress(lhs);
|
|
|
|
loadedflag = 1;
|
1988-03-21 17:22:26 +00:00
|
|
|
/* Fall through */
|
|
|
|
case DSG_PLOADED:
|
|
|
|
case DSG_PFIXED:
|
1988-03-22 17:54:01 +00:00
|
|
|
assert(! loadedflag || rhs->dsg_kind == DSG_FIXED);
|
1988-03-21 17:22:26 +00:00
|
|
|
CodeAddress(rhs);
|
1988-03-22 17:54:01 +00:00
|
|
|
if (loadedflag) {
|
|
|
|
C_exg(pointer_size);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
CodeDesig(left, lhs);
|
|
|
|
CodeAddress(lhs);
|
|
|
|
}
|
|
|
|
switch (suitable_move(tp)) {
|
1988-03-21 17:22:26 +00:00
|
|
|
case USE_BLM:
|
1988-03-22 17:54:01 +00:00
|
|
|
#ifndef SQUEEZE
|
1986-11-28 11:59:08 +00:00
|
|
|
C_blm(tp->tp_size);
|
1987-07-30 13:37:39 +00:00
|
|
|
break;
|
1988-03-22 17:54:01 +00:00
|
|
|
#endif
|
1988-03-21 17:22:26 +00:00
|
|
|
case USE_LOS_STS:
|
|
|
|
CodeConst(tp->tp_size, (int) pointer_size);
|
|
|
|
C_bls(pointer_size);
|
|
|
|
break;
|
|
|
|
case USE_LOAD_STORE:
|
|
|
|
case USE_LOI_STI:
|
|
|
|
CodeConst(tp->tp_size, (int) pointer_size);
|
1988-03-23 17:44:25 +00:00
|
|
|
C_cal("blockmove");
|
1988-03-21 17:22:26 +00:00
|
|
|
C_asp(3 * pointer_size);
|
1987-07-30 13:37:39 +00:00
|
|
|
break;
|
1986-11-28 11:59:08 +00:00
|
|
|
}
|
1988-03-21 17:22:26 +00:00
|
|
|
break;
|
1986-11-28 11:59:08 +00:00
|
|
|
default:
|
|
|
|
crash("CodeMove");
|
|
|
|
}
|
1987-07-30 13:37:39 +00:00
|
|
|
free_desig(lhs);
|
1986-11-28 11:59:08 +00:00
|
|
|
}
|
|
|
|
|
1986-05-16 17:15:36 +00:00
|
|
|
CodeAddress(ds)
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_desig *ds;
|
1986-05-16 17:15:36 +00:00
|
|
|
{
|
|
|
|
/* Generate code to load the address of the designator described
|
|
|
|
in "ds"
|
|
|
|
*/
|
|
|
|
|
|
|
|
switch(ds->dsg_kind) {
|
|
|
|
case DSG_PLOADED:
|
|
|
|
if (ds->dsg_offset) {
|
|
|
|
C_adp(ds->dsg_offset);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DSG_FIXED:
|
|
|
|
if (ds->dsg_name) {
|
|
|
|
C_lae_dnam(ds->dsg_name, ds->dsg_offset);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
C_lal(ds->dsg_offset);
|
1987-05-27 10:16:03 +00:00
|
|
|
if (ds->dsg_def) ds->dsg_def->df_flags |= D_NOREG;
|
1986-05-16 17:15:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DSG_PFIXED:
|
1988-03-21 17:22:26 +00:00
|
|
|
if (! DoLoad(ds, pointer_size)) {
|
|
|
|
assert(0);
|
|
|
|
}
|
1986-05-16 17:15:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DSG_INDEXED:
|
|
|
|
C_aar(word_size);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
1986-05-21 18:32:20 +00:00
|
|
|
crash("(CodeAddress)");
|
1986-05-16 17:15:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ds->dsg_offset = 0;
|
|
|
|
ds->dsg_kind = DSG_PLOADED;
|
|
|
|
}
|
|
|
|
|
|
|
|
CodeFieldDesig(df, ds)
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_def *df;
|
|
|
|
register t_desig *ds;
|
1986-05-16 17:15:36 +00:00
|
|
|
{
|
|
|
|
/* Generate code for a field designator. Only the code common for
|
|
|
|
address as well as value computation is generated, and the
|
|
|
|
resulting information on where to find the designator is placed
|
|
|
|
in "ds". "df" indicates the definition of the field.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (ds->dsg_kind == DSG_INIT) {
|
|
|
|
/* In a WITH statement. We must find the designator in the
|
|
|
|
WITH statement, and act as if the field is a selection
|
|
|
|
of this designator.
|
|
|
|
So, first find the right WITH statement, which is the
|
1986-09-25 19:39:06 +00:00
|
|
|
first one of the proper record type, which is
|
|
|
|
recognized by its scope indication.
|
1986-05-16 17:15:36 +00:00
|
|
|
*/
|
1986-09-25 19:39:06 +00:00
|
|
|
register struct withdesig *wds = WithDesigs;
|
|
|
|
|
1986-05-16 17:15:36 +00:00
|
|
|
assert(wds != 0);
|
|
|
|
|
|
|
|
while (wds->w_scope != df->df_scope) {
|
|
|
|
wds = wds->w_next;
|
|
|
|
assert(wds != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Found it. Now, act like it was a selection.
|
|
|
|
*/
|
|
|
|
*ds = wds->w_desig;
|
1986-05-23 09:46:31 +00:00
|
|
|
assert(ds->dsg_kind == DSG_PFIXED);
|
1986-05-16 17:15:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch(ds->dsg_kind) {
|
|
|
|
case DSG_PLOADED:
|
|
|
|
case DSG_FIXED:
|
|
|
|
ds->dsg_offset += df->fld_off;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DSG_PFIXED:
|
|
|
|
case DSG_INDEXED:
|
|
|
|
CodeAddress(ds);
|
1986-05-21 18:32:20 +00:00
|
|
|
ds->dsg_kind = DSG_PLOADED;
|
1986-05-16 17:15:36 +00:00
|
|
|
ds->dsg_offset = df->fld_off;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
1986-05-21 18:32:20 +00:00
|
|
|
crash("(CodeFieldDesig)");
|
1986-05-16 17:15:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1986-05-21 18:32:20 +00:00
|
|
|
CodeVarDesig(df, ds)
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_def *df;
|
|
|
|
register t_desig *ds;
|
1986-05-21 18:32:20 +00:00
|
|
|
{
|
|
|
|
/* Generate code for a variable represented by a "def" structure.
|
|
|
|
Of course, there are numerous cases: the variable is local,
|
|
|
|
it is a value parameter, it is a var parameter, it is one of
|
|
|
|
those of an enclosing procedure, or it is global.
|
|
|
|
*/
|
1987-09-24 13:07:31 +00:00
|
|
|
register t_scope *sc = df->df_scope;
|
1988-03-23 17:44:25 +00:00
|
|
|
int difflevel;
|
1986-05-21 18:32:20 +00:00
|
|
|
|
|
|
|
/* Selections from a module are handled earlier, when identifying
|
|
|
|
the variable, so ...
|
|
|
|
*/
|
|
|
|
assert(ds->dsg_kind == DSG_INIT);
|
|
|
|
|
1987-06-29 12:46:00 +00:00
|
|
|
if (df->df_flags & D_ADDRGIVEN) {
|
1986-05-21 18:32:20 +00:00
|
|
|
/* the programmer specified an address in the declaration of
|
|
|
|
the variable. Generate code to push the address.
|
|
|
|
*/
|
1987-07-21 13:54:33 +00:00
|
|
|
CodeConst(df->var_off, (int) pointer_size);
|
1986-05-21 18:32:20 +00:00
|
|
|
ds->dsg_kind = DSG_PLOADED;
|
|
|
|
ds->dsg_offset = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (df->var_name) {
|
|
|
|
/* this variable has been given a name, so it is global.
|
|
|
|
It is directly accessible.
|
|
|
|
*/
|
|
|
|
ds->dsg_name = df->var_name;
|
|
|
|
ds->dsg_offset = 0;
|
|
|
|
ds->dsg_kind = DSG_FIXED;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1988-03-23 17:44:25 +00:00
|
|
|
if ((difflevel = proclevel - sc->sc_level) != 0) {
|
1986-05-21 18:32:20 +00:00
|
|
|
/* the variable is local to a statically enclosing procedure.
|
|
|
|
*/
|
1988-03-23 17:44:25 +00:00
|
|
|
assert(difflevel > 0);
|
1986-06-17 12:04:05 +00:00
|
|
|
|
|
|
|
df->df_flags |= D_NOREG;
|
1986-05-21 18:32:20 +00:00
|
|
|
if (df->df_flags & (D_VARPAR|D_VALPAR)) {
|
|
|
|
/* value or var parameter
|
|
|
|
*/
|
1988-03-23 17:44:25 +00:00
|
|
|
C_lxa((arith) difflevel);
|
1986-06-04 09:01:48 +00:00
|
|
|
if ((df->df_flags & D_VARPAR) ||
|
|
|
|
IsConformantArray(df->df_type)) {
|
1986-09-25 19:39:06 +00:00
|
|
|
/* var parameter or conformant array.
|
|
|
|
For conformant array's, the address is
|
|
|
|
passed.
|
1986-05-21 18:32:20 +00:00
|
|
|
*/
|
|
|
|
C_adp(df->var_off);
|
|
|
|
C_loi(pointer_size);
|
|
|
|
ds->dsg_offset = 0;
|
|
|
|
ds->dsg_kind = DSG_PLOADED;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
1988-03-23 17:44:25 +00:00
|
|
|
else C_lxl((arith) difflevel);
|
1986-05-21 18:32:20 +00:00
|
|
|
ds->dsg_kind = DSG_PLOADED;
|
|
|
|
ds->dsg_offset = df->var_off;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now, finally, we have a local variable or a local parameter
|
|
|
|
*/
|
1986-06-04 09:01:48 +00:00
|
|
|
if ((df->df_flags & D_VARPAR) || IsConformantArray(df->df_type)) {
|
1986-05-21 18:32:20 +00:00
|
|
|
/* a var parameter; address directly accessible.
|
|
|
|
*/
|
|
|
|
ds->dsg_kind = DSG_PFIXED;
|
|
|
|
}
|
|
|
|
else ds->dsg_kind = DSG_FIXED;
|
1987-05-27 10:16:03 +00:00
|
|
|
ds->dsg_offset = df->var_off;
|
|
|
|
ds->dsg_def = df;
|
1986-05-21 18:32:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CodeDesig(nd, ds)
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_node *nd;
|
|
|
|
register t_desig *ds;
|
1986-05-21 18:32:20 +00:00
|
|
|
{
|
|
|
|
/* Generate code for a designator. Use divide and conquer
|
|
|
|
principle
|
|
|
|
*/
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_def *df;
|
1986-05-21 18:32:20 +00:00
|
|
|
|
|
|
|
switch(nd->nd_class) { /* Divide */
|
1986-06-04 09:01:48 +00:00
|
|
|
case Def:
|
|
|
|
df = nd->nd_def;
|
1987-07-30 13:37:39 +00:00
|
|
|
if (nd->nd_left) CodeDesig(nd->nd_left, ds);
|
1986-05-21 18:32:20 +00:00
|
|
|
|
|
|
|
switch(df->df_kind) {
|
|
|
|
case D_FIELD:
|
|
|
|
CodeFieldDesig(df, ds);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case D_VARIABLE:
|
|
|
|
CodeVarDesig(df, ds);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
crash("(CodeDesig) Def");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1986-06-10 13:18:52 +00:00
|
|
|
case Arrsel:
|
1986-05-21 18:32:20 +00:00
|
|
|
assert(nd->nd_symb == '[');
|
1986-05-23 19:25:21 +00:00
|
|
|
|
1986-05-21 18:32:20 +00:00
|
|
|
CodeDesig(nd->nd_left, ds);
|
|
|
|
CodeAddress(ds);
|
1986-06-04 09:01:48 +00:00
|
|
|
CodePExpr(nd->nd_right);
|
1988-03-23 17:44:25 +00:00
|
|
|
nd = nd->nd_left;
|
1986-06-04 09:01:48 +00:00
|
|
|
|
|
|
|
/* Now load address of descriptor
|
|
|
|
*/
|
1988-03-23 17:44:25 +00:00
|
|
|
if (IsConformantArray(nd->nd_type)) {
|
|
|
|
arith off;
|
|
|
|
assert(nd->nd_class == Def);
|
1986-06-04 09:01:48 +00:00
|
|
|
|
1988-03-23 17:44:25 +00:00
|
|
|
df = nd->nd_def;
|
|
|
|
off = df->var_off + pointer_size;
|
1986-06-04 09:01:48 +00:00
|
|
|
if (proclevel > df->df_scope->sc_level) {
|
1988-03-21 17:22:26 +00:00
|
|
|
C_lxa((arith) (proclevel - df->df_scope->sc_level));
|
1988-03-23 17:44:25 +00:00
|
|
|
C_adp(off);
|
1986-06-04 09:01:48 +00:00
|
|
|
}
|
1988-03-23 17:44:25 +00:00
|
|
|
else C_lal(off);
|
1986-05-21 18:32:20 +00:00
|
|
|
}
|
|
|
|
else {
|
1988-03-23 17:44:25 +00:00
|
|
|
C_loc(nd->nd_type->arr_low);
|
1988-03-21 17:22:26 +00:00
|
|
|
C_sbu(int_size);
|
1988-03-23 17:44:25 +00:00
|
|
|
c_lae_dlb(nd->nd_type->arr_descr);
|
1986-05-21 18:32:20 +00:00
|
|
|
}
|
1988-03-21 17:22:26 +00:00
|
|
|
if (options['A']) {
|
|
|
|
C_cal("rcka");
|
|
|
|
}
|
1986-05-23 09:46:31 +00:00
|
|
|
ds->dsg_kind = DSG_INDEXED;
|
1986-05-21 18:32:20 +00:00
|
|
|
break;
|
|
|
|
|
1986-06-10 13:18:52 +00:00
|
|
|
case Arrow:
|
1986-05-21 18:32:20 +00:00
|
|
|
assert(nd->nd_symb == '^');
|
1986-05-23 19:25:21 +00:00
|
|
|
|
1988-03-23 17:44:25 +00:00
|
|
|
nd = nd->nd_right;
|
|
|
|
CodeDesig(nd, ds);
|
1986-05-21 18:32:20 +00:00
|
|
|
switch(ds->dsg_kind) {
|
|
|
|
case DSG_LOADED:
|
|
|
|
ds->dsg_kind = DSG_PLOADED;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DSG_INDEXED:
|
|
|
|
case DSG_PLOADED:
|
|
|
|
case DSG_PFIXED:
|
1988-03-23 17:44:25 +00:00
|
|
|
CodeValue(ds, nd->nd_type);
|
1986-05-21 18:32:20 +00:00
|
|
|
ds->dsg_kind = DSG_PLOADED;
|
|
|
|
ds->dsg_offset = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DSG_FIXED:
|
|
|
|
ds->dsg_kind = DSG_PFIXED;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
crash("(CodeDesig) Uoper");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
crash("(CodeDesig) class");
|
|
|
|
}
|
|
|
|
}
|