@@ -79,11 +79,11 @@ def getAllTypes(self) -> set[str]:
79
79
return types
80
80
81
81
gAccessKinds : dict [rabbitizer .Enum , AccessTypeInfo ] = {
82
- rabbitizer .AccessType .BYTE : AccessTypeInfo (1 , "s8" , "u8" ),
83
- rabbitizer .AccessType .SHORT : AccessTypeInfo (2 , "s16" , "u16" ),
82
+ rabbitizer .AccessType .BYTE : AccessTypeInfo (1 , "s8" , "u8" , { "vs8" , "vu8" } ),
83
+ rabbitizer .AccessType .SHORT : AccessTypeInfo (2 , "s16" , "u16" , { "vs16" , "vu16" } ),
84
84
# Ignore signed WORD since it tends to not give a proper type
85
- rabbitizer .AccessType .WORD : AccessTypeInfo (4 , None , "u32" , {"s32" }),
86
- rabbitizer .AccessType .DOUBLEWORD : AccessTypeInfo (8 , "s64" , "u64" ),
85
+ rabbitizer .AccessType .WORD : AccessTypeInfo (4 , None , "u32" , {"s32" , "vs32" , "vu32" }),
86
+ rabbitizer .AccessType .DOUBLEWORD : AccessTypeInfo (8 , "s64" , "u64" , { "vs64" , "vu64" } ),
87
87
rabbitizer .AccessType .FLOAT : AccessTypeInfo (4 , "f32" , None , {"Vec3f" }),
88
88
rabbitizer .AccessType .DOUBLEFLOAT : AccessTypeInfo (8 , "f64" , None ),
89
89
}
@@ -122,8 +122,10 @@ class ContextSymbol:
122
122
"This symbol was automatically generated by the disassembler"
123
123
124
124
isMaybeString : bool = False
125
+ failedStringDecoding : bool = False
125
126
126
127
isMaybePascalString : bool = False
128
+ failedPascalStringDecoding : bool = False
127
129
128
130
referenceCounter : int = 0
129
131
"How much this symbol is referenced by something else"
@@ -140,6 +142,11 @@ class ContextSymbol:
140
142
jumpTables : SortedDict [ContextSymbol ] = dataclasses .field (default_factory = SortedDict )
141
143
"For functions, the jump tables which are contained in this function"
142
144
145
+ parentFileName : str | None = None
146
+ "Name of the file containing this symbol"
147
+ inFileOffset : int | None = None
148
+ "Offset relative to the start of the file"
149
+
143
150
overlayCategory : str | None = None
144
151
145
152
nameGetCallback : Callable [[ContextSymbol ], str ]| None = None
@@ -286,6 +293,9 @@ def isShort(self) -> bool:
286
293
287
294
288
295
def isString (self ) -> bool :
296
+ if self .failedStringDecoding :
297
+ return False
298
+
289
299
currentType = self .getTypeSpecial ()
290
300
291
301
if self .sectionType == FileSectionType .Rodata :
@@ -312,6 +322,9 @@ def isString(self) -> bool:
312
322
return False
313
323
314
324
def isPascalString (self ) -> bool :
325
+ if self .failedPascalStringDecoding :
326
+ return False
327
+
315
328
currentType = self .getTypeSpecial ()
316
329
317
330
if self .sectionType == FileSectionType .Rodata :
@@ -338,6 +351,9 @@ def isPascalString(self) -> bool:
338
351
return False
339
352
340
353
def isFloat (self ) -> bool :
354
+ if self .vram % 4 != 0 :
355
+ return False
356
+
341
357
currentType = self .getTypeSpecial ()
342
358
343
359
if gAccessKinds [rabbitizer .AccessType .FLOAT ].typeMatchesAccess (currentType ):
@@ -388,23 +404,7 @@ def isLateRodata(self) -> bool:
388
404
def hasUserDeclaredSize (self ) -> bool :
389
405
return self .userDeclaredSize is not None
390
406
391
- def getBranchLabelName (self , suffix : str ) -> str :
392
- if GlobalConfig .SEQUENTIAL_LABEL_NAMES and self .parentFunction is not None :
393
- index = self .parentFunction .branchLabels .index (self .vram )
394
- if index is not None :
395
- return f".L{ self .parentFunction .getName ()} _{ index + 1 } "
396
-
397
- return f".L{ self .address :08X} { suffix } "
398
-
399
- def getJumpTableName (self , suffix : str ) -> str :
400
- if GlobalConfig .SEQUENTIAL_LABEL_NAMES and self .parentFunction is not None :
401
- index = self .parentFunction .jumpTables .index (self .vram )
402
- if index is not None :
403
- return f"jtbl_{ self .parentFunction .getName ()} _{ index + 1 } "
404
-
405
- return f"jtbl_{ self .address :08X} { suffix } "
406
-
407
- def getDefaultName (self ) -> str :
407
+ def _defaultName_suffix (self ) -> str :
408
408
suffix = ""
409
409
if self .overlayCategory is not None :
410
410
suffix = "_"
@@ -413,30 +413,74 @@ def getDefaultName(self) -> str:
413
413
414
414
if GlobalConfig .CUSTOM_SUFFIX :
415
415
suffix += GlobalConfig .CUSTOM_SUFFIX
416
+ return suffix
416
417
417
- currentType = self .getTypeSpecial ()
418
+ def _defaultName_uniqueIdentifier (self , symType : SymbolSpecialType | str | None ) -> str :
419
+ if GlobalConfig .SEQUENTIAL_LABEL_NAMES and self .parentFunction is not None :
420
+ if symType in {SymbolSpecialType .branchlabel , SymbolSpecialType .jumptablelabel }:
421
+ index = self .parentFunction .branchLabels .index (self .vram )
422
+ if index is not None :
423
+ return f"{ self .parentFunction .getName ()} _{ index + 1 } "
424
+ elif symType == SymbolSpecialType .jumptable :
425
+ index = self .parentFunction .jumpTables .index (self .vram )
426
+ if index is not None :
427
+ return f"{ self .parentFunction .getName ()} _{ index + 1 } "
428
+
429
+ if GlobalConfig .AUTOGENERATED_NAMES_BASED_ON_FILE_NAME :
430
+ if self .parentFileName is not None and self .inFileOffset is not None :
431
+ sectionName = self .sectionType .toStr ().replace ("." , "_" )
432
+ return f"{ self .parentFileName } { sectionName } _{ self .inFileOffset :06X} "
433
+
434
+ suffix = self ._defaultName_suffix ()
435
+
436
+ # Stringify the address
437
+ if GlobalConfig .LEGACY_SYM_ADDR_ZERO_PADDING :
438
+ return f"{ self .address :06X} { suffix } "
439
+ return f"{ self .address :08X} { suffix } "
418
440
419
- if currentType is not None :
420
- if currentType == SymbolSpecialType .function :
421
- return f"func_{ self .address :08X} { suffix } "
422
- if currentType in {SymbolSpecialType .branchlabel , SymbolSpecialType .jumptablelabel }:
423
- return self .getBranchLabelName (suffix )
424
- if currentType == SymbolSpecialType .jumptable :
425
- return self .getJumpTableName (suffix )
441
+ def _defaultName_sectionPrefix (self , symType : SymbolSpecialType | str | None ) -> str :
442
+ # Functions, labels and jumptables don't get a section prefix because most of the time they are in their respective sections
443
+ if symType in {SymbolSpecialType .function , SymbolSpecialType .branchlabel , SymbolSpecialType .jumptablelabel , SymbolSpecialType .jumptable }:
444
+ return ""
426
445
446
+ # Determine the section type prefix
427
447
if GlobalConfig .AUTOGENERATED_NAMES_BASED_ON_SECTION_TYPE :
428
448
if self .sectionType == FileSectionType .Rodata :
429
- if GlobalConfig .LEGACY_SYM_ADDR_ZERO_PADDING :
430
- return f"RO_{ self .address :06X} { suffix } "
431
- return f"RO_{ self .address :08X} { suffix } "
432
- if self .sectionType == FileSectionType .Bss :
433
- if GlobalConfig .LEGACY_SYM_ADDR_ZERO_PADDING :
434
- return f"B_{ self .address :06X} { suffix } "
435
- return f"B_{ self .address :08X} { suffix } "
449
+ return "RO_"
450
+ elif self .sectionType == FileSectionType .Bss :
451
+ return "B_"
452
+ elif self .sectionType == FileSectionType .Text :
453
+ return "T_"
454
+ elif self .sectionType == FileSectionType .Reloc :
455
+ return "REL_"
456
+ return "D_"
457
+
458
+ def _defaultName_typePrefix (self , symType : SymbolSpecialType | str | None ) -> str :
459
+ if symType == SymbolSpecialType .function :
460
+ return f"func_"
461
+ if symType in {SymbolSpecialType .branchlabel , SymbolSpecialType .jumptablelabel }:
462
+ return f".L"
463
+ if symType == SymbolSpecialType .jumptable :
464
+ return f"jtbl_"
465
+
466
+ if GlobalConfig .AUTOGENERATED_NAMES_BASED_ON_DATA_TYPE :
467
+ if self .isFloat ():
468
+ return f"FLT_"
469
+ elif self .isDouble ():
470
+ return f"DBL_"
471
+ elif self .isString ():
472
+ return f"STR_"
473
+ elif self .isPascalString ():
474
+ return f"PSTR_"
475
+ return ""
436
476
437
- if GlobalConfig .LEGACY_SYM_ADDR_ZERO_PADDING :
438
- return f"D_{ self .address :06X} { suffix } "
439
- return f"D_{ self .address :08X} { suffix } "
477
+ def getDefaultName (self ) -> str :
478
+ currentType = self .getTypeSpecial ()
479
+
480
+ uniqueIdentifier = self ._defaultName_uniqueIdentifier (currentType )
481
+ sectionPrefix = self ._defaultName_sectionPrefix (currentType )
482
+ typePrefix = self ._defaultName_typePrefix (currentType )
483
+ return f"{ sectionPrefix } { typePrefix } { uniqueIdentifier } "
440
484
441
485
def getName (self ) -> str :
442
486
if self .nameGetCallback is not None :
@@ -501,7 +545,7 @@ def setSizeIfUnset(self, size: int) -> bool:
501
545
return True
502
546
return False
503
547
504
- def getTypeSpecial (self ) -> str | SymbolSpecialType | None :
548
+ def getTypeSpecial (self ) -> SymbolSpecialType | str | None :
505
549
if self .userDeclaredType is not None :
506
550
return self .userDeclaredType
507
551
return self .autodetectedType
@@ -520,13 +564,13 @@ def getType(self) -> str:
520
564
return currentType .toStr ()
521
565
return currentType
522
566
523
- def setTypeSpecial (self , newType : str | SymbolSpecialType | None , isAutogenerated : bool ):
567
+ def setTypeSpecial (self , newType : SymbolSpecialType | str | None , isAutogenerated : bool ):
524
568
if isAutogenerated :
525
569
self .autodetectedType = newType
526
570
else :
527
571
self .userDeclaredType = newType
528
572
529
- def setTypeIfUnset (self , newType : str | SymbolSpecialType | None , isAutogenerated : bool ) -> bool :
573
+ def setTypeIfUnset (self , newType : SymbolSpecialType | str | None , isAutogenerated : bool ) -> bool :
530
574
if self .hasNoType ():
531
575
self .setTypeSpecial (newType , isAutogenerated = isAutogenerated )
532
576
return True
@@ -556,12 +600,12 @@ def getLabelMacro(self, isInMiddleLabel: bool=False) -> str|None:
556
600
label = ""
557
601
if GlobalConfig .ASM_COMMENT :
558
602
if self .isStatic ():
559
- label += f"# static variable{ GlobalConfig .LINE_ENDS } "
603
+ label += f"/* static variable */ { GlobalConfig .LINE_ENDS } "
560
604
if self .isAutogeneratedPad ():
561
605
mainSymbolInfo = ""
562
606
if self .autoCreatedPadMainSymbol is not None :
563
607
mainSymbolInfo = f" (generated by the size of { self .autoCreatedPadMainSymbol .getName ()} )"
564
- label += f"# Automatically generated and unreferenced pad{ mainSymbolInfo } { GlobalConfig .LINE_ENDS } "
608
+ label += f"/* Automatically generated and unreferenced pad{ mainSymbolInfo } */ { GlobalConfig .LINE_ENDS } "
565
609
566
610
currentType = self .getTypeSpecial ()
567
611
if currentType == SymbolSpecialType .jumptablelabel :
@@ -583,16 +627,16 @@ def getReferenceeSymbols(self) -> str:
583
627
return ""
584
628
585
629
if len (self .referenceFunctions ):
586
- output = "# Functions referencing this symbol:"
630
+ output = "/* Functions referencing this symbol:"
587
631
for sym in self .referenceFunctions :
588
632
output += f" { sym .getName ()} "
589
- return f"{ output } { GlobalConfig .LINE_ENDS } "
633
+ return f"{ output } */ { GlobalConfig .LINE_ENDS } "
590
634
591
635
if len (self .referenceSymbols ):
592
- output = "# Symbols referencing this symbol:"
636
+ output = "/* Symbols referencing this symbol:"
593
637
for sym in self .referenceSymbols :
594
638
output += f" { sym .getName ()} "
595
- return f"{ output } { GlobalConfig .LINE_ENDS } "
639
+ return f"{ output } */ { GlobalConfig .LINE_ENDS } "
596
640
return ""
597
641
598
642
@@ -608,15 +652,20 @@ def getCsvHeader() -> str:
608
652
output += "autodetectedSize,"
609
653
output += "getSize,getVrom,sectionType,"
610
654
611
- output += "isDefined,isUserDeclared,isAutogenerated,isMaybeString,isMaybePascalString,"
612
- output += "referenceCounter,overlayCategory,unknownSegment,"
655
+ output += "isDefined,isUserDeclared,isAutogenerated,"
656
+ output += "isMaybeString,failedStringDecoding,isMaybePascalString,failedPascalStringDecoding,"
657
+ output += "referenceCounter,"
658
+ output += "parentFunction,"
659
+ output += "parentFileName,"
660
+ output += "inFileOffset,"
661
+ output += "overlayCategory,unknownSegment,"
613
662
output += "isGot,isGotGlobal,isGotLocal,gotIndex,accessedAsGpRel,"
614
663
output += "firstLoAccess,isAutogeneratedPad,autoCreatedPadMainSymbol,isElfNotype,"
615
664
output += "isAutocreatedSymFromOtherSizedSym,isMips1Double"
616
665
return output
617
666
618
667
def toCsv (self ) -> str :
619
- output = f"0x{ self .address :06X } ,{ self .name } ,{ self .getName ()} ,{ self .getNameEnd ()} ,"
668
+ output = f"0x{ self .address :08X } ,{ self .name } ,{ self .getName ()} ,{ self .getNameEnd ()} ,"
620
669
621
670
output += f"{ self .userDeclaredType } ,{ self .autodetectedType } ,{ self .getType ()} ,"
622
671
@@ -633,9 +682,26 @@ def toCsv(self) -> str:
633
682
output += "None,"
634
683
else :
635
684
output += f"0x{ self .autodetectedSize :X} ,"
685
+
636
686
output += f"0x{ self .getSize ():X} ,0x{ self .getVrom ():X} ,{ self .sectionType .toStr ()} ,"
637
- output += f"{ self .isDefined } ,{ self .isUserDeclared } ,{ self .isAutogenerated } ,{ self .isMaybeString } ,{ self .isMaybePascalString } ,"
638
- output += f"{ self .referenceCounter } ,{ self .overlayCategory } ,{ self .unknownSegment } ,"
687
+ output += f"{ self .isDefined } ,{ self .isUserDeclared } ,{ self .isAutogenerated } ,"
688
+ output += f"{ self .isMaybeString } ,{ self .failedStringDecoding } ,{ self .isMaybePascalString } ,{ self .failedPascalStringDecoding } ,"
689
+ output += f"{ self .referenceCounter } ,"
690
+
691
+ if self .parentFunction is not None :
692
+ output += f"{ self .parentFunction .getName ()} ,"
693
+ else :
694
+ output += f"None,"
695
+ if self .parentFileName is not None :
696
+ output += f"{ self .parentFileName } ,"
697
+ else :
698
+ output += f"None,"
699
+ if self .inFileOffset is not None :
700
+ output += f"{ self .inFileOffset } ,"
701
+ else :
702
+ output += f"None,"
703
+
704
+ output += f"{ self .overlayCategory } ,{ self .unknownSegment } ,"
639
705
output += f"{ self .isGot } ,{ self .isGotGlobal } ,{ self .isGotLocal } ,{ self .gotIndex } ,{ self .accessedAsGpRel } ,"
640
706
autoCreatedPadMainSymbolName = ""
641
707
if self .autoCreatedPadMainSymbol is not None :
0 commit comments