fix bugs when exchanging nodes to projs in bepeephole
[libfirm] / ir / be / beemitter.h
1 /*
2  * Copyright (C) 1995-2007 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  * @version     $Id$
26  *
27  * This is a framework for emitting data (usually the final assembly code)
28  */
29 #ifndef FIRM_BE_BEEMITTER_H
30 #define FIRM_BE_BEEMITTER_H
31
32 #include "firm_config.h"
33
34 #include <stdio.h>
35 #include <stdarg.h>
36 #include "firm_types.h"
37 #include "obst.h"
38 #include "be.h"
39
40 /* don't use the following vars directly, they're only here for the inlines */
41 extern FILE           *emit_file;
42 extern struct obstack  emit_obst;
43 extern int             emit_linelength;
44
45 /**
46  * Emit a character to the (assembler) output.
47  *
48  * @param env  the emitter environment
49  */
50 static INLINE void be_emit_char(char c)
51 {
52         obstack_1grow(&emit_obst, c);
53         emit_linelength++;
54 }
55
56 /**
57  * Emit a string to the (assembler) output.
58  *
59  * @param env  the emitter environment
60  * @param str  the string
61  * @param l    the length of the given string
62  */
63 static INLINE void be_emit_string_len(const char *str, size_t l)
64 {
65         obstack_grow(&emit_obst, str, l);
66         emit_linelength += l;
67 }
68
69 /**
70  * Emit a null-terminated string to the (assembler) output.
71  *
72  * @param env  the emitter environment
73  * @param str  the null-terminated string
74  */
75 static INLINE void be_emit_string(const char *str)
76 {
77         size_t len = strlen(str);
78         be_emit_string_len(str, len);
79 }
80
81 /**
82  * Emit a C string-constant to the (assembler) output.
83  *
84  * @param env  the emitter environment
85  * @param str  the null-terminated string constant
86  */
87 #define be_emit_cstring(str) \
88         do { be_emit_string_len(str, sizeof(str)-1); } while(0)
89
90 /**
91  * Initializes an emitter environment.
92  *
93  * @param env  the (uninitialized) emitter environment
94  * @param F    a file handle where the emitted file is written to.
95  */
96 void be_emit_init(FILE *F);
97
98 /**
99  * Destroys the given emitter environment.
100  *
101  * @param env  the emitter environment
102  */
103 void be_emit_exit(void);
104
105 /**
106  * Emit an ident to the (assembler) output.
107  *
108  * @param env  the emitter environment
109  * @param id   the ident to be emitted
110  */
111 void be_emit_ident(ident *id);
112
113 /**
114  * Emit a firm tarval.
115  *
116  * @param env  the emitter environment
117  * @param tv   the tarval to be emitted
118  */
119 void be_emit_tarval(tarval *tv);
120
121 /**
122  * Emit the output of an ir_printf.
123  *
124  * @param env  the emitter environment
125  * @param fmt  the ir_printf format
126  */
127 void be_emit_irprintf(const char *fmt, ...);
128
129 /**
130  * Emit the output of an ir_vprintf.
131  *
132  * @param env  the emitter environment
133  * @param fmt  the ir_printf format
134  */
135 void be_emit_irvprintf(const char *fmt, va_list args);
136
137 /**
138  * Flush the line in the current line buffer to the emitter file.
139  *
140  * @param env  the emitter environment
141  */
142 void be_emit_write_line(void);
143
144 /**
145  * Flush the line in the current line buffer to the emitter file and
146  * appends a gas-style comment with the node number and writes the line
147  *
148  * @param env   the emitter environment
149  * @param node  the node to get the debug info from
150  */
151 void be_emit_finish_line_gas(const ir_node *node);
152
153 /**
154  * Emit spaces until the comment position is reached.
155  *
156  * @param env  the emitter environment
157  */
158 void be_emit_pad_comment(void);
159
160 #endif