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
33
 
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:-
42
 
43
        (1) Its Recipients shall ensure that this Notice is
44
        reproduced upon any copies or amended versions of it;
45
 
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;
49
 
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;
53
 
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
 
61
/**********************************************************************
62
$Author: release $
63
$Date: 1998/01/17 15:56:05 $
64
$Revision: 1.1.1.1 $
65
$Log: eval.c,v $
66
 * Revision 1.1.1.1  1998/01/17  15:56:05  release
67
 * First version to be checked into rolling release.
68
 *
69
 * Revision 1.13  1996/07/16  15:59:47  currie
70
 * alloca alignment
71
 *
72
Revision 1.12  1996/06/17 12:38:31  currie
73
Bitsfield in eval
74
 
75
Revision 1.11  1996/06/13 09:20:37  currie
76
Bitf compound starting at non-0 offset
77
 
78
Revision 1.10  1996/06/04 15:42:05  currie
79
include general_proc_tag in make_compound
80
 
81
 * Revision 1.9  1996/01/09  12:00:36  currie
82
 * var callee par in reg
83
 *
84
 * Revision 1.8  1995/12/08  11:20:04  currie
85
 * Constant offsets + allocaerr_lab
86
 *
87
 * Revision 1.7  1995/10/25  13:48:19  currie
88
 * change to position of .glob
89
 *
90
 * Revision 1.6  1995/09/12  10:59:18  currie
91
 * gcc pedanttry
92
 *
93
 * Revision 1.5  1995/08/16  16:06:35  currie
94
 * Shortened some .h names
95
 *
96
 * Revision 1.4  1995/08/15  09:19:14  currie
97
 * Dynamic callees + trap_tag
98
 *
99
 * Revision 1.3  1995/08/09  10:53:36  currie
100
 * apply_general bug
101
 *
102
 * Revision 1.2  1995/06/28  12:15:19  currie
103
 * New make_stack_limit etc
104
 *
105
 * Revision 1.1  1995/04/13  09:08:06  currie
106
 * Initial revision
107
 *
108
***********************************************************************/
109
/*****************************************************************
110
		eval.c
111
 
112
	The main procedure defined here is evaluated which ouputs
113
assembler for data. The parameters are an evaluated exp and an index
114
into the table of externals (or 0 meaning anonymous). XXX
115
*****************************************************************/
116
 
117
#include "config.h"
118
#include "common_types.h"
119
#include "addrtypes.h"
120
#include "tags.h"
121
#include "expmacs.h"
122
#include "exp.h"
123
#include "exptypes.h"
124
#include "maxminmacs.h"
125
#include "shapemacs.h"
126
#include "flpttypes.h"
127
#include "flpt.h"
128
#include "syms.h"
129
#include "out_ba.h"
130
#include "main.h"
131
#include "ibinasm.h"
132
#include "frames.h"
133
#include "procrectypes.h"
134
#include "f64.h"
135
#include "eval.h"
136
#include "basicread.h"
137
 
7 7u83 138
extern void globalise_name(dec*);
2 7u83 139
extern  procrec * procrecs;
140
 
141
long  G_number = 64;		/* to give choice of .sdata or data */
142
 
143
int   data_lab = 33;
144
 
145
int next_data_lab
7 7u83 146
(void)
2 7u83 147
{	/*  anonymous label in data space - $$n in assember o/p */
148
        return data_lab++;
149
}
150
 
151
int next_dlab_sym
7 7u83 152
(void)
2 7u83 153
{	/* as above - but also gives it a symno for .G output */
7 7u83 154
        symnofordata(data_lab);
2 7u83 155
  return data_lab++;
156
}
157
 
158
 
159
/* various pieces of info for outputting data depending on shape */
160
mm scmm = {
161
  127, -128, "\t.byte %ld :%ld\n"
162
};
163
mm uscmm = {
164
  255, 0, "\t.byte %ld :%ld\n"
165
};
166
mm shmm = {
167
  0x7fff, 0xffff8000, "\t.half %ld :%ld\n"
168
};
169
mm ushmm = {
170
  0xffff, 0, "\t.half %ld :%ld\n"
171
};
172
mm swmm = {
173
  0x7fffffff, 0x80000000, "\t.word %ld :%ld\n"
174
};
175
mm uswmm = {
176
  0xffffffff, 0, "\t.word %ld :%ld\n"
177
};
178
 
