1 // This file is a fragment of the yjit.o compilation unit. See yjit.c.
3 // Save caller-save registers on the stack before a C call
5 push_regs(codeblock_t
*cb
)
19 // Restore caller-save registers from the after a C call
21 pop_regs(codeblock_t
*cb
)
36 print_int_cfun(int64_t val
)
38 fprintf(stderr
, "%lld\n", (long long int)val
);
41 RBIMPL_ATTR_MAYBE_UNUSED()
43 print_int(codeblock_t
*cb
, x86opnd_t opnd
)
47 if (opnd
.num_bits
< 64 && opnd
.type
!= OPND_IMM
)
52 // Call the print function
53 mov(cb
, RAX
, const_ptr_opnd((void*)&print_int_cfun
));
60 print_ptr_cfun(void *val
)
62 fprintf(stderr
, "%p\n", val
);
65 RBIMPL_ATTR_MAYBE_UNUSED()
67 print_ptr(codeblock_t
*cb
, x86opnd_t opnd
)
69 assert (opnd
.num_bits
== 64);
74 mov(cb
, RAX
, const_ptr_opnd((void*)&print_ptr_cfun
));
81 print_str_cfun(const char *str
)
83 fprintf(stderr
, "%s\n", str
);
86 // Print a constant string to stdout
88 print_str(codeblock_t
*cb
, const char *str
)
90 //as.comment("printStr(\"" ~ str ~ "\")");
91 size_t len
= strlen(str
);
95 // Load the string address and jump over the string data
96 lea(cb
, RDI
, mem_opnd(8, RIP
, 5));
97 jmp32(cb
, (int32_t)len
+ 1);
99 // Write the string chars and a null terminator
100 for (size_t i
= 0; i
< len
; ++i
)
101 cb_write_byte(cb
, (uint8_t)str
[i
]);
102 cb_write_byte(cb
, 0);
104 // Call the print function
105 mov(cb
, RAX
, const_ptr_opnd((void*)&print_str_cfun
));