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