Skip to content

Commit

Permalink
Merge pull request #170 from Decompollaborate/develop
Browse files Browse the repository at this point in the history
1.28.1
  • Loading branch information
AngheloAlf authored Aug 19, 2024
2 parents 2b602b8 + bc52b19 commit 49b8cce
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 9 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.28.1] - 2024-08-19

### Changed

- Avoid emitting "global" visibility on labels.
- Avoid emitting a rom offset comment on bss symbols.
- Change on `gpRelHack` behavior:
- Emit `.extern`s with dummy size at the top of the function for all the
`%gp_rel`-accessed symbols within the function.

### Fixed

- Fix function symbols and labels not acknowledging their parent file.
- Used mainly for debugging purposes.

## [1.28.0] - 2024-08-09

### Added
Expand Down Expand Up @@ -1593,6 +1608,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.28.1]: https://github.com/Decompollaborate/spimdisasm/compare/1.28.0...1.28.1
[1.28.0]: https://github.com/Decompollaborate/spimdisasm/compare/1.27.0...1.28.0
[1.27.0]: https://github.com/Decompollaborate/spimdisasm/compare/1.26.1...1.27.0
[1.26.1]: https://github.com/Decompollaborate/spimdisasm/compare/1.26.0...1.26.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.28.0,<2.0.0
spimdisasm>=1.28.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.28.0"
version = "1.28.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, 28, 0)
__version_info__: tuple[int, int, int] = (1, 28, 1)
__version__ = ".".join(map(str, __version_info__))# + "-dev0"
__author__ = "Decompollaborate"

Expand Down
2 changes: 1 addition & 1 deletion spimdisasm/common/ContextSymbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ def _defaultName_uniqueIdentifier(self, symType: SymbolSpecialType|str|None) ->
return f"{self.parentFunction.getName()}_{index + 1}"

if GlobalConfig.AUTOGENERATED_NAMES_BASED_ON_FILE_NAME:
if self.parentFileName is not None and self.inFileOffset is not None:
if self.parentFileName is not None and self.inFileOffset is not None and symType != SymbolSpecialType.function:
sectionName = self.sectionType.toStr().replace(".", "_")
return f"{self.parentFileName}{sectionName}_{self.inFileOffset:06X}"

