Skip to content

Block

block

block(*params: Any)

Decorator used to mark function as a basic block.

def foo(a: int) -> int:
    @block
    def bb0(x: int):
        y: int = x + 2
        bb1(y)

    @block
    def bb1(z: int):
        return z

    # Entry-point.
    bb0(a)
Source code in xdsl/frontend/pyast/utils/block.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
def block(*params: Any):
    """
    Decorator used to mark function as a basic block.
    ```
    def foo(a: int) -> int:
        @block
        def bb0(x: int):
            y: int = x + 2
            bb1(y)

        @block
        def bb1(z: int):
            return z

        # Entry-point.
        bb0(a)
    ```
    """

    def decorate(*params: Any):
        return None

    return decorate

is_block(node: ast.FunctionDef) -> bool

Source code in xdsl/frontend/pyast/utils/block.py
30
31
32
33
34
35
def is_block(node: ast.FunctionDef) -> bool:
    return (
        len(node.decorator_list) == 1
        and isinstance(name := node.decorator_list[0], ast.Name)
        and name.id == "block"
    )