tvm_tirx.script.parser#
Translate TVMScript syntax into IR-builder calls.
Notes
A registered language namespace supplies hooks for function construction,
value binding, statement emission, and control flow. Use register_namespace
and make_decorator to register a namespace and create its decorator.
The hook contracts are defined by script.ir_builder.parser_protocol.
Examples
from tvm_tirx.script import tirx as T
@T.function
def example(a: T.int32):
T.evaluate(a + 1)
The corresponding builder form below omits generated lexical helpers and source locations; it illustrates the construction rather than quoting generated output.
from tvm_tirx.script.ir_builder import IRBuilder
from tvm_tirx.tirx.script import ir_builder as B
with IRBuilder() as builder:
with B.function_():
B.func_name_("example")
a = B.arg_("a", B.int32)
B.emit_(B.evaluate(a + 1))
example = builder.get()
A namespace extending the TIRx builder can customize emit_ as follows:
from types import SimpleNamespace
from tvm_tirx.script.parser import make_decorator, register_namespace
M = SimpleNamespace(**vars(B))
def emit(value, *, loc=None):
print(type(value).__name__)
return B.emit_(value, loc=loc)
M.emit_ = emit
M.function = make_decorator(M, namespace_path="custom.function")
register_namespace("custom", M)
Use @M.function at the definition site. The registered namespace supplies
these hooks; tvm_tirx.script.ir_builder.parser_protocol defines their shared
contracts and language-specific placeholders, not a complete language.
Functions#
|
Register an opaque fixed namespace; its first alias is the syntax key root. |
|
Register a lazy bootstrap callback without importing the language variant. |
|
Create a function decorator with an explicit namespace and construction kind. |
|
Create a decorator for helpers executed in a caller's builder frames. |
|
Keep an ordinary Python callable for collection in a module. |
|
Decorate a Python class with two-phase module construction. |
|
Transpile and execute a source string, Python function, or Python class. |
Alias |
Canonical API |
|---|---|
|