-
Notifications
You must be signed in to change notification settings - Fork 0
/
pattern.hh
executable file
·236 lines (200 loc) · 7.47 KB
/
pattern.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/*--------------------------------------------------------------------------- *
* srtl implementation in c++ *
* *
* This file contains class header definitions for abstract pattern class *
* *
* *
* *
* Change History *
* -------------------------------------------------------------------------- *
* Name Date Change Description *
* Sheweta 14-Aug-13 Initial Version *
* *
*--------------------------------------------------------------------------- */
#ifndef __PATTERN_H_INCLUDED__
#define __PATTERN_H_INCLUDED__
#include <string>
#include <vector>
#include <map>
#include <string>
#include <iostream>
/**
* Operands can be of # types. The number below represents the
* value of the type member variable of Operand of the respective
* operand object.
* 1. PMC Spec :- Has a predicate, mode and a constraint.
* 2. Dup Num Spec :- Is a match_dup.
* 3. Num Spec :-
* 4. Reg Spec :-
* 5. Reg Num Spec :-
* 6. Extra Reg Spec :- pc, cc0, scratch, return, eh_return
* 7. Const Spec :- const_int
* 8. Scratch Spec :- match_scratch
* 9. eq_attr :- For use in secondary tree patterns.
* 10.match_operator :- (match_operator 1 asdasd [Operands])
* 11.fixed_reg :- [A-Z]*[0-9]*_REG
* 12. integer :- <0> - 0
* 13. string :- <UNSPEC_XXX>
**/
/*
* Consider chaning member variable names to name1, name2, name3
* instead of predicate, mode or constraint, to make this class more generic to
* other operand types.
*/
class Operand {
public:
enum Type {pmc, dup, num, reg, regNum, extraReg, constSpec,
scratch, eqAttr, matchOperator, fixedReg, integer, string,
bracketOpen, bracketClose};
private:
Type type;
int operandNumber;
unsigned long int number;
std::string predicate;
std::string mode;
std::string constraint;
std::string misc; /* PlaceHolder for fixed_reg / Const */
// bool bClose;
public:
Operand (Type t, int n, std::string p, std::string m, std::string c);
Operand (Type t, std::string p, std::string m, std::string c);
Operand (Type t, unsigned long int n);
Operand (Type t, int n, std::string p_m, std::string c);
Operand (Type t, int n, std::string p_m);
Operand (Type t, std::string p_m, std::string c);
Operand (Type t, std::string p_m);
Operand () {}
~Operand ();
std::string getOperand ();
Type getType () { return type; }
std::string getMode () { return mode; }
std::string getPredicate () { return predicate; }
std::string getConstraint () { return constraint; }
void setMode (std::string m) { mode = m; }
void setPredicate (std::string p) { predicate = p; }
void setConstraint (std::string c) { constraint = c; }
void setType (Type t) { type = t; }
/* bool getBClose () { return bClose; }
void setBClose (bool _bClose) {
bClose = _bClose;
}
*/ int getOperandNumber () { return operandNumber; }
void setOperandNumber (int o) { operandNumber = o; }
unsigned long int getNumber () { return number; }
void setNumber (unsigned long int n) { number = n; }
};
class ModeStmt {
private:
std::vector <int> accessTree;
std::string predicateOrMode;
std::string patternName;
std::string modeReplacement;
std::vector <std::string> constraintsVector;
Operand op;
public:
enum Type {root, latency, listOfValues, docstring, regclass, mode
, predicate, constraint, operand, allConstraints, replaceMode, pmc};
~ModeStmt () {
}
void addAccessTree (std::vector<int>* at);
void setMode (std::string mode);
void setPatternName (std::string name) {
patternName = name;
}
std::string getPatternName (){
return patternName;
}
std::vector<int>* getAccessTree () {
return &accessTree; }
std::string getMode () {
return predicateOrMode;
}
void setType (Type t) {
type = t;
}
Type getType () {
return type;
}
Operand getOperand () {
return op;
}
void setOperand (std::string p, std::string m, std::string c) {
op.setPredicate (p);
op.setMode (m);
op.setConstraint (c);
op.setType (Operand::pmc);
}
void setOperand (int opNumber, std::string p, std::string m, std::string c) {
op.setPredicate (p);
op.setMode (m);
op.setConstraint (c);
op.setType (Operand::pmc);
op.setOperandNumber (opNumber);
std::cout << opNumber << std::endl;
}
void setOperand (Operand o) {
op = o;
}
void setConstraints (std::vector<std::string>* c) {
constraintsVector = *c;
}
std::string getConstraint (unsigned int i) {
if (i >= constraintsVector.size ()) {
return "";
}
return constraintsVector[i];
}
void setModeReplacement (std::string mr) {
modeReplacement = mr;
}
std::string getModeReplacement () {
return modeReplacement;
}
private:
Type type;
};
class Pattern {
public:
enum Type {abstract, insn, exp, insnAndSplit, split, peep2, insnReservation,
predicate, specialPredicate, attr, asmAttr, cons, regCons, memCons, addCons,
define_code_iterator, define_mode_iterator,define_code_attr,define_mode_attr,
define_constants,define_c_enum,define_asm_attributes,define_reservation,
define_cpu_unit,define_automaton,define_bypass
};
enum SubType {extends, instantiates, overrides};
virtual std::string getPatName()=0;
virtual void setPatName(std::string V)=0;
virtual void setPatType (Type pt) = 0;
virtual Type getPatType () = 0;
virtual void createPattern () {}
virtual void createPatternOut () {}
virtual bool inError () = 0;
virtual void setError () = 0;
virtual void setParentPattern (Pattern* ) {};
virtual Pattern* getParentPattern () { return 0; }
virtual void setSubType (SubType st) { subType = st; }
virtual void setSubTypeOut (SubType st) {}
virtual SubType getSubType () { return subType; }
// TODO
virtual SubType getSubTypeOut () { return subType; }
void setLineStart(int line){
lineStart = line;
}
int getLineStart(){
return lineStart;
}
void setLineEnd(int line){
lineEnd = line;
}
int getLineEnd(){
return lineEnd;
}
virtual ~Pattern () {}
protected:
Type type;
SubType subType;
private:
int lineStart;
int lineEnd;
};
#endif