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

Unified 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, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/vm/ffi_posix.cc ('k') | src/vm/list.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/vm/ffi_test_library.c
diff --git a/src/vm/ffi_test_library.c b/src/vm/ffi_test_library.c
new file mode 100644
index 0000000000000000000000000000000000000000..3cfa5871e7e2003ea0c50583165056b7b1091fc2
--- /dev/null
+++ b/src/vm/ffi_test_library.c
@@ -0,0 +1,206 @@
+// Copyright (c) 2015, the Fletch project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE.md file.
+
+// Testing library for testing the foreign function interface.
+// There are no tests in this file, but we keep this to have a single place
+// for functionality that we want to test in the FFI implementation.
+
+#include <stdio.h>
+#include <stdlib.h>
+
+// Copied from globals.h to have consistent values
+// TODO(ricow): we could split globals into a c only part and a c++ part.
+typedef signed char int8;
+typedef short int16; // NOLINT
+typedef int int32;
+
+typedef unsigned char uint8;
+typedef unsigned short uint16; // NOLINT
+typedef unsigned int uint32;
+
+#ifdef FLETCH64
+typedef long int64; // NOLINT
+typedef unsigned long uint64; // NOLINT
+typedef char foobar;
+#else
+typedef long long int int64; // NOLINT
+typedef long long unsigned uint64;
+typedef int foobar;
+#endif
+
+static int count;
+
+void setup() {
+ count = 0;
+}
+
+int getcount() {
+ return count;
+}
+
+void inc() {
+ count++;
+}
+
+int setcount(int val) {
+ count = val;
+ return count;
+}
+
+int ifun0() {
+ return 0;
+}
+
+int ifun1(int a) {
+ return a;
+}
+
+int ifun2(int a, int b) {
+ return a + b;
+}
+
+int ifun3(int a, int b, int c) {
+ return a + b + c;
+}
+
+int ifun4(int a, int b, int c, int d) {
+ return a + b + c + d;
+}
+
+int ifun5(int a, int b, int c, int d, int e) {
+ return a + b + c + d + e;
+}
+
+int ifun6(int a, int b, int c, int d, int e, int f) {
+ return a + b + c + d + e + f;
+}
+
+void vfun0() {
+ count = 0;
+}
+
+void vfun1(int a) {
+ count = 1;
+}
+
+void vfun2(int a, int b) {
+ count = 2;
+}
+
+void vfun3(int a, int b, int c) {
+ count = 3;
+}
+
+void vfun4(int a, int b, int c, int d) {
+ count = 4;
+}
+
+void vfun5(int a, int b, int c, int d, int e) {
+ count = 5;
+}
+
+void vfun6(int a, int b, int c, int d, int e, int f) {
+ count = 6;
+}
+
+// We assume int are 32 bits, short is 16 bits, char is 8 bits,
+// float is 32 bits, double is 64 bits.
+void* pfun0() {
+ int32* data = malloc(sizeof(int32) * 4);
+ *data = 1;
+ *(data + 1) = 2;
+ *(data + 2) = 3;
+ *(data + 3) = 4;
+ return data;
+}
+
+void* pfun1(int value) {
+ int32* data = malloc(sizeof(int32) * 4);
+ *data = value;
+ *(data + 1) = value;
+ *(data + 2) = value;
+ *(data + 3) = value;
+ return data;
+}
+
+void* pfun2(int value, int value2) {
+ int32* data = malloc(sizeof(int32) * 4);
+ *data = value;
+ *(data + 1) = value2;
+ *(data + 2) = value;
+ *(data + 3) = value2;
+ return data;
+}
+
+void* memint8() {
+ int8* data = malloc(sizeof(int8) * 4);
+ *data = -1;
+ *(data + 1) = -128;
+ *(data + 2) = 'c';
+ *(data + 3) = 'd';
+ return data;
+}
+
+void* memint16() {
+ int16* data = malloc(sizeof(int16) * 4);
+ *data = 32767;
+ *(data + 1) = -32768;
+ *(data + 2) = 0;
+ *(data + 3) = -1;
+ return data;
+}
+
+void* memuint16() {
+ uint16* data = malloc(sizeof(uint16) * 4);
+ *data = 0;
+ *(data + 1) = 32767;
+ *(data + 2) = 32768;
+ *(data + 3) = 65535;
+ return data;
+}
+
+void* memuint32() {
+ uint32* data = malloc(sizeof(uint32) * 4);
+ *data = 0;
+ *(data + 1) = 1;
+ *(data + 2) = 65536;
+ *(data + 3) = 4294967295u;
+ return data;
+}
+
+void* memint64() {
+ int64* data = malloc(sizeof(int64) * 4);
+ *data = 0;
+ *(data + 1) = -1;
+ *(data + 2) = 9223372036854775807u;
+ *(data + 3) = -9223372036854775808u;
+ return data;
+}
+
+void* memuint64() {
+ uint64* data = malloc(sizeof(uint64) * 4);
+ *data = 0;
+ *(data + 1) = 1;
+ *(data + 2) = 2;
+ *(data + 3) = 18446744073709551615u;
+ return data;
+}
+
+void* memfloat32() {
+ float* data = malloc(sizeof(float) * 4);
+ *data = 0.0;
+ *(data + 1) = 1.175494e-38f;
+ *(data + 2) = 3.402823e+38f;
+ *(data + 3) = 4;
+ return data;
+}
+
+void* memfloat64() {
+ double* data = malloc(sizeof(double) * 4);
+ *data = 0.0;
+ *(data + 1) = 1.79769e+308;
+ *(data + 2) = -1.79769e+308;
+ *(data + 3) = 4;
+ return data;
+}
« 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