Fix 32-bit mode (x86)

extensions
Volodymyr Shymanskyy 5 years ago
parent 4f47043d16
commit 3defa25b2d

@ -13,6 +13,11 @@ if(CLANG_CL)
set(CMAKE_LINKER "lld-link")
endif()
if(M EQUAL 32)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
endif()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "set build type to Release")
endif()

@ -26,22 +26,13 @@ typedef uint8_t u8;
typedef int8_t i8;
#if __LP64__
typedef i64 m3reg_t;
typedef u64 m3word_t;
#else
typedef i32 m3reg_t;
typedef u32 m3word_t;
#endif
typedef const void * m3ret_t;
typedef const char * cstr_t;
typedef const char * const ccstr_t;
typedef const u8 * bytes_t;
typedef const u8 * const cbytes_t;
typedef i64 m3reg_t;
typedef u64 * m3stack_t;
typedef

@ -73,7 +73,7 @@ void FreeImportInfo (M3ImportInfo * i_info)
void InitRuntime (IM3Runtime io_runtime, u32 i_stackSizeInBytes)
{
m3Malloc (& io_runtime->stack, i_stackSizeInBytes);
io_runtime->numStackSlots = i_stackSizeInBytes / sizeof (m3word_t);
io_runtime->numStackSlots = i_stackSizeInBytes / sizeof (m3reg_t);
}
@ -448,9 +448,9 @@ _ (Call (i_function->compiled, stack, linearMemory, d_m3OpDefaultArgs));
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: %lu\n", *(u64*)(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: %lu\n", *(u64*)(stack)); break;
case c_m3Type_f64: printf("Result: %llu\n", *(u64*)(stack)); break;
#endif
default: _throw("unknown return type");
}

@ -39,7 +39,7 @@ typedef struct M3Function
cstr_t name;
m3word_t hits;
u32 hits;
IM3FuncType funcType;

@ -12,6 +12,7 @@
// some macros to emulate try/catch
#define EXC_PRINT //printf("Exc: %s:%d\n", __FILE__, __LINE__);
#define _try
#define _(TRY) { result = TRY; if (result) { EXC_PRINT; goto _catch; } }
#define _throw(ERROR) { result = ERROR; EXC_PRINT; goto _catch; }

@ -100,7 +100,7 @@ d_m3OpDef (Compile)
if (not result)
{
// patch up compiled pc and call rewriten op_Call
*((m3word_t *) --_pc) = (m3word_t) (function->compiled);
*((size_t *) --_pc) = (size_t) (function->compiled);
--_pc;
result = nextOp ();
}

@ -159,7 +159,11 @@ i32 m3_fwrite (void * i_ptr, i32 i_size, i32 i_count, FILE * i_file)
i32 m3_write (i32 i_fd, const void * i_data, i32 i_count)
{
#if defined(WIN32)
return 0;
#else
return (i32) write (i_fd, i_data, i_count);
#endif
}

@ -33,7 +33,7 @@ void m3_PrintRuntimeInfo (IM3Runtime i_runtime)
{
printf ("\n-- m3 runtime -------------------------------------------------\n");
printf (" stack-size: %lu \n\n", i_runtime->numStackSlots * sizeof (m3word_t));
printf (" stack-size: %lu \n\n", i_runtime->numStackSlots * sizeof (m3reg_t));
u32 moduleIndex = 0;
ForEachModule (i_runtime, (ModuleVisitor) v_PrintEnvModuleInfo, & moduleIndex);

@ -96,7 +96,7 @@ IM3Function Module_GetFunction (IM3Module i_module, u32 i_functionIndex)
}
M3Result Module_EnsureMemorySize (IM3Module i_module, M3Memory * io_memory, m3word_t i_memorySize)
M3Result Module_EnsureMemorySize (IM3Module i_module, M3Memory * io_memory, size_t i_memorySize)
{
M3Result result = c_m3Err_none;
@ -119,11 +119,11 @@ M3Result Module_EnsureMemorySize (IM3Module i_module, M3Memory * io_memory, m3
size_t extra = c_m3MemPageSize * pages + 900000 * 4 + sizeof (M3MemoryHeader);
m3word_t alignedSize = i_memorySize + extra;
size_t alignedSize = i_memorySize + extra;
if (c_m3AlignWasmMemoryToPages)
{
m3word_t aligner = c_m3MemPageSize - 1;
size_t aligner = c_m3MemPageSize - 1;
alignedSize += aligner;
alignedSize &= ~aligner;
}

@ -11,7 +11,7 @@
#include "m3_env.h"
M3Result Module_EnsureMemorySize (IM3Module i_module, IM3Memory io_memory, m3word_t i_memorySize);
M3Result Module_EnsureMemorySize (IM3Module i_module, IM3Memory io_memory, size_t i_memorySize);
i32 AllocateHeap (M3Memory * io_memory, i32 i_size);

Loading…
Cancel
Save