Subversion Repositories tendra.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
7 7u83 2
 * Copyright (c) 2002-2005 The TenDRA Project <http://www.tendra.org/>.
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions are met:
7
 *
8
 * 1. Redistributions of source code must retain the above copyright notice,
9
 *    this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
11
 *    this list of conditions and the following disclaimer in the documentation
12
 *    and/or other materials provided with the distribution.
13
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
14
 *    may be used to endorse or promote products derived from this software
15
 *    without specific, prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 *
29
 * $Id$
30
 */
31
/*
2 7u83 32
    		 Crown Copyright (c) 1997
7 7u83 33
 
2 7u83 34
    This TenDRA(r) Computer Program is subject to Copyright
35
    owned by the United Kingdom Secretary of State for Defence
36
    acting through the Defence Evaluation and Research Agency
37
    (DERA).  It is made available to Recipients with a
38
    royalty-free licence for its use, reproduction, transfer
39
    to other parties and amendment for any purpose not excluding
40
    product development provided that any such use et cetera
41
    shall be deemed to be acceptance of the following conditions:-
7 7u83 42
 
2 7u83 43
        (1) Its Recipients shall ensure that this Notice is
44
        reproduced upon any copies or amended versions of it;
7 7u83 45
 
2 7u83 46
        (2) Any amended version of it shall be clearly marked to
47
        show both the nature of and the organisation responsible
48
        for the relevant amendment or amendments;
7 7u83 49
 
2 7u83 50
        (3) Its onward transfer from a recipient to another
51
        party shall be deemed to be that party's acceptance of
52
        these conditions;
7 7u83 53
 
2 7u83 54
        (4) DERA gives no warranty or assurance as to its
55
        quality or suitability for any purpose and DERA accepts
56
        no liability whatsoever in relation to any use to which
57
        it may be put.
58
*/
59
 
60
 
7 7u83 61
/* 	$Id$	 */
2 7u83 62
 
63
#ifndef lint
7 7u83 64
static char vcid[] = "$Id$";
2 7u83 65
#endif /* lint */
66
 
67
/*
68
   regexps.c
69
*/
70
 
71
/*
72
$Log: regexps.c,v $
73
 * Revision 1.1.1.1  1998/01/17  15:56:01  release
74
 * First version to be checked into rolling release.
75
 *
76
 * Revision 1.7  1996/01/17  09:31:37  john
77
 * Fix to support current_env dependancy
78
 *
79
 * Revision 1.6  1995/12/04  09:13:11  john
80
 * Fix to dependancy check
81
 *
82
 * Revision 1.5  1995/10/16  12:09:21  john
83
 * Change to alignment calculation
84
 *
85
 * Revision 1.4  1995/08/21  08:46:20  john
86
 * Changed include files
87
 *
88
 * Revision 1.3  1995/05/16  10:55:17  john
89
 * Cosmetic change
90
 *
91
 * Revision 1.2  1995/03/29  14:05:14  john
92
 * Changes to keep tcheck happy
93
 *
94
 * Revision 1.1.1.1  1995/03/23  10:39:20  john
95
 * Entered into CVS
96
 *
97
 * Revision 1.7  1995/03/13  11:44:19  john
98
 * Removed bitad case
99
 *
100
 * Revision 1.6  1995/01/26  13:48:31  john
101
 * Removed unused variable
102
 *
103
*/
104
 
105
#include "config.h"
106
#include "expmacs.h"
107
#include "addresstypes.h"
108
#include "tags.h"
109
#include "move.h"
110
#include "bitsmacs.h"
111
#include "maxminmacs.h"
112
#include "shapemacs.h"
113
#include "common_types.h"
114
#include "extratags.h"
115
#include "reg_defs.h"
116
#include "regexps.h"
117
#include "fail.h"
118
 
7 7u83 119
regpeep regexps[64];
2 7u83 120
 
121
bool eq_size
7 7u83 122
(shape as, shape bs)
2 7u83 123
{
7 7u83 124
  return(shape_size(as) == shape_size(bs));
2 7u83 125
}
126
 
7 7u83 127
bool sim_exp(exp a, exp b);
2 7u83 128
 
129
bool eq_sze
7 7u83 130
(shape as, shape bs)
2 7u83 131
{
7 7u83 132
  if (is_floating(name(as))) return(name(as) ==name(bs));
2 7u83 133
  if (is_floating(name(bs))) return 0;
7 7u83 134
  return(shape_size(as) == shape_size(bs) && shape_align(as) ==shape_align(bs));
2 7u83 135
}
136
 
7 7u83 137
#define is_volatile(X)((X<9) || (X>15))
2 7u83 138
 
139
 
