@@ -997,6 +997,47 @@ static LogicalResult printOperation(CppEmitter &emitter, ModuleOp moduleOp) {
997
997
return success ();
998
998
}
999
999
1000
+ static LogicalResult printOperation (CppEmitter &emitter, ClassOp classOp) {
1001
+ CppEmitter::Scope classScope (emitter);
1002
+ raw_indented_ostream &os = emitter.ostream ();
1003
+ os << " class " << classOp.getSymName () << " {\n " ;
1004
+ os << " public:\n " ;
1005
+ os.indent ();
1006
+
1007
+ for (Operation &op : classOp) {
1008
+ if (failed (emitter.emitOperation (op, /* trailingSemicolon=*/ false )))
1009
+ return failure ();
1010
+ }
1011
+
1012
+ os.unindent ();
1013
+ os << " };" ;
1014
+ return success ();
1015
+ }
1016
+
1017
+ static LogicalResult printOperation (CppEmitter &emitter, FieldOp fieldOp) {
1018
+ raw_ostream &os = emitter.ostream ();
1019
+ if (failed (emitter.emitType (fieldOp->getLoc (), fieldOp.getType ())))
1020
+ return failure ();
1021
+ os << " " << fieldOp.getSymName () << " ;" ;
1022
+ return success ();
1023
+ }
1024
+
1025
+ static LogicalResult printOperation (CppEmitter &emitter,
1026
+ GetFieldOp getFieldOp) {
1027
+ raw_indented_ostream &os = emitter.ostream ();
1028
+
1029
+ Value result = getFieldOp.getResult ();
1030
+ if (failed (emitter.emitType (getFieldOp->getLoc (), result.getType ())))
1031
+ return failure ();
1032
+ os << " " ;
1033
+ if (failed (emitter.emitOperand (result)))
1034
+ return failure ();
1035
+ os << " = " ;
1036
+
1037
+ os << getFieldOp.getFieldName ().str ();
1038
+ return success ();
1039
+ }
1040
+
1000
1041
static LogicalResult printOperation (CppEmitter &emitter, FileOp file) {
1001
1042
if (!emitter.shouldEmitFile (file))
1002
1043
return success ();
@@ -1605,14 +1646,16 @@ LogicalResult CppEmitter::emitOperation(Operation &op, bool trailingSemicolon) {
1605
1646
emitc::BitwiseAndOp, emitc::BitwiseLeftShiftOp,
1606
1647
emitc::BitwiseNotOp, emitc::BitwiseOrOp,
1607
1648
emitc::BitwiseRightShiftOp, emitc::BitwiseXorOp, emitc::CallOp,
1608
- emitc::CallOpaqueOp, emitc::CastOp, emitc::CmpOp,
1609
- emitc::ConditionalOp, emitc::ConstantOp, emitc::DeclareFuncOp,
1610
- emitc::DivOp, emitc::ExpressionOp, emitc::FileOp, emitc::ForOp,
1611
- emitc::FuncOp, emitc::GlobalOp, emitc::IfOp, emitc::IncludeOp,
1612
- emitc::LoadOp, emitc::LogicalAndOp, emitc::LogicalNotOp,
1613
- emitc::LogicalOrOp, emitc::MulOp, emitc::RemOp, emitc::ReturnOp,
1614
- emitc::SubOp, emitc::SwitchOp, emitc::UnaryMinusOp,
1615
- emitc::UnaryPlusOp, emitc::VariableOp, emitc::VerbatimOp>(
1649
+ emitc::CallOpaqueOp, emitc::CastOp, emitc::ClassOp,
1650
+ emitc::CmpOp, emitc::ConditionalOp, emitc::ConstantOp,
1651
+ emitc::DeclareFuncOp, emitc::DivOp, emitc::ExpressionOp,
1652
+ emitc::FieldOp, emitc::FileOp, emitc::ForOp, emitc::FuncOp,
1653
+ emitc::GetFieldOp, emitc::GlobalOp, emitc::IfOp,
1654
+ emitc::IncludeOp, emitc::LoadOp, emitc::LogicalAndOp,
1655
+ emitc::LogicalNotOp, emitc::LogicalOrOp, emitc::MulOp,
1656
+ emitc::RemOp, emitc::ReturnOp, emitc::SubOp, emitc::SwitchOp,
1657
+ emitc::UnaryMinusOp, emitc::UnaryPlusOp, emitc::VariableOp,
1658
+ emitc::VerbatimOp>(
1616
1659
1617
1660
[&](auto op) { return printOperation (*this , op); })
1618
1661
// Func ops.
0 commit comments