fixed config.h include
[libfirm] / ir / tr / tpop.c
1 /*
2  * Project:     libFIRM
3  * File name:   ir/tr/tpop.c
4  * Purpose:     Opcode of types.
5  * Author:      Goetz Lindenmaier
6  * Modified by:
7  * Created:
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 2001-2003 Universität Karlsruhe
10  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11  */
12 #ifdef HAVE_CONFIG_H
13 # include "config.h"
14 #endif
15
16 # include "xmalloc.h"
17 # include "tpop_t.h"
18 # include "type_t.h"
19
20 tp_op *type_class;         tp_op *get_tpop_class      (void) { return type_class;       }
21 tp_op *type_struct;        tp_op *get_tpop_struct     (void) { return type_struct;      }
22 tp_op *type_method;        tp_op *get_tpop_method     (void) { return type_method;      }
23 tp_op *type_union;         tp_op *get_tpop_union      (void) { return type_union;       }
24 tp_op *type_array;         tp_op *get_tpop_array      (void) { return type_array;       }
25 tp_op *type_enumeration;   tp_op *get_tpop_enumeration(void) { return type_enumeration; }
26 tp_op *type_pointer;       tp_op *get_tpop_pointer    (void) { return type_pointer;     }
27 tp_op *type_primitive;     tp_op *get_tpop_primitive  (void) { return type_primitive;   }
28 tp_op *type_id;            tp_op *get_tpop_id         (void) { return type_id;          }
29 tp_op *tpop_none;          tp_op *get_tpop_none       (void) { return tpop_none;        }
30 tp_op *tpop_unknown;       tp_op *get_tpop_unknown    (void) { return tpop_unknown;     }
31
32 tp_op *
33 new_tpop (tp_opcode code, ident *name, size_t attr_size)
34 {
35   tp_op *res;
36
37   res = (tp_op *) xmalloc (sizeof (tp_op));
38   res->code = code;
39   res->name = name;
40   res->attr_size = attr_size;
41   return res;
42 }
43
44 INLINE void
45 free_tpop(tp_op* tpop) {
46   free(tpop);
47 }
48
49 void
50 init_tpop(void)
51 {
52   type_class       = new_tpop (tpo_class      , new_id_from_chars("class"       , 5), sizeof (cls_attr));
53   type_struct      = new_tpop (tpo_struct     , new_id_from_chars("struct"      , 6), sizeof (stc_attr));
54   type_method      = new_tpop (tpo_method     , new_id_from_chars("method"      , 6), sizeof (mtd_attr));
55   type_union       = new_tpop (tpo_union      , new_id_from_chars("union"       , 5), sizeof (uni_attr));
56   type_array       = new_tpop (tpo_array      , new_id_from_chars("array"       , 5), sizeof (arr_attr));
57   type_enumeration = new_tpop (tpo_enumeration, new_id_from_chars("enumeration" ,11), sizeof (enm_attr));
58   type_pointer     = new_tpop (tpo_pointer    , new_id_from_chars("pointer"     , 7), sizeof (ptr_attr));
59   type_primitive   = new_tpop (tpo_primitive  , new_id_from_chars("primitive"   , 9), /* sizeof (pri_attr) */ 0);
60   type_id          = new_tpop (tpo_id         , new_id_from_chars("type_id"     , 7), /* sizeof (id_attr)  */ 0);
61   tpop_none        = new_tpop (tpo_none       , new_id_from_chars("tpop_none"   , 9), /* sizeof (non_attr) */ 0);
62   tpop_unknown     = new_tpop (tpo_unknown    , new_id_from_chars("tpop_unknown",12), /* sizeof (ukn_attr) */ 0);
63 }
64
65 /* Finalize the topo module.
66  * Frees all type opcodes.  */
67 void finish_tpop(void) {
68   free_tpop(type_class      ); type_class       = NULL;
69   free_tpop(type_struct     ); type_struct      = NULL;
70   free_tpop(type_method     ); type_method      = NULL;
71   free_tpop(type_union      ); type_union       = NULL;
72   free_tpop(type_array      ); type_array       = NULL;
73   free_tpop(type_enumeration); type_enumeration = NULL;
74   free_tpop(type_pointer    ); type_pointer     = NULL;
75   free_tpop(type_primitive  ); type_primitive   = NULL;
76   free_tpop(type_id         ); type_id          = NULL;
77   free_tpop(tpop_none       ); tpop_none        = NULL;
78   free_tpop(tpop_unknown    ); tpop_unknown     = NULL;
79 }
80
81 /* Returns the string for the tp_opcode. */
82 const char  *get_tpop_name      (tp_op *op) {
83   return get_id_str(op->name);
84 }
85
86 tp_opcode (get_tpop_code)(tp_op *op){
87   return __get_tpop_code(op);
88 }
89
90 ident *(get_tpop_ident)(tp_op *op){
91   return __get_tpop_ident(op);
92 }
93
94 /* returns the attribute size of the operator. */
95 int (get_tpop_attr_size)(tp_op *op) {
96   return __get_tpop_attr_size(op);
97 }