[Mlir-commits] [mlir] [mlir][emitC] Add support to emitter for `classop`, `fieldop` and `getfieldop` (PR #145605)
Jaden Angella
llvmlistbot at llvm.org
Wed Jun 25 10:39:50 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";
----------------
Jaddyen wrote:
true! it would be nicer to indent using the `os`
https://github.com/llvm/llvm-project/pull/145605
More information about the Mlir-commits
mailing list