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) 1997
32
    		 Crown Copyright (c) 1997
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 56... Line 86...
56
 * Revision 1.5  1995/09/19  15:43:09  pwe
86
 * Revision 1.5  1995/09/19  15:43:09  pwe
57
 * round, fp overflow etc
87
 * round, fp overflow etc
58
 *
88
 *
59
 * Revision 1.4  1995/03/20  09:23:49  pwe
89
 * Revision 1.4  1995/03/20  09:23:49  pwe
60
 * move codeview into sco directory
90
 * move codeview into sco directory
61
 *
91
 *
62
 * Revision 1.3  1995/01/31  13:43:07  pwe
92
 * Revision 1.3  1995/01/31  13:43:07  pwe
63
 * correct CR95_034.-g_on_sco:_array_size_1_too_short
93
 * correct CR95_034.-g_on_sco:_array_size_1_too_short
64
 *
94
 *
65
 * Revision 1.2  1995/01/30  12:57:05  pwe
95
 * Revision 1.2  1995/01/30  12:57:05  pwe
66
 * Ownership -> PWE, tidy banners
96
 * Ownership -> PWE, tidy banners
Line 68... Line 98...
68
 * Revision 1.1  1994/07/13  08:32:41  jmf
98
 * Revision 1.1  1994/07/13  08:32:41  jmf
69
 * Initial revision
99
 * Initial revision
70
 *
100
 *
71
**********************************************************************/
101
**********************************************************************/
72
 
102
 
73
 
103
 
74
 
104
 
75
#include "config.h"
105
#include "config.h"
76
#include "common_types.h"
106
#include "common_types.h"
77
#include "cv_types.h"
107
#include "cv_types.h"
78
#include "expmacs.h"
108
#include "expmacs.h"
79
#include "out.h"
109
#include "out.h"
80
#include "xalloc.h"
110
#include "xalloc.h"
81
 
111
 
82
 
112
 
83
/* PROCEDURES */
113
/* PROCEDURES */
84
 
114
 
85
ot out_type
115
ot
86
    PROTO_N ( (t, in_struct) )
-
 
87
    PROTO_T ( diag_type t X int in_struct )
