Add magic for better code emission of 64bit minus.
[libfirm] / ir / be / beemitter.h
1 /*
2  * Copyright (C) 1995-2007 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  * @version     $Id$
26  */
27 #ifndef FIRM_BE_BEEMITTER_H
28 #define FIRM_BE_BEEMITTER_H
29
30 #include "firm_config.h"
31
32 #include <stdio.h>
33 #include <stdarg.h>
34 #include "firm_types.h"
35 #include "obst.h"
36 #include "be.h"
37
38 /* framework for emitting data (usually the final assembly code) */
39
40 /** The emitter environment. */
41 typedef struct be_emit_env_t {
42         FILE           *F;         /**< The handle of the (assembler) file that is written to. */
43         struct obstack obst;       /**< An obstack for temporary storage. */
44         int            linelength; /**< The length of the current line. */
45 } be_emit_env_t;
46
47 #define NULL_EMITTER    { NULL, NULL_OBST, 0 }
48
49 /**
50  * Emit a character to the (assembler) output.
51  *
52  * @param env  the emitter environment
53  */
54 static INLINE void be_emit_char(be_emit_env_t *env, char c) {
55         obstack_1grow(&env->obst, c);
56         env->linelength++;
57 }
58
59 /**
60  * Emit a string to the (assembler) output.
61  *
62  * @param env  the emitter environment
63  * @param str  the string
64  * @param l    the length of the given string
65  */
66 static INLINE void be_emit_string_len(be_emit_env_t *env, const char *str,
67                                       size_t l)
68 {
69         obstack_grow(&env->obst, str, l);
70         env->linelength += l;
71 }
72
73 /**
74  * Emit a null-terminated string to the (assembler) output.
75  *
76  * @param env  the emitter environment
77  * @param str  the null-terminated string
78  */
79 static INLINE void be_emit_string(be_emit_env_t *env, const char *str)
80 {
81         size_t len = strlen(str);
82         be_emit_string_len(env, str, len);
83 }
84
85 /**
86  * Emit a C string-constant to the (assembler) output.
87  *
88  * @param env  the emitter environment
89  * @param str  the null-terminated string constant
90  */
91 #define be_emit_cstring(env, str) do { be_emit_string_len(env, str, sizeof(str)-1); } while(0)
92
93 /**
94  * Initializes an emitter environment.
95  *
96  * @param env  the (uninitialized) emitter environment
97  * @param F    a file handle where the emitted file is written to.
98  */
99 void be_emit_init_env(be_emit_env_t *env, FILE *F);
100
101 /**
102  * Destroys the given emitter environment.
103  *
104  * @param env  the emitter environment
105  */
106 void be_emit_destroy_env(be_emit_env_t *env);
107
108 /**
109  * Emit an ident to the (assembler) output.
110  *
111  * @param env  the emitter environment
112  * @param id   the ident to be emitted
113  */
114 void be_emit_ident(be_emit_env_t *env, ident *id);
115
116 /**
117  * Emit a firm tarval.
118  *
119  * @param env  the emitter environment
120  * @param tv   the tarval to be emitted
121  */
122 void be_emit_tarval(be_emit_env_t *env, tarval *tv);
123
124 /**
125  * Emit the output of an ir_printf.
126  *
127  * @param env  the emitter environment
128  * @param fmt  the ir_printf format
129  */
130 void be_emit_irprintf(be_emit_env_t *env, const char *fmt, ...);
131
132 /**
133  * Emit the output of an ir_vprintf.
134  *
135  * @param env  the emitter environment
136  * @param fmt  the ir_printf format
137  */
138 void be_emit_irvprintf(be_emit_env_t *env, const char *fmt, va_list args);
139
140 /**
141  * Flush the line in the current line buffer to the emitter file.
142  *
143  * @param env  the emitter environment
144  */
145 void be_emit_write_line(be_emit_env_t *env);
146
147 /**
148  * Flush the line in the current line buffer to the emitter file and
149  * appends a gas-style comment with the node number and writes the line
150  *
151  * @param env   the emitter environment
152  * @param node  the node to get the debug info from
153  */
154 void be_emit_finish_line_gas(be_emit_env_t *env, const ir_node *node);
155
156 /**
157  * Emit spaces until the comment position is reached.
158  *
159  * @param env  the emitter environment
160  */
161 void be_emit_pad_comment(be_emit_env_t *env);
162
163 #endif /* FIRM_BE_BEEMITTER_H */