Skip to content

Commit 4548f94

Browse files
authored
Merge pull request #132 from Decompollaborate/develop
1.16.3
2 parents b693e88 + 44e289d commit 4548f94

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[project]
55
name = "spimdisasm"
66
# Version should be synced with spimdisasm/__init__.py
7-
version = "1.16.2"
7+
version = "1.16.3"
88
description = "MIPS disassembler"
99
# license = "MIT"
1010
readme = "README.md"

spimdisasm/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from __future__ import annotations
77

8-
__version_info__: tuple[int, int, int] = (1, 16, 2)
8+
__version_info__: tuple[int, int, int] = (1, 16, 3)
99
__version__ = ".".join(map(str, __version_info__))
1010
__author__ = "Decompollaborate"
1111

spimdisasm/common/Utils.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,22 +124,39 @@ def wordsToBytes(words_list: list[int]) -> bytes:
124124
beWordsToBytes = wordsToBytes
125125

126126
def wordToFloat(word: int) -> float:
127-
return struct.unpack('>f', struct.pack('>I', word))[0]
127+
b = struct.pack('>I', word)
128+
return struct.unpack('>f', b)[0]
128129

129130
def qwordToDouble(qword: int) -> float:
130-
return struct.unpack('>d', struct.pack('>Q', qword))[0]
131+
b = struct.pack('>Q', qword)
132+
return struct.unpack('>d', b)[0]
131133

132134
def wordToCurrenEndian(word: int) -> int:
133135
if GlobalConfig.ENDIAN == InputEndian.BIG:
134136
return word
135137

136138
if GlobalConfig.ENDIAN == InputEndian.LITTLE:
137-
return struct.unpack('<I', struct.pack('>I', word))[0]
139+
b = struct.pack('>I', word)
140+
return struct.unpack('<I', b)[0]
138141

139142
# MIDDLE
140-
first, second = struct.unpack('>2H', struct.pack('<2H', word >> 16, word & 0xFFFF))
143+
b = struct.pack('<2H', word >> 16, word & 0xFFFF)
144+
first, second = struct.unpack('>2H', b)
141145
return (first << 16) | second
142146

147+
def qwordToCurrenEndian(word: int) -> int:
148+
if GlobalConfig.ENDIAN == InputEndian.BIG:
149+
return word
150+
151+
if GlobalConfig.ENDIAN == InputEndian.LITTLE:
152+
b = struct.pack('>Q', word)
153+
return struct.unpack('<Q', b)[0]
154+
155+
# MIDDLE
156+
b = struct.pack('<4H', (word >> 48) & 0xFFFF, (word >> 32) & 0xFFFF, (word >> 16) & 0xFFFF, word & 0xFFFF)
157+
first, second, third, fourth = struct.unpack('>4H', b)
158+
return (first << 48) | (second << 32) | (third << 16) | fourth
159+
143160
def runCommandGetOutput(command: str, args: list[str]) -> list[str] | None:
144161
try:
145162
output = subprocess.check_output([command, *args]).decode("utf-8")

spimdisasm/mips/symbols/MipsSymbolBase.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def canUseConstantsOnData(self) -> bool:
6666
return self.contextSym.allowedToReferenceConstants
6767

6868

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

@@ -77,7 +77,10 @@ def generateAsmLineComment(self, localOffset: int, wordValue: int|None = None) -
7777

7878
wordValueHex = ""
7979
if wordValue is not None:
80-
wordValueHex = f"{common.Utils.wordToCurrenEndian(wordValue):08X} "
80+
if isDouble:
81+
wordValueHex = f"{common.Utils.qwordToCurrenEndian(wordValue):016X} "
82+
else:
83+
wordValueHex = f"{common.Utils.wordToCurrenEndian(wordValue):08X} "
8184

8285
return f"/* {offsetHex} {vramHex} {wordValueHex}*/"
8386

@@ -435,7 +438,7 @@ def getNthWordAsDouble(self, i: int) -> tuple[str, int]:
435438
doubleValue = common.Utils.qwordToDouble(doubleWord)
436439
value = f"{doubleValue:.18g}"
437440

438-
comment = self.generateAsmLineComment(localOffset, doubleWord)
441+
comment = self.generateAsmLineComment(localOffset, doubleWord, isDouble=True)
439442
output += f"{label}{comment} {dotType} {value}"
440443
output += self.getEndOfLineComment(i)
441444
output += common.GlobalConfig.LINE_ENDS

0 commit comments

Comments
 (0)