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

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"
15
# include "ident.h"
16
# include <stdlib.h>
Christian Schäfer's avatar
Christian Schäfer committed
17
# include <stddef.h>
18
# include <string.h>
Christian Schäfer's avatar
Christian Schäfer committed
19
# include "tv.h"
20
# include "array.h"
Christian Schäfer's avatar
Christian Schäfer committed
21

22
#if 0
Götz Lindenmaier's avatar
Götz Lindenmaier committed
23
static long long count = 0;
24
25
26
27
#  define ANNOUNCE() printf(__FILE__": call no. %lld (%s)\n", count++, __FUNCTION__)
#else
#  define ANNOUNCE() ((void)0)
#endif
Christian Schäfer's avatar
Christian Schäfer committed
28

29
30
31
/* * *
 * local values
 * * */
32

Christian Schäfer's avatar
Christian Schäfer committed
33

Michael Beck's avatar
Michael Beck committed
34
/** dynamic array to hold all modes */
35
36
37
38
39
40
static ir_mode * modes;
/* dynamic arrays to hold special modes' values */
static tarval** modes_min;
static tarval** modes_max;
static tarval** modes_null;
static tarval** modes_one;
Christian Schäfer's avatar
Christian Schäfer committed
41

Michael Beck's avatar
Michael Beck committed
42
/** number of defined modes */
43
static int num_modes;
Christian Schäfer's avatar
Christian Schäfer committed
44

45
46
47
/* * *
 * local functions
 * * */
Christian Schäfer's avatar
Christian Schäfer committed
48

49
/**
50
 * Compare modes that don't need to have their code field
51
52
 * correctly set
 */
Michael Beck's avatar
Michael Beck committed
53
static int modes_are_equal(const ir_mode *m, const ir_mode *n)
54
55
56
{
  if (m == n) return 1;
  if ( (m->sort == n->sort) && (m->size == n->size) &&
57
58
      (m->align == n->align) && (m->sign == n->sign) &&
      (m->name == n->name)
59
     )
60
    return 1;
Christian Schäfer's avatar
Christian Schäfer committed
61

62
63
  return 0;
}
Matthias Heil's avatar
Matthias Heil committed
64

65
66
/**
 * searches the modes array for the given mode and returns
67
 * a pointer on an equal mode already in the array, NULL if
68
69
 * none found
 */
70
71
72
static ir_mode *find_mode(ir_mode *m)
{
  int i;
Matthias Heil's avatar
Matthias Heil committed
73

74
75
76
77
  for (i = 0; i < num_modes; i++)
  {
    if (modes_are_equal(m, &modes[i])) return &modes[i];
  }
Matthias Heil's avatar
Matthias Heil committed
78

79
80
  return NULL;
}
Christian Schäfer's avatar
Christian Schäfer committed
81

82
83
84
/**
 * sets special values of modes
 */
85
86
87
88
89
90
91
92
93
94
static void set_mode_values(ir_mode* mode)
{
  modes_min[get_mode_modecode(mode)] = get_tarval_min(mode);
  modes_max[get_mode_modecode(mode)] = get_tarval_max(mode);
  modes_null[get_mode_modecode(mode)] = get_tarval_null(mode);
  modes_one[get_mode_modecode(mode)] = get_tarval_one(mode);
}
/* * *
 * globals defined in irmode.h
 * * */
Matthias Heil's avatar
Matthias Heil committed
95

96
/* --- Predefined modes --- */
Christian Schäfer's avatar
Christian Schäfer committed
97

98
99
100
101
102
/* FIRM internal modes: */
ir_mode *mode_T;
ir_mode *mode_X;
ir_mode *mode_M;
ir_mode *mode_BB;
103
104
ir_mode *mode_ANY;
ir_mode *mode_BAD;
Christian Schäfer's avatar
Christian Schäfer committed
105

106
107
108
109
/* predefined numerical modes: */
ir_mode *mode_F;    /* float */
ir_mode *mode_D;    /* double */
ir_mode *mode_E;    /* long double */
Christian Schäfer's avatar
Christian Schäfer committed
110

