- implemented get_irg_value_param_type()
[libfirm] / testprograms / empty.c
1 /*
2  * Project:     libFIRM
3  * File name:   testprograms/empty.c
4  * Purpose:     The smallest possible firm graph.
5  * Author:      Christian Schaefer, Goetz Lindenmaier
6  * Modified by:
7  * Created:
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 1999-2003 Universität Karlsruhe
10  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11  */
12
13
14 #include <stdio.h>
15 #include <string.h>
16
17
18
19 #include <libfirm/firm.h>
20
21 /**
22 *  An empty Firm program.
23 *
24 *  This file constructs the ir for the following pseudo-program:
25 *
26 *  main() {
27 *    return;
28 *  }
29 *
30 *
31 **/
32
33 int main(void)
34 {
35   ir_graph *irg;        /* this variable contains the irgraph */
36   ir_type     *owner;      /* the class in which this method is defined */
37   ir_type     *proc_main;  /* ir_type information for the method main */
38   ir_entity   *ent;        /* represents this method as ir_entity of owner */
39   ir_node  *x;          /* to build control flow */
40
41   printf("\nCreating an IR graph: EMPTY...\n");
42
43   /* init library */
44   init_firm (NULL);
45
46   /** Build ir_type information for the procedure. **/
47
48   /* FIRM was designed for oo languages where all methods belong to a class.
49    * For imperative languages like C we view a file as a large class containing
50    * all functions in this file as methods.
51    * This clas is generated automatically.
52    */
53   owner = get_glob_type();
54
55 #define METHODNAME "EMPTY_main"
56 #define NRARGS 0
57 #define NRES 0
58   /* The ir_type of the method */
59   proc_main = new_type_method(new_id_from_chars(METHODNAME, strlen(METHODNAME)),
60                               NRARGS, NRES);
61   /* An ir_entity representing the method.  Owner of the ir_entity is the global class
62      ir_type mentioned above. */
63   ent = new_entity ((ir_type *)owner,
64                     new_id_from_chars (METHODNAME, strlen(METHODNAME)),
65                     (ir_type *)proc_main);
66
67   /** Build code for the procedure. **/
68
69   /* Generates the basic graph for the method represented by ir_entity ent, that
70    * is, generates start and end blocks and nodes and a first, initial block.
71    * The constructor needs to know the number of local variables (including
72    * the arguments) in the method.
73    */
74 #define NUM_OF_LOCAL_VARS 0
75   irg = new_ir_graph (ent, NUM_OF_LOCAL_VARS);
76
77   /* The constructor new_ir_graph() generated a region to place nodes in.
78    * This region is accessible via the attribut current_block of irg and
79    * it is not matured.
80    * Generate the return node into this region. The Return node is needed to
81    * return at least the memory. */
82     x = new_Return (get_store(), 0, NULL);
83   /* Now we generated all instructions for this block and all its predecessor
84    * blocks so we can mature it.  (There are not too much.) */
85   mature_immBlock (get_irg_current_block(irg));
86
87   /* This adds the in edge of the end block which originates at the return statement.
88    * The return node passes controlflow to the end block.  */
89   add_immBlock_pred (get_irg_end_block(irg), x);
90   /* Now we can mature the end block as all it's predecessors are known. */
91   mature_immBlock (get_irg_end_block(irg));
92
93   /* Verify the graph.  Finds some very bad errors in the graph. */
94   irg_vrfy(irg);
95   irg_finalize_cons (irg);
96
97   printf("Done building the graph.  Dumping it.\n");
98   dump_ir_block_graph (irg, 0);
99
100   printf("Use ycomp to view this graph:\n");
101   printf("ycomp GRAPHNAME\n\n");
102
103   return (0);
104 }