irmode.c 11.1 KB
Newer Older
Christian Schäfer's avatar
Christian Schäfer committed
1
2
3
4
5
6
7
/* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
** All rights reserved.
**
** Authors: Martin Trapp, Christian Schaefer
**
*/

Boris Boesler's avatar
Boris Boesler committed
8
9
/* $Id$ */

Boris Boesler's avatar
added    
Boris Boesler committed
10
11
12
13
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

Götz Lindenmaier's avatar
Götz Lindenmaier committed
14
# include "irmode_t.h"
Christian Schäfer's avatar
Christian Schäfer committed
15
16
# include <malloc.h>
# include <stddef.h>
17
# include <string.h>
Christian Schäfer's avatar
Christian Schäfer committed
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# include "tv.h"

ir_mode *mode_T;
ir_mode *mode_f;
ir_mode *mode_d;
ir_mode *mode_c;
ir_mode *mode_C;
ir_mode *mode_h;
ir_mode *mode_H;
ir_mode *mode_i;
ir_mode *mode_I;
ir_mode *mode_l;
ir_mode *mode_L;
ir_mode *mode_B;
ir_mode *mode_b;
ir_mode *mode_p;
ir_mode *mode_s;
ir_mode *mode_S;
ir_mode *mode_X;
ir_mode *mode_M;
ir_mode *mode_R;
ir_mode *mode_Z;

void
init_mode (void)
{
Götz Lindenmaier's avatar
Götz Lindenmaier committed
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
  /* allocate all modes. We need to memset them as tarval_vrfy
     reads fields before they are initialized: It compares to
     min/max when tarvals for min/max are allocated!  */
  mode_T = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_T, 0, sizeof(ir_mode));
  mode_f = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_f, 0, sizeof(ir_mode));
  mode_d = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_d, 0, sizeof(ir_mode));
  mode_c = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_c, 0, sizeof(ir_mode));
  mode_C = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_C, 0, sizeof(ir_mode));
  mode_h = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_h, 0, sizeof(ir_mode));
  mode_H = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_H, 0, sizeof(ir_mode));
  mode_i = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_i, 0, sizeof(ir_mode));
  mode_I = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_I, 0, sizeof(ir_mode));
  mode_l = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_l, 0, sizeof(ir_mode));
  mode_L = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_L, 0, sizeof(ir_mode));
  mode_B = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_B, 0, sizeof(ir_mode));
  mode_b = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_b, 0, sizeof(ir_mode));
  mode_p = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_p, 0, sizeof(ir_mode));
  mode_s = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_s, 0, sizeof(ir_mode));
  mode_S = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_S, 0, sizeof(ir_mode));
  mode_X = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_X, 0, sizeof(ir_mode));
  mode_M = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_M, 0, sizeof(ir_mode));
  mode_R = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_R, 0, sizeof(ir_mode));
  mode_Z = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_Z, 0, sizeof(ir_mode));
Christian Schäfer's avatar
Christian Schäfer committed
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98

  mode_T->code = irm_T;
  mode_f->code = irm_f;
  mode_d->code = irm_d;
  mode_c->code = irm_c;
  mode_C->code = irm_C;
  mode_h->code = irm_h;
  mode_H->code = irm_H;
  mode_i->code = irm_i;
  mode_I->code = irm_I;
  mode_l->code = irm_l;
  mode_L->code = irm_L;
  mode_B->code = irm_B;
  mode_b->code = irm_b;
  mode_p->code = irm_p;
  mode_s->code = irm_s;
  mode_S->code = irm_S;
  mode_X->code = irm_X;
  mode_M->code = irm_M;
  mode_R->code = irm_R;
  mode_Z->code = irm_Z;

  /* initialize all modes */

  mode_T->name = id_from_str ("T", 1);
  mode_T->fsigned = 0;
  mode_T->ffloat = 0;

  /* float */
  mode_f->name = id_from_str ("f", 1);
  mode_f->fsigned = 1;
  mode_f->ffloat = 1;
99
100
  mode_f->ld_align = 4;
  mode_f->size = 4;
