Implement tracing for C backend

This commit is contained in:
Niklas Larsson 2017-06-20 16:59:14 +02:00
parent 4903cb784d
commit 8d8869bd67
2 changed files with 19 additions and 2 deletions

View File

@ -419,6 +419,13 @@ VAL MKB64(VM* vm, uint64_t bits64) {
return cl;
}
void idris_trace(VM* vm, const char* func, int line) {
printf("At %s:%d\n", func, line);
dumpStack(vm);
puts("");
fflush(stdout);
}
void dumpStack(VM* vm) {
int i = 0;
VAL* root;
@ -426,7 +433,8 @@ void dumpStack(VM* vm) {
for (root = vm->valstack; root < vm->valstack_top; ++root, ++i) {
printf("%d: ", i);
dumpVal(*root);
if (*root >= (VAL)(vm->heap.heap) && *root < (VAL)(vm->heap.end)) { printf("OK"); }
if (*root >= (VAL)(vm->heap.heap) && *root < (VAL)(vm->heap.end)) { printf(" OK"); }
if (root == vm->valstack_base) { printf(" <--- base"); }
printf("\n");
}
printf("RET: ");

View File

@ -235,7 +235,15 @@ typedef intptr_t i_int;
// Stack management
#define INITFRAME VAL* myoldbase
#ifdef IDRIS_TRACE
#define TRACE idris_trace(vm, __FUNCTION__, __LINE__);
#else
#define TRACE
#endif
#define INITFRAME TRACE\
VAL* myoldbase
#define REBASE vm->valstack_base = oldbase
#define RESERVE(x) if (vm->valstack_top+(x) > vm->stack_max) { stackOverflow(); } \
else { memset(vm->valstack_top, 0, (x)*sizeof(VAL)); }
@ -348,6 +356,7 @@ VM* idris_getSender(Msg* msg);
int idris_getChannel(Msg* msg);
void idris_freeMsg(Msg* msg);
void idris_trace(VM* vm, const char* func, int line);
void dumpVal(VAL r);
void dumpStack(VM* vm);