179
/*************************************************************
180
maxmin
181
 
182
finds the data size from the range of an integer shape
183
**************************************************************/
184
mm maxmin
7 7u83 185
(shape s)
2 7u83 186
{
7 7u83 187
  switch (name(s)) {
2 7u83 188
    case scharhd:
189
      return scmm;
190
    case ucharhd:
191
      return uscmm;
192
    case swordhd:
193
      return shmm;
194
    case uwordhd:
195
      return ushmm;
196
    case slonghd:
197
      return swmm;
198
    case ulonghd:
199
      return uswmm;
200
    default: {
201
 
202
	return uswmm;
203
      }
204
  }
205
 
206
}
207
 
208
 
209
/**************************************************************
210
outlab
211
 
212
outputs the label parameter if non negative else interprets it
213
to be an index into the externals and outputs the identifier.
214
**************************************************************/
215
 
216
void outlab
7 7u83 217
(int l)
2 7u83 218
{
219
  if (l >= 0) {
7 7u83 220
    fprintf(as_file, "$$%d", l);
2 7u83 221
  }
222
  else {
223
    char *extname = main_globals[-l - 1] -> dec_u.dec_val.dec_id;
7 7u83 224
    fprintf(as_file, "%s", extname);
2 7u83 225
  }
226
}
227
 
228
 
229
 
230
 
231
 
232
/***************************************************************
233
evalone
234
 
235
This procedure outputs all non-pack expressions and puts in label
236
values for the pack exps (putting new label numbers into their number
237
fields) which it accumulates for later application in the ptr parameter
238
of evalone. This is done to cope with the fact that the exp to evaluated
239
may contain pack operations which are graph-like .
240
***************************************************************/
241
long  evalexp
7 7u83 242
(exp e)
2 7u83 243
{
244
  switch (name(e)) {
245
    case  val_tag: case null_tag: case top_tag:{
246
	if (name(sh(e)) == offsethd && al2(sh(e)) >= 8) {
7 7u83 247
		return(no(e) >>3);
2 7u83 248
	}
7 7u83 249
        return(no(e));
2 7u83 250
    }
251
    case bitf_to_int_tag:
252
      {
7 7u83 253
	return evalexp(son(e));
2 7u83 254
      }
255
    case int_to_bitf_tag:
256
      {
257
	ash a;
7 7u83 258
	long  w = evalexp(son(e));
259
	a = ashof(sh(e));
2 7u83 260
	if (a.ashalign != 1) {
7 7u83 261
	  failer("should be align 1");
2 7u83 262
	}
263
	if (a.ashsize != 32) {
264
	  w &= ((1 << a.ashsize) - 1);
265
	}
266
	return w;
267
      }
268
    case not_tag:
269
      {
7 7u83 270
	return(~evalexp(son(e)));
2 7u83 271
      }
272
    case and_tag:
273
      {
7 7u83 274
	return(evalexp(son(e)) & evalexp(bro(son(e))));
2 7u83 275
      }
276
    case or_tag:
277
      {
7 7u83 278
	return(evalexp(son(e)) | evalexp(bro(son(e))));
2 7u83 279
      }
280
    case xor_tag:
281
      {
7 7u83 282
	return(evalexp(son(e))^ evalexp(bro(son(e))));
2 7u83 283
      }
284
 
285
    case shr_tag:
286
      {
7 7u83 287
	return(evalexp(son(e)) >> evalexp(bro(son(e))));
2 7u83 288
      }
289
 
290
    case shl_tag:
291
      {
7 7u83 292
	return(evalexp(son(e)) << evalexp(bro(son(e))));
2 7u83 293
      }
294
 
295
    case concatnof_tag:
296
      {
297
	ash a;
7 7u83 298
	long  wd = evalexp(son(e));
299
	a = ashof(sh(son(e)));
300
	return(wd | (evalexp(bro(son(e))) << a.ashsize));
2 7u83 301
      }
302
 
303
    case clear_tag:
304
      {
305
	ash a;
7 7u83 306
	a = ashof(sh(e));
2 7u83 307
	if (a.ashsize > 32)
7 7u83 308
	  failer("clearshape");
2 7u83 309
	return 0;
310
      }
311
   case env_offset_tag:
312
   case general_env_offset_tag: {
313
   	return frame_offset(son(e));
314
   }
315
   case env_size_tag: {
316
	exp tg = son(son(e));
317
	procrec * pr = &procrecs[no(son(tg))];
318
	return((pr->frame_size+pr->callee_size) >> 3);
319
   }
320
   case offset_add_tag:{
7 7u83 321
    	return(evalexp(son(e)) +evalexp(bro(son(e))));
2 7u83 322
   }
323
   case offset_max_tag:{
7 7u83 324
    	return(max(evalexp(son(e)),evalexp(bro(son(e)))));
2 7u83 325
   }
326
   case offset_pad_tag:{
7 7u83 327
	return(rounder(evalexp(son(e)), shape_align(sh(e))));
2 7u83 328
   }
329
   case offset_mult_tag:{
7 7u83 330
    	return(evalexp(son(e))*evalexp(bro(son(e))));
2 7u83 331
   }
332
   case offset_div_tag:case offset_div_by_int_tag:{
7 7u83 333
    	return(evalexp(son(e)) /evalexp(bro(son(e))));
2 7u83 334
   }
335
   case offset_subtract_tag:{
7 7u83 336
    	return(evalexp(son(e)) -evalexp(bro(son(e))));
2 7u83 337
   }
338
   case offset_negate_tag: {
7 7u83 339
	return(- evalexp(son(e)));
2 7u83 340
   }
341
    default:
7 7u83 342
      failer("tag not in evalexp");
2 7u83 343
  }
344
  return 0;
345
}
346
 
