2 * Copyright (C) 1995-2007 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 Interface for assembler output.
23 * @author Matthias Braun
27 #ifndef FIRM_BE_BEEMITTER_H
28 #define FIRM_BE_BEEMITTER_H
32 #include "firm_types.h"
36 /* framework for emitting data (usually the final assembly code) */
38 /** The emitter environment. */
39 typedef struct be_emit_env_t {
40 FILE *F; /**< The handle of the (assembler) file that is written to. */
41 struct obstack obst; /**< An obstack for temporary storage. */
42 int linelength; /**< The length of the current line. */
46 * Emit a character to the (assembler) output.
48 * @param env the emitter environment
50 static INLINE void be_emit_char(be_emit_env_t *env, char c) {
51 obstack_1grow(&env->obst, c);
56 * Emit a string to the (assembler) output.
58 * @param env the emitter environment
59 * @param str the string
60 * @param l the length of the given string
62 static INLINE void be_emit_string_len(be_emit_env_t *env, const char *str,
65 obstack_grow(&env->obst, str, l);
70 * Emit a null-terminated string to the (assembler) output.
72 * @param env the emitter environment
73 * @param str the null-terminated string
75 static INLINE void be_emit_string(be_emit_env_t *env, const char *str)
77 size_t len = strlen(str);
78 be_emit_string_len(env, str, len);
82 * Emit a C string-constant to the (assembler) output.
84 * @param env the emitter environment
85 * @param str the null-terminated string constant
87 #define be_emit_cstring(env, str) do { be_emit_string_len(env, str, sizeof(str)-1); } while(0)
90 * Initializes an emitter environment.
92 * @param env the (uninitialized) emitter environment
93 * @param F a file handle where the emitted file is written to.
95 void be_emit_init_env(be_emit_env_t *env, FILE *F);
98 * Destroys the given emitter environment.
100 * @param env the emitter environment
102 void be_emit_destroy_env(be_emit_env_t *env);
105 * Emit an ident to the (assembler) output.
107 * @param env the emitter environment
108 * @param id the ident to be emitted
110 void be_emit_ident(be_emit_env_t *env, ident *id);
113 * Emit a firm tarval.
115 * @param env the emitter environment
116 * @param tv the tarval to be emitted
118 void be_emit_tarval(be_emit_env_t *env, tarval *tv);
121 * Emit the output of an ir_printf.
123 * @param env the emitter environment
124 * @param fmt the ir_printf format
126 void be_emit_irprintf(be_emit_env_t *env, const char *fmt, ...);
129 * Emit the output of an ir_vprintf.
131 * @param env the emitter environment
132 * @param fmt the ir_printf format
134 void be_emit_irvprintf(be_emit_env_t *env, const char *fmt, va_list args);
137 * Flush the line in the current line buffer to the emitter file.
139 * @param env the emitter environment
141 void be_emit_write_line(be_emit_env_t *env);
144 * Flush the line in the current line buffer to the emitter file and
145 * appends a gas-style comment with the node number and writes the line
147 * @param env the emitter environment
148 * @param node the node to get the debug info from
150 void be_emit_finish_line_gas(be_emit_env_t *env, const ir_node *node);
153 * Emit spaces until the comment position is reached.
155 * @param env the emitter environment
157 void be_emit_pad_comment(be_emit_env_t *env);
159 #endif /* FIRM_BE_BEEMITTER_H */