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