Fix some warnings

extensions
Volodymyr Shymanskyy 5 years ago
parent ef59f8b2bf
commit 2ee36d51e2

@ -34,6 +34,7 @@
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
typedef const char * M3Result;
@ -54,7 +55,7 @@ typedef struct M3ErrorInfo
const char * file;
uint32_t line;
char message [1024];
char message [256];
}
M3ErrorInfo;

@ -52,7 +52,7 @@ m3ret_t PushArg_p##INDEX (d_m3BindingArgList, M3State * _state) \
}
//printf ("push ptr: r%d off: %d\n", INDEX, offset);
//printf ("push [%d]: %lld\n", INDEX, _i##INDEX);
//printf ("push [%d]: %" PRId64 "\n", INDEX, _i##INDEX);
#define d_argPusherInt(INDEX) \
m3ret_t PushArg_i##INDEX (d_m3BindingArgList, M3State * _state) \
{ \

@ -635,7 +635,7 @@ M3Result Compile_Const_i32 (IM3Compilation o, u8 i_opcode)
M3Result result;
i32 value;
_ (ReadLEB_i32 (& value, & o->wasm, o->wasmEnd)); m3log (compile, d_indent "%s (const i32 = %d)", GetIndentionString (o), value);
_ (ReadLEB_i32 (& value, & o->wasm, o->wasmEnd)); m3log (compile, d_indent "%s (const i32 = %" PRIi32 ")", GetIndentionString (o), value);
_ (PushConst (o, value, c_m3Type_i32));
@ -648,7 +648,7 @@ M3Result Compile_Const_i64 (IM3Compilation o, u8 i_opcode)
M3Result result;
i64 value;
_ (ReadLEB_i64 (& value, & o->wasm, o->wasmEnd)); m3log (compile, d_indent "%s (const i32 = %lld)", GetIndentionString (o), value);
_ (ReadLEB_i64 (& value, & o->wasm, o->wasmEnd)); m3log (compile, d_indent "%s (const i64 = %" PRIi64 ")", GetIndentionString (o), value);
_ (PushConst (o, value, c_m3Type_i64));
@ -661,12 +661,14 @@ M3Result Compile_Const_f32 (IM3Compilation o, u8 i_opcode)
M3Result result;
_try {
u32 value;
_ (ReadLEB_u32 (& value, & o->wasm, o->wasmEnd)); m3log (compile, d_indent "%s (const f32 = %f)", GetIndentionString (o), * ((f32 *) & value));
union { u32 u; f32 f; } union32;
union { u64 u; f64 f; } union64;
// convert to double
f64 f = * (f32 *) & value;
_ (PushConst (o, * (u64 *) & f, c_m3Type_f64));
_ (ReadLEB_u32 (& union32.u, & o->wasm, o->wasmEnd)); m3log (compile, d_indent "%s (const f32 = %f)", GetIndentionString (o), * ((f32 *) & value));
union64.f = union32.f; // convert to double
_ (PushConst (o, union64.u, c_m3Type_f64));
} _catch: return result;
}
@ -1616,7 +1618,7 @@ _ (IsLocalReferencedWithCurrentBlock (o, & preserveToSlot, i));
if (preserveToSlot != i)
{
printf ("preserving local: %d to slot: %d\n", i, preserveToSlot);
// printf ("preserving local: %d to slot: %d\n", i, preserveToSlot);
m3NotImplemented();
}
}

@ -19,8 +19,8 @@
# warning "Compiler not detected"
# endif
# ifndef d_m3CodePageSize
# define d_m3MaxNumFunctionArgs 32
# ifndef d_m3MaxNumFunctionArgs
# define d_m3MaxNumFunctionArgs 16
# endif
# ifndef d_m3CodePageSize
# define d_m3CodePageSize 4096
@ -46,7 +46,8 @@
# endif
# ifndef d_m3FixedHeap
# define d_m3FixedHeap 0
# define d_m3FixedHeap false
//# define d_m3FixedHeap (32*1024)
# endif
# ifndef d_m3FixedHeapAlign

