mirror of https://git.suyu.dev/suyu/suyu
				
				
				
			
			You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			33 lines
		
	
	
		
			889 B
		
	
	
	
		
			C++
		
	
			
		
		
	
	
			33 lines
		
	
	
		
			889 B
		
	
	
	
		
			C++
		
	
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
 | 
						|
// SPDX-License-Identifier: GPL-2.0-or-later
 | 
						|
 | 
						|
#pragma once
 | 
						|
 | 
						|
#include <string>
 | 
						|
 | 
						|
namespace llvm {
 | 
						|
char* itaniumDemangle(const char* mangled_name, char* buf, size_t* n, int* status);
 | 
						|
}
 | 
						|
 | 
						|
namespace Common {
 | 
						|
std::string DemangleSymbol(const std::string& mangled) {
 | 
						|
    auto is_itanium = [](const std::string& name) -> bool {
 | 
						|
        // A valid Itanium encoding requires 1-4 leading underscores, followed by 'Z'.
 | 
						|
        auto pos = name.find_first_not_of('_');
 | 
						|
        return pos > 0 && pos <= 4 && name[pos] == 'Z';
 | 
						|
    };
 | 
						|
 | 
						|
    char* demangled = nullptr;
 | 
						|
    if (is_itanium(mangled)) {
 | 
						|
        demangled = llvm::itaniumDemangle(mangled.c_str(), nullptr, nullptr, nullptr);
 | 
						|
    }
 | 
						|
 | 
						|
    if (!demangled) {
 | 
						|
        return mangled;
 | 
						|
    }
 | 
						|
 | 
						|
    std::string ret = demangled;
 | 
						|
    std::free(demangled);
 | 
						|
    return ret;
 | 
						|
}
 | 
						|
} // namespace Common
 |