| 1 | #include <stdio.h> |
| 2 | #include <stdarg.h> |
| 3 | #include <errno.h> |
| 4 | #include "src/precommondefs.h" |
| 5 | |
| 6 | |
| 7 | static char _testfunc0(char a, char b) |
| 8 | { |
| 9 | return a + b; |
| 10 | } |
| 11 | static long _testfunc1(int a, long b) |
| 12 | { |
| 13 | return (long)a + b; |
| 14 | } |
| 15 | static long long _testfunc2(long long a, long long b) |
| 16 | { |
| 17 | return a + b; |
| 18 | } |
| 19 | static double _testfunc3(float a, double b) |
| 20 | { |
| 21 | return a + b; |
| 22 | } |
| 23 | static float _testfunc4(float a, double b) |
| 24 | { |
| 25 | return (float)(a + b); |
| 26 | } |
| 27 | static void _testfunc5(void) |
| 28 | { |
| 29 | errno = errno + 15; |
| 30 | } |
| 31 | static int *_testfunc6(int *x) |
| 32 | { |
| 33 | static int y; |
| 34 | y = *x - 1000; |
| 35 | return &y; |
| 36 | } |
| 37 | struct _testfunc7_s { unsigned char a1; short a2; }; |
| 38 | static short _testfunc7(struct _testfunc7_s inlined) |
| 39 | { |
| 40 | return inlined.a1 + inlined.a2; |
| 41 | } |
| 42 | static int _testfunc9(int num, ...) |
| 43 | { |
| 44 | va_list vargs; |
| 45 | int i, total = 0; |
| 46 | va_start(vargs, num); |
| 47 | for (i=0; i<num; i++) { |
| 48 | int value = va_arg(vargs, int); |
| 49 | if (value == 0) |
| 50 | value = -66666666; |
| 51 | total += value; |
| 52 | } |
| 53 | va_end(vargs); |
| 54 | return total; |
| 55 | } |
| 56 | |
| 57 | static struct _testfunc7_s _testfunc10(int n) |
| 58 | { |
| 59 | struct _testfunc7_s result; |
| 60 | result.a1 = n; |
| 61 | result.a2 = n * n; |
| 62 | return result; |
| 63 | } |
| 64 | |
| 65 | struct _testfunc11_s { int a1, a2; }; |
| 66 | static struct _testfunc11_s _testfunc11(int n) |
| 67 | { |
| 68 | struct _testfunc11_s result; |
| 69 | result.a1 = n; |
| 70 | result.a2 = n * n; |
| 71 | return result; |
| 72 | } |
| 73 | |
| 74 | struct _testfunc12_s { double a1; }; |
| 75 | static struct _testfunc12_s _testfunc12(int n) |
| 76 | { |
| 77 | struct _testfunc12_s result; |
| 78 | result.a1 = n; |
| 79 | return result; |
| 80 | } |
| 81 | |
| 82 | struct _testfunc13_s { int a1, a2, a3; }; |
| 83 | static struct _testfunc13_s _testfunc13(int n) |
| 84 | { |
| 85 | struct _testfunc13_s result; |
| 86 | result.a1 = n; |
| 87 | result.a2 = n * n; |
| 88 | result.a3 = n * n * n; |
| 89 | return result; |
| 90 | } |
| 91 | |
| 92 | struct _testfunc14_s { float a1; }; |
| 93 | static struct _testfunc14_s _testfunc14(int n) |
| 94 | { |
| 95 | struct _testfunc14_s result; |
| 96 | result.a1 = (float)n; |
| 97 | return result; |
| 98 | } |
| 99 | |
| 100 | struct _testfunc15_s { float a1; int a2; }; |
| 101 | static struct _testfunc15_s _testfunc15(int n) |
| 102 | { |
| 103 | struct _testfunc15_s result; |
| 104 | result.a1 = (float)n; |
| 105 | result.a2 = n * n; |
| 106 | return result; |
| 107 | } |
| 108 | |
| 109 | struct _testfunc16_s { float a1, a2; }; |
| 110 | static struct _testfunc16_s _testfunc16(int n) |
| 111 | { |
| 112 | struct _testfunc16_s result; |
| 113 | result.a1 = (float)n; |
| 114 | result.a2 = -(float)n; |
| 115 | return result; |
| 116 | } |
| 117 | |
| 118 | struct _testfunc17_s { int a1; float a2; }; |
| 119 | static struct _testfunc17_s _testfunc17(int n) |
| 120 | { |
| 121 | struct _testfunc17_s result; |
| 122 | result.a1 = n; |
| 123 | result.a2 = (float)n * (float)n; |
| 124 | return result; |
| 125 | } |
| 126 | |
| 127 | static int _testfunc18(struct _testfunc17_s *ptr) |
| 128 | { |
| 129 | return ptr->a1 + (int)ptr->a2; |
| 130 | } |
| 131 | |
| 132 | static long double _testfunc19(long double x, int count) |
| 133 | { |
| 134 | int i; |
| 135 | for (i=0; i<count; i++) { |
| 136 | x = 4*x - x*x; |
| 137 | } |
| 138 | return x; |
| 139 | } |
| 140 | |
| 141 | static short _testfunc20(struct _testfunc7_s *ptr) |
| 142 | { |
| 143 | return ptr->a1 + ptr->a2; |
| 144 | } |
| 145 | |
| 146 | struct _testfunc21_s { int a, b, c, d, e, f, g, h, i, j; }; |
| 147 | static int _testfunc21(struct _testfunc21_s inlined) |
| 148 | { |
| 149 | return ((inlined.a << 0) + |
| 150 | (inlined.b << 1) + |
| 151 | (inlined.c << 2) + |
| 152 | (inlined.d << 3) + |
| 153 | (inlined.e << 4) + |
| 154 | (inlined.f << 5) + |
| 155 | (inlined.g << 6) + |
| 156 | (inlined.h << 7) + |
| 157 | (inlined.i << 8) + |
| 158 | (inlined.j << 9)); |
| 159 | } |
| 160 | |
| 161 | struct _testfunc22_s { int a[10]; }; |
| 162 | static struct _testfunc22_s _testfunc22(struct _testfunc22_s s1, |
| 163 | struct _testfunc22_s s2) |
| 164 | { |
| 165 | struct _testfunc22_s result; |
| 166 | int i; |
| 167 | for (i=0; i<10; i++) |
| 168 | result.a[i] = s1.a[i] - s2.a[i]; |
| 169 | return result; |
| 170 | } |
| 171 | |
| 172 | static int _testfunc23(char *p) |
| 173 | { |
| 174 | if (p) |
| 175 | return 1000 * p[0]; |
| 176 | return -42; |
| 177 | } |
| 178 | |
| 179 | RPY_EXPORTED void *gettestfunc(int num) |
| 180 | { |
| 181 | void *f; |
| 182 | switch (num) { |
| 183 | case 0: f = &_testfunc0; break; |
| 184 | case 1: f = &_testfunc1; break; |
| 185 | case 2: f = &_testfunc2; break; |
| 186 | case 3: f = &_testfunc3; break; |
| 187 | case 4: f = &_testfunc4; break; |
| 188 | case 5: f = &_testfunc5; break; |
| 189 | case 6: f = &_testfunc6; break; |
| 190 | case 7: f = &_testfunc7; break; |
| 191 | case 8: f = stderr; break; |
| 192 | case 9: f = &_testfunc9; break; |
| 193 | case 10: f = &_testfunc10; break; |
| 194 | case 11: f = &_testfunc11; break; |
| 195 | case 12: f = &_testfunc12; break; |
| 196 | case 13: f = &_testfunc13; break; |
| 197 | case 14: f = &_testfunc14; break; |
| 198 | case 15: f = &_testfunc15; break; |
| 199 | case 16: f = &_testfunc16; break; |
| 200 | case 17: f = &_testfunc17; break; |
| 201 | case 18: f = &_testfunc18; break; |
| 202 | case 19: f = &_testfunc19; break; |
| 203 | case 20: f = &_testfunc20; break; |
| 204 | case 21: f = &_testfunc21; break; |
| 205 | case 22: f = &_testfunc22; break; |
| 206 | case 23: f = &_testfunc23; break; |
| 207 | default: |
| 208 | return NULL; |
| 209 | } |
| 210 | return f; |
| 211 | } |