Changed dumping modes from positive to negativ list. This allows unknown
[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 #define RFLCT_ARG_IS_A(arg,modes) (((arg)->accepted_modes & modes) != 0)
66 #define RFLCT_ARG_VALID(arg) ((arg)->name != NULL)
67 #define RFLCT_SIG_VALID(sig) ((sig) != INT_MAX)
68
69 /**
70  * Get the mode class for an IR mode.
71  * @param mode An IR mode.
72  * @return The corresponding smallest reflection mode class.
73  */
74 rflct_mode_class_t rflct_get_mode_class(const ir_mode *mode);
75
76 /**
77  * Get the number of signatures for a Firm opcode.
78  * @param opc The opcode.
79  * @return The number of signatures for this opcode.
80  */
81 int rflct_get_signature_count(opcode opc);
82
83 /**
84  * Try to get the signature, that matches to a given instance
85  * of a Firm node.
86  * @param irn The node.
87  * @return The first matching signature or -1, if no signature matches.
88  */
89 int rflct_get_signature(ir_node *irn);
90
91 /**
92  * Get the number of in arguments.
93  * An in argument is a use of a value.
94  * @param opc The opcode.
95  * @param sig The signature you are refering to.
96  * @return The number of arguments.
97  */
98 int rflct_get_in_args_count(opcode opc, int sig);
99
100 /**
101  * Get the number of out arguments.
102  * An out argument is a def of a value.
103  * @param opc The opcode.
104  * @param sig The signature you are refering to.
105  * @return The number of arguments.
106  */
107 int rflct_get_out_args_count(opcode opc, int sig);
108
109 /**
110  * Get the array of use args.
111  * The array is terminated with an entry for which
112  * <code>RFLCT_ARG_VALID</code> is 0.
113  * @param opc The opcode.
114  * @param sig The signature you are referring to (Must be between
115  * 0 and the signature count).
116  * @return The array.
117  */
118 const rflct_arg_t *rflct_get_in_args(opcode opc, int sig);
119
120 /**
121  * Get the array of def args.
122  * The array is terminated with an entry for which
123  * <code>RFLCT_ARG_VALID</code> is 0.
124  * @param opc The opcode.
125  * @param sig The signature you are referring to (Must be between
126  * 0 and the signature count).
127  * @return The array.
128  */
129 const rflct_arg_t *rflct_get_out_args(opcode opc, int sig);
130
131 /**
132  * Make a string representation of a signature of an opcode.
133  * @param buf The buffer to put the string to.
134  * @param n The size of buf.
135  * @param opc The opcode.
136  * @param sig The signature.
137  * @return buf.
138  */
139 char *rflct_to_string(char *buf, int n, opcode opc, int sig);
140
141 /**
142  * Get a string representation of a mode class.
143  * @param str The buffer to put the string to.
144  * @param n The size of the buffer.
145  * @param mc The mode class.
146  * @return str.
147  */
148 char *rflct_mode_class_name(char *str, int n, rflct_mode_class_t mc);
149
150 #endif