becopyheur4: Clean up co_mst_irn_init().
[libfirm] / ir / be / beemitter.h
1 /*
2  * This file is part of libFirm.
3  * Copyright (C) 2012 University of Karlsruhe.
4  */
5
6 /**
7  * @file
8  * @brief       Interface for assembler output.
9  * @author      Matthias Braun
10  * @date        12.03.2007
11  *
12  * This is a framework for emitting data (usually the final assembly code)
13  */
14 #ifndef FIRM_BE_BEEMITTER_H
15 #define FIRM_BE_BEEMITTER_H
16
17 #include <stdio.h>
18 #include <stdarg.h>
19 #include "firm_types.h"
20 #include "obst.h"
21 #include "be.h"
22 #include "irop_t.h"
23
24 /* don't use the following vars directly, they're only here for the inlines */
25 extern FILE           *emit_file;
26 extern struct obstack  emit_obst;
27
28 /**
29  * Emit a character to the (assembler) output.
30  */
31 static inline void be_emit_char(char c)
32 {
33         obstack_1grow(&emit_obst, c);
34 }
35
36 /**
37  * Emit a string to the (assembler) output.
38  *
39  * @param str  the string
40  * @param l    the length of the given string
41  */
42 static inline void be_emit_string_len(const char *str, size_t l)
43 {
44         obstack_grow(&emit_obst, str, l);
45 }
46
47 /**
48  * Emit a null-terminated string to the (assembler) output.
49  *
50  * @param str  the null-terminated string
51  */
52 static inline void be_emit_string(const char *str)
53 {
54         size_t len = strlen(str);
55         be_emit_string_len(str, len);
56 }
57
58 /**
59  * Emit a C string-constant to the (assembler) output.
60  *
61  * @param str  the null-terminated string constant
62  */
63 #define be_emit_cstring(str) \
64         be_emit_string_len(str, sizeof(str) - 1)
65
66 /**
67  * Initializes an emitter environment.
68  *
69  * @param F    a file handle where the emitted file is written to.
70  */
71 void be_emit_init(FILE *F);
72
73 /**
74  * Destroys the given emitter environment.
75  */
76 void be_emit_exit(void);
77
78 /**
79  * Emit the output of an ir_printf.
80  *
81  * @param fmt  the ir_printf format
82  */
83 void be_emit_irprintf(const char *fmt, ...);
84
85 /**
86  * Emit the output of an ir_vprintf.
87  *
88  * @param fmt  the ir_printf format
89  */
90 void be_emit_irvprintf(const char *fmt, va_list args);
91
92 /**
93  * Flush the line in the current line buffer to the emitter file.
94  */
95 void be_emit_write_line(void);
96
97 /**
98  * Flush the line in the current line buffer to the emitter file and
99  * appends a gas-style comment with the node number and writes the line
100  *
101  * @param node  the node to get the debug info from
102  */
103 void be_emit_finish_line_gas(const ir_node *node);
104
105 /**
106  * Emit spaces until the comment position is reached.
107  */
108 void be_emit_pad_comment(void);
109
110 /**
111  * The type of a emitter function.
112  */
113 typedef void emit_func(ir_node const *node);
114
115 static inline void be_set_emitter(ir_op *const op, emit_func *const func)
116 {
117         set_generic_function_ptr(op, func);
118 }
119
120 void be_emit_nothing(ir_node const *node);
121
122 /**
123  * Emit code for a node.
124  */
125 void be_emit_node(ir_node const *node);
126
127 #endif