Skip to content

Riscv cf

riscv_cf

RiscvCfFunctions dataclass

Bases: InterpreterFunctions

Source code in xdsl/interpreters/riscv_cf.py
 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
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
@dataclass
@register_impls
class RiscvCfFunctions(InterpreterFunctions):
    bitwidth: int = 32

    @impl_terminator(riscv_cf.JOp)
    def run_j(
        self,
        interpreter: Interpreter,
        op: riscv_cf.JOp,
        args: tuple[Any, ...],
    ):
        return Successor(op.successor, args), ()

    @impl_terminator(riscv_cf.BranchOp)
    def run_branch(
        self,
        interpreter: Interpreter,
        op: riscv_cf.BranchOp,
        args: tuple[Any, ...],
    ):
        return Successor(op.successor, args), ()

    def run_cond_branch(
        self,
        interpreter: Interpreter,
        op: riscv_cf.ConditionalBranchOperation,
        lhs: int,
        rhs: int,
        bitwidth: int,
    ) -> tuple[Successor, PythonValues]:
        cond = op.const_evaluate(lhs, rhs, bitwidth)
        if cond:
            block_args = interpreter.get_values(op.then_arguments)
            return Successor(op.then_block, block_args), ()
        else:
            block_args = interpreter.get_values(op.else_arguments)
            return Successor(op.else_block, block_args), ()

    @impl_terminator(riscv_cf.BeqOp)
    def run_beq(
        self,
        interpreter: Interpreter,
        op: riscv_cf.BeqOp,
        args: tuple[Any, ...],
    ):
        return self.run_cond_branch(interpreter, op, args[0], args[1], self.bitwidth)

    @impl_terminator(riscv_cf.BneOp)
    def run_bne(
        self,
        interpreter: Interpreter,
        op: riscv_cf.BneOp,
        args: tuple[Any, ...],
    ):
        return self.run_cond_branch(interpreter, op, args[0], args[1], self.bitwidth)

    @impl_terminator(riscv_cf.BltOp)
    def run_blt(
        self,
        interpreter: Interpreter,
        op: riscv_cf.BltOp,
        args: tuple[Any, ...],
    ):
        return self.run_cond_branch(interpreter, op, args[0], args[1], self.bitwidth)

    @impl_terminator(riscv_cf.BgeOp)
    def run_bge(
        self,
        interpreter: Interpreter,
        op: riscv_cf.BgeOp,
        args: tuple[Any, ...],
    ):
        return self.run_cond_branch(interpreter, op, args[0], args[1], self.bitwidth)

    @impl_terminator(riscv_cf.BltuOp)
    def run_bltu(
        self,
        interpreter: Interpreter,
        op: riscv_cf.BltuOp,
        args: tuple[Any, ...],
    ):
        return self.run_cond_branch(interpreter, op, args[0], args[1], self.bitwidth)

    @impl_terminator(riscv_cf.BgeuOp)
    def run_bgeu(
        self,
        interpreter: Interpreter,
        op: riscv_cf.BgeuOp,
        args: tuple[Any, ...],
    ):
        return self.run_cond_branch(interpreter, op, args[0], args[1], self.bitwidth)

bitwidth: int = 32 class-attribute instance-attribute

__init__(bitwidth: int = 32) -> None

run_j(interpreter: Interpreter, op: riscv_cf.JOp, args: tuple[Any, ...])

Source code in xdsl/interpreters/riscv_cf.py
20
21
22
23
24
25
26
27
@impl_terminator(riscv_cf.JOp)
def run_j(
    self,
    interpreter: Interpreter,
    op: riscv_cf.JOp,
    args: tuple[Any, ...],
):
    return Successor(op.successor, args), ()

run_branch(interpreter: Interpreter, op: riscv_cf.BranchOp, args: tuple[Any, ...])

Source code in xdsl/interpreters/riscv_cf.py
29
30
31
32
33
34
35
36
@impl_terminator(riscv_cf.BranchOp)
def run_branch(
    self,
    interpreter: Interpreter,
    op: riscv_cf.BranchOp,
    args: tuple[Any, ...],
):
    return Successor(op.successor, args), ()

