cleanup: Remove pointless assert(is_${NODE}(x)) just before get_${NODE}_${FOO}(x...
[libfirm] / ir / be / beemitter.h
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  * This is a framework for emitting data (usually the final assembly code)
27  */
28 #ifndef FIRM_BE_BEEMITTER_H
29 #define FIRM_BE_BEEMITTER_H
30
31 #include <stdio.h>
32 #include <stdarg.h>
33 #include "firm_types.h"
34 #include "obst.h"
35 #include "be.h"
36 #include "irop_t.h"
37
38 /* don't use the following vars directly, they're only here for the inlines */
39 extern FILE           *emit_file;
40 extern struct obstack  emit_obst;
41
42 /**
43  * Emit a character to the (assembler) output.
44  */
45 static inline void be_emit_char(char c)
46 {
47         obstack_1grow(&emit_obst, c);
48 }
49
50 /**
51  * Emit a string to the (assembler) output.
52  *
53  * @param str  the string
54  * @param l    the length of the given string
55  */
56 static inline void be_emit_string_len(const char *str, size_t l)
57 {
58         obstack_grow(&emit_obst, str, l);
59 }
60
61 /**
62  * Emit a null-terminated string to the (assembler) output.
63  *
64  * @param str  the null-terminated string
65  */
66 static inline void be_emit_string(const char *str)
67 {
68         size_t len = strlen(str);
69         be_emit_string_len(str, len);
70 }
71
72 /**
73  * Emit a C string-constant to the (assembler) output.
74  *
75  * @param str  the null-terminated string constant
76  */
77 #define be_emit_cstring(str) \
78         be_emit_string_len(str, sizeof(str) - 1)
79
80 /**
81  * Initializes an emitter environment.
82  *
83  * @param F    a file handle where the emitted file is written to.
84  */
85 void be_emit_init(FILE *F);
86
87 /**
88  * Destroys the given emitter environment.
89  */
90 void be_emit_exit(void);
91
92 /**
93  * Emit the output of an ir_printf.
94  *
95  * @param fmt  the ir_printf format
96  */
97 void be_emit_irprintf(const char *fmt, ...);
98
99 /**
100  * Emit the output of an ir_vprintf.
101  *
102  * @param fmt  the ir_printf format
103  */
104 void be_emit_irvprintf(const char *fmt, va_list args);
105
106 /**
107  * Flush the line in the current line buffer to the emitter file.
108  */
109 void be_emit_write_line(void);
110
111 /**
112  * Flush the line in the current line buffer to the emitter file and
113  * appends a gas-style comment with the node number and writes the line
114  *
115  * @param node  the node to get the debug info from
116  */
117 void be_emit_finish_line_gas(const ir_node *node);
118
119 /**
120  * Emit spaces until the comment position is reached.
121  */
122 void be_emit_pad_comment(void);
123
124 /**
125  * The type of a emitter function.
126  */
127 typedef void emit_func(ir_node const *node);
128
129 static inline void be_set_emitter(ir_op *const op, emit_func *const func)
130 {
131         set_generic_function_ptr(op, func);
132 }
133
134 void be_emit_nothing(ir_node const *node);
135
136 /**
137  * Emit code for a node.
138  */
139 void be_emit_node(ir_node const *node);
140
141 #endif