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