OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libffi/] [testsuite/] [libffi.call/] [cls_multi_uchar.c] - Blame information for rev 735

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 732 jeremybenn
/* Area:        ffi_call, closure_call
2
   Purpose:     Check passing of multiple unsigned char values.
3
   Limitations: none.
4
   PR:          PR13221.
5
   Originator:  <andreast@gcc.gnu.org> 20031129  */
6
 
7
/* { dg-do run } */
8
#include "ffitest.h"
9
 
10
unsigned char test_func_fn(unsigned char a1, unsigned char a2,
11
                           unsigned char a3, unsigned char a4)
12
{
13
  unsigned char result;
14
 
15
  result = a1 + a2 + a3 + a4;
16
 
17
  printf("%d %d %d %d: %d\n", a1, a2, a3, a4, result);
18
 
19
  return result;
20
 
21
}
22
 
23
static void test_func_gn(ffi_cif *cif __UNUSED__, void *rval, void **avals,
24
                         void *data __UNUSED__)
25
{
26
  unsigned char a1, a2, a3, a4;
27
 
28
  a1 = *(unsigned char *)avals[0];
29
  a2 = *(unsigned char *)avals[1];
30
  a3 = *(unsigned char *)avals[2];
31
  a4 = *(unsigned char *)avals[3];
32
 
33
  *(ffi_arg *)rval = test_func_fn(a1, a2, a3, a4);
34
 
35
}
36
 
37
typedef unsigned char (*test_type)(unsigned char, unsigned char,
38
                                   unsigned char, unsigned char);
39
 
40
void test_func(ffi_cif *cif __UNUSED__, void *rval __UNUSED__, void **avals,
41
               void *data __UNUSED__)
42
{
43
  printf("%d %d %d %d\n", *(unsigned char *)avals[0],
44
         *(unsigned char *)avals[1], *(unsigned char *)avals[2],
45
         *(unsigned char *)avals[3]);
46
}
47
int main (void)
48
{
49
  ffi_cif cif;
50
  void *code;
51
  ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
52
  void * args_dbl[5];
53
  ffi_type * cl_arg_types[5];
54
  ffi_arg res_call;
55
  unsigned char a, b, c, d, res_closure;
56
 
57
  a = 1;
58
  b = 2;
59
  c = 127;
60
  d = 125;
61
 
62
  args_dbl[0] = &a;
63
  args_dbl[1] = &b;
64
  args_dbl[2] = &c;
65
  args_dbl[3] = &d;
66
  args_dbl[4] = NULL;
67
 
68
  cl_arg_types[0] = &ffi_type_uchar;
69
  cl_arg_types[1] = &ffi_type_uchar;
70
  cl_arg_types[2] = &ffi_type_uchar;
71
  cl_arg_types[3] = &ffi_type_uchar;
72
  cl_arg_types[4] = NULL;
73
 
74
  /* Initialize the cif */
75
  CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4,
76
                     &ffi_type_uchar, cl_arg_types) == FFI_OK);
77
 
78
  ffi_call(&cif, FFI_FN(test_func_fn), &res_call, args_dbl);
79
  /* { dg-output "1 2 127 125: 255" } */
80
  printf("res: %d\n", (unsigned char)res_call);
81
  /* { dg-output "\nres: 255" } */
82
 
83
  CHECK(ffi_prep_closure_loc(pcl, &cif, test_func_gn, NULL, code)  == FFI_OK);
84
 
85
  res_closure = (*((test_type)code))(1, 2, 127, 125);
86
  /* { dg-output "\n1 2 127 125: 255" } */
87
  printf("res: %d\n", res_closure);
88
  /* { dg-output "\nres: 255" } */
89
 
90
  exit(0);
91
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.