[decompiler] maybe fix symbol decompile issue (#776)

* maybe fix symbol decompile issue

* try again on a label

* allow int to float on seconds
This commit is contained in:
water111
2021-08-21 10:20:55 -04:00
committed by GitHub
parent b8d55d9fa3
commit 30d1e1d6c9
4 changed files with 27 additions and 8 deletions
+16
View File
@@ -549,6 +549,22 @@ FormElement* make_label_load(int label_idx,
}
}
if (load_kind != LoadVarOp::Kind::FLOAT && load_size == 8) {
if ((int)env.file->words_by_seg.at(label.target_segment).size() > (label.offset / 4) + 1) {
assert((label.offset % 8) == 0);
auto word0 = env.file->words_by_seg.at(label.target_segment).at(label.offset / 4);
auto word1 = env.file->words_by_seg.at(label.target_segment).at(1 + (label.offset / 4));
assert(word0.kind == LinkedWord::PLAIN_DATA);
assert(word1.kind == LinkedWord::PLAIN_DATA);
u64 value;
memcpy(&value, &word0.data, 4);
memcpy(((u8*)&value) + 4, &word1.data, 4);
return pool.alloc_element<CastElement>(TypeSpec("uint"),
pool.alloc_single_element_form<SimpleAtomElement>(
nullptr, SimpleAtom::make_int_constant(value)));
}
}
return nullptr;
}
+1 -1
View File
@@ -1800,7 +1800,7 @@ void SimpleExpressionElement::update_from_stack_int_to_float(const Env& env,
auto fpr_convert_matcher =
Matcher::op(GenericOpMatcher::fixed(FixedOperatorKind::GPR_TO_FPR), {Matcher::any(0)});
auto type = env.get_types_before_op(var.idx()).get(var.reg()).typespec();
if (type == TypeSpec("int") || type == TypeSpec("uint")) {
if (type == TypeSpec("int") || type == TypeSpec("uint") || type == TypeSpec("seconds")) {
auto mr = match(fpr_convert_matcher, arg);
if (mr.matched) {
arg = mr.maps.forms.at(0);
+9 -6
View File
@@ -588,12 +588,6 @@ goos::Object decompile_structure(const TypeSpec& type,
continue;
}
// OK - READ THE FIELD:
for (int i = field_start; i < field_end; i++) {
// even if our field was partially zero, we mark those zero bytes as "has data".
field_status_per_byte.at(i) = HAS_DATA_READ;
}
// first, let's see if it's a value or reference
auto field_type_info = ts.lookup_type(field.type());
if (!field_type_info->is_reference()) {
@@ -627,6 +621,9 @@ goos::Object decompile_structure(const TypeSpec& type,
field.name(), sp_field_init_spec_decompile(obj_words, labels, label.target_segment,
field_start, ts, field, words, file));
} else {
if (obj_words.at(field_start / 4).kind != LinkedWord::PLAIN_DATA) {
continue;
}
std::vector<u8> bytes_out;
for (int byte_idx = field_start; byte_idx < field_end; byte_idx++) {
bytes_out.push_back(obj_words.at(byte_idx / 4).get_byte(byte_idx % 4));
@@ -758,6 +755,12 @@ goos::Object decompile_structure(const TypeSpec& type,
}
}
}
// OK - READ THE FIELD:
for (int i = field_start; i < field_end; i++) {
// even if our field was partially zero, we mark those zero bytes as "has data".
field_status_per_byte.at(i) = HAS_DATA_READ;
}
}
for (size_t i = 0; i < field_status_per_byte.size(); i++) {
+1 -1
View File
@@ -31,7 +31,7 @@
;; WARN: Unsupported inline assembly instruction kind - [sync.p]
(defun disable-irq ()
(local-vars (v0-0 int))
(let ((v1-0 (l.d L21)))
(let ((v1-0 (the-as uint #xfffffffe)))
(.mfc0 v0-0 Status)
(let ((v0-1 (logand v0-0 v1-0)))
(.mtc0 Status v0-1)