Skip to content

Address

get_validation

get_validation(arch_spec: ArchSpec) -> type[ValidationPass]

Build an address-validation pass bound to arch_spec.

kirin's :class:ValidationSuite instantiates each pass with no arguments (pass_cls()), so a pass cannot take arch_spec as a constructor argument. We close over arch_spec and stash it on a :data:ClassVar, yielding a no-arg-constructible pass class that the suite can drive directly.

Source code in .venv/lib/python3.12/site-packages/bloqade/lanes/validation/address.py
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
def get_validation(arch_spec: ArchSpec) -> type[ValidationPass]:
    """Build an address-validation pass bound to ``arch_spec``.

    ``kirin``'s :class:`ValidationSuite` instantiates each pass with no
    arguments (``pass_cls()``), so a pass cannot take ``arch_spec`` as a
    constructor argument. We close over ``arch_spec`` and stash it on a
    :data:`ClassVar`, yielding a no-arg-constructible pass class that the
    suite can drive directly.
    """

    @dataclass
    class Validation(ValidationPass):
        """Validates a move program against an architecture specification."""

        ARCH_SPEC: ClassVar[ArchSpec] = arch_spec

        def name(self) -> str:
            return "lanes.address.validation"

        def run(self, method: ir.Method) -> tuple[Any, list[ir.ValidationError]]:
            analysis = _ValidationAnalysis(
                method.dialects,
                arch_spec=self.ARCH_SPEC,
            )
            frame, _ = analysis.run(method)

            return frame, analysis.get_validation_errors()

    return Validation