Subversion Repositories tendra.SVN

Rev

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

Rev Author Line No. Line
2 7u83 1
/*
7 7u83 2
 * Copyright (c) 2002-2005 The TenDRA Project <http://www.tendra.org/>.
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions are met:
7
 *
8
 * 1. Redistributions of source code must retain the above copyright notice,
9
 *    this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
11
 *    this list of conditions and the following disclaimer in the documentation
12
 *    and/or other materials provided with the distribution.
13
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
14
 *    may be used to endorse or promote products derived from this software
15
 *    without specific, prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 *
29
 * $Id$
30
 */
31
/*
2 7u83 32
    		 Crown Copyright (c) 1997
7 7u83 33
 
2 7u83 34
    This TenDRA(r) Computer Program is subject to Copyright
35
    owned by the United Kingdom Secretary of State for Defence
36
    acting through the Defence Evaluation and Research Agency
37
    (DERA).  It is made available to Recipients with a
38
    royalty-free licence for its use, reproduction, transfer
39
    to other parties and amendment for any purpose not excluding
40
    product development provided that any such use et cetera
41
    shall be deemed to be acceptance of the following conditions:-
7 7u83 42
 
2 7u83 43
        (1) Its Recipients shall ensure that this Notice is
44
        reproduced upon any copies or amended versions of it;
7 7u83 45
 
2 7u83 46
        (2) Any amended version of it shall be clearly marked to
47
        show both the nature of and the organisation responsible
48
        for the relevant amendment or amendments;
7 7u83 49
 
2 7u83 50
        (3) Its onward transfer from a recipient to another
51
        party shall be deemed to be that party's acceptance of
52
        these conditions;
7 7u83 53
 
2 7u83 54
        (4) DERA gives no warranty or assurance as to its
55
        quality or suitability for any purpose and DERA accepts
56
        no liability whatsoever in relation to any use to which
57
        it may be put.
58
*/
59
 
60
 
61
/*
62
  type_to_aux.c
63
 
7 7u83 64
  contains procedure
65
  long add_type_to_aux (diag_type s, long ind) which converts a TDF
66
  shape into an AUXU (see sym.h) and adds it to the auxillary table
67
  for the file number given as parameter as required by the MIPS
68
  (and alpha) symbol table(s).  If the entry generated is greater
69
  than 1 AUXU in length the index corresponding to the first entry
2 7u83 70
  made is returned.
71
*/
72
 
73
/*
74
$Log: type_to_aux.c,v $
75
 * Revision 1.2  1998/02/04  10:43:34  release
76
 * Changes during testing.
77
 *
78
 * Revision 1.1.1.1  1998/01/17  15:56:01  release
79
 * First version to be checked into rolling release.
80
 *
81
 * Revision 1.3  1995/06/13  14:02:59  john
82
 * Fixed error
83
 *
84
 * Revision 1.2  1995/05/23  13:30:58  john
85
 * Reformatting
86
 *
87
*/
88
 
89
#include "config.h"
90
#include "common_types.h"
91
#include "shapemacs.h"
92
#include "exp.h"
93
#include "expmacs.h"
94
#include "diagtypes.h"
95
#include "diag_fns.h"
96
#include "xalloc.h"
97
#include "main.h"
98
#include "symtab.h"
99
#include "symbol.h"
100
#include "type_to_aux.h"
101
#include "cross_config.h"
102
 
103
#ifndef CROSS_INCLUDE
104
#include <symconst.h>
105
#else
106
#include CROSS_INCLUDE/symconst.h>
107
#endif
108
 
109
 
7 7u83 110
extern long find_aux(diag_type e);
111
extern int add_aux(AUXU,int);
2 7u83 112
 
113
int field=0;
114
 
115
 
