Subversion Repositories tendra.SVN

Rev

Go to most recent revision | 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
/* 	$Id: regexps.c,v 1.1.1.1 1998/01/17 15:56:01 release Exp $	 */
32
 
33
#ifndef lint
34
static char vcid[] = "$Id: regexps.c,v 1.1.1.1 1998/01/17 15:56:01 release Exp $";
35
#endif /* lint */
36
 
37
/*
38
   regexps.c
39
*/
40
 
41
/*
42
$Log: regexps.c,v $
43
 * Revision 1.1.1.1  1998/01/17  15:56:01  release
44
 * First version to be checked into rolling release.
45
 *
46
 * Revision 1.7  1996/01/17  09:31:37  john
47
 * Fix to support current_env dependancy
48
 *
49
 * Revision 1.6  1995/12/04  09:13:11  john
50
 * Fix to dependancy check
51
 *
52
 * Revision 1.5  1995/10/16  12:09:21  john
53
 * Change to alignment calculation
54
 *
55
 * Revision 1.4  1995/08/21  08:46:20  john
56
 * Changed include files
57
 *
58
 * Revision 1.3  1995/05/16  10:55:17  john
59
 * Cosmetic change
60
 *
61
 * Revision 1.2  1995/03/29  14:05:14  john
62
 * Changes to keep tcheck happy
63
 *
64
 * Revision 1.1.1.1  1995/03/23  10:39:20  john
65
 * Entered into CVS
66
 *
67
 * Revision 1.7  1995/03/13  11:44:19  john
68
 * Removed bitad case
69
 *
70
 * Revision 1.6  1995/01/26  13:48:31  john
71
 * Removed unused variable
72
 *
73
*/
74
 
75
#include "config.h"
76
#include "expmacs.h"
77
#include "addresstypes.h"
78
#include "tags.h"
79
#include "move.h"
80
#include "bitsmacs.h"
81
#include "maxminmacs.h"
82
#include "shapemacs.h"
83
#include "common_types.h"
84
#include "extratags.h"
85
#include "reg_defs.h"
86
#include "regexps.h"
87
#include "fail.h"
88
 
89
regpeep regexps[64];		
90
 
91
bool eq_size
92
    PROTO_N ( ( as, bs ) )
93
    PROTO_T ( shape as X shape bs )
94
{
95
  return (shape_size(as) == shape_size(bs));
96
}
97
 
98
bool sim_exp PROTO_S ((exp a, exp b));
99
 
100
bool eq_sze
101
    PROTO_N ( ( as, bs ) )
102
    PROTO_T ( shape as X shape bs )
103
{
104
  if (is_floating(name(as))) return(name(as)==name(bs));
105
  if (is_floating(name(bs))) return 0;
106
  return (shape_size(as) == shape_size(bs) && shape_align(as)==shape_align(bs));
107
}
108
 
109
#define is_volatile(X) ((X<9)||(X>15))
110
 
111
 
112
bool sim_explist
113
    PROTO_N ( ( al, bl ) )
114
    PROTO_T ( exp al X exp bl )
115
{
116
  if (al == nilexp && bl == nilexp)
117
    return (1);
118
  if (al == nilexp || bl == nilexp)
119
    return (0);
120
  if (!sim_exp (al, bl))
121
    return (0);
122
  if (last (al) && last (bl))
123
    return (1);
124
  if (last (al) || last (bl))
125
    return (0);
126
  return (sim_explist (bro (al), bro (bl)));
127
}
128
 
129
 
130
 
131
bool sim_exp
132
    PROTO_N ( ( a,b ) )
133
    PROTO_T ( exp a X exp b )
134
{
135
  /* basically eq_exp except equal shapes
136
     requirement  is weakened to equal sizes
137
     and alignments */
138
  if (name (a) == name (b)) {
139
    if (name (a) == name_tag)
140
      return (son (a) == son (b) && no (a) == no (b) &&
141
	      eq_sze (sh (a), sh (b)));
142
    if (name(a)==maxlike_tag || name(a)==minlike_tag || name(a)==abslike_tag) {
143
    	return (props(son(a))==props(son(b)) && eq_size(sh(a), sh(b)) &&
144
    			sim_explist(son(son(a)),son(son(b)) ) );
145
    }
146
    if (!is_a (name (a)) || !eq_sze (sh (a), sh (b)))
147
      return (0);
148
    return (no (a) == no (b) &&
149
	sim_explist (son (a), son (b)));
150
  };
151
  return (0);
152
}
153
 
154
void clear_all
155
    PROTO_Z ()
156
{
157
  /* forget all register - exp associations 
158
   */
159
  int   i;
160
  for (i = 0; i < 64; i++) {
161
/*    if(is_volatile(i)){*/
162
      regexps[i].keptexp = nilexp;
163
      regexps[i].alignment = 0;
164
      setregalt (regexps[i].inans, NO_REG);
165
/*    }*/
166
  }
167
}
168
 
169
 
170
 
171
 
172
 
173
 
174
 
175
 
176
void clear_reg
177
    PROTO_N ( ( i ) )
178
    PROTO_T ( int i )
