tpop.c 3.9 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
/*
 * Project:     libFIRM
 * File name:   ir/tr/tpop.c
 * Purpose:     Opcode of types.
 * Author:      Goetz Lindenmaier
 * Modified by:
 * Created:
 * CVS-ID:      $Id$
 * Copyright:   (c) 2001-2003 Universitt Karlsruhe
 * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
 */
Götz Lindenmaier's avatar
new.  
Götz Lindenmaier committed
12

Boris Boesler's avatar
Boris Boesler committed
13

Götz Lindenmaier's avatar
new.  
Götz Lindenmaier committed
14
15
16
17
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

18
# include "xmalloc.h"
Götz Lindenmaier's avatar
new.  
Götz Lindenmaier committed
19
20
21
# include "tpop_t.h"
# include "type_t.h"

22
23
24
25
26
27
28
29
30
31
32
tp_op *type_class;         tp_op *get_tpop_class      (void) { return type_class;       }
tp_op *type_struct;        tp_op *get_tpop_struct     (void) { return type_struct;      }
tp_op *type_method;        tp_op *get_tpop_method     (void) { return type_method;      }
tp_op *type_union;         tp_op *get_tpop_union      (void) { return type_union;       }
tp_op *type_array;         tp_op *get_tpop_array      (void) { return type_array;       }
tp_op *type_enumeration;   tp_op *get_tpop_enumeration(void) { return type_enumeration; }
tp_op *type_pointer;       tp_op *get_tpop_pointer    (void) { return type_pointer;     }
tp_op *type_primitive;     tp_op *get_tpop_primitive  (void) { return type_primitive;   }
tp_op *type_id;            tp_op *get_tpop_id         (void) { return type_id;          }
tp_op *tpop_none;          tp_op *get_tpop_none       (void) { return tpop_none;        }
tp_op *tpop_unknown;       tp_op *get_tpop_unknown    (void) { return tpop_unknown;     }
Götz Lindenmaier's avatar
new.  
Götz Lindenmaier committed
33
34
35
36
37
38
39
40
41
42
43
44
45

tp_op *
new_tpop (tp_opcode code, ident *name, size_t attr_size)
{
  tp_op *res;

  res = (tp_op *) xmalloc (sizeof (tp_op));
  res->code = code;
  res->name = name;
  res->attr_size = attr_size;
  return res;
}

46
47
48
49
50
INLINE void
free_tpop(tp_op* tpop) {
  free(tpop);
}

Götz Lindenmaier's avatar
new.  
Götz Lindenmaier committed
51
52
53
void
init_tpop(void)
{
54
55
56
57
58
59
60
61
62
63
64
  type_class       = new_tpop (tpo_class      , new_id_from_chars("class"       , 5), sizeof (cls_attr));
  type_struct      = new_tpop (tpo_struct     , new_id_from_chars("struct"      , 6), sizeof (stc_attr));
  type_method      = new_tpop (tpo_method     , new_id_from_chars("method"      , 6), sizeof (mtd_attr));
  type_union       = new_tpop (tpo_union      , new_id_from_chars("union"       , 5), sizeof (uni_attr));
  type_array       = new_tpop (tpo_array      , new_id_from_chars("array"       , 5), sizeof (arr_attr));
  type_enumeration = new_tpop (tpo_enumeration, new_id_from_chars("enumeration" ,11), sizeof (enm_attr));
  type_pointer     = new_tpop (tpo_pointer    , new_id_from_chars("pointer"     , 7), sizeof (ptr_attr));
  type_primitive   = new_tpop (tpo_primitive  , new_id_from_chars("primitive"   , 9), /* sizeof (pri_attr) */ 0);
  type_id          = new_tpop (tpo_id         , new_id_from_chars("type_id"     , 7), /* sizeof (id_attr)  */ 0);
  tpop_none        = new_tpop (tpo_none       , new_id_from_chars("tpop_none"   , 9), /* sizeof (non_attr) */ 0);
  tpop_unknown     = new_tpop (tpo_unknown    , new_id_from_chars("tpop_unknown",12), /* sizeof (ukn_attr) */ 0);
Götz Lindenmaier's avatar
new.  
Götz Lindenmaier committed
65
66
}

67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/* Finalize the topo module.
 * Frees all type opcodes.  */
void finish_tpop(void) {
  free_tpop(type_class      ); type_class       = NULL;
  free_tpop(type_struct     ); type_struct      = NULL;
  free_tpop(type_method     ); type_method      = NULL;
  free_tpop(type_union      ); type_union       = NULL;
  free_tpop(type_array      ); type_array       = NULL;
  free_tpop(type_enumeration); type_enumeration = NULL;
  free_tpop(type_pointer    ); type_pointer     = NULL;
  free_tpop(type_primitive  ); type_primitive   = NULL;
  free_tpop(type_id         ); type_id          = NULL;
  free_tpop(tpop_none       ); tpop_none        = NULL;
  free_tpop(tpop_unknown    ); tpop_unknown     = NULL;
}

Götz Lindenmaier's avatar
new.  
Götz Lindenmaier committed
83
84
/* Returns the string for the tp_opcode. */
const char  *get_tpop_name      (tp_op *op) {
85
  return get_id_str(op->name);
Götz Lindenmaier's avatar
new.  
Götz Lindenmaier committed
86
87
}

88
89
tp_opcode (get_tpop_code)(tp_op *op){
  return __get_tpop_code(op);
Götz Lindenmaier's avatar
new.  
Götz Lindenmaier committed
90
91
}

92
93
ident *(get_tpop_ident)(tp_op *op){
  return __get_tpop_ident(op);
Götz Lindenmaier's avatar
new.  
Götz Lindenmaier committed
94
95
96
}

/* returns the attribute size of the operator. */
97
98
int (get_tpop_attr_size)(tp_op *op) {
  return __get_tpop_attr_size(op);
Götz Lindenmaier's avatar
new.  
Götz Lindenmaier committed
99
}