[Mlir-commits] [mlir] [mlir][emitc] Add 'emitc.switch' op to the dialect (PR #102331)
Simon Camphausen
llvmlistbot at llvm.org
Mon Aug 12 04:00:46 PDT 2024
================
@@ -449,6 +449,43 @@ static LogicalResult printOperation(CppEmitter &emitter, emitc::SubOp subOp) {
return printBinaryOperation(emitter, operation, "-");
}
+static LogicalResult emitSwitchCase(CppEmitter &emitter,
+ raw_indented_ostream &os, Region ®ion) {
+ for (Region::OpIterator iteratorOp = region.op_begin(), end = region.op_end();
+ std::next(iteratorOp) != end; ++iteratorOp) {
+ if (failed(emitter.emitOperation(*iteratorOp, /*trailingSemicolon=*/true)))
+ return failure();
+ }
+ os << "break;\n";
+ return success();
+}
+
+static LogicalResult printOperation(CppEmitter &emitter,
+ emitc::SwitchOp switchOp) {
+ raw_indented_ostream &os = emitter.ostream();
+
+ os << "\nswitch (" << emitter.getOrCreateName(switchOp.getArg()) << ") {";
+
+ for (auto pair : llvm::zip(switchOp.getCases(), switchOp.getCaseRegions())) {
+ os << "\ncase (" << std::get<0>(pair) << "): {\n";
----------------
simon-camp wrote:
Do we want to have parentheses around the cases?
https://github.com/llvm/llvm-project/pull/102331
More information about the Mlir-commits
mailing list