diff --git a/CHANGELOG.md b/CHANGELOG.md index 3be51c2..37fff3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - May be desirable to be used with IDEs that support collapsing code by looking at the whitespace of each line. - This can be controlled by setting the `GlobalConfig.ASM_INDENTATION` option. +- Add a way to indentate labels within functions. + - May be desirable to be used with IDEs that support collapsing code by + looking at the whitespace of each line. + - This can be controlled by setting the `GlobalConfig.ASM_INDENTATION_LABELS` + option. ## [1.30.0] - 2024-09-10 diff --git a/spimdisasm/common/GlobalConfig.py b/spimdisasm/common/GlobalConfig.py index 4f1a913..5c5aac0 100644 --- a/spimdisasm/common/GlobalConfig.py +++ b/spimdisasm/common/GlobalConfig.py @@ -239,8 +239,10 @@ def AGGRESSIVE_STRING_GUESSER(self, value: bool) -> None: """Toggle the glabel count comment on functions""" ASM_REFERENCEE_SYMBOLS: bool = False - ASM_INDENTATION: int = 0 + ASM_INDENTATION: int = 4 """Sets the indentation used for every instruction and data""" + ASM_INDENTATION_LABELS: int = 2 + """Sets the indentation used for labels within functions""" ASM_TEXT_LABEL: str = "glabel" ASM_TEXT_ALT_LABEL: str = "glabel" @@ -386,7 +388,8 @@ def addParametersToArgParse(self, parser: argparse.ArgumentParser) -> None: miscConfig.add_argument("--glabel-count", help=f"Toggle glabel count comment. Defaults to {self.GLABEL_ASM_COUNT}", action=Utils.BooleanOptionalAction) miscConfig.add_argument("--asm-referencee-symbols", help=f"Toggle glabel count comment. Defaults to {self.ASM_REFERENCEE_SYMBOLS}", action=Utils.BooleanOptionalAction) - miscConfig.add_argument("--asm-indentation", help=f"Sets the indentation used for every instruction and data. Defaults to {self.ASM_INDENTATION}") + miscConfig.add_argument("--asm-indentation", help=f"Sets the indentation used for every instruction and data. Defaults to {self.ASM_INDENTATION}", type=int) + miscConfig.add_argument("--asm-indentation-labels", help=f"Sets the indentation used for labels within functions. Defaults to {self.ASM_INDENTATION_LABELS}", type=int) miscConfig.add_argument("--asm-text-label", help=f"Changes the label used to declare functions. Defaults to {self.ASM_TEXT_LABEL}") miscConfig.add_argument("--asm-text-alt-label", help=f"Changes the label used to declare symbols in the middle of functions. Defaults to {self.ASM_TEXT_ALT_LABEL}") @@ -582,8 +585,10 @@ def parseArgs(self, args: argparse.Namespace) -> None: if args.asm_referencee_symbols is not None: self.ASM_REFERENCEE_SYMBOLS = args.asm_referencee_symbols - if args.asm_referencee_symbols is not None: - self.ASM_REFERENCEE_SYMBOLS = args.asm_referencee_symbols + if args.asm_indentation is not None: + self.ASM_INDENTATION = args.asm_indentation + if args.asm_indentation_labels is not None: + self.ASM_INDENTATION_LABELS = args.asm_indentation_labels if args.asm_text_label: self.ASM_TEXT_LABEL = args.asm_text_label diff --git a/spimdisasm/mips/symbols/MipsSymbolFunction.py b/spimdisasm/mips/symbols/MipsSymbolFunction.py index 050b41d..28efd02 100644 --- a/spimdisasm/mips/symbols/MipsSymbolFunction.py +++ b/spimdisasm/mips/symbols/MipsSymbolFunction.py @@ -729,8 +729,10 @@ def getLabelForOffset(self, instructionOffset: int, migrate: bool=False) -> str: label += f"{labelMacro} {labelSym.getName()}{common.GlobalConfig.LINE_ENDS}" if common.GlobalConfig.ASM_TEXT_FUNC_AS_LABEL: label += f"{labelSym.getName()}:{common.GlobalConfig.LINE_ENDS}" - return label - return labelSym.getName() + ":" + common.GlobalConfig.LINE_ENDS + else: + label = labelSym.getName() + ":" + common.GlobalConfig.LINE_ENDS + label = (" " * common.GlobalConfig.ASM_INDENTATION_LABELS) + label + return label def _emitInstruction(self, instr: rabbitizer.Instruction, instructionOffset: int, wasLastInstABranch: bool, isSplittedSymbol: bool=False) -> str: immOverride, relocInfo = self._getImmOverrideForInstruction(instr, instructionOffset, isSplittedSymbol=isSplittedSymbol)