[Mlir-commits] [mlir] [emitC]Option to mlir-translate class instead of function (PR #141158)
Mehdi Amini
llvmlistbot at llvm.org
Thu May 29 12:20:04 PDT 2025
================
@@ -1129,6 +1170,45 @@ static LogicalResult printOperation(CppEmitter &emitter,
return success();
}
+static LogicalResult emitClassFields(CppEmitter &emitter,
+ emitc::FuncOp functionOp) {
+ raw_indented_ostream &os = emitter.ostream();
+ auto argAttrs = functionOp.getArgAttrs();
+ Operation *operation = functionOp.getOperation();
+ if (failed(printFields(emitter, operation, functionOp.getArguments())))
+ return failure();
+ os << ";\n";
+
+ std::map<std::string, Value> fields;
+ os << "\nstd::map<std::string, char*> _buffer_map {";
+ if (argAttrs) {
+ for (const auto [a, v] : zip(*argAttrs, functionOp.getArguments())) {
+ if (auto da = dyn_cast<mlir::DictionaryAttr>(a)) {
+ auto nv = da.getNamed(emitter.getfieldNameAttribute())->getValue();
+ auto name = cast<mlir::StringAttr>(cast<mlir::ArrayAttr>(nv)[0]).str();
+ auto Ins = fields.insert({name, v});
+ if (!Ins.second)
+ return failure();
+ os << " { \"" << name << "\"" << ", reinterpret_cast<char*>("
+ << emitter.getOrCreateName(v) << ") }, ";
+ }
+ }
+ } else
+ return failure();
+
+ os << "};\n";
+ os << "char* getBufferForName(const std::string& name) const {\n";
+ os.indent();
+ os.indent();
+ os << "auto it = _buffer_map.find(name);\n";
+ os << "return (it == _buffer_map.end()) ? nullptr : it->second;\n";
+ os.unindent();
+ os.unindent();
+ os << "}\n\n";
+
+ return success();
+}
----------------
joker-eph wrote:
Where is the contract about this map and what it's doing documented?
https://github.com/llvm/llvm-project/pull/141158
More information about the Mlir-commits
mailing list