111
112
113
114
115
116
117
118
ir_mode *mode_Bs;   /* integral values, signed and unsigned */
ir_mode *mode_Bu;   /* 8 bit */
ir_mode *mode_Hs;   /* 16 bit */
ir_mode *mode_Hu;
ir_mode *mode_Is;   /* 32 bit */
ir_mode *mode_Iu;
ir_mode *mode_Ls;   /* 64 bit */
ir_mode *mode_Lu;
Christian Schäfer's avatar
Christian Schäfer committed
119

120
121
122
123
ir_mode *mode_C;
ir_mode *mode_U;
ir_mode *mode_b;
ir_mode *mode_P;
124

125
126
127
128
129
/* * *
 * functions defined in irmode.h
 * * */

/* JNI access functions */
Michael Beck's avatar
Michael Beck committed
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
INLINE ir_mode *get_modeT(void) { ANNOUNCE(); return mode_T; }
INLINE ir_mode *get_modeF(void) { ANNOUNCE(); return mode_F; }
INLINE ir_mode *get_modeD(void) { ANNOUNCE(); return mode_D; }
INLINE ir_mode *get_modeE(void) { ANNOUNCE(); return mode_E; }
INLINE ir_mode *get_modeBs(void) { ANNOUNCE(); return mode_Bs; }
INLINE ir_mode *get_modeBu(void) { ANNOUNCE(); return mode_Bu; }
INLINE ir_mode *get_modeHs(void) { ANNOUNCE(); return mode_Hs; }
INLINE ir_mode *get_modeHu(void) { ANNOUNCE(); return mode_Hu; }
INLINE ir_mode *get_modeIs(void) { ANNOUNCE(); return mode_Is; }
INLINE ir_mode *get_modeIu(void) { ANNOUNCE(); return mode_Iu; }
INLINE ir_mode *get_modeLs(void) { ANNOUNCE(); return mode_Ls; }
INLINE ir_mode *get_modeLu(void) { ANNOUNCE(); return mode_Lu; }
INLINE ir_mode *get_modeC(void) { ANNOUNCE(); return mode_C; }
INLINE ir_mode *get_modeU(void) { ANNOUNCE(); return mode_U; }
INLINE ir_mode *get_modeb(void) { ANNOUNCE(); return mode_b; }
INLINE ir_mode *get_modeP(void) { ANNOUNCE(); return mode_P; }
INLINE ir_mode *get_modeX(void) { ANNOUNCE(); return mode_X; }
INLINE ir_mode *get_modeM(void) { ANNOUNCE(); return mode_M; }
INLINE ir_mode *get_modeBB(void) { ANNOUNCE(); return mode_BB; }
149
150
INLINE ir_mode *get_modeANY(void) { ANNOUNCE(); return mode_ANY; }
INLINE ir_mode *get_modeBAD(void) { ANNOUNCE(); return mode_BAD; }
151

152
153
154
155
156
/**
 * Registers a new mode if not defined yet, else returns
 * the "equivalent" one.
 */
static ir_mode *register_mode(ir_mode* new_mode)
157
158
159
160
161
162
163
164
165
166
167
168
169
{
  ir_mode *mode;

  ANNOUNCE();
  assert(new_mode);

  /* first check if there already is a matching mode */
  mode = find_mode(new_mode);
  if (mode) return mode;

  /* sanity checks */
  switch (new_mode->sort)
  {
170
171
    case irms_auxiliary:
    case irms_internal_boolean:
172
      assert(0 && "internal modes cannot be user defined");
173
      return NULL;
174
175
      break;

176
    case irms_float_number:
177
      assert(0 && "not yet implemented");
178
      return NULL;
179
180
      break;

181
182
183
    case irms_int_number:
    case irms_reference:
    case irms_character:
184
185
186
      break;

    default:
187
      assert(0 && "wrong mode sort");
188
      return NULL;
189
  }
Christian Schäfer's avatar
Christian Schäfer committed
190

191
192
193
194
195
196
197
  /* copy mode struct to modes array */
  ARR_EXTEND(ir_mode, modes, 1);
  ARR_EXTEND(tarval*, modes_min, 1);
  ARR_EXTEND(tarval*, modes_max, 1);
  ARR_EXTEND(tarval*, modes_null, 1);
  ARR_EXTEND(tarval*, modes_one, 1);
  mode = &modes[num_modes];
Christian Schäfer's avatar
Christian Schäfer committed
198

199
200
201
202
203
  memcpy(mode, new_mode, sizeof(ir_mode));
  mode->code = num_modes;
  num_modes++;

  set_mode_values(mode);
Christian Schäfer's avatar
Christian Schäfer committed
204

205
  return mode;
Christian Schäfer's avatar
Christian Schäfer committed
206
207
}

