new SymConst semantics
[libfirm] / ir / tr / mangle.c
1 /*
2  * Project:     libFIRM
3  * File name:   ir/tr/mangle.c
4  * Purpose:     Methods to manipulate names.
5  * Author:      Martin Trapp, Christian Schaefer
6  * Modified by: Goetz Lindenmaier
7  * Created:
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 1998-2003 Universität Karlsruhe
10  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11  */
12
13
14
15 #ifdef HAVE_CONFIG_H
16 # include <config.h>
17 #endif
18
19 # include "mangle.h"
20 # include "obst.h"
21
22 /* Make types visible to allow most efficient access */
23 # include "entity_t.h"
24 # include "type_t.h"
25 # include "tpop_t.h"
26
27 static struct obstack mangle_obst;
28
29 static INLINE ident *
30 mangle_type (type *tp)
31 {
32   assert (tp->kind == k_type);
33   return tp->name;
34 }
35
36 ident *
37 mangle_entity (entity *ent)
38 {
39   ident *type_id;
40   char *cp;
41   int len;
42   ident *res;
43
44   type_id = mangle_type ((type *) ent->owner);
45   obstack_grow(&mangle_obst, get_id_str(type_id), get_id_strlen(type_id));
46   obstack_1grow(&mangle_obst,'_');
47   obstack_grow(&mangle_obst,get_id_str(ent->name),get_id_strlen(ent->name));
48   len = obstack_object_size (&mangle_obst);
49   cp = obstack_finish (&mangle_obst);
50   res = id_from_str(cp, len);
51   obstack_free (&mangle_obst, cp);
52   return res;
53 }
54
55
56 /* Returns a new ident that represents firstscnd. */
57 ident *mangle (ident *first, ident* scnd) {
58   char *cp;
59   int len;
60   ident *res;
61
62   obstack_grow(&mangle_obst, get_id_str(first), get_id_strlen(first));
63   obstack_grow(&mangle_obst, get_id_str(scnd), get_id_strlen(scnd));
64   len = obstack_object_size (&mangle_obst);
65   cp = obstack_finish (&mangle_obst);
66   res = id_from_str (cp, len);
67   obstack_free (&mangle_obst, cp);
68   return res;
69 }
70
71 /* Returns a new ident that represents first_scnd. */
72 ident *mangle_u (ident *first, ident* scnd) {
73   char *cp;
74   int len;
75   ident *res;
76
77   obstack_grow(&mangle_obst, get_id_str(first), get_id_strlen(first));
78   obstack_1grow(&mangle_obst,'_');
79   obstack_grow(&mangle_obst,get_id_str(scnd),get_id_strlen(scnd));
80   len = obstack_object_size (&mangle_obst);
81   cp = obstack_finish (&mangle_obst);
82   res = id_from_str (cp, len);
83   obstack_free (&mangle_obst, cp);
84   return res;
85 }
86
87
88 void
89 init_mangle (void)
90 {
91   obstack_init(&mangle_obst);
92 }