116
out_type(diag_type t, int in_struct)
88
{
117
{
89
  ot res;
118
  ot res;
90
 
119
 
91
  switch (t -> key)
120
  switch (t -> key)
92
   {
121
   {
93
     case DIAG_TYPE_VARIETY:
122
     case DIAG_TYPE_VARIETY:
94
       {
123
       {
95
         variety v = t -> data.var;
124
         variety v = t->data.var;
96
         res.modifier = 0;
125
         res.modifier = 0;
97
         res.size = shape_size(v)/8;
126
         res.size = shape_size(v) /8;
98
         res.type = 04;
127
         res.type = 04;
99
         if (res.size == 1)
128
         if (res.size == 1) {
100
           res.type = 02;
129
           res.type = 02;
-
 
130
	 }
101
         if (res.size == 2)
131
         if (res.size == 2) {
102
           res.type = 03;
132
           res.type = 03;
-
 
133
	 }
103
         if (!is_signed(v))
134
         if (!is_signed(v)) {
104
           res.type += 012;
135
           res.type += 012;
-
 
136
	 }
105
         break;
137
         break;
106
       };
138
       }
107
     case DIAG_TYPE_FLOAT:
139
     case DIAG_TYPE_FLOAT:
108
       {
140
       {
109
         floating_variety v = t -> data.f_var;
141
         floating_variety v = t->data.f_var;
110
         res.modifier = 0;
142
         res.modifier = 0;
111
         res.size = 8;
143
         res.size = 8;
112
         res.type = 07;
144
         res.type = 07;
113
         if (v == 0)
145
         if (v == 0) {
114
          {
-
 
115
            res.type = 06;
146
            res.type = 06;
116
            res.size = 4;
147
            res.size = 4;
117
          };
148
	 }
118
         break;
149
         break;
119
       };
150
       }
120
     case DIAG_TYPE_ARRAY:
151
     case DIAG_TYPE_ARRAY:
121
       {
152
       {
122
         ot arg;
153
         ot arg;
123
         int lwb = no(t -> data.array.lower_b);
154
         int lwb = no(t->data.array.lower_b);
124
         int upb = no(t -> data.array.upper_b);
155
         int upb = no(t->data.array.upper_b);
125
         int n = upb -lwb +1;
156
         int n = upb -lwb +1;
126
         arg = out_type(t -> data.array.element_type, in_struct);
157
         arg = out_type(t->data.array.element_type, in_struct);
127
         res.modifier = (arg.modifier << 2) + 3;
158
         res.modifier = (arg.modifier << 2) + 3;
128
         res.type = arg.type;
159
         res.type = arg.type;
129
         res.size = arg.size * n;
160
         res.size = arg.size * n;
130
         outs(".dim ");
161
         outs(".dim ");
131
         outn((long)n);
162
         outn((long)n);
132
         outs("; .size ");
163
         outs("; .size ");
133
         outn((long)res.size);
164
         outn((long)res.size);
134
         outs("; ");
165
         outs("; ");
135
         break;
166
         break;
136
       };
167
       }
137
     case DIAG_TYPE_PTR:
168
     case DIAG_TYPE_PTR:
138
       {
169
       {
139
         ot arg;
170
         ot arg;
140
         arg = out_type(t -> data.ptr.object, in_struct);
171
         arg = out_type(t->data.ptr.object, in_struct);
141
         res.modifier = (arg.modifier << 2) + 1;
172
         res.modifier = (arg.modifier << 2) + 1;
142
         res.size = 4;
173
         res.size = 4;
143
         res.type = arg.type;
174
         res.type = arg.type;
144
         break;
175
         break;
145
       };
176
       }
146
     case DIAG_TYPE_PROC:
177
     case DIAG_TYPE_PROC:
147
       {
178
       {
148
         ot arg;
179
         ot arg;
149
         arg = out_type(t -> data.proc.result_type, in_struct);
180
         arg = out_type(t->data.proc.result_type, in_struct);
150
         res.modifier = (arg.modifier << 4) + 9;
181
         res.modifier = (arg.modifier << 4) + 9;
151
         res.size = 4;
182
         res.size = 4;
152
         res.type = arg.type;
183
         res.type = arg.type;
153
         break;
184
         break;
154
       };
185
       }
155
     case DIAG_TYPE_STRUCT:
186
     case DIAG_TYPE_STRUCT:
156
       {
187
       {
157
         res.modifier = 0;
188
         res.modifier = 0;
158
         res.type = 010;
189
         res.type = 010;
159
         res.size = shape_size(t -> data.t_struct.tdf_shape)/8;
190
         res.size = shape_size(t->data.t_struct.tdf_shape) / 8;
160
         if (t -> been_outed == 1)  {
191
         if (t->been_outed == 1) {
161
           outs(".tag ");
192
           outs(".tag ");
162
           outs(t -> data.t_struct.nme.ints.chars);
193
           outs(t->data.t_struct.nme.ints.chars);
163
           outs("; ");
194
           outs("; ");
164
           outs(".size ");
195
           outs(".size ");
165
           outn((long)res.size);
196
           outn((long)res.size);
166
           outs("; ");
197
           outs("; ");
167
         };
198
         }
168
         break;
199
         break;
169
       };
200
       }
170
     case DIAG_TYPE_UNION:
201
     case DIAG_TYPE_UNION:
171
       {
202
       {
172
         res.modifier = 0;
203
         res.modifier = 0;
173
         res.type = 011;
204
         res.type = 011;
174
         res.size = shape_size(t -> data.t_union.tdf_shape)/8;
205
         res.size = shape_size(t->data.t_union.tdf_shape) / 8;
175
         if (t -> been_outed == 1)  {
206
         if (t->been_outed == 1) {
176
           outs(".tag ");
207
           outs(".tag ");
177
           outs(t -> data.t_union.nme.ints.chars);
208
           outs(t->data.t_union.nme.ints.chars);
178
           outs("; ");
209
           outs("; ");
179
           outs(".size ");
210
           outs(".size ");
180
           outn((long)res.size);
211
           outn((long)res.size);
181
           outs("; ");
212
           outs("; ");
182
         };
213
         }
183
         break;
214
         break;
184
       };
215
       }
185
     case DIAG_TYPE_ENUM:
216
     case DIAG_TYPE_ENUM:
186
       {
217
       {
187
         ot arg;
218
         ot arg;
188
         arg = out_type(t -> data.t_enum.base_type, in_struct);
219
         arg = out_type(t->data.t_enum.base_type, in_struct);
189
         res.modifier = 0;
220
         res.modifier = 0;
190
         res.type = 012;
221
         res.type = 012;
191
         res.size = arg.size;
222
         res.size = arg.size;
192
         if (!in_struct)  {
223
         if (!in_struct) {
193
           outs(".tag ");
224
           outs(".tag ");
194
           outs(t -> data.t_struct.nme.ints.chars);
225
           outs(t->data.t_struct.nme.ints.chars);
195
           outs("; ");
226
           outs("; ");
196
         };
227
         }
197
         outs(".size ");
228
         outs(".size ");
198
         outn((long)res.size);
229
         outn((long)res.size);
199
         outs("; ");
230
         outs("; ");
200
         break;
231
         break;
201
       };
232
       }
202
     case DIAG_TYPE_NULL:
233
     case DIAG_TYPE_NULL:
203
       {
234
       {
204
         res.modifier = 0;
235
         res.modifier = 0;
205
         res.size = 4;
236
         res.size = 4;
206
         res.type = 4;
237
         res.type = 4;
207
         break;
238
         break;
208
       };
239
       }
209
     case DIAG_TYPE_LOC:
240
     case DIAG_TYPE_LOC:
210
       res = out_type(t -> data.loc.object, in_struct);
241
       res = out_type(t->data.loc.object, in_struct);
211
       break;
242
       break;
212
     default:
243
     default:
213
/*
244
/*
214
       failer("outtype not yet implemented");
245
       failer("outtype not yet implemented");
215
*/
246
*/
216
       res.modifier = 0;
247
       res.modifier = 0;
217
       res.size = 4;
248
       res.size = 4;
218
       res.type = 4;
249
       res.type = 4;
219
       break;
250
       break;
220
   };
251
   }
221
  return res;
252
  return res;
222
}
253
}
223
 
