Lunderberg commented on code in PR #15260:
URL: https://github.com/apache/tvm/pull/15260#discussion_r1256622048
##########
python/tvm/script/parser/tir/parser.py:
##########
@@ -528,3 +543,76 @@ def visit_tvm_declare_function(self: Parser, node:
doc.FunctionDef) -> GlobalVar
# Only ret_type is needed for func_signature.
func_signature = tvm.tir.PrimFunc([], None, ret_type=ret_type)
return I.decl_function(node.name, func_signature)
+
+
+def process_insert_macro(self: Parser, call: doc.Call) -> None:
+ """Bind arguments to T.insert to the parameters of the macro, and pass the
macro body
+ for further parsing.
+ """
+
+ def find_macro_def(name: str, decl_list: doc.AST) ->
Union[doc.FunctionDef, Any]:
+ for decl in decl_list:
+ if isinstance(decl, doc.FunctionDef) and decl.name == name:
+ return decl
+ return None
+
+ macro_name = call.args[0]
+
+ if not isinstance(macro_name, doc.Name):
+ self.report_error(call, "Invalid macro name in T.insert")
+ macro_name = macro_name.id
+
+ macro = self.var_table.get().get(macro_name)
+ if macro is None:
+ self.report_error(node, f"Undefined macro '{macro_name}'")
+
+ if isinstance(macro.doc, doc.Module):
+ macro_def = find_macro_def(macro_name, macro.doc.body)
Review Comment:
Huh, looks like I was entirely off about the return type of `ast.parse`. I
had expected it to return the most specific AST type that can describe the
string, but even if I just run `ast.parse("1 + 2")` it results in an
`ast.Module`. Checking
[here](https://docs.python.org/3/library/ast.html#ast.Module), it looks like
that's guaranteed behavior, so we couldn't get a `doc.FunctionDef` at this
location anyways.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]