1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-01 12:20:26 +02:00
guile/tests/ret.c
Paolo Bonzini e2cb4af6aa added ret test and clarified JIT_RET documentation
Patches applied:

 * lcourtes@laas.fr--2005-libre/lightning--sparc-fixes--1.2--base-0
   tag of lcourtes@laas.fr--2005-libre/lightning--stable--1.2--patch-18

 * lcourtes@laas.fr--2005-libre/lightning--sparc-fixes--1.2--patch-1
   tests/push-pop.c: Use more `pushr's.

 * lcourtes@laas.fr--2005-libre/lightning--sparc-fixes--1.2--patch-3
   Added a test for `JIT_RET' (fails on SPARC).

 * lcourtes@laas.fr--2005-libre/lightning--sparc-fixes--1.2--patch-4
   Fixed use of `JIT_RET': Move %o0 into %i0 after `calli' and `callr'.

 * lcourtes@laas.fr--2005-libre/lightning--stable--1.2--patch-19
   Merge from `sparc-fixes': Fixed `pushr' and `popr', fixed `JIT_RET'.

 * lcourtes@laas.fr--2005-libre/lightning--stable--1.2--patch-20
   Undoed `lightning--sparc-fixes--1.2--patch-4' (about `JIT_RET') which was wrong.

 * lcourtes@laas.fr--2005-libre/lightning--stable--1.2--patch-21
   tests/ret.c: Use `jit_retval_i' to copy the function's return value.

 * lcourtes@laas.fr--2005-libre/lightning--stable--1.2--patch-22
   Doc: Clarified the use of `JIT_RET' and documented `jit_retval'.

git-archimport-id: bonzini@gnu.org--2004b/lightning--stable--1.2--patch-32
2008-01-09 15:49:47 +01:00

72 lines
1.3 KiB
C
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/******************************** -*- C -*- ****************************
*
* Test `JIT_RET'
*
***********************************************************************/
/* Contributed by Ludovic Courtès. */
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdio.h>
#include <string.h>
#include "lightning.h"
typedef int (* int_return_int_t) (int);
static int
identity (int arg)
{
return arg;
}
static int_return_int_t
generate_function_proxy (int_return_int_t func)
{
static char buffer[1024];
int_return_int_t result;
int arg;
result = (int_return_int_t)(jit_set_ip (buffer).ptr);
jit_prolog (1);
arg = jit_arg_i ();
jit_getarg_i (JIT_R1, arg);
/* Reset `JIT_RET'. */
jit_movi_i (JIT_RET, -1);
/* Invoke a FUNC. */
jit_prepare (1);
jit_pusharg_i (JIT_R1);
(void)jit_finish (func);
/* Copy the result of FUNC from `JIT_RET' into our own result register. */
jit_retval_i (JIT_RET);
jit_ret ();
jit_flush_code (buffer, jit_get_ip ().ptr);
return result;
}
int
main (int argc, char *argv[])
{
int_return_int_t identity_proxy;
identity_proxy = generate_function_proxy (identity);
if (identity_proxy (7777) != 7777)
{
printf ("failed: got %i instead of %i\n",
identity_proxy (7777), 7777);
return 1;
}
else
printf ("succeeded\n");
return 0;
}