@@ -361,6 +361,22 @@ static LogicalResult printBinaryOperation(CppEmitter &emitter,
361
361
return success ();
362
362
}
363
363
364
+ static LogicalResult printUnaryOperation (CppEmitter &emitter,
365
+ Operation *operation,
366
+ StringRef unaryOperator) {
367
+ raw_ostream &os = emitter.ostream ();
368
+
369
+ if (failed (emitter.emitAssignPrefix (*operation)))
370
+ return failure ();
371
+
372
+ os << unaryOperator;
373
+
374
+ if (failed (emitter.emitOperand (operation->getOperand (0 ))))
375
+ return failure ();
376
+
377
+ return success ();
378
+ }
379
+
364
380
static LogicalResult printOperation (CppEmitter &emitter, emitc::AddOp addOp) {
365
381
Operation *operation = addOp.getOperation ();
366
382
@@ -603,17 +619,8 @@ printOperation(CppEmitter &emitter,
603
619
604
620
static LogicalResult printOperation (CppEmitter &emitter,
605
621
emitc::BitwiseNotOp bitwiseNotOp) {
606
- raw_ostream &os = emitter.ostream ();
607
-
608
- if (failed (emitter.emitAssignPrefix (*bitwiseNotOp.getOperation ())))
609
- return failure ();
610
-
611
- os << " ~" ;
612
-
613
- if (failed (emitter.emitOperand (bitwiseNotOp.getOperand ())))
614
- return failure ();
615
-
616
- return success ();
622
+ Operation *operation = bitwiseNotOp.getOperation ();
623
+ return printUnaryOperation (emitter, operation, " ~" );
617
624
}
618
625
619
626
static LogicalResult printOperation (CppEmitter &emitter,
@@ -682,17 +689,8 @@ static LogicalResult printOperation(CppEmitter &emitter,
682
689
683
690
static LogicalResult printOperation (CppEmitter &emitter,
684
691
emitc::LogicalNotOp logicalNotOp) {
685
- raw_ostream &os = emitter.ostream ();
686
-
687
- if (failed (emitter.emitAssignPrefix (*logicalNotOp.getOperation ())))
688
- return failure ();
689
-
690
- os << " !" ;
691
-
692
- if (failed (emitter.emitOperand (logicalNotOp.getOperand ())))
693
- return failure ();
694
-
695
- return success ();
692
+ Operation *operation = logicalNotOp.getOperation ();
693
+ return printUnaryOperation (emitter, operation, " !" );
696
694
}
697
695
698
696
static LogicalResult printOperation (CppEmitter &emitter,
0 commit comments