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

Class Parser

python/tvm/script/parser/core/parser.py:352–952  ·  view source on GitHub ↗

The TVMScript parser Parameters ---------- diag : Diagnostics The diagnostics for error reporting. dispatch_tokens : List[str] The list of dispatching tokens to dispatching parsing method of different IRs and different doc AST structure. var_table : Var

Source from the content-addressed store, hash-verified

350
351
352class Parser(doc.NodeVisitor):
353 """The TVMScript parser
354
355 Parameters
356 ----------
357 diag : Diagnostics
358 The diagnostics for error reporting.
359
360 dispatch_tokens : List[str]
361 The list of dispatching tokens to dispatching parsing method
362 of different IRs and different doc AST structure.
363
364 var_table : VarTable
365 The variable table for parsing.
366 """
367
368 diag: Diagnostics
369 dispatch_tokens: list[str]
370 function_annotations: dict[str, dict[str, Any]] | None
371 var_table: VarTable
372 inside_function: bool # whether we are within a function
373 current_class: str | None = None # current class being parsed
374 base_py_module_context: bool = False # whether current class inherits from BasePyModule
375
376 def __init__(
377 self,
378 source: Source,
379 function_annotations: dict[str, dict[str, Any]],
380 ) -> None:
381 self.diag = Diagnostics(source)
382 self.dispatch_tokens = ["default"]
383 self.function_annotations = function_annotations
384 self.var_table = VarTable()
385 self.inside_function = False
386
387 def parse(self, extra_vars: dict[str, Any] | None = None) -> Any:
388 """The main parse method for parser.
389
390 Parameters
391 ----------
392 extra_vars : Optional[Dict[str, Any]]
393 The optional global value table for parsing.
394
395 Returns
396 -------
397 res : Any
398 The doc AST node visiting result.
399 """
400 if extra_vars is None:
401 extra_vars = {}
402 with self.var_table.with_frame():
403 for k, v in extra_vars.items():
404 self.var_table.add(k, v)
405 node = self.diag.source.as_ast()
406 self.visit(node)
407
408 def get_dispatch_token(self, node: doc.FunctionDef) -> str:
409 if not isinstance(node, doc.FunctionDef):

Callers 1

parseFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…