Merge branch 'multivalue-prep' into main

extensions
Steven Massey 3 years ago
commit 0dbc617a23

@ -95,7 +95,7 @@ _ (Module_AddFunction (i_module, funcTypeIndex, NULL));
if (i_doCompilation and not i_module->runtime)
_throw ("module must be loaded into runtime to compile function");
_ (Compile_Function (function));
_ (CompileFunction (function));
_catch:
m3_Free (ftype);

File diff suppressed because it is too large Load Diff

@ -46,10 +46,11 @@ enum
// since the end location of a block is unknown when a branch is compiled, writing
// the actual address must deferred. A linked-list of patch locations is kept in
// M3CompilationScope. When the block compilation exits, it patches these addresses.
// this data structure is embedded into the code pages themselves
typedef struct M3BranchPatch
{
pc_t location;
struct M3BranchPatch * next;
pc_t * location;
}
M3BranchPatch;
@ -64,6 +65,7 @@ typedef struct M3CompilationScope
IM3BranchPatch patches;
i32 depth;
i16 initStackIndex;
u16 topSlot;
IM3FuncType type;
m3opcode_t opcode;
bool isPolymorphic;
@ -87,8 +89,6 @@ typedef struct
IM3CodePage page;
IM3BranchPatch releasedPatches;
#ifdef DEBUG
u32 numEmits;
u32 numOpcodes;
@ -175,19 +175,19 @@ u8 GetSingleRetType(IM3FuncType ftype) {
//-----------------------------------------------------------------------------------------------------------------------------------
u16 GetTypeNumSlots (u8 i_type);
void AlignSlotIndexToType (u16 * io_slotIndex, u8 i_type);
void AlignSlotToType (u16 * io_slotIndex, u8 i_type);
bool IsRegisterAllocated (IM3Compilation o, u32 i_register);
bool IsRegisterLocation (i16 i_location);
bool IsFpRegisterLocation (i16 i_location);
bool IsIntRegisterLocation (i16 i_location);
bool IsRegisterSlotAlias (i16 i_slot);
bool IsFpRegisterSlotAlias (i16 i_slot);
bool IsIntRegisterSlotAlias (i16 i_slot);
bool IsStackPolymorphic (IM3Compilation o);
M3Result CompileBlock (IM3Compilation io, IM3FuncType i_blockType, m3opcode_t i_blockOpcode);
M3Result Compile_BlockStatements (IM3Compilation io);
M3Result Compile_Function (IM3Function io_function);
M3Result CompileBlockStatements (IM3Compilation io);
M3Result CompileFunction (IM3Function io_function);
u16 GetMaxUsedSlotPlusOne (IM3Compilation o);

@ -240,7 +240,8 @@ M3Result ReadLEB_i32 (i32 * o_value, bytes_t * io_bytes, cbytes_t
M3Result ReadLEB_i64 (i64 * o_value, bytes_t * io_bytes, cbytes_t i_end);
M3Result Read_utf8 (cstr_t * o_utf8, bytes_t * io_bytes, cbytes_t i_end);
size_t SPrintArg (char * o_string, size_t i_n, m3stack_t i_sp, u8 i_type);
cstr_t SPrintValue (void * i_value, u8 i_type);
size_t SPrintArg (char * o_string, size_t i_stringBufferSize, m3stack_t i_sp, u8 i_type);
void ReportError (IM3Runtime io_runtime, IM3Module i_module, IM3Function i_function, ccstr_t i_errorMessage, ccstr_t i_file, u32 i_lineNum);

@ -221,20 +221,6 @@ void * _FreeModule (IM3Module i_module, void * i_info)
}
void FreeCompilationPatches (IM3Compilation o)
{
IM3BranchPatch patches = o->releasedPatches;
while (patches)
{
IM3BranchPatch next = patches->next;
m3_Free (patches);
patches = next;
}
}
void Runtime_Release (IM3Runtime i_runtime)
{
ForEachModule (i_runtime, _FreeModule, NULL); d_m3Assert (i_runtime->numActiveCodePages == 0);
@ -242,8 +228,6 @@ void Runtime_Release (IM3Runtime i_runtime)
Environment_ReleaseCodePages (i_runtime->environment, i_runtime->pagesOpen);
Environment_ReleaseCodePages (i_runtime->environment, i_runtime->pagesFull);
FreeCompilationPatches (& i_runtime->compilation);
m3_Free (i_runtime->stack);
m3_Free (i_runtime->memory.mallocated);
}
@ -307,8 +291,8 @@ M3Result EvaluateExpression (IM3Module i_module, void * o_expressed, u8 i_type
m3ret_t r = Call (m3code, stack, NULL, d_m3OpDefaultArgs);
if (r == 0)
{
if (SizeOfType (i_type) == sizeof (u32))
{ m3log (runtime, "expression result: %s", SPrintValue (stack, i_type));
if (SizeOfType (i_type) == sizeof (u32))
{
* (u32 *) o_expressed = * ((u32 *) stack);
}
@ -535,7 +519,7 @@ M3Result m3_RunStart (IM3Module io_module)
if (not function->compiled)
{
_ (Compile_Function (function));
_ (CompileFunction (function));
}
IM3FuncType ftype = function->funcType;
@ -691,7 +675,7 @@ M3Result m3_FindFunction (IM3Function * o_function, IM3Runtime i_runtime, cons
{
if (not function->compiled)
{
_ (Compile_Function (function))
_ (CompileFunction (function))
}
// Check if start function needs to be called

@ -13,12 +13,8 @@
# if d_m3EnableExceptionBreakpoint
// a central function you can be breakpoint:
static void ExceptionBreakpoint (cstr_t i_exception, cstr_t i_message)
{
printf ("\nexception: '%s' @ %s\n", i_exception, i_message);
return;
}
// declared in m3_info.c
void ExceptionBreakpoint (cstr_t i_exception, cstr_t i_message);
# define EXCEPTION_PRINT(ERROR) ExceptionBreakpoint (ERROR, (__FILE__ ":" M3_STR(__LINE__)))

@ -552,7 +552,7 @@ d_m3Op (CallIndirect)
if (LIKELY(type == function->funcType))
{
if (UNLIKELY(not function->compiled))
r = Compile_Function (function);
r = CompileFunction (function);
if (LIKELY(not r))
{
@ -700,7 +700,7 @@ d_m3Op (Compile)
m3ret_t result = m3Err_none;
if (UNLIKELY(not function->compiled)) // check to see if function was compiled since this operation was emitted.
result = Compile_Function (function);
result = CompileFunction (function);
if (not result)
{
@ -1106,28 +1106,32 @@ d_m3Op (BranchIf_s)
}
// branching to blocks that produce a (int) value
#define d_m3BranchIf(TYPE, LABEL, COND) \
d_m3Op (TYPE##_BranchIf_##LABEL##s) \
{ \
i32 condition = (i32) COND; \
TYPE value = slot (TYPE); \
pc_t branch = immediate (pc_t); \
\
if (condition) \
{ \
_r0 = value; \
jumpOp (branch); \
} \
else nextOp (); \
d_m3Op (BranchIfPrologue_r)
{
i32 condition = (i32) _r0;
pc_t branch = immediate (pc_t);
if (condition)
{
// this is the "prologue" that ends with
// a plain branch to the actual target
nextOp ();
}
else jumpOp (branch); // jump over the prologue
}
d_m3BranchIf (i32, r, _r0)
d_m3BranchIf (i64, r, _r0)
d_m3BranchIf (i32, s, slot (i32))
d_m3BranchIf (i64, s, slot (i32))
d_m3Op (BranchIfPrologue_s)
{
i32 condition = slot (i32);
pc_t branch = immediate (pc_t);
if (condition)
{
nextOp ();
}
else jumpOp (branch);
}
d_m3Op (ContinueLoop)

@ -13,6 +13,14 @@
#ifdef DEBUG
// a central function you can be breakpoint:
void ExceptionBreakpoint (cstr_t i_exception, cstr_t i_message)
{
printf ("\nexception: '%s' @ %s\n", i_exception, i_message);
return;
}
typedef struct OpInfo
{
IM3OpInfo info;
@ -89,21 +97,21 @@ cstr_t SPrintFuncTypeSignature (IM3FuncType i_funcType)
}
size_t SPrintArg (char * o_string, size_t i_n, m3stack_t i_sp, u8 i_type)
size_t SPrintArg (char * o_string, size_t i_stringBufferSize, m3stack_t i_sp, u8 i_type)
{
int len = 0;
* o_string = 0;
if (i_type == c_m3Type_i32)
len = snprintf (o_string, i_n, "%" PRIi32, * (i32 *) i_sp);
len = snprintf (o_string, i_stringBufferSize, "%" PRIi32, * (i32 *) i_sp);
else if (i_type == c_m3Type_i64)
len = snprintf (o_string, i_n, "%" PRIi64, * (i64 *) i_sp);
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_n, "%" PRIf32, * (f32 *) i_sp);
len = snprintf (o_string, i_stringBufferSize, "%" PRIf32, * (f32 *) i_sp);
else if (i_type == c_m3Type_f64)
len = snprintf (o_string, i_n, "%" PRIf64, * (f64 *) i_sp);
len = snprintf (o_string, i_stringBufferSize, "%" PRIf64, * (f64 *) i_sp);
#endif
len = M3_MAX (0, len);
@ -112,6 +120,14 @@ size_t SPrintArg (char * o_string, size_t i_n, m3stack_t i_sp, u8 i_type)
}
cstr_t SPrintValue (void * i_value, u8 i_type)
{
static char string [100];
SPrintArg (string, 100, (m3stack_t) i_value, i_type);
return string;
}
cstr_t SPrintFunctionArgList (IM3Function i_function, m3stack_t i_sp)
{
int ret;
@ -345,9 +361,9 @@ void dump_type_stack (IM3Compilation o)
u16 slot = o->wasmStack [i];
if (IsRegisterLocation (slot))
if (IsRegisterSlotAlias (slot))
{
bool isFp = IsFpRegisterLocation (slot);
bool isFp = IsFpRegisterSlotAlias (slot);
printf ("%s", isFp ? "f0" : "r0");
regAllocated [isFp]--;

@ -290,7 +290,7 @@ M3Result Parse_InitExpr (M3Module * io_module, bytes_t * io_bytes, cbytes_t i_
#endif
compilation = (M3Compilation){ NULL, io_module, * io_bytes, i_end };
result = Compile_BlockStatements (& compilation);
result = CompileBlockStatements (& compilation);
* io_bytes = compilation.wasm;

@ -222,10 +222,42 @@ int main (int argc, const char * argv [])
i32 ret0 = 0;
f32 ret1 = 0.;
m3_GetResultsV (function, & ret0, & ret1);
m3_GetResultsV (function, & ret0, & ret1);
printf ("%d %f\n", ret0, ret1);
}
}
Test (multireturn.branch)
{
# if 0
(module
(func (param i32) (result i32 i32)
i32.const 123
i32.const 456
i32.const 789
block (param i32 i32) (result i32 i32 i32)
local.get 0
local.get 0
local.get 0
br_if 0
drop
end
drop
drop
)
(export "main" (func 0))
)
# endif
}
return 0;

Loading…
Cancel
Save