better stack dump

extensions
Steven Massey 3 years ago
parent 20275d64c6
commit ed69d293d4

@ -120,13 +120,21 @@ i16 GetStackTopIndex (IM3Compilation o)
}
// Items in the static portion of the stack (args/locals) are hidden from GetStackTypeFromTop ()
// In other words, only "real" Wasm stack items can be inspected. This is important when
// returning values, etc. and you need an accurate wasm-view of the stack.
u8 GetStackTypeFromTop (IM3Compilation o, u16 i_offset)
{
u8 type = c_m3Type_none;
++i_offset;
if (o->stackIndex >= i_offset)
type = o->typeStack [o->stackIndex - i_offset];
{
u16 index = o->stackIndex - i_offset;
if (index >= o->stackFirstDynamicIndex)
type = o->typeStack [index];
}
return type;
}
@ -1028,13 +1036,13 @@ M3Result ReturnValues (IM3Compilation o, IM3CompilationScope i_functionBlock,
{
// return slots like args are 64-bit aligned
u16 returnSlot = numReturns * c_ioSlotCount;
u16 stackIndex = GetStackTopIndex (o);
u16 stackTop = GetStackTopIndex (o);
for (u16 i = 0; i < numReturns; ++i)
{
u8 returnType = GetFuncTypeResultType (i_functionBlock->type, numReturns - 1 - i);
u8 stackType = GetStackTypeFromBottom (o, stackIndex);
u8 stackType = GetStackTypeFromTop (o, i); // using FromTop so that only dynamic items are checked
if (IsStackPolymorphic (o) and stackType == c_m3Type_none)
stackType = returnType;
@ -1044,7 +1052,7 @@ M3Result ReturnValues (IM3Compilation o, IM3CompilationScope i_functionBlock,
if (not IsStackPolymorphic (o))
{
returnSlot -= c_ioSlotCount;
_ (CopyStackIndexToSlot (o, returnSlot, stackIndex--));
_ (CopyStackIndexToSlot (o, returnSlot, stackTop--));
}
if (not i_isBranch)
@ -1559,8 +1567,8 @@ _ (ReadLEB_u32 (& functionIndex, & o->wasm, o->wasmEnd));
IM3Function function = Module_GetFunction (o->module, functionIndex);
if (function)
{ m3log (compile, d_indent " (func= '%s'; args= %d)",
get_indention_string (o), m3_GetFunctionName (function), function->funcType->numArgs);
{ m3log (compile, d_indent " (func= [%d] '%s'; args= %d)",
get_indention_string (o), functionIndex, m3_GetFunctionName (function), function->funcType->numArgs);
if (function->module)
{
u16 slotTop;

@ -356,45 +356,69 @@ void dump_type_stack (IM3Compilation o)
d_m3Log(stack, "\n");
d_m3Log(stack, " ");
printf ("%s %s ", regAllocated [0] ? "(r0)" : " ", regAllocated [1] ? "(fp0)" : " ");
printf("\n");
// printf ("%d", o->stackIndex -)
for (u32 i = 0; i < o->stackIndex; ++i)
for (u32 p = 1; p <= 2; ++p)
{
if (i > 0 and i == o->stackFirstDynamicIndex)
printf ("]");
d_m3Log(stack, " ");
if (i == o->block.blockStackIndex)
printf (" |");
printf (" %s", c_waCompactTypes [o->typeStack [i]]);
u16 slot = o->wasmStack [i];
if (IsRegisterSlotAlias (slot))
for (u32 i = 0; i < o->stackIndex; ++i)
{
bool isFp = IsFpRegisterSlotAlias (slot);
printf ("%s", isFp ? "f0" : "r0");
if (i > 0 and i == o->stackFirstDynamicIndex)
printf ("#");
if (i == o->block.blockStackIndex)
printf (">");
const char * type = c_waCompactTypes [o->typeStack [i]];
char * location = "";
i32 slot = o->wasmStack [i];
if (IsRegisterSlotAlias (slot))
{
bool isFp = IsFpRegisterSlotAlias (slot);
location = isFp ? "/f" : "/r";
regAllocated [isFp]--;
}
else
{
if (slot < o->slotFirstDynamicIndex)
regAllocated [isFp]--;
slot = -1;
}
else
{
if (slot >= o->slotFirstConstIndex)
printf ("c");
else if (slot >= o->function->numRetAndArgSlots)
printf ("L");
else
printf ("a");
if (slot < o->slotFirstDynamicIndex)
{
if (slot >= o->slotFirstConstIndex)
location = "c";
else if (slot >= o->function->numRetAndArgSlots)
location = "L";
else
location = "a";
}
}
printf ("%d", (i32) slot); // slot
}
char item [100];
if (slot >= 0)
sprintf (item, "%s%s%d", type, location, slot);
else
sprintf (item, "%s%s", type, location);
printf (" ");
if (p == 1)
{
size_t s = strlen (item);
sprintf (item, "%d", i);
while (strlen (item) < s)
strcat (item, " ");
}
printf ("|%s ", item);
}
printf ("\n");
}
printf ("\n");
// for (u32 r = 0; r < 2; ++r)
// d_m3Assert (regAllocated [r] == 0); // reg allocation & stack out of sync

Loading…
Cancel
Save