Skip to content

Commit

Permalink
Indent labels too
Browse files Browse the repository at this point in the history
  • Loading branch information
AngheloAlf committed Sep 11, 2024
1 parent df4f838 commit 7466eb1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 9 additions & 4 deletions spimdisasm/common/GlobalConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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}")
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions spimdisasm/mips/symbols/MipsSymbolFunction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7466eb1

Please sign in to comment.