140
bool sim_explist
7 7u83 141
(exp al, exp bl)
2 7u83 142
{
143
  if (al == nilexp && bl == nilexp)
7 7u83 144
    return(1);
2 7u83 145
  if (al == nilexp || bl == nilexp)
7 7u83 146
    return(0);
147
  if (!sim_exp(al, bl))
148
    return(0);
149
  if (last(al) && last(bl))
150
    return(1);
151
  if (last(al) || last(bl))
152
    return(0);
153
  return(sim_explist(bro(al), bro(bl)));
2 7u83 154
}
155
 
156
 
157
 
158
bool sim_exp
7 7u83 159
(exp a, exp b)
2 7u83 160
{
161
  /* basically eq_exp except equal shapes
162
     requirement  is weakened to equal sizes
163
     and alignments */
7 7u83 164
  if (name(a) == name(b)) {
165
    if (name(a) == name_tag)
166
      return(son(a) == son(b) && no(a) == no(b) &&
167
	      eq_sze(sh(a), sh(b)));
168
    if (name(a) ==maxlike_tag || name(a) ==minlike_tag || name(a) ==abslike_tag) {
169
    	return(props(son(a)) ==props(son(b)) && eq_size(sh(a), sh(b)) &&
170
    			sim_explist(son(son(a)),son(son(b))));
2 7u83 171
    }
7 7u83 172
    if (!is_a(name(a)) || !eq_sze(sh(a), sh(b)))
173
      return(0);
174
    return(no(a) == no(b) &&
175
	sim_explist(son(a), son(b)));
2 7u83 176
  };
7 7u83 177
  return(0);
2 7u83 178
}
179
 
180
void clear_all
7 7u83 181
(void)
2 7u83 182
{
7 7u83 183
  /* forget all register - exp associations
2 7u83 184
   */
185
  int   i;
186
  for (i = 0; i < 64; i++) {
187
/*    if(is_volatile(i)){*/
188
      regexps[i].keptexp = nilexp;
189
      regexps[i].alignment = 0;
7 7u83 190
      setregalt(regexps[i].inans, NO_REG);
2 7u83 191
/*    }*/
192
  }
193
}
194
 
195
 
196
 
197
 
198
 
199
 
7 7u83 200
 
201
 
2 7u83 202
void clear_reg
7 7u83 203
(int i)
2 7u83 204
{
205
  /* forget reg i - exp association */
7 7u83 206
  i = abs(i);
2 7u83 207
  if (i >= 0 && i < 64) {
208
    regexps[i].keptexp = nilexp;
209
    regexps[i].alignment = 0;
7 7u83 210
    setregalt(regexps[i].inans, NO_REG);
2 7u83 211
  }
212
}
213
 
214
void clear_freg
7 7u83 215
(int i)
2 7u83 216
{
7 7u83 217
  i=abs(i) +32;
218
  if (i<64)
2 7u83 219
  {
220
    regexps[i].keptexp=nilexp;
221
    setregalt(regexps[i].inans,NO_REG);	/* ?? */
222
  }
223
}
224
 
225
 
226
 
227
ans iskept
7 7u83 228
(exp e)
2 7u83 229
{
230
  /* find if e has already been evaluated
231
     into a register */
232
  int   i;
233
  ans nilans;
234
  ans aa;
7 7u83 235
  setregalt(nilans, 32);
2 7u83 236
  aa = nilans;
237
  for (i = 0; i < 48; i++) {
238
    exp ke = regexps[i].keptexp;
239
    bool isc = regexps[i].iscont;
240
    if (ke != nilexp) {		/* there is an accociation with reg i */
241
      if (
7 7u83 242
	 ((!isc && sim_exp(ke, e)) ||
243
	  (name(e) == cont_tag && isc && eq_sze(sh(ke), sh(e))
244
	    && sim_exp(ke, son(e)))
245
	  )
246
	 ) {
2 7u83 247
	aa = (regexps[i].inans);
248
	switch (aa.discrim) {
7 7u83 249
	 case notinreg:
2 7u83 250
	  {
251
	    if (!aa.val.instoreans.adval) {
252
	      /* the expression is given indirectly - it
253
		 may have also been loaded into a
254
		 register */
255
	      continue;
256
	    }
257
	    /* else ... */
258
	  }
259
	  FALL_THROUGH
7 7u83 260
	 default:
2 7u83 261
	  return aa;
262
	}
263
      }
264
      else
7 7u83 265
	if (name(ke) == cont_tag && !isc) {
2 7u83 266
	  ans aq;
267
	  aq = regexps[i].inans;
268
	  if (aq.discrim == notinreg) {
269
	    instore is;
7 7u83 270
	    is = insalt(aq);
2 7u83 271
	    if (!is.adval && is.b.offset == 0 && is.b.base > 0 && is.b.base < 31
7 7u83 272
		&& sim_exp(son(ke), e)) {
2 7u83 273
	      /* the contents of req expression is here
274
		 as a reg-offset */
275
	      is.adval = 1;
7 7u83 276
	      setinsalt(aq, is);
2 7u83 277
	      return aq;
278
	    }
279
	  }
280
	}
281
	else
7 7u83 282
	  if (name(ke) == reff_tag && !isc) {
2 7u83 283
	    ans aq;
284
	    aq = regexps[i].inans;
285
	    if (aq.discrim == notinreg) {
286
	      instore is;
7 7u83 287
	      is = insalt(aq);
288
	      if (is.adval && is.b.offset == (no(ke) / 8)
2 7u83 289
		  && is.b.base > 0 && is.b.base < 31
7 7u83 290
		  && sim_exp(son(ke), e)) {
2 7u83 291
		/* a ref select of req expression is here
292
		   as a reg-offset */
293
		is.adval = 1;
294
		is.b.offset = 0;
7 7u83 295
		setinsalt(aq, is);
2 7u83 296
		return aq;
297
	      }
298
	    }
299
	  }
300
    }
301
  }
302
  return aa;
303
}
304
 
