refactored immediates:
[libfirm] / ir / be / arm / arm_nodes_attr.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   declarations for ARM node attributes
23  * @author  Oliver Richter, Tobias Gneist, Michael Beck
24  * @version $Id$
25  */
26 #ifndef FIRM_BE_ARM_ARM_NODES_ATTR_H
27 #define FIRM_BE_ARM_ARM_NODES_ATTR_H
28
29 #include "firm_types.h"
30 #include "irnode_t.h"
31 #include "../bearch_t.h"
32
33 /**
34  * Possible ARM register shift types.
35  */
36 typedef enum _arm_shift_modifier {
37         ARM_SHF_NONE = 0,   /**< no shift */
38         ARM_SHF_IMM  = 1,   /**< immediate operand with implicit ROR */
39         ARM_SHF_ASR  = 2,   /**< arithmetic shift right */
40         ARM_SHF_LSL  = 3,   /**< logical shift left */
41         ARM_SHF_LSR  = 4,   /**< logical shift right */
42         ARM_SHF_ROR  = 5,   /**< rotate right */
43         ARM_SHF_RRX  = 6,   /**< rotate with sign extend */
44 } arm_shift_modifier;
45
46 /** True, if the modifier implies a shift argument */
47 #define ARM_HAS_SHIFT(mod)          ((mod) > ARM_SHF_IMM)
48
49 /** get the shift modifier from flags */
50 #define ARM_GET_SHF_MOD(attr)       ((attr)->instr_fl & 7)
51
52 /** set the shift modifier to flags */
53 #define ARM_SET_SHF_MOD(attr, mod)  ((attr)->instr_fl = (((attr)->instr_fl & ~7) | (mod)))
54
55 /** fpa immediate bit */
56 #define ARM_FPA_IMM  (1 << 3)   /**< fpa floating point immediate */
57
58 #define ARM_GET_FPA_IMM(attr)        ((attr)->instr_fl & ARM_FPA_IMM)
59 #define ARM_SET_FPA_IMM(attr)        ((attr)->instr_fl |= ARM_FPA_IMM)
60 #define ARM_CLR_FPA_IMM(attr)        ((attr)->instr_fl &= ~ARM_FPA_IMM)
61
62 /**
63  * Possible ARM condition codes.
64  */
65 typedef enum _arm_condition {
66         ARM_COND_EQ = 0,   /**< Equal, Z set. */
67         ARM_COND_NE = 1,   /**< Not Equal, Z clear */
68         ARM_COND_CS = 2,   /**< Carry set, unsigned >=, C set */
69         ARM_COND_CC = 3,   /**< Carry clear, unsigned <, C clear */
70         ARM_COND_MI = 4,   /**< Minus/Negative, N set */
71         ARM_COND_PL = 5,   /**< Plus/Positive or Zero, N clear */
72         ARM_COND_VS = 6,   /**< Overflow, V set */
73         ARM_COND_VC = 7,   /**< No overflow, V clear */
74         ARM_COND_HI = 8,   /**< unsigned >, C set and Z clear */
75         ARM_COND_LS = 9,   /**< unsigned <=, C clear or Z set */
76         ARM_COND_GE = 10,  /**< signed >=, N == V */
77         ARM_COND_LT = 11,  /**< signed <, N != V */
78         ARM_COND_GT = 12,  /**< signed >, Z clear and N == V */
79         ARM_COND_LE = 13,  /**< signed <=, Z set or N != V */
80         ARM_COND_AL = 14,  /**< Always (unconditional) */
81         ARM_COND_NV = 15   /**< forbidden */
82 } arm_condition;
83
84 /** Get the condition code from flags */
85 #define ARM_GET_COND(attr)        (((attr)->instr_fl >> 4) & 15)
86
87 /** Set the condition code to flags */
88 #define ARM_SET_COND(attr, code)  ((attr)->instr_fl = (((attr)->instr_fl & ~(15 << 4)) | ((code) << 4)))
89
90 /** Encoding for fpa immediates */
91 enum fpa_immediates {
92         fpa_null = 0,
93         fpa_one,
94         fpa_two,
95         fpa_three,
96         fpa_four,
97         fpa_five,
98         fpa_ten,
99         fpa_half,
100         fpa_max
101 };
102
103 /** Generic ARM node attributes. */
104 typedef struct _arm_attr_t {
105         except_attr      exc;                /**< the exception attribute. MUST be the first one. */
106         arch_irn_flags_t flags;              /**< indicating if spillable, rematerializeable ... etc. */
107
108         const arch_register_req_t **in_req;  /**< register requirements for arguments */
109         const arch_register_req_t **out_req; /**< register requirements for results */
110
111         ir_mode  *op_mode;                   /**< operation mode if different from node's mode */
112         unsigned instr_fl;                   /**< condition code, shift modifier */
113         long     imm_value;                  /**< immediate */
114         int      *out_flags;                 /**< flags for each produced value */
115
116         const arch_register_t **slots;       /**< register slots for assigned registers */
117 } arm_attr_t;
118
119 /** Attributes for a SymConst */
120 typedef struct _arm_SymConst_attr_t {
121         arm_attr_t  attr;                   /**< base attributes */
122         ident       *symconst_id;           /**< for SymConsts: its ident */
123 } arm_SymConst_attr_t;
124
125 /** Attributes for a CondJmp */
126 typedef struct _arm_CondJmp_attr_t {
127         arm_attr_t  attr;                   /**< base attributes */
128         int         proj_num;
129 } arm_CondJmp_attr_t;
130
131 /** Attributes for a SwitchJmp */
132 typedef struct _arm_SwitchJmp_attr_t {
133         arm_attr_t  attr;                   /**< base attributes */
134         int         n_projs;
135         long        default_proj_num;
136 } arm_SwitchJmp_attr_t;
137
138 /** Attributes for a fpaConst */
139 typedef struct _arm_fpaConst_attr_t {
140         arm_attr_t  attr;                   /**< base attributes */
141         tarval      *tv;                    /**< the tarval representing the FP const */
142 } arm_fpaConst_attr_t;
143
144 /**
145  * Returns the shift modifier string.
146  */
147 const char *arm_shf_mod_name(arm_shift_modifier mod);
148
149 /**
150  * Return the fpa immediate from the encoding.
151  */
152 const char *arm_get_fpa_imm_name(long imm_value);
153
154 #define CAST_ARM_ATTR(type,ptr)        ((type *)(ptr))
155 #define CONST_CAST_ARM_ATTR(type,ptr)  ((const type *)(ptr))
156
157 #endif