|
5 | 5 | #include "llvm/ADT/ArrayRef.h" |
6 | 6 | #include "llvm/ADT/DenseMap.h" |
7 | 7 | #include "llvm/ADT/SmallVector.h" |
| 8 | +#include "llvm/ADT/TypeSwitch.h" |
8 | 9 | #include "llvm/Support/Debug.h" |
9 | 10 | #include "llvm/Support/DebugLog.h" |
10 | 11 | #include "llvm/Support/EndianStream.h" |
@@ -101,21 +102,17 @@ class Writer { |
101 | 102 | return emitError(value.getLoc(), "undefined operand"); |
102 | 103 | } |
103 | 104 |
|
104 | | - if (auto operand = dyn_cast<dxsa::Operand>(*op)) { |
105 | | - if (failed(emitOperand(operand))) { |
106 | | - return failure(); |
107 | | - } |
108 | | - continue; |
| 105 | + auto result = |
| 106 | + llvm::TypeSwitch<Operation &, LogicalResult>(*op) |
| 107 | + .Case<dxsa::Operand>([this](auto op) { return emitOperand(op); }) |
| 108 | + .Case<dxsa::OperandImm>( |
| 109 | + [this](auto op) { return emitOperandImm(op); }) |
| 110 | + .Default([this](auto &op) { |
| 111 | + return emitError(op.getLoc(), "unexpected operand kind"); |
| 112 | + }); |
| 113 | + if (failed(result)) { |
| 114 | + return result; |
109 | 115 | } |
110 | | - |
111 | | - if (auto operand = dyn_cast<dxsa::OperandImm>(*op)) { |
112 | | - if (failed(emitOperandImm(operand))) { |
113 | | - return failure(); |
114 | | - } |
115 | | - continue; |
116 | | - } |
117 | | - |
118 | | - return emitError(op->getLoc(), "unexpected operand kind"); |
119 | 116 | } |
120 | 117 |
|
121 | 118 | // Fixup instruction length after all operands are accumulated in |
@@ -204,28 +201,20 @@ class Writer { |
204 | 201 | return emitError(value.getLoc(), "index must be defined"); |
205 | 202 | } |
206 | 203 |
|
207 | | - if (auto indexImm = dyn_cast<dxsa::IndexImm>(*index)) { |
208 | | - if (failed(emitIndexImm(indexImm))) { |
209 | | - return failure(); |
210 | | - } |
211 | | - continue; |
212 | | - } |
213 | | - |
214 | | - if (auto indexRel = dyn_cast<dxsa::IndexRel>(*index)) { |
215 | | - if (failed(emitIndexRel(indexRel))) { |
216 | | - return failure(); |
217 | | - } |
218 | | - continue; |
| 204 | + auto result = llvm::TypeSwitch<Operation &, LogicalResult>(*index) |
| 205 | + .Case<dxsa::IndexImm>( |
| 206 | + [this](auto op) { return emitIndexImm(op); }) |
| 207 | + .Case<dxsa::IndexRel>( |
| 208 | + [this](auto op) { return emitIndexRel(op); }) |
| 209 | + .Case<dxsa::IndexRelImm>( |
| 210 | + [this](auto op) { return emitIndexRelImm(op); }) |
| 211 | + .Default([this](auto &op) { |
| 212 | + return emitError(op.getLoc(), "invalid index type"); |
| 213 | + }); |
| 214 | + |
| 215 | + if (failed(result)) { |
| 216 | + return result; |
219 | 217 | } |
220 | | - |
221 | | - if (auto indexRelImm = dyn_cast<dxsa::IndexRelImm>(*index)) { |
222 | | - if (failed(emitIndexRelImm(indexRelImm))) { |
223 | | - return failure(); |
224 | | - } |
225 | | - continue; |
226 | | - } |
227 | | - |
228 | | - return emitError(value.getLoc(), "invalid index type"); |
229 | 218 | } |
230 | 219 |
|
231 | 220 | return success(); |
|
0 commit comments