1 /*
2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef CFA_RULE_H
6 #define CFA_RULE_H
7
8
9 #include "Types.h"
10
11
12 enum cfa_rule_type {
13 CFA_RULE_UNDEFINED,
14 CFA_RULE_SAME_VALUE,
15 CFA_RULE_LOCATION_OFFSET,
16 CFA_RULE_VALUE_OFFSET,
17 CFA_RULE_REGISTER,
18 CFA_RULE_LOCATION_EXPRESSION,
19 CFA_RULE_VALUE_EXPRESSION
20 };
21
22
23 enum cfa_cfa_rule_type {
24 CFA_CFA_RULE_UNDEFINED,
25 CFA_CFA_RULE_REGISTER_OFFSET,
26 CFA_CFA_RULE_EXPRESSION
27 };
28
29
30 struct CfaExpression {
31 const void* block;
32 size_t size;
33 };
34
35
36 class CfaRule {
37 public:
38 inline CfaRule();
39
Type()40 cfa_rule_type Type() const { return fType; }
41
Offset()42 int64 Offset() const { return fOffset; }
Register()43 uint32 Register() const { return fRegister; }
Expression()44 const CfaExpression& Expression() const { return fExpression; }
45
46 inline void SetToUndefined();
47 inline void SetToSameValue();
48 inline void SetToLocationOffset(int64 offset);
49 inline void SetToValueOffset(int64 offset);
50 inline void SetToRegister(uint32 reg);
51 inline void SetToLocationExpression(const void* block,
52 size_t size);
53 inline void SetToValueExpression(const void* block,
54 size_t size);
55
56 private:
57 cfa_rule_type fType;
58 union {
59 int64 fOffset;
60 uint32 fRegister;
61 CfaExpression fExpression;
62 };
63 };
64
65
66 class CfaCfaRule {
67 public:
68 inline CfaCfaRule();
69
Type()70 cfa_cfa_rule_type Type() const { return fType; }
71
Offset()72 uint64 Offset() const
73 { return fRegisterOffset.offset; }
Register()74 uint32 Register() const
75 { return fRegisterOffset.reg; }
Expression()76 const CfaExpression& Expression() const { return fExpression; }
77
78 inline void SetToUndefined();
79 inline void SetToRegisterOffset(uint32 reg, uint64 offset);
80 inline void SetToExpression(const void* block, size_t size);
81
82 inline void SetRegister(uint32 reg);
83 inline void SetOffset(uint64 offset);
84
85 private:
86 cfa_cfa_rule_type fType;
87 union {
88 struct {
89 uint64 offset;
90 uint32 reg;
91 } fRegisterOffset;
92 CfaExpression fExpression;
93 };
94 };
95
96
97 // #pragma mark - CfaRule
98
99
CfaRule()100 CfaRule::CfaRule()
101 :
102 fType(CFA_RULE_UNDEFINED)
103 {
104 }
105
106
107 void
SetToUndefined()108 CfaRule::SetToUndefined()
109 {
110 fType = CFA_RULE_UNDEFINED;
111 }
112
113
114 void
SetToSameValue()115 CfaRule::SetToSameValue()
116 {
117 fType = CFA_RULE_SAME_VALUE;
118 }
119
120
121 void
SetToLocationOffset(int64 offset)122 CfaRule::SetToLocationOffset(int64 offset)
123 {
124 fType = CFA_RULE_LOCATION_OFFSET;
125 fOffset = offset;
126 }
127
128
129 void
SetToValueOffset(int64 offset)130 CfaRule::SetToValueOffset(int64 offset)
131 {
132 fType = CFA_RULE_VALUE_OFFSET;
133 fOffset = offset;
134 }
135
136
137 void
SetToRegister(uint32 reg)138 CfaRule::SetToRegister(uint32 reg)
139 {
140 fType = CFA_RULE_REGISTER;
141 fRegister = reg;
142 }
143
144
145 void
SetToLocationExpression(const void * block,size_t size)146 CfaRule::SetToLocationExpression(const void* block, size_t size)
147 {
148 fType = CFA_RULE_LOCATION_EXPRESSION;
149 fExpression.block = block;
150 fExpression.size = size;
151 }
152
153
154 void
SetToValueExpression(const void * block,size_t size)155 CfaRule::SetToValueExpression(const void* block, size_t size)
156 {
157 fType = CFA_RULE_VALUE_EXPRESSION;
158 fExpression.block = block;
159 fExpression.size = size;
160 }
161
162
163 // #pragma mark - CfaCfaRule
164
165
CfaCfaRule()166 CfaCfaRule::CfaCfaRule()
167 :
168 fType(CFA_CFA_RULE_UNDEFINED)
169 {
170 }
171
172
173 void
SetToUndefined()174 CfaCfaRule::SetToUndefined()
175 {
176 fType = CFA_CFA_RULE_UNDEFINED;
177 }
178
179
180 void
SetToRegisterOffset(uint32 reg,uint64 offset)181 CfaCfaRule::SetToRegisterOffset(uint32 reg, uint64 offset)
182 {
183 fType = CFA_CFA_RULE_REGISTER_OFFSET;
184 fRegisterOffset.reg = reg;
185 fRegisterOffset.offset = offset;
186 }
187
188
189 void
SetToExpression(const void * block,size_t size)190 CfaCfaRule::SetToExpression(const void* block, size_t size)
191 {
192 fType = CFA_CFA_RULE_EXPRESSION;
193 fExpression.block = block;
194 fExpression.size = size;
195 }
196
197
198 void
SetRegister(uint32 reg)199 CfaCfaRule::SetRegister(uint32 reg)
200 {
201 fRegisterOffset.reg = reg;
202 }
203
204
205 void
SetOffset(uint64 offset)206 CfaCfaRule::SetOffset(uint64 offset)
207 {
208 fRegisterOffset.offset = offset;
209 }
210
211
212 #endif // CFA_RULE_H
213