f8cf44b222b7770dba21992a87a08f39c485db59
[libfirm] / ir / ir / irreflect.h
1 /**
2  * @file reflect.h
3  * @date 9.9.2004
4  * @author Sebastian Hack
5  * @brief Reflection for Firm operations.
6  *
7  * $Id$
8  */
9
10 #ifndef __REFLECT_H
11 #define __REFLECT_H
12
13 #include <limits.h>
14 #include <stdbool.h>
15
16 #include "irop.h"
17 #include "irnode.h"
18
19 #define RFLCT_MC(m) rflct_ms_ ## m
20 typedef enum {
21   RFLCT_MC(None) = 0,
22   RFLCT_MC(Mem) = 2,
23   RFLCT_MC(Bool) = 4,
24   RFLCT_MC(IntS) = 8,
25   RFLCT_MC(IntU) = 16,
26   RFLCT_MC(Float) = 32,
27   RFLCT_MC(Ref) = 64,
28   RFLCT_MC(Char) = 128,
29   RFLCT_MC(X) = 256,
30   RFLCT_MC(BB) = 512,
31   RFLCT_MC(Cf) = RFLCT_MC(X) | RFLCT_MC(BB),
32
33   RFLCT_MC(Int) = RFLCT_MC(IntS) | RFLCT_MC(IntU),
34   RFLCT_MC(Intb) = RFLCT_MC(Int) | RFLCT_MC(Bool),
35   RFLCT_MC(Num) = RFLCT_MC(Int) | RFLCT_MC(Float),
36   RFLCT_MC(NumP) = RFLCT_MC(Num) | RFLCT_MC(Ref),
37   RFLCT_MC(Data) = RFLCT_MC(NumP) | RFLCT_MC(Char),
38   RFLCT_MC(Datab) = RFLCT_MC(Data) | RFLCT_MC(Bool),
39   RFLCT_MC(DataM) = RFLCT_MC(Data) | RFLCT_MC(Mem),
40   RFLCT_MC(DataMX) = RFLCT_MC(Data) | RFLCT_MC(Mem) | RFLCT_MC(X),
41   RFLCT_MC(Lh) = RFLCT_MC(Mem) | RFLCT_MC(BB),
42
43   RFLCT_MC(Any) = -1
44
45 } rflct_mode_class_t;
46
47 typedef struct {
48   const char *name;  /**< The name of the argument (just a description). */
49
50   bool is_variadic; /**< True, if this argument can have multiple parameters. */
51   rflct_mode_class_t accepted_modes; /**< The set of accepted modes. */
52
53   int mode_equals; /**< If not variadic: You can specify the index of
54                         another argument meaning, that the mode of the
55                         operand binding at this argument must be the same
56                         as the mode of the operand binding to the argument
57                         at index. If you don't want to express such a
58                         dependency, just give -1 here.
59
60                         If variadic: If true, the modes of all
61                         variadic operands binding to this argument
62                         must be the same. If false, they can differ. */
63 } rflct_arg_t;
64
65 typedef unsigned int rflct_mode_set_t;
66
67 #define rflct_modeset_contains(mode_set,modecode) \
68   (((mode_set) & (1 << modecode)) != 0)
69
70 #define rflct_modeset_issubset(s1,s2) \
71   (((s1) & (s2)) == (s1))
72
73 #define rflct_modeset_union(s1,s2) \
74   ((s1) | (s2))
75
76 #define rflct_modeset_intersect(s1,s2) \
77   ((s1) & (s2))
78
79 #define rflct_modeset_diff(s1,s2) \
80   ((s1) & ~(s2))
81
82 #define RFLCT_ARG_VALID(arg) ((arg)->name != NULL)
83
84 /**
85  * Get the mode class for an IR mode.
86  * @param mode An IR mode.
87  * @return The corresponding smallest reflection mode class.
88  */
89 rflct_mode_class_t rflct_get_mode_class(const ir_mode *mode);
90
91 /**
92  * Get the number of signatures for a Firm opcode.
93  * @param opc The opcode.
94  * @return The number of signatures for this opcode.
95  */
96 int rflct_get_signature_count(opcode opc);
97
98 /**
99  * Try to get the signature, that matches to a given instance
100  * of a Firm node.
101  * @param irn The node.
102  * @return The first matching signature or -1, if no signature matches.
103  */
104 int rflct_get_signature(ir_node *irn);
105
106 /**
107  * Get the number of in arguments.
108  * An in argument is a use of a value.
109  * @param opc The opcode.
110  * @param sig The signature you are refering to.
111  * @return The number of arguments.
112  */
113 int rflct_get_in_args_count(opcode opc, int sig);
114
115 /**
116  * Get the number of out arguments.
117  * An out argument is a def of a value.
118  * @param opc The opcode.
119  * @param sig The signature you are refering to.
120  * @return The number of arguments.
121  */
122 int rflct_get_out_args_count(opcode opc, int sig);
123
124 /**
125  * Get the array of use args.
126  * The array is terminated with an entry for which
127  * <code>RFLCT_ARG_VALID</code> is 0.
128  * @param opc The opcode.
129  * @param sig The signature you are referring to (Must be between
130  * 0 and the signature count).
131  * @return The array.
132  */
133 const rflct_arg_t *rflct_get_in_args(opcode opc, int sig);
134
135 /**
136  * Get the array of def args.
137  * The array is terminated with an entry for which
138  * <code>RFLCT_ARG_VALID</code> is 0.
139  * @param opc The opcode.
140  * @param sig The signature you are referring to (Must be between
141  * 0 and the signature count).
142  * @return The array.
143  */
144 const rflct_arg_t *rflct_get_out_args(opcode opc, int sig);
145
146 char *rflct_to_string(char *buf, int n, opcode opc, int sig);
147
148 char *rflct_mode_class_name(char *str, int n, rflct_mode_class_t mc);
149
150 #endif