fcee39d5285f18a845cc0f9f5b0d866cde3c46f3
[libfirm] / ir / be / ia32 / ia32_emitter.h
1 /**
2  * Header file for ia32 emitter, containing some function definitions and types.
3  * @author Christian Wuerdig, Matthias Braun
4  * $Id$
5  */
6 #ifndef _IA32_EMITTER_H_
7 #define _IA32_EMITTER_H_
8
9 #include "irargs_t.h"
10 #include "irnode.h"
11 #include "debug.h"
12
13 #include "../bearch.h"
14
15 #include "bearch_ia32_t.h"
16
17 typedef struct _ia32_emit_env_t {
18         FILE                  *out;
19         const arch_env_t      *arch_env;
20         const ia32_code_gen_t *cg;
21         ia32_isa_t            *isa;
22         struct obstack        *obst;
23         int                    linelength;
24         DEBUG_ONLY(firm_dbg_module_t *mod;)
25 } ia32_emit_env_t;
26
27 static INLINE void ia32_emit_char(ia32_emit_env_t *env, char c)
28 {
29         obstack_1grow(env->obst, c);
30         env->linelength++;
31 }
32
33 static INLINE void ia32_emit_string_len(ia32_emit_env_t *env, const char *str, size_t l)
34 {
35         obstack_grow(env->obst, str, l);
36         env->linelength += l;
37 }
38
39 static INLINE void ia32_emit_string(ia32_emit_env_t *env, const char *str)
40 {
41         size_t len = strlen(str);
42         ia32_emit_string_len(env, str, len);
43 }
44
45 #define ia32_emit_cstring(env,x) { ia32_emit_string_len(env, x, sizeof(x)-1); }
46
47 void ia32_emit_source_register(ia32_emit_env_t *env, const ir_node *node, int pos);
48 void ia32_emit_dest_register(ia32_emit_env_t *env, const ir_node *node, int pos);
49 void ia32_emit_x87_name(ia32_emit_env_t *env, const ir_node *node, int pos);
50 void ia32_emit_immediate(ia32_emit_env_t *env, const ir_node *node);
51 void ia32_emit_mode_suffix(ia32_emit_env_t *env, const ir_mode *mode);
52 void ia32_emit_x87_mode_suffix(ia32_emit_env_t *env, const ir_node *node);
53 void ia32_emit_extend_suffix(ia32_emit_env_t *env, const ir_mode *mode);
54 void ia32_emit_binop(ia32_emit_env_t *env, const ir_node *node);
55 void ia32_emit_unop(ia32_emit_env_t *env, const ir_node *node);
56 void ia32_emit_am(ia32_emit_env_t *env, const ir_node *node);
57 void ia32_emit_adr(ia32_emit_env_t *env, const ir_node *node);
58 void ia32_emit_x87_binop(ia32_emit_env_t *env, const ir_node *node);
59 void ia32_emit_finish_line(ia32_emit_env_t *env, const ir_node *node);
60
61 void ia32_gen_routine(ia32_code_gen_t *cg, FILE *F, ir_graph *irg);
62
63 /**
64  * Sections.
65  */
66 typedef enum section_t {
67         NO_SECTION     = -1,  /**< no section selected yet. */
68         SECTION_TEXT   = 0,   /**< text section */
69         SECTION_DATA   = 1,   /**< data section */
70         SECTION_RODATA = 2,   /**< rodata section */
71         SECTION_COMMON = 3,   /**< common section */
72         SECTION_TLS    = 4,   /**< thread local storage section */
73         SECTION_CTOR   = 5,   /**< ctor section for instrumentation code init */
74         SECTION_MAX    = 6
75 } section_t;
76
77 /**
78  * Switch to a new section.
79  */
80 void ia32_switch_section(FILE *f, section_t sec);
81
82 typedef enum asm_flavour_t {
83         ASM_LINUX_GAS = 0,  /**< Linux gas */
84         ASM_MINGW_GAS = 1,  /**< MinGW gas */
85         ASM_MAX       = 2
86 } asm_flavour_t;
87
88 extern asm_flavour_t asm_flavour;
89
90 #endif /* _IA32_EMITTER_H_ */