added
[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 "entity.h"
16 # include <stdlib.h>
17 # include "ident_t.h"
18
19 /* Make types visible to allow most efficient access */
20 # include "entity_t.h"
21
22 static struct obstack mangle_obst;
23
24 ident *
25 mangle_entity (entity *ent)
26 {
27   ident *type_id;
28   char *cp;
29   int len;
30   ident *res;
31
32   type_id = mangle_type ((type *) ent->owner);
33   xoprintf (&mangle_obst, "%I_%I", type_id, ent->name);
34   len = obstack_object_size (&mangle_obst);
35   cp = obstack_finish (&mangle_obst);
36   res = id_from_str (cp, len);
37   obstack_free (&mangle_obst, cp);
38   return res;
39 }
40
41 ident *
42 mangle_type (type *type)
43 {
44   char *cp;
45   int len;
46   ident *res;
47
48   assert (type->kind == k_type_class);
49
50   xoprintf (&mangle_obst, "%I", type->clss.name);
51   len = obstack_object_size (&mangle_obst);
52   cp = obstack_finish (&mangle_obst);
53   res = id_from_str (cp, len);
54   obstack_free (&mangle_obst, cp);
55   return res;
56 }
57
58
59 void
60 init_mangle (void)
61 {
62   obstack_init (&mangle_obst);
63 }