MCPcopy Index your code
hub / github.com/apache/tvm / parse

Function parse

python/tvm/script/parser/core/entry.py:76–148  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

74
75
76def 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(

Callers

nothing calls this directly

Calls 12

parseMethod · 0.95
report_errorMethod · 0.95
as_astMethod · 0.95
_default_globalsFunction · 0.85
SourceClass · 0.85
ParserClass · 0.85
IRBuilderClass · 0.85
from_exprMethod · 0.80
verify_well_formedMethod · 0.80
itemsMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…