- Added ir_export which is supposed to export the whole irp
[libfirm] / ir / tr / typegmod.c
1 /*
2  * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
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.
10  *
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.
14  *
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
17  * PURPOSE.
18  */
19
20 /**
21  * @file    typegmod.c
22  * @brief   Functionality to modify the type graph.
23  * @author  Goetz Lindenmaier, Michael Beck
24  * @version $Id$
25  */
26 #include "config.h"
27
28 #include "type_t.h"
29 #include "tpop_t.h"
30 #include "irmode.h"
31
32 void exchange_types(ir_type *old_type, ir_type *new_type) {
33         unsigned flags = old_type->flags & (tf_frame_type | tf_value_param_type | tf_global_type | tf_tls_type);
34         /* Deallocate datastructures not directly contained in the
35            old type.  We must do this now as it is the latest point
36            where we know the original kind of type.
37            */
38         free_type_attrs(old_type);
39
40         /* @@@@
41            Things to deal with:
42            * After exchange_types the type has two entries in the list of
43              all types in irp.  So far this is fine for the walker.
44              Maybe it's better to remove the id entry and shrink the list.
45              Does this conflict with the walker?  Might a type be left out
46              during the walk?
47            * Deallocation:  if the Id is removed from the list it will eventually
48              disappear in a memory leak.  When is impossible to determine so we
49              need to hold it in a separate list for deallocation.
50         */
51
52         /* Exchange the types */
53         old_type->type_op = type_id;
54         old_type->mode = (ir_mode *) new_type;
55         /* ensure that the frame, value param, global and tls flags
56            are set right if these types are exchanged */
57         new_type->flags |= flags;
58 }
59
60 ir_type *skip_tid(ir_type *tp) {
61         /* @@@ implement the self cycle killing trick of skip_id(ir_node *) */
62         while (tp->type_op == type_id)
63                 tp = (ir_type *) tp->mode;
64         return tp;
65 }