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

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libffi/] [testsuite/] [libffi.call/] [cls_1_1byte.c] - Blame information for rev 14

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
/* Area:        ffi_call, closure_call
2
   Purpose:     Check structure passing with different structure size.
3
                Especially with small structures which may fit in one
4
                register. Depending on the ABI.
5
   Limitations: none.
6
   PR:          none.
7
   Originator:  <andreast@gcc.gnu.org> 20030902  */
8
 
9
/* { dg-do run { xfail mips64*-*-* arm*-*-* strongarm*-*-* xscale*-*-* } } */
10
#include "ffitest.h"
11
 
12
typedef struct cls_struct_1_1byte {
13
  unsigned char a;
14
} cls_struct_1_1byte;
15
 
16
cls_struct_1_1byte cls_struct_1_1byte_fn(struct cls_struct_1_1byte a1,
17
                            struct cls_struct_1_1byte a2)
18
{
19
  struct cls_struct_1_1byte result;
20
 
21
  result.a = a1.a + a2.a;
22
 
23
  printf("%d %d: %d\n", a1.a, a2.a, result.a);
24
 
25
  return  result;
26
}
27
 
28
static void
29
cls_struct_1_1byte_gn(ffi_cif* cif, void* resp, void** args, void* userdata)
30
{
31
 
32
  struct cls_struct_1_1byte a1, a2;
33
 
34
  a1 = *(struct cls_struct_1_1byte*)(args[0]);
35
  a2 = *(struct cls_struct_1_1byte*)(args[1]);
36
 
37
  *(cls_struct_1_1byte*)resp = cls_struct_1_1byte_fn(a1, a2);
38
}
39
 
40
int main (void)
41
{
42
  ffi_cif cif;
43
#ifndef USING_MMAP
44
  static ffi_closure cl;
45
#endif
46
  ffi_closure *pcl;
47
  void* args_dbl[5];
48
  ffi_type* cls_struct_fields[2];
49
  ffi_type cls_struct_type;
50
  ffi_type* dbl_arg_types[5];
51
 
52
#ifdef USING_MMAP
53
  pcl = allocate_mmap (sizeof(ffi_closure));
54
#else
55
  pcl = &cl;
56
#endif
57
 
58
  cls_struct_type.size = 0;
59
  cls_struct_type.alignment = 0;
60
  cls_struct_type.type = FFI_TYPE_STRUCT;
61
  cls_struct_type.elements = cls_struct_fields;
62
 
63
  struct cls_struct_1_1byte g_dbl = { 12 };
64
  struct cls_struct_1_1byte f_dbl = { 178 };
65
  struct cls_struct_1_1byte res_dbl;
66
 
67
  cls_struct_fields[0] = &ffi_type_uchar;
68
  cls_struct_fields[1] = NULL;
69
 
70
  dbl_arg_types[0] = &cls_struct_type;
71
  dbl_arg_types[1] = &cls_struct_type;
72
  dbl_arg_types[2] = NULL;
73
 
74
  CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &cls_struct_type,
75
                     dbl_arg_types) == FFI_OK);
76
 
77
  args_dbl[0] = &g_dbl;
78
  args_dbl[1] = &f_dbl;
79
  args_dbl[2] = NULL;
80
 
81
  ffi_call(&cif, FFI_FN(cls_struct_1_1byte_fn), &res_dbl, args_dbl);
82
  /* { dg-output "12 178: 190" } */
83
  printf("res: %d\n", res_dbl.a);
84
  /* { dg-output "\nres: 190" } */
85
 
86
  CHECK(ffi_prep_closure(pcl, &cif, cls_struct_1_1byte_gn, NULL) == FFI_OK);
87
 
88
  res_dbl = ((cls_struct_1_1byte(*)(cls_struct_1_1byte, cls_struct_1_1byte))(pcl))(g_dbl, f_dbl);
89
  /* { dg-output "\n12 178: 190" } */
90
  printf("res: %d\n", res_dbl.a);
91
  /* { dg-output "\nres: 190" } */
92
 
93
  exit(0);
94
}

powered by: WebSVN 2.1.0

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