305
void keepexp
7 7u83 306
(exp e, ans loc)
2 7u83 307
{
308
  /* set up exp - address association */
309
  int   pos;
310
  switch (loc.discrim) {
7 7u83 311
   case insomereg:
2 7u83 312
   case insomefreg: {
7 7u83 313
     failer("Keep ? reg");
2 7u83 314
     break;
315
   }
7 7u83 316
   case inreg:
2 7u83 317
    {
7 7u83 318
      pos = regalt(loc);
2 7u83 319
      break;
320
    }
7 7u83 321
   case infreg:
2 7u83 322
    {
7 7u83 323
      pos = fregalt(loc).fr + 32;
2 7u83 324
      break;
325
    }
7 7u83 326
   case notinreg:
2 7u83 327
    {
7 7u83 328
      pos = insalt(loc).b.base;
2 7u83 329
      if (pos < 0 || pos > 30)
330
	return;
7 7u83 331
    }
2 7u83 332
 
333
  };
334
  if (pos==0 || pos == 32) return;
335
  regexps[pos].keptexp = e;
336
  regexps[pos].inans = loc;
337
  regexps[pos].iscont = 0;
7 7u83 338
}
2 7u83 339
 
340
void keepcont
7 7u83 341
(exp e, int reg)
2 7u83 342
{
343
  /* set up cont(e)-reg association */
344
  freg fr;
7 7u83 345
  int   z = abs(reg);
2 7u83 346
  /*  if (z==2|| z==32) return;*/
347
  if (z > 31) {
7 7u83 348
    if (reg<0)
2 7u83 349
      fr.type = IEEE_double;
350
    else
351
      fr.type = IEEE_single;
352
    fr.fr = z - 32;
7 7u83 353
    setfregalt(regexps[z].inans, fr);
2 7u83 354
  }
355
  else {
356
    instore is;
357
    is.b.base = reg;
358
    is.b.offset = 0;
359
    is.adval = 1;
7 7u83 360
    setinsalt(regexps[z].inans, is);
2 7u83 361
  }
362
 
363
  regexps[z].keptexp = e;
364
 
365
  regexps[z].iscont = 1;
366
 
367
}
368
 
369
void keepreg
7 7u83 370
(exp e, int reg)
2 7u83 371
{
372
  /* set up e-reg association */
373
  freg fr;
7 7u83 374
  int   z = abs(reg);
375
  if (z==0) return;
2 7u83 376
/*  if (z==2 || z==32) return;*/
377
  if (z > 31) {
7 7u83 378
    if (reg<0)
2 7u83 379
      fr.type = IEEE_double;
380
    else
381
      fr.type = IEEE_single;
382
    fr.fr = z - 32;
7 7u83 383
    setfregalt(regexps[z].inans, fr);
2 7u83 384
  }
385
  else {
386
    instore is;
387
    is.b.base = reg;
388
    is.b.offset = 0;
389
    is.adval = 1;
7 7u83 390
    setinsalt(regexps[z].inans, is);
2 7u83 391
  }
392
 
393
  regexps[z].keptexp = e;
394
  regexps[z].iscont = 0;
395
}
396
 
7 7u83 397
bool couldeffect(exp e, exp z);
2 7u83 398
 
