Subversion Repositories tendra.SVN

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
2
    		 Crown Copyright (c) 1997
3
 
4
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
12
 
13
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
15
 
16
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
19
 
20
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
22
        these conditions;
23
 
24
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
27
        it may be put.
28
*/
29
 
30
 
31
/**********************************************************************
32
$Author: release $
33
$Date: 1998/01/17 15:56:05 $
34
$Revision: 1.1.1.1 $
35
$Log: code_here.c,v $
36
 * Revision 1.1.1.1  1998/01/17  15:56:05  release
37
 * First version to be checked into rolling release.
38
 *
39
 * Revision 1.2  1995/08/16  16:06:31  currie
40
 * Shortened some .h names
41
 *
42
 * Revision 1.1  1995/04/13  09:08:06  currie
43
 * Initial revision
44
 *
45
***********************************************************************/
46
/******************************************************************
47
		code_here
48
 
49
This contains procedures :-
50
 
51
regofval, fregofval : to see if an exp is a load_tag that has been allocated to a register.
52
 
53
regoperand, freoperand : to evaluate an exp into a register using make_code
54
 
55
code_here :  calls make_code and ensures that any internal exit labels are tied up after the call
56
 
57
 
58
	The procedures regoperand and fregoperand evaluate their
59
exp parameter into a single register using make_code. This register is
60
returned. An initial test with regofval checks to see if the exp is already
61
in a register.
62
 
63
******************************************************************/
64
 
65
#include "config.h"
66
#include "common_types.h"
67
#include "addrtypes.h"
68
#include "procrectypes.h"
69
#include "labels.h"
70
#include "expmacs.h"
71
#include "tags.h"
72
#include "new_code.h"
73
#include "exp.h"
74
#include "bitsmacs.h"
75
#include "locate.h"
76
#include "regexps.h"
77
#include "inst_fmt.h"
78
#include "mips_ins.h"
79
#include "shapemacs.h"
80
#include "special.h"
81
#include "handle_sregs.h"
82
#include "code_here.h"
83
 
84
 
85
/*********************************************************************
86
regofval
87
The procedure regofval checks to see if an exp is a load_tag
88
that has been allocated into a fixpnt register and if so return it or else 100.
89
*********************************************************************/
90
int   regofval
91
    PROTO_N ( (e) )
92
    PROTO_T ( exp e )
93
{
94
        exp decx = son (e);
95
  if (name (e) == name_tag && name (decx) == ident_tag) {/* ident tag */
96
    if ((props (decx) & defer_bit) != 0) {
97
      return regofval (son (decx));
98
    }
99
    if ((props (decx) & inreg_bits) != 0) {
100
      return ((isvar (decx)) ? (-no (decx)) : (no (decx)));
101
    }
102
    return 100;
103
  }
104
  else
105
  if ((name (e) == val_tag && no (e) == 0) ||
106
		 name(e) == clear_tag || name(e)== top_tag) {
107
	return 0;
108
  }
109
  else {
110
	return 100;
111
  }
112
}
113
 
114
int   fregofval
115
    PROTO_N ( (e) )
116
    PROTO_T ( exp e )
117
{
118
        exp decx = son (e);
119
  if (name (e) == name_tag && name (decx) == ident_tag) {
120
    if ((props (decx) & infreg_bits) != 0) {
121
      return no (decx);
122
    }
123
    return 100;
124
  }
125
  else
126
  if (name(e)==clear_tag || name(e)==top_tag) {
127
	return 0;
128
  }
129
  else {
130
      return 100;
131
  }
132
}
133
 
134
/**********************************************************************
135
code_here
136
The procedure code_here calls make_code and ensures that
137
any internal exit labels are tied up after the call.
138
**********************************************************************/
139
 
140
int   code_here
141
    PROTO_N ( (e, sp, dest) )
142
    PROTO_T ( exp e X space sp X where dest )
143
{
144
        makeans mka;
145
  mka = make_code (e, sp, dest, 0);
146
  if (mka.lab != 0) {
147
    set_label (mka.lab);
148
  }
149
  return mka.regmove;
150
}
151
 
152
ash ash0 = {
153
  0, 0
154
};
155
ash ash32 = {
156
  32, 32
157
};
158
 
159
 
160
int   reg_operand
161
    PROTO_N ( (e, sp) )
162
    PROTO_T ( exp e X space sp )
163
{
164
  int   x = regofval (e);
165
  ans aa;
166
  where w;
167
  if (x >= 0 && x < 100) {
168
    return x;
169
  }				/* x is a register for e */
170
  if (name (e) == cont_tag) {
171
    x = regofval (son (e));
172
    if (x < 0) {
173
      return (-x);
174
    }
175
  }
176
  else
177
    if (name (e) == apply_tag && specialfn (son (e)) == 0) {
178
				/* apply proc */
179
      setregalt (aa, 0);
180
      w.answhere = aa;
181
      w.ashwhere = ash0;
182
      make_code (e, sp, w, 0);
183
      return 2;			/* simple proc calls give result in reg 2
184
				*/
185
    }
186
 
187
  aa = iskept (e);
188
  if (aa.discrim == inreg && regalt (aa) != 0) {
189
				/* the same expression has already been
190
				   evaluated into a reg */
191
    return regalt (aa);
192
  }
193
  if (aa.discrim == notinreg) {
194
    instore is;
195
    is = insalt (aa);
196
    if (is.adval && is.b.offset == 0) {
197
      int   r = is.b.base;
198
      /* the same expression has already been evaluated into a reg */
199
      return r;
200
    }
201
  }
202
 
203
  {
204
    int   reg = -1;
205
    setsomeregalt (aa, &reg);
206
    /* allow code_here to evaluate e into reg of its choice */
207
    w.answhere = aa;
208
    w.ashwhere = ashof (sh (e));
209
    code_here (e, sp, w);
210
    keepreg (e, reg);
211
    return reg;
212
  }
213
}
214
 
215
int   freg_operand
216
    PROTO_N ( (e, sp) )
217
    PROTO_T ( exp e X space sp )
218
{
219
  int   x = fregofval (e);
220
  ans aa;
221
  where w;
222
  freg fr;
223
  w.ashwhere = ashof (sh (e));
224
  if (x >= 0 && x < 100) {
225
    return x;
226
  }
227
  if (name (e) == cont_tag) {
228
    x = fregofval (son (e));
229
    if (x < 100) {
230
      return (x);
231
    }
232
  }
233
  else
234
    if (name (e) == apply_tag) {
235
      setregalt (aa, 0);
236
      w.answhere = aa;
237
      w.ashwhere = ash0;
238
      make_code (e, sp, w, 0);
239
      return 0;
240
    }
241
 
242
  aa = iskept (e);
243
  if (aa.discrim == infreg) {	/* e already evaluated in fl reg */
244
    return regalt (aa) /* cheat */ ;
245
  }
246
 
247
 { int reg = -1;
248
   somefreg sfr;
249
   sfr.fr = &reg;
250
   sfr.dble = fr.dble = (w.ashwhere.ashsize == 64) ? 1 : 0;
251
  setsomefregalt (aa, sfr);
252
  w.answhere = aa;
253
  /* evaluate e into reg ... */
254
  code_here (e, sp, w);
255
  fr.fr = reg;
256
  setfregalt(aa, fr);
257
  keepexp (e, aa);
258
  return reg;
259
 }
260
}