Remove the unused parameter const arch_env_t *env from arch_reg_is_allocatable().
[libfirm] / testprograms / float_example.c
1 /*
2  * Project:     libFIRM
3  * File name:   testprograms/float_example.c
4  * Purpose:
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 #include <stdio.h>
14 #include <string.h>
15
16
17
18 #include <libfirm/firm.h>
19
20 /**
21 *  An Firm program to test float values.
22 *
23 *  This file constructs the ir for the following pseudo-program:
24 *
25 *  main() {
26 *    ...
27 *  }
28 *
29 *
30 **/
31
32 int main(void)
33 {
34   ir_graph *irg;        /* this variable contains the irgraph */
35   ir_type     *owner;      /* the class in which this method is defined */
36   ir_type     *proc_main;  /* ir_type information for the method main */
37   ir_type     *prim_t_dbl;
38   ir_entity   *ent;        /* represents this method as ir_entity of owner */
39   ir_node  *x;          /* to build control flow */
40   tarval *tv;
41
42   printf("\nCreating an IR graph: FLOAT EXAMPLE...\n");
43
44   /* init library */
45   init_firm (NULL);
46
47   /** Build ir_type information for the procedure. **/
48
49   /* FIRM was designed for oo languages where all methods belong to a class.
50    * For imperative languages like C we view a file as a large class containing
51    * all functions in this file as methods.
52    * This clas is generated automatically.
53    */
54   owner = get_glob_type();
55
56 #define METHODNAME "FLOAT_EXAMPLE_main"
57 #define NRARGS 0
58 #define NRES 1
59   /* The ir_type of the method */
60   prim_t_dbl = new_type_primitive(new_id_from_chars ("dbl", 3), mode_D);
61   proc_main = new_type_method(new_id_from_chars(METHODNAME, strlen(METHODNAME)),
62                               NRARGS, NRES);
63   set_method_res_type(proc_main, 0, prim_t_dbl);
64
65   /* An ir_entity representing the method.  Owner of the ir_entity is the global class
66      ir_type mentioned above. */
67   ent = new_entity ((ir_type *)owner,
68                     new_id_from_chars (METHODNAME, strlen(METHODNAME)),
69                     (ir_type *)proc_main);
70
71   /** Build code for the procedure. **/
72
73   /* Generates the basic graph for the method represented by ir_entity ent, that
74    * is, generates start and end blocks and nodes and a first, initial block.
75    * The constructor needs to know the number of local variables (including
76    * the arguments) in the method.
77    */
78 #define NUM_OF_LOCAL_VARS 0
79   irg = new_ir_graph (ent, NUM_OF_LOCAL_VARS);
80
81   tv = new_tarval_from_str ("12345678901234567890.1234567890", 31, mode_D);
82
83
84
85
86   {
87     ir_node *in[1]; /* this is the array containing the return parameters */
88     in[0] = new_Const(mode_D, tv);
89     x = new_Return (get_store(), 1, in);
90   }
91   /* Now we generated all instructions for this block and all its predecessor
92    * blocks so we can mature it.  (There are not too much.) */
93   mature_immBlock (get_irg_current_block(irg));
94
95   /* This adds the in edge of the end block which originates at the return statement.
96    * The return node passes controlflow to the end block.  */
97   add_immBlock_pred (get_irg_end_block(irg), x);
98   /* Now we can mature the end block as all it's predecessors are known. */
99   mature_immBlock (get_irg_end_block(irg));
100
101   /* Verify the graph.  Finds some very bad errors in the graph. */
102   irg_vrfy(irg);
103   irg_finalize_cons (irg);
104
105   printf("Done building the graph.  Dumping it.\n");
106   dump_ir_block_graph (irg, 0);
107
108   printf("Use ycomp to view this graph:\n");
109   printf("ycomp GRAPHNAME\n\n");
110
111   return (0);
112 }