@ -86,56 +86,56 @@ static const char * m3LogTruncFilename (const char * i_file)
# if d_m3LogParse
# define m3log_parse(CATEGORY, FMT, ...) d_m3Log(CATEGORY, FMT, ##__VA_ARGS__)
# else
# define m3log_parse(...)
# define m3log_parse(...) {}
# endif
# if d_m3LogCompile
# define m3log_compile(CATEGORY, FMT, ...) d_m3Log(CATEGORY, FMT, ##__VA_ARGS__)
# else
# define m3log_compile(...)
# define m3log_compile(...) {}
# endif
# if d_m3LogStack
# define m3log_stack(CATEGORY, FMT, ...) d_m3Log(CATEGORY, FMT, ##__VA_ARGS__)
# else
# define m3log_stack(...)
# define m3log_stack(...) {}
# endif
# if d_m3LogEmit
# define m3log_emit(CATEGORY, FMT, ...) d_m3Log(CATEGORY, FMT, ##__VA_ARGS__)
# else
# define m3log_emit(...)
# define m3log_emit(...) {}
# endif
# if d_m3LogCodePages
# define m3log_code(CATEGORY, FMT, ...) d_m3Log(CATEGORY, FMT, ##__VA_ARGS__)
# else
# define m3log_code(...)
# define m3log_code(...) {}
# endif
# if d_m3LogModule
# define m3log_module(CATEGORY, FMT, ...) d_m3Log(CATEGORY, FMT, ##__VA_ARGS__)
# else
# define m3log_module(...)
# define m3log_module(...) {}
# endif
# if d_m3LogRuntime
# define m3log_runtime(CATEGORY, FMT, ...) d_m3Log(CATEGORY, FMT, ##__VA_ARGS__)
# else
# define m3log_runtime(...)
# define m3log_runtime(...) {}
# endif
# if d_m3LogExec
# define m3log_exec(CATEGORY, FMT, ...) d_m3Log(CATEGORY, FMT, ##__VA_ARGS__)
# else
# define m3log_exec(...)
# define m3log_exec(...) {}
# endif
# define m3log(CATEGORY, FMT, ...) m3log_##CATEGORY (CATEGORY, FMT "\n", ##__VA_ARGS__)
# define m3logif(CATEGORY, STATEMENT) m3log_##CATEGORY (CATEGORY, ""); if (d_m3Log_##CATEGORY) { STATEMENT; printf ("\n"); }
# else
# define m3log(CATEGORY, FMT, ...)
# define m3logif(CATEGORY, STATEMENT)
# define m3log(CATEGORY, FMT, ...) {}
# define m3logif(CATEGORY, STATEMENT) {}
# endif

