Subversion Repositories tendra.SVN

Rev

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

Rev Author Line No. Line
2 7u83 1
/*
7 7u83 2
 * Copyright (c) 2002-2005 The TenDRA Project <http://www.tendra.org/>.
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions are met:
7
 *
8
 * 1. Redistributions of source code must retain the above copyright notice,
9
 *    this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
11
 *    this list of conditions and the following disclaimer in the documentation
12
 *    and/or other materials provided with the distribution.
13
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
14
 *    may be used to endorse or promote products derived from this software
15
 *    without specific, prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 *
29
 * $Id$
30
 */
31
/*
2 7u83 32
    		 Crown Copyright (c) 1997
33
 
34
    This TenDRA(r) Computer Program is subject to Copyright
35
    owned by the United Kingdom Secretary of State for Defence
36
    acting through the Defence Evaluation and Research Agency
37
    (DERA).  It is made available to Recipients with a
38
    royalty-free licence for its use, reproduction, transfer
39
    to other parties and amendment for any purpose not excluding
40
    product development provided that any such use et cetera
41
    shall be deemed to be acceptance of the following conditions:-
42
 
43
        (1) Its Recipients shall ensure that this Notice is
44
        reproduced upon any copies or amended versions of it;
45
 
46
        (2) Any amended version of it shall be clearly marked to
47
        show both the nature of and the organisation responsible
48
        for the relevant amendment or amendments;
49
 
50
        (3) Its onward transfer from a recipient to another
51
        party shall be deemed to be that party's acceptance of
52
        these conditions;
53
 
54
        (4) DERA gives no warranty or assurance as to its
55
        quality or suitability for any purpose and DERA accepts
56
        no liability whatsoever in relation to any use to which
57
        it may be put.
58
*/
59
 
60
 
61
/* sco/cv_outtype.c */
62
 
63
/**********************************************************************
64
$Author: release $
65
$Date: 1998/01/17 15:55:51 $
66
$Revision: 1.1.1.1 $
67
$Log: cv_outtype.c,v $
68
 * Revision 1.1.1.1  1998/01/17  15:55:51  release
69
 * First version to be checked into rolling release.
70
 *
71
 * Revision 1.10  1997/03/24  12:43:40  pwe
72
 * outn int->long
73
 *
74
 * Revision 1.9  1996/02/22  10:03:44  pwe
75
 * sco diag recursive struct (& clearinlined)
76
 *
77
 * Revision 1.8  1995/11/30  10:19:54  pwe
78
 * diag struct struct
79
 *
80
 * Revision 1.7  1995/10/23  17:34:37  pwe
81
 * dynamic initialisation PIC, and sco diags
82
 *
83
 * Revision 1.6  1995/10/18  11:24:43  pwe
84
 * diag struct
85
 *
86
 * Revision 1.5  1995/09/19  15:43:09  pwe
87
 * round, fp overflow etc
88
 *
89
 * Revision 1.4  1995/03/20  09:23:49  pwe
90
 * move codeview into sco directory
91
 *
92
 * Revision 1.3  1995/01/31  13:43:07  pwe
93
 * correct CR95_034.-g_on_sco:_array_size_1_too_short
94
 *
95
 * Revision 1.2  1995/01/30  12:57:05  pwe
96
 * Ownership -> PWE, tidy banners
97
 *
98
 * Revision 1.1  1994/07/13  08:32:41  jmf
99
 * Initial revision
100
 *
101
**********************************************************************/
102
 
103
 
104
 
105
#include "config.h"
106
#include "common_types.h"
107
#include "cv_types.h"
108
#include "expmacs.h"
109
#include "out.h"
110
#include "xalloc.h"
111
 
112
 
113
/* PROCEDURES */
114
 