254
 
224
static int fixup_no = 0;
255
static int fixup_no = 0;
225
 
256
 
226
 
257
 
227
static void fixup
258
static void
228
    PROTO_N ( (n) )
-
 
229
    PROTO_T ( char ** n )
259
fixup(char **n)
230
{
260
{
231
  if (*n == (char*)0 || (*n)[0] == 0)
261
  if (*n == (char *)0 || (*n)[0] == 0) {
232
    {
-
 
233
      char * k = (char*)xcalloc(10, sizeof(char));
262
      char * k = (char*)xcalloc(10, sizeof(char));
234
      k[0] = '.';
263
      k[0] = '.';
235
      sprintf(&k[1], "%d", fixup_no++);
264
      sprintf(&k[1], "%d", fixup_no++);
236
      strcpy(k + strlen(k), "fake");
265
      strcpy(k + strlen(k), "fake");
237
      *n = k;
266
      *n = k;
238
    };
267
  }
239
  return;
268
  return;
240
}
269
}
241
 
270
 
242
void out_tagged
271
void
243
    PROTO_N ( (d) )
-
 
244
    PROTO_T ( diag_type d )
272
out_tagged(diag_type d)
245
{
273
{
246
  int i;
274
  int i;
247
  if ( d -> been_outed )
275
  if (d->been_outed) {
248
     return;
276
     return;
-
 
277
  }
249
  switch (d -> key)
278
  switch (d->key)
250
   {
279
   {
251
     case DIAG_TYPE_STRUCT:
280
     case DIAG_TYPE_STRUCT:
252
      {
281
      {
253
        struct diag_field_list_t fs;
282
        struct diag_field_list_t fs;
254
        int sz_in_bits = shape_size(d -> data.t_struct.tdf_shape);
283
        int sz_in_bits = shape_size(d->data.t_struct.tdf_shape);
255
        int sz = sz_in_bits/8;
284
        int sz = sz_in_bits / 8;
256
        fs = *d -> data.t_struct.fields;
285
        fs = *d->data.t_struct.fields;
257
        fixup(&d -> data.t_struct.nme.ints.chars);
286
        fixup(&d->data.t_struct.nme.ints.chars);
258
 
287
 
259
	d -> been_outed = -1;
288
	d->been_outed = -1;
260
        for (i=fs.len-1; i>=0; --i)
289
        for (i = fs.len - 1; i >= 0; --i) {
261
         { struct diag_field_t f;
290
	   struct diag_field_t f;
262
           f = *fs.array[i];
291
           f = *fs.array[i];
263
	   out_tagged (f.field_type);
292
	   out_tagged(f.field_type);
264
	 }
293
	}
265
 
294
 
266
        fprintf(fpout, " .def %s; .scl 10; .type 010; .size %d; .endef\n",
295
        fprintf(fpout, " .def %s; .scl 10; .type 010; .size %d; .endef\n",
267
                  d -> data.t_struct.nme.ints.chars, sz);
296
		d->data.t_struct.nme.ints.chars, sz);
268
	d -> been_outed = 1;
297
	d->been_outed = 1;
269
        for (i=fs.len-1; i>=0; --i)
298
        for (i=fs.len-1; i>=0; --i) {
270
         { struct diag_field_t f;
299
	   struct diag_field_t f;
271
           ot ty;
300
           ot ty;
272
           f = *fs.array[i];
301
           f = *fs.array[i];
273
 
302
 
274
           if (f.field_type -> key == DIAG_TYPE_BITFIELD)  {
303
           if (f.field_type->key == DIAG_TYPE_BITFIELD) {
275
             fprintf(fpout, " .def %s; .val %d; .scl 18; .type 04; .size %d; .endef\n",
304
             fprintf(fpout,
276
                       f.field_name.ints.chars,
305
		     " .def %s; .val %d; .scl 18; .type 04; .size %d; .endef\n",
277
                       no(f.where),
306
		     f.field_name.ints.chars, no(f.where),
278
                       f.field_type -> data.bitfield.no_of_bits.nat_val.small_nat);
307
		     f.field_type->data.bitfield.no_of_bits.nat_val.small_nat);
279
           }
-
 
280
           else  {
308
           } else {
281
             fprintf(fpout, " .def %s; .val %d; .scl 8; ",
309
             fprintf(fpout, " .def %s; .val %d; .scl 8; ",
282
                    f.field_name.ints.chars,
-
 
283
                    no(f.where)/8);
310
		     f.field_name.ints.chars, no(f.where) / 8);
284
             ty = out_type(f.field_type, 1);
311
             ty = out_type(f.field_type, 1);
285
             fprintf(fpout, ".type 0%o; .endef\n",
312
             fprintf(fpout, ".type 0%o; .endef\n", ty.type +
286
                    ty.type + (ty.modifier << 4));
313
		     (ty.modifier << 4));
287
           };
314
	   }
-
 
315
	}
288
         };
316
        fprintf(fpout,
289
        fprintf(fpout, " .def .eos; .val %d; .scl 102; .tag %s; .size %d; .endef\n",
317
		" .def .eos; .val %d; .scl 102; .tag %s; .size %d; .endef\n",
290
                  sz, d -> data.t_struct.nme.ints.chars, sz);
318
		sz, d->data.t_struct.nme.ints.chars, sz);
291
        return;
319
        return;
292
      };
320
      }
293
     case DIAG_TYPE_UNION:
321
     case DIAG_TYPE_UNION:
294
      {
322
      {
295
        struct diag_field_list_t fs;
323
        struct diag_field_list_t fs;
296
        int sz_in_bits = shape_size(d -> data.t_union.tdf_shape);
324
        int sz_in_bits = shape_size(d->data.t_union.tdf_shape);
297
        int sz = sz_in_bits/8;
325
        int sz = sz_in_bits / 8;
298
        fs = *d -> data.t_union.fields;
326
        fs = *d->data.t_union.fields;
299
        fixup(&d -> data.t_union.nme.ints.chars);
327
        fixup(&d->data.t_union.nme.ints.chars);
300
 
328
 
301
	d -> been_outed = -1;
329
	d->been_outed = -1;
302
        for (i=fs.len-1; i>=0; --i)
330
        for (i = fs.len - 1; i >= 0; --i) {
303
         { struct diag_field_t f;
331
	   struct diag_field_t f;
304
           f = *fs.array[i];
332
           f = *fs.array[i];
305
	   out_tagged (f.field_type);
333
	   out_tagged(f.field_type);
306
	 }
334
	}
307
 
335
 
308
        fprintf(fpout, " .def %s; .scl 12; .type 011; .size %d; .endef\n",
336
        fprintf(fpout, " .def %s; .scl 12; .type 011; .size %d; .endef\n",
309
                  d -> data.t_union.nme.ints.chars, sz);
337
		d->data.t_union.nme.ints.chars, sz);
310
	d -> been_outed = 1;
338
	d->been_outed = 1;
311
        for (i=fs.len-1; i>=0; --i)
339
        for (i = fs.len - 1; i >= 0; --i) {
312
         { struct diag_field_t f;
340
	   struct diag_field_t f;
313
           ot ty;
341
           ot ty;
314
           f = *fs.array[i];
342
           f = *fs.array[i];
315
 
343
 
316
           fprintf(fpout, " .def %s; .val 0; .scl 11; ",
344
           fprintf(fpout, " .def %s; .val 0; .scl 11; ",
317
                    f.field_name.ints.chars);
345
		   f.field_name.ints.chars);
318
           ty = out_type(f.field_type, 1);
346
           ty = out_type(f.field_type, 1);
319
           fprintf(fpout, ".type 0%o; .endef\n",
347
           fprintf(fpout, ".type 0%o; .endef\n", ty.type + (ty.modifier << 4));
320
                    ty.type + (ty.modifier << 4));
-
 
-
 
348
	}
321
         };
349
        fprintf(fpout,
322
        fprintf(fpout, " .def .eos; .val %d; .scl 102; .tag %s; .size %d; .endef\n",
350
		" .def .eos; .val %d; .scl 102; .tag %s; .size %d; .endef\n",
323
                  sz, d -> data.t_union.nme.ints.chars, sz);
351
		sz, d->data.t_union.nme.ints.chars, sz);
324
        return;
352
        return;
325
      };
353
      }
326
     case DIAG_TYPE_ENUM:
354
     case DIAG_TYPE_ENUM:
327
      {
355
      {
328
        struct enum_values_list_t es;
356
        struct enum_values_list_t es;
329
        int sz = 4;
357
        int sz = 4;
330
        es = *d -> data.t_enum.values;
358
        es = *d->data.t_enum.values;
331
        fixup(&d -> data.t_enum.nme.ints.chars);
359
        fixup(&d->data.t_enum.nme.ints.chars);
332
 
360
 
333
        fprintf(fpout, " .def %s; .scl 15; .type 012; .size %d; .endef\n",
361
        fprintf(fpout, " .def %s; .scl 15; .type 012; .size %d; .endef\n",
334
                  d -> data.t_enum.nme.ints.chars, sz);
362
		d->data.t_enum.nme.ints.chars, sz);
335
        for (i=es.len-1; i>=0; --i)
363
        for (i = es.len - 1; i >= 0; --i) {
336
         { struct enum_values_t e;
364
	   struct enum_values_t e;
337
           e = *es.array[i];
365
           e = *es.array[i];
338
           fprintf(fpout, " .def %s; .val %d; .scl 16; .type 013; .endef\n",
366
           fprintf(fpout, " .def %s; .val %d; .scl 16; .type 013; .endef\n",
339
                    e.nme.ints.chars, no(e.val));
367
		   e.nme.ints.chars, no(e.val));
-
 
368
	}
340
         };
369
        fprintf(fpout,
341
        fprintf(fpout, " .def .eos; .val %d; .scl 102; .tag %s; .size %d; .endef\n",
370
		" .def .eos; .val %d; .scl 102; .tag %s; .size %d; .endef\n",
342
                  sz, d -> data.t_enum.nme.ints.chars, sz);
371
		sz, d->data.t_enum.nme.ints.chars, sz);
343
        return;
372
        return;
344
      };
373
      }
345
     default:
374
     default:
346
        return;
375
        return;
347
   };
376
   }
348
}
377
}
349
 
-