in src/contrib/msc/plugin/base_codegen.h [333:483]
virtual void CodeGenManagerMethods() {
// init method
stack_.func_def("__init__")
.func_arg("self", "object")
.func_arg("root", "str", "None")
.func_start()
.cond_if("root is None")
.assign("root", "os.path.dirname(__name__)")
.cond_end()
.assign(DocUtils::ToAttrAccess("self", "_lib_folder"), "os.path.join(root, \"lib\")")
.func_call("assert")
.inplace_start("os.path.isdir")
.call_arg(DocUtils::ToAttrAccess("self", "_lib_folder"))
.inplace_end()
.assign(DocUtils::ToAttrAccess("self", "_include_folder"),
"os.path.join(root, \"include\")")
.func_call("assert")
.inplace_start("os.path.isdir")
.call_arg(DocUtils::ToAttrAccess("self", "_include_folder"))
.inplace_end()
.assign(DocUtils::ToAttrAccess("self", "_manager_file"),
"os.path.join(root, \"manager.py\")")
.func_call("assert")
.inplace_start("os.path.isfile")
.call_arg(DocUtils::ToAttrAccess("self", "_manager_file"))
.inplace_end()
.func_call("setup", "", "self")
.func_end();
// list headers
this->stack_.func_def("list_includes")
.func_arg("self", "object")
.func_arg("as_abs", "bool", "False")
.func_start()
.assign("includes", "[]")
.for_start("f", "os.listdir(self._include_folder)")
.cond_if("as_abs")
.func_call("append", "", "includes")
.inplace_start("os.path.join")
.call_arg(DocUtils::ToAttrAccess("self", "_include_folder"))
.call_arg("f")
.inplace_end()
.cond_else()
.func_call("append", "", "includes")
.call_arg("f")
.cond_end()
.for_end()
.func_end("includes");
// copy the headers
this->stack_.func_def("copy_includes")
.func_arg("self", "object")
.func_arg("dst", "str")
.func_start()
.cond_if("not os.path.isdir(dst)")
.func_call("makedirs", "", "os")
.call_arg("dst")
.cond_end()
.for_start("header", "os.listdir(self._include_folder)")
.func_call("shutil.copyfile")
.inplace_start("os.path.join")
.call_arg(DocUtils::ToAttrAccess("self", "_include_folder"))
.call_arg("header")
.inplace_end()
.inplace_start("os.path.join")
.call_arg("dst")
.call_arg("header")
.inplace_end()
.for_end()
.func_end();
// list libs
this->stack_.func_def("list_libs")
.func_arg("self", "object")
.func_arg("as_abs", "bool", "False")
.func_start()
.assign("libs", "[]")
.for_start("f", "os.listdir(self._lib_folder)")
.cond_if("as_abs")
.func_call("append", "", "libs")
.inplace_start("os.path.join")
.call_arg(DocUtils::ToAttrAccess("self", "_lib_folder"))
.call_arg("f")
.inplace_end()
.cond_else()
.func_call("append", "", "libs")
.call_arg("f")
.cond_end()
.for_end()
.func_end("libs");
// copy the libs
this->stack_.func_def("copy_libs")
.func_arg("self", "object")
.func_arg("dst", "str")
.func_start()
.cond_if("not os.path.isdir(dst)")
.func_call("makedirs", "", "os")
.call_arg("dst")
.cond_end()
.for_start("lib", "os.listdir(self._lib_folder)")
.func_call("shutil.copyfile")
.inplace_start("os.path.join")
.call_arg(DocUtils::ToAttrAccess("self", "_lib_folder"))
.call_arg("lib")
.inplace_end()
.inplace_start("os.path.join")
.call_arg("dst")
.call_arg("lib")
.inplace_end()
.for_end()
.func_end();
// export method
this->stack_.func_def("export")
.func_arg("self", "object")
.func_arg("dst", "str")
.func_start()
.func_call("copy_includes", "", "self")
.inplace_start("os.path.join")
.call_arg("dst")
.call_arg(DocUtils::ToStr("include"))
.inplace_end()
.func_call("copy_libs", "", "self")
.inplace_start("os.path.join")
.call_arg("dst")
.call_arg(DocUtils::ToStr("lib"))
.inplace_end()
.func_call("shutil.copyfile")
.call_arg(DocUtils::ToAttrAccess("self", "_manager_file"))
.inplace_start("os.path.join")
.call_arg("dst")
.call_arg(DocUtils::ToStr("manager.py"))
.inplace_end()
.func_end();
// get op names
this->stack_.func_def("get_op_names", "List[str]")
.func_arg("self", "object")
.func_start()
.assign("names", "[]");
for (const auto& name : ListPluginNames()) {
this->stack_.func_call("append", "", "names").call_arg(DocUtils::ToStr(name));
}
this->stack_.func_end("names");
// get ops info
this->stack_.func_def("get_ops_info", "dict")
.func_arg("self", "object")
.func_start()
.assign("info", "{}");
for (const auto& name : ListPluginNames()) {
ICHECK(this->config()->ops_info.count(name)) << "Can not find op info for " << name;
const auto& info = this->config()->ops_info[name];
this->stack_.assign(DocUtils::ToIndex("info", DocUtils::ToStr(name)), info);
}
this->stack_.func_end("info");
}