7 7u83 115
ot
116
out_type(diag_type t, int in_struct)
2 7u83 117
{
118
  ot res;
119
 
120
  switch (t -> key)
121
   {
122
     case DIAG_TYPE_VARIETY:
123
       {
7 7u83 124
         variety v = t->data.var;
2 7u83 125
         res.modifier = 0;
7 7u83 126
         res.size = shape_size(v) /8;
2 7u83 127
         res.type = 04;
7 7u83 128
         if (res.size == 1) {
2 7u83 129
           res.type = 02;
7 7u83 130
	 }
131
         if (res.size == 2) {
2 7u83 132
           res.type = 03;
7 7u83 133
	 }
134
         if (!is_signed(v)) {
2 7u83 135
           res.type += 012;
7 7u83 136
	 }
2 7u83 137
         break;
7 7u83 138
       }
2 7u83 139
     case DIAG_TYPE_FLOAT:
140
       {
7 7u83 141
         floating_variety v = t->data.f_var;
2 7u83 142
         res.modifier = 0;
143
         res.size = 8;
144
         res.type = 07;
7 7u83 145
         if (v == 0) {
2 7u83 146
            res.type = 06;
147
            res.size = 4;
7 7u83 148
	 }
2 7u83 149
         break;
7 7u83 150
       }
2 7u83 151
     case DIAG_TYPE_ARRAY:
152
       {
153
         ot arg;
7 7u83 154
         int lwb = no(t->data.array.lower_b);
155
         int upb = no(t->data.array.upper_b);
2 7u83 156
         int n = upb -lwb +1;
7 7u83 157
         arg = out_type(t->data.array.element_type, in_struct);
2 7u83 158
         res.modifier = (arg.modifier << 2) + 3;
159
         res.type = arg.type;
160
         res.size = arg.size * n;
161
         outs(".dim ");
162
         outn((long)n);
163
         outs("; .size ");
164
         outn((long)res.size);
165
         outs("; ");
166
         break;
7 7u83 167
       }
2 7u83 168
     case DIAG_TYPE_PTR:
169
       {
170
         ot arg;
7 7u83 171
         arg = out_type(t->data.ptr.object, in_struct);
2 7u83 172
         res.modifier = (arg.modifier << 2) + 1;
173
         res.size = 4;
174
         res.type = arg.type;
175
         break;
7 7u83 176
       }
2 7u83 177
     case DIAG_TYPE_PROC:
178
       {
179
         ot arg;
7 7u83 180
         arg = out_type(t->data.proc.result_type, in_struct);
2 7u83 181
         res.modifier = (arg.modifier << 4) + 9;
182
         res.size = 4;
183
         res.type = arg.type;
184
         break;
7 7u83 185
       }
2 7u83 186
     case DIAG_TYPE_STRUCT:
187
       {
188
         res.modifier = 0;
189
         res.type = 010;
7 7u83 190
         res.size = shape_size(t->data.t_struct.tdf_shape) / 8;
191
         if (t->been_outed == 1) {
2 7u83 192
           outs(".tag ");
7 7u83 193
           outs(t->data.t_struct.nme.ints.chars);
2 7u83 194
           outs("; ");
195
           outs(".size ");
196
           outn((long)res.size);
197
           outs("; ");
7 7u83 198
         }
2 7u83 199
         break;
7 7u83 200
       }
2 7u83 201
     case DIAG_TYPE_UNION:
202
       {
203
         res.modifier = 0;
204
         res.type = 011;
7 7u83 205
         res.size = shape_size(t->data.t_union.tdf_shape) / 8;
206
         if (t->been_outed == 1) {
2 7u83 207
           outs(".tag ");
7 7u83 208
           outs(t->data.t_union.nme.ints.chars);
2 7u83 209
           outs("; ");
210
           outs(".size ");
211
           outn((long)res.size);
212
           outs("; ");
7 7u83 213
         }
2 7u83 214
         break;
7 7u83 215
       }
2 7u83 216
     case DIAG_TYPE_ENUM:
217
       {
218
         ot arg;
7 7u83 219
         arg = out_type(t->data.t_enum.base_type, in_struct);
2 7u83 220
         res.modifier = 0;
221
         res.type = 012;
222
         res.size = arg.size;
7 7u83 223
         if (!in_struct) {
2 7u83 224
           outs(".tag ");
7 7u83 225
           outs(t->data.t_struct.nme.ints.chars);
2 7u83 226
           outs("; ");
7 7u83 227
         }
2 7u83 228
         outs(".size ");
229
         outn((long)res.size);
230
         outs("; ");
231
         break;
7 7u83 232
       }
2 7u83 233
     case DIAG_TYPE_NULL:
234
       {
235
         res.modifier = 0;
236
         res.size = 4;
237
         res.type = 4;
238
         break;
7 7u83 239
       }
2 7u83 240
     case DIAG_TYPE_LOC:
7 7u83 241
       res = out_type(t->data.loc.object, in_struct);
2 7u83 242
       break;
243
     default:
244
/*
245
       failer("outtype not yet implemented");
246
*/
247
       res.modifier = 0;
248
       res.size = 4;
249
       res.type = 4;
250
       break;
7 7u83 251
   }
2 7u83 252
  return res;
253
}
254
 
255
static int fixup_no = 0;
256
 
257
 
7 7u83 258
static void
259
fixup(char **n)
2 7u83 260
{
7 7u83 261
  if (*n == (char *)0 || (*n)[0] == 0) {
2 7u83 262
      char * k = (char*)xcalloc(10, sizeof(char));
263
      k[0] = '.';
264
      sprintf(&k[1], "%d", fixup_no++);
265
      strcpy(k + strlen(k), "fake");
266
      *n = k;
7 7u83 267
  }
2 7u83 268
  return;
269
}
270
 
