remove duplicate code for codegen calling convention

This commit is contained in:
matcool 2023-03-20 15:42:01 -03:00
parent 94138f32ad
commit 33a2883058
No known key found for this signature in database
GPG key ID: BF58756086D7AB1C

View file

@ -153,48 +153,6 @@ namespace codegen {
return fmt::format("{}", fmt::join(parameters, ", "));
}
inline std::string getConvention(Field& f) {
if (codegen::platform != Platform::Windows) return "DefaultConv";
if (auto fn = f.get_fn()) {
auto status = getStatus(f);
if (fn->is_static) {
if (status == BindStatus::Binded) return "x86::Cdecl";
else return "x86::Optcall";
}
else if (fn->is_virtual || fn->is_callback) {
return "x86::Thiscall";
}
else {
if (status == BindStatus::Binded) return "x86::Thiscall";
else return "x86::Membercall";
}
}
else throw codegen::error("Tried to get convention of non-function");
}
inline std::string getModifyConvention(Field& f) {
if (codegen::platform != Platform::Windows) return "tulip::hook::DefaultConvention";
if (auto fn = f.get_fn()) {
auto status = getStatus(f);
if (fn->is_static) {
if (status == BindStatus::Binded) return "tulip::hook::CdeclConvention";
else return "tulip::hook::OptcallConvention";
}
else if (fn->is_virtual || fn->is_callback) {
return "tulip::hook::ThiscallConvention";
}
else {
if (status == BindStatus::Binded) return "tulip::hook::ThiscallConvention";
else return "tulip::hook::MembercallConvention";
}
}
else throw codegen::error("Tried to get convention of non-function");
}
inline std::string getModifyConventionName(Field& f) {
if (codegen::platform != Platform::Windows) return "Default";
@ -216,6 +174,18 @@ namespace codegen {
else throw codegen::error("Tried to get convention of non-function");
}
inline std::string getConvention(Field& f) {
if (codegen::platform != Platform::Windows) return "DefaultConv";
return std::string("x86::") + getModifyConventionName(f);
}
inline std::string getModifyConvention(Field& f) {
if (codegen::platform != Platform::Windows) return "tulip::hook::DefaultConvention";
return std::string("tulip::hook::") + getModifyConventionName(f) + "Convention";
}
inline std::string getUnqualifiedClassName(std::string const& s) {
auto index = s.rfind("::");
if (index == std::string::npos) return s;