Christian Schäfer's avatar
Christian Schäfer committed
101
102
103
104
105

  /* double */
  mode_d->name = id_from_str ("d", 1);
  mode_d->fsigned = 1;
  mode_d->ffloat = 1;
106
107
  mode_d->ld_align = 4;
  mode_d->size = 8;
Christian Schäfer's avatar
Christian Schäfer committed
108
109
110
111
112

  /* signed char */
  mode_c->name = id_from_str ("c", 1);
  mode_c->fsigned = 1;
  mode_c->ffloat = 0;
Boris Boesler's avatar
Boris Boesler committed
113
  mode_c->ld_align = 1;
Christian Schäfer's avatar
Christian Schäfer committed
114
115
116
117
118
119
120
121
122
  mode_c->size = 1;
  mode_c->min = tarval_from_long (mode_l, 0xffffff80);
  mode_c->max = tarval_from_long (mode_l, 0x0000007f);
  mode_c->null = tarval_from_long (mode_c, 0);

  /* unsigned char */
  mode_C->name = id_from_str ("C", 1);
  mode_C->fsigned = 0;
  mode_C->ffloat = 0;
Boris Boesler's avatar
Boris Boesler committed
123
  mode_C->ld_align = 1;
Christian Schäfer's avatar
Christian Schäfer committed
124
125
126
127
128
129
130
131
132
  mode_C->size = 1;
  mode_C->min = tarval_from_long (mode_L, 0x00000000);
  mode_C->max = tarval_from_long (mode_L, 0x000000ff);
  mode_C->null = tarval_from_long (mode_C, 0);

  /* signed short integer */
  mode_h->name = id_from_str ("h", 1);
  mode_h->fsigned = 1;
  mode_h->ffloat = 0;
Boris Boesler's avatar
Boris Boesler committed
133
134
  mode_h->ld_align = 2;
  mode_h->size = 2;
Christian Schäfer's avatar
Christian Schäfer committed
135
136
137
138
139
140
141
142
  mode_h->min = tarval_from_long (mode_l, 0xffff8000);
  mode_h->max = tarval_from_long (mode_l, 0x00007fff);
  mode_h->null = tarval_from_long (mode_h, 0);

  /* unsigened short integer */
  mode_H->name = id_from_str ("H", 1);
  mode_H->fsigned = 0;
  mode_H->ffloat = 0;
Boris Boesler's avatar
Boris Boesler committed
143
144
  mode_H->ld_align = 2;
  mode_H->size = 2;
Christian Schäfer's avatar
Christian Schäfer committed
145
146
147
148
149
150
151
152
  mode_H->min = tarval_from_long (mode_L, 0x00000000);
  mode_H->max = tarval_from_long (mode_L, 0x0000ffff);
  mode_H->null = tarval_from_long (mode_H, 0);

  /* signed integer */
  mode_i->name = id_from_str ("i", 1);
  mode_i->fsigned = 1;
  mode_i->ffloat = 0;
Boris Boesler's avatar
Boris Boesler committed
153
  mode_i->ld_align = 4;
Christian Schäfer's avatar
Christian Schäfer committed
154
155
156
157
158
159
160
161
162
  mode_i->size = 4;
  mode_i->min = tarval_from_long (mode_l, 0x80000000);
  mode_i->max = tarval_from_long (mode_l, 0x7fffffff);
  mode_i->null = tarval_from_long (mode_i, 0);

  /* unsigned integer */
  mode_I->name = id_from_str ("I", 1);
  mode_I->fsigned = 0;
  mode_I->ffloat = 0;
Boris Boesler's avatar
Boris Boesler committed
163
  mode_I->ld_align = 4;
Christian Schäfer's avatar
Christian Schäfer committed
164
165
166
167
168
169
170
171
172
  mode_I->size = 4;
  mode_I->min = tarval_from_long (mode_L, 0x00000000);
  mode_I->max = tarval_from_long (mode_L, 0xffffffff);
  mode_I->null = tarval_from_long (mode_I, 0);

  /* signed long integer */
  mode_l->name = id_from_str ("l", 1);
  mode_l->fsigned = 1;
  mode_l->ffloat = 0;