7 7u83 271
void
272
out_tagged(diag_type d)
2 7u83 273
{
274
  int i;
7 7u83 275
  if (d->been_outed) {
2 7u83 276
     return;
7 7u83 277
  }
278
  switch (d->key)
2 7u83 279
   {
280
     case DIAG_TYPE_STRUCT:
281
      {
282
        struct diag_field_list_t fs;
7 7u83 283
        int sz_in_bits = shape_size(d->data.t_struct.tdf_shape);
284
        int sz = sz_in_bits / 8;
285
        fs = *d->data.t_struct.fields;
286
        fixup(&d->data.t_struct.nme.ints.chars);
2 7u83 287
 
7 7u83 288
	d->been_outed = -1;
289
        for (i = fs.len - 1; i >= 0; --i) {
290
	   struct diag_field_t f;
2 7u83 291
           f = *fs.array[i];
7 7u83 292
	   out_tagged(f.field_type);
293
	}
2 7u83 294
 
295
        fprintf(fpout, " .def %s; .scl 10; .type 010; .size %d; .endef\n",
7 7u83 296
		d->data.t_struct.nme.ints.chars, sz);
297
	d->been_outed = 1;
298
        for (i=fs.len-1; i>=0; --i) {
299
	   struct diag_field_t f;
2 7u83 300
           ot ty;
301
           f = *fs.array[i];
302
 
7 7u83 303
           if (f.field_type->key == DIAG_TYPE_BITFIELD) {
304
             fprintf(fpout,
305
		     " .def %s; .val %d; .scl 18; .type 04; .size %d; .endef\n",
306
		     f.field_name.ints.chars, no(f.where),
307
		     f.field_type->data.bitfield.no_of_bits.nat_val.small_nat);
308
           } else {
2 7u83 309
             fprintf(fpout, " .def %s; .val %d; .scl 8; ",
7 7u83 310
		     f.field_name.ints.chars, no(f.where) / 8);
2 7u83 311
             ty = out_type(f.field_type, 1);
7 7u83 312
             fprintf(fpout, ".type 0%o; .endef\n", ty.type +
313
		     (ty.modifier << 4));
314
	   }
315
	}
316
        fprintf(fpout,
317
		" .def .eos; .val %d; .scl 102; .tag %s; .size %d; .endef\n",
318
		sz, d->data.t_struct.nme.ints.chars, sz);
2 7u83 319
        return;
7 7u83 320
      }
2 7u83 321
     case DIAG_TYPE_UNION:
322
      {
323
        struct diag_field_list_t fs;
7 7u83 324
        int sz_in_bits = shape_size(d->data.t_union.tdf_shape);
325
        int sz = sz_in_bits / 8;
326
        fs = *d->data.t_union.fields;
327
        fixup(&d->data.t_union.nme.ints.chars);
2 7u83 328
 
7 7u83 329
	d->been_outed = -1;
330
        for (i = fs.len - 1; i >= 0; --i) {
331
	   struct diag_field_t f;
2 7u83 332
           f = *fs.array[i];
7 7u83 333
	   out_tagged(f.field_type);
334
	}
2 7u83 335
 
336
        fprintf(fpout, " .def %s; .scl 12; .type 011; .size %d; .endef\n",
7 7u83 337
		d->data.t_union.nme.ints.chars, sz);
338
	d->been_outed = 1;
339
        for (i = fs.len - 1; i >= 0; --i) {
340
	   struct diag_field_t f;
2 7u83 341
           ot ty;
342
           f = *fs.array[i];
343
 
344
           fprintf(fpout, " .def %s; .val 0; .scl 11; ",
7 7u83 345
		   f.field_name.ints.chars);
2 7u83 346
           ty = out_type(f.field_type, 1);
7 7u83 347
           fprintf(fpout, ".type 0%o; .endef\n", ty.type + (ty.modifier << 4));
348
	}
349
        fprintf(fpout,
350
		" .def .eos; .val %d; .scl 102; .tag %s; .size %d; .endef\n",
351
		sz, d->data.t_union.nme.ints.chars, sz);
2 7u83 352
        return;
7 7u83 353
      }
2 7u83 354
     case DIAG_TYPE_ENUM:
355
      {
356
        struct enum_values_list_t es;
357
        int sz = 4;
7 7u83 358
        es = *d->data.t_enum.values;
359
        fixup(&d->data.t_enum.nme.ints.chars);
2 7u83 360
 
361
        fprintf(fpout, " .def %s; .scl 15; .type 012; .size %d; .endef\n",
7 7u83 362
		d->data.t_enum.nme.ints.chars, sz);
363
        for (i = es.len - 1; i >= 0; --i) {
364
	   struct enum_values_t e;
2 7u83 365
           e = *es.array[i];
366
           fprintf(fpout, " .def %s; .val %d; .scl 16; .type 013; .endef\n",
7 7u83 367
		   e.nme.ints.chars, no(e.val));
368
	}
369
        fprintf(fpout,
370
		" .def .eos; .val %d; .scl 102; .tag %s; .size %d; .endef\n",
371
		sz, d->data.t_enum.nme.ints.chars, sz);
2 7u83 372
        return;
7 7u83 373
      }
2 7u83 374
     default:
375
        return;
7 7u83 376
   }
2 7u83 377
}