15
15
16
16
namespace llvm {
17
17
18
- void PredicateExpander::expandTrue (formatted_raw_ostream &OS) { OS << " true" ; }
19
- void PredicateExpander::expandFalse (formatted_raw_ostream &OS) {
20
- OS << " false" ;
21
- }
18
+ void PredicateExpander::expandTrue (raw_ostream &OS) { OS << " true" ; }
19
+ void PredicateExpander::expandFalse (raw_ostream &OS) { OS << " false" ; }
22
20
23
- void PredicateExpander::expandCheckImmOperand (formatted_raw_ostream &OS,
24
- int OpIndex, int ImmVal) {
21
+ void PredicateExpander::expandCheckImmOperand (raw_ostream &OS, int OpIndex ,
22
+ int ImmVal) {
25
23
OS << " MI" << (isByRef () ? " ." : " ->" ) << " getOperand(" << OpIndex
26
24
<< " ).getImm() " << (shouldNegate () ? " != " : " == " ) << ImmVal;
27
25
}
28
26
29
- void PredicateExpander::expandCheckImmOperand (formatted_raw_ostream &OS,
30
- int OpIndex, StringRef ImmVal) {
27
+ void PredicateExpander::expandCheckImmOperand (raw_ostream &OS, int OpIndex ,
28
+ StringRef ImmVal) {
31
29
OS << " MI" << (isByRef () ? " ." : " ->" ) << " getOperand(" << OpIndex
32
30
<< " ).getImm() " << (shouldNegate () ? " != " : " == " ) << ImmVal;
33
31
}
34
32
35
- void PredicateExpander::expandCheckRegOperand (formatted_raw_ostream &OS,
36
- int OpIndex, const Record *Reg) {
33
+ void PredicateExpander::expandCheckRegOperand (raw_ostream &OS, int OpIndex ,
34
+ const Record *Reg) {
37
35
assert (Reg->isSubClassOf (" Register" ) && " Expected a register Record!" );
38
36
39
37
OS << " MI" << (isByRef () ? " ." : " ->" ) << " getOperand(" << OpIndex
@@ -44,33 +42,31 @@ void PredicateExpander::expandCheckRegOperand(formatted_raw_ostream &OS,
44
42
OS << Reg->getName ();
45
43
}
46
44
47
- void PredicateExpander::expandCheckInvalidRegOperand (formatted_raw_ostream &OS,
45
+ void PredicateExpander::expandCheckInvalidRegOperand (raw_ostream &OS,
48
46
int OpIndex) {
49
47
OS << " MI" << (isByRef () ? " ." : " ->" ) << " getOperand(" << OpIndex
50
48
<< " ).getReg() " << (shouldNegate () ? " != " : " == " ) << " 0" ;
51
49
}
52
50
53
- void PredicateExpander::expandCheckSameRegOperand (formatted_raw_ostream &OS,
54
- int First, int Second) {
51
+ void PredicateExpander::expandCheckSameRegOperand (raw_ostream &OS, int First ,
52
+ int Second) {
55
53
OS << " MI" << (isByRef () ? " ." : " ->" ) << " getOperand(" << First
56
54
<< " ).getReg() " << (shouldNegate () ? " !=" : " ==" ) << " MI"
57
55
<< (isByRef () ? " ." : " ->" ) << " getOperand(" << Second << " ).getReg()" ;
58
56
}
59
57
60
- void PredicateExpander::expandCheckNumOperands (formatted_raw_ostream &OS,
61
- int NumOps) {
58
+ void PredicateExpander::expandCheckNumOperands (raw_ostream &OS, int NumOps) {
62
59
OS << " MI" << (isByRef () ? " ." : " ->" ) << " getNumOperands() "
63
60
<< (shouldNegate () ? " != " : " == " ) << NumOps;
64
61
}
65
62
66
- void PredicateExpander::expandCheckOpcode (formatted_raw_ostream &OS,
67
- const Record *Inst) {
63
+ void PredicateExpander::expandCheckOpcode (raw_ostream &OS, const Record *Inst) {
68
64
OS << " MI" << (isByRef () ? " ." : " ->" ) << " getOpcode() "
69
65
<< (shouldNegate () ? " != " : " == " ) << Inst->getValueAsString (" Namespace" )
70
66
<< " ::" << Inst->getName ();
71
67
}
72
68
73
- void PredicateExpander::expandCheckOpcode (formatted_raw_ostream &OS,
69
+ void PredicateExpander::expandCheckOpcode (raw_ostream &OS,
74
70
const RecVec &Opcodes) {
75
71
assert (!Opcodes.empty () && " Expected at least one opcode to check!" );
76
72
bool First = true ;
@@ -86,7 +82,7 @@ void PredicateExpander::expandCheckOpcode(formatted_raw_ostream &OS,
86
82
increaseIndentLevel ();
87
83
for (const Record *Rec : Opcodes) {
88
84
OS << ' \n ' ;
89
- OS.PadToColumn (getIndentLevel () * 2 );
85
+ OS.indent (getIndentLevel () * 2 );
90
86
if (!First)
91
87
OS << (shouldNegate () ? " && " : " || " );
92
88
@@ -96,19 +92,19 @@ void PredicateExpander::expandCheckOpcode(formatted_raw_ostream &OS,
96
92
97
93
OS << ' \n ' ;
98
94
decreaseIndentLevel ();
99
- OS.PadToColumn (getIndentLevel () * 2 );
95
+ OS.indent (getIndentLevel () * 2 );
100
96
OS << ' )' ;
101
97
}
102
98
103
- void PredicateExpander::expandCheckPseudo (formatted_raw_ostream &OS,
99
+ void PredicateExpander::expandCheckPseudo (raw_ostream &OS,
104
100
const RecVec &Opcodes) {
105
101
if (shouldExpandForMC ())
106
102
expandFalse (OS);
107
103
else
108
104
expandCheckOpcode (OS, Opcodes);
109
105
}
110
106
111
- void PredicateExpander::expandPredicateSequence (formatted_raw_ostream &OS,
107
+ void PredicateExpander::expandPredicateSequence (raw_ostream &OS,
112
108
const RecVec &Sequence,
113
109
bool IsCheckAll) {
114
110
assert (!Sequence.empty () && " Found an invalid empty predicate set!" );
@@ -124,20 +120,20 @@ void PredicateExpander::expandPredicateSequence(formatted_raw_ostream &OS,
124
120
setNegatePredicate (false );
125
121
for (const Record *Rec : Sequence) {
126
122
OS << ' \n ' ;
127
- OS.PadToColumn (getIndentLevel () * 2 );
123
+ OS.indent (getIndentLevel () * 2 );
128
124
if (!First)
129
125
OS << (IsCheckAll ? " && " : " || " );
130
126
expandPredicate (OS, Rec);
131
127
First = false ;
132
128
}
133
129
OS << ' \n ' ;
134
130
decreaseIndentLevel ();
135
- OS.PadToColumn (getIndentLevel () * 2 );
131
+ OS.indent (getIndentLevel () * 2 );
136
132
OS << ' )' ;
137
133
setNegatePredicate (OldValue);
138
134
}
139
135
140
- void PredicateExpander::expandTIIFunctionCall (formatted_raw_ostream &OS,
136
+ void PredicateExpander::expandTIIFunctionCall (raw_ostream &OS,
141
137
StringRef TargetName,
142
138
StringRef MethodName) {
143
139
OS << (shouldNegate () ? " !" : " " );
@@ -149,85 +145,88 @@ void PredicateExpander::expandTIIFunctionCall(formatted_raw_ostream &OS,
149
145
OS << MethodName << (isByRef () ? " (MI)" : " (*MI)" );
150
146
}
151
147
152
- void PredicateExpander::expandCheckIsRegOperand (formatted_raw_ostream &OS,
153
- int OpIndex) {
148
+ void PredicateExpander::expandCheckIsRegOperand (raw_ostream &OS, int OpIndex) {
154
149
OS << (shouldNegate () ? " !" : " " ) << " MI" << (isByRef () ? " ." : " ->" )
155
150
<< " getOperand(" << OpIndex << " ).isReg() " ;
156
151
}
157
152
158
- void PredicateExpander::expandCheckIsImmOperand (formatted_raw_ostream &OS,
159
- int OpIndex) {
153
+ void PredicateExpander::expandCheckIsImmOperand (raw_ostream &OS, int OpIndex) {
160
154
OS << (shouldNegate () ? " !" : " " ) << " MI" << (isByRef () ? " ." : " ->" )
161
155
<< " getOperand(" << OpIndex << " ).isImm() " ;
162
156
}
163
157
164
- void PredicateExpander::expandCheckFunctionPredicate (formatted_raw_ostream &OS,
158
+ void PredicateExpander::expandCheckFunctionPredicate (raw_ostream &OS,
165
159
StringRef MCInstFn,
166
160
StringRef MachineInstrFn) {
167
161
OS << (shouldExpandForMC () ? MCInstFn : MachineInstrFn)
168
162
<< (isByRef () ? " (MI)" : " (*MI)" );
169
163
}
170
164
171
- void PredicateExpander::expandCheckNonPortable (formatted_raw_ostream &OS,
165
+ void PredicateExpander::expandCheckNonPortable (raw_ostream &OS,
172
166
StringRef Code) {
173
167
if (shouldExpandForMC ())
174
168
return expandFalse (OS);
175
169
176
170
OS << ' (' << Code << ' )' ;
177
171
}
178
172
179
- void PredicateExpander::expandReturnStatement (formatted_raw_ostream &OS,
173
+ void PredicateExpander::expandReturnStatement (raw_ostream &OS,
180
174
const Record *Rec) {
181
- OS << " return " ;
182
- expandPredicate (OS, Rec);
183
- OS << " ;" ;
175
+ std::string Buffer;
176
+ raw_string_ostream SS (Buffer);
177
+
178
+ SS << " return " ;
179
+ expandPredicate (SS, Rec);
180
+ SS << " ;" ;
181
+ SS.flush ();
182
+ OS << Buffer;
184
183
}
185
184
186
- void PredicateExpander::expandOpcodeSwitchCase (formatted_raw_ostream &OS,
185
+ void PredicateExpander::expandOpcodeSwitchCase (raw_ostream &OS,
187
186
const Record *Rec) {
188
187
const RecVec &Opcodes = Rec->getValueAsListOfDefs (" Opcodes" );
189
188
for (const Record *Opcode : Opcodes) {
190
- OS.PadToColumn (getIndentLevel () * 2 );
189
+ OS.indent (getIndentLevel () * 2 );
191
190
OS << " case " << Opcode->getValueAsString (" Namespace" )
192
191
<< " ::" << Opcode->getName () << " :\n " ;
193
192
}
194
193
195
194
increaseIndentLevel ();
195
+ OS.indent (getIndentLevel () * 2 );
196
196
expandStatement (OS, Rec->getValueAsDef (" CaseStmt" ));
197
197
decreaseIndentLevel ();
198
198
}
199
199
200
- void PredicateExpander::expandOpcodeSwitchStatement (formatted_raw_ostream &OS,
200
+ void PredicateExpander::expandOpcodeSwitchStatement (raw_ostream &OS,
201
201
const RecVec &Cases,
202
202
const Record *Default) {
203
- OS << " switch(MI" << (isByRef () ? " ." : " ->" ) << " getOpcode()) {\n " ;
203
+ std::string Buffer;
204
+ raw_string_ostream SS (Buffer);
204
205
206
+ SS << " switch(MI" << (isByRef () ? " ." : " ->" ) << " getOpcode()) {\n " ;
205
207
for (const Record *Rec : Cases) {
206
- expandOpcodeSwitchCase (OS , Rec);
207
- OS << ' \n ' ;
208
+ expandOpcodeSwitchCase (SS , Rec);
209
+ SS << ' \n ' ;
208
210
}
209
211
210
- unsigned ColNum = getIndentLevel () * 2 ;
211
- OS.PadToColumn (ColNum);
212
-
213
212
// Expand the default case.
214
- OS << " default :\n " ;
213
+ SS.indent (getIndentLevel () * 2 );
214
+ SS << " default :\n " ;
215
+
215
216
increaseIndentLevel ();
216
- expandStatement (OS, Default);
217
+ SS.indent (getIndentLevel () * 2 );
218
+ expandStatement (SS, Default);
217
219
decreaseIndentLevel ();
218
- OS << ' \n ' ;
220
+ SS << ' \n ' ;
219
221
220
- OS.PadToColumn (ColNum);
221
- OS << " } // end of switch-stmt" ;
222
+ SS.indent (getIndentLevel () * 2 );
223
+ SS << " } // end of switch-stmt" ;
224
+ SS.flush ();
225
+ OS << Buffer;
222
226
}
223
227
224
- void PredicateExpander::expandStatement (formatted_raw_ostream &OS,
225
- const Record *Rec) {
226
- OS.flush ();
227
- unsigned ColNum = getIndentLevel () * 2 ;
228
- if (OS.getColumn () < ColNum)
229
- OS.PadToColumn (ColNum);
230
-
228
+ void PredicateExpander::expandStatement (raw_ostream &OS, const Record *Rec) {
229
+ // Assume that padding has been added by the caller.
231
230
if (Rec->isSubClassOf (" MCOpcodeSwitchStatement" )) {
232
231
expandOpcodeSwitchStatement (OS, Rec->getValueAsListOfDefs (" Cases" ),
233
232
Rec->getValueAsDef (" DefaultCase" ));
@@ -242,13 +241,8 @@ void PredicateExpander::expandStatement(formatted_raw_ostream &OS,
242
241
llvm_unreachable (" No known rules to expand this MCStatement" );
243
242
}
244
243
245
- void PredicateExpander::expandPredicate (formatted_raw_ostream &OS,
246
- const Record *Rec) {
247
- OS.flush ();
248
- unsigned ColNum = getIndentLevel () * 2 ;
249
- if (OS.getColumn () < ColNum)
250
- OS.PadToColumn (ColNum);
251
-
244
+ void PredicateExpander::expandPredicate (raw_ostream &OS, const Record *Rec) {
245
+ // Assume that padding has been added by the caller.
252
246
if (Rec->isSubClassOf (" MCTrue" )) {
253
247
if (shouldNegate ())
254
248
return expandFalse (OS);
0 commit comments