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 */
26 #include "config.h"
27
28 #include <stdlib.h>
29
30 #include "irprog_t.h"
31 #include "irgraph_t.h"
32 #include "irnode_t.h"
33 #include "irmode_t.h"
34 #include "ircons_t.h"
35 #include "iropt_t.h"
36 #include "irop.h"
37 #include "irprintf.h"
38 #include "xmalloc.h"
39
40 #include "bearch.h"
41
42 #include "TEMPLATE_nodes_attr.h"
43 #include "TEMPLATE_new_nodes.h"
44 #include "gen_TEMPLATE_regalloc_if.h"
45
46 /**
47 * Dumper interface for dumping TEMPLATE nodes in vcg.
48 * @param F the output file
49 * @param n the node to dump
50 * @param reason indicates which kind of information should be dumped
51 */
TEMPLATE_dump_node(FILE * F,const ir_node * n,dump_reason_t reason)52 static void TEMPLATE_dump_node(FILE *F, const ir_node *n, dump_reason_t reason)
53 {
54 ir_mode *mode = NULL;
55
56 switch (reason) {
57 case dump_node_opcode_txt:
58 fprintf(F, "%s", get_irn_opname(n));
59 break;
60
61 case dump_node_mode_txt:
62 mode = get_irn_mode(n);
63
64 if (mode) {
65 fprintf(F, "[%s]", get_mode_name(mode));
66 } else {
67 fprintf(F, "[?NOMODE?]");
68 }
69 break;
70
71 case dump_node_nodeattr_txt:
72
73 /* TODO: dump some attributes which should show up */
74 /* in node name in dump (e.g. consts or the like) */
75
76 break;
77
78 case dump_node_info_txt:
79 arch_dump_reqs_and_registers(F, n);
80 break;
81 }
82 }
83
get_TEMPLATE_attr_const(const ir_node * node)84 const TEMPLATE_attr_t *get_TEMPLATE_attr_const(const ir_node *node)
85 {
86 assert(is_TEMPLATE_irn(node) && "need TEMPLATE node to get attributes");
87 return (const TEMPLATE_attr_t *)get_irn_generic_attr_const(node);
88 }
89
get_TEMPLATE_attr(ir_node * node)90 TEMPLATE_attr_t *get_TEMPLATE_attr(ir_node *node)
91 {
92 assert(is_TEMPLATE_irn(node) && "need TEMPLATE node to get attributes");
93 return (TEMPLATE_attr_t *)get_irn_generic_attr(node);
94 }
95
96 /**
97 * Initializes the nodes attributes.
98 */
init_TEMPLATE_attributes(ir_node * node,arch_irn_flags_t flags,const arch_register_req_t ** in_reqs,int n_res)99 static void init_TEMPLATE_attributes(ir_node *node, arch_irn_flags_t flags,
100 const arch_register_req_t **in_reqs,
101 int n_res)
102 {
103 ir_graph *irg = get_irn_irg(node);
104 struct obstack *obst = get_irg_obstack(irg);
105 backend_info_t *info;
106
107 arch_set_irn_flags(node, flags);
108 arch_set_irn_register_reqs_in(node, in_reqs);
109
110 info = be_get_info(node);
111 info->out_infos = NEW_ARR_D(reg_out_info_t, obst, n_res);
112 memset(info->out_infos, 0, n_res * sizeof(info->out_infos[0]));
113 }
114
set_TEMPLATE_value(ir_node * node,ir_tarval * value)115 static void set_TEMPLATE_value(ir_node *node, ir_tarval *value)
116 {
117 TEMPLATE_attr_t *attr = get_TEMPLATE_attr(node);
118 attr->value = value;
119 }
120
TEMPLATE_compare_attr(const ir_node * a,const ir_node * b)121 static int TEMPLATE_compare_attr(const ir_node *a, const ir_node *b)
122 {
123 const TEMPLATE_attr_t *attr_a = get_TEMPLATE_attr_const(a);
124 const TEMPLATE_attr_t *attr_b = get_TEMPLATE_attr_const(b);
125 (void) attr_a;
126 (void) attr_b;
127
128 return 0;
129 }
130
TEMPLATE_copy_attr(ir_graph * irg,const ir_node * old_node,ir_node * new_node)131 static void TEMPLATE_copy_attr(ir_graph *irg, const ir_node *old_node,
132 ir_node *new_node)
133 {
134 struct obstack *obst = get_irg_obstack(irg);
135 const void *attr_old = get_irn_generic_attr_const(old_node);
136 void *attr_new = get_irn_generic_attr(new_node);
137 backend_info_t *old_info = be_get_info(old_node);
138 backend_info_t *new_info = be_get_info(new_node);
139
140 /* copy the attributes */
141 memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));
142
143 /* copy out flags */
144 new_info->flags = old_info->flags;
145 new_info->out_infos =
146 DUP_ARR_D(reg_out_info_t, obst, old_info->out_infos);
147 new_info->in_reqs = old_info->in_reqs;
148 }
149
150 /* Include the generated constructor functions */
151 #include "gen_TEMPLATE_new_nodes.c.inl"
152