added routines to free memory
[libfirm] / ir / ir / irprog.h
1 /*
2  * Project:     libFIRM
3  * File name:   ir/ir/irprog.h
4  * Purpose:     Entry point to the representation of a whole program.
5  * Author:      Goetz Lindenmaier
6  * Modified by:
7  * Created:     2000
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 2000-2003 Universität Karlsruhe
10  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11  */
12
13 /**
14 * @file irprog.h
15 *
16 * ir representation of a program.
17 *
18 * @author Goetz Lindenmaier
19 *
20 * This file defines a construct that keeps all information about a
21 * program:
22 *   - A list of all procedures.
23 *   - A list of all types.
24 *   - A global type that can be thought of as a god-class containing all
25 *     global variables and procedures.  This is not the base class of
26 *     all classes in a class hierarchy (as, e.g., "object" in java).
27 *   - (An obstack containing global things, e.g., the above mentioned lists.)
28 */
29
30 # ifndef _IRPROG_H_
31 # define _IRPROG_H_
32
33 # include "irnode.h"
34 # include "type.h"
35
36 /**
37  * Datastructure that holds central information about a program
38  *
39  * Preliminary documentation ;-)
40  *
41  * - main_irg:  The ir graph that is the entry point to the program.
42  *              (Anything not reachable from here may be optimized away.
43  *              If we want to translate libraries or the like correctly
44  *              we must replace this by a list.)
45  * - irg:       List of all ir graphs in the program.
46  * - type:      A list containing all types known to the translated program.
47  *              Some types can have several entries in this list (as a result of
48  *              using exchange_types()).
49  * - glob_type: The unique global type that is owner of all global entities.
50  *
51  */
52 typedef struct ir_prog ir_prog;
53
54 /**
55  * A variable from where everything in the ir can be accessed.
56  * This variable contains the irp, the "immediate representation program".
57  * This variable should be considered constant. Moreover, one should use get_irp()
58  * to get access the the irp.
59  *
60  * @note
61  *      Think of the irp as the "handle" of libFirm.
62  */
63 extern ir_prog *irp;
64
65 /**
66  * Returns the access points from where everything in the ir can be accessed.
67  *
68  * @see irp
69  */
70 ir_prog *get_irp(void);
71
72 /** initializes ir_prog. Calls the constructor for an ir_prog. */
73 void init_irprog(void);
74
75 /** Creates a new ir_prog, returns it and sets irp with it.
76    Automatically called by init_firm() through init_irprog.  */
77 ir_prog *new_ir_prog (void);
78
79 /** frees all memory used by irp.  Types in type list and irgs in irg
80     list must be freed by hand before. */
81 void     free_ir_prog(void);
82
83 /** Gets the main routine of the compiled program. */
84 ir_graph *get_irp_main_irg(void);
85
86 /** Sets the main routine of the compiled program. */
87 void      set_irp_main_irg(ir_graph *main_irg);
88
89 /** Adds irg to the list of ir graphs in irp. */
90 void      add_irp_irg(ir_graph *irg);
91
92 /** Removes irg from the list of irgs, deallocates it and
93     shrinks the list by one. */
94 void      remove_irp_irg(ir_graph *irg);
95
96 /** Returns the number of ir graphs in the irp. */
97 int       get_irp_n_irgs(void);
98
99 /** Returns the ir graph at position pos in the irp. */
100 ir_graph *get_irp_irg(int pos);
101
102 /** Sets the ir graph at position pos. */
103 void      set_irp_irg(int pos, ir_graph *irg);
104
105 /** Adds type to the list of types in irp. */
106 void  add_irp_type(type *typ);
107
108 /** Removes type from the list of types, deallocates it and
109    shrinks the list by one. */
110 void  remove_irp_type(type *typ);
111
112 /** Returns the number of all types in the irp. */
113 int   get_irp_n_types(void);
114
115 /** Returns the type at position pos in the irp. */
116 type *get_irp_type(int pos);
117
118 /** Overwrites the type at position pos with another type. */
119 void  set_irp_type(int pos, type *typ);
120
121 /** Returns the "global" type of the irp. */
122 type *get_glob_type(void);
123
124 /** File name / executable name or the like. Initially NULL! **/
125 void   set_irp_prog_name (ident *name);
126 ident *get_irp_prog_ident(void);
127 const char  *get_irp_prog_name (void);
128
129 /**
130  *   Returns an irgraph that only contains constant
131  *
132  *   expressions for constant entities.
133  *   Do not use any access function for this graph, do not generate code
134  *   for this graph.  This graph contains only one block.  The constant
135  *   expressions may not contain control flow.  See also copy_const_code()
136  *   in entity.h.
137  */
138 ir_graph *get_const_code_irg(void);
139
140 #endif /* ifndef _IRPROG_H_ */