-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dialects (arm): add return instruction (bx lr) (#3521)
Add a return instruction which is equivalent to ```bx lr``` --------- Co-authored-by: emmau678 <eu233@Emma-laptop>
- Loading branch information
Showing
3 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"} : () -> () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
], | ||
) |