2 * Copyright (C) 2010 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
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.
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.
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
22 * @brief Dump MinIR format for register coalescing
23 * @author Matthias Braun
33 static const arch_env_t *arch_env;
36 static int item_indent_add;
37 static bool had_list_item;
38 static bool no_newline;
40 static void newline(void)
50 for (i = 0; i < indent + item_indent_add; ++i) {
55 static void begin_key(const char *name)
58 fprintf(out, "%s: ", name);
61 static void end_key(const char *name)
67 static void begin_block_sequence(const char *name)
73 static void end_block_sequence(const char *name)
80 static void block_sequence_item(void)
89 static void begin_mapping(const char *name)
95 static void end_maping(const char *name)
101 static void value(const char *val)
106 static void key_value(const char *name, const char *val)
113 static void begin_list(const char *name)
117 had_list_item = false;
120 static void end_list(const char *name)
122 /* TODO: verify that we started a list */
127 static void list_item(void)
131 had_list_item = true;
134 static void list_item_value(const char *val)
140 static void print_regclasses(void)
142 int n_classes = arch_env_get_n_reg_class(arch_env);
145 begin_block_sequence("regclasses");
146 for (c = 0; c < n_classes; ++c) {
149 const arch_register_class_t *cls = arch_env_get_reg_class(arch_env, c);
150 if (arch_register_class_flags(cls) & arch_register_class_flag_manual_ra)
153 n_regs = arch_register_class_n_regs(cls);
155 block_sequence_item();
157 key_value("name", cls->name);
158 begin_list("registers");
159 for (r = 0; r < n_regs; ++r) {
160 const arch_register_t *reg = arch_register_for_index(cls, r);
161 list_item_value(reg->name);
163 end_list("registers");
165 begin_mapping("flags");
166 for (r = 0; r < n_regs; ++r) {
167 const arch_register_t *reg = arch_register_for_index(cls, r);
168 unsigned type = reg->type;
169 if (type & arch_register_type_ignore) {
170 begin_list(reg->name);
171 list_item_value("reserved");
172 list_item_value("nossa"); /* do we need this? */
178 end_block_sequence("regclasses");
181 static void dump_block(ir_node *block, void *data)
183 ir_graph *irg = get_irn_irg(block);
186 block_sequence_item();
187 if (block == get_irg_start_block(irg)) {
188 key_value("label", "start");
189 } else if (block == get_irg_end_block(irg)) {
190 key_value("label", "end");
193 snprintf(name, sizeof(name), "bb%ld", get_irn_node_nr(block));
194 key_value("label", name);
197 begin_block_sequence("ops");
198 end_block_sequence("ops");
201 static void print_function(ir_graph *irg)
203 ir_entity *entity = get_irg_entity(irg);
205 block_sequence_item();
207 key_value("label", get_entity_name(entity));
208 begin_list("entries"); list_item_value("start"); end_list("entries");
209 begin_list("exit"); list_item_value("end"); end_list("entries");
211 begin_block_sequence("bbs");
212 irg_block_walk_graph(irg, dump_block, NULL, NULL);
213 end_block_sequence("bbs");
216 void be_export_minir(const arch_env_t *new_arch_env, FILE *new_out, ir_graph *irg)
218 arch_env = new_arch_env;
225 begin_block_sequence("functions");
227 end_block_sequence("functions");