Use printf-like format in JitRegister::Register

The API is cleaner (no more magic default parameter) and more
extensible like this.
This commit is contained in:
Gabriel Corona 2014-12-29 01:09:07 +01:00
parent beaa9905a6
commit a957f93532
5 changed files with 19 additions and 16 deletions

View File

@ -72,18 +72,17 @@ void Shutdown()
}
void Register(const void* base_address, u32 code_size,
const char* name, u32 original_address)
const char* format, ...)
{
#if !(defined USE_OPROFILE && USE_OPROFILE) && !defined(USE_VTUNE)
if (!s_perf_map_file.IsOpen())
return;
#endif
std::string symbol_name;
if (original_address)
symbol_name = StringFromFormat("%s_%x", name, original_address);
else
symbol_name = name;
va_list args;
va_start(args, format);
std::string symbol_name = StringFromFormatV(format, args);
va_end(args);
#if defined USE_OPROFILE && USE_OPROFILE
op_write_native_code(s_agent, symbol_name.data(), (u64)base_address,

View File

@ -11,6 +11,6 @@ namespace JitRegister
void Init();
void Shutdown();
void Register(const void* base_address, u32 code_size,
const char* name, u32 original_address=0);
const char* format, ...);
}

View File

@ -95,28 +95,30 @@ bool CharArrayFromFormatV(char* out, int outsize, const char* format, va_list ar
std::string StringFromFormat(const char* format, ...)
{
va_list args;
va_start(args, format);
std::string res = StringFromFormatV(format, args);
va_end(args);
return std::move(res);
}
std::string StringFromFormatV(const char* format, va_list args)
{
char *buf = nullptr;
#ifdef _WIN32
int required = 0;
va_start(args, format);
required = _vscprintf(format, args);
int required = _vscprintf(format, args);
buf = new char[required + 1];
CharArrayFromFormatV(buf, required + 1, format, args);
va_end(args);
std::string temp = buf;
delete[] buf;
#else
va_start(args, format);
if (vasprintf(&buf, format, args) < 0)
ERROR_LOG(COMMON, "Unable to allocate memory for string");
va_end(args);
std::string temp = buf;
free(buf);
#endif
return temp;
return std::move(temp);
}
// For Debugging. Read out an u8 array.

View File

@ -13,6 +13,8 @@
#include "Common/Common.h"
std::string StringFromFormatV(const char* format, va_list args);
std::string StringFromFormat(const char* format, ...)
#if !defined _WIN32
// On compilers that support function attributes, this gives StringFromFormat

View File

@ -144,7 +144,7 @@ using namespace Gen;
}
JitRegister::Register(blockCodePointers[block_num], b.codeSize,
"JIT_PPC", b.originalAddress);
"JIT_PPC_%08x", b.originalAddress);
}
const u8 **JitBaseBlockCache::GetCodePointers()