Subversion Repositories tendra.SVN

Rev

Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 7
Line -... Line 1...
-
 
1
/*
-
 
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
 */
1
/*
31
/*
2
    Copyright (c) 1993 Open Software Foundation, Inc.
32
    Copyright (c) 1993 Open Software Foundation, Inc.
3
 
33
 
4
 
34
 
5
    All Rights Reserved
35
    All Rights Reserved
Line 24... Line 54...
24
    WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
54
    WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25
*/
55
*/
26
 
56
 
27
/*
57
/*
28
    		 Crown Copyright (c) 1997
58
    		 Crown Copyright (c) 1997
29
    
59
 
30
    This TenDRA(r) Computer Program is subject to Copyright
60
    This TenDRA(r) Computer Program is subject to Copyright
31
    owned by the United Kingdom Secretary of State for Defence
61
    owned by the United Kingdom Secretary of State for Defence
32
    acting through the Defence Evaluation and Research Agency
62
    acting through the Defence Evaluation and Research Agency
33
    (DERA).  It is made available to Recipients with a
63
    (DERA).  It is made available to Recipients with a
34
    royalty-free licence for its use, reproduction, transfer
64
    royalty-free licence for its use, reproduction, transfer
35
    to other parties and amendment for any purpose not excluding
65
    to other parties and amendment for any purpose not excluding
36
    product development provided that any such use et cetera
66
    product development provided that any such use et cetera
37
    shall be deemed to be acceptance of the following conditions:-
67
    shall be deemed to be acceptance of the following conditions:-
38
    
68
 
39
        (1) Its Recipients shall ensure that this Notice is
69
        (1) Its Recipients shall ensure that this Notice is
40
        reproduced upon any copies or amended versions of it;
70
        reproduced upon any copies or amended versions of it;
41
    
71
 
42
        (2) Any amended version of it shall be clearly marked to
72
        (2) Any amended version of it shall be clearly marked to
43
        show both the nature of and the organisation responsible
73
        show both the nature of and the organisation responsible
44
        for the relevant amendment or amendments;
74
        for the relevant amendment or amendments;
45
    
75
 
46
        (3) Its onward transfer from a recipient to another
76
        (3) Its onward transfer from a recipient to another
47
        party shall be deemed to be that party's acceptance of
77
        party shall be deemed to be that party's acceptance of
48
        these conditions;
78
        these conditions;
49
    
79
 
50
        (4) DERA gives no warranty or assurance as to its
80
        (4) DERA gives no warranty or assurance as to its
51
        quality or suitability for any purpose and DERA accepts
81
        quality or suitability for any purpose and DERA accepts
52
        no liability whatsoever in relation to any use to which
82
        no liability whatsoever in relation to any use to which
53
        it may be put.
83
        it may be put.
54
*/
84
*/
Line 100... Line 130...
100
#include "eval.h"
130
#include "eval.h"
101
#include "frames.h"
131
#include "frames.h"
102
#include "f64.h"
132
#include "f64.h"
103
extern FILE *as_file;
133
extern FILE *as_file;
104
 
134
 
105
long correct_shape PROTO_S ((long, int));
135
long correct_shape(long, int);
106
 
136
 
107
/* various pieces of info for outputting data depending on shape */
137
/* various pieces of info for outputting data depending on shape */
108
static	mm scmm	=	{127,		-128,		"\t.byte\t%ld\n"};
138
static	mm scmm	=	{127,		-128,		"\t.byte\t%ld\n"};
109
static	mm uscmm =	{255,		0,		"\t.byte\t%ld\n"};
139
static	mm uscmm =	{255,		0,		"\t.byte\t%ld\n"};
110
static	mm shmm	=	{0x7fff,	0xffff8000,	"\t.short\t%ld\n"};
140
static	mm shmm	=	{0x7fff,	0xffff8000,	"\t.short\t%ld\n"};
Line 112... Line 142...
112
static	mm swmm	=	{0x7fffffff,	0x80000000,	"\t.long\t%ld\n"};
142
static	mm swmm	=	{0x7fffffff,	0x80000000,	"\t.long\t%ld\n"};
113
static	mm uswmm =	{0xffffffff,	0,		"\t.long\t%ld\n"};
143
static	mm uswmm =	{0xffffffff,	0,		"\t.long\t%ld\n"};
114
 
144
 
115
 
145
 
116
/* number for anonymous label in data space - L.Dnnn */
146
/* number for anonymous label in data space - L.Dnnn */
117
int next_data_lab PROTO_Z ()
147
int next_data_lab(void)
118
{
148
{
119
  static int data_lab = 100;
149
  static int data_lab = 100;
120
 
150
 
121
  return ++data_lab;
151
  return ++data_lab;
122
}
152
}
123
 
153
 
124
 
154
 
