Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions mlir/include/mlir/Dialect/EmitC/IR/EmitC.td
Original file line number Diff line number Diff line change
Expand Up @@ -1618,10 +1618,20 @@ def EmitC_ClassOp
return
}
}
// Class with a final speciferAdd commentMore actions
emitc.class final @modelClass {
emitc.field @fieldName0 : !emitc.array<1xf32> = {emitc.opaque = "input_tensor"}
emitc.func @execute() {
%0 = "emitc.constant"() <{value = 0 : index}> : () -> !emitc.size_t
%1 = get_field @fieldName0 : !emitc.array<1xf32>
%2 = subscript %1[%0] : (!emitc.array<1xf32>, !emitc.size_t) -> !emitc.lvalue<f32>
return
}
}
```
}];

let arguments = (ins SymbolNameAttr:$sym_name);
let arguments = (ins SymbolNameAttr:$sym_name, UnitAttr:$final_specifier);

let regions = (region AnyRegion:$body);

Expand All @@ -1632,7 +1642,8 @@ def EmitC_ClassOp

let hasCustomAssemblyFormat = 1;

let assemblyFormat = [{ $sym_name attr-dict-with-keyword $body }];
let assemblyFormat =
[{ (`final` $final_specifier^)? $sym_name attr-dict-with-keyword $body }];
}

def EmitC_FieldOp : EmitC_Op<"field", [Symbol]> {
Expand Down
6 changes: 4 additions & 2 deletions mlir/lib/Target/Cpp/TranslateToCpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1000,8 +1000,10 @@ static LogicalResult printOperation(CppEmitter &emitter, ModuleOp moduleOp) {
static LogicalResult printOperation(CppEmitter &emitter, ClassOp classOp) {
CppEmitter::Scope classScope(emitter);
raw_indented_ostream &os = emitter.ostream();
os << "class " << classOp.getSymName() << " {\n";
os << "public:\n";
os << "class " << classOp.getSymName();
if (classOp.getFinalSpecifier())
os << " final ";
os << "{\n public:\n";
os.indent();

for (Operation &op : classOp) {
Expand Down
4 changes: 2 additions & 2 deletions mlir/test/mlir-translate/emitc_classops.mlir
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RUN: mlir-translate --mlir-to-cpp %s | FileCheck %s

emitc.class @modelClass {
emitc.class final @modelClass {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add a separate test for final. Otherwise lgtm

emitc.field @fieldName0 : !emitc.array<1xf32>
emitc.field @fieldName1 : !emitc.array<1xf32>
emitc.func @execute() {
Expand All @@ -12,7 +12,7 @@ emitc.class @modelClass {
}
}

// CHECK: class modelClass {
// CHECK: class modelClass final {
// CHECK-NEXT: public:
// CHECK-NEXT: float[1] fieldName0;
// CHECK-NEXT: float[1] fieldName1;
Expand Down