Boris Boesler's avatar
Boris Boesler committed
173
  mode_l->ld_align = 4;
Christian Schäfer's avatar
Christian Schäfer committed
174
175
176
177
178
179
180
181
182
  mode_l->size = 4;
  mode_l->min = tarval_from_long (mode_l, 0x80000000);
  mode_l->max = tarval_from_long (mode_l, 0x7fffffff);
  mode_I->null = tarval_from_long (mode_l, 0);

  /* unsigned long integer */
  mode_L->name = id_from_str ("L", 1);
  mode_L->fsigned = 0;
  mode_L->ffloat = 0;
Boris Boesler's avatar
Boris Boesler committed
183
  mode_L->ld_align = 4;
Christian Schäfer's avatar
Christian Schäfer committed
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
  mode_L->size = 4;
  mode_L->min = tarval_from_long (mode_L, 0x00000000);
  mode_L->max = tarval_from_long (mode_L, 0xffffffff);
  mode_L->null = tarval_from_long (mode_L, 0);

  /* universal bits */
  mode_B->name = id_from_str ("B", 1);
  mode_B->fsigned = 0;
  mode_B->ffloat = 0;

  /* boolean */
  mode_b->name = id_from_str ("b", 1);
  mode_b->fsigned = 0;
  mode_b->ffloat = 0;

  /* pointer */
  mode_p->name = id_from_str ("p", 1);
  mode_p->fsigned = 0;
  mode_p->ffloat = 0;
Boris Boesler's avatar
Boris Boesler committed
203
  mode_p->ld_align = 4;
Christian Schäfer's avatar
Christian Schäfer committed
204
205
206
207
208
209
210
211
212
213
214
215
216
  mode_p->size = 4;
  mode_p->min = tarval_from_long (mode_L, 0x00000000);
  mode_p->max = tarval_from_long (mode_L, 0xffffffff);
  mode_p->null = tarval_from_long (mode_p, 0);

  mode_s->name = id_from_str ("s", 1);
  mode_s->fsigned = 0;
  mode_s->ffloat = 0;

  mode_S->name = id_from_str ("S", 1);
  mode_S->fsigned = 0;
  mode_S->ffloat = 0;

Götz Lindenmaier's avatar
Götz Lindenmaier committed
217
  /* Execution */
Christian Schäfer's avatar
Christian Schäfer committed
218
219
220
221
  mode_X->name = id_from_str ("X", 1);
  mode_X->fsigned = 0;
  mode_X->ffloat = 0;

Götz Lindenmaier's avatar
Götz Lindenmaier committed
222
  /* Memory */
Christian Schäfer's avatar
Christian Schäfer committed
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
  mode_M->name = id_from_str ("M", 1);
  mode_M->fsigned = 0;
  mode_M->ffloat = 0;

  mode_R->name = id_from_str ("R", 1);
  mode_R->fsigned = 0;
  mode_R->ffloat = 0;

  mode_Z->name = id_from_str ("Z", 1);
  mode_Z->fsigned = 1;
  mode_Z->ffloat = 0;
}

/* Functions for the direct access to all attributes od a ir_mode */

