The function declaration step for tirx Parameters ---------- self : Parser The visiting parser. node : doc.Return The doc AST return node.
(self: Parser, node: doc.FunctionDef)
| 869 | |
| 870 | @dispatch.register(token="tirx", type_name="tvm_declare_function") |
| 871 | def visit_tvm_declare_function(self: Parser, node: doc.FunctionDef) -> GlobalVar: |
| 872 | """The function declaration step for tirx |
| 873 | |
| 874 | Parameters |
| 875 | ---------- |
| 876 | self : Parser |
| 877 | The visiting parser. |
| 878 | |
| 879 | node : doc.Return |
| 880 | The doc AST return node. |
| 881 | """ |
| 882 | |
| 883 | supplied_annotation = self.function_annotations |
| 884 | func_annotation = supplied_annotation.get(node.name, {}) |
| 885 | |
| 886 | ret_type = None |
| 887 | with self.var_table.with_frame(): |
| 888 | if node.returns is not None: |
| 889 | ret_type = self.eval_expr(node.returns) |
| 890 | if callable(ret_type): |
| 891 | ret_type = PrimType(ret_type().dtype) |
| 892 | |
| 893 | arg_annotations = [] |
| 894 | for arg in node.args.args: |
| 895 | if arg.annotation is None: |
| 896 | self.report_error(arg, "Type annotation required for function parameters.") |
| 897 | try: |
| 898 | ann = self.eval_expr(arg.annotation) |
| 899 | if callable(ann): |
| 900 | ann = ann() |
| 901 | except Exception: # pylint: disable=broad-except |
| 902 | ann = func_annotation.get(arg.arg, None) |
| 903 | if ann is None: |
| 904 | raise |
| 905 | |
| 906 | IRBuilder.name(arg.arg, ann) |
| 907 | arg_annotations.append(ann) |
| 908 | |
| 909 | func_signature = tvm.tirx.PrimFunc(arg_annotations, None, ret_type=ret_type) |
| 910 | return I.decl_function(node.name, func_signature) |
nothing calls this directly
no test coverage detected
searching dependent graphs…