208
209
210
211
212
/*
 * Creates a new mode.
 */
ir_mode *new_ir_mode(const char *name, mode_sort sort, int bit_size, int align, int sign)
{
213
  ir_mode mode_tmpl;
214
215
216
217
218
219
220
221
222
223
224

  mode_tmpl.name    = new_id_from_str(name);
  mode_tmpl.sort    = sort;
  mode_tmpl.size    = bit_size;
  mode_tmpl.align   = align;
  mode_tmpl.sign    = sign ? 1 : 0;
  mode_tmpl.tv_priv = NULL;

  return register_mode(&mode_tmpl);
}

225
/* Functions for the direct access to all attributes od a ir_mode */
Christian Schäfer's avatar
Christian Schäfer committed
226
modecode
Michael Beck's avatar
Michael Beck committed
227
get_mode_modecode(const ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
228
{
229
  ANNOUNCE();
Christian Schäfer's avatar
Christian Schäfer committed
230
231
232
233
  return mode->code;
}

ident *
Michael Beck's avatar
Michael Beck committed
234
get_mode_ident(const ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
235
{
236
  ANNOUNCE();
Christian Schäfer's avatar
Christian Schäfer committed
237
238
239
  return mode->name;
}

240
const char *
Michael Beck's avatar
Michael Beck committed
241
get_mode_name(const ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
242
{
243
244
  ANNOUNCE();
  return id_to_str(mode->name);
Christian Schäfer's avatar
Christian Schäfer committed
245
246
}

247
mode_sort
Michael Beck's avatar
Michael Beck committed
248
get_mode_sort(const ir_mode* mode)
249
250
251
{
  ANNOUNCE();
  return mode->sort;
Götz Lindenmaier's avatar
Götz Lindenmaier committed
252
253
}

Götz Lindenmaier's avatar
Götz Lindenmaier committed
254
INLINE int
Michael Beck's avatar
Michael Beck committed
255
get_mode_size_bits(const ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
256
{
257
  ANNOUNCE();
Christian Schäfer's avatar
Christian Schäfer committed
258
259
260
  return mode->size;
}

Michael Beck's avatar
Michael Beck committed
261
int get_mode_size_bytes(const ir_mode *mode) {
Götz Lindenmaier's avatar
Götz Lindenmaier committed
262
263
  ANNOUNCE();
  int size = get_mode_size_bits(mode);
Michael Beck's avatar
Michael Beck committed
264
265
  if ((size & 7) != 0) return -1;
  return size >> 3;
Götz Lindenmaier's avatar
Götz Lindenmaier committed
266
267
}

Christian Schäfer's avatar
Christian Schäfer committed
268
int
Michael Beck's avatar
Michael Beck committed
269
get_mode_align (const ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
270
{
271
272
  ANNOUNCE();
  return mode->align;
Christian Schäfer's avatar
Christian Schäfer committed
273
}
274
275

int
Michael Beck's avatar
Michael Beck committed
276
get_mode_sign (const ir_mode *mode)
277
278
279
280
281
{
  ANNOUNCE();
  return mode->sign;
}

Christian Schäfer's avatar
Christian Schäfer committed
282
tarval *
Götz Lindenmaier's avatar
Götz Lindenmaier committed
283
get_mode_min (ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
284
{
285
286
287
288
  ANNOUNCE();
  assert(mode);
  assert(get_mode_modecode(mode) < num_modes);
  assert(mode_is_data(mode));
Christian Schäfer's avatar
Christian Schäfer committed
289

290
  return modes_min[get_mode_modecode(mode)];
Christian Schäfer's avatar
Christian Schäfer committed
291
292
293
}

tarval *
Götz Lindenmaier's avatar
Götz Lindenmaier committed
294
get_mode_max (ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
295
{
296
297
298
299
  ANNOUNCE();
  assert(mode);
  assert(get_mode_modecode(mode) < num_modes);
  assert(mode_is_data(mode));
Christian Schäfer's avatar
Christian Schäfer committed
300

301
  return modes_max[get_mode_modecode(mode)];
Christian Schäfer's avatar
Christian Schäfer committed
302
303
304
}

tarval *
Götz Lindenmaier's avatar
Götz Lindenmaier committed
305
get_mode_null (ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
306
{
307
308
309
310
  ANNOUNCE();
  assert(mode);
  assert(get_mode_modecode(mode) < num_modes);
  assert(mode_is_data(mode));
Christian Schäfer's avatar
Christian Schäfer committed
311

312
  return modes_null[get_mode_modecode(mode)];
Christian Schäfer's avatar
Christian Schäfer committed
313
314
}

315
316
tarval *
get_mode_one (ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
317
{
318
319
320
321
  ANNOUNCE();
  assert(mode);
  assert(get_mode_modecode(mode) < num_modes);
  assert(mode_is_data(mode));
Christian Schäfer's avatar
Christian Schäfer committed
322

323
  return modes_one[get_mode_modecode(mode)];
Christian Schäfer's avatar
Christian Schäfer committed
324
325
}

326
327
tarval *
get_mode_infinite(ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
328
{
329
330
331
332
333
334
  ANNOUNCE();
  assert(mode);
  assert(get_mode_modecode(mode) < num_modes);
  assert(mode_is_float(mode));

  return get_tarval_inf(mode);
Christian Schäfer's avatar
Christian Schäfer committed
335
336
}

337
338
tarval *
get_mode_NAN(ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
339
{
340
341
342
343
344
345
  ANNOUNCE();
  assert(mode);
  assert(get_mode_modecode(mode) < num_modes);
  assert(mode_is_float(mode));

  return get_tarval_nan(mode);
Christian Schäfer's avatar
Christian Schäfer committed
346
347
348
349
350
351
352
353
}

/* 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:
   ---------------------------------
Matthias Heil's avatar
Matthias Heil committed
354
   float = {irm_F, irm_D, irm_E}
Christian Schäfer's avatar
Christian Schäfer committed
355
356
357

   The set of "int" is defined as:
   -------------------------------
Matthias Heil's avatar
Matthias Heil committed
358
   int   = {irm_Bs, irm_Bu, irm_Hs, irm_Hu, irm_Is, irm_Iu, irm_Ls, irm_Lu}
Christian Schäfer's avatar
Christian Schäfer committed
359
360
361

   The set of "num" is defined as:
   -------------------------------
Matthias Heil's avatar
Matthias Heil committed
362
363
   num   = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
            irm_Is, irm_Iu, irm_Ls, irm_Lu}
Christian Schäfer's avatar
Christian Schäfer committed
364
365
366
367
            = {float || int}

   The set of "data" is defined as:
   -------------------------------
Matthias Heil's avatar
Matthias Heil committed
368
   data  = {irm_F, irm_D, irm_E irm_Bs, irm_Bu, irm_Hs, irm_Hu,
369
370
            irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P}
            = {num || irm_C || irm_U || irm_P}
Christian Schäfer's avatar
Christian Schäfer committed
371
372
373

   The set of "datab" is defined as:
   ---------------------------------
Matthias Heil's avatar
Matthias Heil committed
374
   datab = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
375
            irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P, irm_b}
Matthias Heil's avatar
Matthias Heil committed
376
            = {data || irm_b }
Christian Schäfer's avatar
Christian Schäfer committed
377
378
379

   The set of "dataM" is defined as:
   ---------------------------------
Matthias Heil's avatar
Matthias Heil committed
380
   dataM = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
381
            irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P, irm_M}
Christian Schäfer's avatar
Christian Schäfer committed
382
383
384
            = {data || irm_M}
*/

385
386
387
388
389
390
391
392
393
#ifdef MODE_ACCESS_DEFINES
#  undef mode_is_signed
#  undef mode_is_float
#  undef mode_is_int
#  undef mode_is_num
#  undef mode_is_data
#  undef mode_is_datab
#  undef mode_is_dataM
#endif
Christian Schäfer's avatar
Christian Schäfer committed
394
int
Michael Beck's avatar
Michael Beck committed
395
mode_is_signed (const ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
396
{
397
398
399
  ANNOUNCE();
  assert(mode);
  return mode->sign;
Christian Schäfer's avatar
Christian Schäfer committed
400
401
}

402
int
Michael Beck's avatar
Michael Beck committed
403
mode_is_float (const ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
404
{
405
406
  ANNOUNCE();
  assert(mode);
407
  return (get_mode_sort(mode) == irms_float_number);
Christian Schäfer's avatar
Christian Schäfer committed
408
409
}

410
int
Michael Beck's avatar
Michael Beck committed
411
mode_is_int (const ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
412
{
413
414
  ANNOUNCE();
  assert(mode);
415
  return (get_mode_sort(mode) == irms_int_number);
Christian Schäfer's avatar
Christian Schäfer committed
416
417
}

Michael Beck's avatar
Michael Beck committed
418
int mode_is_character (const ir_mode *mode)
419
420
421
422
423
424
{
  ANNOUNCE();
  assert(mode);
  return (get_mode_sort(mode) == irms_character);
}

Michael Beck's avatar
Michael Beck committed
425
int mode_is_reference (const ir_mode *mode)
426
427
428
429
430
431
{
  ANNOUNCE();
  assert(mode);
  return (get_mode_sort(mode) == irms_reference);
}

432
int
Michael Beck's avatar
Michael Beck committed
433
mode_is_num (const ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
434
{
435
436
437
  ANNOUNCE();
  assert(mode);
  return (mode_is_int(mode) || mode_is_float(mode));
Christian Schäfer's avatar
Christian Schäfer committed
438
439
}

440
int
Michael Beck's avatar
Michael Beck committed
441
mode_is_data (const ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
442
{
443
444
  ANNOUNCE();
  assert(mode);
445
  return (mode_is_num(mode) || get_mode_sort(mode) == irms_character || get_mode_sort(mode) == irms_reference);
Christian Schäfer's avatar
Christian Schäfer committed
446
447
448
}

int
Michael Beck's avatar
Michael Beck committed
449
mode_is_datab (const ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
450
{
451
452
  ANNOUNCE();
  assert(mode);
453
  return (mode_is_data(mode) || get_mode_sort(mode) == irms_internal_boolean);
Christian Schäfer's avatar
Christian Schäfer committed
454
455
456
}

int
Michael Beck's avatar
Michael Beck committed
457
mode_is_dataM (const ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
458
{
459
460
461
  ANNOUNCE();
  assert(mode);
  return (mode_is_data(mode) || get_mode_modecode(mode) == irm_M);
Christian Schäfer's avatar
Christian Schäfer committed
462
}
463
464
#ifdef MODE_ACCESS_DEFINES
#  define mode_is_signed(mode) (mode)->sign
465
466
467
468
469
470
#  define mode_is_float(mode) ((mode)->sort == irms_float_number)
#  define mode_is_int(mode) ((mode)->sort == irms_int_number)
#  define mode_is_num(mode) (((mode)->sort == irms_float_number) || ((mode)->sort == irms_int_number))
#  define mode_is_data(mode) (((mode)->sort == irms_float_number) || ((mode)->sort == irms_int_number) || ((mode)->sort == irms_character) || ((mode)->sort == irms_reference))
#  define mode_is_datab(mode) (((mode)->sort == irms_float_number) || ((mode)->sort == irms_int_number) || ((mode)->sort == irms_character) || ((mode)->sort == irms_reference) || ((mode)->sort == irms_internal_boolean))
#  define mode_is_dataM(mode) (((mode)->sort == irms_float_number) || ((mode)->sort == irms_int_number) || ((mode)->sort == irms_character) || ((mode)->sort == irms_reference) || ((mode)->code == irm_M))
471
#endif
472
/* Returns true if sm can be converted to lm without loss. */
473
int
Michael Beck's avatar
Michael Beck committed
474
smaller_mode(const ir_mode *sm, const ir_mode *lm)
475
476
477
478
479
480
481
482
483
{
  ANNOUNCE();
  assert(sm);
  assert(lm);

  if (sm == lm) return 1;

  switch(get_mode_sort(sm))
  {
484
    case irms_int_number:
485
486
      switch(get_mode_sort(lm))
      {
487
        case irms_int_number:
488
489
490
491
492
493
494
          /* integers are convertable if
           *   - both have the same sign and lm is the larger one
           *   - lm is the signed one and is at least two bits larger
           *     (one for the sign, one for the highest bit of sm)
           */
          if (mode_is_signed(sm))
          {
495
            if ( mode_is_signed(lm) && (get_mode_size_bits(lm) > get_mode_size_bits(sm)) )
496
497
498
499
              return 1;
          }
          else if (mode_is_signed(lm))
          {
500
            if (get_mode_size_bits(lm) > get_mode_size_bits(sm) + 1)
501
502
              return 1;
          }
503
          else if (get_mode_size_bits(lm) > get_mode_size_bits(sm))
504
505
506
507
508
          {
            return 1;
          }
          break;

509
        case irms_float_number:
510
511
512
513
514
515
516
517
          /* int to float works if the float is large enough */
          return 0;

        default:
          break;
      }
      break;

518
    case irms_float_number:
519
520
      /* XXX currently only the three standard 32,64,80 bit floats
       * are supported which can safely be converted */
521
      if ( (get_mode_sort(lm) == irms_float_number)
522
           && (get_mode_size_bits(lm) > get_mode_size_bits(sm)) )
523
524
525
         return 1;
      break;

526
    case irms_reference:
527
528
529
530
531
532
533
534
535
536
537
       /* do exist machines out there with different pointer lenghts ?*/
      return 0;

    default:
      break;
  }

  /* else */
  return 0;
}

538
/* ** initialization ** */
539
540
541
542
543
void
init_mode (void)
{
  ANNOUNCE();
  /* init flexible array */
544
545
546
  modes      = NEW_ARR_F(ir_mode, irm_max);
  modes_min  = NEW_ARR_F(tarval*, irm_max);
  modes_max  = NEW_ARR_F(tarval*, irm_max);
547
  modes_null = NEW_ARR_F(tarval*, irm_max);
548
  modes_one  = NEW_ARR_F(tarval*, irm_max);
549
550
551
552

  /* initialize predefined modes */
  /* Basic Block */
  mode_BB = &modes[irm_BB];
553
554
555
556
557
558
  mode_BB->name    = id_from_str("BB", 2);
  mode_BB->code    = irm_BB;
  mode_BB->sort    = irms_auxiliary;
  mode_BB->size    = 0;
  mode_BB->align   = 0;
  mode_BB->sign    = 0;
559
  mode_BB->tv_priv = NULL;
560
561
562

  /* eXecution */
  mode_X = &modes[irm_X];
563
564
565
566
567
568
  mode_X->name    = id_from_str("X", 1);
  mode_X->code    = irm_X;
  mode_X->sort    = irms_auxiliary;
  mode_X->size    = 0;
  mode_X->align   = 0;
  mode_X->sign    = 0;
569
  mode_X->tv_priv = NULL;
570
571
572

  /* Memory */
  mode_M = &modes[irm_M];
573
574
575
576
577
578
  mode_M->name    = id_from_str("M", 1);
  mode_M->code    = irm_M;
  mode_M->sort    = irms_auxiliary;
  mode_M->size    = 0;
  mode_M->align   = 0;
  mode_M->sign    = 0;
579
  mode_M->tv_priv = NULL;
580
581
582

  /* Tuple */
  mode_T = &modes[irm_T];
583
584
585
586
587
588
  mode_T->name    = id_from_str("T", 1);
  mode_T->code    = irm_T;
  mode_T->sort    = irms_auxiliary,
  mode_T->size    = 0;
  mode_T->align   = 0;
  mode_T->sign    = 0;
589
  mode_T->tv_priv = NULL;
590

591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
  /* ANY */
  mode_ANY = &modes[irm_ANY];
  mode_ANY->name    = id_from_str("ANY", 3);
  mode_ANY->code    = irm_ANY;
  mode_ANY->sort    = irms_auxiliary;
  mode_ANY->sign    = 0;
  mode_ANY->align   = 0;
  mode_ANY->size    = 0;
  mode_ANY->tv_priv = NULL;

  /* BAD */
  mode_BAD = &modes[irm_BAD];
  mode_BAD->name    = id_from_str("BAD", 3);
  mode_BAD->code    = irm_BAD;
  mode_BAD->sort    = irms_auxiliary;
  mode_BAD->sign    = 0;
  mode_BAD->align   = 0;
  mode_BAD->size    = 0;
  mode_BAD->tv_priv = NULL;

611
612
  /* boolean */
  mode_b = &modes[irm_b];
613
614
615
616
617
618
  mode_b->name    = id_from_str("b", 1);
  mode_b->code    = irm_b;
  mode_b->sort    = irms_internal_boolean;
  mode_b->size    = 0;
  mode_b->align   = 0;
  mode_b->sign    = 0;
619
  mode_b->tv_priv = NULL;
620
621
622

  /* float */
  mode_F = &modes[irm_F];
623
624
625
626
  mode_F->name    = id_from_str("F", 1);
  mode_F->code    = irm_F;
  mode_F->sort    = irms_float_number;
  mode_F->sign    = 1;
627
  mode_F->align   = 4;
628
  mode_F->size    = 32;
629
  mode_F->tv_priv = NULL;
630
631
632
633
634

  set_mode_values(mode_F);

  /* double */
  mode_D = &modes[irm_D];
635
636
637
638
  mode_D->name    = id_from_str("D", 1);
  mode_D->code    = irm_D;
  mode_D->sort    = irms_float_number;
  mode_D->sign    = 1;
639
  mode_D->align   = 4;
640
  mode_D->size    = 64;
641
  mode_D->tv_priv = NULL;
642
643
644
645
646

  set_mode_values(mode_D);

  /* extended */
  mode_E = &modes[irm_E];
647
648
649
650
  mode_E->name    = id_from_str("E", 1);
  mode_E->code    = irm_E;
  mode_E->sort    = irms_float_number;
  mode_E->sign    = 1;
651
  mode_E->align   = 4;
652
  mode_E->size    = 80;
653
  mode_E->tv_priv = NULL;
654
655
656
657
658

  set_mode_values(mode_E);

  /* signed byte */
  mode_Bs = &modes[irm_Bs];
659
660
661
662
  mode_Bs->name    = id_from_str("Bs", 2);
  mode_Bs->code    = irm_Bs;
  mode_Bs->sort    = irms_int_number;
  mode_Bs->sign    = 1;
663
  mode_Bs->align   = 1;
664
  mode_Bs->size    = 8;
665
  mode_Bs->tv_priv = NULL;
666
667
668
669
670

  set_mode_values(mode_Bs);

  /* unsigned byte */
  mode_Bu = &modes[irm_Bu];
671
672
673
674
  mode_Bu->name    = id_from_str("Bu", 2);
  mode_Bu->code    = irm_Bu;
  mode_Bu->sort    = irms_int_number;
  mode_Bu->sign    = 0;
675
  mode_Bu->align   = 1;
676
  mode_Bu->size    = 8;
677
  mode_Bu->tv_priv = NULL;
678
679
680
681
682

  set_mode_values(mode_Bu);

  /* signed short integer */
  mode_Hs = &modes[irm_Hs];
683
684
685
686
  mode_Hs->name    = id_from_str("Hs", 2);
  mode_Hs->code    = irm_Hs;
  mode_Hs->sort    = irms_int_number;
  mode_Hs->sign    = 1;
687
  mode_Hs->align   = 2;
688
  mode_Hs->size    = 16;
689
  mode_Hs->tv_priv = NULL;
690
691
692
693
694

  set_mode_values(mode_Hs);

  /* unsigned short integer */
  mode_Hu = &modes[irm_Hu];
695
696
697
698
  mode_Hu->name    = id_from_str("Hu", 2);
  mode_Hu->code    = irm_Hu;
  mode_Hu->sort    = irms_int_number;
  mode_Hu->sign    = 0;
699
  mode_Hu->align   = 2;
700
  mode_Hu->size    = 16;
701
  mode_Hu->tv_priv = NULL;
702
703
704
705
706

  set_mode_values(mode_Hu);

  /* signed integer */
  mode_Is = &modes[irm_Is];
707
708
709
710
  mode_Is->name    = id_from_str("Is", 2);
  mode_Is->code    = irm_Is;
  mode_Is->sort    = irms_int_number;
  mode_Is->sign    = 1;
711
  mode_Is->align   = 4;
712
  mode_Is->size    = 32;
713
  mode_Is->tv_priv = NULL;
714
715
716
717
718

  set_mode_values(mode_Is);

  /* unsigned integer */
  mode_Iu = &modes[irm_Iu];
719
720
721
722
  mode_Iu->name    = id_from_str("Iu", 2);
  mode_Iu->code    = irm_Iu;
  mode_Iu->sort    = irms_int_number;
  mode_Iu->sign    = 0;
723
  mode_Iu->align   = 4;
724
  mode_Iu->size    = 32;
725
  mode_Iu->tv_priv = NULL;
726
727
728
729
730

  set_mode_values(mode_Iu);

  /* signed long integer */
  mode_Ls = &modes[irm_Ls];
731
732
733
734
  mode_Ls->name    = id_from_str("Ls", 2);
  mode_Ls->code    = irm_Ls;
  mode_Ls->sort    = irms_int_number;
  mode_Ls->sign    = 1;
735
  mode_Ls->align   = 4;
736
  mode_Ls->size    = 64;
737
  mode_Ls->tv_priv = NULL;
738
739
740
741
742

  set_mode_values(mode_Ls);

  /* unsigned long integer */
  mode_Lu = &modes[irm_Lu];
743
744
745
746
  mode_Lu->name    = id_from_str("Lu", 2);
  mode_Lu->code    = irm_Lu;
  mode_Lu->sort    = irms_int_number;
  mode_Lu->sign    = 0;
747
  mode_Lu->align   = 4;
748
  mode_Lu->size    = 64;
749
  mode_Lu->tv_priv = NULL;
750
751
752
753
754

  set_mode_values(mode_Lu);

  /* Character */
  mode_C = &modes[irm_C];
755
756
757
758
  mode_C->name    = id_from_str("C", 1);
  mode_C->code    = irm_C;
  mode_C->sort    = irms_character;
  mode_C->sign    = 0;
759
  mode_C->align   = 1;
760
  mode_C->size    = 8;
761
  mode_C->tv_priv = NULL;
762
763
764
765
766

  set_mode_values(mode_C);

  /* Unicode character */
  mode_U = &modes[irm_U];
767
768
769
770
  mode_U->name    = id_from_str("U", 1);
  mode_U->code    = irm_U;
  mode_U->sort    = irms_character;
  mode_U->sign    = 0;
771
  mode_U->align   = 2;
772
  mode_U->size    = 16;
773
  mode_U->tv_priv = NULL;
774
775
776
777
778

  set_mode_values(mode_U);

  /* pointer */
  mode_P = &modes[irm_P];
779
780
781
782
  mode_P->name    = id_from_str("P", 1);
  mode_P->code    = irm_P;
  mode_P->sort    = irms_reference;
  mode_P->sign    = 0;
783
  mode_P->align   = 4;
784
  mode_P->size    = 32;
785
  mode_P->tv_priv = NULL;
786
787

  num_modes = irm_max;
788
}