@ -15,7 +15,7 @@
#include "m3_exec.h"
#include "m3_exception.h"
ccstr_t GetFunctionName (IM3Function i_function)
cstr_t GetFunctionName (IM3Function i_function)
{
return (i_function->name) ? i_function->name : ".unnamed";
}
@ -172,11 +172,11 @@ M3Result EvaluateExpression (IM3Module i_module, void * o_expressed, u8 i_type
{
if (SizeOfType (i_type) == sizeof (u32))
{
* (u32 *) o_expressed = * (u32 *) stack;
* (u32 *) o_expressed = *stack & 0xFFFFFFFF;
}
else if (SizeOfType (i_type) == sizeof (u64))
{
* (u64 *) o_expressed = * (u64 *) stack;
* (u64 *) o_expressed = *stack;
}
}
}
@ -185,7 +185,7 @@ M3Result EvaluateExpression (IM3Module i_module, void * o_expressed, u8 i_type
}
else result = c_m3Err_mallocFailedCodePage;
rt.stack = NULL; // prevent free(stack) in ReleaseRuntime ()
rt.stack = NULL; // prevent free(stack) in ReleaseRuntime
ReleaseRuntime (& rt);
i_module->runtime = savedRuntime;
@ -435,21 +435,27 @@ _ ((M3Result)Call (i_function->compiled, stack, linearMemory, d_m3OpDefaultArgs
switch (ftype->returnType) {
case c_m3Type_none: break;
#ifdef USE_HUMAN_FRIENDLY_ARGS
case c_m3Type_i32: printf("Result: %ld\n", *(i32*)(stack)); break;
case c_m3Type_i64: printf("Result: %lld\n", *(i64*)(stack)); break;
case c_m3Type_i32: printf("Result: %" PRIi32 "\n", *(i32*)(stack)); break;
case c_m3Type_i64: printf("Result: %" PRIi64 "\n", *(i64*)(stack)); break;
case c_m3Type_f32: printf("Result: %f\n", *(f32*)(stack)); break;
case c_m3Type_f64: printf("Result: %lf\n", *(f64*)(stack)); break;
#else
case c_m3Type_i32: printf("Result: %u\n", *(u32*)(stack)); break;
case c_m3Type_i64: printf("Result: %llu\n", *(u64*)(stack)); break;
case c_m3Type_f32: { f32 val = *(f64*)(stack); printf("Result: %u\n", *(u32*)&val ); } break;
case c_m3Type_f64: printf("Result: %llu\n", *(u64*)(stack)); break;
case c_m3Type_f32: {
union { u32 u; f32 f; } union32;
union32.f = *(f64*)(stack);
printf("Result: %u\n", union32.u );
break;
}
case c_m3Type_i64:
case c_m3Type_f64:
printf("Result: %" PRIu64 "\n", *(u64*)(stack)); break;
#endif
default: _throw("unknown return type");
}
//u64 value = * (u64 *) (stack);
//m3log (runtime, "return64: %llu return32: %u", value, (u32) value);
//m3log (runtime, "return64: %" PRIu64 " return32: %u", value, (u32) value);
}
else _throw (c_m3Err_missingCompiledCode);
@ -500,8 +506,8 @@ _ (Module_EnsureMemorySize (module, & i_function->module->memory, 3000000));
_ ((M3Result)Call (i_function->compiled, stack, linearMemory, d_m3OpDefaultArgs));
u64 value = * (u64 *) (stack);
m3log (runtime, "return64: %llu return32: %u", value, (u32) value);
//u64 value = * (u64 *) (stack);
//m3log (runtime, "return64: % " PRIu64 " return32: %" PRIu32, value, (u32) value);
}
else _throw (c_m3Err_missingCompiledCode);
@ -574,7 +580,7 @@ M3Result m3Error (M3Result i_result, IM3Runtime i_runtime, IM3Module i_module,
va_list args;
va_start (args, i_errorMessage);
vsnprintf (info.message, 1023, i_errorMessage, args);
vsnprintf (info.message, sizeof(info.message), i_errorMessage, args);
va_end (args);
i_runtime->error = info;

@ -58,14 +58,14 @@ M3Function;
typedef M3Function * IM3Function;
ccstr_t GetFunctionName (IM3Function i_function);
cstr_t GetFunctionName (IM3Function i_function);
u32 GetFunctionNumArgs (IM3Function i_function);
u32 GetFunctionNumReturns (IM3Function i_function);
u8 GetFunctionReturnType (IM3Function i_function);
u32 GetFunctionNumArgsAndLocals (IM3Function i_function);
ccstr_t SPrintFunctionArgList (IM3Function i_function, m3stack_t i_sp);
cstr_t SPrintFunctionArgList (IM3Function i_function, m3stack_t i_sp);
//---------------------------------------------------------------------------------------------------------------------------------

@ -15,7 +15,7 @@ m3ret_t ReportOutOfBoundsMemoryError (pc_t i_pc, u8 * i_mem, u32 i_offset)
M3MemoryHeader * info = (M3MemoryHeader *) (i_mem - sizeof (M3MemoryHeader));
u8 * mem8 = i_mem + i_offset;
ErrorModule (c_m3Err_trapOutOfBoundsMemoryAccess, info->module, "memory bounds: [%p %p); accessed: %p; offset: %u overflow: %lld bytes", i_mem, info->end, mem8, i_offset, mem8 - (u8 *) info->end);
ErrorModule (c_m3Err_trapOutOfBoundsMemoryAccess, info->module, "memory bounds: [%p %p); accessed: %p; offset: %u overflow: %zd bytes", i_mem, info->end, mem8, i_offset, mem8 - (u8 *) info->end);
return c_m3Err_trapOutOfBoundsMemoryAccess;
}
@ -151,7 +151,7 @@ d_m3OpDef (DumpStack)
cstr_t funcName = (function) ? function->name : "";
printf (" %4d ", opcodeIndex);
printf (" %-25s r0: 0x%016llx i:%lld u:%llu \n", funcName, _r0, _r0, _r0);
printf (" %-25s r0: 0x%016" PRIx64 " i:%" PRIi64 " u:%" PRIu64 "\n", funcName, _r0, _r0, _r0);
printf (" fp0: %lf \n", _fp0);
u64 * sp = _sp;
@ -162,7 +162,7 @@ d_m3OpDef (DumpStack)
cstr_t kind = "";
printf ("%5s %2d: 0x%llx %lld\n", kind, i, (u64) *(sp), (i64) *sp);
printf ("%5s %2d: 0x%" PRIx64 " %" PRIi64 "\n", kind, i, (u64) *(sp), (i64) *sp);
++sp;
}
@ -232,7 +232,7 @@ d_m3OpDef (If_r)
{
i32 condition = (i32) _r0;
immediate (pc_t); // empty preservation chain
skip_immediate (pc_t); // empty preservation chain
pc_t elsePC = immediate (pc_t);
@ -247,7 +247,7 @@ d_m3OpDef (If_s)
{
i32 condition = slot (i32);
immediate (pc_t); // empty preservation chain
skip_immediate (pc_t); // empty preservation chain
pc_t elsePC = immediate (pc_t);

@ -28,6 +28,7 @@
# define d_m3OpDecl(NAME) d_m3OpDef (NAME);
# define immediate(TYPE) * ((TYPE *) _pc++)
# define skip_immediate(TYPE) (void)* ((TYPE *) _pc++)
# define slot(TYPE) * (TYPE *) (_sp + immediate (i32))
@ -328,16 +329,17 @@ d_m3FpToFpConvertOp (f32, Demote)
#define d_m3ReinterpretOp(REG, TO, SRC, FROM, CAST) \
d_m3Op(TO##_Reinterpret_##CAST##_r) \
{ \
const CAST copy = (FROM)SRC; \
REG = *(TO*)&copy; \
union { CAST c; TO t; } u; \
u.c = (FROM)SRC; \
REG = u.t; \
return nextOp (); \
} \
\
d_m3Op(TO##_Reinterpret_##CAST##_s) \
{ \
FROM * stack = (FROM *) (_sp + immediate (i32)); \
const CAST copy = (* stack); \
REG = *(TO*)&copy; \
union { CAST c; TO t; } u; \
u.c = *(FROM *) (_sp + immediate (i32)); \
REG = u.t; \
return nextOp (); \
}
@ -545,7 +547,7 @@ d_m3Op (GetGlobal)
{
i64 * global = immediate (i64 *);
// printf ("get global: %p %lld\n", global, *global);
// printf ("get global: %p %" PRIi64 "\n", global, *global);
i32 offset = immediate (i32);
* (_sp + offset) = * global;
@ -569,7 +571,7 @@ d_m3Op (SetGlobal_i)
i64 * global = immediate (i64 *);
* global = _r0;
// printf ("set global: %p %lld\n", global, _r0);
// printf ("set global: %p %" PRIi64 "\n", global, _r0);
return nextOp ();
}
@ -589,7 +591,7 @@ d_m3Op (CopySlot)
u64 * dst = _sp + immediate (i32);
u64 * src = _sp + immediate (i32);
* dst = * src; // printf ("copy: %p <- %lld <- %p\n", dst, * dst, src);
* dst = * src; // printf ("copy: %p <- %" PRIi64 " <- %p\n", dst, * dst, src);
return nextOp ();
}

@ -90,7 +90,7 @@ size_t SPrintArg (char * o_string, size_t i_n, m3stack_t i_sp, u8 i_type)
}
ccstr_t SPrintFunctionArgList (IM3Function i_function, m3stack_t i_sp)
cstr_t SPrintFunctionArgList (IM3Function i_function, m3stack_t i_sp)
{
static char string [256];
@ -173,7 +173,7 @@ void DecodeOperation (char * o_string, u8 i_opcode, IM3OpInfo i_opInfo, pc_t *
case 0xbf+1:
{
value = fetch (u64); offset = fetch (i32);
sprintf (o_string, " slot [%d] = %llu", offset, value);
sprintf (o_string, " slot [%d] = %" PRIu64, offset, value);
break;
}

@ -475,7 +475,10 @@ M3Result ParseModuleSection (M3Module * o_module, u8 i_sectionType, bytes_t i_
cbytes_t end = i_bytes + i_numBytes;
result = parser (o_module, i_bytes, end);
}
else m3log (parse, "<skipped (id: %d)>", (u32) i_sectionType);
else
{
m3log (parse, "<skipped (id: %d)>", (u32) i_sectionType);
}
return result;
}

Loading…
Cancel
Save