1 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
2 ** All rights reserved.
4 ** Authors: Christian Schaefer, Goetz Lindenmaier
14 *** An Firm program to test float values.
16 *** This file constructs the ir for the following pseudo-program:
25 int main(int argc, char **argv)
27 ir_graph *irg; /* this variable contains the irgraph */
28 type *owner; /* the class in which this method is defined */
29 type *proc_main; /* type information for the method main */
31 entity *ent; /* represents this method as entity of owner */
32 ir_node *x; /* to build control flow */
35 printf("\nCreating an IR graph: EMPTY...\n");
40 /** Build type information for the procedure. **/
42 /* FIRM was designed for oo languages where all methods belong to a class.
43 * For imperative languages like C we view a file as a large class containing
44 * all functions in this file as methods.
45 * This clas is generated automatically.
47 owner = get_glob_type();
49 #define METHODNAME "main"
52 /* The type of the method */
53 prim_t_dbl = new_type_primitive(id_from_str ("dbl", 3), mode_d);
54 proc_main = new_type_method(id_from_str(METHODNAME, strlen(METHODNAME)),
56 set_method_res_type(proc_main, 0, prim_t_dbl);
58 /* An entity representing the method. Owner of the entity is the global class
59 type mentioned above. */
60 ent = new_entity ((type *)owner,
61 id_from_str (METHODNAME, strlen(METHODNAME)),
64 /** Build code for the procedure. **/
66 /* Generates the basic graph for the method represented by entity ent, that
67 * is, generates start and end blocks and nodes and a first, initial block.
68 * The constructor needs to know the number of local variables (including
69 * the arguments) in the method.
71 #define NUM_OF_LOCAL_VARS 0
72 irg = new_ir_graph (ent, NUM_OF_LOCAL_VARS);
74 tv = tarval_d_from_str ("12345678901234567890.1234567890", 31);
80 ir_node *in[1]; /* this is the array containing the return parameters */
81 in[0] = new_Const(mode_d, tv);
82 x = new_Return (get_store(), 1, in);
84 /* Now we generated all instructions for this block and all its predecessor
85 * blocks so we can mature it. (There are not too much.) */
86 mature_block (get_irg_current_block(irg));
88 /* This adds the in edge of the end block which originates at the return statement.
89 * The return node passes controlflow to the end block. */
90 add_in_edge (get_irg_end_block(irg), x);
91 /* Now we can mature the end block as all it's predecessors are known. */
92 mature_block (get_irg_end_block(irg));
94 /* Verify the graph. Finds some very bad errors in the graph. */
98 printf("Done building the graph. Dumping it.\n");
99 dump_ir_block_graph (irg);
101 printf("use xvcg to view this graph:\n");
102 printf("/ben/goetz/bin/xvcg GRAPHNAME\n\n");