Changed implementation of tr module.
[libfirm] / ir / tr / mangle.c
1 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
2 ** All rights reserved.
3 **
4 ** Authors: Martin Trapp, Christian Schaefer
5 **
6 */
7
8 #ifdef HAVE_CONFIG_H
9 # include <config.h>
10 #endif
11
12 # include "mangle.h"
13 # include <obstack.h>
14 # include "obst.h"
15 # include <stdlib.h>
16 # include "misc.h"
17
18 /* Make types visible to allow most efficient access */
19 # include "entity_t.h"
20 # include "type_t.h"
21 # include "tpop_t.h"
22
23 static struct obstack mangle_obst;
24
25 ident *
26 mangle_entity (entity *ent)
27 {
28   ident *type_id;
29   char *cp;
30   int len;
31   ident *res;
32
33   type_id = mangle_type ((type *) ent->owner);
34   xoprintf (&mangle_obst, "%I_%I", type_id, ent->name);
35   len = obstack_object_size (&mangle_obst);
36   cp = obstack_finish (&mangle_obst);
37   res = id_from_str (cp, len);
38   obstack_free (&mangle_obst, cp);
39   return res;
40 }
41
42 ident *
43 mangle_type (type *type)
44 {
45   char *cp;
46   int len;
47   ident *res;
48
49   assert (type->kind == k_type);
50   assert (type->type_op->code == tpo_class);
51
52   xoprintf (&mangle_obst, "%I", type->name);
53   len = obstack_object_size (&mangle_obst);
54   cp = obstack_finish (&mangle_obst);
55   res = id_from_str (cp, len);
56   obstack_free (&mangle_obst, cp);
57   return res;
58 }
59
60
61 void
62 init_mangle (void)
63 {
64   obstack_init (&mangle_obst);
65 }