179
{
180
  /* forget reg i - exp association */
181
  i = abs (i);
182
  if (i >= 0 && i < 64) {
183
    regexps[i].keptexp = nilexp;
184
    regexps[i].alignment = 0;
185
    setregalt (regexps[i].inans, NO_REG);
186
  }
187
}
188
 
189
void clear_freg
190
    PROTO_N ( ( i ) )
191
    PROTO_T ( int i )
192
{
193
  i=abs(i)+32;
194
  if(i<64)
195
  {
196
    regexps[i].keptexp=nilexp;
197
    setregalt(regexps[i].inans,NO_REG);	/* ?? */
198
  }
199
}
200
 
201
 
202
 
203
ans iskept
204
    PROTO_N ( ( e ) )
205
    PROTO_T ( exp e )
206
{
207
  /* find if e has already been evaluated
208
     into a register */
209
  int   i;
210
  ans nilans;
211
  ans aa;
212
  setregalt (nilans, 32);
213
  aa = nilans;
214
  for (i = 0; i < 48; i++) {
215
    exp ke = regexps[i].keptexp;
216
    bool isc = regexps[i].iscont;
217
    if (ke != nilexp) {		/* there is an accociation with reg i */
218
      if (
219
	  ((!isc && sim_exp (ke, e)) ||
220
	   (name (e) == cont_tag && isc && eq_sze (sh (ke), sh (e))
221
	    && sim_exp (ke, son (e)))
222
	   )
223
	  ) {
224
	aa = (regexps[i].inans);
225
	switch (aa.discrim) {
226
	 case notinreg: 
227
	  {
228
	    if (!aa.val.instoreans.adval) {
229
	      /* the expression is given indirectly - it
230
		 may have also been loaded into a
231
		 register */
232
	      continue;
233
	    }
234
	    /* else ... */
235
	  }
236
	  FALL_THROUGH
237
	 default: 
238
	  return aa;
239
	}
240
      }
241
      else
242
	if (name (ke) == cont_tag && !isc) {
243
	  ans aq;
244
	  aq = regexps[i].inans;
245
	  if (aq.discrim == notinreg) {
246
	    instore is;
247
	    is = insalt (aq);
248
	    if (!is.adval && is.b.offset == 0 && is.b.base > 0 && is.b.base < 31
249
		&& sim_exp (son (ke), e)) {
250
	      /* the contents of req expression is here
251
		 as a reg-offset */
252
	      is.adval = 1;
253
	      setinsalt (aq, is);
254
	      return aq;
255
	    }
256
	  }
257
	}
258
	else
259
	  if (name (ke) == reff_tag && !isc) {
260
	    ans aq;
261
	    aq = regexps[i].inans;
262
	    if (aq.discrim == notinreg) {
263
	      instore is;
264
	      is = insalt (aq);
265
	      if (is.adval && is.b.offset == (no (ke) / 8)
266
		  && is.b.base > 0 && is.b.base < 31
267
		  && sim_exp (son (ke), e)) {
268
		/* a ref select of req expression is here
269
		   as a reg-offset */
270
		is.adval = 1;
271
		is.b.offset = 0;
272
		setinsalt (aq, is);
273
		return aq;
274
	      }
275
	    }
276
	  }
277
    }
278
  }
279
  return aa;
280
}
281
 
282
void keepexp
283
    PROTO_N ( ( e, loc ) )
284
    PROTO_T ( exp e X ans loc )
285
{
286
  /* set up exp - address association */
287
  int   pos;
288
  switch (loc.discrim) {
289
   case insomereg: 
290
   case insomefreg: {
291
     failer ("Keep ? reg");
292
     break;
293
   }
294
   case inreg: 
295
    {
296
      pos = regalt (loc);
297
      break;
298
    }
299
   case infreg: 
300
    {
301
      pos = fregalt (loc).fr + 32;
302
      break;
303
    }
304
   case notinreg: 
305
    {
306
      pos = insalt (loc).b.base;
307
      if (pos < 0 || pos > 30)
308
	return;
309
    }	
310
 
311
  };
312
  if (pos==0 || pos == 32) return;
313
  regexps[pos].keptexp = e;
314
  regexps[pos].inans = loc;
315
  regexps[pos].iscont = 0;
316
}	
317
 
318
void keepcont
319
    PROTO_N ( ( e, reg ) )
320
    PROTO_T ( exp e X int reg )
321
{
322
  /* set up cont(e)-reg association */
323
  freg fr;
324
  int   z = abs (reg);
325
  /*  if (z==2|| z==32) return;*/
326
  if (z > 31) {
327
    if(reg<0) 
328
      fr.type = IEEE_double;
329
    else
330
      fr.type = IEEE_single;
331
    fr.fr = z - 32;
332
    setfregalt (regexps[z].inans, fr);
333
  }
334
  else {
335
    instore is;
336
    is.b.base = reg;
337
    is.b.offset = 0;
338
    is.adval = 1;
339
    setinsalt (regexps[z].inans, is);
340
  }
341
 
342
  regexps[z].keptexp = e;
343
 
344
  regexps[z].iscont = 1;
345
 
346
}
347
 
