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
    		 Crown Copyright (c) 1996
32
    		 Crown Copyright (c) 1996
3
 
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
Line 116... Line 146...
116
#include "f64.h"
146
#include "f64.h"
117
#if have_diagnostics
147
#if have_diagnostics
118
#include "xdb_basics.h"
148
#include "xdb_basics.h"
119
#endif
149
#endif
120
 
150
 
121
extern int is_comm PROTO_S ( ( exp ) ) ;
151
extern int is_comm(exp);
122
extern char *get_pointer_name PROTO_S ( ( void * ) ) ;
152
extern char *get_pointer_name(void *);
123
extern int flpt_const_overflow_fail ;
153
extern int flpt_const_overflow_fail;
124
extern double atof PROTO_S ( ( CONST char * ) ) ;
154
extern double atof(CONST char *);
125
extern double frexp PROTO_S ( ( double, int * ) ) ;
155
extern double frexp(double, int *);
126
 
156
 
127
 
157
 
128
#define  par_pl		1	/* On the stack (procedure argument) */
158
#define  par_pl		1	/* On the stack (procedure argument) */
129
#define  var_pl		2	/* On the stack (allocated variable) */
159
#define  var_pl		2	/* On the stack (allocated variable) */
130
 
160
 
Line 135... Line 165...
135
 
165
 
136
/*
166
/*
137
    NAME OF THE CONSTANT BEING EVALUATED
167
    NAME OF THE CONSTANT BEING EVALUATED
138
*/
168
*/
139
 
169
 
140
static char *ext_eval_name = "???" ;
170
static char *ext_eval_name = "???";
141
 
171
 
142
 
172
 
143
/*
173
/*
144
    LIST OF EXTERNAL CONSTANTS
174
    LIST OF EXTERNAL CONSTANTS
145
 
175
 
146
    All external constants created are formed into a bro-list.
176
    All external constants created are formed into a bro-list.
147
*/
177
*/
148
 
178
 
149
exp const_list = nilexp ;
179
exp const_list = nilexp;
150
 
180
 
151
 
181
 
152
/*
182
/*
153
    DATA CONSTANTS
183
    DATA CONSTANTS
154
 
184
 
155
    In outputting data constants, current_op is the list of values currently
185
    In outputting data constants, current_op is the list of values currently
156
    being built up.  These values are all of size current_sz.  Values not
186
    being built up.  These values are all of size current_sz.  Values not
157
    yet of this size are built up in pvalue, which contains psz bits.
187
    yet of this size are built up in pvalue, which contains psz bits.
158
*/
188
*/
159
 
189
 
160
static mach_op *current_op = null ;
190
static mach_op *current_op = null;
161
static long current_sz = 0 ;
191
static long current_sz = 0;
162
 
192
 
163
 
193
 
164
/*
194
/*
165
    OUTPUT AN EVALUATION INSTRUCTION
195
    OUTPUT AN EVALUATION INSTRUCTION
166
 
196
 
167
    An instruction corresponding to current_op is output, and current_op
197
    An instruction corresponding to current_op is output, and current_op
168
    is reset.
198
    is reset.
169
*/
199
*/
170
 
200
 
171
static void eval_instr
201
static void eval_instr
172
    PROTO_Z ()
202
(void)
173
{
203
{
174
    if ( current_op ) {
204
    if (current_op) {
175
	int s = ins ( current_sz, m_as_byte, m_as_short, m_as_long ) ;
205
	int s = ins(current_sz, m_as_byte, m_as_short, m_as_long);
176
	make_instr ( s, current_op, null, 0 ) ;
206
	make_instr(s, current_op, null, 0);
177
	current_op = null ;
207
	current_op = null;
178
    }
208
    }
179
    current_sz = 0 ;
209
    current_sz = 0;
180
    return ;
210
    return;
181
}
211
}
182
 
212
 
183
 
213
 
184
/*
214
/*
185
    OUTPUT AN OPERAND
215
    OUTPUT AN OPERAND
186
 
216
 
187
    The operand op of size sz is added to current_op.
217
    The operand op of size sz is added to current_op.
188
*/
218
*/
189
 
219
 
190
void eval_op
220
void eval_op
191
    PROTO_N ( ( sz, op ) )
-
 
192
    PROTO_T ( long sz X mach_op *op )
221
(long sz, mach_op *op)
193
{
222
{
194
    static mach_op *last_op ;
223
    static mach_op *last_op;
195
    if ( sz != current_sz ) {
224
    if (sz != current_sz) {
196
	eval_instr () ;
225
	eval_instr();
197
	current_op = op ;
226
	current_op = op;
198
	current_sz = sz ;
227
	current_sz = sz;
199
    } else {
228
    } else {
200
	last_op->of = op ;
229
	last_op->of = op;
201
    }
230
    }
202
    last_op = op ;
231
    last_op = op;
203
    return ;
232
    return;
204
}
233
}
205
 
234
 
206
/*
235
/*
207
    EVALUATE AN EXPRESSION
236
    EVALUATE AN EXPRESSION
208
 
237
 
209
    The expression e, is evaluated and the integer result is returned.
238
    The expression e, is evaluated and the integer result is returned.
210
    (from trans386)
239
    (from trans386)
211
*/
240
*/
212
extern int PIC_code ;
241
extern int PIC_code;
213
 
242
 
214
long  evalexp
243
long  evalexp
215
    PROTO_N ( (e) )
-
 
216
    PROTO_T ( exp e )
