Register a method for a operand type, AST operator node and operand index. Parameters ---------- program : Union[doc.AST, Any, str] The TVMScript code to parse. extra_vars : Dict[str, Any] The extra variable table for parsing. check_well_formed : bool W
(
program: doc.AST | Any | str,
extra_vars: dict[str, Any] | None = None,
check_well_formed: bool = True,
s_tir: bool = False,
)
| 74 | |
| 75 | |
| 76 | def parse( |
| 77 | program: doc.AST | Any | str, |
| 78 | extra_vars: dict[str, Any] | None = None, |
| 79 | check_well_formed: bool = True, |
| 80 | s_tir: bool = False, |
| 81 | ) -> Any: |
| 82 | """Register a method for a operand type, AST operator node and operand index. |
| 83 | |
| 84 | Parameters |
| 85 | ---------- |
| 86 | program : Union[doc.AST, Any, str] |
| 87 | The TVMScript code to parse. |
| 88 | |
| 89 | extra_vars : Dict[str, Any] |
| 90 | The extra variable table for parsing. |
| 91 | |
| 92 | check_well_formed : bool |
| 93 | Whether to check well-formedness after parsing. |
| 94 | |
| 95 | Returns |
| 96 | ------- |
| 97 | func : Any |
| 98 | The parsed TVMScript program. |
| 99 | """ |
| 100 | if extra_vars is None: |
| 101 | extra_vars = _default_globals() |
| 102 | |
| 103 | ann = {} |
| 104 | all_pyfuncs = {} |
| 105 | if inspect.isfunction(program): |
| 106 | ann = {program.__name__: program.__annotations__} |
| 107 | elif inspect.isclass(program): |
| 108 | for name, func in program.__dict__.items(): |
| 109 | if inspect.isfunction(func): |
| 110 | ann[name] = func.__annotations__ |
| 111 | all_pyfuncs[name] = func |
| 112 | |
| 113 | source = Source(program) |
| 114 | parser = Parser(source, ann) |
| 115 | with IRBuilder() as builder: |
| 116 | try: |
| 117 | parser.parse(extra_vars=extra_vars) |
| 118 | except ParserError as err: |
| 119 | parser.report_error(err.node, err.args[0]) |
| 120 | ret = builder.get() |
| 121 | # Attach pyfuncs to the IRModule |
| 122 | if inspect.isclass(program) and isinstance(ret, IRModule): |
| 123 | _attach_pyfuncs_to_irmodule(ret, all_pyfuncs) |
| 124 | |
| 125 | # check well-formedness in both Relax and TIR |
| 126 | if check_well_formed: |
| 127 | check_ret = ret |
| 128 | if not isinstance(check_ret, IRModule): |
| 129 | check_ret = IRModule.from_expr(ret) |
| 130 | |
| 131 | source_ast = source.as_ast() |
| 132 | |
| 133 | if isinstance( |
nothing calls this directly
no test coverage detected
searching dependent graphs…