TEMPLATE_new_nodes.c 4.24 KB
Newer Older
Christian Würdig's avatar
Christian Würdig committed
1
/*
Michael Beck's avatar
Michael Beck committed
2
 * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
Christian Würdig's avatar
Christian Würdig committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 *
 * This file is part of libFirm.
 *
 * This file may be distributed and/or modified under the terms of the
 * GNU General Public License version 2 as published by the Free Software
 * Foundation and appearing in the file LICENSE.GPL included in the
 * packaging of this file.
 *
 * Licensees holding valid libFirm Professional Edition licenses may use
 * this file in accordance with the libFirm Commercial License.
 * Agreement provided with the Software.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE.
 */

20
/**
Matthias Braun's avatar
Matthias Braun committed
21
22
23
24
25
 * @file
 * @brief   This file implements the creation of the achitecture specific firm
 *          opcodes and the coresponding node constructors for the TEMPLATE
 *          assembler irg.
 * @version $Id$
26
 */
27
#include "config.h"
28
29
30
31
32
33
34
35
36
37

#include <stdlib.h>

#include "irprog_t.h"
#include "irgraph_t.h"
#include "irnode_t.h"
#include "irmode_t.h"
#include "ircons_t.h"
#include "iropt_t.h"
#include "irop.h"
Christian Würdig's avatar
Christian Würdig committed
38
#include "irprintf.h"
39
#include "xmalloc.h"
40

41
#include "../bearch.h"
42
43
44
45
46
47
48
49

#include "TEMPLATE_nodes_attr.h"
#include "TEMPLATE_new_nodes.h"
#include "gen_TEMPLATE_regalloc_if.h"

/**
 * Dumper interface for dumping TEMPLATE nodes in vcg.
 * @param F        the output file
50
 * @param n        the node to dump
51
52
 * @param reason   indicates which kind of information should be dumped
 */
53
static void TEMPLATE_dump_node(FILE *F, ir_node *n, dump_reason_t reason)
54
{
55
	ir_mode *mode = NULL;
56
57

	switch (reason) {
58
59
60
	case dump_node_opcode_txt:
		fprintf(F, "%s", get_irn_opname(n));
		break;
61

62
63
	case dump_node_mode_txt:
		mode = get_irn_mode(n);
Christian Würdig's avatar
Christian Würdig committed
64

65
66
67
68
69
70
71
72
		if (mode) {
			fprintf(F, "[%s]", get_mode_name(mode));
		} else {
			fprintf(F, "[?NOMODE?]");
		}
		break;

	case dump_node_nodeattr_txt:
73

74
75
		/* TODO: dump some attributes which should show up */
		/* in node name in dump (e.g. consts or the like)  */
76

77
78
79
80
81
82
83
		break;

	case dump_node_info_txt:
		arch_dump_reqs_and_registers(F, n);
		break;
	}
}
84

85
86
const TEMPLATE_attr_t *get_TEMPLATE_attr_const(const ir_node *node)
{
87
	assert(is_TEMPLATE_irn(node) && "need TEMPLATE node to get attributes");
Matthias Braun's avatar
Matthias Braun committed
88
	return (const TEMPLATE_attr_t *)get_irn_generic_attr_const(node);
89
90
}

91
92
TEMPLATE_attr_t *get_TEMPLATE_attr(ir_node *node)
{
93
	assert(is_TEMPLATE_irn(node) && "need TEMPLATE node to get attributes");
94
	return (TEMPLATE_attr_t *)get_irn_generic_attr(node);
95
96
}

Matthias Braun's avatar
Matthias Braun committed
97
98
99
/**
 * Initializes the nodes attributes.
 */
100
101
102
103
static void init_TEMPLATE_attributes(ir_node *node, arch_irn_flags_t flags,
                                     const arch_register_req_t **in_reqs,
                                     const be_execution_unit_t ***execution_units,
                                     int n_res)
Matthias Braun's avatar
Matthias Braun committed
104
{
105
106
	ir_graph        *irg  = get_irn_irg(node);
	struct obstack  *obst = get_irg_obstack(irg);
107
	backend_info_t  *info;
Matthias Braun's avatar
Matthias Braun committed
108
	(void) execution_units;
Matthias Braun's avatar
Matthias Braun committed
109

110
	arch_irn_set_flags(node, flags);
111
	arch_set_in_register_reqs(node, in_reqs);
112

113
114
115
	info            = be_get_info(node);
	info->out_infos = NEW_ARR_D(reg_out_info_t, obst, n_res);
	memset(info->out_infos, 0, n_res * sizeof(info->out_infos[0]));
Matthias Braun's avatar
Matthias Braun committed
116
}
117

Matthias Braun's avatar
Matthias Braun committed
118
static void set_TEMPLATE_value(ir_node *node, ir_tarval *value)
119
120
121
122
123
{
	TEMPLATE_attr_t *attr = get_TEMPLATE_attr(node);
	attr->value = value;
}

124
static int TEMPLATE_compare_attr(const ir_node *a, const ir_node *b)
125
126
127
{
	const TEMPLATE_attr_t *attr_a = get_TEMPLATE_attr_const(a);
	const TEMPLATE_attr_t *attr_b = get_TEMPLATE_attr_const(b);
Matthias Braun's avatar
Matthias Braun committed
128
129
	(void) attr_a;
	(void) attr_b;
130
131
132
133

	return 0;
}

134
135
136
137
138
139
140
141
142
143
144
145
146
static void TEMPLATE_copy_attr(ir_graph *irg, const ir_node *old_node,
                               ir_node *new_node)
{
	struct obstack *obst    = get_irg_obstack(irg);
	const void     *attr_old = get_irn_generic_attr_const(old_node);
	void           *attr_new = get_irn_generic_attr(new_node);
	backend_info_t *old_info = be_get_info(old_node);
	backend_info_t *new_info = be_get_info(new_node);

	/* copy the attributes */
	memcpy(attr_new, attr_old, get_op_attr_size(get_irn_op(old_node)));

	/* copy out flags */
147
	new_info->flags = old_info->flags;
148
149
150
151
152
	new_info->out_infos =
		DUP_ARR_D(reg_out_info_t, obst, old_info->out_infos);
	new_info->in_reqs = old_info->in_reqs;
}

153
154
/* Include the generated constructor functions */
#include "gen_TEMPLATE_new_nodes.c.inl"