Flutter Engine
The Flutter Engine
ffi_native_test_module.c
Go to the documentation of this file.
1// Copyright (c) 2022, the Dart 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 file.
4
5#include <emscripten.h>
6#include <stdbool.h>
7#include <stdint.h>
8#include <stdlib.h>
9
10struct MyStruct {
11 double x;
12 int16_t y;
13} s = { 1.0, 2 }, a[10];
14
15EMSCRIPTEN_KEEPALIVE
17 return &s;
18}
19
20EMSCRIPTEN_KEEPALIVE
21void clearStruct(struct MyStruct* s) {
22 s->x = 0.0;
23 s->y = 0;
24}
25
26EMSCRIPTEN_KEEPALIVE
27void empty() {}
28
29EMSCRIPTEN_KEEPALIVE
30int8_t addInt8(int8_t a, int8_t b) {
31 return a + b;
32}
33
34EMSCRIPTEN_KEEPALIVE
35uint8_t addUint8(uint8_t a, uint8_t b) {
36 return a + b;
37}
38
39EMSCRIPTEN_KEEPALIVE
40int16_t addInt16(int16_t a, int16_t b) {
41 return a + b;
42}
43
44EMSCRIPTEN_KEEPALIVE
45uint16_t addUint16(uint16_t a, uint16_t b) {
46 return a + b;
47}
48
49EMSCRIPTEN_KEEPALIVE
50int32_t addInt32(int32_t a, int32_t b) {
51 return a + b;
52}
53
54EMSCRIPTEN_KEEPALIVE
55uint32_t addUint32(uint32_t a, uint32_t b) {
56 return a + b;
57}
58
59EMSCRIPTEN_KEEPALIVE
60int64_t addInt64(int64_t a, int64_t b) {
61 return a + b;
62}
63
64EMSCRIPTEN_KEEPALIVE
65uint64_t addUint64(uint64_t a, uint64_t b) {
66 return a + b;
67}
68
69EMSCRIPTEN_KEEPALIVE
70bool negateBool(bool a) {
71 return !a;
72}
73
74static bool b = true;
75
76EMSCRIPTEN_KEEPALIVE
77void toggleBool() {
78 b = !b;
79}
80
81EMSCRIPTEN_KEEPALIVE
82bool boolReturn(int a) {
83 if (a == 123) {
84 return true;
85 } else if (a == 456) {
86 return false;
87 } else {
88 return b;
89 }
90}
91
92EMSCRIPTEN_KEEPALIVE
93char incrementChar(char a) {
94 return a + 1;
95}
96
97EMSCRIPTEN_KEEPALIVE
98unsigned char incrementUnsignedChar(unsigned char a) {
99 return a + 1;
100}
101
102EMSCRIPTEN_KEEPALIVE
103signed char incrementSignedChar(signed char a) {
104 return a + 1;
105}
106
107EMSCRIPTEN_KEEPALIVE
108short incrementShort(short a) {
109 return a + 1;
110}
111
112EMSCRIPTEN_KEEPALIVE
113unsigned short incrementUnsignedShort(unsigned short a) {
114 return a + 1;
115}
116
117EMSCRIPTEN_KEEPALIVE
118int incrementInt(int a) {
119 return a + 1;
120}
121
122EMSCRIPTEN_KEEPALIVE
123unsigned int incrementUnsignedInt(unsigned int a) {
124 return a + 1;
125}
126
127EMSCRIPTEN_KEEPALIVE
128long incrementLong(long a) {
129 return a + 1;
130}
131
132EMSCRIPTEN_KEEPALIVE
133unsigned long incrementUnsignedLong(unsigned long a) {
134 return a + 1;
135}
136
137EMSCRIPTEN_KEEPALIVE
138long long incrementLongLong(long long a) {
139 return a + 1;
140}
141
142EMSCRIPTEN_KEEPALIVE
143unsigned long long incrementUnsignedLongLong(unsigned long long a) {
144 return a + 1;
145}
146
147EMSCRIPTEN_KEEPALIVE
148intptr_t incrementIntPtr(intptr_t a) {
149 return a + 1;
150}
151
152EMSCRIPTEN_KEEPALIVE
153uintptr_t incrementUintPtr(uintptr_t a) {
154 return a + 1;
155}
156
157EMSCRIPTEN_KEEPALIVE
158size_t incrementSize(size_t a) {
159 return a + 1;
160}
161
162EMSCRIPTEN_KEEPALIVE
163wchar_t incrementWchar(wchar_t a) {
164 return a + 1;
165}
EMSCRIPTEN_KEEPALIVE size_t incrementSize(size_t a)
static bool b
EMSCRIPTEN_KEEPALIVE char incrementChar(char a)
EMSCRIPTEN_KEEPALIVE unsigned int incrementUnsignedInt(unsigned int a)
EMSCRIPTEN_KEEPALIVE bool negateBool(bool a)
struct MyStruct s
EMSCRIPTEN_KEEPALIVE int16_t addInt16(int16_t a, int16_t b)
EMSCRIPTEN_KEEPALIVE unsigned long incrementUnsignedLong(unsigned long a)
EMSCRIPTEN_KEEPALIVE short incrementShort(short a)
EMSCRIPTEN_KEEPALIVE uintptr_t incrementUintPtr(uintptr_t a)
EMSCRIPTEN_KEEPALIVE bool boolReturn(int a)
EMSCRIPTEN_KEEPALIVE int8_t addInt8(int8_t a, int8_t b)
EMSCRIPTEN_KEEPALIVE int32_t addInt32(int32_t a, int32_t b)
struct MyStruct a[10]
EMSCRIPTEN_KEEPALIVE void empty()
EMSCRIPTEN_KEEPALIVE uint8_t addUint8(uint8_t a, uint8_t b)
EMSCRIPTEN_KEEPALIVE long long incrementLongLong(long long a)
EMSCRIPTEN_KEEPALIVE unsigned char incrementUnsignedChar(unsigned char a)
EMSCRIPTEN_KEEPALIVE wchar_t incrementWchar(wchar_t a)
EMSCRIPTEN_KEEPALIVE int incrementInt(int a)
EMSCRIPTEN_KEEPALIVE signed char incrementSignedChar(signed char a)
EMSCRIPTEN_KEEPALIVE void clearStruct(struct MyStruct *s)
EMSCRIPTEN_KEEPALIVE int64_t addInt64(int64_t a, int64_t b)
EMSCRIPTEN_KEEPALIVE uint32_t addUint32(uint32_t a, uint32_t b)
EMSCRIPTEN_KEEPALIVE uint16_t addUint16(uint16_t a, uint16_t b)
EMSCRIPTEN_KEEPALIVE struct MyStruct * getStruct()
EMSCRIPTEN_KEEPALIVE unsigned short incrementUnsignedShort(unsigned short a)
EMSCRIPTEN_KEEPALIVE unsigned long long incrementUnsignedLongLong(unsigned long long a)
EMSCRIPTEN_KEEPALIVE uint64_t addUint64(uint64_t a, uint64_t b)
EMSCRIPTEN_KEEPALIVE intptr_t incrementIntPtr(intptr_t a)
EMSCRIPTEN_KEEPALIVE long incrementLong(long a)
EMSCRIPTEN_KEEPALIVE void toggleBool()