Skip to content

Program

program

P = ParamSpec('P') module-attribute

R = TypeVar('R') module-attribute

PyASTProgram dataclass

Bases: Generic[P, R]

Wrapper to associate an IR representation with a Python function.

Source code in xdsl/frontend/pyast/program.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
@dataclass
class PyASTProgram(Generic[P, R]):
    """Wrapper to associate an IR representation with a Python function."""

    name: Final[str]
    """The name of the function describing the program."""

    func: Final[Callable[P, R]]
    """A callable object for the function describing the program."""

    _builder: Final[PyASTBuilder]
    """An internal object to contextually build an IR module from the function."""

    _module: ModuleOp | None = None
    """An internal object to cache the built IR module."""

    @property
    def module(self) -> ModuleOp:
        """Lazily build the module when required, once."""
        if self._module is None:
            self._module = self._builder.build()
        return self._module

    def __call__(self, *args: P.args, **kwargs: P.kwargs) -> R:
        """Pass through calling the object to its Python implementation."""
        return self.func(*args, **kwargs)

name: Final[str] instance-attribute

The name of the function describing the program.

func: Final[Callable[P, R]] instance-attribute

A callable object for the function describing the program.

module: ModuleOp property

Lazily build the module when required, once.

__init__(name: Final[str], func: Final[Callable[P, R]], _builder: Final[PyASTBuilder], _module: ModuleOp | None = None) -> None

__call__(*args: P.args, **kwargs: P.kwargs) -> R

Pass through calling the object to its Python implementation.

Source code in xdsl/frontend/pyast/program.py
37
38
39
def __call__(self, *args: P.args, **kwargs: P.kwargs) -> R:
    """Pass through calling the object to its Python implementation."""
    return self.func(*args, **kwargs)