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