- Reworked backends to put out register_requirements into backend_info_t
[libfirm] / ir / be / TEMPLATE / TEMPLATE_new_nodes.c
1 /*
2  * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
6  * This file may be distributed and/or modified under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation and appearing in the file LICENSE.GPL included in the
9  * packaging of this file.
10  *
11  * Licensees holding valid libFirm Professional Edition licenses may use
12  * this file in accordance with the libFirm Commercial License.
13  * Agreement provided with the Software.
14  *
15  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief   This file implements the creation of the achitecture specific firm
23  *          opcodes and the coresponding node constructors for the TEMPLATE
24  *          assembler irg.
25  * @version $Id$
26  */
27 #include "config.h"
28
29 #include <stdlib.h>
30
31 #include "irprog_t.h"
32 #include "irgraph_t.h"
33 #include "irnode_t.h"
34 #include "irmode_t.h"
35 #include "ircons_t.h"
36 #include "iropt_t.h"
37 #include "irop.h"
38 #include "irvrfy_t.h"
39 #include "irprintf.h"
40 #include "xmalloc.h"
41
42 #include "../bearch.h"
43
44 #include "TEMPLATE_nodes_attr.h"
45 #include "TEMPLATE_new_nodes.h"
46 #include "gen_TEMPLATE_regalloc_if.h"
47
48
49
50 /***********************************************************************************
51  *      _                                   _       _             __
52  *     | |                                 (_)     | |           / _|
53  *   __| |_   _ _ __ ___  _ __   ___ _ __   _ _ __ | |_ ___ _ __| |_ __ _  ___ ___
54  *  / _` | | | | '_ ` _ \| '_ \ / _ \ '__| | | '_ \| __/ _ \ '__|  _/ _` |/ __/ _ \
55  * | (_| | |_| | | | | | | |_) |  __/ |    | | | | | ||  __/ |  | || (_| | (_|  __/
56  *  \__,_|\__,_|_| |_| |_| .__/ \___|_|    |_|_| |_|\__\___|_|  |_| \__,_|\___\___|
57  *                       | |
58  *                       |_|
59  ***********************************************************************************/
60
61 /**
62  * Dumper interface for dumping TEMPLATE nodes in vcg.
63  * @param n        the node to dump
64  * @param F        the output file
65  * @param reason   indicates which kind of information should be dumped
66  * @return 0 on success or != 0 on failure
67  */
68 static int TEMPLATE_dump_node(ir_node *n, FILE *F, dump_reason_t reason)
69 {
70         ir_mode *mode = NULL;
71
72         switch (reason) {
73         case dump_node_opcode_txt:
74                 fprintf(F, "%s", get_irn_opname(n));
75                 break;
76
77         case dump_node_mode_txt:
78                 mode = get_irn_mode(n);
79
80                 if (mode) {
81                         fprintf(F, "[%s]", get_mode_name(mode));
82                 } else {
83                         fprintf(F, "[?NOMODE?]");
84                 }
85                 break;
86
87         case dump_node_nodeattr_txt:
88
89                 /* TODO: dump some attributes which should show up */
90                 /* in node name in dump (e.g. consts or the like)  */
91
92                 break;
93
94         case dump_node_info_txt:
95                 arch_dump_reqs_and_registers(F, n);
96                 break;
97         }
98
99         return 0;
100 }
101
102 /***************************************************************************************************
103  *        _   _                   _       __        _                    _   _               _
104  *       | | | |                 | |     / /       | |                  | | | |             | |
105  *   __ _| |_| |_ _ __   ___  ___| |_   / /_ _  ___| |_   _ __ ___   ___| |_| |__   ___   __| |___
106  *  / _` | __| __| '__| / __|/ _ \ __| / / _` |/ _ \ __| | '_ ` _ \ / _ \ __| '_ \ / _ \ / _` / __|
107  * | (_| | |_| |_| |    \__ \  __/ |_ / / (_| |  __/ |_  | | | | | |  __/ |_| | | | (_) | (_| \__ \
108  *  \__,_|\__|\__|_|    |___/\___|\__/_/ \__, |\___|\__| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|___/
109  *                                        __/ |
110  *                                       |___/
111  ***************************************************************************************************/
112
113 const TEMPLATE_attr_t *get_TEMPLATE_attr_const(const ir_node *node)
114 {
115         assert(is_TEMPLATE_irn(node) && "need TEMPLATE node to get attributes");
116         return (const TEMPLATE_attr_t *)get_irn_generic_attr_const(node);
117 }
118
119 TEMPLATE_attr_t *get_TEMPLATE_attr(ir_node *node)
120 {
121         assert(is_TEMPLATE_irn(node) && "need TEMPLATE node to get attributes");
122         return (TEMPLATE_attr_t *)get_irn_generic_attr(node);
123 }
124
125 /**
126  * Returns the argument register requirements of a TEMPLATE node.
127  */
128 const arch_register_req_t **get_TEMPLATE_in_req_all(const ir_node *node)
129 {
130         const TEMPLATE_attr_t *attr = get_TEMPLATE_attr_const(node);
131         return attr->in_req;
132 }
133
134 /**
135  * Returns the argument register requirement at position pos of an TEMPLATE node.
136  */
137 const arch_register_req_t *get_TEMPLATE_in_req(const ir_node *node, int pos)
138 {
139         const TEMPLATE_attr_t *attr = get_TEMPLATE_attr_const(node);
140         return attr->in_req[pos];
141 }
142
143 /**
144  * Returns the result register requirement at position pos of an TEMPLATE node.
145  */
146 const arch_register_req_t *get_TEMPLATE_out_req(const ir_node *node, int pos)
147 {
148         const backend_info_t *info = be_get_info(node);
149         return info->out_infos[pos].req;
150 }
151
152 /**
153  * Sets the IN register requirements at position pos.
154  */
155 void set_TEMPLATE_req_in(ir_node *node, const arch_register_req_t *req, int pos)
156 {
157         TEMPLATE_attr_t *attr  = get_TEMPLATE_attr(node);
158         attr->in_req[pos] = req;
159 }
160
161 /**
162  * Initializes the nodes attributes.
163  */
164 void init_TEMPLATE_attributes(ir_node *node, arch_irn_flags_t flags,
165                               const arch_register_req_t **in_reqs,
166                               const be_execution_unit_t ***execution_units,
167                               int n_res)
168 {
169         ir_graph        *irg  = get_irn_irg(node);
170         struct obstack  *obst = get_irg_obstack(irg);
171         TEMPLATE_attr_t *attr = get_TEMPLATE_attr(node);
172         backend_info_t  *info;
173         (void) execution_units;
174
175         arch_irn_set_flags(node, flags);
176         attr->in_req  = in_reqs;
177
178         info            = be_get_info(node);
179         info->out_infos = NEW_ARR_D(reg_out_info_t, obst, n_res);
180         memset(info->out_infos, 0, n_res * sizeof(info->out_infos[0]));
181 }
182
183 /***************************************************************************************
184  *                  _                            _                   _
185  *                 | |                          | |                 | |
186  *  _ __   ___   __| | ___    ___ ___  _ __  ___| |_ _ __ _   _  ___| |_ ___  _ __ ___
187  * | '_ \ / _ \ / _` |/ _ \  / __/ _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__/ __|
188  * | | | | (_) | (_| |  __/ | (_| (_) | | | \__ \ |_| |  | |_| | (__| || (_) | |  \__ \
189  * |_| |_|\___/ \__,_|\___|  \___\___/|_| |_|___/\__|_|   \__,_|\___|\__\___/|_|  |___/
190  *
191  ***************************************************************************************/
192
193 static int TEMPLATE_compare_attr(ir_node *a, ir_node *b)
194 {
195         const TEMPLATE_attr_t *attr_a = get_TEMPLATE_attr_const(a);
196         const TEMPLATE_attr_t *attr_b = get_TEMPLATE_attr_const(b);
197         (void) attr_a;
198         (void) attr_b;
199
200         return 0;
201 }
202
203
204 /* Include the generated constructor functions */
205 #include "gen_TEMPLATE_new_nodes.c.inl"