MCPcopy Create free account
hub / github.com/apache/tvm-ffi / RegisterMethod

Method RegisterMethod

include/tvm/ffi/reflection/overload.h:484–515  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

482 // register a method
483 template <typename Func, typename... Extra>
484 void RegisterMethod(const char* name, bool is_static, Func&& func, Extra&&... extra) {
485 using FuncInfo = ::tvm::ffi::details::FunctionInfo<std::decay_t<Func>>;
486 MethodInfoBuilder info;
487 info.name = TVMFFIByteArray{name, std::char_traits<char>::length(name)};
488 info.doc = TVMFFIByteArray{nullptr, 0};
489 info.flags = 0;
490 if (is_static) {
491 info.flags |= kTVMFFIFieldFlagBitMaskIsStaticMethod;
492 }
493
494 auto method_name = std::string(type_key_) + "." + name;
495
496 // if an overload method exists, register to existing overload function
497 if (const auto overload_it = registered_fields_.find(name);
498 overload_it != registered_fields_.end()) {
499 ::tvm::ffi::details::OverloadBase* overload_ptr = overload_it->second;
500 return overload_ptr->Register(NewOverload(std::move(method_name), std::forward<Func>(func)));
501 }
502
503 // first time registering overload method
504 auto [method, overload_ptr] =
505 GetOverloadMethod(std::move(method_name), std::forward<Func>(func));
506 registered_fields_.try_emplace(name, overload_ptr);
507
508 info.method = AnyView(method).CopyToTVMFFIAny();
509 info.metadata_.emplace_back("type_schema", FuncInfo::TypeSchema());
510 // apply method info traits
511 ((ApplyMethodInfoTrait(&info, std::forward<Extra>(extra)), ...));
512 std::string metadata_str = Metadata::ToJSON(info.metadata_);
513 info.metadata = TVMFFIByteArray{metadata_str.c_str(), metadata_str.size()};
514 TVM_FFI_CHECK_SAFE_CALL(TVMFFITypeRegisterMethod(type_index_, &info));
515 }
516
517 std::unordered_map<std::string, ::tvm::ffi::details::OverloadBase*> registered_fields_;
518};

Callers

nothing calls this directly

Calls 9

TVMFFITypeRegisterMethodFunction · 0.85
CopyToTVMFFIAnyMethod · 0.80
c_strMethod · 0.80
AnyViewClass · 0.50
findMethod · 0.45
endMethod · 0.45
RegisterMethod · 0.45
emplace_backMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected