[Mlir-commits] [mlir] [mlir][emitC] Add support to emitter for `classop`, `fieldop` and `getfieldop` (PR #145605)
Paul Kirth
llvmlistbot at llvm.org
Wed Jun 25 09:50:15 PDT 2025
================
@@ -997,6 +997,61 @@ static LogicalResult printOperation(CppEmitter &emitter, ModuleOp moduleOp) {
return success();
}
+static LogicalResult printOperation(CppEmitter &emitter, ClassOp classOp) {
+ CppEmitter::Scope classScope(emitter);
+ raw_indented_ostream &os = emitter.ostream();
+ os << "class " << classOp.getSymName() << " final {\n";
+ os << "public:\n\n";
+
+ os.indent();
+ os << "const std::map<std::string, char*> _buffer_map {\n";
+ for (Operation &op : classOp) {
+ if (auto fieldOp = dyn_cast<FieldOp>(op))
+ os << " { \"" << fieldOp.getSymName() << "\", reinterpret_cast<char*>(&"
+ << fieldOp.getAttrs() << ") },\n";
+ }
+ os << "};\n";
+
+ os << "char* getBufferForName(const std::string& name) const {\n";
+ os << " auto it = _buffer_map.find(name);\n";
+ os << " return (it == _buffer_map.end()) ? nullptr : it->second;\n";
----------------
ilovepi wrote:
Should these lines be indented manually? It's certainly easier to read, but you could end up w/ inconsistent indentation, right?
https://github.com/llvm/llvm-project/pull/145605
More information about the Mlir-commits
mailing list