removed xprint stuff completely
[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 <stdio.h>
19 # include "misc.h"
20
21 /* Make types visible to allow most efficient access */
22 # include "entity_t.h"
23 # include "type_t.h"
24 # include "tpop_t.h"
25
26 static struct obstack mangle_obst;
27
28 ident *
29 mangle_entity (entity *ent)
30 {
31   ident *type_id;
32   char *cp;
33   int len;
34   ident *res;
35
36   type_id = mangle_type ((type *) ent->owner);
37   obstack_printf (&mangle_obst, "%s_%s", id_to_str(type_id), id_to_str(ent->name));
38   len = obstack_object_size (&mangle_obst);
39   cp = obstack_finish (&mangle_obst);
40   res = id_from_str(cp, len);
41   obstack_free (&mangle_obst, cp);
42   return res;
43 }
44
45 ident *
46 mangle_type (type *tp)
47 {
48   char *cp;
49   int len;
50   ident *res;
51
52   assert (tp->kind == k_type);
53   /* assert (tp->type_op->code == tpo_class); */
54
55   obstack_printf (&mangle_obst, "%s", id_to_str(tp->name));
56   len = obstack_object_size (&mangle_obst);
57   cp = obstack_finish (&mangle_obst);
58   res = id_from_str (cp, len);
59   obstack_free (&mangle_obst, cp);
60   return res;
61 }
62
63 /* Returns a new ident that represents firstscnd. */
64 ident *mangle (ident *first, ident* scnd) {
65   char *cp;
66   int len;
67   ident *res;
68
69   obstack_printf (&mangle_obst, "%s%s",  id_to_str(first), id_to_str(scnd));
70   len = obstack_object_size (&mangle_obst);
71   cp = obstack_finish (&mangle_obst);
72   res = id_from_str (cp, len);
73   obstack_free (&mangle_obst, cp);
74   return res;
75 }
76
77 /* Returns a new ident that represents first_scnd. */
78 ident *mangle_u (ident *first, ident* scnd) {
79   char *cp;
80   int len;
81   ident *res;
82
83   obstack_printf (&mangle_obst, "%s_%s",  id_to_str(first), id_to_str(scnd));
84   len = obstack_object_size (&mangle_obst);
85   cp = obstack_finish (&mangle_obst);
86   res = id_from_str (cp, len);
87   obstack_free (&mangle_obst, cp);
88   return res;
89 }
90
91
92 void
93 init_mangle (void)
94 {
95   obstack_init (&mangle_obst);
96 }