modecode
Götz Lindenmaier's avatar
Götz Lindenmaier committed
239
get_mode_modecode (ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
240
241
242
243
244
{
  return mode->code;
}

/*
245
INLINE void
Götz Lindenmaier's avatar
Götz Lindenmaier committed
246
set_mode_modecode (ir_mode *mode, modecode code)
Christian Schäfer's avatar
Christian Schäfer committed
247
248
249
250
251
252
253
254
255
256
257
258
{
  mode->code = code;
}
*/

ident *
get_mode_ident (ir_mode *mode)
{
  return mode->name;
}

/*
259
INLINE void
Götz Lindenmaier's avatar
Götz Lindenmaier committed
260
set_mode_ident (ir_mode *mode, ident *name)
Christian Schäfer's avatar
Christian Schäfer committed
261
262
263
264
265
{
  mode->name = name;
}
*/

266
INLINE const char *
Götz Lindenmaier's avatar
Götz Lindenmaier committed
267
268
269
270
271
272
get_mode_name       (ir_mode *mode) {
  assert(mode);
  return id_to_str(mode->name);
}
/* void  set_mode_name       (ir_mode *mode, char *name);    */

Christian Schäfer's avatar
Christian Schäfer committed
273
int
Götz Lindenmaier's avatar
Götz Lindenmaier committed
274
get_mode_size (ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
275
276
277
278
{
  return mode->size;
}
/*
279
INLINE void
Götz Lindenmaier's avatar
Götz Lindenmaier committed
280
set_mode_size (ir_mode *mode, int size)
Christian Schäfer's avatar
Christian Schäfer committed
281
282
283
284
285
286
{
  mode->size = size;
}
*/

int
Götz Lindenmaier's avatar
Götz Lindenmaier committed
287
get_mode_ld_align (ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
288
289
290
291
292
{
  return mode->ld_align;
}

/*
293
INLINE void
Götz Lindenmaier's avatar
Götz Lindenmaier committed
294
set_mode_ld_align (ir_mode *mode, int ld_align)
Christian Schäfer's avatar
Christian Schäfer committed
295
296
297
298
299
300
{
  mode->ld_align = ld_align;
}
*/

tarval *
Götz Lindenmaier's avatar
Götz Lindenmaier committed
301
get_mode_min (ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
302
303
304
305
306
{
  return mode->min;
}

/*
307
INLINE void
Götz Lindenmaier's avatar
Götz Lindenmaier committed
308
set_mode_min (ir_mode *mode, tarval *min)
Christian Schäfer's avatar
Christian Schäfer committed
309
310
311
312
313
314
{
mode->min = min;
}
*/

tarval *
Götz Lindenmaier's avatar
Götz Lindenmaier committed
315
get_mode_max (ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
316
317
318
319
320
{
  return mode->max;
}

/*
321
INLINE void
Götz Lindenmaier's avatar
Götz Lindenmaier committed
322
set_mode_max (ir_mode *mode, tarval *max)
Christian Schäfer's avatar
Christian Schäfer committed
323
324
325
326
327
328
{
  mode->max = max;
}
*/

tarval *
Götz Lindenmaier's avatar
Götz Lindenmaier committed
329
get_mode_null (ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
330
331
332
333
334
{
  return mode->null;
}

/*
335
INLINE void
Götz Lindenmaier's avatar
Götz Lindenmaier committed
336
set_mode_null (ir_mode *mode, tarval *null)
Christian Schäfer's avatar
Christian Schäfer committed
337
338
339
340
341
342
{
  mode->null = null;
}
*/

unsigned
Götz Lindenmaier's avatar
Götz Lindenmaier committed
343
get_mode_fsigned (ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
344
345
346
347
348
{
  return mode->fsigned;
}

/*
349
INLINE voida
Götz Lindenmaier's avatar
Götz Lindenmaier committed
350
set_mode_fsigned (ir_mode *mode, unsigned fsigned)
Christian Schäfer's avatar
Christian Schäfer committed
351
352
353
354
355
356
{
  mode->fsigned = fsigned;
}
*/

unsigned
Götz Lindenmaier's avatar
Götz Lindenmaier committed
357
get_mode_ffloat (ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
358
359
360
361
362
{
  return mode->ffloat;
}

/*
363
INLINE void
Götz Lindenmaier's avatar
Götz Lindenmaier committed
364
set_mode_ffloat (ir_mode *mode, unsigned ffloat)
Christian Schäfer's avatar
Christian Schäfer committed
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
{
  mode->ffloat = ffloat;
}
*/

/* Functions to check, whether a modecode is signed, float, int, num, data,
   datab or dataM. For more exact definitions read the corresponding pages
   in the firm documentation or the followingenumeration

   The set of "float" is defined as:
   ---------------------------------
   float = {irm_f, irm_d}

   The set of "int" is defined as:
   -------------------------------
   int   = {irm_c, irm_C, irm_h, irm_H, irm_i, irm_I, irm_l, irm_L}

   The set of "num" is defined as:
   -------------------------------
   num   = {irm_f, irm_d, irm_c, irm_C, irm_h, irm_H,
            irm_i, irm_I, irm_l, irm_L}
            = {float || int}

   The set of "data" is defined as:
   -------------------------------
   data  = {irm_f, irm_d, irm_c, irm_C, irm_h, irm_H,
            irm_i, irm_I, irm_l, irm_L, irm_p}
            = {num || irm_p}

   The set of "datab" is defined as:
   ---------------------------------
   datab = {irm_f, irm_d, irm_c, irm_C, irm_h, irm_H,
            irm_i, irm_I, irm_l, irm_L, irm_p, irm_b, irm_B}
            = {data || irm_b || irm_B}

   The set of "dataM" is defined as:
   ---------------------------------
   dataM = {irm_f, irm_d, irm_c, irm_C, irm_h, irm_H, irm_i,
            irm_I, irm_l, irm_L, irm_p, irm_M}
            = {data || irm_M}
*/

int
mode_is_signed (ir_mode *mode)
{
   int res;
   unsigned fsigned;
Götz Lindenmaier's avatar
Götz Lindenmaier committed
412
   fsigned = get_mode_fsigned (mode);
Christian Schäfer's avatar
Christian Schäfer committed
413
414
415
416
417
418
419
420
421
422
423
424
425
426
   if (fsigned == 1) {
     res = 1;
    }
   else {
     res = 0;
   }
   return res;
}

int
mode_is_float (ir_mode *mode)
{
   int res;
   unsigned ffloat;
Götz Lindenmaier's avatar
Götz Lindenmaier committed
427
   ffloat = get_mode_ffloat (mode);
Christian Schäfer's avatar
Christian Schäfer committed
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
   if (ffloat == 1) {
      res = 1;
    }
   else {
     res = 0;
   }
   return res;
}


int
mode_is_int (ir_mode *mode)
{
   int res;
   modecode code;
Götz Lindenmaier's avatar
Götz Lindenmaier committed
443
   code = get_mode_modecode (mode);
Christian Schäfer's avatar
Christian Schäfer committed
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
   if ((code >= irm_c) &&  (code <= irm_L)) {
      res = 1;
    }
   else {
     res = 0;
   }
   return res;
}


int
mode_is_num (ir_mode *mode)
{
  int res;
  if (mode_is_int (mode) || mode_is_float (mode)) {
    res = 1;
  }
  else {
    res = 0;
  }
  return res;
}

int
mode_is_data (ir_mode *mode)
{
  int res;
  modecode code;
Götz Lindenmaier's avatar
Götz Lindenmaier committed
472
  code = get_mode_modecode (mode);
Christian Schäfer's avatar
Christian Schäfer committed
473
474
475
476
477
478
479
480
481
482
483
484
485
486
  if (mode_is_num (mode) || code == irm_p) {
    res = 1;
  }
  else {
    res = 0;
  }
  return res;
}

int
mode_is_datab (ir_mode *mode)
{
  int res;
  modecode code;
Götz Lindenmaier's avatar
Götz Lindenmaier committed
487
  code = get_mode_modecode (mode);
Christian Schäfer's avatar
Christian Schäfer committed
488
489
490
491
492
493
494
495
496
497
498
499
500
501
  if (mode_is_data (mode) || code == irm_b || code == irm_B) {
    res = 1;
  }
  else {
    res = 0;
  }
  return res;
}

int
mode_is_dataM (ir_mode *mode)
{
  int res;
  modecode code;
Götz Lindenmaier's avatar
Götz Lindenmaier committed
502
  code = get_mode_modecode (mode);
Christian Schäfer's avatar
Christian Schäfer committed
503
504
505
506
507
508
509
510
  if (mode_is_data (mode) || code == irm_M) {
    res = 1;
  }
  else {
    res = 0;
  }
  return res;
}