Expand Down
2 changes: 1 addition & 1 deletion spimdisasm/common/ElementBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def getLabelFromSymbol(self, sym: ContextSymbol|None, symName: str|None) -> str:
if label is None:
return ""
label += f" {symName or sym.getName()}"
if sym.visibility is not None:
if sym.visibility is not None and sym.visibility != "global":
label += f", {sym.visibility}"
if GlobalConfig.GLABEL_ASM_COUNT:
if self.index is not None:
Expand Down
1 change: 1 addition & 0 deletions spimdisasm/mips/sections/MipsSectionRodata.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def _analyze_processJumptable(self, localOffset: int, w: int, contextSym: common
labelSym.referenceCounter += 1
if jumpTableSym.parentFunction is not None:
labelSym.parentFunction = jumpTableSym.parentFunction
labelSym.parentFileName = jumpTableSym.parentFunction.parentFileName
jumpTableSym.parentFunction.branchLabels.add(labelSym.vram, labelSym)

return jumpTableSym, firstJumptableWord
Expand Down
9 changes: 6 additions & 3 deletions spimdisasm/mips/symbols/MipsSymbolBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,14 @@ def canUseConstantsOnData(self) -> bool:
return self.contextSym.allowedToReferenceConstants


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

offsetHex = "{0:0{1}X}".format(localOffset + self.inFileOffset + self.commentOffset, common.GlobalConfig.ASM_COMMENT_OFFSET_WIDTH)
if emitRomOffset:
offsetHex = "{0:0{1}X} ".format(localOffset + self.inFileOffset + self.commentOffset, common.GlobalConfig.ASM_COMMENT_OFFSET_WIDTH)
else:
offsetHex = ""

currentVram = self.getVramOffset(localOffset)
vramHex = f"{currentVram:08X}"
Expand All @@ -80,7 +83,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"/* {offsetHex}{vramHex} {wordValueHex}*/"


def getSymbolAsmDeclaration(self, symName: str, useGlobalLabel: bool=True) -> str:
Expand Down
2 changes: 1 addition & 1 deletion spimdisasm/mips/symbols/MipsSymbolBss.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def disassembleAsBss(self, useGlobalLabel: bool = True) -> str:
output += self.getPrevAlignDirective(0)

output += self.getSymbolAsmDeclaration(self.getName(), useGlobalLabel)
output += self.generateAsmLineComment(0)
output += self.generateAsmLineComment(0, emitRomOffset=False)
output += f" .space 0x{self.spaceSize:02X}{common.GlobalConfig.LINE_ENDS}"

nameEnd = self.getNameEnd()
Expand Down
13 changes: 13 additions & 0 deletions spimdisasm/mips/symbols/MipsSymbolFunction.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,10 @@ def _generateRelocsFromInstructionAnalyzer(self) -> None:


def analyze(self) -> None:
self.contextSym.inFileOffset = self.inFileOffset
if self.parent is not None:
self.contextSym.parentFileName = self.parent.getName()

if not common.GlobalConfig.DISASSEMBLE_UNKNOWN_INSTRUCTIONS and self.hasUnimplementedIntrs:
offset = 0
for instr in self.instructions:
Expand Down Expand Up @@ -423,6 +427,7 @@ def analyze(self) -> None:
labelSym.referenceCounter += 1
labelSym.referenceFunctions.add(self.contextSym)
labelSym.parentFunction = self.contextSym
labelSym.parentFileName = self.contextSym.parentFileName
self.contextSym.branchLabels.add(labelSym.vram, labelSym)

# Function calls
Expand Down Expand Up @@ -787,6 +792,14 @@ def disassemble(self, migrate: bool=False, useGlobalLabel: bool=True, isSplitted
if self.hasUnimplementedIntrs:
return self.disassembleAsData(useGlobalLabel=useGlobalLabel, isSplittedSymbol=isSplittedSymbol)

if not common.GlobalConfig.PIC and self.gpRelHack and len(self.instrAnalyzer.gpReferencedSymbols) > 0:
output += f"/* Symbols accessed via $gp register */{common.GlobalConfig.LINE_ENDS}"
for gpAddress in self.instrAnalyzer.gpReferencedSymbols:
gpSym = self.getSymbol(gpAddress, tryPlusOffset=False)
if gpSym is not None:
output += f".extern {gpSym.getName()}, 1{common.GlobalConfig.LINE_ENDS}"
output += common.GlobalConfig.LINE_ENDS

output += self.contextSym.getReferenceeSymbols()
output += self.getPrevAlignDirective(0)

Expand Down
2 changes: 2 additions & 0 deletions spimdisasm/mips/symbols/analysis/InstrAnalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def __init__(self, funcVram: int, context: common.Context) -> None:
"key: offset of instruction which is setting the %lo symbol, value: symbol"

self.symbolGpInstrOffset: dict[int, int] = dict()
self.gpReferencedSymbols: set[int] = set()

self.symbolInstrOffset: dict[int, int] = dict()

Expand Down Expand Up @@ -300,6 +301,7 @@ def processSymbol(self, address: int, luiOffset: int|None, lowerInstr: rabbitize
self.lowToHiDict[lowerOffset] = luiOffset
else:
self.symbolGpInstrOffset[lowerOffset] = address
self.gpReferencedSymbols.add(address)
self.symbolInstrOffset[lowerOffset] = address
self.referencedVramsInstrOffset[lowerOffset] = address

Expand Down

0 comments on commit 49b8cce

Please sign in to comment.