Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 | |
| 52 int icall0() { | |
|
kasperl
2015/06/30 07:16:01
Maybe replace call with fun in all these methods t
ricow1
2015/06/30 07:34:22
Acknowledged.
ricow1
2015/07/02 16:01:56
Done.
| |
| 53 return 0; | |
| 54 } | |
| 55 | |
| 56 int icall1(int a) { | |
| 57 return a; | |
| 58 } | |
| 59 | |
| 60 int icall2(int a, int b) { | |
| 61 return a + b; | |
| 62 } | |
| 63 | |
| 64 int icall3(int a, int b, int c) { | |
| 65 return a + b + c; | |
| 66 } | |
| 67 | |
| 68 int icall4(int a, int b, int c, int d) { | |
| 69 return a + b + c + d; | |
| 70 } | |
| 71 | |
| 72 int icall5(int a, int b, int c, int d, int e) { | |
| 73 return a + b + c + d + e; | |
| 74 } | |
| 75 | |
| 76 int icall6(int a, int b, int c, int d, int e, int f) { | |
| 77 return a + b + c + d + e + f; | |
| 78 } | |
| 79 | |
| 80 void vcall0() { | |
| 81 count = 0; | |
| 82 } | |
| 83 | |
| 84 void vcall1(int a) { | |
| 85 count = 1; | |
| 86 } | |
| 87 | |
| 88 void vcall2(int a, int b) { | |
| 89 count = 2; | |
| 90 } | |
| 91 | |
| 92 void vcall3(int a, int b, int c) { | |
| 93 count = 3; | |
| 94 } | |
| 95 | |
| 96 void vcall4(int a, int b, int c, int d) { | |
| 97 count = 4; | |
| 98 } | |
| 99 | |
| 100 void vcall5(int a, int b, int c, int d, int e) { | |
| 101 count = 5; | |
| 102 } | |
| 103 | |
| 104 void vcall6(int a, int b, int c, int d, int e, int f) { | |
| 105 count = 6; | |
| 106 } | |
| 107 | |
| 108 // We assume int are 32 bits, short is 16 bits, char is 8 bits, | |
| 109 // float is 32 bits, double is 64 bits. | |
| 110 void* pcall0() { | |
| 111 int32* data = malloc(sizeof(int32) * 4); | |
| 112 *data = 1; | |
| 113 *(data + 1) = 2; | |
| 114 *(data + 2) = 3; | |
| 115 *(data + 3) = 4; | |
| 116 return data; | |
| 117 } | |
| 118 | |
| 119 void* pcall1(int value) { | |
| 120 int32* data = malloc(sizeof(int32) * 4); | |
| 121 *data = value; | |
| 122 *(data + 1) = value; | |
| 123 *(data + 2) = value; | |
| 124 *(data + 3) = value; | |
| 125 return data; | |
| 126 } | |
| 127 | |
| 128 void* pcall2(int value, int value2) { | |
| 129 int32* data = malloc(sizeof(int32) * 4); | |
| 130 *data = value; | |
| 131 *(data + 1) = value2; | |
| 132 *(data + 2) = value; | |
| 133 *(data + 3) = value2; | |
| 134 return data; | |
| 135 } | |
| 136 | |
| 137 void* memint8() { | |
| 138 int8* data = malloc(sizeof(int8) * 4); | |
| 139 *data = -1; | |
| 140 *(data + 1) = -128; | |
| 141 *(data + 2) = 'c'; | |
| 142 *(data + 3) = 'd'; | |
| 143 return data; | |
| 144 } | |
| 145 | |
| 146 void* memint16() { | |
| 147 int16* data = malloc(sizeof(int16) * 4); | |
| 148 *data = 32767; | |
| 149 *(data + 1) = -32768; | |
| 150 *(data + 2) = 0; | |
| 151 *(data + 3) = -1; | |
| 152 return data; | |
| 153 } | |
| 154 | |
| 155 void* memuint16() { | |
| 156 uint16* data = malloc(sizeof(uint16) * 4); | |
| 157 *data = 0; | |
| 158 *(data + 1) = 32767; | |
| 159 *(data + 2) = 32768; | |
| 160 *(data + 3) = 65535; | |
| 161 return data; | |
| 162 } | |
| 163 | |
| 164 void* memuint32() { | |
| 165 uint32* data = malloc(sizeof(uint32) * 4); | |
| 166 *data = 0; | |
| 167 *(data + 1) = 1; | |
| 168 *(data + 2) = 65536; | |
| 169 *(data + 3) = 4294967295u; | |
| 170 return data; | |
| 171 } | |
| 172 | |
| 173 void* memint64() { | |
| 174 int64* data = malloc(sizeof(int64) * 4); | |
| 175 *data = 0; | |
| 176 *(data + 1) = -1; | |
| 177 *(data + 2) = 9223372036854775807u; | |
| 178 *(data + 3) = -9223372036854775808u; | |
| 179 return data; | |
| 180 } | |
| 181 | |
| 182 void* memuint64() { | |
| 183 uint64* data = malloc(sizeof(uint64) * 4); | |
| 184 *data = 0; | |
| 185 *(data + 1) = 1; | |
| 186 *(data + 2) = 2; | |
| 187 *(data + 3) = 18446744073709551615u; | |
| 188 return data; | |
| 189 } | |
| 190 | |
| 191 void* memfloat32() { | |
| 192 float* data = malloc(sizeof(float) * 4); | |
|
kasperl
2015/06/30 07:16:00
= malloc -> = malloc
ricow1
2015/06/30 07:34:22
this was clearly just a test to see if your whites
ricow1
2015/07/02 16:01:56
Done.
| |
| 193 *data = 0.0; | |
| 194 *(data + 1) = 1.175494e-38f; | |
| 195 *(data + 2) = 3.402823e+38f; | |
| 196 *(data + 3) = 4; | |
| 197 return data; | |
| 198 } | |
| 199 | |
| 200 void* memFloat64() { | |
|
kasperl
2015/06/30 07:16:01
Float -> float?
ricow1
2015/06/30 07:34:22
Acknowledged.
ricow1
2015/07/02 16:01:56
Done.
| |
| 201 double* data = malloc(sizeof(double) * 4); | |
|
kasperl
2015/06/30 07:16:00
= malloc -> = malloc
ricow1
2015/06/30 07:34:22
Acknowledged.
ricow1
2015/07/02 16:01:56
Done.
| |
| 202 *data = 0.0; | |
| 203 *(data + 1) = 1.79769e+308; | |
| 204 *(data + 2) = -1.79769e+308; | |
| 205 *(data + 3) = 4; | |
| 206 return data; | |
| 207 } | |
| OLD | NEW |