diff --git a/tests/filecheck/dialects/arm_func/test_ops.mlir b/tests/filecheck/dialects/arm_func/test_ops.mlir new file mode 100644 index 0000000000..816e53f7dd --- /dev/null +++ b/tests/filecheck/dialects/arm_func/test_ops.mlir @@ -0,0 +1,9 @@ +// RUN: XDSL_ROUNDTRIP +// RUN: XDSL_GENERIC_ROUNDTRIP +// RUN: xdsl-opt -t arm-asm %s | filecheck %s --check-prefix=CHECK-ASM + +// CHECK: arm_func.return {"comment" = "this is a return instruction"} +// CHECK-ASM: bx lr # this is a return instruction +arm_func.return {"comment" = "this is a return instruction"} + +// CHECK-GENERIC: "arm_func.return"() {"comment" = "this is a return instruction"} : () -> () diff --git a/xdsl/dialects/__init__.py b/xdsl/dialects/__init__.py index 3fe02e45b0..a879e0f729 100644 --- a/xdsl/dialects/__init__.py +++ b/xdsl/dialects/__init__.py @@ -38,6 +38,11 @@ def get_arm(): return ARM + def get_arm_func(): + from xdsl.dialects.arm_func import ARM_FUNC + + return ARM_FUNC + def get_bufferization(): from xdsl.dialects.bufferization import Bufferization @@ -335,6 +340,7 @@ def get_transform(): "air": get_air, "arith": get_arith, "arm": get_arm, + "arm_func": get_arm_func, "bufferization": get_bufferization, "builtin": get_builtin, "cf": get_cf, diff --git a/xdsl/dialects/arm_func.py b/xdsl/dialects/arm_func.py new file mode 100644 index 0000000000..bd86f135f1 --- /dev/null +++ b/xdsl/dialects/arm_func.py @@ -0,0 +1,51 @@ +from xdsl.dialects import arm +from xdsl.dialects.builtin import StringAttr +from xdsl.ir import Dialect +from xdsl.irdl import ( + irdl_op_definition, + traits_def, +) +from xdsl.traits import IsTerminator + + +@irdl_op_definition +class RetOp(arm.ops.ARMInstruction): + """ + Return from subroutine. + + Equivalent to `bx lr` + """ + + name = "arm_func.return" + + assembly_format = "attr-dict" + + traits = traits_def(IsTerminator()) + + def __init__( + self, + *, + comment: str | StringAttr | None = None, + ): + if isinstance(comment, str): + comment = StringAttr(comment) + + super().__init__( + attributes={ + "comment": comment, + }, + ) + + def assembly_line_args(self): + return () + + def assembly_instruction_name(self) -> str: + return "bx lr" + + +ARM_FUNC = Dialect( + "arm_func", + [ + RetOp, + ], +)