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/] [problem1.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
   Limitations: none.
4
   PR:          none.
5
   Originator:  <andreast@gcc.gnu.org> 20030828  */
6
 
7
/* { dg-do run { xfail mips64*-*-* arm*-*-* strongarm*-*-* xscale*-*-* } } */
8
#include "ffitest.h"
9
 
10
typedef struct my_ffi_struct {
11
  double a;
12
  double b;
13
  double c;
14
} my_ffi_struct;
15
 
16
my_ffi_struct callee(struct my_ffi_struct a1, struct my_ffi_struct a2)
17
{
18
  struct my_ffi_struct result;
19
  result.a = a1.a + a2.a;
20
  result.b = a1.b + a2.b;
21
  result.c = a1.c + a2.c;
22
 
23
 
24
  printf("%g %g %g %g %g %g: %g %g %g\n", a1.a, a1.b, a1.c,
25
         a2.a, a2.b, a2.c, result.a, result.b, result.c);
26
 
27
  return result;
28
}
29
 
30
void stub(ffi_cif* cif, void* resp, void** args, void* userdata)
31
{
32
  struct my_ffi_struct a1;
33
  struct my_ffi_struct a2;
34
 
35
  a1 = *(struct my_ffi_struct*)(args[0]);
36
  a2 = *(struct my_ffi_struct*)(args[1]);
37
 
38
  *(my_ffi_struct *)resp = callee(a1, a2);
39
}
40
 
41
 
42
int main(void)
43
{
44
  ffi_type* my_ffi_struct_fields[4];
45
  ffi_type my_ffi_struct_type;
46
  ffi_cif cif;
47
#ifndef USING_MMAP
48
  static ffi_closure cl;
49
#endif
50
  ffi_closure *pcl;
51
  void* args[4];
52
  ffi_type* arg_types[3];
53
 
54
#ifdef USING_MMAP
55
  pcl = allocate_mmap (sizeof(ffi_closure));
56
#else
57
  pcl = &cl;
58
#endif
59
 
60
  struct my_ffi_struct g = { 1.0, 2.0, 3.0 };
61
  struct my_ffi_struct f = { 1.0, 2.0, 3.0 };
62
  struct my_ffi_struct res;
63
 
64
  my_ffi_struct_type.size = 0;
65
  my_ffi_struct_type.alignment = 0;
66
  my_ffi_struct_type.type = FFI_TYPE_STRUCT;
67
  my_ffi_struct_type.elements = my_ffi_struct_fields;
68
 
69
  my_ffi_struct_fields[0] = &ffi_type_double;
70
  my_ffi_struct_fields[1] = &ffi_type_double;
71
  my_ffi_struct_fields[2] = &ffi_type_double;
72
  my_ffi_struct_fields[3] = NULL;
73
 
74
  arg_types[0] = &my_ffi_struct_type;
75
  arg_types[1] = &my_ffi_struct_type;
76
  arg_types[2] = NULL;
77
 
78
  CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &my_ffi_struct_type,
79
                     arg_types) == FFI_OK);
80
 
81
  args[0] = &g;
82
  args[1] = &f;
83
  args[2] = NULL;
84
  ffi_call(&cif, FFI_FN(callee), &res, args);
85
  /* { dg-output "1 2 3 1 2 3: 2 4 6" } */
86
  printf("res: %g %g %g\n", res.a, res.b, res.c);
87
  /* { dg-output "\nres: 2 4 6" } */
88
 
89
  CHECK(ffi_prep_closure(pcl, &cif, stub, NULL) == FFI_OK);
90
 
91
  res = ((my_ffi_struct(*)(struct my_ffi_struct, struct my_ffi_struct))(pcl))(g, f);
92
  /* { dg-output "\n1 2 3 1 2 3: 2 4 6" } */
93
  printf("res: %g %g %g\n", res.a, res.b, res.c);
94
  /* { dg-output "\nres: 2 4 6" } */
95
 
96
  exit(0);;
97
}

powered by: WebSVN 2.1.0

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