diff --git a/xdsl/dialects/x86/ops.py b/xdsl/dialects/x86/ops.py index 9639a8dcf7..7f72676600 100644 --- a/xdsl/dialects/x86/ops.py +++ b/xdsl/dialects/x86/ops.py @@ -490,7 +490,9 @@ def __init__( ) def assembly_line_args(self) -> tuple[AssemblyInstructionArg | None, ...]: - return self.r1, self.r2 + memory_access = _memory_access_str(self.r2, self.offset) + destination = _assembly_arg_str(self.r1) + return (destination, memory_access) @classmethod def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]: @@ -508,27 +510,6 @@ def custom_print_attributes(self, printer: Printer) -> Set[str]: _print_immediate_value(printer, self.offset) return {"offset"} - def assembly_line(self) -> str | None: - instruction_name = self.assembly_instruction_name() - destination = _assembly_arg_str(self.r1) - source = _assembly_arg_str(self.r2) - if self.offset is not None: - offset = _assembly_arg_str(self.offset) - if self.offset.value.data > 0: - return _assembly_line( - instruction_name, - f"{destination}, [{source}+{offset}]", - self.comment, - ) - else: - return _assembly_line( - instruction_name, f"{destination}, [{source}{offset}]", self.comment - ) - else: - return _assembly_line( - instruction_name, f"{destination}, [{source}]", self.comment - ) - @irdl_op_definition class RM_AddOp(RMOperation[GeneralRegisterType, GeneralRegisterType]): @@ -758,16 +739,8 @@ def __init__( ) def assembly_line_args(self) -> tuple[AssemblyInstructionArg | None, ...]: - destination = _assembly_arg_str(self.r1) - if self.offset is not None: - offset = _assembly_arg_str(self.offset) - if self.offset.value.data > 0: - destination = f"[{destination}+{offset}]" - else: - destination = f"[{destination}{offset}]" - else: - destination = f"[{destination}]" - return destination, self.r2 + memory_access = _memory_access_str(self.r1, self.offset) + return memory_access, self.r2 @classmethod def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]: @@ -889,17 +862,9 @@ def __init__( ) def assembly_line_args(self) -> tuple[AssemblyInstructionArg | None, ...]: - destination = _assembly_arg_str(self.r1) immediate = _assembly_arg_str(self.immediate) - if self.offset is not None: - offset = _assembly_arg_str(self.offset) - if self.offset.value.data > 0: - destination = f"[{destination}+{offset}]" - else: - destination = f"[{destination}{offset}]" - else: - destination = f"[{destination}]" - return destination, immediate + memory_access = _memory_access_str(self.r1, self.offset) + return memory_access, immediate @classmethod def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]: @@ -1091,17 +1056,9 @@ def __init__( def assembly_line_args(self) -> tuple[AssemblyInstructionArg | None, ...]: destination = _assembly_arg_str(self.r1) - source = _assembly_arg_str(self.r2) immediate = _assembly_arg_str(self.immediate) - if self.offset is not None: - offset = _assembly_arg_str(self.offset) - if self.offset.value.data > 0: - source = f"[{source}+{offset}]" - else: - source = f"[{source}{offset}]" - else: - source = f"[{source}]" - return destination, source, immediate + memory_access = _memory_access_str(self.r2, self.offset) + return destination, memory_access, immediate @classmethod def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]: @@ -1170,16 +1127,8 @@ def __init__( ) def assembly_line_args(self) -> tuple[AssemblyInstructionArg | None, ...]: - source = _assembly_arg_str(self.source) - if self.offset is not None: - offset = _assembly_arg_str(self.offset) - if self.offset.value.data > 0: - source = f"[{source}+{offset}]" - else: - source = f"[{source}{offset}]" - else: - source = f"[{source}]" - return (source,) + memory_access = _memory_access_str(self.source, self.offset) + return (memory_access,) @classmethod def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]: @@ -1228,16 +1177,8 @@ def __init__( ) def assembly_line_args(self) -> tuple[AssemblyInstructionArg | None, ...]: - source = _assembly_arg_str(self.source) - if self.offset is not None: - offset = _assembly_arg_str(self.offset) - if self.offset.value.data > 0: - source = f"[{source}+{offset}]" - else: - source = f"[{source}{offset}]" - else: - source = f"[{source}]" - return (source,) + memory_access = _memory_access_str(self.source, self.offset) + return (memory_access,) @classmethod def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]: @@ -1362,6 +1303,21 @@ def _print_immediate_value(printer: Printer, immediate: AnyIntegerAttr | LabelAt printer.print_string_literal(immediate.data) +def _memory_access_str( + register: AssemblyInstructionArg, offset: AnyIntegerAttr | None +) -> str: + register_str = _assembly_arg_str(register) + if offset is not None: + offset_str = _assembly_arg_str(offset) + if offset.value.data > 0: + mem_acc_str = f"[{register_str}+{offset_str}]" + else: + mem_acc_str = f"[{register_str}{offset_str}]" + else: + mem_acc_str = f"[{register_str}]" + return mem_acc_str + + # endregion