244
(exp e)
217
{
245
{
218
   switch (name(e)) {
246
   switch (name(e)) {
219
   case  val_tag:
247
   case  val_tag:
220
   case null_tag:
248
   case null_tag:
221
   case top_tag:
249
   case top_tag:
222
    {
250
    {
223
       int k = no ( e ) ;
251
       int k = no(e);
224
       if ( is_offset ( e ) ) k /= 8 ;
252
       if (is_offset(e))k /= 8;
225
       return ( k );
253
       return(k);
226
    }
254
    }
227
   case bitf_to_int_tag:
255
   case bitf_to_int_tag:
228
    {
256
    {
229
       return evalexp (son (e));
257
       return evalexp(son(e));
230
    }
258
    }
231
   case int_to_bitf_tag:
259
   case int_to_bitf_tag:
232
    {
260
    {
233
       long  w = evalexp (son (e));
261
       long  w = evalexp(son(e));
234
       if (shape_align(sh(e)) != 1) {
262
       if (shape_align(sh(e))!= 1) {
235
	  failer ("should be align 1");
263
	  failer("should be align 1");
236
       }
264
       }
237
       if (shape_size(sh(e)) != 32) {
265
       if (shape_size(sh(e))!= 32) {
238
	  w &= ((1 << shape_size(sh(e))) - 1);
266
	  w &= ((1 << shape_size(sh(e))) - 1);
239
       }
267
       }
240
       return w;
268
       return w;
241
    }
269
    }
242
   case not_tag:
270
   case not_tag:
243
    {
271
    {
244
       return (~evalexp (son (e)));
272
       return(~evalexp(son(e)));
245
    }
273
    }
246
   case and_tag:
274
   case and_tag:
247
    {
275
    {
248
       return (evalexp (son (e)) & evalexp (bro (son (e))));
276
       return(evalexp(son(e)) & evalexp(bro(son(e))));
249
    }
277
    }
250
   case or_tag:
278
   case or_tag:
251
    {
279
    {
252
       return (evalexp (son (e)) | evalexp (bro (son (e))));
280
       return(evalexp(son(e)) | evalexp(bro(son(e))));
253
    }
281
    }
254
   case xor_tag:
282
   case xor_tag:
255
    {
283
    {
256
       return (evalexp (son (e)) ^ evalexp (bro (son (e))));
284
       return(evalexp(son(e))^ evalexp(bro(son(e))));
257
    }
285
    }
258
 
286
 
259
   case shr_tag:
287
   case shr_tag:
260
    {
288
    {
261
       return (evalexp (son (e)) >> evalexp (bro (son (e))));
289
       return(evalexp(son(e)) >> evalexp(bro(son(e))));
262
    }
290
    }
263
 
291
 
264
   case shl_tag:
292
   case shl_tag:
265
    {
293
    {
266
       return (evalexp (son (e)) << evalexp (bro (son (e))));
294
       return(evalexp(son(e)) << evalexp(bro(son(e))));
267
    }
295
    }
268
 
296
 
269
   case concatnof_tag:
297
   case concatnof_tag:
270
    {
298
    {
271
       long  wd = evalexp (son (e));
299
       long  wd = evalexp(son(e));
272
       return (wd | (evalexp (bro (son (e))) << shape_size(sh(son(e)))));
300
       return(wd | (evalexp(bro(son(e))) << shape_size(sh(son(e)))));
273
    }
301
    }
274
 
302
 
275
   case clear_tag:
303
   case clear_tag:
276
    {
304
    {
277
       if (shape_size(sh(e)) <= 32)
305
       if (shape_size(sh(e)) <= 32)
278
       return 0;
306
       return 0;
279
       break;
307
       break;
280
    }
308
    }
281
   case env_offset_tag:
309
   case env_offset_tag:
282
    {
310
    {
283
       exp ident_exp = son(e) ;
311
       exp ident_exp = son(e);
284
 
312
 
285
       if (ismarked(ident_exp)) {
313
       if (ismarked(ident_exp)) {
286
          long offval ;
314
          long offval;
287
          switch (ptno(ident_exp)) {
315
          switch (ptno(ident_exp)) {
288
          case var_pl:
316
          case var_pl:
289
             offval = -no(ident_exp)/8;
317
             offval = -no(ident_exp) /8;
290
             break;
318
             break;
291
          case par2_pl:
319
          case par2_pl:
292
             offval = no(ident_exp)/8;
320
             offval = no(ident_exp) /8;
293
             break;
321
             break;
294
          case par3_pl:
322
          case par3_pl:
295
          case par_pl:
323
          case par_pl:
296
          default:
324
          default:
297
             offval = no(ident_exp)/8 + 8;
325
             offval = no(ident_exp) /8 + 8;
298
          }
326
          }
299
          return offval ;
327
          return offval;
300
       }
328
       }
301
       break;
329
       break;
302
    }
330
    }
303
   case env_size_tag:
331
   case env_size_tag:
304
    {
332
    {
305
       dec * et = brog(son(son(e)));
333
       dec * et = brog(son(son(e)));
306
       if (et -> dec_u.dec_val.processed)
334
       if (et -> dec_u.dec_val.processed)
307
       return (et -> dec_u.dec_val.index);
335
       return(et -> dec_u.dec_val.index);
308
       break;
336
       break;
309
    }
337
    }
310
   case offset_add_tag:
338
   case offset_add_tag:
311
    {
339
    {
312
       return (evalexp(son(e))+evalexp(bro(son(e))));
340
       return(evalexp(son(e)) +evalexp(bro(son(e))));
313
    }
341
    }
314
   case offset_max_tag:
342
   case offset_max_tag:
315
    {
343
    {
316
       long a = evalexp(son(e));
344
       long a = evalexp(son(e));
317
       long b = evalexp(bro(son(e)));
345
       long b = evalexp(bro(son(e)));
318
       return (a > b ? a : b);
346
       return(a > b ? a : b);
319
    }
347
    }
320
   case offset_pad_tag:
348
   case offset_pad_tag:
321
    {
349
    {
322
       return( rounder(evalexp(son(e)), shape_align(sh(e)) / 8));
350
       return(rounder(evalexp(son(e)), shape_align(sh(e)) / 8));
323
    }
351
    }
324
   case offset_mult_tag:
352
   case offset_mult_tag:
325
    {
353
    {
326
       return (evalexp(son(e))*evalexp(bro(son(e))));
354
       return(evalexp(son(e))*evalexp(bro(son(e))));
327
    }
355
    }
328
   case offset_div_tag:
356
   case offset_div_tag:
329
   case offset_div_by_int_tag:
357
   case offset_div_by_int_tag:
330
    {
358
    {
331
       long n = evalexp(bro(son(e))) ;
359
       long n = evalexp(bro(son(e)));
332
       if ( n == 0 ) {
360
       if (n == 0) {
333
          n++;
361
          n++;
334
          error("evalexp: divide by zero");
362
          error("evalexp: divide by zero");
335
       }
363
       }
336
       return (evalexp(son(e)) / n);
364
       return(evalexp(son(e)) / n);
337
    }
365
    }
338
   case offset_subtract_tag:
366
   case offset_subtract_tag:
339
    {
367
    {
340
       return (evalexp(son(e))-evalexp(bro(son(e))));
368
       return(evalexp(son(e)) -evalexp(bro(son(e))));
341
    }
369
    }
342
   case offset_negate_tag:
370
   case offset_negate_tag:
343
    {
371
    {
344
       return (- evalexp(son(e)));
372
       return(- evalexp(son(e)));
345
    }
373
    }
346
   case seq_tag:
374
   case seq_tag:
347
    {
375
    {
348
       if (name(son(son(e))) == prof_tag && last(son(son(e))))
376
       if (name(son(son(e))) == prof_tag && last(son(son(e))))
349
	   return (evalexp(bro(son(e))));
377
	   return(evalexp(bro(son(e))));
350
       break;
378
       break;
351
    }
379
    }
352
   case cont_tag:
380
   case cont_tag:
353
    {
381
    {
354
       if (PIC_code && name(son(e)) == name_tag && isglob(son(son(e)))
382
       if (PIC_code && name(son(e)) == name_tag && isglob(son(son(e)))
355
           && son(son(son(e))) != nilexp
383
           && son(son(son(e)))!= nilexp
356
           && !(brog(son(son(e))) -> dec_u.dec_val.dec_var))
384
           && !(brog(son(son(e))) -> dec_u.dec_val.dec_var))
357
       return (evalexp(son(son(son(e)))));
385
       return(evalexp(son(son(son(e)))));
358
       break;
386
       break;
359
    }
387
    }
360
   }
388
   }
361
   error ( "Illegal constant expression in %s", ext_eval_name ) ;
389
   error("Illegal constant expression in %s", ext_eval_name);
362
   return ( 0 ) ;
390
   return(0);
363
}
391
}
364
 
392
 
365
/*
393
/*
366
    EVALUATE AN INTEGER VALUE
394
    EVALUATE AN INTEGER VALUE
367
 
395
 
368
    The expression e, representing an integer value, is evaluated.
396
    The expression e, representing an integer value, is evaluated.
369
*/
397
*/
370
 
398
 
371
static void evalno
399
static void evalno
372
    PROTO_N ( ( e ) )
-
 
373
    PROTO_T ( exp e )
400
(exp e)
374
{
401
{
375
    mach_op *op ;
402
    mach_op *op;
376
    long sz = shape_size ( sh ( e ) ) ;
403
    long sz = shape_size(sh(e));
377
    long k = evalexp(e);
404
    long k = evalexp(e);
378
 
405
 
379
    switch ( sz ) {
406
    switch (sz) {
380
 
407
 
381
      case 8 : {
408
      case 8: {
-
 
409
	op = make_value(k & 0xff);
-
 
410
	eval_op(L8, op);
-
 
411
	return;
-
 
412
      }
-
 
413
 
-
 
414
      case 16: {
-
 
415
	op = make_value((k >> 8) & 0xff);
-
 
416
	eval_op(L8, op);
382
	op = make_value ( k & 0xff ) ;
417
	op = make_value(k & 0xff);
383
	eval_op ( L8, op ) ;
418
	eval_op(L8, op);
384
	return ;
419
	return;
385
      }
420
      }
386
 
421
 
387
      case 16 : {
422
      case 32: {
-
 
423
	op = make_value((k >> 24) & 0xff);
-
 
424
	eval_op(L8, op);
-
 
425
	op = make_value((k >> 16) & 0xff);
-
 
426
	eval_op(L8, op);
388
	op = make_value ( ( k >> 8 ) & 0xff ) ;
427
	op = make_value((k >> 8) & 0xff);
389
	eval_op ( L8, op ) ;
428
	eval_op(L8, op);
390
	op = make_value ( k & 0xff ) ;
429
	op = make_value(k & 0xff);
391
	eval_op ( L8, op ) ;
430
	eval_op(L8, op);
392
	return ;
431
	return;
393
      }
432
      }
394
 
-
 
395
      case 32 : {
-
 
396
	op = make_value ( ( k >> 24 ) & 0xff ) ;
-
 
397
	eval_op ( L8, op ) ;
-
 
398
	op = make_value ( ( k >> 16 ) & 0xff ) ;
-
 
399
	eval_op ( L8, op ) ;
-
 
400
	op = make_value ( ( k >> 8 ) & 0xff ) ;
-
 
401
	eval_op ( L8, op ) ;
-
 
402
	op = make_value ( k & 0xff ) ;
-
 
403
	eval_op ( L8, op ) ;
-
 
404
	return ;
-
 
405
      }
-
 
406
      case 64 : {
433
      case 64: {
407
	flt64 bval;
434
	flt64 bval;
408
	bval = exp_to_f64(e);
435
	bval = exp_to_f64(e);
409
	op = make_value((bval.small>>24) & 0xff);
436
	op = make_value((bval.small>>24) & 0xff);
410
	eval_op(L8,op);
437
	eval_op(L8,op);
411
	op = make_value((bval.small>>16) & 0xff);
438
	op = make_value((bval.small>>16) & 0xff);
412
	eval_op(L8,op);
439
	eval_op(L8,op);
413
	op = make_value((bval.small>>8) & 0xff);
440
	op = make_value((bval.small>>8) & 0xff);
414
	eval_op(L8,op);
441
	eval_op(L8,op);
415
	op = make_value(bval.small & 0xff);
442
	op = make_value(bval.small & 0xff);
416
	eval_op(L8,op);
443
	eval_op(L8,op);
417
 
444
 
418
	op = make_value((bval.big>>24) & 0xff);
445
	op = make_value((bval.big>>24) & 0xff);
419
	eval_op(L8,op);
446
	eval_op(L8,op);
420
	op = make_value((bval.big>>16) & 0xff);
447
	op = make_value((bval.big>>16) & 0xff);
421
	eval_op(L8,op);
448
	eval_op(L8,op);
422
	op = make_value((bval.big>>8) & 0xff);
449
	op = make_value((bval.big>>8) & 0xff);
423
	eval_op(L8,op);
450
	eval_op(L8,op);
424
	op = make_value(bval.big & 0xff);
451
	op = make_value(bval.big & 0xff);
425
	eval_op(L8,op);
452
	eval_op(L8,op);
426
	return;
453
	return;
427
      }
454
      }
428
    }
455
    }
429
    error ( "Illegal integer value in %s", ext_eval_name ) ;
456
    error("Illegal integer value in %s", ext_eval_name);
430
    return ;
457
    return;
431
}
458
}
432
 