347
void set_align
7 7u83 348
(int al)
2 7u83 349
{
350
	if (al<16) return;
351
	if (as_file)
7 7u83 352
	  fprintf(as_file, "\t.align%s\n",
353
	     (al == 16)? " 1" :
354
	     ((al == 32)? " 2" :
355
		((al == 64)? " 3" : " 0")));
356
	out_value(0, ialign,(al == 16)? 1 :
357
	   ((al == 32)? 2 :
358
	     ((al == 64)? 3 : 0)), 0);
2 7u83 359
 
360
}
361
 
362
int eval_al
7 7u83 363
(shape s)
2 7u83 364
{
365
	if (shape_align(s)!=1) return shape_align(s);
366
	if (shape_size(s) <=8) return 8;
367
	if (shape_size(s) <=16) return 16;
368
	return 32;
369
}
370
 
371
void oneval
7 7u83 372
(int val, int al, int rep)
2 7u83 373
{
7 7u83 374
	char *as = (al <= 8)? "\t.byte %ld :%ld\n"
375
	:    ((al <= 16)? "\t.half %ld :%ld\n"
2 7u83 376
	  :     "\t.word %ld :%ld\n");
377
	set_align(al);
378
	if (as_file)
7 7u83 379
	  fprintf(as_file, as, val, rep);
380
	out_value(0,(al <= 8)? ibyte :((al <= 16)? ihalf : iword), val, rep);
2 7u83 381
}
382
 
383
 
384
 
