Skip to content

Commit

Permalink
Merge pull request #175 from Decompollaborate/develop
Browse files Browse the repository at this point in the history
1.30.1
  • Loading branch information
AngheloAlf committed Sep 19, 2024
2 parents 9593eb7 + eb5e1c1 commit ed6b430
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 8 deletions.
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,33 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.30.1] - 2024-09-19

### Added

- Add a way to indentate instructions and data.
- 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.
- Defaults to 4.
- 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.
- Defaults to 2.

### Changed

- Assembly now gets indentated by default to 4 spaces (or 2 spaces for labels).
- Use `GlobalConfig.ASM_INDENTATION` and `GlobalConfig.ASM_INDENTATION_LABELS`
to disable this behavior.

### Fixed

- Prevent generating labels for ignored symbols that are referenced by function
calls (ie in a `jal`).

## [1.30.0] - 2024-09-10

### Changed
Expand Down Expand Up @@ -1655,6 +1682,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Version 1.0.0

[unreleased]: https://github.com/Decompollaborate/spimdisasm/compare/master...develop
[1.30.1]: https://github.com/Decompollaborate/spimdisasm/compare/1.30.0...1.30.1
[1.30.0]: https://github.com/Decompollaborate/spimdisasm/compare/1.29.0...1.30.0
[1.29.0]: https://github.com/Decompollaborate/spimdisasm/compare/1.28.1...1.29.0
[1.28.1]: https://github.com/Decompollaborate/spimdisasm/compare/1.28.0...1.28.1
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ If you use a `requirements.txt` file in your repository, then you can add
this library with the following line:

```txt
spimdisasm>=1.30.0,<2.0.0
spimdisasm>=1.30.1,<2.0.0
```

### Development version
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[project]
name = "spimdisasm"
# Version should be synced with spimdisasm/__init__.py
version = "1.30.0"
version = "1.30.1"
description = "MIPS disassembler"
readme = "README.md"
license = {file = "LICENSE"}
Expand Down
2 changes: 1 addition & 1 deletion spimdisasm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from __future__ import annotations

__version_info__: tuple[int, int, int] = (1, 30, 0)
__version_info__: tuple[int, int, int] = (1, 30, 1)
__version__ = ".".join(map(str, __version_info__))# + "-dev0"
__author__ = "Decompollaborate"

Expand Down
6 changes: 6 additions & 0 deletions spimdisasm/common/ContextSymbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,9 @@ def getCsvHeader() -> str:
output += "isDefined,isUserDeclared,isAutogenerated,"
output += "isMaybeString,failedStringDecoding,isMaybePascalString,failedPascalStringDecoding,"
output += "referenceCounter,"
if False:
output += "referenceFunctions,"
output += "referenceSymbols,"
output += "parentFunction,"
output += "parentFileName,"
output += "inFileOffset,"
Expand Down Expand Up @@ -760,6 +763,9 @@ def toCsv(self) -> str:
output += f"{self.isDefined},{self.isUserDeclared},{self.isAutogenerated},"
output += f"{self.isMaybeString},{self.failedStringDecoding},{self.isMaybePascalString},{self.failedPascalStringDecoding},"
output += f"{self.referenceCounter},"
if False:
output += f"\"{','.join(x.getName() for x in self.referenceFunctions)}\","
output += f"\"{','.join(x.getName() for x in self.referenceSymbols)}\","

if self.parentFunction is not None:
output += f"{self.parentFunction.getName()},"
Expand Down
15 changes: 14 additions & 1 deletion spimdisasm/common/GlobalConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,11 @@ def AGGRESSIVE_STRING_GUESSER(self, value: bool) -> None:
"""Toggle the glabel count comment on functions"""
ASM_REFERENCEE_SYMBOLS: bool = False

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"
ASM_JTBL_LABEL: str = "jlabel"
Expand Down Expand Up @@ -379,10 +384,13 @@ def addParametersToArgParse(self, parser: argparse.ArgumentParser) -> None:
miscConfig = parser.add_argument_group("Disassembler misc options")

miscConfig.add_argument("--asm-comments", help=f"Toggle the comments in generated assembly code. Defaults to {self.ASM_COMMENT}", action=Utils.BooleanOptionalAction)
miscConfig.add_argument("--comment-offset-width", help=f"Sets the zeroes width padding for the file offset comment. Defaults to {self.ASM_COMMENT_OFFSET_WIDTH}", action=Utils.BooleanOptionalAction)
miscConfig.add_argument("--comment-offset-width", help=f"Sets the zeroes width padding for the file offset comment. Defaults to {self.ASM_COMMENT_OFFSET_WIDTH}")
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}", 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}")
miscConfig.add_argument("--asm-jtbl-label", help=f"Changes the label used to declare jumptable labels. Defaults to {self.ASM_JTBL_LABEL}")
Expand Down Expand Up @@ -577,6 +585,11 @@ 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_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
if args.asm_text_alt_label:
Expand Down
6 changes: 4 additions & 2 deletions spimdisasm/mips/symbols/MipsSymbolBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ def canUseConstantsOnData(self) -> bool:


def generateAsmLineComment(self, localOffset: int, wordValue: int|None=None, *, isDouble: bool=False, emitRomOffset: bool=True) -> str:
indentation = " " * common.GlobalConfig.ASM_INDENTATION

if not common.GlobalConfig.ASM_COMMENT:
return ""
return indentation

if emitRomOffset:
offsetHex = "{0:0{1}X} ".format(localOffset + self.inFileOffset + self.commentOffset, common.GlobalConfig.ASM_COMMENT_OFFSET_WIDTH)
Expand All @@ -83,7 +85,7 @@ def generateAsmLineComment(self, localOffset: int, wordValue: int|None=None, *,
else:
wordValueHex = f"{common.Utils.wordToCurrenEndian(wordValue):08X} "

return f"/* {offsetHex}{vramHex} {wordValueHex}*/"
return f"{indentation}/* {offsetHex}{vramHex} {wordValueHex}*/"


def getSymbolAsmDeclaration(self, symName: str, useGlobalLabel: bool=True) -> str:
Expand Down
15 changes: 13 additions & 2 deletions spimdisasm/mips/symbols/MipsSymbolFunction.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,9 @@ def analyze(self) -> None:

# Branches
for instrOffset, targetBranchVram in self.instrAnalyzer.branchInstrOffsets.items():
if self.context.isAddressBanned(targetBranchVram):
continue

if common.GlobalConfig.INPUT_FILE_TYPE == common.InputFileType.ELF:
if self.getVromOffset(instrOffset) in self.context.globalRelocationOverrides:
# Avoid creating wrong symbols on elf files
Expand All @@ -442,6 +445,9 @@ def analyze(self) -> None:

# Function calls
for instrOffset, targetVram in self.instrAnalyzer.funcCallInstrOffsets.items():
if self.context.isAddressBanned(targetVram):
continue

if common.GlobalConfig.INPUT_FILE_TYPE == common.InputFileType.ELF:
if self.getVromOffset(instrOffset) in self.context.globalRelocationOverrides:
# Avoid creating wrong symbols on elf files
Expand Down Expand Up @@ -521,6 +527,9 @@ def analyze(self) -> None:

# Jump tables
for targetVram in self.instrAnalyzer.referencedJumpTableOffsets.values():
if self.context.isAddressBanned(targetVram):
continue

jumpTable = self.addJumpTable(targetVram, isAutogenerated=True)
jumpTable.parentFunction = self.contextSym
self.contextSym.jumpTables.add(jumpTable.vram, jumpTable)
Expand Down Expand Up @@ -729,8 +738,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 ed6b430

Please sign in to comment.