Skip to content

Commit b8c7b18

Browse files
committed
Add final specifier to the classop
1 parent e811383 commit b8c7b18

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

mlir/include/mlir/Dialect/EmitC/IR/EmitC.td

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,10 +1618,20 @@ def EmitC_ClassOp
16181618
return
16191619
}
16201620
}
1621+
// Class with a final speciferAdd commentMore actions
1622+
emitc.class final @modelClass {
1623+
emitc.field @fieldName0 : !emitc.array<1xf32> = {emitc.opaque = "input_tensor"}
1624+
emitc.func @execute() {
1625+
%0 = "emitc.constant"() <{value = 0 : index}> : () -> !emitc.size_t
1626+
%1 = get_field @fieldName0 : !emitc.array<1xf32>
1627+
%2 = subscript %1[%0] : (!emitc.array<1xf32>, !emitc.size_t) -> !emitc.lvalue<f32>
1628+
return
1629+
}
1630+
}
16211631
```
16221632
}];
16231633

1624-
let arguments = (ins SymbolNameAttr:$sym_name);
1634+
let arguments = (ins SymbolNameAttr:$sym_name, UnitAttr:$final_specifier);
16251635

16261636
let regions = (region AnyRegion:$body);
16271637

@@ -1632,7 +1642,8 @@ def EmitC_ClassOp
16321642

16331643
let hasCustomAssemblyFormat = 1;
16341644

1635-
let assemblyFormat = [{ $sym_name attr-dict-with-keyword $body }];
1645+
let assemblyFormat =
1646+
[{ (`final` $final_specifier^)? $sym_name attr-dict-with-keyword $body }];
16361647
}
16371648

16381649
def EmitC_FieldOp : EmitC_Op<"field", [Symbol]> {

mlir/lib/Target/Cpp/TranslateToCpp.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,8 +1000,10 @@ static LogicalResult printOperation(CppEmitter &emitter, ModuleOp moduleOp) {
10001000
static LogicalResult printOperation(CppEmitter &emitter, ClassOp classOp) {
10011001
CppEmitter::Scope classScope(emitter);
10021002
raw_indented_ostream &os = emitter.ostream();
1003-
os << "class " << classOp.getSymName() << " {\n";
1004-
os << "public:\n";
1003+
os << "class " << classOp.getSymName();
1004+
if (classOp.getFinalSpecifier())
1005+
os << " final ";
1006+
os << "{\n public:\n";
10051007
os.indent();
10061008

10071009
for (Operation &op : classOp) {

mlir/test/mlir-translate/emitc_classops.mlir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: mlir-translate --mlir-to-cpp %s | FileCheck %s
22

3-
emitc.class @modelClass {
3+
emitc.class final @modelClass {
44
emitc.field @fieldName0 : !emitc.array<1xf32>
55
emitc.field @fieldName1 : !emitc.array<1xf32>
66
emitc.func @execute() {
@@ -12,7 +12,7 @@ emitc.class @modelClass {
1212
}
1313
}
1414

15-
// CHECK: class modelClass {
15+
// CHECK: class modelClass final {
1616
// CHECK-NEXT: public:
1717
// CHECK-NEXT: float[1] fieldName0;
1818
// CHECK-NEXT: float[1] fieldName1;

0 commit comments

Comments
 (0)