2 * Copyright (C) 1995-2010 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * @brief Methods to manipulate names.
23 * @author Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Michael Beck
33 /* Make types visible to allow most efficient access */
38 /** An obstack used for temporary space */
39 static struct obstack mangle_obst;
41 /** returned a mangled type name, currently no mangling */
42 static inline ident *mangle_type(const ir_type *tp)
44 assert(tp->kind == k_type);
48 /* Returns a new ident that represents 'firstscnd'. */
49 ident *id_mangle(ident *first, ident *scnd)
55 obstack_grow(&mangle_obst, get_id_str(first), get_id_strlen(first));
56 obstack_grow(&mangle_obst, get_id_str(scnd), get_id_strlen(scnd));
57 len = obstack_object_size(&mangle_obst);
58 cp = (char*)obstack_finish(&mangle_obst);
59 res = new_id_from_chars(cp, len);
60 obstack_free(&mangle_obst, cp);
64 /** Returns a new ident that represents 'prefixscndsuffix'. */
65 ident *id_mangle3(const char *prefix, ident *scnd, const char *suffix)
71 obstack_grow(&mangle_obst, prefix, strlen(prefix));
72 obstack_grow(&mangle_obst, get_id_str(scnd), get_id_strlen(scnd));
73 obstack_grow(&mangle_obst, suffix, strlen(suffix));
74 len = obstack_object_size(&mangle_obst);
75 cp = (char*)obstack_finish(&mangle_obst);
76 res = new_id_from_chars(cp, len);
77 obstack_free(&mangle_obst, cp);
81 /** Returns a new ident that represents first<c>scnd. */
82 static ident *id_mangle_3(ident *first, char c, ident *scnd)
88 obstack_grow(&mangle_obst, get_id_str(first), get_id_strlen(first));
89 obstack_1grow(&mangle_obst, c);
90 obstack_grow(&mangle_obst,get_id_str(scnd),get_id_strlen(scnd));
91 len = obstack_object_size(&mangle_obst);
92 cp = (char*)obstack_finish(&mangle_obst);
93 res = new_id_from_chars(cp, len);
94 obstack_free(&mangle_obst, cp);
98 /* Returns a new ident that represents first_scnd. */
99 ident *id_mangle_u(ident *first, ident* scnd)
101 return id_mangle_3(first, '_', scnd);
104 /* Returns a new ident that represents first.scnd. */
105 ident *id_mangle_dot(ident *first, ident *scnd)
107 return id_mangle_3(first, '.', scnd);
110 void firm_init_mangle(void)
112 obstack_init(&mangle_obst);
115 void firm_finish_mangle(void)
117 obstack_free(&mangle_obst, NULL);