125
/*************************************************************
155
/*************************************************************
126
maxmin
156
maxmin
127
 
157
 
128
finds the data size from the range of an integer shape
158
finds the data size from the range of an integer shape
129
**************************************************************/
159
**************************************************************/
130
mm maxmin PROTO_N ((s)) PROTO_T (shape s)
160
mm maxmin(shape s)
131
{
161
{
132
  switch (name(s))
162
  switch (name(s))
133
  {
163
  {
134
  case scharhd:
164
  case scharhd:
135
    return scmm;
165
    return scmm;
Line 155... Line 185...
155
 
185
 
156
outputs the label parameter if non negative else interprets it
186
outputs the label parameter if non negative else interprets it
157
to be an index into the externals and outputs the identifier.
187
to be an index into the externals and outputs the identifier.
158
**************************************************************/
188
**************************************************************/
159
 
189
 
160
void outlab PROTO_N ((l)) PROTO_T (int l)
190
void outlab(int l)
161
{
191
{
162
  fprintf(as_file, "%s", ext_name(l));
192
  fprintf(as_file, "%s", ext_name(l));
163
}
193
}
164
 
194
 
165
/* translate time evaluate integer exp 'e' */
195
/* translate time evaluate integer exp 'e' */
166
long evalexp PROTO_N ((e)) PROTO_T (exp e)
196
long evalexp(exp e)
167
{
197
{
168
  switch (name(e))
198
  switch (name(e))
169
  {
199
  {
170
   case null_tag:case top_tag:
200
   case null_tag:case top_tag:
171
    return 0;
201
    return 0;
172
   case val_tag:
202
   case val_tag:
173
    {
203
    {
174
      /* offsets appear as bits, but are converted to bytes if alignment 
204
      /* offsets appear as bits, but are converted to bytes if alignment
175
       is not bits */
205
       is not bits */
176
      if (name(sh(e)) == offsethd && al2(sh(e)) >= 8) 
206
      if (name(sh(e)) == offsethd && al2(sh(e)) >= 8)
177
      {
207
      {
178
	return (no(e)>>3);
208
	return(no(e) >>3);
179
      }
209
      }
180
      return no(e);
210
      return no(e);
181
    }
211
    }
182
    case env_size_tag :
212
    case env_size_tag:
183
    {
213
    {
184
      exp tg = son(son(e));
214
      exp tg = son(son(e));
185
      procrec *pr = &procrecs[no(son(tg))];
215
      procrec *pr = &procrecs[no(son(tg))];
186
      return ((pr->frame_size)>>3) + pr->max_callee_bytes;
216
      return((pr->frame_size) >>3) + pr->max_callee_bytes;
187
    }
-
 
188
    case offset_add_tag : {
-
 
189
      return (evalexp(son(e)) + evalexp(bro(son(e))));
-
 
190
    }
-
 
191
    case offset_max_tag : {
-
 
192
      return (max(evalexp(son(e)),evalexp(bro(son(e)))));
-
 
193
    }
-
 
194
    case offset_pad_tag : {
-
 
195
      return (rounder(evalexp(son(e)),shape_align(sh(e))));
-
 
196
    }
-
 
197
    case offset_mult_tag : {
-
 
198
      return (evalexp(son(e))*evalexp(bro(son(e))));
-
 
199
    }
217
    }
200
    case offset_div_tag :
218
    case offset_add_tag: {
201
    case offset_div_by_int_tag : {
-
 
202
      return (evalexp(son(e))/evalexp(bro(son(e))));
219
      return(evalexp(son(e)) + evalexp(bro(son(e))));
203
    }
220
    }
204
    case offset_subtract_tag : {
221
    case offset_max_tag: {
205
      return (evalexp(son(e))-evalexp(bro(son(e))));
222
      return(max(evalexp(son(e)),evalexp(bro(son(e)))));
206
    }
223
    }
207
    case offset_negate_tag : {
224
    case offset_pad_tag: {
208
      return (- evalexp(son(e)));
225
      return(rounder(evalexp(son(e)),shape_align(sh(e))));
209
    }
226
    }
-
 
227
    case offset_mult_tag: {
-
 
228
      return(evalexp(son(e))*evalexp(bro(son(e))));
-
 
229
    }
-
 
230
    case offset_div_tag:
-
 
231
    case offset_div_by_int_tag: {
-
 
232
      return(evalexp(son(e)) /evalexp(bro(son(e))));
-
 
233
    }
-
 
234
    case offset_subtract_tag: {
-
 
235
      return(evalexp(son(e)) -evalexp(bro(son(e))));
-
 
236
    }
-
 
237
    case offset_negate_tag: {
-
 
238
      return(- evalexp(son(e)));
-
 
239
    }
-
 
240
 
210
 
241
 
211
    
-
 
212
   case chvar_tag:
242
   case chvar_tag:
213
    {
243
    {
214
      return correct_shape(evalexp(son(e)),name(sh(e)));
244
      return correct_shape(evalexp(son(e)),name(sh(e)));
215
    }
245
    }
216
   case bitf_to_int_tag:
246
   case bitf_to_int_tag:
Line 239... Line 269...
239
      return correct_shape(~evalexp(son(e)),name(sh(e)));
269
      return correct_shape(~evalexp(son(e)),name(sh(e)));
240
    }
270
    }
241
 
271
 
242
   case and_tag:
272
   case and_tag:
243
    {
273
    {
244
      return (evalexp(son(e)) & evalexp(bro(son(e))));
274
      return(evalexp(son(e)) & evalexp(bro(son(e))));
245
    }
275
    }
246
 
276
 
247
   case or_tag:
277
   case or_tag:
248
    {
278
    {
249
      return (evalexp(son(e)) | evalexp(bro(son(e))));
279
      return(evalexp(son(e)) | evalexp(bro(son(e))));
250
    }
280
    }
251
 
281
 
252
   case xor_tag:
282
   case xor_tag:
253
    {
283
    {
254
      return (evalexp(son(e)) ^ evalexp(bro(son(e))));
284
      return(evalexp(son(e))^ evalexp(bro(son(e))));
255
    }
285
    }
256
 
286
 
257
   case shr_tag:
287
   case shr_tag:
258
    {
288
    {
259
      bool sgned = is_signed(sh(e));
289
      bool sgned = is_signed(sh(e));
260
      long sl;
290
      long sl;
261
      unsigned long ul;
291
      unsigned long ul;
262
      if (sgned)
292
      if (sgned)
263
      {
293
      {
264
	sl = (long)correct_shape(evalexp(son(e)),name(sh(e)));
294
	sl = (long)correct_shape(evalexp(son(e)),name(sh(e)));
265
	return ( sl >> evalexp(bro(son(e))) );
295
	return(sl >> evalexp(bro(son(e))));
266
      }
296
      }
267
      else
297
      else
268
      {
298
      {
269
	ul = (unsigned long)correct_shape(evalexp(son(e)),name(sh(e)));
299
	ul = (unsigned long)correct_shape(evalexp(son(e)),name(sh(e)));
270
	return ( ul >> evalexp(bro(son(e))) );
300
	return(ul >> evalexp(bro(son(e))));
271
      }
301
      }
272
    }
302
    }
273
 
303
 
274
  case shl_tag:
304
  case shl_tag:
275
    {
305
    {
276
      return correct_shape(evalexp(son(e))<<evalexp(bro(son(e))),name(sh(e)));
306
      return correct_shape(evalexp(son(e)) <<evalexp(bro(son(e))),name(sh(e)));
277
    }
307
    }
278
 
308
 
279
  case concatnof_tag:
309
  case concatnof_tag:
280
    {
310
    {
281
      unsigned long w_lhs = evalexp(son(e));
311
      unsigned long w_lhs = evalexp(son(e));
Line 286... Line 316...
286
 
316
 
287
      ASSERT(ash_lhs.ashalign==1 && ash_lhs.ashsize<=32);
317
      ASSERT(ash_lhs.ashalign==1 && ash_lhs.ashsize<=32);
288
      ASSERT(ash_rhs.ashalign==1 && ash_rhs.ashsize<=32);
318
      ASSERT(ash_rhs.ashalign==1 && ash_rhs.ashsize<=32);
289
      ASSERT(ash_lhs.ashsize+ash_rhs.ashsize<=32);
319
      ASSERT(ash_lhs.ashsize+ash_rhs.ashsize<=32);
290
 
320
 
291
      FULLCOMMENT4("evalexp() concatnof_tag: lhs,rhs=%#x,%#x ash(rhs)=%d,%d",
321
      FULLCOMMENT4("evalexp() concatnof_tag: lhs,rhs=%#x,%#x ash(rhs) =%d,%d",
292
		w_lhs, w_rhs, ash_rhs.ashalign, ash_rhs.ashsize);
322
		w_lhs, w_rhs, ash_rhs.ashalign, ash_rhs.ashsize);
293
 
323
 
294
      if (ash_rhs.ashsize == 32)
324
      if (ash_rhs.ashsize == 32)
295
      {
325
      {
296
	/* avoid illegal shift by 32 */
326
	/* avoid illegal shift by 32 */
297
	ASSERT(w_lhs==0);
327
	ASSERT(w_lhs==0);
298
	return w_rhs;
328
	return w_rhs;
299
      }
329
      }
300
      return (w_lhs << ash_rhs.ashsize) | w_rhs;
330
      return(w_lhs << ash_rhs.ashsize) | w_rhs;
301
    }
331
    }
302
 
332
 
303
  case clear_tag:
333
  case clear_tag:
304
    {
334
    {
305
      ash a;
335
      ash a;
Line 335... Line 365...
335
  unsigned long		value;
365
  unsigned long		value;
336
};
366
};
337
typedef struct concbittypet	concbittype;
367
typedef struct concbittypet	concbittype;
338
 
368
 
339
 
369
 
340
static concbittype emptyconcbit PROTO_N ((bitposn)) PROTO_T (int bitposn)
370
static concbittype emptyconcbit(int bitposn)
341
{
371
{
342
  concbittype start;
372
  concbittype start;
343
 
373
 
344
  start.bitposn = bitposn;
374
  start.bitposn = bitposn;
345
  start.value_size = 0;
375
  start.value_size = 0;
Line 347... Line 377...
347
 
377
 
348
  return start;
378
  return start;
349
}
379
}
350
 
380
 
351
 
381
 
352
static void outconcbit PROTO_N ((c)) PROTO_T (concbittype c)
382
static void outconcbit(concbittype c)
353
{
383
{
354
  unsigned long w = c.value;
384
  unsigned long w = c.value;
355
  int bytes = (c.value_size + 7) / 8;
385
  int bytes = (c.value_size + 7) / 8;
356
  int i;
386
  int i;
357
 
387
 
Line 372... Line 402...
372
  fprintf(as_file, "\t.byte\t");
402
  fprintf(as_file, "\t.byte\t");
373
  for (i = 0; i < bytes; i++)
403
  for (i = 0; i < bytes; i++)
374
  {
404
  {
375
    if (i != 0)
405
    if (i != 0)
376
      fprintf(as_file, ",");
406
      fprintf(as_file, ",");
377
    fprintf(as_file, "%#lx", (w >> 24) & 255);
407
    fprintf(as_file, "%#lx",(w >> 24) & 255);
378
    w = w << 8;
408
    w = w << 8;
379
  }
409
  }
380
  fprintf(as_file, "\n");
410
  fprintf(as_file, "\n");
381
  ASSERT(w == 0);
411
  ASSERT(w == 0);
382
}
412
}
383
/*
413
/*
384
  Output a unary representation of the number val.  val should be 
414
  Output a unary representation of the number val.  val should be
385
  less than or equal to 31 as it represent the number of bits
415
  less than or equal to 31 as it represent the number of bits
386
  in a bitfield which does not occupy a whole machine word.
416
  in a bitfield which does not occupy a whole machine word.
387
*/
417
*/
388
long unary PROTO_N ((val)) PROTO_T (int val)
418
long unary(int val)
389
{
419
{
390
  int loop;
420
  int loop;
391
  long result=0;
421
  long result=0;
392
  ASSERT(val <=31);
422
  ASSERT(val <=31);
393
  for(loop=0;loop<val;++loop)
423
  for (loop=0;loop<val;++loop)
394
  {
424
  {
395
    result <<=1;
425
    result <<=1;
396
    result |= 1;
426
    result |= 1;
397
  }
427
  }
398
  return result;
428
  return result;
399
}
429
}
400
 
430
 
401
 
431
 
402
 
432
 
403
static concbittype addconcbitaux PROTO_N ((w,size,before)) PROTO_T (unsigned long w X int size X concbittype before)
433
static concbittype addconcbitaux(unsigned long w, int size, concbittype before)
404
{
434
{
405
  int wordbitposn;			/* 0..32 bit position in current word,
435
  int wordbitposn;			/* 0..32 bit position in current word,
406
					 * 0 only at start of bit sequence */
436
					 * 0 only at start of bit sequence */
407
  
437
 
408
  if (before.value_size==32 || (before.value_size != 0 && (before.bitposn&31)==0))
438
  if (before.value_size==32 || (before.value_size != 0 && (before.bitposn&31) ==0))
409
  {
439
  {
410
    ASSERT((before.bitposn&31)==0);
440
    ASSERT((before.bitposn&31) ==0);
411
    wordbitposn = 32;
441
    wordbitposn = 32;
412
  }
442
  }
413
  else
443
  else
414
  {
444
  {
415
    wordbitposn = (before.bitposn&31);
445
    wordbitposn = (before.bitposn&31);
416
  }
446
  }
417
  
447
 
418
  FULLCOMMENT2("addconcbitaux() sz=%d w=%d",
448
  FULLCOMMENT2("addconcbitaux() sz=%d w=%d",
419
	       size, w);
449
	       size, w);
420
  FULLCOMMENT4("\tbefore=%d(%d) %#x:%d",
450
  FULLCOMMENT4("\tbefore=%d(%d) %#x:%d",
421
	       before.bitposn, wordbitposn, before.value, before.value_size);
451
	       before.bitposn, wordbitposn, before.value, before.value_size);
422
#if 0
452
#if 0
423
  ASSERT(size>0);		/* no longer have to handle zero for C */
453
  ASSERT(size>0);		/* no longer have to handle zero for C */
424
#endif
454
#endif
425
  ASSERT(size<=32);
455
  ASSERT(size<=32);
426
  
456
 
427
  ASSERT(before.value_size<=32);
457
  ASSERT(before.value_size<=32);
428
  ASSERT(wordbitposn==0 || before.value_size<=wordbitposn);
458
  ASSERT(wordbitposn==0 || before.value_size<=wordbitposn);
429
  
459
 
430
  if (
460
  if (
431
      (size == 0 && (wordbitposn != 0 || before.value_size != 0))
461
     (size == 0 && (wordbitposn != 0 || before.value_size != 0))
432
      ||
462
      ||
433
      (wordbitposn + size > 32)
463
     (wordbitposn + size > 32)
434
      )
464
     )
435
  {
465
  {
436
    /*
466
    /*
437
     * C zero size bitfield, align to word boundary; or
467
     * C zero size bitfield, align to word boundary; or
438
     * would go over word boundary, so output before and padding.
468
     * would go over word boundary, so output before and padding.
439
     */
469
     */
440
    int pad_bits = 32 - wordbitposn;
470
    int pad_bits = 32 - wordbitposn;
441
    
471
 
442
#if 1
472
#if 1
443
    ASSERT(pad_bits==0);		/* padding should now be explicit */
473
    ASSERT(pad_bits==0);		/* padding should now be explicit */
444
    
474
 
445
    before.value_size += pad_bits;
475
    before.value_size += pad_bits;
446
    before.value <<= pad_bits;
476
    before.value <<= pad_bits;
447
#endif
477
#endif
448
    
478
 
449
    outconcbit(before);
479
    outconcbit(before);
450
    
480
 
451
    /* clear before, as it has been output */
481
    /* clear before, as it has been output */
452
    before.bitposn += pad_bits;
482
    before.bitposn += pad_bits;
453
    before.value_size = 0;
483
    before.value_size = 0;
454
    before.value = 0;
484
    before.value = 0;
455
    
485
 
456
    /* should be at word boundary */
486
    /* should be at word boundary */
457
    ASSERT((before.bitposn&31)==0);
487
    ASSERT((before.bitposn&31) ==0);
458
  }
488
  }
459
  
489
 
460
  if (size == 0)
490
  if (size == 0)
461
    return before;
491
    return before;
462
  
492
 
463
  /* add to before */
493
  /* add to before */
464
  before.bitposn += size;
494
  before.bitposn += size;
465
  before.value_size += size;
495
  before.value_size += size;
466
  if (size == 32)
496
  if (size == 32)
467
    before.value = w;
497
    before.value = w;
468
  else
498
  else
469
    before.value = (before.value << size) | (w & unary(size));
499
    before.value = (before.value << size) | (w & unary(size));
470
  
500
 
471
  FULLCOMMENT4("\t after=%d(%d) %#x:%d",
501
  FULLCOMMENT4("\t after=%d(%d) %#x:%d",
472
	       before.bitposn, wordbitposn, before.value, before.value_size);
502
	       before.bitposn, wordbitposn, before.value, before.value_size);
473
  
503
 
474
  ASSERT(before.value_size<=32);
504
  ASSERT(before.value_size<=32);
475
  
505
 
476
  return before;
506
  return before;
477
}
507
}
478
 
508
 
479
 
509
 
480
static concbittype evalconcbitaux PROTO_N ((e,before)) PROTO_T (exp e X concbittype before)
510
static concbittype evalconcbitaux(exp e, concbittype before)
481
{
511
{
482
  switch (name(e))
512
  switch (name(e))
483
  {
513
  {
484
  case concatnof_tag:
514
  case concatnof_tag:
485
    {
515
    {
486
      concbittype lhs, rhs;
516
      concbittype lhs, rhs;
487
      lhs = evalconcbitaux(son(e), before);
517
      lhs = evalconcbitaux(son(e), before);
488
      rhs = evalconcbitaux(bro(son(e)), lhs);
518
      rhs = evalconcbitaux(bro(son(e)), lhs);
489
 
519
 
490
      return rhs;
520
      return rhs;
491
    }
521
    }
492
 
522
 
493
  default:
523
  default:
494
    {
524
    {
495
      ASSERT(shape_align(sh(e))==1);
525
      ASSERT(shape_align(sh(e)) ==1);
496
 
526
 
497
      return addconcbitaux(evalexp(e), shape_size(sh(e)), before);
527
      return addconcbitaux(evalexp(e), shape_size(sh(e)), before);
498
    }
528
    }
499
  }
529
  }
500
}
530
}
501
 
531
 
502
 
532
 
503
static void evalconcbit PROTO_N ((e,bitposn)) PROTO_T (exp e X int bitposn)
533
static void evalconcbit(exp e, int bitposn)
504
{
534
{
505
  concbittype start;
535
  concbittype start;
506
  start = emptyconcbit(bitposn);
536
  start = emptyconcbit(bitposn);
507
 
537
 
508
  outconcbit(evalconcbitaux(e, start));
538
  outconcbit(evalconcbitaux(e, start));
509
}
539
}
510
 
540
 
511
 
541
 
512
 
542
 
513
static void set_align PROTO_N ((al)) PROTO_T (int al)
543
static void set_align(int al)
514
{
544
{
515
  /* output .align if needed */
545
  /* output .align if needed */
516
  switch (al)
546
  switch (al)
517
  {
547
  {
518
  case 0:
548
  case 0:
519
  case 1:
549
  case 1:
520
  case 8:
550
  case 8:
521
    break;
551
    break;
522
 
552
 
523
  case 16:
553
  case 16:
524
    fprintf(as_file, "\t.align\t1\n");
554
    fprintf(as_file, "\t.align\t1\n");
525
    break;
555
    break;
526
 
556
 
527
  case 32:
557
  case 32:
528
    fprintf(as_file, "\t.align\t2\n");
558
    fprintf(as_file, "\t.align\t2\n");
529
    break;
559
    break;
530
 
560
 
531
  case 64:
561
  case 64:
532
    fprintf(as_file, "\t.align\t3\n");
562
    fprintf(as_file, "\t.align\t3\n");
533
    break;
563
    break;
534
 
564
 
535
  default:
565
  default:
536
    fail("unexpected alignment");
566
    fail("unexpected alignment");
537
  }
567
  }
538
}
568
}
539
 
569
 
540
 
570
 
541
 
571
 
542
static void evalone PROTO_N ((e,bitposn)) PROTO_T (exp e X int bitposn)
572
static void evalone(exp e, int bitposn)
543
{
573
{
544
  ash a;
574
  ash a;
545
 
575
 
546
  a = ashof(sh(e));
576
  a = ashof(sh(e));
547
 
577
 
548
  COMMENT4("evalone: name(e)=%d, bitposn=%d, ash=%d,%d", name(e), 
578
  COMMENT4("evalone: name(e) =%d, bitposn=%d, ash=%d,%d", name(e),
549
	   bitposn, a.ashsize, a.ashalign);
579
	   bitposn, a.ashsize, a.ashalign);
550
  COMMENT1("evalone no(e)=%d",no(e));
580
  COMMENT1("evalone no(e) =%d",no(e));
551
  
581
 
552
  set_align(a.ashalign);
582
  set_align(a.ashalign);
553
 
583
 
554
  /* align bitposn */
584
  /* align bitposn */
555
  if (a.ashalign != 0)
585
  if (a.ashalign != 0)
556
  {
586
  {
557
    bitposn = (bitposn / a.ashalign) * a.ashalign;
587
    bitposn = (bitposn / a.ashalign)* a.ashalign;
558
  }
588
  }
559
  
589
 
560
  /* generate data initialiser for e */
590
  /* generate data initialiser for e */
561
  switch (name(e))
591
  switch (name(e))
562
  {
592
  {
563
   case string_tag:
593
   case string_tag:
564
    {
594
    {
565
      long char_size = props(e);	/* bits width of each output char */
595
      long char_size = props(e);	/* bits width of each output char */
566
      long strsize = shape_size(sh(e)) / char_size;
596
      long strsize = shape_size(sh(e)) / char_size;
567
      unsigned char *st = (unsigned char *)nostr(e);
597
      unsigned char *st = (unsigned char *)nostr(e);
568
      int i;
598
      int i;
569
      
599
 
570
      if (char_size != 8 )
600
      if (char_size != 8)
571
      {
601
      {
572
	/* wide chars, generate a .XXX line for each */
602
	/* wide chars, generate a .XXX line for each */
573
	for (i = 0; i <strsize; i++)
603
	for (i = 0; i <strsize; i++)
574
	{
604
	{
575
	  unsigned int c;
605
	  unsigned int c;
576
	  char *directive;
606
	  char *directive;
577
	  
607
 
578
	  switch(char_size)
608
	  switch (char_size)
579
	  {
609
	  {
580
	   case 16:	
610
	   case 16:
581
	    c = ((unsigned short *)st)[i];
611
	    c = ((unsigned short *)st)[i];
582
	    directive = ".short";
612
	    directive = ".short";
583
	    break;
613
	    break;
584
	   case 32:	
614
	   case 32:
585
	    c = ((unsigned int *)st)[i]; 
615
	    c = ((unsigned int *)st)[i];
586
	    directive = ".long";
616
	    directive = ".long";
587
	    break;
617
	    break;
588
	    /* +++ case 64 ??? */
618
	    /* +++ case 64 ??? */
589
	   default:	
619
	   default:
590
	    fail("unexpected wide char data width");
620
	    fail("unexpected wide char data width");
591
	  }
621
	  }
592
	  fprintf(as_file, "\t%s\t%#x\n", directive, c);
622
	  fprintf(as_file, "\t%s\t%#x\n", directive, c);
593
	}
623
	}
594
 
624
 
595
	return;
625
	return;
596
      }
626
      }
597
      
627
 
598
      /* output as ascii where possible for the human reader */
628
      /* output as ascii where possible for the human reader */
599
      while (strsize > 0)
629
      while (strsize > 0)
600
      {
630
      {
601
	int c = *st;
631
	int c = *st;
602
 
632
 
603
	if (c >= 32 && c < 127)
633
	if (c >= 32 && c < 127)
604
	{
634
	{
605
	  fprintf(as_file, "\t.byte\t\"");
635
	  fprintf(as_file,
606
 
-
 
607
	  for (i = 0; strsize > 0 && i < 48 && c >= 32 && c < 127; i++)
636
	  for (i = 0; strsize > 0 && i < 48 && c >= 32 && c < 127; i++)
608
	  {
637
	  {
609
	    if (c != '"')
638
	    if (c != '"')
610
	      putc(c, as_file);
639
	      putc(c, as_file);
611
	    else
640
	    else
612
	      fprintf(as_file, "\"\"");		/* " represented as "" */
641
	      fprintf(as_file, "\"\"");		/* " represented as "" */
613
 
642
 
Line 642... Line 671...
642
 
671
 
643
  case real_tag:
672
  case real_tag:
644
    {
673
    {
645
      flt *f = flptnos + no(e);
674
      flt *f = flptnos + no(e);
646
      r2l v;
675
      r2l v;
647
      
676
 
648
      if (a.ashsize==32) 
677
      if (a.ashsize==32)
649
      {
678
      {
650
	v=real2longs_IEEE(f,0);
679
	v=real2longs_IEEE(f,0);
651
	fprintf(as_file,"\t.long\t");
680
	fprintf(as_file,"\t.long\t");
652
	fprintf(as_file,"%ld",(long)v.i1);
681
	fprintf(as_file,"%ld",(long)v.i1);
653
      } 
682
      }
654
      else if (a.ashsize==64) 
683
      else if (a.ashsize==64)
655
      {
684
      {
656
	v=real2longs_IEEE(f,1);
685
	v=real2longs_IEEE(f,1);
657
	fprintf(as_file,"\t.long\t");
686
	fprintf(as_file,"\t.long\t");
658
	fprintf(as_file,"%ld",(long)v.i2);
687
	fprintf(as_file,"%ld",(long)v.i2);
659
	fprintf(as_file,",");   
688
	fprintf(as_file,",");
660
	fprintf(as_file,"%ld",(long)v.i1);
689
	fprintf(as_file,"%ld",(long)v.i1);
661
      } 
690
      }
662
      else 
691
      else
663
      {
692
      {
664
	v=real2longs_IEEE(f,2);
693
	v=real2longs_IEEE(f,2);
665
	fprintf(as_file,"\t.long\t");
694
	fprintf(as_file,"\t.long\t");
666
	fprintf(as_file,"%ld",(long)v.i4);
695
	fprintf(as_file,"%ld",(long)v.i4);
667
	fprintf(as_file,",");
696
	fprintf(as_file,",");
668
	fprintf(as_file,"%ld",(long)v.i3);
697
	fprintf(as_file,"%ld",(long)v.i3);
669
	fprintf(as_file,",") ;
698
	fprintf(as_file,",");
670
	fprintf(as_file,"%ld",(long)v.i2);	
699
	fprintf(as_file,"%ld",(long)v.i2);
671
	fprintf(as_file,",");
700
	fprintf(as_file,",");
672
	fprintf(as_file,"%ld",(long)v.i1);
701
	fprintf(as_file,"%ld",(long)v.i1);
673
      }
702
      }
674
      fprintf(as_file, "\n") ;
703
      fprintf(as_file, "\n");
675
      return;
704
      return;
676
    }
705
    }
677
   case null_tag:case top_tag:
706
   case null_tag:case top_tag:
678
    no(e) = 0;
707
    no(e) = 0;
679
    /* FALLTHROUGH */
708
    /* FALLTHROUGH */
680
   case val_tag:
709
   case val_tag:
681
    {
710
    {
682
      char *asdata;
711
      char *asdata;
683
      
712
 
684
      FULLCOMMENT1("evalone() val_tag: %d", val_tag);
713
      FULLCOMMENT1("evalone() val_tag: %d", val_tag);
685
      
714
 
686
      /* allow 64 bit integers */
715
      /* allow 64 bit integers */
687
      if (shape_size(sh(e))>32)
716
      if (shape_size(sh(e)) >32)
688
      {
717
      {
689
	flt64 temp;
718
	flt64 temp;
690
	int ov;
719
	int ov;
691
	if (isbigval(e)) 
720
	if (isbigval(e))
692
	{
721
	{
693
	  temp = flt_to_f64(no(e), 0, &ov);
722
	  temp = flt_to_f64(no(e), 0, &ov);
694
	}
723
	}
695
	else 
724
	else
696
	{
725
	{
697
	  temp.big = (is_signed(sh(e)) && no(e)<0)?-1:0;
726
	  temp.big = (is_signed(sh(e)) && no(e) <0)?-1:0;
698
	  temp.small = no(e);
727
	  temp.small = no(e);
699
	}
728
	}
700
	fprintf(as_file,"\t.long\t%ld\n",(long)temp.small);
729
	fprintf(as_file,"\t.long\t%ld\n",(long)temp.small);
701
	fprintf(as_file,"\t.long\t%ld\n",(long)temp.big);
730
	fprintf(as_file,"\t.long\t%ld\n",(long)temp.big);
702
	return;
731
	return;
Line 735... Line 764...
735
      {
764
      {
736
	fprintf(as_file, "\t.long\t%s\n", nm);
765
	fprintf(as_file, "\t.long\t%s\n", nm);
737
      }
766
      }
738
      else
767
      else
739
      {
768
      {
740
	fprintf(as_file, "\t.long\t%s+%ld\n", nm, (long)(no(e)/8));
769
	fprintf(as_file, "\t.long\t%s+%ld\n", nm,(long)(no(e) /8));
741
      }
770
      }
742
 
771
 
743
      return;
772
      return;
744
    }
773
    }
745
 
774
 
Line 767... Line 796...
767
 
796
 
768
	COMMENT4("evalone compound_tag: gap=%d off=%d ash=%d,%d",
797
	COMMENT4("evalone compound_tag: gap=%d off=%d ash=%d,%d",
769
		gap, no(off), tupa.ashsize, tupa.ashalign);
798
		gap, no(off), tupa.ashsize, tupa.ashalign);
770
 
799
 
771
	/* check that component's alignment matches offset in struct */
800
	/* check that component's alignment matches offset in struct */
772
	ASSERT((no(off)/tupa.ashalign)*tupa.ashalign <= no(off));
801
	ASSERT((no(off) /tupa.ashalign)*tupa.ashalign <= no(off));
773
 
802
 
774
	/* and is no greater that struct's alignment */
803
	/* and is no greater that struct's alignment */
775
	ASSERT(tupa.ashalign<=maxalign);
804
	ASSERT(tupa.ashalign<=maxalign);
776
 
805
 
777
	if (no(off) < last_offset)
806
	if (no(off) < last_offset)
Line 787... Line 816...
787
	  }
816
	  }
788
	}
817
	}
789
	else
818
	else
790
	{
819
	{
791
	  /* alignment will handle gap */
820
	  /* alignment will handle gap */
792
	  remainderbits.bitposn = ((remainderbits.bitposn + (tupa.ashalign-1)) / tupa.ashalign) * tupa.ashalign;
821
	  remainderbits.bitposn = ((remainderbits.bitposn + (tupa.ashalign-1)) / tupa.ashalign)* tupa.ashalign;
793
	}
822
	}
794
 
823
 
795
	last_offset = no(off);
824
	last_offset = no(off);
796
	last_align = tupa.ashalign;
825
	last_align = tupa.ashalign;
797
 
826
 
Line 823... Line 852...
823
	  ASSERT(a.ashsize >= databits);
852
	  ASSERT(a.ashsize >= databits);
824
 
853
 
825
	  /* pad out trailing unitialised space, eg union */
854
	  /* pad out trailing unitialised space, eg union */
826
	  if (a.ashsize > databits && trailing_bytes > 0)
855
	  if (a.ashsize > databits && trailing_bytes > 0)
827
	  {
856
	  {
828
	    fprintf(as_file, "\t.space\t%d\n", (int)trailing_bytes);
857
	    fprintf(as_file, "\t.space\t%d\n",(int)trailing_bytes);
829
	  }
858
	  }
830
	  return;
859
	  return;
831
	}
860
	}
832
 
861
 
833
	off = bro(bro(off));
862
	off = bro(bro(off));
Line 869... Line 898...
869
      }
898
      }
870
 
899
 
871
      e = son(e);
900
      e = son(e);
872
      copya = ashof(sh(e));
901
      copya = ashof(sh(e));
873
      if (copya.ashalign != 0)
902
      if (copya.ashalign != 0)
874
	bitsize = (copya.ashsize / copya.ashalign) * copya.ashalign;
903
	bitsize = (copya.ashsize / copya.ashalign)* copya.ashalign;
875
      else
904
      else
876
	bitsize = 0;		/* probably never happen! */
905
	bitsize = 0;		/* probably never happen! */
877
 
906
 
878
      for (i = 0; i < n; i++)
907
      for (i = 0; i < n; i++)
879
      {
908
      {
Line 901... Line 930...
901
	evalone(son(e), bitposn);
930
	evalone(son(e), bitposn);
902
	bitposn += a.ashsize;
931
	bitposn += a.ashsize;
903
 
932
 
904
	a = ashof(sh(bro(son(e))));
933
	a = ashof(sh(bro(son(e))));
905
	if (a.ashalign != 0)
934
	if (a.ashalign != 0)
906
	  bitposn = (bitposn / a.ashalign) * a.ashalign;
935
	  bitposn = (bitposn / a.ashalign)* a.ashalign;
907
	evalone(bro(son(e)), bitposn);
936
	evalone(bro(son(e)), bitposn);
908
      }
937
      }
909
      return;
938
      return;
910
    }
939
    }
911
 
940
 
Line 914... Line 943...
914
      /* allow for bitfields */
943
      /* allow for bitfields */
915
      if (a.ashalign == 1)
944
      if (a.ashalign == 1)
916
      {
945
      {
917
	evalconcbit(e, bitposn);
946
	evalconcbit(e, bitposn);
918
	return;
947
	return;
919
      }
948
      }
920
 
949
 
921
      fprintf(as_file, "\t.space\t%ld\n", (a.ashsize + 7) >> 3);
950
      fprintf(as_file, "\t.space\t%ld\n",(a.ashsize + 7) >> 3);
922
      return;
951
      return;
923
    }
952
    }
924
 
953
 
925
   case not_tag:
954
   case not_tag:
926
   case and_tag:
955
   case and_tag:
Line 930... Line 959...
930
   case bitf_to_int_tag:
959
   case bitf_to_int_tag:
931
   case int_to_bitf_tag:
960
   case int_to_bitf_tag:
932
   case chvar_tag:
961
   case chvar_tag:
933
    case env_offset_tag:case env_size_tag:
962
    case env_offset_tag:case env_size_tag:
934
    case general_env_offset_tag:
963
    case general_env_offset_tag:
935
    case offset_add_tag : case offset_max_tag :
964
    case offset_add_tag: case offset_max_tag:
936
    case offset_pad_tag : case offset_mult_tag : case offset_div_tag :
965
    case offset_pad_tag: case offset_mult_tag: case offset_div_tag:
937
    case offset_div_by_int_tag : case offset_subtract_tag : 
966
    case offset_div_by_int_tag: case offset_subtract_tag:
938
    case offset_negate_tag:
967
    case offset_negate_tag:
939
     
968
 
940
    {
969
    {
941
      fprintf(as_file, "\t.long\t%ld\n", evalexp(e));
970
      fprintf(as_file, "\t.long\t%ld\n", evalexp(e));
942
      return;
971
      return;
943
    }
972
    }
944
   case minptr_tag:
973
   case minptr_tag:
945
    {
974
    {
946
      exp p1 = son(e);
975
      exp p1 = son(e);
947
      exp p2 = bro(p1);
976
      exp p2 = bro(p1);
948
      if (name(p1)==name_tag && name(p2)==name_tag)
977
      if (name(p1) ==name_tag && name(p2) ==name_tag)
949
      {
978
      {
950
	long n = no(p1)-no(p2);
979
	long n = no(p1) -no(p2);
951
	char *n1 = brog(son(p1))->dec_u.dec_val.dec_id ;
980
	char *n1 = brog(son(p1)) ->dec_u.dec_val.dec_id;
952
	char *n2 = brog(son(p2))->dec_u.dec_val.dec_id ;
981
	char *n2 = brog(son(p2)) ->dec_u.dec_val.dec_id;
953
	fprintf(as_file,"\t.long\t(%s-%s)",n1,n2);
982
	fprintf(as_file,"\t.long\t(%s-%s)",n1,n2);
954
	if(n<0)
983
	if (n<0)
955
	{
984
	{
956
	  fprintf(as_file,"%ld",n);
985
	  fprintf(as_file,"%ld",n);
957
	}
986
	}
958
	else if (n>0)
987
	else if (n>0)
959
	{
988
	{
Line 961... Line 990...
961
	}
990
	}
962
	fprintf(as_file,"\n");
991
	fprintf(as_file,"\n");
963
      }
992
      }
964
      return;
993
      return;
965
    }
994
    }
966
     
995
 
967
   default:
996
   default:
968
    COMMENT1("tag not in evaluated: %d", name(e));
997
    COMMENT1("tag not in evaluated: %d", name(e));
969
    fail("illegal constant");
998
    fail("illegal constant");
970
  }				/* end switch */
999
  }				/* end switch */
971
}
1000
}
972
 
1001
 
973
 
1002
 
974
 
1003
 
975
/*
1004
/*
976
 * Outputs data initialisers for the evaluated exp.
1005
 * Outputs data initialisers for the evaluated exp.
977
 * The result is the instore "address" of the constant.
1006
 * The result is the instore "address" of the constant.
978
 * A negative l implies that this is the initialisation of a global variable.
1007
 * A negative l implies that this is the initialisation of a global variable.
979
 */
1008
 */
980
instore evaluated PROTO_N ((e,l)) PROTO_T (exp e X int l)
1009
instore evaluated(exp e, int l)
981
{
1010
{
982
  int lab = (l == 0) ? next_data_lab() : (l < 0) ? l : -l;
1011
  int lab = (l == 0)? next_data_lab():(l < 0)? l : -l;
983
  instore isa;
1012
  instore isa;
984
  ash a;
1013
  ash a;
985
  char *extname = ext_name(lab);
1014
  char *extname = ext_name(lab);
986
  a = ashof(sh(e));
1015
  a = ashof(sh(e));
987
 
1016
 
Line 998... Line 1027...
998
    bool temp = (l == 0 || (extname[0] == local_prefix[0] && extname[1] == local_prefix[1]));
1027
    bool temp = (l == 0 || (extname[0] == local_prefix[0] && extname[1] == local_prefix[1]));
999
 
1028
 
1000
    if (temp)
1029
    if (temp)
1001
    {
1030
    {
1002
      fprintf(as_file, "\t.lcomm\t");
1031
      fprintf(as_file, "\t.lcomm\t");
1003
    }
1032
    }
1004
    else
1033
    else
1005
    {
1034
    {
1006
      fprintf(as_file, "\t.comm\t");
1035
      fprintf(as_file, "\t.comm\t");
1007
    }
1036
    }
1008
    outlab(lab);
1037
    outlab(lab);
1009
    fprintf(as_file, ",%ld\n", byte_size);
1038
    fprintf(as_file, ",%ld\n", byte_size);
Line 1029... Line 1058...
1029
  }
1058
  }
1030
 
1059
 
1031
  return isa;
1060
  return isa;
1032
}
1061
}
1033
 
1062
 
1034
 
1063
 
1035
instore evaluated_const PROTO_N ((e)) PROTO_T (exp e)
1064
instore evaluated_const(exp e)
1036
{
1065
{
1037
  instore isa;
1066
  instore isa;
1038
  int lab;
1067
  int lab;
1039
  char *id;
1068
  char *id;
1040
 
1069
 
1041
  /* +++ to share consts */
1070
  /* +++ to share consts */
1042
 
1071
 
1043
  /* generate read only data */
1072
  /* generate read only data */
1044
  fprintf(as_file, "\t.csect\t[RO]\n");
1073
  fprintf(as_file, "\t.csect\t[RO]\n");
1045
 
1074
 
1046
  isa = evaluated(e, 0);
1075
  isa = evaluated(e, 0);
1047
 
1076
 
1048
  lab = isa.b.base;
1077
  lab = isa.b.base;
1049
  
1078
 
1050
  id = ext_name(lab);
1079
  id = ext_name(lab);
1051
 
1080
 
1052
  /* generate .toc entry */
1081
  /* generate .toc entry */
1053
  fprintf(as_file, "\t.toc\n");
1082
  fprintf(as_file, "\t.toc\n");
1054
  fprintf(as_file, "T.%s:\n\t.tc\t%s[TC],%s\n", id, id, id);
1083
  fprintf(as_file, "T.%s:\n\t.tc\t%s[TC],%s\n", id, id, id);
Line 1056... Line 1085...
1056
  /* reset to default text segment */
1085
  /* reset to default text segment */
1057
  fprintf(as_file, "\t.csect\t[PR]\n");
1086
  fprintf(as_file, "\t.csect\t[PR]\n");
1058
 
1087
 
1059
  return isa;
1088
  return isa;
1060
}
1089
}
1061
long correct_shape PROTO_N ((n,shpe)) PROTO_T (long n X int shpe)
1090
long correct_shape(long n, int shpe)
1062
{
1091
{
1063
  switch(shpe)
1092
  switch (shpe)
1064
  {
1093
  {
1065
   case scharhd:
1094
   case scharhd:
1066
    n = n<<24;
1095
    n = n<<24;
1067
    n = n>>24;
1096
    n = n>>24;
1068
    return n;
1097
    return n;