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