tqchen commented on a change in pull request #6227:
URL: https://github.com/apache/incubator-tvm/pull/6227#discussion_r467532618



##########
File path: python/tvm/hybrid/parser.py
##########
@@ -0,0 +1,755 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""Hybrid Script Parser For TIR"""
+# pylint: disable=invalid-name, missing-docstring, 
inconsistent-return-statements, no-else-return
+# pylint: disable=unnecessary-comprehension, unused-argument, 
import-outside-toplevel
+# pylint: disable=unused-import
+import json
+import numbers
+import operator
+from typed_ast import ast3 as ast
+
+import tvm._ffi
+from tvm import tir
+from tvm._ffi.base import TVMError
+from tvm.ir import GlobalVar
+from tvm.tir import all as _all
+from tvm.tir import expr as _expr
+
+from . import scope_emitter, special_stmt, scope_handler, intrin
+from .meta_unparser import MetaUnparser
+from .registry import Registry
+
+
+class HybridParserError(RuntimeError):
+    """Hybrid Parser Runtime Error"""
+
+
+class HybridParser(ast.NodeVisitor):
+    """Python AST visitor pass which finally lowers it to TIR
+    Notes for extension:
+    1. To support new types of AST nodes. Add a function visit_xxx().
+    2. To support new functions
+        We divide allowed function calls in hybrid script into 3 categories,
+        which is scope_handler, intrin and special_stmt.
+        1) scope_handler: scope_handler functions correspond to StmtNodes 
without body, which can be
+        further classified into 2 categories: with scope handler can for scope 
handlers
+        2) intrin: intrin functions corresponds to the remaining IRNodes 
(StmtNodes without body,
+        PrimExprNodes and more)
+        3) special_stmt: special_stmt functions don't correspond to an IRNode 
in the AST directly.
+        It is usually used for some information that is not suitable to be 
printed directly.
+        When visiting With node, we check with_scope registry.
+        When visiting For node, we check for_scope registry.
+    """
+
+    _binop_maker = {
+        ast.Add: tir.Add,

Review comment:
       For followup PR.
   
   To enable automatic conversion in frontend(syntax sugar), we might want to 
be able change to the operator version instead of the tir.Add(requires both 
operands to share the same type).




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to