385
void evalone
7 7u83 386
(exp e, long rep)
2 7u83 387
{
388
				/* outputs constant expression e, rep
389
				   times;  */
390
  ash a;
7 7u83 391
  a = ashof(sh(e));
392
  switch (name(e)) {
2 7u83 393
 
394
    case string_tag:
395
      {
396
        long char_size = props(e);
7 7u83 397
	long  strsize = shape_size(sh(e)) /char_size;
2 7u83 398
	char *st = nostr(e);
7 7u83 399
	long  strs = shape_size(sh(e)) >>3;
2 7u83 400
	int   i,j;
401
	if (rep != 1 && as_file)
7 7u83 402
	  fprintf(as_file, "\t.repeat %ld\n", rep);
2 7u83 403
	set_align(char_size);
404
	if (as_file) {
7 7u83 405
	  for (j=0; j< strsize;) {
406
	    switch (char_size) {
407
	      case 8: fprintf(as_file, "\t.byte "); break;
408
	      case 16: fprintf(as_file, "\t.half "); break;
409
	      case 32: fprintf(as_file, "\t.word "); break;
2 7u83 410
	    }
411
	    for (i = j; i < strsize && i-j < 8; i++) {
412
	      switch (char_size) {
7 7u83 413
	        case 8:fprintf(as_file, "0x%x ", st[i]); break;
414
	        case 16:fprintf(as_file, "0x%x ",((short *)st)[i]); break;
415
	        case 32:fprintf(as_file, "0x%lx ",((long *)st)[i]); break;
2 7u83 416
	      }
417
	    }
418
	    j =i;
7 7u83 419
	    fprintf(as_file, "\n");
2 7u83 420
	  }
421
	}
422
	if (rep != 1 && as_file)
7 7u83 423
	  fprintf(as_file, "\t.endr\n");
424
	out_chars(0, iascii, strs, rep);
425
	out_data(st, strs);
2 7u83 426
	return;
427
      }
428
    case real_tag:
429
      {
430
	r2l   n;
431
	int i;
7 7u83 432
	n = real2longs_IEEE(&flptnos[no(e)],(a.ashsize>32)?1:0);
2 7u83 433
	set_align(a.ashalign);
7 7u83 434
	for (i=0; i<rep; i++) {
2 7u83 435
		if (BIGEND) {
7 7u83 436
			if (a.ashsize>32) oneval(n.i2, 32, 1);
2 7u83 437
			oneval(n.i1, 32, 1);
438
		}
439
		else {
440
              		oneval(n.i1, 32, 1);
7 7u83 441
          		if (a.ashsize>32)oneval(n.i2, 32, 1);
2 7u83 442
		}
443
        }
444
	return;
445
      }
446
    case null_tag: case top_tag:
7 7u83 447
      no(e) = 0;
2 7u83 448
    case val_tag:
449
      {
450
	if (shape_size(sh(e)) > 32) {
451
		flt64 temp;
452
		int ov;
453
		int i;
454
		if (isbigval(e)) {
455
			temp = flt_to_f64(no(e), 0, &ov);
456
		}
457
		else {
7 7u83 458
			temp.big = (is_signed(sh(e)) && no(e) <0)?-1:0;
2 7u83 459
			temp.small = no(e);
460
		}
7 7u83 461
		for (i=0; i<rep; i++) {
2 7u83 462
			oneval(temp.small, 32, 1);
463
			oneval(temp.big, 32, 1);
464
		}
465
		return;
466
	}
467
 
468
	oneval(evalexp(e), eval_al(sh(e)), rep);
469
	return;
470
      }
471
 
472
    case name_tag:
473
      {
474
	exp dc = son(e);
475
	dec * globdec= brog(dc);/* must be global name */
476
	char *nm = globdec -> dec_u.dec_val.dec_id;
477
	long symdef = globdec ->dec_u.dec_val.sym_number;
7 7u83 478
	if (!isvar(dc) && son(dc)!= nilexp
479
		&& name(son(dc))!= proc_tag && name(son(dc))!= general_proc_tag
480
		&& no(e) ==0
481
		&& shape_size(sh(e)) == shape_size(sh(son(dc)))) {
2 7u83 482
		evalone(son(dc), rep);
483
		return;
484
	}
485
  	set_align(32);
486
	if (as_file) {
7 7u83 487
	  if (no(e) == 0) {
488
	    fprintf(as_file, "\t.word %s : %ld\n", nm, rep);
2 7u83 489
	  }
490
	  else {
7 7u83 491
	    fprintf(as_file, "\t.word %s + %d :%ld\n", nm, no(e) / 8, rep);
2 7u83 492
	  }
493
	}
7 7u83 494
	out_value(symnos[symdef], iword, no(e) / 8, rep);
2 7u83 495
	return;
496
      }
497
    case compound_tag:  {
7 7u83 498
	exp tup = son(e);
2 7u83 499
	unsigned long val;
500
	bool first_bits=1;
501
	long bits_start =0;
502
	long offs =0;
503
 
504
	if (rep != 1)
7 7u83 505
	  failer("CAN'T REP TUPLES");
2 7u83 506
	set_align(a.ashalign);
507
 
508
 
7 7u83 509
	for (;;) {
2 7u83 510
	     ash ae;
511
	     ae = ashof(sh(bro(tup)));
512
	     offs = no(tup);
513
	     if (ae.ashalign == 1) {
514
		unsigned long vb = evalexp(bro(tup));
515
		if (ae.ashsize != 32) {
7 7u83 516
		  vb = vb & ((1<<ae.ashsize) -1);
2 7u83 517
		}
518
                if (first_bits) {
519
		     val = 0;
520
                     first_bits=0;
521
                }
522
 
523
                if (offs - bits_start +ae.ashsize > 32) {
524
                   if (BIGEND) {
7 7u83 525
                      for (;;) {
2 7u83 526
                              oneval(val>>24, 8, 1);
527
                              val <<=8;
528
                              bits_start+=8;
7 7u83 529
                              if (offs-bits_start < 8)break;
2 7u83 530
                      }
531
                   }
532
                   else {
7 7u83 533
                     for (;;) {
2 7u83 534
                        oneval(val &255, 8,1);
535
                        val >>= 8;
536
                        bits_start += 8;
537
                        if (offs - bits_start  < 8)
538
                                 break;
539
                     }
540
                   }
541
                }
542
 
543
                if (offs - bits_start +ae.ashsize <= 32) {
544
                     if (BIGEND) {
545
			val |= (vb << (32 -offs+bits_start-ae.ashsize));
546
		     }
547
		     else {
7 7u83 548
                     	val |= (vb << (offs-bits_start));
2 7u83 549
		     }
550
                }
551
                else {
552
                   failer("Constant bitfield does not fit into 32 bits");
553
                }
554
	     }
555
	     else {
556
	     	if (!first_bits) {
557
		    first_bits=1;
558
		    if (BIGEND) {
7 7u83 559
		   	for (;;) {
2 7u83 560
		   		oneval(val>>24, 8, 1);
561
		   		val <<=8;
562
		   		bits_start+=8;
7 7u83 563
		   		if (offs-bits_start <= 0)break;
2 7u83 564
		   	}
565
		     }
566
		     else {
7 7u83 567
                       for (;;) {
2 7u83 568
                          oneval(val &255, 8,1);
569
                          val >>=8;
570
                          bits_start += 8;
7 7u83 571
                          if (offs - bits_start  <=0)
2 7u83 572
                                   break;
573
                       }
574
                     }
575
	  	}
576
		while (bits_start < offs) {
577
			oneval(0, 0, 1);
578
			bits_start+=8;
579
		}
580
		evalone(bro(tup),1);
581
		bits_start += shape_size(sh(bro(tup)));
582
	     }
583
 
584
	     if (last(bro(tup))) {
585
	     	     offs += ae.ashsize;
7 7u83 586
		     offs = (offs+7) &~7;
587
		     for (;!first_bits;) {
2 7u83 588
                      if (BIGEND) {
589
                            oneval(val>>24, 8, 1);
590
                            val <<=8;
591
                            bits_start+=8;
7 7u83 592
                            if (offs-bits_start<= 0)break;
2 7u83 593
                       }
594
                       else {
595
                            oneval(val &255, 8,1);
596
                            val >>= 8;
597
                            bits_start +=8;
7 7u83 598
                            if (offs - bits_start <=0)
2 7u83 599
                                     break;
600
                       }
601
		     }
602
		     Assert(a.ashsize >= offs);
603
		     while (a.ashsize > offs) { /* pad out unions etc */
604
		     	oneval(0,8,1);
605
		     	offs+=8;
606
		     }
607
		     return;
608
	     }
609
	     tup = bro(bro(tup));
610
	}
611
 
612
   }
613
 
614
   case nof_tag: {
615
   	exp s = son(e);
616
	if (s==nilexp) return;
617
	if (rep != 1)
7 7u83 618
	  failer("CAN'T REP TUPLES");
2 7u83 619
   	set_align(a.ashalign);
7 7u83 620
   	for (;;) {
2 7u83 621
   		evalone(s,1);
622
   		if (last(s)) return;
623
   		s = bro(s);
624
   	}
625
   }
626
 
627
 
628
    case ncopies_tag:
629
      {
630
        if (name(son(e)) == compound_tag || name(son(e)) == concatnof_tag ||
631
               name(son(e)) == nof_tag) {
632
             int n;
633
             for (n = rep*no(e); n > 0; n--) {
634
             	evalone(son(e), 1);
635
             }
636
        }
7 7u83 637
	else evalone(son(e), rep * no(e));
2 7u83 638
	return;
639
      }
640
 
641
    case concatnof_tag:
642
      {
643
	if (a.ashalign == 1) {
7 7u83 644
	  long  ee = evalexp(e);
2 7u83 645
	  exp dad = father(e);
646
	  ash abits;
647
	  abits = ashof(sh(dad));
648
	  oneval(ee, abits.ashalign, rep);
649
	}
650
	else {
651
	  if (rep != 1)
7 7u83 652
	    failer("CAN'T REP concat");
653
	  evalone(son(e), 1);
654
	  evalone(bro(son(e)), 1);
2 7u83 655
	}
656
	return;
657
      }
658
 
659
    case clear_tag:
660
      {
661
	int s = eval_al(sh(e));
662
	if (as_file)
7 7u83 663
	  fprintf(as_file, "\t.space %ld\n",(s>>3)* rep);
664
	out_value(0, ispace,(s>>3)* rep, 1);
2 7u83 665
	return;
666
      }
667
 
668
 
669
 
670
    case not_tag:
671
    case and_tag:
672
    case or_tag:
673
    case shl_tag:
674
    case shr_tag:
675
    case bitf_to_int_tag:
676
    case int_to_bitf_tag:
677
    case env_offset_tag:
678
    case general_env_offset_tag:
679
   case env_size_tag: case offset_add_tag: case offset_max_tag:
680
   case offset_pad_tag: case offset_mult_tag: case offset_div_tag:
681
   case offset_div_by_int_tag: case offset_subtract_tag: case offset_negate_tag:
682
      {
7 7u83 683
	long  ee = evalexp(e);
684
	oneval(ee, eval_al(sh(e)), rep);
2 7u83 685
	return;
686
      }
687
   case seq_tag:
688
      {
689
	if (name(son(son(e))) == prof_tag && last(son(son(e))))
690
	   { evalone(bro(son(e)),rep); return;}
691
      }		/* otherwise drop through to failure */
692
 
693
 
694
    default:
7 7u83 695
      failer("tag not in evaluated");
2 7u83 696
 
697
  }				/* end switch */
698
}
699
 
