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 GetStackTypeFromTop (IM3Compilation o, u16 i_offset)
{ {
u8 type = c_m3Type_none; u8 type = c_m3Type_none;
++i_offset; ++i_offset;
if (o->stackIndex >= 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; return type;
} }
@ -1028,13 +1036,13 @@ M3Result ReturnValues (IM3Compilation o, IM3CompilationScope i_functionBlock,
{ {
// return slots like args are 64-bit aligned // return slots like args are 64-bit aligned
u16 returnSlot = numReturns * c_ioSlotCount; u16 returnSlot = numReturns * c_ioSlotCount;
u16 stackIndex = GetStackTopIndex (o); u16 stackTop = GetStackTopIndex (o);
for (u16 i = 0; i < numReturns; ++i) for (u16 i = 0; i < numReturns; ++i)
{ {
u8 returnType = GetFuncTypeResultType (i_functionBlock->type, numReturns - 1 - 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) if (IsStackPolymorphic (o) and stackType == c_m3Type_none)
stackType = returnType; stackType = returnType;
@ -1044,7 +1052,7 @@ M3Result ReturnValues (IM3Compilation o, IM3CompilationScope i_functionBlock,
if (not IsStackPolymorphic (o)) if (not IsStackPolymorphic (o))
{ {
returnSlot -= c_ioSlotCount; returnSlot -= c_ioSlotCount;
_ (CopyStackIndexToSlot (o, returnSlot, stackIndex--)); _ (CopyStackIndexToSlot (o, returnSlot, stackTop--));
} }
if (not i_isBranch) if (not i_isBranch)
@ -1559,8 +1567,8 @@ _ (ReadLEB_u32 (& functionIndex, & o->wasm, o->wasmEnd));
IM3Function function = Module_GetFunction (o->module, functionIndex); IM3Function function = Module_GetFunction (o->module, functionIndex);
if (function) if (function)
{ m3log (compile, d_indent " (func= '%s'; args= %d)", { m3log (compile, d_indent " (func= [%d] '%s'; args= %d)",
get_indention_string (o), m3_GetFunctionName (function), function->funcType->numArgs); get_indention_string (o), functionIndex, m3_GetFunctionName (function), function->funcType->numArgs);
if (function->module) if (function->module)
{ {
u16 slotTop; u16 slotTop;

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

Loading…
Cancel
Save