116
long set_tq
7 7u83 117
(int qual, TIR *type, long ind)
2 7u83 118
{
119
  AUXU retaux;
120
  long index=0;
121
  switch (field++)
122
    {
123
    case 0: break;
124
    case 1: type->tq1=type->tq0;
125
      break;
126
    case 2: type->tq2=type->tq1;
127
      type->tq1=type->tq0;
128
      break;
129
    case 3: type->tq3=type->tq2;
130
      type->tq2=type->tq1;
131
      type->tq1=type->tq0;
132
      break;
133
    case 4: type->tq4=type->tq3;
134
      type->tq3=type->tq2;
135
      type->tq2=type->tq1;
136
      type->tq1=type->tq0;
137
      break;
138
    case 5: type->tq5=type->tq4;
139
      type->tq4=type->tq3;
140
      type->tq3=type->tq2;
141
      type->tq2=type->tq1;
142
      type->tq1=type->tq0;
143
      break;
144
    case 6:	type->continued=1;
7 7u83 145
      retaux.ti= (*type);
2 7u83 146
      index=add_aux(retaux, ind);
7 7u83 147
      type= (TIR*)xcalloc(1,sizeof(TIR));
2 7u83 148
      type->tq0=qual;
149
      field=1;
150
      return index;
151
    }
152
  type->tq0=qual;
153
  return -1;
154
}
155
 
156
 
157
long type_size
7 7u83 158
(diag_type dt)
2 7u83 159
{
7 7u83 160
  switch (dt->key)
2 7u83 161
    {
162
    case DIAG_TYPE_VARIETY: {
163
      return shape_size(dt->data.var);
164
    }
165
    case DIAG_TYPE_STRUCT: case DIAG_TYPE_UNION: {
166
      return shape_size(dt->data.t_struct.tdf_shape);
167
    }
168
    case DIAG_TYPE_FLOAT: {
7 7u83 169
      return((dt->data.f_var)?64:32);
2 7u83 170
    }
171
    case DIAG_TYPE_ARRAY: {
172
      long is = type_size(dt->data.array.element_type);
7 7u83 173
      return(is *(dt->data.array.upper_b-dt->data.array.lower_b+1));
2 7u83 174
    }
175
    case DIAG_TYPE_ENUM: {
176
      return type_size(dt->data.t_enum.base_type);
177
    }
178
    default: return 32;
179
    }
7 7u83 180
}
2 7u83 181
 
