Drop DEBUG requirement for d_m3EnableStrace >= 2

This commit is contained in:
Volodymyr Shymanskyy
2022-08-30 14:42:51 +03:00
parent 99cbf5144d
commit 3a144c0d39
2 changed files with 69 additions and 66 deletions
+1 -1
View File
@@ -86,7 +86,7 @@
# ifndef d_m3EnableStrace
# define d_m3EnableStrace 0 // 1 - trace exported function calls
// 2 - trace all calls (structured) - requires DEBUG
// 2 - trace all calls (structured)
// 3 - all calls + loops + memory operations
# endif
+68 -65
View File
@@ -9,6 +9,74 @@
#include "m3_info.h"
#include "m3_compile.h"
#if defined(DEBUG) || (d_m3EnableStrace >= 2)
size_t SPrintArg (char * o_string, size_t i_stringBufferSize, voidptr_t i_sp, u8 i_type)
{
int len = 0;
* o_string = 0;
if (i_type == c_m3Type_i32)
len = snprintf (o_string, i_stringBufferSize, "%" PRIi32, * (i32 *) i_sp);
else if (i_type == c_m3Type_i64)
len = snprintf (o_string, i_stringBufferSize, "%" PRIi64, * (i64 *) i_sp);
#if d_m3HasFloat
else if (i_type == c_m3Type_f32)
len = snprintf (o_string, i_stringBufferSize, "%" PRIf32, * (f32 *) i_sp);
else if (i_type == c_m3Type_f64)
len = snprintf (o_string, i_stringBufferSize, "%" PRIf64, * (f64 *) i_sp);
#endif
len = M3_MAX (0, len);
return len;
}
cstr_t SPrintFunctionArgList (IM3Function i_function, m3stack_t i_sp)
{
int ret;
static char string [256];
char * s = string;
ccstr_t e = string + sizeof(string) - 1;
ret = snprintf (s, e-s, "(");
s += M3_MAX (0, ret);
u64 * argSp = (u64 *) i_sp;
IM3FuncType funcType = i_function->funcType;
if (funcType)
{
u32 numArgs = funcType->numArgs;
for (u32 i = 0; i < numArgs; ++i)
{
u8 type = d_FuncArgType(funcType, i);
ret = snprintf (s, e-s, "%s: ", c_waTypes [type]);
s += M3_MAX (0, ret);
s += SPrintArg (s, e-s, argSp + i, type);
if (i != numArgs - 1) {
ret = snprintf (s, e-s, ", ");
s += M3_MAX (0, ret);
}
}
}
else printf ("null signature");
ret = snprintf (s, e-s, ")");
s += M3_MAX (0, ret);
return string;
}
#endif
#ifdef DEBUG
// a central function you can be breakpoint:
@@ -98,29 +166,6 @@ cstr_t SPrintFuncTypeSignature (IM3FuncType i_funcType)
}
size_t SPrintArg (char * o_string, size_t i_stringBufferSize, voidptr_t i_sp, u8 i_type)
{
int len = 0;
* o_string = 0;
if (i_type == c_m3Type_i32)
len = snprintf (o_string, i_stringBufferSize, "%" PRIi32, * (i32 *) i_sp);
else if (i_type == c_m3Type_i64)
len = snprintf (o_string, i_stringBufferSize, "%" PRIi64, * (i64 *) i_sp);
#if d_m3HasFloat
else if (i_type == c_m3Type_f32)
len = snprintf (o_string, i_stringBufferSize, "%" PRIf32, * (f32 *) i_sp);
else if (i_type == c_m3Type_f64)
len = snprintf (o_string, i_stringBufferSize, "%" PRIf64, * (f64 *) i_sp);
#endif
len = M3_MAX (0, len);
return len;
}
cstr_t SPrintValue (void * i_value, u8 i_type)
{
static char string [100];
@@ -128,48 +173,6 @@ cstr_t SPrintValue (void * i_value, u8 i_type)
return string;
}
cstr_t SPrintFunctionArgList (IM3Function i_function, m3stack_t i_sp)
{
int ret;
static char string [256];
char * s = string;
ccstr_t e = string + sizeof(string) - 1;
ret = snprintf (s, e-s, "(");
s += M3_MAX (0, ret);
u64 * argSp = (u64 *) i_sp;
IM3FuncType funcType = i_function->funcType;
if (funcType)
{
u32 numArgs = funcType->numArgs;
for (u32 i = 0; i < numArgs; ++i)
{
u8 type = d_FuncArgType(funcType, i);
ret = snprintf (s, e-s, "%s: ", c_waTypes [type]);
s += M3_MAX (0, ret);
s += SPrintArg (s, e-s, argSp + i, type);
if (i != numArgs - 1) {
ret = snprintf (s, e-s, ", ");
s += M3_MAX (0, ret);
}
}
}
else printf ("null signature");
ret = snprintf (s, e-s, ")");
s += M3_MAX (0, ret);
return string;
}
static
OpInfo find_operation_info (IM3Operation i_operation)
{