The class definition visiting method for ir module. Parameters ---------- self : Parser The visiting parser. node : doc.ClassDef The doc AST class definition node.
(self: Parser, node: doc.ClassDef)
| 34 | |
| 35 | @dispatch.register(token="ir", type_name="ClassDef") |
| 36 | def _visit_class_def(self: Parser, node: doc.ClassDef) -> None: |
| 37 | """The class definition visiting method for ir module. |
| 38 | |
| 39 | Parameters |
| 40 | ---------- |
| 41 | self : Parser |
| 42 | The visiting parser. |
| 43 | |
| 44 | node : doc.ClassDef |
| 45 | The doc AST class definition node. |
| 46 | """ |
| 47 | |
| 48 | with self.var_table.with_frame(): |
| 49 | with I.ir_module(): |
| 50 | # Step 0. Add the class name to the var table |
| 51 | fake_module = ModuleWithGlobalVars() |
| 52 | self.var_table.add(node.name, fake_module) |
| 53 | |
| 54 | # Step 1: Check if this class inherits from BasePyModule |
| 55 | is_base_py_module = _check_base_py_module_inheritance(node) |
| 56 | if is_base_py_module: |
| 57 | # Store this information in the IRModule for later use |
| 58 | I.module_attrs({"base_py_module": True}) |
| 59 | # Set the parser context to allow Python functions |
| 60 | self.set_class_context(node.name, True) |
| 61 | else: |
| 62 | # Set the parser context to disallow Python functions |
| 63 | self.set_class_context(node.name, False) |
| 64 | |
| 65 | # Step 2. Visit non-function stmts, including but not limited to |
| 66 | # 1. `I.module_attrs` |
| 67 | # 2. `I.module_global_infos` |
| 68 | with self.with_dispatch_token("ir"): |
| 69 | for stmt in node.body: |
| 70 | if not isinstance(stmt, doc.FunctionDef): |
| 71 | self.visit(stmt) |
| 72 | |
| 73 | # Step 3. Visit function stmts to declare the global vars |
| 74 | for stmt in node.body: |
| 75 | if isinstance(stmt, doc.FunctionDef): |
| 76 | global_var = self.visit_tvm_declare_function(stmt) |
| 77 | fake_module.__setattr__(stmt.name, global_var) |
| 78 | |
| 79 | # Step 4. Visit and parse the functions |
| 80 | with self.with_dispatch_token("ir"): |
| 81 | for stmt in node.body: |
| 82 | if isinstance(stmt, doc.FunctionDef): |
| 83 | self.visit(stmt) |
| 84 | |
| 85 | |
| 86 | @dispatch.register(token="ir", type_name="Assign") |
nothing calls this directly
no test coverage detected
searching dependent graphs…