1 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
2 ** All rights reserved.
4 ** Authors: Christian Schaefer, Goetz Lindenmaier
15 * das leere FIRM Programm
19 *** This file constructs the ir for the following pseudo-program:
26 int main(int argc, char **argv)
28 ir_graph *irg; /* this variable contains the irgraph */
29 type_class *owner; /* the class in which this method is defined */
30 type_method *proc_main; /* typeinformation for the method main */
31 entity *ent; /* represents this method as entity of owner */
34 printf("creating an IR graph: EMPTY...\n");
39 /* FIRM was designed for oo languages where all methods belong to a class.
40 * For imperative languages like C we view a file as a large class containing
41 * all functions as methods in this file.
42 * Therefore we define a class "empty" according to the file name
43 * with a method main as an entity.
45 #define CLASSNAME "EMPTY"
46 #define METHODNAME "main"
50 owner = new_type_class (id_from_str (CLASSNAME, strlen(CLASSNAME)));
51 proc_main = new_type_method(id_from_str(METHODNAME, strlen(METHODNAME)),
53 ent = new_entity ((type *)owner,
54 id_from_str (METHODNAME, strlen(METHODNAME)),
57 /* Generates the basic graph for the method represented by entity ent, that
58 * is, generates start and end blocks and nodes and a first, initial block.
59 * The constructor needs to know how many local variables the method has.
61 #define NUM_OF_LOCAL_VARS 0
63 irg = new_ir_graph (ent, NUM_OF_LOCAL_VARS);
66 /* The constructor new_ir_graph() generated a region to place nodes in.
67 * This region is accessible via the attribut current_block of irg and
69 * Generate the return node into this region. The Return node is needed to
70 * return at least the store. */
72 ir_node *in[0]; /* this is the array containing the return parameters */
73 x = new_Return (get_store(), 0, in);
75 /* Now generate all instructions for this block and all its predecessor blocks
76 * so we can mature it. */
77 mature_block (irg->current_block);
79 /* This adds the in edge of the end block which originates at the return statement.
80 * The return node passes controlflow to the end block. */
81 add_in_edge (irg->end_block, x);
82 /* Now we can mature the end block as all it's predecessors are known. */
83 mature_block (irg->end_block);
85 printf("\nDone building the graph. Dumping it.\n");
86 dump_ir_block_graph (irg);
88 printf("use xvcg to view this graph:\n");
89 printf("/ben/trapp/bin/i486/xvcg GRAPHNAME\n");