348
void keepreg
349
    PROTO_N ( ( e, reg ) )
350
    PROTO_T ( exp e X int reg )
351
{
352
  /* set up e-reg association */
353
  freg fr;
354
  int   z = abs (reg);
355
  if(z==0) return;
356
/*  if (z==2 || z==32) return;*/
357
  if (z > 31) {
358
    if(reg<0)
359
      fr.type = IEEE_double;
360
    else
361
      fr.type = IEEE_single;
362
    fr.fr = z - 32;
363
    setfregalt (regexps[z].inans, fr);
364
  }
365
  else {
366
    instore is;
367
    is.b.base = reg;
368
    is.b.offset = 0;
369
    is.adval = 1;
370
    setinsalt (regexps[z].inans, is);
371
  }
372
 
373
  regexps[z].keptexp = e;
374
  regexps[z].iscont = 0;
375
}
376
 
377
bool couldeffect PROTO_S ((exp e, exp z));
378
 
379
bool couldbe
380
    PROTO_N ( ( e, lhs ) )
381
    PROTO_T ( exp e X exp lhs )
382
{
383
  /* could e be lhs? */ 			
384
  int   ne = name (e);
385
  exp s = son (e);
386
 
387
  if (ne == name_tag) {
388
    if (lhs != 0 && s == son (lhs)) {
389
      return 1;
390
    }
391
    if (isvar (s)) {
392
      return (lhs == 0 && isvis(s));
393
      /*
394
      return (lhs == 0 && (isvis (s) || isglob(s) ));*/
395
    }
396
    if (name (s) == proc_tag)
397
      return (lhs == 0);
398
    if (son (s) == nilexp)
399
      return 1;
400
    return couldbe (son (s), lhs);
401
  }
402
  if (ne == cont_tag) {
403
    if (lhs != 0 && name (s) == name_tag && son (s) != nilexp) {
404
      return (son (s) == son (lhs) || isvis (son (lhs)) || isvis (son (s)));
405
    }
406
    return 1;
407
  }
408
  if (ne == reff_tag || ne == field_tag) {
409
    return couldbe (s, lhs);
410
  }
411
  if (ne == addptr_tag || ne == subptr_tag) {
412
    return (couldbe (s, lhs) || couldeffect (bro (s), lhs));
413
  }
414
 
415
  return 1;
416
 
417
}
418
 
419
bool couldeffect
420
    PROTO_N ( ( e, z ) )
421
    PROTO_T ( exp e X exp z )
422
{
423
  /* could alteration to z effect e? */
424
  int   ne = name (e);
425
  if (ne == cont_tag) {
426
    return couldbe (son (e), z);
427
  }
428
  if (ne == name_tag) {
429
    if (isvar (son (e)))
430
      return (z == 0 && isvis (son (e)));
431
    if (name (son (e)) == proc_tag)
432
      return 0;
433
    if (son (son (e)) == nilexp)
434
      return 1 /* could it happen? */ ;
435
 
436
    return couldeffect (son (son (e)), z);
437
 
438
  }
439
  if (ne < plus_tag || ne == contvol_tag)
440
    return 1;
441
 
442
  e = son (e);
443
 
444
  while (e != nilexp) {
445
    if (couldeffect (e, z))
446
      return 1;
447
    if (last (e))
448
      return 0;
449
    e = bro (e);
450
  }
451
  return 0;
452
}
453
 
454
 
455
 
456
bool dependson
457
    PROTO_N ( ( e, isc, z ) )
458
    PROTO_T ( exp e X bool isc X exp z )
459
{
460
  /* does e depend on z */
461
  if (e == nilexp) {
462
    return 0;
463
  }
464
  for (;;) {
465
    if (name (z) == reff_tag || name (z) == addptr_tag ||
466
	name (z) == subptr_tag) {
467
      z = son (z);
468
      if(name(z) == null_tag) return 0;
469
    }
470
    else
471
      if (name (z) != name_tag) {
472
	if (name (z) != cont_tag)
473
	  return 1;
474
	z = 0;
475
	break;
476
    }
477
      if(name(z) == current_env_tag) {
478
	return 0;
479
      }
480
 
481
    if (isvar (son (z)))
482
      break;
483
    if (name (son (z)) == proc_tag) {
484
      z = 0;
485
      break;
486
    }
487
    if (son (son (z)) == nilexp)
488
      return 1;			/* can it happen? */
489
    z = son (son (z));
490
  }
491
 
492
  /* z is now unambiguous variable name or 0 meaning some contents */
493
 
494
  return ((isc) ? couldbe (e, z) : couldeffect (e, z));
495
}
496
 
497
 
498
 
499
 
500
 
501
void clear_dep_reg
502
    PROTO_N ( ( lhs ) )
503
    PROTO_T ( exp lhs )
504
{
505
  /* remove association of any register
506
     which depends on lhs */
507
  int   i;
508
  for (i = 0; i < 64; i++) {
509
    if (dependson (regexps[i].keptexp, regexps[i].iscont, lhs)) {
510
      regexps[i].keptexp = nilexp;
511
      setregalt (regexps[i].inans, NO_REG);
512
    }
513
  }
514
}
515