[Mlir-commits] [mlir] [mlir][emitc][cf] add 'cf.switch' support in CppEmitter (PR #101478)

Andrey Timonin llvmlistbot at llvm.org
Thu Aug 1 06:10:36 PDT 2024


================
@@ -774,6 +774,41 @@ static LogicalResult printOperation(CppEmitter &emitter,
   return printBinaryOperation(emitter, operation, "||");
 }
 
+static LogicalResult printOperation(CppEmitter &emitter,
+                                    cf::SwitchOp switchOp) {
+  raw_indented_ostream &os = emitter.ostream();
+  auto iteratorCaseValues = (*switchOp.getCaseValues()).begin();
+  auto iteratorCaseValuesEnd = (*switchOp.getCaseValues()).end();
+
+  os << "\nswitch(" << emitter.getOrCreateName(switchOp.getFlag()) << ") {";
+
+  for (const auto caseBlock : switchOp.getCaseDestinations()) {
+    if (iteratorCaseValues == iteratorCaseValuesEnd)
+      return switchOp.emitOpError("case's value is absent for case block");
+
+    os << "\ncase " << *(iteratorCaseValues++) << ": {\n";
+    os.indent() << "goto ";
----------------
EtoAndruwa wrote:

I will fix the test right now too. Missed it.

https://github.com/llvm/llvm-project/pull/101478


More information about the Mlir-commits mailing list