annotate test/callf/main.c @ 358:30aae7371373

- extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall - made formatted call (dcV?{Call,Arg}F) interface use those calling convention mode signature specifications to begin with - extended callf testcode with one standard and one vararg call to test those cc mode switches
author Tassilo Philipp
date Mon, 13 Apr 2020 15:12:01 +0200
parents f5577f6bf97a
children 78dfa2f9783a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
1 /*
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
2
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
3 Package: dyncall
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
4 Library: test
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
5 File: test/callf/main.c
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
6 Description:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
7 License:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
8
281
f5577f6bf97a - file header cleanups for release
Tassilo Philipp
parents: 0
diff changeset
9 Copyright (c) 2007-2018 Daniel Adler <dadler@uni-goettingen.de>,
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
10 Tassilo Philipp <tphilipp@potion-studios.com>
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
11
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
12 Permission to use, copy, modify, and distribute this software for any
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
13 purpose with or without fee is hereby granted, provided that the above
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
14 copyright notice and this permission notice appear in all copies.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
15
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
16 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
17 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
18 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
19 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
20 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
21 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
22 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
23
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
24 */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
25
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
26
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
27
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
28 /* test dcCallF API */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
29
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
30 #include "../../dyncall/dyncall_callf.h"
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
31 #include "../common/platformInit.h"
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
32 #include "../common/platformInit.c" /* Impl. for functions only used in this translation unit */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
33
358
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
34 #include <stdarg.h>
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
35
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
36
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
37 /* sample void function */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
38
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
39 int vf_iii(int x,int y,int z)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
40 {
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
41 int r = (x == 1 && y == 2 && z == 3);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
42 printf("%d %d %d: %d", x, y, z, r);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
43 return r;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
44 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
45
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
46 int vf_ffiffiffi(float a, float b, int c, float d, float e, int f, float g, float h, int i)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
47 {
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
48 int r = (a == 1.f && b == 2.f && c == 3 && d == 4.f && e == 5.f && f == 6 && g == 7.f && h == 8.f && i == 9);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
49 printf("%f %f %d %f %f %d %f %f %d: %d", a, b, c, d, e, f, g, h, i, r);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
50 return r;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
51 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
52
358
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
53 int vf_ffiV(float a, float b, int c, ...)
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
54 {
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
55 va_list ap;
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
56 double d, e, g, h;
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
57 int f, i;
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
58 int r;
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
59
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
60 va_start(ap, c);
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
61 d = va_arg(ap, double);
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
62 e = va_arg(ap, double);
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
63 f = va_arg(ap, int);
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
64 g = va_arg(ap, double);
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
65 h = va_arg(ap, double);
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
66 i = va_arg(ap, int);
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
67 va_end(ap);
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
68
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
69 r = (a == 1.f && b == 2.f && c == 3 && d == 4. && e == 5. && f == 6 && g == 7. && h == 8. && i == 9);
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
70 printf("%f %f %d %f %f %d %f %f %d: %d", a, b, c, d, e, f, g, h, i, r);
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
71 return r;
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
72 }
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
73
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
74 /* main */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
75
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
76 int main(int argc, char* argv[])
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
77 {
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
78 DCCallVM* vm;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
79 DCValue ret;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
80 int r = 1;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
81
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
82 dcTest_initPlatform();
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
83
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
84 /* allocate call vm */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
85 vm = dcNewCallVM(4096);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
86
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
87
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
88 /* calls using 'formatted' API */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
89 dcReset(vm);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
90 printf("callf iii)i: ");
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
91 dcCallF(vm, &ret, (void*)&vf_iii, "iii)i", 1, 2, 3);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
92 r = ret.i && r;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
93
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
94 dcReset(vm);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
95 printf("\ncallf ffiffiffi)i: ");
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
96 dcCallF(vm, &ret, (void*)&vf_ffiffiffi, "ffiffiffi)i", 1.f, 2.f, 3, 4.f, 5.f, 6, 7.f, 8.f, 9);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
97 r = ret.i && r;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
98
358
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
99 /* same but with calling convention prefix */
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
100 dcReset(vm);
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
101 printf("\ncallf _:ffiffiffi)i: ");
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
102 dcCallF(vm, &ret, (void*)&vf_ffiffiffi, "_:ffiffiffi)i", 1.f, 2.f, 3, 4.f, 5.f, 6, 7.f, 8.f, 9);
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
103 r = ret.i && r;
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
104
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
105 /* vararg call */
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
106 dcReset(vm);
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
107 printf("\ncallf _effi_.ddiddi)i: ");
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
108 dcCallF(vm, &ret, (void*)&vf_ffiV, "_effi_.ddiddi)i", 1.f, 2.f, 3, 4., 5., 6, 7., 8., 9);
30aae7371373 - extended signature with calling convention mode switches for fastcall (gnu), default, cdecl, stdcall, arm (arm), arm (thumb), syscall
Tassilo Philipp
parents: 281
diff changeset
109 r = ret.i && r;
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
110
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
111 /* arg binding then call using 'formatted' API */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
112 dcReset(vm);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
113 printf("\nargf iii)i then call: ");
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
114 dcArgF(vm, "iii)i", 1, 2, 3);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
115 r = r && dcCallInt(vm, (void*)&vf_iii);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
116
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
117 dcReset(vm);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
118 printf("\nargf iii then call: ");
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
119 dcArgF(vm, "iii", 1, 2, 3);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
120 r = r && dcCallInt(vm, (void*)&vf_iii);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
121
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
122 dcReset(vm);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
123 printf("\nargf ffiffiffi)i then call: ");
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
124 dcArgF(vm, "ffiffiffi)i", 1.f, 2.f, 3, 4.f, 5.f, 6, 7.f, 8.f, 9);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
125 r = r && dcCallInt(vm, (void*)&vf_ffiffiffi);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
126
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
127 dcReset(vm);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
128 printf("\nargf ffiffiffi then call: ");
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
129 dcArgF(vm, "ffiffiffi", 1.f, 2.f, 3, 4.f, 5.f, 6, 7.f, 8.f, 9);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
130 r = r && dcCallInt(vm, (void*)&vf_ffiffiffi);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
131
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
132
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
133 /* free vm */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
134 dcFree(vm);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
135
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
136 printf("\nresult: callf: %d\n", r);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
137
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
138 dcTest_deInitPlatform();
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
139
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
140 return 0;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
141 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
142