run_cond_branch(interpreter: Interpreter, op: riscv_cf.ConditionalBranchOperation, lhs: int, rhs: int, bitwidth: int) -> tuple[Successor, PythonValues]

Source code in xdsl/interpreters/riscv_cf.py
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
def run_cond_branch(
    self,
    interpreter: Interpreter,
    op: riscv_cf.ConditionalBranchOperation,
    lhs: int,
    rhs: int,
    bitwidth: int,
) -> tuple[Successor, PythonValues]:
    cond = op.const_evaluate(lhs, rhs, bitwidth)
    if cond:
        block_args = interpreter.get_values(op.then_arguments)
        return Successor(op.then_block, block_args), ()
    else:
        block_args = interpreter.get_values(op.else_arguments)
        return Successor(op.else_block, block_args), ()

run_beq(interpreter: Interpreter, op: riscv_cf.BeqOp, args: tuple[Any, ...])

Source code in xdsl/interpreters/riscv_cf.py
54
55
56
57
58
59
60
61
@impl_terminator(riscv_cf.BeqOp)
def run_beq(
    self,
    interpreter: Interpreter,
    op: riscv_cf.BeqOp,
    args: tuple[Any, ...],
):
    return self.run_cond_branch(interpreter, op, args[0], args[1], self.bitwidth)

run_bne(interpreter: Interpreter, op: riscv_cf.BneOp, args: tuple[Any, ...])

Source code in xdsl/interpreters/riscv_cf.py
63
64
65
66
67
68
69
70
@impl_terminator(riscv_cf.BneOp)
def run_bne(
    self,
    interpreter: Interpreter,
    op: riscv_cf.BneOp,
    args: tuple[Any, ...],
):
    return self.run_cond_branch(interpreter, op, args[0], args[1], self.bitwidth)

run_blt(interpreter: Interpreter, op: riscv_cf.BltOp, args: tuple[Any, ...])

Source code in xdsl/interpreters/riscv_cf.py
72
73
74
75
76
77
78
79
@impl_terminator(riscv_cf.BltOp)
def run_blt(
    self,
    interpreter: Interpreter,
    op: riscv_cf.BltOp,
    args: tuple[Any, ...],
):
    return self.run_cond_branch(interpreter, op, args[0], args[1], self.bitwidth)

run_bge(interpreter: Interpreter, op: riscv_cf.BgeOp, args: tuple[Any, ...])

Source code in xdsl/interpreters/riscv_cf.py
81
82
83
84
85
86
87
88
@impl_terminator(riscv_cf.BgeOp)
def run_bge(
    self,
    interpreter: Interpreter,
    op: riscv_cf.BgeOp,
    args: tuple[Any, ...],
):
    return self.run_cond_branch(interpreter, op, args[0], args[1], self.bitwidth)

run_bltu(interpreter: Interpreter, op: riscv_cf.BltuOp, args: tuple[Any, ...])

Source code in xdsl/interpreters/riscv_cf.py
90
91
92
93
94
95
96
97
@impl_terminator(riscv_cf.BltuOp)
def run_bltu(
    self,
    interpreter: Interpreter,
    op: riscv_cf.BltuOp,
    args: tuple[Any, ...],
):
    return self.run_cond_branch(interpreter, op, args[0], args[1], self.bitwidth)

run_bgeu(interpreter: Interpreter, op: riscv_cf.BgeuOp, args: tuple[Any, ...])

Source code in xdsl/interpreters/riscv_cf.py
 99
100
101
102
103
104
105
106
@impl_terminator(riscv_cf.BgeuOp)
def run_bgeu(
    self,
    interpreter: Interpreter,
    op: riscv_cf.BgeuOp,
    args: tuple[Any, ...],
):
    return self.run_cond_branch(interpreter, op, args[0], args[1], self.bitwidth)