besched: Add and use sched_replace().
[libfirm] / ir / be / beemitter.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       Interface for assembler output.
23  * @author      Matthias Braun
24  * @date        12.03.2007
25  */
26 #include "config.h"
27
28 #include "bedwarf.h"
29 #include "beemitter.h"
30 #include "be_t.h"
31 #include "error.h"
32 #include "irnode_t.h"
33 #include "irprintf.h"
34 #include "ident.h"
35 #include "tv.h"
36 #include "dbginfo.h"
37
38 FILE           *emit_file;
39 struct obstack  emit_obst;
40
41 void be_emit_init(FILE *file)
42 {
43         emit_file       = file;
44         obstack_init(&emit_obst);
45 }
46
47 void be_emit_exit(void)
48 {
49         obstack_free(&emit_obst, NULL);
50 }
51
52 void be_emit_irvprintf(const char *fmt, va_list args)
53 {
54         ir_obst_vprintf(&emit_obst, fmt, args);
55 }
56
57 void be_emit_irprintf(const char *fmt, ...)
58 {
59         va_list ap;
60
61         va_start(ap, fmt);
62         be_emit_irvprintf(fmt, ap);
63         va_end(ap);
64 }
65
66 void be_emit_write_line(void)
67 {
68         size_t  len  = obstack_object_size(&emit_obst);
69         char   *line = (char*)obstack_finish(&emit_obst);
70
71         fwrite(line, 1, len, emit_file);
72         obstack_free(&emit_obst, line);
73 }
74
75 void be_emit_pad_comment(void)
76 {
77         size_t len = obstack_object_size(&emit_obst);
78         if (len > 30)
79                 len = 30;
80         /* 34 spaces */
81         be_emit_string_len("                                  ", 34 - len);
82 }
83
84 void be_emit_finish_line_gas(const ir_node *node)
85 {
86         dbg_info  *dbg;
87         src_loc_t  loc;
88
89         if (node == NULL || !be_options.verbose_asm) {
90                 be_emit_char('\n');
91                 be_emit_write_line();
92                 return;
93         }
94
95         be_emit_pad_comment();
96         be_emit_cstring("/* ");
97         be_emit_irprintf("%+F ", node);
98
99         dbg = get_irn_dbg_info(node);
100         loc = ir_retrieve_dbg_info(dbg);
101         if (loc.file) {
102                 be_emit_string(loc.file);
103                 if (loc.line != 0) {
104                         be_emit_irprintf(":%u", loc.line);
105                         if (loc.column != 0) {
106                                 be_emit_irprintf(":%u", loc.column);
107                         }
108                 }
109         }
110         be_emit_cstring(" */\n");
111         be_emit_write_line();
112 }
113
114 void be_emit_nothing(ir_node const *const node)
115 {
116         (void)node;
117 }
118
119 void be_emit_node(ir_node const *const node)
120 {
121         be_dwarf_location(get_irn_dbg_info(node));
122         ir_op     *const op   = get_irn_op(node);
123         emit_func *const emit = get_generic_function_ptr(emit_func, op);
124         DEBUG_ONLY(if (!emit) panic("no emit handler for node %+F (%+G, graph %+F)\n", node, node, get_irn_irg(node));)
125         emit(node);
126 }