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
37 /* don't use the following vars directly, they're only here for the inlines */
38 extern FILE *emit_file;
39 extern struct obstack emit_obst;
40
41 /**
42 * Emit a character to the (assembler) output.
43 */
be_emit_char(char c)44 static inline void be_emit_char(char c)
45 {
46 obstack_1grow(&emit_obst, c);
47 }
48
49 /**
50 * Emit a string to the (assembler) output.
51 *
52 * @param str the string
53 * @param l the length of the given string
54 */
be_emit_string_len(const char * str,size_t l)55 static inline void be_emit_string_len(const char *str, size_t l)
56 {
57 obstack_grow(&emit_obst, str, l);
58 }
59
60 /**
61 * Emit a null-terminated string to the (assembler) output.
62 *
63 * @param str the null-terminated string
64 */
be_emit_string(const char * str)65 static inline void be_emit_string(const char *str)
66 {
67 size_t len = strlen(str);
68 be_emit_string_len(str, len);
69 }
70
71 /**
72 * Emit a C string-constant to the (assembler) output.
73 *
74 * @param str the null-terminated string constant
75 */
76 #define be_emit_cstring(str) \
77 be_emit_string_len(str, sizeof(str) - 1)
78
79 /**
80 * Initializes an emitter environment.
81 *
82 * @param F a file handle where the emitted file is written to.
83 */
84 void be_emit_init(FILE *F);
85
86 /**
87 * Destroys the given emitter environment.
88 */
89 void be_emit_exit(void);
90
91 /**
92 * Emit the output of an ir_printf.
93 *
94 * @param fmt the ir_printf format
95 */
96 void be_emit_irprintf(const char *fmt, ...);
97
98 /**
99 * Emit the output of an ir_vprintf.
100 *
101 * @param fmt the ir_printf format
102 */
103 void be_emit_irvprintf(const char *fmt, va_list args);
104
105 /**
106 * Flush the line in the current line buffer to the emitter file.
107 */
108 void be_emit_write_line(void);
109
110 /**
111 * Flush the line in the current line buffer to the emitter file and
112 * appends a gas-style comment with the node number and writes the line
113 *
114 * @param node the node to get the debug info from
115 */
116 void be_emit_finish_line_gas(const ir_node *node);
117
118 /**
119 * Emit spaces until the comment position is reached.
120 */
121 void be_emit_pad_comment(void);
122
123 #endif
124