182
long add_type_to_aux
7 7u83 183
(diag_type dt, long ind)
2 7u83 184
{
7 7u83 185
  TIR* type= (TIR*)xcalloc(1,sizeof(TIR));
2 7u83 186
  long firstind= -1;
187
  int dimension=0;
188
  int elemsize=0;
189
  int scale=1;
190
  diag_type xdt = dt;
191
  AUXU maxaux, retaux;
192
  maxaux.isym=0xffffffff;
193
  field=0;
194
 
195
  type->bt=63;
7 7u83 196
  while (type->bt==63) {
2 7u83 197
    if (dt == (diag_type)0) {
198
      type->bt = btNil;
7 7u83 199
      retaux.ti= (*type);
2 7u83 200
      break;
201
    }
7 7u83 202
    switch (dt->key)
2 7u83 203
      {
204
      case DIAG_TYPE_BITFIELD: {
205
	type->bt=btUInt;
206
	type->fBitfield=1;
207
	retaux.ti = *type;
208
	firstind = add_aux(retaux, ind);
209
	retaux.rndx.rfd = dt->data.bitfield.no_of_bits.nat_val.small_nat;
210
	retaux.rndx.index=0;
211
	add_aux(retaux, ind);
212
	break;
7 7u83 213
      }
2 7u83 214
      case DIAG_TYPE_UNINIT:  case DIAG_TYPE_NULL: case DIAG_TYPE_INITED:
215
	type->bt = btNil;
7 7u83 216
	retaux.ti= (*type);
2 7u83 217
	break;
218
      case DIAG_TYPE_VARIETY: {
7 7u83 219
	switch (name(dt->data.var))
2 7u83 220
	  {
221
	  case scharhd:
7 7u83 222
	    type->bt = btChar;
223
	    retaux.ti= (*type);
2 7u83 224
	    break;
7 7u83 225
	  case ucharhd:
226
	    type->bt = btUChar;
227
	    retaux.ti= (*type);
2 7u83 228
	    break;
7 7u83 229
	  case swordhd:
230
	    type->bt = btShort;
231
	    retaux.ti= (*type);
2 7u83 232
	    break;
7 7u83 233
	  case uwordhd:
234
	    type->bt = btUShort;
235
	    retaux.ti= (*type);
2 7u83 236
	    break;
7 7u83 237
	  case slonghd:
238
	    type->bt = btInt32;
239
	    retaux.ti= (*type);
2 7u83 240
	    break;
7 7u83 241
	  case ulonghd:
242
	    type->bt = btUInt32;
243
	    retaux.ti= (*type);
2 7u83 244
	    break;
245
	  case s64hd:
246
	    type->bt = btLong64;
7 7u83 247
	    retaux.ti= (*type);
2 7u83 248
	    break;
249
	  case u64hd:
250
	    type->bt = btULong64;
7 7u83 251
	    retaux.ti= (*type);
2 7u83 252
	    break;
253
	  default: failer("DIAGS - not variety ");
254
          }
255
	break;
256
      }
257
      case DIAG_TYPE_FLOAT: {
258
	if (dt->data.f_var == 0) {
259
	  type->bt = btFloat;
260
	}
261
	else {
262
	  type->bt = btDouble;
7 7u83 263
	}
264
	retaux.ti= (*type);
2 7u83 265
	break;
266
      }
7 7u83 267
      case DIAG_TYPE_PROC: {
2 7u83 268
   /* ???  MIPS   ???  should use result type ???  */
269
	set_tq(tqProc, type, ind);
270
	type->bt = btUInt;
7 7u83 271
	retaux.ti= (*type);
2 7u83 272
	break;
273
      }
274
      case DIAG_TYPE_PTR: {
275
	firstind= set_tq(tqPtr, type, ind);
276
	dt = dt->data.ptr.object;
277
	break;
278
      }
279
      case DIAG_TYPE_STRUCT: case DIAG_TYPE_UNION: {
280
	type->bt = (dt->key == DIAG_TYPE_STRUCT)? btStruct:btUnion;
281
	retaux.ti = *type;
7 7u83 282
	if (firstind==-1) {
2 7u83 283
	  firstind=add_aux(retaux, ind);
284
	}
285
	else{
286
	  add_aux(retaux, ind);
287
	}
288
	retaux.rndx.rfd = 4095;
289
	retaux.rndx.index=find_aux(dt);
290
	add_aux(retaux,ind);
291
	retaux.rndx.rfd = mainfile;
292
	retaux.rndx.index=0;
293
	break;
294
      }
295
      case DIAG_TYPE_ARRAY: {
296
	diag_type ndt = dt->data.array.element_type;
297
	firstind=set_tq(tqArray, type, ind);
298
	dimension=1;
299
	xdt = dt;
300
	while (ndt->key==DIAG_TYPE_ARRAY) {
301
	  dimension++;
7 7u83 302
	  ndt = ndt->data.array.element_type;
2 7u83 303
	}
304
	dt = ndt;
7 7u83 305
	elemsize = type_size(ndt) >>3;
2 7u83 306
	break;
307
      }
308
      case DIAG_TYPE_ENUM: case DIAG_TYPE_LOC: {
309
	dt = dt->data.t_enum.base_type;
310
	break;
311
      }
7 7u83 312
      default:
313
	failer("bad diagnostics type");
2 7u83 314
	break;
315
      }
7 7u83 316
  }
317
  if (firstind==-1) {
2 7u83 318
    firstind=add_aux(retaux,ind);
319
  }
320
  else{
321
    add_aux(retaux,ind);
322
  }
323
  while (dimension--) {
324
    int i;
7 7u83 325
    diag_type ndt = xdt;
2 7u83 326
    for (i=1;i<dimension;i++) {
327
      ndt = ndt->data.array.element_type;
328
    }
7 7u83 329
    i = no(ndt->data.array.upper_b) - no(ndt->data.array.lower_b) -1;
2 7u83 330
    retaux.rndx.rfd = 4095;
331
    retaux.rndx.index=4;
332
    add_aux(retaux,ind);
333
    retaux.rndx.rfd = mainfile;
334
    retaux.rndx.index=0;
335
    add_aux(retaux,ind);
336
    retaux.rndx.rfd =0;
337
    add_aux(retaux,ind);
338
    retaux.rndx.rfd=i;
339
    add_aux(retaux,ind);
340
    retaux.rndx.rfd=elemsize*scale;
341
    scale =i*scale;
342
    add_aux(retaux,ind);
343
  }
344
  return firstind;
345
/* return index of first element added to the AUX table */
346
}
347
 
348
 
349
 
350
 
351
 
352
 
353
 
354
 
7 7u83 355
 
356