[decompiler] handle pointer to symbol value, clean up prints on offline test (#1978)

- fix issue described in
https://github.com/open-goal/jak-project/issues/1939
- fix `text`, which was manually patched with the wrong offset (was
reading the symbol value off by one byte)
- clean up some random useless prints
- make the offline tests keep trying if there's a comparison error,
clean up the output a bit so the diffs are all at the end.
This commit is contained in:
water111
2022-10-16 18:19:59 -04:00
committed by GitHub
parent e7bb0fb68d
commit ddd60fca48
21 changed files with 291 additions and 509 deletions
+8 -2
View File
@@ -189,11 +189,14 @@ void LinkedObjectFile::symbol_link_word(int source_segment,
* Add link information that a word's lower 16 bits are the offset of the given symbol relative to
* the symbol table register.
*/
void LinkedObjectFile::symbol_link_offset(int source_segment, int source_offset, const char* name) {
void LinkedObjectFile::symbol_link_offset(int source_segment,
int source_offset,
const char* name,
bool subtract_one) {
ASSERT((source_offset % 4) == 0);
auto& word = words_by_seg.at(source_segment).at(source_offset / 4);
ASSERT(word.kind() == LinkedWord::PLAIN_DATA);
word.set_to_symbol(LinkedWord::SYM_OFFSET, name);
word.set_to_symbol(subtract_one ? LinkedWord::SYM_VAL_OFFSET : LinkedWord::SYM_OFFSET, name);
}
/*!
@@ -312,6 +315,9 @@ void LinkedObjectFile::append_word_to_string(std::string& dest, const LinkedWord
case LinkedWord::SYM_OFFSET:
sprintf(buff, " .sym-off 0x%x %s\n", word.data >> 16, word.symbol_name().c_str());
break;
case LinkedWord::SYM_VAL_OFFSET:
sprintf(buff, " .sym-val-off 0x%x %s\n", word.data >> 16, word.symbol_name().c_str());
break;
default:
throw std::runtime_error("nyi");
}
+4 -1
View File
@@ -41,7 +41,10 @@ class LinkedObjectFile {
int source_offset,
const char* name,
LinkedWord::Kind kind);
void symbol_link_offset(int source_segment, int source_offset, const char* name);
void symbol_link_offset(int source_segment,
int source_offset,
const char* name,
bool subtract_one);
Function& get_function_at_label(int label_id);
Function* try_get_function_at_label(int label_id);
Function* try_get_function_at_label(const DecompilerLabel& label);
@@ -143,8 +143,8 @@ static uint32_t c_symlink2(LinkedObjectFile& f,
ASSERT((code_value & 0xffff) == 0 || (code_value & 0xffff) == 0xffff);
ASSERT(kind == SymbolLinkKind::SYMBOL);
// ASSERT(false); // this case does not occur in V2/V4. It does in V3.
f.symbol_link_offset(seg_id, code_ptr_offset - initial_offset, name);
f.symbol_link_offset(seg_id, code_ptr_offset - initial_offset, name,
(code_value & 0xffff) == 0xffff);
}
} while (data.at(link_ptr_offset));
@@ -197,9 +197,11 @@ static uint32_t c_symlink3(LinkedObjectFile& f,
f.symbol_link_word(seg, code_ptr - initial_offset, name, word_kind);
} else {
u16 lower = code_value & 0xffff;
ASSERT(lower == 0 || lower == 0xffff);
f.stats.v3_symbol_link_offset++;
ASSERT(kind == SymbolLinkKind::SYMBOL);
f.symbol_link_offset(seg, code_ptr - initial_offset, name);
f.symbol_link_offset(seg, code_ptr - initial_offset, name, lower == 0xffff);
}
} while (data.at(link_ptr));
+11 -9
View File
@@ -24,14 +24,15 @@ namespace decompiler {
class LinkedWord {
public:
enum Kind : u8 {
PLAIN_DATA, // just plain data
PTR, // pointer to a location
HI_PTR, // lower 16-bits of this data are the upper 16 bits of a pointer
LO_PTR, // lower 16-bits of this data are the lower 16 bits of a pointer
SYM_PTR, // this is a pointer to a symbol
EMPTY_PTR, // this is a pointer to the empty list
SYM_OFFSET, // this is an offset of a symbol in the symbol table
TYPE_PTR // this is a pointer to a type
PLAIN_DATA, // just plain data
PTR, // pointer to a location
HI_PTR, // lower 16-bits of this data are the upper 16 bits of a pointer
LO_PTR, // lower 16-bits of this data are the lower 16 bits of a pointer
SYM_PTR, // this is a pointer to a symbol
EMPTY_PTR, // this is a pointer to the empty list
SYM_OFFSET, // this is an offset of a symbol in the symbol table
SYM_VAL_OFFSET, // offset to the value of the symbol (different in jak 2)
TYPE_PTR // this is a pointer to a type
};
private:
@@ -46,7 +47,8 @@ class LinkedWord {
explicit LinkedWord(uint32_t _data) : data(_data) {}
bool holds_string() const {
return m_kind == SYM_PTR || m_kind == SYM_OFFSET || m_kind == TYPE_PTR;
return m_kind == SYM_PTR || m_kind == SYM_OFFSET || m_kind == TYPE_PTR ||
m_kind == SYM_VAL_OFFSET;
}
LinkedWord(const LinkedWord& other) {