Skip to content

Commit 395527f

Browse files
committed
class emitted with failing test
1 parent 194fd83 commit 395527f

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

mlir/lib/Target/Cpp/TranslateToCpp.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,13 +1004,17 @@ static LogicalResult printOperation(CppEmitter &emitter, ClassOp classOp) {
10041004
os << "public:\n";
10051005

10061006
os.indent();
1007+
<<<<<<< Updated upstream
10071008
for (Operation &op : classOp) {
10081009
if (isa<FieldOp>(op)) {
10091010
if (failed(emitter.emitOperation(op, /*trailingSemicolon=*/true)))
10101011
return failure();
10111012
}
10121013
}
10131014
os << "\nconst std::map<std::string, char*> _buffer_map {\n";
1015+
=======
1016+
os << "const std::map<std::string, char*> _buffer_map {\n";
1017+
>>>>>>> Stashed changes
10141018
for (Operation &op : classOp) {
10151019
if (auto fieldOp = dyn_cast<FieldOp>(op)) {
10161020
os << " { \"" << fieldOp.getSymName() << "\", reinterpret_cast<char*>(&"
@@ -1022,12 +1026,19 @@ static LogicalResult printOperation(CppEmitter &emitter, ClassOp classOp) {
10221026
os << "char* getBufferForName(const std::string& name) const {\n";
10231027
os << " auto it = _buffer_map.find(name);\n";
10241028
os << " return (it == _buffer_map.end()) ? nullptr : it->second;\n";
1029+
<<<<<<< Updated upstream
10251030
os << "}\n\n";
10261031
for (Operation &op : classOp) {
10271032
if (!isa<FieldOp>(op)) {
10281033
if (failed(emitter.emitOperation(op, /*trailingSemicolon=*/false)))
10291034
return failure();
10301035
}
1036+
=======
1037+
os << "}\n";
1038+
for (Operation &op : classOp) {
1039+
if (failed(emitter.emitOperation(op, /*trailingSemicolon=*/false)))
1040+
return failure();
1041+
>>>>>>> Stashed changes
10311042
}
10321043

10331044
os.unindent();
@@ -1037,11 +1048,17 @@ static LogicalResult printOperation(CppEmitter &emitter, ClassOp classOp) {
10371048

10381049
static LogicalResult printOperation(CppEmitter &emitter, FieldOp fieldOp) {
10391050
raw_ostream &os = emitter.ostream();
1051+
<<<<<<< Updated upstream
10401052
Location loc = fieldOp->getLoc();
10411053
Type type = fieldOp.getType();
10421054
if (failed(emitter.emitType(loc, type)))
10431055
return failure();
10441056
os << " " << fieldOp.getSymName();
1057+
=======
1058+
if (failed(emitter.emitType(fieldOp->getLoc(), fieldOp.getType())))
1059+
return failure();
1060+
os << " " << fieldOp.getSymName() << ";";
1061+
>>>>>>> Stashed changes
10451062
return success();
10461063
}
10471064

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// RUN: mlir-translate --mlir-to-cpp %s | FileCheck %s
2+
3+
emitc.class @modelClass {
4+
emitc.field @input_tensor : !emitc.array<1xf32>
5+
emitc.func @execute() {
6+
%0 = "emitc.constant"() <{value = 0 : index}> : () -> !emitc.size_t
7+
%1 = get_field @input_tensor : !emitc.array<1xf32>
8+
%2 = subscript %1[%0] : (!emitc.array<1xf32>, !emitc.size_t) -> !emitc.lvalue<f32>
9+
return
10+
}
11+
}
12+
13+
// CHECK: class modelClass final {
14+
// CHECK-NEXT: public:
15+
// CHECK-NEXT:const std::map<std::string, char*> buffer_map {
16+
// CHECK-NEXT: { "input_tensor", reinterpret_cast<char*>(&input_tensor) },
17+
// CHECK-NEXT: };
18+
// CHECK-NEXT: char* getBufferForName(const std::string& name) const {
19+
// CHECK-NEXT: auto it = buffer_map.find(name);
20+
// CHECK-NEXT: return (it == buffer_map.end()) ? nullptr : it->second;
21+
// CHECK-NEXT: }
22+
// CHECK-NEXT: float input_tensor[1];
23+
// CHECK-NEXT: void execute() {
24+
// CHECK-NEXT: size_t v1 = 0;
25+
// CHECK-NEXT: float v2[1] = input_tensor;
26+
// CHECK-NEXT: return;
27+
// CHECK-NEXT: }
28+
// CHECK-EMPTY:
29+
// CHECK-NEXT: };

0 commit comments

Comments
 (0)