MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / emit_tpl_spl

Method emit_tpl_spl

imperative/tablegen/targets/cpp_class.cpp:167–198  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

165}
166
167void OpDefEmitter::emit_tpl_spl() {
168 for (auto&& i : op.getMgbAttributes()) {
169 if (auto attr = llvm::dyn_cast<MgbEnumAttr>(&i.attr)) {
170 if (attr->supportToString()) {
171 std::vector<std::string> case_body;
172 std::string ename =
173 formatv("{0}::{1}", op.getCppClassName(), attr->getEnumName());
174 llvm::for_each(attr->getEnumMembers(), [&](auto&& v) {
175 size_t d1 = v.find(' ');
176 size_t d2 = v.find('=');
177 size_t d = d1 <= d2 ? d1 : d2;
178 case_body.push_back(formatv(
179 "case {0}::{1}: return \"{1}\";", ename, v.substr(0, d)));
180 });
181 os << formatv(
182 R"(
183template <>
184struct ToStringTrait<{0}> {
185 std::string operator()({0} e) const {
186 switch (e) {
187 {1}
188 default:
189 return "{0}::Unknown";
190 }
191 }
192};
193)",
194 ename, llvm::join(case_body, "\n"));
195 }
196 }
197 }
198}
199
200void OpDefEmitter::emit_body() {
201 auto&& className = op.getCppClassName();

Callers 1

gen_op_def_c_headerFunction · 0.45

Calls 6

getMgbAttributesMethod · 0.80
supportToStringMethod · 0.80
getEnumNameMethod · 0.80
getEnumMembersMethod · 0.80
findMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected