331c2202d580242408261e023143cb1d408db25c
[libfirm] / ir / be / beemitter.h
1 /*
2  * Author:      Matthias Braun
3  * Date:                12.03.2007
4  * Copyright:   (c) Universitaet Karlsruhe
5  * License:     This file is protected by GPL -  GNU GENERAL PUBLIC LICENSE.
6  */
7 #ifndef FIRM_BE_BEEMITTER_H
8 #define FIRM_BE_BEEMITTER_H
9
10 #include <stdio.h>
11 #include <stdarg.h>
12 #include "obst.h"
13 #include "ident.h"
14 #include "irnode.h"
15 #include "be.h"
16
17 /* framework for emitting data (usually the final assembly code) */
18
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. */
24 } be_emit_env_t;
25
26 /**
27  * Emit a character to the (assembler) output.
28  *
29  * @param env  the emitter environment
30  */
31 static INLINE void be_emit_char(be_emit_env_t *env, char c) {
32         obstack_1grow(&env->obst, c);
33         env->linelength++;
34 }
35
36 /**
37  * Emit a string to the (assembler) output.
38  *
39  * @param env  the emitter environment
40  * @param str  the string
41  * @param l    the length of the given string
42  */
43 static INLINE void be_emit_string_len(be_emit_env_t *env, const char *str,
44                                       size_t l)
45 {
46         obstack_grow(&env->obst, str, l);
47         env->linelength += l;
48 }
49
50 /**
51  * Emit a null-terminated string to the (assembler) output.
52  *
53  * @param env  the emitter environment
54  * @param str  the null-terminated string
55  */
56 static INLINE void be_emit_string(be_emit_env_t *env, const char *str)
57 {
58         size_t len = strlen(str);
59         be_emit_string_len(env, str, len);
60 }
61
62 /**
63  * Emit a C string-constant to the (assembler) output.
64  *
65  * @param env  the emitter environment
66  * @param str  the null-terminated string constant
67  */
68 #define be_emit_cstring(env, str) { be_emit_string_len(env, str, sizeof(str)-1); }
69
70 /**
71  * Initializes an emitter environment.
72  *
73  * @param env  the (uninitialized) emitter environment
74  * @param F    a file handle where the emitted file is written to.
75  */
76 void be_emit_init_env(be_emit_env_t *env, FILE *F);
77
78 /**
79  * Destroys the given emitter environment.
80  *
81  * @param env  the emitter environment
82  */
83 void be_emit_destroy_env(be_emit_env_t *env);
84
85 /**
86  * Emit an ident to the (assembler) output.
87  *
88  * @param env  the emitter environment
89  * @param id   the ident to be emitted
90  */
91 void be_emit_ident(be_emit_env_t *env, ident *id);
92
93 /**
94  * Emit the output of an ir_printf.
95  *
96  * @param env  the emitter environment
97  * @param fmt  the ir_printf format
98  */
99 void be_emit_irprintf(be_emit_env_t *env, const char *fmt, ...);
100
101 /**
102  * Emit the output of an ir_vprintf.
103  *
104  * @param env  the emitter environment
105  * @param fmt  the ir_printf format
106  */
107 void be_emit_irvprintf(be_emit_env_t *env, const char *fmt, va_list args);
108
109 /**
110  * Flush the line in the current line buffer to the emitter file.
111  *
112  * @param env  the emitter environment
113  */
114 void be_emit_write_line(be_emit_env_t *env);
115
116 /**
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
119  *
120  * @param env   the emitter environment
121  * @param node  the node to get the debug info from
122  */
123 void be_emit_finish_line_gas(be_emit_env_t *env, const ir_node *node);
124
125 /**
126  * Emit spaces until the comment position is reached.
127  *
128  * @param env  the emitter environment
129  */
130 void be_emit_pad_comment(be_emit_env_t *env);
131
132 #endif /* FIRM_BE_BEEMITTER_H */