2 * Author: Matthias Braun
4 * Copyright: (c) Universitaet Karlsruhe
5 * License: This file is protected by GPL - GNU GENERAL PUBLIC LICENSE.
7 #ifndef FIRM_BE_BEEMITTER_H
8 #define FIRM_BE_BEEMITTER_H
17 /* framework for emitting data (usually the final assembly code) */
19 /** The emitter environment. */
20 typedef struct be_emit_env_t {
21 FILE *F; /**< The handle of the (assembler) file that is written to. */
22 struct obstack obst; /**< An obstack for temporary storage. */
23 int linelength; /**< The length of the current line. */
27 * Emit a character to the (assembler) output.
29 * @param env the emitter environment
31 static INLINE void be_emit_char(be_emit_env_t *env, char c) {
32 obstack_1grow(&env->obst, c);
37 * Emit a string to the (assembler) output.
39 * @param env the emitter environment
40 * @param str the string
41 * @param l the length of the given string
43 static INLINE void be_emit_string_len(be_emit_env_t *env, const char *str,
46 obstack_grow(&env->obst, str, l);
51 * Emit a null-terminated string to the (assembler) output.
53 * @param env the emitter environment
54 * @param str the null-terminated string
56 static INLINE void be_emit_string(be_emit_env_t *env, const char *str)
58 size_t len = strlen(str);
59 be_emit_string_len(env, str, len);
63 * Emit a C string-constant to the (assembler) output.
65 * @param env the emitter environment
66 * @param str the null-terminated string constant
68 #define be_emit_cstring(env, str) { be_emit_string_len(env, str, sizeof(str)-1); }
71 * Initializes an emitter environment.
73 * @param env the (uninitialized) emitter environment
74 * @param F a file handle where the emitted file is written to.
76 void be_emit_init_env(be_emit_env_t *env, FILE *F);
79 * Destroys the given emitter environment.
81 * @param env the emitter environment
83 void be_emit_destroy_env(be_emit_env_t *env);
86 * Emit an ident to the (assembler) output.
88 * @param env the emitter environment
89 * @param id the ident to be emitted
91 void be_emit_ident(be_emit_env_t *env, ident *id);
94 * Emit the output of an ir_printf.
96 * @param env the emitter environment
97 * @param fmt the ir_printf format
99 void be_emit_irprintf(be_emit_env_t *env, const char *fmt, ...);
102 * Emit the output of an ir_vprintf.
104 * @param env the emitter environment
105 * @param fmt the ir_printf format
107 void be_emit_irvprintf(be_emit_env_t *env, const char *fmt, va_list args);
110 * Flush the line in the current line buffer to the emitter file.
112 * @param env the emitter environment
114 void be_emit_write_line(be_emit_env_t *env);
117 * Flush the line in the current line buffer to the emitter file and
118 * appends a gas-style comment with the node number and writes the line
120 * @param env the emitter environment
121 * @param node the node to get the debug info from
123 void be_emit_finish_line_gas(be_emit_env_t *env, const ir_node *node);
126 * Emit spaces until the comment position is reached.
128 * @param env the emitter environment
130 void be_emit_pad_comment(be_emit_env_t *env);
132 #endif /* FIRM_BE_BEEMITTER_H */