Subversion Repositories tendra.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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