700
 
701
/*****************************************************************
702
evaluated
703
 
704
This outputs data from the evaluated exp into either .sdata or .data
705
depending on size and labels this data either with either id in main_globals
706
or an anonymous label derived from l. The result is the instore "address"
707
of the constant. A negative l implies that this is the initialisation of a global
708
variable.
709
 
710
*****************************************************************/
711
 
712
instore evaluated
7 7u83 713
(exp e, long l, dec * dc)
2 7u83 714
{
715
 
7 7u83 716
  int   lab = (l == 0)? next_dlab_sym()
717
  				:(l< 0)? l: -l;
2 7u83 718
  int   lab0 = lab;
719
  ash a;
720
  instore isa;
721
  exp z = e;
722
 
723
  isa.adval = 0;
724
  isa.b.offset = 0;
725
  isa.b.base = lab0;
726
 
727
 
728
  if (name (e) == clear_tag) {/* uninitialised global */
7 7u83 729
    int   size = (ashof(sh(e)).ashsize + 7) >> 3;
2 7u83 730
    bool temp = (l == 0 ||
731
	(main_globals[-lab - 1] -> dec_u.dec_val.dec_id)[0] == '$');
7 7u83 732
    if (dc != (dec*)0)globalise_name(dc);
2 7u83 733
    if (as_file) {
7 7u83 734
      fprintf(as_file,(temp)? "\t.lcomm\t" : "\t.comm\t");
735
      outlab(lab);
736
      fprintf(as_file, " %d\n", size);
2 7u83 737
    }
7 7u83 738
    out_value((lab >= 0)? tempsnos[lab - 32]: symnos[-lab - 1],
739
	(temp)? ilcomm : icomm, size, 1);
2 7u83 740
 
741
    return isa;
742
  }
743
 
744
 
7 7u83 745
    a = ashof(sh(z));
2 7u83 746
    if (a.ashsize <= G_number) {
747
      if (as_file)
7 7u83 748
	fprintf(as_file, "\t.sdata\n");
749
      out_common(0, isdata);
2 7u83 750
    }
751
    else {
752
      if (as_file)
7 7u83 753
	fprintf(as_file, "\t.data\n");
754
      out_common(0, idata);
2 7u83 755
    }
756
    set_align(a.ashalign);   /* I think this is unnecessary ? bug in as */
7 7u83 757
    if (dc != (dec*)0)globalise_name(dc);
2 7u83 758
    if (as_file) {
7 7u83 759
      outlab(lab);
760
      fprintf(as_file, ":\n");
2 7u83 761
    }
7 7u83 762
    out_common((lab > 0)? tempsnos[lab - 32]: symnos[-lab - 1], ilabel);
763
    evalone(z, 1);
2 7u83 764
 
765
  return isa;
766
}