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