639ccf2a8e1536af788207a9e250a9ba7ddfb5a0
[libfirm] / ir / ir / irprog.h
1 /* Copyright (C) 2000 by Universitaet Karlsruhe
2 * All rights reserved.
3 *
4 * Authors: Goetz Lindenmaier
5 *
6 * irprog.h: ir representation of a program
7 *
8 * This file defines a construct that keeps all information about a
9 * program:
10 *   - A list of all procedures.
11 *   - A list of all types.
12 *   - A global type that can be thought of as a god-class containing all
13 *     global variables and procedures.  This is not the base class of
14 *     all classes in a class hierarchy (as, e.g., "object" in java).
15 *   - (An obstack containing global things, e.g., the above mentioned lists.)
16 */
17
18 /* $Id$ */
19
20 # ifndef _IRPROG_H_
21 # define _IRPROG_H_
22
23 # include "irnode.h"
24 # include "type.h"
25
26 /**
27  *
28  * NAME  Datastructure that holds central information about a program
29  *
30  *   Preliminary documentation ;-)
31  *
32  */
33
34 /**
35  *
36  * NAME  Datastructure that holds central information about a program
37  *
38  *   Preliminary documentation ;-)
39  *
40  *  main_irg  The ir graph that is the entry point to the program.
41  *            (Anything not reachable from here may be optimized away.
42  *            If we want to translate libraries or the like correctly
43  *            we must replace this by a list.)
44  *  irg       List of all ir graphs in the program.
45  *  type      A list containing all types known to the translated program.
46  *            Some types can have several entries in this list (as a result of
47  *            using exchange_types()).
48  *  glob_type The unique global type that is owner of all global entities.
49  *
50  */
51 typedef struct ir_prog ir_prog;
52
53 /* A variable from where everything in the ir can be accessed. */
54 extern ir_prog *irp;
55 ir_prog *get_irp();
56
57 /* initializes ir_prog. Calls the constructor for an ir_prog. */
58 void init_irprog(void);
59
60 /* Creates a new ir_prog, returns it and sets irp with it.
61    Automatically called by init_firm through init_irprog.  */
62 ir_prog *new_ir_prog (void);
63
64 /* Access the main routine of the compiled program. */
65 ir_graph *get_irp_main_irg();
66 void      set_irp_main_irg(ir_graph *main_irg);
67
68 /* Adds irg to the list of ir graphs in irp. */
69 void      add_irp_irg(ir_graph *irg);
70 /* Removes irg from the list of irgs, deallocates it and
71    shrinks the list by one. */
72 void      remove_irp_irg(ir_graph *irg);
73 int       get_irp_n_irgs();
74 ir_graph *get_irp_irg(int pos);
75 void      set_irp_irg(int pos, ir_graph *irg);
76
77 /* Adds type to the list of types in irp. */
78 void  add_irp_type(type *typ);
79 /* Removes type from the list of types, deallocates it and
80    shrinks the list by one. */
81 void  remove_irp_type(type *typ);
82 int   get_irp_n_types();
83 type *get_irp_type(int pos);
84 void  set_irp_type(int pos, type *typ);
85
86 /** Functions to access the fields of ir_prog **/
87 type *get_glob_type(void);
88
89
90 /**
91  *
92  *   Returns an irgraph that only contains constant
93  *   expressions for constant entities.
94  *   Do not use any access function for this graph, do not generate code
95  *   for this graph.  This graph contains only one block.  The constant
96  *   expressions may not contain control flow.  See also copy_const_code
97  *   in entity.h.
98  */
99 ir_graph *get_const_code_irg();
100
101 #endif /* ifndef _IRPROG_H_ */