minor changes to help with making the ajacs-jikes backend
[libfirm] / ir / tr / mangle.c
1 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
2 ** All rights reserved.
3 **
4 ** Authors: Martin Trapp, Christian Schaefer
5 **
6 */
7
8 /* $Id$ */
9
10 #ifdef HAVE_CONFIG_H
11 # include <config.h>
12 #endif
13
14 # include "mangle.h"
15 # include <obstack.h>
16 # include "obst.h"
17 # include <stdlib.h>
18 # include "misc.h"
19
20 /* Make types visible to allow most efficient access */
21 # include "entity_t.h"
22 # include "type_t.h"
23 # include "tpop_t.h"
24
25 static struct obstack mangle_obst;
26
27 ident *
28 mangle_entity (entity *ent)
29 {
30   ident *type_id;
31   char *cp;
32   int len;
33   ident *res;
34
35   type_id = mangle_type ((type *) ent->owner);
36   xoprintf (&mangle_obst, "%I_%I", type_id, ent->name);
37   len = obstack_object_size (&mangle_obst);
38   cp = obstack_finish (&mangle_obst);
39   res = id_from_str (cp, len);
40   obstack_free (&mangle_obst, cp);
41   return res;
42 }
43
44 ident *
45 mangle_type (type *type)
46 {
47   char *cp;
48   int len;
49   ident *res;
50
51   assert (type->kind == k_type);
52   /* assert (type->type_op->code == tpo_class); */
53
54   xoprintf (&mangle_obst, "%I", type->name);
55   len = obstack_object_size (&mangle_obst);
56   cp = obstack_finish (&mangle_obst);
57   res = id_from_str (cp, len);
58   obstack_free (&mangle_obst, cp);
59   return res;
60 }
61
62 /* Returns a new ident that represents firstscnd. */
63 ident *mangle (ident *first, ident* scnd) {
64   char *cp;
65   int len;
66   ident *res;
67
68   xoprintf (&mangle_obst, "%I%I",  first, scnd);
69   len = obstack_object_size (&mangle_obst);
70   cp = obstack_finish (&mangle_obst);
71   res = id_from_str (cp, len);
72   obstack_free (&mangle_obst, cp);
73   return res;
74 }
75
76 /* Returns a new ident that represents first_scnd. */
77 ident *mangle_u (ident *first, ident* scnd) {
78   char *cp;
79   int len;
80   ident *res;
81
82   xoprintf (&mangle_obst, "%I_%I",  first, scnd);
83   len = obstack_object_size (&mangle_obst);
84   cp = obstack_finish (&mangle_obst);
85   res = id_from_str (cp, len);
86   obstack_free (&mangle_obst, cp);
87   return res;
88 }
89
90
91 void
92 init_mangle (void)
93 {
94   obstack_init (&mangle_obst);
95 }