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

Subversion Repositories openrisc

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

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

Line No. Rev Author Line
1 732 jeremybenn
/* Area:        ffi_call
2
   Purpose:     Check structures.
3
   Limitations: none.
4
   PR:          none.
5
   Originator:  From the original ffitest.c  */
6
 
7
/* { dg-do run } */
8
#include "ffitest.h"
9
 
10
typedef struct
11
{
12
  unsigned char uc;
13
  double d;
14
  unsigned int ui;
15
} test_structure_1;
16
 
17
static test_structure_1 struct1(test_structure_1 ts)
18
{
19
  ts.uc++;
20
  ts.d--;
21
  ts.ui++;
22
 
23
  return ts;
24
}
25
 
26
int main (void)
27
{
28
  ffi_cif cif;
29
  ffi_type *args[MAX_ARGS];
30
  void *values[MAX_ARGS];
31
  ffi_type ts1_type;
32
  ffi_type *ts1_type_elements[4];
33
  ts1_type.size = 0;
34
  ts1_type.alignment = 0;
35
  ts1_type.type = FFI_TYPE_STRUCT;
36
  ts1_type.elements = ts1_type_elements;
37
  ts1_type_elements[0] = &ffi_type_uchar;
38
  ts1_type_elements[1] = &ffi_type_double;
39
  ts1_type_elements[2] = &ffi_type_uint;
40
  ts1_type_elements[3] = NULL;
41
 
42
  test_structure_1 ts1_arg;
43
  /* This is a hack to get a properly aligned result buffer */
44
  test_structure_1 *ts1_result =
45
    (test_structure_1 *) malloc (sizeof(test_structure_1));
46
 
47
  args[0] = &ts1_type;
48
  values[0] = &ts1_arg;
49
 
50
  /* Initialize the cif */
51
  CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
52
                     &ts1_type, args) == FFI_OK);
53
 
54
  ts1_arg.uc = '\x01';
55
  ts1_arg.d = 3.14159;
56
  ts1_arg.ui = 555;
57
 
58
  ffi_call(&cif, FFI_FN(struct1), ts1_result, values);
59
 
60
  CHECK(ts1_result->ui == 556);
61
  CHECK(ts1_result->d == 3.14159 - 1);
62
 
63
  free (ts1_result);
64
  exit(0);
65
}

powered by: WebSVN 2.1.0

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