Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: src/vm/ffi_test_library.c

Issue 1209033003: Work in progres, please take a look and give early feedback if this is the way we want to structure… (Closed) Base URL: git@github.com:dart-lang/fletch.git@master
Patch Set: address comments Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/vm/ffi_posix.cc ('k') | src/vm/list.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2015, the Fletch project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE.md file.
4
5 // Testing library for testing the foreign function interface.
6 // There are no tests in this file, but we keep this to have a single place
7 // for functionality that we want to test in the FFI implementation.
8
9 #include <stdio.h>
10 #include <stdlib.h>
11
12 // Copied from globals.h to have consistent values
13 // TODO(ricow): we could split globals into a c only part and a c++ part.
14 typedef signed char int8;
15 typedef short int16; // NOLINT
16 typedef int int32;
17
18 typedef unsigned char uint8;
19 typedef unsigned short uint16; // NOLINT
20 typedef unsigned int uint32;
21
22 #ifdef FLETCH64
23 typedef long int64; // NOLINT
24 typedef unsigned long uint64; // NOLINT
25 typedef char foobar;
26 #else
27 typedef long long int int64; // NOLINT
28 typedef long long unsigned uint64;
29 typedef int foobar;
30 #endif
31
32 static int count;
33
34 void setup() {
35 count = 0;
36 }
37
38 int getcount() {
39 return count;
40 }
41
42 void inc() {
43 count++;
44 }
45
46 int setcount(int val) {
47 count = val;
48 return count;
49 }
50
51 int ifun0() {
52 return 0;
53 }
54
55 int ifun1(int a) {
56 return a;
57 }
58
59 int ifun2(int a, int b) {
60 return a + b;
61 }
62
63 int ifun3(int a, int b, int c) {
64 return a + b + c;
65 }
66
67 int ifun4(int a, int b, int c, int d) {
68 return a + b + c + d;
69 }
70
71 int ifun5(int a, int b, int c, int d, int e) {
72 return a + b + c + d + e;
73 }
74
75 int ifun6(int a, int b, int c, int d, int e, int f) {
76 return a + b + c + d + e + f;
77 }
78
79 void vfun0() {
80 count = 0;
81 }
82
83 void vfun1(int a) {
84 count = 1;
85 }
86
87 void vfun2(int a, int b) {
88 count = 2;
89 }
90
91 void vfun3(int a, int b, int c) {
92 count = 3;
93 }
94
95 void vfun4(int a, int b, int c, int d) {
96 count = 4;
97 }
98
99 void vfun5(int a, int b, int c, int d, int e) {
100 count = 5;
101 }
102
103 void vfun6(int a, int b, int c, int d, int e, int f) {
104 count = 6;
105 }
106
107 // We assume int are 32 bits, short is 16 bits, char is 8 bits,
108 // float is 32 bits, double is 64 bits.
109 void* pfun0() {
110 int32* data = malloc(sizeof(int32) * 4);
111 *data = 1;
112 *(data + 1) = 2;
113 *(data + 2) = 3;
114 *(data + 3) = 4;
115 return data;
116 }
117
118 void* pfun1(int value) {
119 int32* data = malloc(sizeof(int32) * 4);
120 *data = value;
121 *(data + 1) = value;
122 *(data + 2) = value;
123 *(data + 3) = value;
124 return data;
125 }
126
127 void* pfun2(int value, int value2) {
128 int32* data = malloc(sizeof(int32) * 4);
129 *data = value;
130 *(data + 1) = value2;
131 *(data + 2) = value;
132 *(data + 3) = value2;
133 return data;
134 }
135
136 void* memint8() {
137 int8* data = malloc(sizeof(int8) * 4);
138 *data = -1;
139 *(data + 1) = -128;
140 *(data + 2) = 'c';
141 *(data + 3) = 'd';
142 return data;
143 }
144
145 void* memint16() {
146 int16* data = malloc(sizeof(int16) * 4);
147 *data = 32767;
148 *(data + 1) = -32768;
149 *(data + 2) = 0;
150 *(data + 3) = -1;
151 return data;
152 }
153
154 void* memuint16() {
155 uint16* data = malloc(sizeof(uint16) * 4);
156 *data = 0;
157 *(data + 1) = 32767;
158 *(data + 2) = 32768;
159 *(data + 3) = 65535;
160 return data;
161 }
162
163 void* memuint32() {
164 uint32* data = malloc(sizeof(uint32) * 4);
165 *data = 0;
166 *(data + 1) = 1;
167 *(data + 2) = 65536;
168 *(data + 3) = 4294967295u;
169 return data;
170 }
171
172 void* memint64() {
173 int64* data = malloc(sizeof(int64) * 4);
174 *data = 0;
175 *(data + 1) = -1;
176 *(data + 2) = 9223372036854775807u;
177 *(data + 3) = -9223372036854775808u;
178 return data;
179 }
180
181 void* memuint64() {
182 uint64* data = malloc(sizeof(uint64) * 4);
183 *data = 0;
184 *(data + 1) = 1;
185 *(data + 2) = 2;
186 *(data + 3) = 18446744073709551615u;
187 return data;
188 }
189
190 void* memfloat32() {
191 float* data = malloc(sizeof(float) * 4);
192 *data = 0.0;
193 *(data + 1) = 1.175494e-38f;
194 *(data + 2) = 3.402823e+38f;
195 *(data + 3) = 4;
196 return data;
197 }
198
199 void* memfloat64() {
200 double* data = malloc(sizeof(double) * 4);
201 *data = 0.0;
202 *(data + 1) = 1.79769e+308;
203 *(data + 2) = -1.79769e+308;
204 *(data + 3) = 4;
205 return data;
206 }
OLDNEW
« no previous file with comments | « src/vm/ffi_posix.cc ('k') | src/vm/list.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698