2 * This file is part of libFirm.
3 * Copyright (C) 2012 University of Karlsruhe.
8 * @brief Methods to manipulate names.
9 * @author Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Michael Beck
19 /* Make types visible to allow most efficient access */
24 /** An obstack used for temporary space */
25 static struct obstack mangle_obst;
27 /** returned a mangled type name, currently no mangling */
28 static inline ident *mangle_type(const ir_type *tp)
30 assert(tp->kind == k_type);
34 /* Returns a new ident that represents 'firstscnd'. */
35 ident *id_mangle(ident *first, ident *scnd)
41 obstack_grow(&mangle_obst, get_id_str(first), get_id_strlen(first));
42 obstack_grow(&mangle_obst, get_id_str(scnd), get_id_strlen(scnd));
43 len = obstack_object_size(&mangle_obst);
44 cp = (char*)obstack_finish(&mangle_obst);
45 res = new_id_from_chars(cp, len);
46 obstack_free(&mangle_obst, cp);
50 /** Returns a new ident that represents 'prefixscndsuffix'. */
51 ident *id_mangle3(const char *prefix, ident *scnd, const char *suffix)
57 obstack_grow(&mangle_obst, prefix, strlen(prefix));
58 obstack_grow(&mangle_obst, get_id_str(scnd), get_id_strlen(scnd));
59 obstack_grow(&mangle_obst, suffix, strlen(suffix));
60 len = obstack_object_size(&mangle_obst);
61 cp = (char*)obstack_finish(&mangle_obst);
62 res = new_id_from_chars(cp, len);
63 obstack_free(&mangle_obst, cp);
67 /** Returns a new ident that represents first<c>scnd. */
68 static ident *id_mangle_3(ident *first, char c, ident *scnd)
74 obstack_grow(&mangle_obst, get_id_str(first), get_id_strlen(first));
75 obstack_1grow(&mangle_obst, c);
76 obstack_grow(&mangle_obst,get_id_str(scnd),get_id_strlen(scnd));
77 len = obstack_object_size(&mangle_obst);
78 cp = (char*)obstack_finish(&mangle_obst);
79 res = new_id_from_chars(cp, len);
80 obstack_free(&mangle_obst, cp);
84 /* Returns a new ident that represents first_scnd. */
85 ident *id_mangle_u(ident *first, ident* scnd)
87 return id_mangle_3(first, '_', scnd);
90 /* Returns a new ident that represents first.scnd. */
91 ident *id_mangle_dot(ident *first, ident *scnd)
93 return id_mangle_3(first, '.', scnd);
96 void firm_init_mangle(void)
98 obstack_init(&mangle_obst);
101 void firm_finish_mangle(void)
103 obstack_free(&mangle_obst, NULL);