459
 
433
 
460
 
434
/*
461
/*
435
    CONVERT A REAL VALUE TO A BITPATTERN
462
    CONVERT A REAL VALUE TO A BITPATTERN
436
 
463
 
437
    This routine converts the real constant e into an array of longs
464
    This routine converts the real constant e into an array of longs
438
    giving the bitpattern corresponding to this constant.  Although
465
    giving the bitpattern corresponding to this constant.  Although
439
    care has been taken, this may not work properly on all machines
466
    care has been taken, this may not work properly on all machines
440
    (although it should for all IEEE machines).  It returns NULL if
467
    (although it should for all IEEE machines).  It returns NULL if
441
    it cannot convert the number sufficiently accurately.
468
    it cannot convert the number sufficiently accurately.
442
*/
469
*/
443
 
470
 
444
long *realrep
471
long *realrep
445
    PROTO_N ( ( e ) )
-
 
446
    PROTO_T ( exp e )
472
(exp e)
447
{
473
{
448
    int i, n, ex ;
474
    int i, n, ex;
449
    double d, m ;
475
    double d, m;
450
    char bits [128] ;
476
    char bits[128];
451
    static long longs [4] ;
477
    static long longs[4];
452
    int exp_bits, mant_bits ;
478
    int exp_bits, mant_bits;
453
    long sz = shape_size ( sh ( e ) ) ;
479
    long sz = shape_size(sh(e));
454
 
480
 
455
    /* Find size of exponent and mantissa */
481
    /* Find size of exponent and mantissa */
456
    if ( sz == 32 ) {
482
    if (sz == 32) {
457
	exp_bits = 8 ;
483
	exp_bits = 8;
458
	mant_bits = 23 ;
484
	mant_bits = 23;
459
    } else if ( sz == 64 ) {
485
    } else if (sz == 64) {
460
	exp_bits = 11 ;
486
	exp_bits = 11;
461
	mant_bits = 52 ;
487
	mant_bits = 52;
462
    } else {
488
    } else {
463
	exp_bits = 15 ;
489
	exp_bits = 15;
464
	mant_bits = 96 /* or 112? */ ;
490
	mant_bits = 96 /* or 112? */ ;
465
    }
491
    }
466
 
492
 
467
#if ( FBASE == 10 )
493
#if (FBASE == 10)
468
 
494
 
469
    if ( !convert_floats ) return ( NULL ) ;
495
    if (!convert_floats) return(NULL);
470
 
496
 
471
    if ( name ( e ) == real_tag ) {
497
    if (name(e) == real_tag) {
472
	/* Calculate value */
498
	/* Calculate value */
473
	flt *f = flptnos + no ( e ) ;
499
	flt *f = flptnos + no(e);
474
	char fbuff [100] ;
500
	char fbuff[100];
475
	char *p = fbuff ;
501
	char *p = fbuff;
476
	if ( f->exp <= DBL_MIN_10_EXP || f->exp >= DBL_MAX_10_EXP ) {
502
	if (f->exp <= DBL_MIN_10_EXP || f->exp >= DBL_MAX_10_EXP) {
477
	    /* Reject anything that won't fit into a double */
503
	    /* Reject anything that won't fit into a double */
478
	    return ( NULL ) ;
504
	    return(NULL);
479
	}
505
	}
480
	if ( f->sign < 0 ) *( p++ ) = '-' ;
506
	if (f->sign < 0)*(p++) = '-';
481
	*( p++ ) = '0' + f->mant [0] ;
507
	*(p++) = '0' + f->mant[0];
482
	*( p++ ) = '.' ;
508
	*(p++) = '.';
483
	for ( i = 1 ; i < MANT_SIZE ; i++ ) *( p++ ) = '0' + f->mant [i] ;
509
	for (i = 1; i < MANT_SIZE; i++)*(p++) = '0' + f->mant[i];
484
	sprintf ( p, "e%d", ( int ) f->exp ) ;
510
	sprintf(p, "e%d",(int)f->exp);
485
	d = atof ( fbuff ) ;
511
	d = atof(fbuff);
486
	if ( sz == 32 ) {
512
	if (sz == 32) {
487
	    /* Round floats */
513
	    /* Round floats */
488
	    static float fd ;
514
	    static float fd;
489
	    fd = ( float ) d ;
515
	    fd = (float)d;
490
	    d = ( double ) fd ;
516
	    d = (double)fd;
491
	}
517
	}
492
    } else {
518
    } else {
493
	error ( "Illegal floating-point constant" ) ;
519
	error("Illegal floating-point constant");
494
	return ( NULL ) ;
520
	return(NULL);
495
    }
521
    }
496
 
522
 
497
    /* Deal with 0 */
523
    /* Deal with 0 */
498
    if ( d == 0.0 ) {
524
    if (d == 0.0) {
499
	for ( i = 0 ; i < sz / 32 ; i++ ) longs [i] = 0 ;
525
	for (i = 0; i < sz / 32; i++)longs[i] = 0;
500
	return ( longs ) ;
526
	return(longs);
501
    }
527
    }
502
 
528
 
503
    /* Fill in sign */
529
    /* Fill in sign */
504
    if ( d < 0.0 ) {
530
    if (d < 0.0) {
505
	bits [0] = 1 ;
531
	bits[0] = 1;
506
	d = -d ;
532
	d = -d;
507
    } else {
533
    } else {
508
	bits [0] = 0 ;
534
	bits[0] = 0;
509
    }
535
    }
510
 
536
 
511
    /* Work out mantissa and exponent */
537
    /* Work out mantissa and exponent */
512
    m = frexp ( d, &ex ) ;
538
    m = frexp(d, &ex);
513
    m = 2.0 * m - 1.0 ;
539
    m = 2.0 * m - 1.0;
514
    ex-- ;
540
    ex--;
515
 
541
 
516
    /* Fill in mantissa */
542
    /* Fill in mantissa */
517
    for ( i = 1 ; i <= mant_bits ; i++ ) {
543
    for (i = 1; i <= mant_bits; i++) {
518
	int j = exp_bits + i ;
544
	int j = exp_bits + i;
519
	m *= 2.0 ;
545
	m *= 2.0;
520
	if ( m >= 1.0 ) {
546
	if (m >= 1.0) {
521
	    m -= 1.0 ;
547
	    m -= 1.0;
522
	    bits [j] = 1 ;
548
	    bits[j] = 1;
523
	} else {
549
	} else {
524
	    bits [j] = 0 ;
550
	    bits[j] = 0;
525
	}
551
	}
526
    }
552
    }
527
 
553
 
528
#else
554
#else
529
 
555
 
530
    if ( name ( e ) == real_tag ) {
556
    if (name(e) == real_tag) {
531
	int j, k = -1 ;
557
	int j, k = -1;
532
	flt *f = flptnos + no ( e ) ;
558
	flt *f = flptnos + no(e);
533
 
559
 
534
	/* Deal with 0 */
560
	/* Deal with 0 */
535
	if ( f->sign == 0 ) {
561
	if (f->sign == 0) {
536
	    for ( i = 0 ; i < sz / 32 ; i++ ) longs [i] = 0 ;
562
	    for (i = 0; i < sz / 32; i++)longs[i] = 0;
537
	    return ( longs ) ;
563
	    return(longs);
538
	}
564
	}
539
 
565
 
540
	/* Fill in sign */
566
	/* Fill in sign */
541
	bits [0] = ( f->sign < 0 ? 1 : 0 ) ;
567
	bits[0] = (f->sign < 0 ? 1 : 0);
542
 
568
 
543
	/* Work out exponent */
569
	/* Work out exponent */
544
	ex = FBITS * ( f->exp ) + ( FBITS - 1 ) ;
570
	ex = FBITS *(f->exp) + (FBITS - 1);
545
 
571
 
546
	/* Fill in mantissa */
572
	/* Fill in mantissa */
547
	for ( i = 0 ; i < MANT_SIZE ; i++ ) {
573
	for (i = 0; i < MANT_SIZE; i++) {
548
	    for ( j = FBITS - 1 ; j >= 0 ; j-- ) {
574
	    for (j = FBITS - 1; j >= 0; j--) {
549
		if ( ( f->mant [i] ) & ( 1 << j ) ) {
575
		if ((f->mant[i]) & (1 << j)) {
550
		    if ( k >= 0 ) {
576
		    if (k >= 0) {
551
			if ( k < sz ) bits [k] = 1 ;
577
			if (k < sz)bits[k] = 1;
552
			k++ ;
578
			k++;
553
		    } else {
579
		    } else {
554
			/* Ignore first 1 */
580
			/* Ignore first 1 */
555
			k = exp_bits + 1 ;
581
			k = exp_bits + 1;
556
		    }
582
		    }
557
		} else {
583
		} else {
558
		    if ( k >= 0 ) {
584
		    if (k >= 0) {
559
			if ( k < sz ) bits [k] = 0 ;
585
			if (k < sz)bits[k] = 0;
560
			k++ ;
586
			k++;
561
		    } else {
587
		    } else {
562
			/* Step over initial zeros */
588
			/* Step over initial zeros */
563
			ex-- ;
589
			ex--;
564
		    }
590
		    }
565
		}
591
		}
566
	    }
592
	    }
567
	}
593
	}
568
 
594
 
569
    } else {
595
    } else {
570
	error ( "Illegal floating-point constant" ) ;
596
	error("Illegal floating-point constant");
571
	return ( NULL ) ;
597
	return(NULL);
572
    }
598
    }
573
 
599
 
574
#endif
600
#endif
575
 
601
 
576
    /* Fill in exponent */
602
    /* Fill in exponent */
577
    ex += ( 1 << ( exp_bits - 1 ) ) - 1 ;
603
    ex += (1 << (exp_bits - 1)) - 1;
578
    if ( ex <= 0 || ex >= ( 1 << exp_bits ) - 1 ) {
604
    if (ex <= 0 || ex >= (1 << exp_bits) - 1) {
579
	if ( flpt_const_overflow_fail ) {
605
	if (flpt_const_overflow_fail) {
580
	    error ( "Floating point constant out of range" ) ;
606
	    error("Floating point constant out of range");
581
	}
607
	}
582
	if ( sz == 32 ) {
608
	if (sz == 32) {
583
	    if ( bits [0] ) longs [0] = 0x80000000 ;
609
	    if (bits[0])longs[0] = 0x80000000;
584
	    longs [0] += 0x7f800000 ;
610
	    longs[0] += 0x7f800000;
585
	} else {
611
	} else {
586
	    if ( bits [0] ) longs [0] = 0x80000000 ;
612
	    if (bits[0])longs[0] = 0x80000000;
587
	    longs [0] += 0x7ff00000 ;
613
	    longs[0] += 0x7ff00000;
588
	    longs [1] = 0 ;
614
	    longs[1] = 0;
589
	}
615
	}
590
	return ( longs ) ;
616
	return(longs);
591
    }
617
    }
592
    for ( i = 0 ; i < exp_bits ; i++ ) {
618
    for (i = 0; i < exp_bits; i++) {
593
	int j = exp_bits - i ;
619
	int j = exp_bits - i;
594
	bits [j] = ( ( ex & ( 1 << i ) ) ? 1 : 0 ) ;
620
	bits[j] = ((ex & (1 << i))? 1 : 0);
595
    }
621
    }
596
 
622
 
597
    /* Convert bits to longs */
623
    /* Convert bits to longs */
598
    n = ( sz / 32 ) - 1 ;
624
    n = (sz / 32) - 1;
599
    for ( i = 0 ; i <= n ; i++ ) {
625
    for (i = 0; i <= n; i++) {
600
	int j ;
626
	int j;
601
	long b0 = 0, b1 = 0, b2 = 0, b3 = 0 ;
627
	long b0 = 0, b1 = 0, b2 = 0, b3 = 0;
602
	for ( j = 0 ; j < 8 ; j++ ) b0 = 2 * b0 + bits [ 32 * i + j ] ;
628
	for (j = 0; j < 8; j++)b0 = 2 * b0 + bits[32 * i + j];
603
	for ( j = 8 ; j < 16 ; j++ ) b1 = 2 * b1 + bits [ 32 * i + j ] ;
629
	for (j = 8; j < 16; j++)b1 = 2 * b1 + bits[32 * i + j];
604
	for ( j = 16 ; j < 24 ; j++ ) b2 = 2 * b2 + bits [ 32 * i + j ] ;
630
	for (j = 16; j < 24; j++)b2 = 2 * b2 + bits[32 * i + j];
605
	for ( j = 24 ; j < 32 ; j++ ) b3 = 2 * b3 + bits [ 32 * i + j ] ;
631
	for (j = 24; j < 32; j++)b3 = 2 * b3 + bits[32 * i + j];
606
#if little_end
632
#if little_end
607
	longs [ n - i ] = ( b0 << 24 ) + ( b1 << 16 ) + ( b2 << 8 ) + b3 ;
633
	longs[n - i] = (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
608
#else
634
#else
609
	longs [i] = ( b0 << 24 ) + ( b1 << 16 ) + ( b2 << 8 ) + b3 ;
635
	longs[i] = (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
610
#endif
636
#endif
611
    }
637
    }
612
    return ( longs ) ;
638
    return(longs);
613
}
639
}
614
 
640
 
615
 
641
 
616
/*
642
/*
617
    EVALUATE A REAL VALUE
643
    EVALUATE A REAL VALUE
Line 620... Line 646...
620
    are two cases, depending on the macro convert_floats.  Either the
646
    are two cases, depending on the macro convert_floats.  Either the
621
    number itself or its representation in bits is output.
647
    number itself or its representation in bits is output.
622
*/
648
*/
623
 
649
 
624
static void evalreal
650
static void evalreal
625
    PROTO_N ( ( e ) )
-
 
626
    PROTO_T ( exp e )
651
(exp e)
627
{
652
{
628
    long *p ;
653
    long *p;
629
    long sz = shape_size ( sh ( e ) ) ;
654
    long sz = shape_size(sh(e));
630
    eval_instr () ;
655
    eval_instr();
631
    p = realrep ( e ) ;
656
    p = realrep(e);
632
    if ( p ) {
657
    if (p) {
633
	int i ;
658
	int i;
634
	for ( i = 0 ; i < sz / 32 ; i++ ) {
659
	for (i = 0; i < sz / 32; i++) {
635
	    mach_op *op = make_value ( p [i] ) ;
660
	    mach_op *op = make_value(p[i]);
636
	    eval_op ( L32, op ) ;
661
	    eval_op(L32, op);
637
	}
662
	}
638
    } else {
663
    } else {
639
	flt *f = flptnos + no ( e ) ;
664
	flt *f = flptnos + no(e);
640
	mach_op *op = make_float_data ( f ) ;
665
	mach_op *op = make_float_data(f);
641
	int instr = insf ( sz, m_as_float, m_as_double, m_dont_know ) ;
666
	int instr = insf(sz, m_as_float, m_as_double, m_dont_know);
642
	make_instr ( instr, op, null, 0 ) ;
667
	make_instr(instr, op, null, 0);
643
	current_sz = 0 ;
668
	current_sz = 0;
644
    }
669
    }
645
    return ;
670
    return;
646
}
671
}
647
 
672
 
648
 
673
 
649
/*
674
/*
650
    CLEAR A NUMBER OF BYTES
675
    CLEAR A NUMBER OF BYTES
651
 
676
 
652
    The next n bits are cleared, either by padding with zeros or by
677
    The next n bits are cleared, either by padding with zeros or by
653
    using a space instruction.
678
    using a space instruction.
654
*/
679
*/
655
 
680
 
656
static void clear_out
681
static void clear_out
657
    PROTO_N ( ( n, isconst, al ) )
-
 
658
    PROTO_T ( long n X bool isconst X long al )
682
(long n, bool isconst, long al)
659
{
683
{
660
    mach_op *op ;
684
    mach_op *op;
661
    if ( isconst ) {
685
    if (isconst) {
662
	while ( n > 0 ) {
686
	while (n > 0) {
663
	    op = make_value ( 0 ) ;
687
	    op = make_value(0);
664
	    eval_op ( L8, op ) ;
688
	    eval_op(L8, op);
665
	    n-- ;
689
	    n--;
666
	}
690
	}
667
    } else {
691
    } else {
668
	eval_instr () ;
692
	eval_instr();
669
	current_sz = 0 ;
693
	current_sz = 0;
670
	if(n > 0) {
694
	if (n > 0) {
671
	  op = make_int_data ( n ) ;
695
	  op = make_int_data(n);
672
	  make_instr ( m_as_space, op, null, 0 ) ;
696
	  make_instr(m_as_space, op, null, 0);
673
	}
697
	}
674
	current_sz = 0 ;
698
	current_sz = 0;
675
    }
699
    }
676
    return ;
700
    return;
677
}
701
}
678
 
702
 
679
 
703
 
680
/*
704
/*
681
    OUTPUT A CONSTANT
705
    OUTPUT A CONSTANT
682
 
706
 
683
    This is the main constant evaluation routine.  The expression e is
707
    This is the main constant evaluation routine.  The expression e is
684
    evaluated.  al gives the alignment of e.
708
    evaluated.  al gives the alignment of e.
685
*/
709
*/
686
 
710
 
687
void evalaux
711
void evalaux
688
    PROTO_N ( ( e, isconst, al ) )
-
 
689
    PROTO_T ( exp e X bool isconst X long al )
712
(exp e, bool isconst, long al)
690
{
713
{
691
    switch ( name ( e ) ) {
714
    switch (name(e)) {
692
 
715
 
693
	case real_tag : {
716
	case real_tag: {
694
	    /* Real values */
717
	    /* Real values */
695
	    evalreal ( e ) ;
718
	    evalreal(e);
696
	    return ;
719
	    return;
697
	}
720
	}
698
 
721
 
699
	case compound_tag : {
722
	case compound_tag: {
700
	    /* Compound values - deal with each component */
723
	    /* Compound values - deal with each component */
701
	    exp val ;
724
	    exp val;
702
	    mach_op *op ;
725
	    mach_op *op;
703
	    exp offe = son ( e ) ;
726
	    exp offe = son(e);
704
	    long off ;
727
	    long off;
705
	    long work = 0 ;
728
	    long work = 0;
706
	    long crt_off = 0 ;
729
	    long crt_off = 0;
707
	    long bits_left = 0 ;
730
	    long bits_left = 0;
708
            int pad ;
731
            int pad;
709
            bool param_aligned = 0 ;
732
            bool param_aligned = 0;
710
 
733
 
711
	    if ( offe == nilexp ) return ;
734
	    if (offe == nilexp) return;
712
 
735
 
713
            /* look ahead to determine if it is parameter aligned */
736
            /* look ahead to determine if it is parameter aligned */
714
            val = bro ( offe ) ;
737
            val = bro(offe);
715
            if ( ! last ( val ) ) {
738
            if (! last(val)) {
716
               offe = bro ( val ) ;
739
               offe = bro(val);
717
               if ( offe->shf->sonf.ald->al.al_val.al == 32 ) {
740
               if (offe->shf->sonf.ald->al.al_val.al == 32) {
718
                  param_aligned = 1 ;
741
                  param_aligned = 1;
719
               }
742
               }
720
            }
743
            }
721
            offe = son ( e ) ;
744
            offe = son(e);
722
 
-
 
723
	    while ( 1 ) {
-
 
724
		off = no ( offe ) ;
-
 
725
		val = bro ( offe ) ;
-
 
726
 
-
 
727
		if ( bits_left && off >= ( crt_off + 8 ) ) {
-
 
728
		    op = make_value ( ( work >> 24 ) & 0xff ) ;
-
 
729
		    eval_op ( L8, op ) ;
-
 
730
		    crt_off += 8 ;
-
 
731
		    work = 0 ;
-
 
732
		    bits_left = 0 ;
-
 
733
		}
-
 
734
 
-
 
735
		if ( off < crt_off ) {
-
 
736
		    error ( "Compound constants out of order in %s",
-
 
737
			    ext_eval_name ) ;
-
 
738
		}
-
 
739
 
745
 
-
 
746
	    while (1) {
-
 
747
		off = no(offe);
-
 
748
		val = bro(offe);
-
 
749
 
-
 
750
		if (bits_left && off >= (crt_off + 8)) {
-
 
751
		    op = make_value((work >> 24) & 0xff);
-
 
752
		    eval_op(L8, op);
-
 
753
		    crt_off += 8;
-
 
754
		    work = 0;
-
 
755
		    bits_left = 0;
-
 
756
		}
-
 
757
 
-
 
758
		if (off < crt_off) {
-
 
759
		    error("Compound constants out of order in %s",
-
 
760
			    ext_eval_name);
-
 
761
		}
-
 
762
 
740
		if ( off > crt_off && !bits_left ) {
763
		if (off > crt_off && !bits_left) {
741
		    clear_out ( ( off - crt_off ) / 8, 1, al ) ;
764
		    clear_out((off - crt_off) / 8, 1, al);
742
		    crt_off = off ;
765
		    crt_off = off;
743
		}
766
		}
744
 
767
 
745
		if ( name ( sh ( val ) ) != bitfhd ) {
768
		if (name(sh(val))!= bitfhd) {
746
                   pad = 0 ;
769
                   pad = 0;
747
                   if ( param_aligned ) {
770
                   if (param_aligned) {
748
                      switch ( name ( sh ( val ) ) ) {
771
                      switch (name(sh(val))) {
749
                      case scharhd:
772
                      case scharhd:
750
                      case ucharhd:
773
                      case ucharhd:
751
                         clear_out ( 3, 1, al ) ;
774
                         clear_out(3, 1, al);
752
                         crt_off += 3*8 ;
775
                         crt_off += 3*8;
753
                         break;
776
                         break;
754
                      case swordhd:
777
                      case swordhd:
755
                      case uwordhd:
778
                      case uwordhd:
756
                         clear_out ( 2, 1, al ) ;
779
                         clear_out(2, 1, al);
757
                         crt_off += 2*8 ;
780
                         crt_off += 2*8;
758
                         break;
781
                         break;
759
                      }
782
                      }
760
                   }
783
                   }
761
 
784
 
762
		    evalaux ( val, isconst, ( crt_off + al ) & 56 ) ;
785
		    evalaux(val, isconst,(crt_off + al) & 56);
763
		    crt_off += shape_size ( sh ( val ) ) ;
786
		    crt_off += shape_size(sh(val));
764
		} else {
787
		} else {
765
		    long sz = shape_size ( sh ( val ) ) ;
788
		    long sz = shape_size(sh(val));
766
		    long offn = off - crt_off ;
789
		    long offn = off - crt_off;
767
		    long nx, enx ;
790
		    long nx, enx;
768
		    long extra_byte = 0 ;
791
		    long extra_byte = 0;
769
		    if ( name ( val ) == val_tag ) {
792
		    if (name(val) == val_tag) {
770
			nx = no ( val ) ;
793
			nx = no(val);
771
		    } else {
794
		    } else {
772
			nx = no ( son ( val ) ) ;
795
			nx = no(son(val));
773
		    }
796
		    }
774
		    if ( sz > 32 - offn ) {
797
		    if (sz > 32 - offn) {
775
			enx = ( nx & 0xff ) ;
798
			enx = (nx & 0xff);
776
			extra_byte = 1 ;
799
			extra_byte = 1;
777
			nx >>= 8 ;
800
			nx >>= 8;
778
			sz -= 8 ;
801
			sz -= 8;
779
		    }
802
		    }
780
		    nx = ( nx & lo_bits [sz] ) << ( 32 - offn - sz ) ;
803
		    nx = (nx & lo_bits[sz]) << (32 - offn - sz);
781
		    work += nx ;
804
		    work += nx;
782
		    bits_left = offn + sz ;
805
		    bits_left = offn + sz;
783
		    while ( bits_left >= 8 ) {
806
		    while (bits_left >= 8) {
784
			long v ;
807
			long v;
785
			bits_left -= 8 ;
808
			bits_left -= 8;
786
			v = ( work >> 24 ) & 0xff ;
809
			v = (work >> 24) & 0xff;
787
			work <<= 8 ;
810
			work <<= 8;
788
			if ( extra_byte ) {
811
			if (extra_byte) {
789
			    bits_left += 8 ;
812
			    bits_left += 8;
790
			    work += ( enx << ( 32 - bits_left ) ) ;
813
			    work += (enx << (32 - bits_left));
791
			    extra_byte = 0 ;
814
			    extra_byte = 0;
792
			}
815
			}
793
			op = make_value ( v ) ;
816
			op = make_value(v);
794
			eval_op ( L8, op ) ;
817
			eval_op(L8, op);
795
			crt_off += 8 ;
818
			crt_off += 8;
796
		    }
819
		    }
797
		}
820
		}
798
 
821
 
799
		if ( last ( val ) ) {
822
		if (last(val)) {
800
		    long left ;
823
		    long left;
801
		    if ( bits_left ) {
824
		    if (bits_left) {
802
			op = make_value ( ( work >> 24 ) & 0xff ) ;
825
			op = make_value((work >> 24) & 0xff);
803
			eval_op ( L8, op ) ;
826
			eval_op(L8, op);
804
			crt_off += 8 ;
827
			crt_off += 8;
805
		    }
828
		    }
806
		    left = shape_size ( sh ( e ) ) - crt_off ;
829
		    left = shape_size(sh(e)) - crt_off;
807
		    if ( left > 0 ) clear_out ( left / 8, 1, al ) ;
830
		    if (left > 0)clear_out(left / 8, 1, al);
808
		    return ;
831
		    return;
809
		}
832
		}
810
		offe = bro ( val ) ;
833
		offe = bro(val);
811
	    }
834
	    }
812
	    /* Not reached */
835
	    /* Not reached */
813
	}
836
	}
814
 
837
 
815
	case name_tag : {
838
	case name_tag: {
816
	    /* External names */
839
	    /* External names */
817
	    mach_op *op ;
840
	    mach_op *op;
818
	    long n = no ( e ) ;
841
	    long n = no(e);
819
	    long sz = shape_size ( sh ( e ) ) ;
842
	    long sz = shape_size(sh(e));
820
	    char *nm = brog ( son ( e ) )->dec_u.dec_val.dec_id ;
843
	    char *nm = brog(son(e)) ->dec_u.dec_val.dec_id;
821
	    op = make_extern_data ( nm, n / 8 ) ;
844
	    op = make_extern_data(nm, n / 8);
822
	    eval_op ( sz, op ) ;
845
	    eval_op(sz, op);
823
	    return ;
846
	    return;
824
	}
847
	}
825
 
848
 
826
	case string_tag : {
849
	case string_tag: {
827
	    /* Strings */
850
	    /* Strings */
828
	    long i ;
851
	    long i;
829
	    long char_size = ( long ) props ( e ) ;
852
	    long char_size = (long)props(e);
830
	    long n = shape_size ( sh ( e ) ) / char_size ;
853
	    long n = shape_size(sh(e)) / char_size;
831
	    switch ( char_size ) {
854
	    switch (char_size) {
832
 
855
 
833
		case 8 : {
856
		case 8: {
834
		    char *s = nostr ( e ) ;
857
		    char *s = nostr(e);
835
		    for ( i = 0 ; i < n ; i++ ) {
858
		    for (i = 0; i < n; i++) {
836
			long ch = ( long ) s [i] ;
859
			long ch = (long)s[i];
837
			eval_op ( char_size, make_value ( ch ) ) ;
860
			eval_op(char_size, make_value(ch));
838
		    }
861
		    }
839
		    break ;
862
		    break;
840
		}
863
		}
841
 
864
 
842
		case 16 : {
865
		case 16: {
843
		    short *s = ( short * ) nostr ( e ) ;
866
		    short *s = (short *)nostr(e);
844
		    for ( i = 0 ; i < n ; i++ ) {
867
		    for (i = 0; i < n; i++) {
845
			long ch = ( long ) s [i] ;
868
			long ch = (long)s[i];
846
			eval_op ( char_size, make_value ( ch ) ) ;
869
			eval_op(char_size, make_value(ch));
847
		    }
870
		    }
848
		    break ;
871
		    break;
849
		}
872
		}
850
 
873
 
851
		case 32 : {
874
		case 32: {
852
		    long *s = ( long * ) nostr ( e ) ;
875
		    long *s = (long *)nostr(e);
853
		    for ( i = 0 ; i < n ; i++ ) {
876
		    for (i = 0; i < n; i++) {
854
			long ch = s [i] ;
877
			long ch = s[i];
855
			eval_op ( char_size, make_value ( ch ) ) ;
878
			eval_op(char_size, make_value(ch));
856
		    }
879
		    }
857
		    break ;
880
		    break;
858
		}
881
		}
859
 
882
 
860
		default : {
883
		default : {
861
		    error ( "Illegal string size in %s", ext_eval_name ) ;
884
		    error("Illegal string size in %s", ext_eval_name);
862
		    break ;
885
		    break;
863
		}
886
		}
864
	    }
887
	    }
865
	    return ;
888
	    return;
866
	}
889
	}
867
 
890
 
868
	case res_tag : {
891
	case res_tag: {
869
	    /* Result values */
892
	    /* Result values */
870
	    shape ss = sh ( son ( e ) ) ;
893
	    shape ss = sh(son(e));
871
	    long sz = shape_size ( ss ) / 8 ;
894
	    long sz = shape_size(ss) / 8;
872
	    long sa = shape_align ( ss ) ;
895
	    long sa = shape_align(ss);
873
	    clear_out ( sz, isconst, sa ) ;
896
	    clear_out(sz, isconst, sa);
874
	    return ;
897
	    return;
875
	}
898
	}
876
      case top_tag :
899
      case top_tag:
877
      case null_tag : {
900
      case null_tag: {
878
	    /* Null values */
901
	    /* Null values */
879
	    shape ss = sh ( e ) ;
902
	    shape ss = sh(e);
880
	    long sz = shape_size ( ss ) / 8 ;
903
	    long sz = shape_size(ss) / 8;
881
	    long sa = shape_align ( ss ) ;
904
	    long sa = shape_align(ss);
882
	    clear_out ( sz, isconst, sa ) ;
905
	    clear_out(sz, isconst, sa);
883
	    return ;
906
	    return;
884
	}
907
	}
885
 
908
 
886
	case ncopies_tag : {
909
	case ncopies_tag: {
887
	    /* Multiple copies */
910
	    /* Multiple copies */
888
	    long i ;
911
	    long i;
889
	    exp t = son ( e ) ;
912
	    exp t = son(e);
890
	    long sa = shape_align ( sh ( t ) ) ;
913
	    long sa = shape_align(sh(t));
891
	    if ( is_comm ( t ) ) {
914
	    if (is_comm(t)) {
892
		long sz = rounder ( shape_size ( sh ( t ) ), sa ) / 8 ;
915
		long sz = rounder(shape_size(sh(t)), sa) / 8;
893
		clear_out ( sz * no ( e ), isconst, sa ) ;
916
		clear_out(sz * no(e), isconst, sa);
894
		return ;
917
		return;
895
	    }
918
	    }
896
	    for ( i = 0 ; i < no ( e ) ; i++ ) evalaux ( t, isconst, sa ) ;
919
	    for (i = 0; i < no(e); i++)evalaux(t, isconst, sa);
897
	    return ;
920
	    return;
898
	}
921
	}
899
 
922
 
900
	case nof_tag : {
923
	case nof_tag: {
901
	    /* Array values */
924
	    /* Array values */
902
	    exp t = son ( e ) ;
925
	    exp t = son(e);
903
	    if ( t == nilexp ) return ;
926
	    if (t == nilexp) return;
904
	    while ( 1 ) {
927
	    while (1) {
905
		evalaux ( t, isconst, al ) ;
928
		evalaux(t, isconst, al);
906
		if ( last ( t ) ) return ;
929
		if (last(t)) return;
907
		t = bro ( t ) ;
930
		t = bro(t);
908
	    }
931
	    }
909
	    /* Not reached */
932
	    /* Not reached */
910
	}
933
	}
911
 
934
 
912
	case concatnof_tag : {
935
	case concatnof_tag: {
913
	    /* Concatenated arrays */
936
	    /* Concatenated arrays */
914
	    long a2 = ( al + shape_size ( son ( e ) ) ) & 63 ;
937
	    long a2 = (al + shape_size(son(e))) & 63;
915
	    evalaux ( son ( e ), isconst, al ) ;
938
	    evalaux(son(e), isconst, al);
916
	    evalaux ( bro ( son ( e ) ), isconst, a2 ) ;
939
	    evalaux(bro(son(e)), isconst, a2);
917
	    return ;
940
	    return;
918
	}
941
	}
919
 
942
 
920
	case chvar_tag :
943
	case chvar_tag:
921
	case int_to_bitf_tag : {
944
	case int_to_bitf_tag: {
922
	    /* Change variety */
945
	    /* Change variety */
923
	    if ( name ( son ( e ) ) == val_tag ) {
946
	    if (name(son(e)) == val_tag) {
924
		sh ( son ( e ) ) = sh ( e ) ;
947
		sh(son(e)) = sh(e);
925
		evalaux ( son ( e ), isconst, al ) ;
948
		evalaux(son(e), isconst, al);
926
		return ;
949
		return;
927
	    }
950
	    }
928
	    error ( "Illegal change variety constant in %s", ext_eval_name ) ;
951
	    error("Illegal change variety constant in %s", ext_eval_name);
929
	    return ;
952
	    return;
930
	}
953
	}
931
 
954
 
932
	case chfl_tag : {
955
	case chfl_tag: {
933
	    /* Change floating variety */
956
	    /* Change floating variety */
934
	    if ( name ( son ( e ) ) == real_tag ) {
957
	    if (name(son(e)) == real_tag) {
935
		sh ( son ( e ) ) = sh ( e ) ;
958
		sh(son(e)) = sh(e);
936
		evalaux ( son ( e ), isconst, al ) ;
959
		evalaux(son(e), isconst, al);
937
		return ;
960
		return;
938
	    }
961
	    }
939
	    error ( "Illegal change floating variety constant in %s",
962
	    error("Illegal change floating variety constant in %s",
940
		    ext_eval_name ) ;
963
		    ext_eval_name);
941
	    return ;
964
	    return;
942
	}
965
	}
943
 
966
 
944
	case clear_tag : {
967
	case clear_tag: {
945
	    long sz = shape_size ( sh ( e ) ) / 8 ;
968
	    long sz = shape_size(sh(e)) / 8;
946
	    clear_out ( sz, isconst, al ) ;
969
	    clear_out(sz, isconst, al);
947
	    return ;
970
	    return;
948
	}
971
	}
949
#if 0
972
#if 0
950
        case env_size_tag: {
973
        case env_size_tag: {
951
           dec* d = brog(son(son(e)));
974
           dec* d = brog(son(son(e)));
952
           mach_op* op = make_lab_data ( (long) d, 0 ) ;
975
           mach_op* op = make_lab_data((long)d, 0);
953
           eval_op(L32,op);
976
           eval_op(L32,op);
954
           return ;
977
           return;
955
        }
978
        }
956
 
979
 
957
	case env_offset_tag : {
980
	case env_offset_tag: {
958
           /* Offsets */
981
           /* Offsets */
959
           long offval;
982
           long offval;
960
           mach_op *op;
983
           mach_op *op;
961
           exp ident_exp = son ( e ) ;
984
           exp ident_exp = son(e);
962
           op = make_lab_data ( (long) ident_exp, 0 ) ;
985
           op = make_lab_data((long)ident_exp, 0);
963
           eval_op(L32,op);
986
           eval_op(L32,op);
964
 
987
 
965
           return ;
988
           return;
966
	}
989
	}
967
#endif
990
#endif
968
	case ident_tag : {
991
	case ident_tag: {
969
	     /* Simple identifications */
992
	     /* Simple identifications */
970
	     exp body = bro ( son ( e ) ) ;
993
	     exp body = bro(son(e));
971
	     if ( name ( body ) == name_tag && son ( body ) == e ) {
994
	     if (name(body) == name_tag && son(body) == e) {
972
		evalaux ( son ( e ), isconst, al ) ;
995
		evalaux(son(e), isconst, al);
973
		return ;
996
		return;
974
	     }
997
	     }
975
	     break ;
998
	     break;
976
	}
999
	}
977
 
1000
 
978
	case minptr_tag : {
1001
	case minptr_tag: {
979
	    exp p1 = son ( e ) ;
1002
	    exp p1 = son(e);
980
	    exp p2 = bro ( p1 ) ;
1003
	    exp p2 = bro(p1);
981
	    if ( name ( p1 ) == name_tag && name ( p2 ) == name_tag ) {
1004
	    if (name(p1) == name_tag && name(p2) == name_tag) {
982
		long n = no ( p1 ) - no ( p2 ) ;
1005
		long n = no(p1) - no(p2);
983
		long sz = shape_size ( sh ( e ) ) ;
1006
		long sz = shape_size(sh(e));
984
		char *n1 = brog ( son ( p1 ) )->dec_u.dec_val.dec_id ;
1007
		char *n1 = brog(son(p1)) ->dec_u.dec_val.dec_id;
985
		char *n2 = brog ( son ( p2 ) )->dec_u.dec_val.dec_id ;
1008
		char *n2 = brog(son(p2)) ->dec_u.dec_val.dec_id;
986
		mach_op *op1 = new_mach_op () ;
1009
		mach_op *op1 = new_mach_op();
987
		mach_op *op2 = new_mach_op () ;
1010
		mach_op *op2 = new_mach_op();
988
		mach_op *op3 = new_mach_op () ;
1011
		mach_op *op3 = new_mach_op();
989
		op1->type = MACH_EXT ;
1012
		op1->type = MACH_EXT;
990
		op1->def.str = n1 ;
1013
		op1->def.str = n1;
991
		op1->plus = op2 ;
1014
		op1->plus = op2;
992
		op2->type = MACH_NEG ;
1015
		op2->type = MACH_NEG;
993
		op2->plus = op3 ;
1016
		op2->plus = op3;
994
		op3->type = MACH_EXT ;
1017
		op3->type = MACH_EXT;
995
		op3->def.str = n2 ;
1018
		op3->def.str = n2;
996
		if ( n ) {
1019
		if (n) {
997
		    mach_op *op4 = new_mach_op () ;
1020
		    mach_op *op4 = new_mach_op();
998
		    op4->type = MACH_VAL ;
1021
		    op4->type = MACH_VAL;
999
		    op4->def.num = n ;
1022
		    op4->def.num = n;
1000
		    op3->plus = op4 ;
1023
		    op3->plus = op4;
1001
		}
1024
		}
1002
		eval_op ( sz, op1 ) ;
1025
		eval_op(sz, op1);
1003
		return ;
1026
		return;
1004
	    }
1027
	    }
1005
	    break ;
1028
	    break;
1006
	}
1029
	}
1007
	default:
1030
	default:
1008
            evalno ( e ) ;
1031
            evalno(e);
1009
    }
1032
    }
1010
}
1033
}
1011
 
1034
 
1012
 
1035
 
1013
#if 0
1036
#if 0
Line 1017... Line 1040...
1017
 
1040
 
1018
    If so it can be put into the common area.
1041
    If so it can be put into the common area.
1019
*/
1042
*/
1020
 
1043
 
1021
static int is_comm
1044
static int is_comm
1022
    PROTO_N ( ( e ) )
-
 
1023
    PROTO_T ( exp e )
1045
(exp e)
1024
{
1046
{
1025
    switch ( name ( e ) ) {
1047
    switch (name(e)) {
1026
 
1048
 
1027
	case val_tag : return ( no ( e ) ? 0 : 1 ) ;
1049
	case val_tag: return(no(e)? 0 : 1);
1028
 
1050
 
1029
	case int_to_bitf_tag :
1051
	case int_to_bitf_tag:
1030
	case chvar_tag : return ( is_comm ( son ( e ) ) ) ;
1052
	case chvar_tag: return(is_comm(son(e)));
1031
 
1053
 
1032
	case real_tag : {
1054
	case real_tag: {
1033
	    flpt f = no ( e ) ;
1055
	    flpt f = no(e);
1034
	    return ( flptnos [f].sign ? 0 : 1 ) ;
1056
	    return(flptnos[f].sign ? 0 : 1);
1035
	}
1057
	}
1036
 
1058
 
1037
	case compound_tag : {
1059
	case compound_tag: {
1038
	    exp t = son ( e ) ;
1060
	    exp t = son(e);
1039
	    if ( t == nilexp ) return ( 1 ) ;
1061
	    if (t == nilexp) return(1);
1040
	    while ( 1 ) {
1062
	    while (1) {
1041
		t = bro ( t ) ;
1063
		t = bro(t);
1042
		if ( name ( sh ( t ) ) != bitfhd ) {
1064
		if (name(sh(t))!= bitfhd) {
1043
		    if ( !is_comm ( t ) ) return ( 0 ) ;
1065
		    if (!is_comm(t)) return(0);
1044
		} else {
1066
		} else {
1045
		    if ( name ( t ) == val_tag ) {
1067
		    if (name(t) == val_tag) {
1046
			if ( no ( t ) ) return ( 0 ) ;
1068
			if (no(t)) return(0);
1047
		    } else {
1069
		    } else {
1048
			if ( no ( son ( t ) ) ) return ( 0 ) ;
1070
			if (no(son(t))) return(0);
1049
		    }
1071
		    }
1050
		}
1072
		}
1051
		if ( last ( t ) ) return ( 1 ) ;
1073
		if (last(t)) return(1);
1052
		t = bro ( t ) ;
1074
		t = bro(t);
1053
	    }
1075
	    }
1054
	    /* Not reached */
1076
	    /* Not reached */
1055
	}
1077
	}
1056
 
1078
 
1057
	case ncopies_tag : return ( is_comm ( son ( e ) ) ) ;
1079
	case ncopies_tag: return(is_comm(son(e)));
1058
 
1080
 
1059
	case nof_tag : {
1081
	case nof_tag: {
1060
	    exp t = son ( e ) ;
1082
	    exp t = son(e);
1061
	    if ( t == nilexp ) return ( 1 ) ;
1083
	    if (t == nilexp) return(1);
1062
	    while ( 1 ) {
1084
	    while (1) {
1063
		if ( !is_comm ( t ) ) return ( 0 ) ;
1085
		if (!is_comm(t)) return(0);
1064
		if ( last ( t ) ) return ( 1 ) ;
1086
		if (last(t)) return(1);
1065
		t = bro ( t ) ;
1087
		t = bro(t);
1066
	    }
1088
	    }
1067
	    /* Not reached */
1089
	    /* Not reached */
1068
	}
1090
	}
1069
 
1091
 
1070
	case concatnof_tag : {
1092
	case concatnof_tag: {
1071
	    exp t = son ( e ) ;
1093
	    exp t = son(e);
1072
	    return ( is_comm ( t ) && is_comm ( bro ( t ) ) ) ;
1094
	    return(is_comm(t) && is_comm(bro(t)));
1073
	}
1095
	}
1074
 
1096
 
1075
	case clear_tag :
1097
	case clear_tag:
1076
	case res_tag :
1098
	case res_tag:
1077
	case null_tag : return ( 1 ) ;
1099
	case null_tag: return(1);
1078
    }
1100
    }
1079
    return ( 0 ) ;
1101
    return(0);
1080
}
1102
}
1081
 
1103
 
1082
#endif
1104
#endif
1083
 
1105
 
1084
 
1106
 
1085
/*
1107
/*
1086
    OUTPUT A CONSTANT
1108
    OUTPUT A CONSTANT
1087
*/
1109
*/
1088
 
1110
 
1089
void evaluate
1111
void evaluate
1090
    PROTO_N ( ( c, cname, s, isconst, global, di ) )
-
 
1091
    PROTO_T ( exp c X long cname X char *s X int isconst X int global X diag_global *di )
1112
(exp c, long cname, char *s, int isconst, int global, diag_global *di)
1092
{
1113
{
1093
    mach_op *op1, *op2 ;
1114
    mach_op *op1, *op2;
1094
    long al = ( long ) shape_align ( sh ( c ) ) ;
1115
    long al = (long)shape_align(sh(c));
1095
 
1116
 
1096
    if ( is_comm ( c ) ||
1117
    if (is_comm(c) ||
1097
        ((name(c) == name_tag) && (son(son(c))) && (name(son(son(c))) == null_tag))) {
1118
       ((name(c) == name_tag) && (son(son(c))) && (name(son(son(c))) == null_tag))) {
1098
 
1119
 
1099
	long sz = rounder ( shape_size ( sh ( c ) ), 32 ) ;
1120
	long sz = rounder(shape_size(sh(c)), 32);
1100
 
1121
 
1101
	/* Common global values */
1122
	/* Common global values */
1102
	if ( global && cname == -1 && !is_local ( s ) ) {
1123
	if (global && cname == -1 && !is_local(s)) {
1103
	    op1 = make_extern_data ( s, 0 ) ;
1124
	    op1 = make_extern_data(s, 0);
1104
	    op2 = make_int_data ( sz / 8 ) ;
1125
	    op2 = make_int_data(sz / 8);
1105
	    make_instr ( m_as_common, op1, op2, 0 ) ;
1126
	    make_instr(m_as_common, op1, op2, 0);
1106
#if have_diagnostics
1127
#if have_diagnostics
1107
	    if ( di ) xdb_diag_val_begin ( di, s, cname, global ) ;
1128
	    if (di)xdb_diag_val_begin(di, s, cname, global);
1108
#endif
1129
#endif
1109
	    return ;
1130
	    return;
1110
	}
1131
	}
1111
 
1132
 
1112
#ifdef asm_uses_lcomm
1133
#ifdef asm_uses_lcomm
1113
	/* Common local value */
1134
	/* Common local value */
1114
	if ( cname == -1 ) {
1135
	if (cname == -1) {
1115
	    op1 = make_extern_data ( s, 0 ) ;
1136
	    op1 = make_extern_data(s, 0);
1116
	} else {
1137
	} else {
1117
	    op1 = make_lab_data ( cname, 0 ) ;
1138
	    op1 = make_lab_data(cname, 0);
1118
	}
1139
	}
1119
	op2 = make_int_data ( sz / 8 ) ;
1140
	op2 = make_int_data(sz / 8);
1120
	make_instr ( m_as_local, op1, op2, 0 ) ;
1141
	make_instr(m_as_local, op1, op2, 0);
1121
#if have_diagnostics
1142
#if have_diagnostics
1122
	if ( di ) xdb_diag_val_begin ( di, s, cname, global ) ;
1143
	if (di)xdb_diag_val_begin(di, s, cname, global);
1123
#endif
1144
#endif
1124
#else
1145
#else
1125
	/* Common local value */
1146
	/* Common local value */
1126
	area ( pbss ) ;
1147
	area(pbss);
1127
	if ( cname == -1 ) {
1148
	if (cname == -1) {
1128
	     make_external_label ( s ) ;
1149
	     make_external_label(s);
1129
	} else {
1150
	} else {
1130
	     make_label ( cname ) ;
1151
	     make_label(cname);
1131
	}
1152
	}
1132
#if have_diagnostics
1153
#if have_diagnostics
1133
	if ( di ) xdb_diag_val_begin ( di, s, cname, global ) ;
1154
	if (di)xdb_diag_val_begin(di, s, cname, global);
1134
#endif
1155
#endif
1135
	op1 = make_int_data ( sz / 8 ) ;
1156
	op1 = make_int_data(sz / 8);
1136
	make_instr ( m_as_space, op1, null, 0 ) ;
1157
	make_instr(m_as_space, op1, null, 0);
1137
#endif
1158
#endif
1138
	return ;
1159
	return;
1139
    }
1160
    }
1140
 
1161
 
1141
    /* Data values */
1162
    /* Data values */
1142
    if ( global && cname == -1 && !is_local ( s ) ) {
1163
    if (global && cname == -1 && !is_local(s)) {
1143
	op1 = make_extern_data ( s, 0 ) ;
1164
	op1 = make_extern_data(s, 0);
1144
	make_instr ( m_as_global, op1, null, 0 ) ;
1165
	make_instr(m_as_global, op1, null, 0);
1145
    }
1166
    }
1146
 
1167
 
1147
#if have_diagnostics
1168
#if have_diagnostics
1148
    if ( di ) xdb_diag_val_begin ( di, s, cname, global ) ;
1169
    if (di)xdb_diag_val_begin(di, s, cname, global);
1149
#endif
1170
#endif
1150
 
1171
 
1151
    if ( al <= 32 ) al = 32 ;
1172
    if (al <= 32)al = 32;
1152
 
1173
 
1153
    ext_eval_name = "statically declared object" ;
1174
    ext_eval_name = "statically declared object";
1154
    if ( cname == -1 ) {
1175
    if (cname == -1) {
1155
	make_external_label ( s ) ;
1176
	make_external_label(s);
1156
	if ( !is_local ( s ) ) ext_eval_name = s ;
1177
	if (!is_local(s))ext_eval_name = s;
1157
    } else {
1178
    } else {
1158
	make_label ( cname ) ;
1179
	make_label(cname);
1159
    }
1180
    }
1160
    evalaux ( c, ( bool ) isconst, al ) ;
1181
    evalaux(c,(bool)isconst, al);
1161
    eval_instr () ;
1182
    eval_instr();
1162
    return ;
1183
    return;
1163
}
1184
}
1164
 
1185
 
1165
 
1186