Skip to content

Riscv func

riscv_func

RiscvFuncFunctions dataclass

Bases: InterpreterFunctions

Source code in xdsl/interpreters/riscv_func.py
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
@register_impls
class RiscvFuncFunctions(InterpreterFunctions):
    @impl_terminator(riscv_func.ReturnOp)
    def run_return(
        self, interpreter: Interpreter, op: riscv_func.ReturnOp, args: tuple[Any, ...]
    ) -> tuple[TerminatorValue, PythonValues]:
        args = RiscvFunctions.get_reg_values(interpreter, op.operands, args)
        return ReturnedValues(args), ()

    @impl(riscv_func.CallOp)
    def run_call(
        self, interpreter: Interpreter, op: riscv_func.CallOp, args: tuple[Any, ...]
    ) -> tuple[Any, ...]:
        args = RiscvFunctions.get_reg_values(interpreter, op.operands, args)
        results = interpreter.call_op(op.callee.string_value(), args)
        results = RiscvFunctions.set_reg_values(interpreter, op.results, results)
        return results

    @impl_callable(riscv_func.FuncOp)
    def run_func(
        self, interpreter: Interpreter, op: riscv_func.FuncOp, args: tuple[Any, ...]
    ) -> tuple[Any, ...]:
        if (first_block := op.body.blocks.first) is None or not first_block.ops:
            return interpreter.call_external(op.sym_name.data, op, args)
        else:
            # Either this is the entry function, and the register values are not set,
            # or this is a result of a call impl, and the registers have already been
            # validated, so it is safe to set them again.
            args = RiscvFunctions.set_reg_values_for_types(
                interpreter, op.function_type.inputs.data, args
            )
            return interpreter.run_ssacfg_region(op.body, args, op.sym_name.data)

run_return(interpreter: Interpreter, op: riscv_func.ReturnOp, args: tuple[Any, ...]) -> tuple[TerminatorValue, PythonValues]

Source code in xdsl/interpreters/riscv_func.py
20
21
22
23
24
25
@impl_terminator(riscv_func.ReturnOp)
def run_return(
    self, interpreter: Interpreter, op: riscv_func.ReturnOp, args: tuple[Any, ...]
) -> tuple[TerminatorValue, PythonValues]:
    args = RiscvFunctions.get_reg_values(interpreter, op.operands, args)
    return ReturnedValues(args), ()

run_call(interpreter: Interpreter, op: riscv_func.CallOp, args: tuple[Any, ...]) -> tuple[Any, ...]

Source code in xdsl/interpreters/riscv_func.py
27
28
29
30
31
32
33
34
@impl(riscv_func.CallOp)
def run_call(
    self, interpreter: Interpreter, op: riscv_func.CallOp, args: tuple[Any, ...]
) -> tuple[Any, ...]:
    args = RiscvFunctions.get_reg_values(interpreter, op.operands, args)
    results = interpreter.call_op(op.callee.string_value(), args)
    results = RiscvFunctions.set_reg_values(interpreter, op.results, results)
    return results

run_func(interpreter: Interpreter, op: riscv_func.FuncOp, args: tuple[Any, ...]) -> tuple[Any, ...]

Source code in xdsl/interpreters/riscv_func.py
36
37
38
39
40
41
42
43
44
45
46
47
48
49
@impl_callable(riscv_func.FuncOp)
def run_func(
    self, interpreter: Interpreter, op: riscv_func.FuncOp, args: tuple[Any, ...]
) -> tuple[Any, ...]:
    if (first_block := op.body.blocks.first) is None or not first_block.ops:
        return interpreter.call_external(op.sym_name.data, op, args)
    else:
        # Either this is the entry function, and the register values are not set,
        # or this is a result of a call impl, and the registers have already been
        # validated, so it is safe to set them again.
        args = RiscvFunctions.set_reg_values_for_types(
            interpreter, op.function_type.inputs.data, args
        )
        return interpreter.run_ssacfg_region(op.body, args, op.sym_name.data)