399
bool couldbe
7 7u83 400
(exp e, exp lhs)
2 7u83 401
{
7 7u83 402
  /* could e be lhs? */
403
  int   ne = name(e);
404
  exp s = son(e);
2 7u83 405
 
406
  if (ne == name_tag) {
7 7u83 407
    if (lhs != 0 && s == son(lhs)) {
2 7u83 408
      return 1;
409
    }
7 7u83 410
    if (isvar(s)) {
411
      return(lhs == 0 && isvis(s));
2 7u83 412
      /*
413
      return (lhs == 0 && (isvis (s) || isglob(s) ));*/
414
    }
7 7u83 415
    if (name(s) == proc_tag)
416
      return(lhs == 0);
417
    if (son(s) == nilexp)
2 7u83 418
      return 1;
7 7u83 419
    return couldbe(son(s), lhs);
2 7u83 420
  }
421
  if (ne == cont_tag) {
7 7u83 422
    if (lhs != 0 && name(s) == name_tag && son(s)!= nilexp) {
423
      return(son(s) == son(lhs) || isvis(son(lhs)) || isvis(son(s)));
2 7u83 424
    }
425
    return 1;
426
  }
427
  if (ne == reff_tag || ne == field_tag) {
7 7u83 428
    return couldbe(s, lhs);
2 7u83 429
  }
430
  if (ne == addptr_tag || ne == subptr_tag) {
7 7u83 431
    return(couldbe(s, lhs) || couldeffect(bro(s), lhs));
2 7u83 432
  }
433
 
434
  return 1;
435
 
436
}
437
 
438
bool couldeffect
7 7u83 439
(exp e, exp z)
2 7u83 440
{
441
  /* could alteration to z effect e? */
7 7u83 442
  int   ne = name(e);
2 7u83 443
  if (ne == cont_tag) {
7 7u83 444
    return couldbe(son(e), z);
2 7u83 445
  }
446
  if (ne == name_tag) {
7 7u83 447
    if (isvar(son(e)))
448
      return(z == 0 && isvis(son(e)));
449
    if (name(son(e)) == proc_tag)
2 7u83 450
      return 0;
7 7u83 451
    if (son(son(e)) == nilexp)
2 7u83 452
      return 1 /* could it happen? */ ;
453
 
7 7u83 454
    return couldeffect(son(son(e)), z);
2 7u83 455
 
456
  }
457
  if (ne < plus_tag || ne == contvol_tag)
458
    return 1;
459
 
7 7u83 460
  e = son(e);
2 7u83 461
 
462
  while (e != nilexp) {
7 7u83 463
    if (couldeffect(e, z))
2 7u83 464
      return 1;
7 7u83 465
    if (last(e))
2 7u83 466
      return 0;
7 7u83 467
    e = bro(e);
2 7u83 468
  }
469
  return 0;
470
}
471
 
472
 
473
 
474
bool dependson
7 7u83 475
(exp e, bool isc, exp z)
2 7u83 476
{
477
  /* does e depend on z */
478
  if (e == nilexp) {
479
    return 0;
480
  }
481
  for (;;) {
7 7u83 482
    if (name(z) == reff_tag || name(z) == addptr_tag ||
483
	name(z) == subptr_tag) {
484
      z = son(z);
485
      if (name(z) == null_tag) return 0;
2 7u83 486
    }
487
    else
7 7u83 488
      if (name(z)!= name_tag) {
489
	if (name(z)!= cont_tag)
2 7u83 490
	  return 1;
491
	z = 0;
492
	break;
493
    }
7 7u83 494
      if (name(z) == current_env_tag) {
2 7u83 495
	return 0;
496
      }
7 7u83 497
 
498
    if (isvar(son(z)))
2 7u83 499
      break;
7 7u83 500
    if (name(son(z)) == proc_tag) {
2 7u83 501
      z = 0;
502
      break;
503
    }
7 7u83 504
    if (son(son(z)) == nilexp)
2 7u83 505
      return 1;			/* can it happen? */
7 7u83 506
    z = son(son(z));
2 7u83 507
  }
508
 
509
  /* z is now unambiguous variable name or 0 meaning some contents */
510
 
7 7u83 511
  return((isc)? couldbe(e, z): couldeffect(e, z));
2 7u83 512
}
513
 
514
 
515
 
516
 
517
 
518
void clear_dep_reg
7 7u83 519
(exp lhs)
2 7u83 520
{
521
  /* remove association of any register
522
     which depends on lhs */
523
  int   i;
524
  for (i = 0; i < 64; i++) {
7 7u83 525
    if (dependson(regexps[i].keptexp, regexps[i].iscont, lhs)) {
2 7u83 526
      regexps[i].keptexp = nilexp;
7 7u83 527
      setregalt(regexps[i].inans, NO_REG);
2 7u83 528
    }
529
  }
530
}
531