mirror of
https://github.com/open-goal/jak-project
synced 2026-07-09 14:55:51 -04:00
[decompiler] detect cpad-hold? and cpad-pressed? (#986)
* [decompiler] detect `cpad-hold?` and `cpad-pressed?` * cleanup cpad macro button lookup * better * fix
This commit is contained in:
@@ -163,6 +163,13 @@ Matcher Matcher::any_constant_token(int match_id) {
|
||||
return m;
|
||||
}
|
||||
|
||||
Matcher Matcher::constant_token(const std::string& name) {
|
||||
Matcher m;
|
||||
m.m_kind = Kind::CONSTANT_TOKEN;
|
||||
m.m_str = name;
|
||||
return m;
|
||||
}
|
||||
|
||||
Matcher Matcher::begin(const std::vector<Matcher>& elts) {
|
||||
Matcher m;
|
||||
m.m_kind = Kind::BEGIN;
|
||||
@@ -303,6 +310,14 @@ bool Matcher::do_match(Form* input, MatchResult::Maps* maps_out) const {
|
||||
}
|
||||
} break;
|
||||
|
||||
case Kind::CONSTANT_TOKEN: {
|
||||
auto as_ct = input->try_as_element<ConstantTokenElement>();
|
||||
if (as_ct) {
|
||||
return as_ct->value() == m_str;
|
||||
}
|
||||
return false;
|
||||
} break;
|
||||
|
||||
case Kind::CAST: {
|
||||
auto as_cast = dynamic_cast<CastElement*>(input->try_as_single_active_element());
|
||||
if (as_cast) {
|
||||
@@ -616,6 +631,13 @@ DerefTokenMatcher DerefTokenMatcher::any_string(int match_id) {
|
||||
return result;
|
||||
}
|
||||
|
||||
DerefTokenMatcher DerefTokenMatcher::any_integer(int match_id) {
|
||||
DerefTokenMatcher result;
|
||||
result.m_kind = Kind::ANY_INTEGER;
|
||||
result.m_str_out_id = match_id;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool DerefTokenMatcher::do_match(const DerefToken& input, MatchResult::Maps* maps_out) const {
|
||||
switch (m_kind) {
|
||||
case Kind::STRING:
|
||||
@@ -630,6 +652,14 @@ bool DerefTokenMatcher::do_match(const DerefToken& input, MatchResult::Maps* map
|
||||
return false;
|
||||
case Kind::CONSTANT_INTEGER:
|
||||
return input.kind() == DerefToken::Kind::INTEGER_CONSTANT && input.is_int(m_int);
|
||||
case Kind::ANY_INTEGER:
|
||||
if (input.kind() == DerefToken::Kind::INTEGER_CONSTANT) {
|
||||
if (m_str_out_id != -1) {
|
||||
maps_out->ints[m_str_out_id] = input.int_constant();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
default:
|
||||
assert(false);
|
||||
return false;
|
||||
@@ -694,4 +724,4 @@ bool GenericOpMatcher::do_match(GenericOperator& input, MatchResult::Maps* maps_
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace decompiler
|
||||
} // namespace decompiler
|
||||
|
||||
Reference in New Issue
Block a user