summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com>2020-10-14 14:03:31 -0400
committerAlan Wu <XrXr@users.noreply.github.com>2021-10-20 18:19:25 -0400
commit6f81bd2c76c9eec7a95db92f552405cc68367e4d (patch)
tree45e90c82f82b6c38d59a3230662057eeadf91ccd
parente5751768baeb7c1e0a48c466c98014667058d2c3 (diff)
Added print_ptr() util function for debugging
-rw-r--r--ujit_compile.c7
-rw-r--r--ujit_utils.c19
-rw-r--r--ujit_utils.h1
3 files changed, 20 insertions, 7 deletions
diff --git a/ujit_compile.c b/ujit_compile.c
index 2b6fad3a72..67162fbd21 100644
--- a/ujit_compile.c
+++ b/ujit_compile.c
@@ -426,13 +426,6 @@ void gen_opt_minus(codeblock_t* cb, codeblock_t* ocb, ctx_t* ctx)
jo_ptr(cb, side_exit);
add(cb, RAX, imm_opnd(1));
- /*
- print_int(cb, arg0);
- print_int(cb, arg1);
- print_int(cb, RAX);
- print_str(cb, "");
- */
-
// Push the output on the stack
x86opnd_t dst = ctx_stack_push(ctx, 1);
mov(cb, dst, RAX);
diff --git a/ujit_utils.c b/ujit_utils.c
index 0594503924..b7d121c9ef 100644
--- a/ujit_utils.c
+++ b/ujit_utils.c
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <string.h>
+#include <assert.h>
#include "ujit_utils.h"
#include "ujit_asm.h"
@@ -54,6 +55,24 @@ void print_int(codeblock_t* cb, x86opnd_t opnd)
pop_regs(cb);
}
+static void print_ptr_cfun(int64_t val)
+{
+ printf("%llX\n", val);
+}
+
+void print_ptr(codeblock_t* cb, x86opnd_t opnd)
+{
+ assert (opnd.num_bits == 64);
+
+ push_regs(cb);
+
+ mov(cb, RDI, opnd);
+ mov(cb, RAX, const_ptr_opnd((void*)&print_ptr_cfun));
+ call(cb, RAX);
+
+ pop_regs(cb);
+}
+
static void print_str_cfun(const char* str)
{
printf("%s\n", str);
diff --git a/ujit_utils.h b/ujit_utils.h
index 5244d59734..005d928511 100644
--- a/ujit_utils.h
+++ b/ujit_utils.h
@@ -9,6 +9,7 @@
void push_regs(codeblock_t* cb);
void pop_regs(codeblock_t* cb);
void print_int(codeblock_t* cb, x86opnd_t opnd);
+void print_ptr(codeblock_t* cb, x86opnd_t opnd);
void print_str(codeblock_t* cb, const char* str);
#endif // #ifndef UJIT_UTILS_H