aboutsummaryrefslogtreecommitdiff
path: root/compile_data
diff options
context:
space:
mode:
Diffstat (limited to 'compile_data')
-rw-r--r--compile_data/custom_const.c9
-rw-r--r--compile_data/custom_struct.c26
-rw-r--r--compile_data/custom_struct2.c41
-rw-r--r--compile_data/custom_struct3.c15
-rw-r--r--compile_data/custom_struct4.c28
-rw-r--r--compile_data/custom_subexp.c9
-rw-r--r--compile_data/custom_subexp2.c10
-rw-r--r--compile_data/func_pointer.c19
8 files changed, 157 insertions, 0 deletions
diff --git a/compile_data/custom_const.c b/compile_data/custom_const.c
new file mode 100644
index 0000000..d0126f3
--- /dev/null
+++ b/compile_data/custom_const.c
@@ -0,0 +1,9 @@
+int sum;
+void f() {
+ sum = 3;
+}
+int main() {
+ sum = 1;
+ f();
+ printf("%d\n", sum);
+}
diff --git a/compile_data/custom_struct.c b/compile_data/custom_struct.c
new file mode 100644
index 0000000..0d473f5
--- /dev/null
+++ b/compile_data/custom_struct.c
@@ -0,0 +1,26 @@
+struct D {
+ int a, b;
+};
+struct A {
+ int a[100];
+ struct B {
+ struct C {
+ int x, y;
+ } c;
+ int z;
+ struct D *p;
+ } b;
+} s;
+int main() {
+ struct D d;
+ int n = 0;
+ s.a[1] = 1;
+ s.a[2] = 2;
+ s.b.z = 4;
+ s.b.c.x = 5;
+ s.b.c.y = 6;
+ s.b.p = &d;
+ s.b.p->a = 7;
+ s.b.p->b = 8;
+ printf("%d %d %d %d %d %d %d\n", s.a[1], s.a[2], s.b.z, s.b.c.x, s.b.c.y, s.b.p->a, s.b.p->b);
+}
diff --git a/compile_data/custom_struct2.c b/compile_data/custom_struct2.c
new file mode 100644
index 0000000..e147186
--- /dev/null
+++ b/compile_data/custom_struct2.c
@@ -0,0 +1,41 @@
+struct A {
+ int x, y;
+} sa;
+struct A print(struct A a, struct A b) {
+ a.x++;
+ a.y++;
+ b.x--;
+ b.y--;
+ printf("args: %d %d\n", a.x, a.y);
+ printf("args: %d %d\n", b.x, b.y);
+ return a;
+}
+int main() {
+ int i;
+ int t;
+ int *a, *b;
+ struct A sb, sc;
+ a = malloc(sizeof(int) * 100);
+ for (i = 0; i < 100; i++)
+ a[i] = i;
+ b = malloc(sizeof(int) * 100);
+ memcpy(b, a, sizeof(int) * 100);
+ for (i = 0; i < 100; i++)
+ printf("%d ", b[i]);
+ sb.x = 1;
+ sb.y = 2;
+ sa = sb;
+ sc = sa;
+ printf("\n%d %d\n", sa.x, sa.y);
+ printf("%d %d\n", sc.x, sc.y);
+ sa.x = 1;
+ sa.y = 2;
+ sb.x = 1;
+ sb.y = 2;
+ sa = print(sa, sb);
+ sb = print(sa, sb);
+ sa = print(sa, sb);
+ sb = print(sa, sb);
+ printf("%d %d\n", sa.x, sa.y);
+ printf("%d %d\n", sb.x, sb.y);
+}
diff --git a/compile_data/custom_struct3.c b/compile_data/custom_struct3.c
new file mode 100644
index 0000000..d7060b3
--- /dev/null
+++ b/compile_data/custom_struct3.c
@@ -0,0 +1,15 @@
+struct A {
+ int x, y;
+} a[10];
+struct A f(struct A a) {
+ a.x++;
+ a.y++;
+ return a;
+}
+int main(){
+ int i;
+ for (i = 1; i < 10; i++)
+ a[i] = f(a[i - 1]);
+ for (i = 0; i < 10; i++)
+ printf("%d %d\n", a[i].x, a[i].y);
+}
diff --git a/compile_data/custom_struct4.c b/compile_data/custom_struct4.c
new file mode 100644
index 0000000..75f50ea
--- /dev/null
+++ b/compile_data/custom_struct4.c
@@ -0,0 +1,28 @@
+struct A {
+ struct B {
+ int x, y;
+ struct C {
+ int w;
+ } c;
+ } b;
+ int z;
+};
+
+struct B f(struct A a) {
+ printf("z: %d\n", a.z);
+ return a.b;
+}
+
+struct C g(struct B b) {
+ printf("x: %d\ny: %d\n", b.x, b.y);
+ return b.c;
+}
+
+int main() {
+ struct A a;
+ a.z = 1;
+ a.b.x = 2;
+ a.b.y = 3;
+ a.b.c.w = 4;
+ printf("w: %d\n", g(f(a)).w);
+}
diff --git a/compile_data/custom_subexp.c b/compile_data/custom_subexp.c
new file mode 100644
index 0000000..bce5bdb
--- /dev/null
+++ b/compile_data/custom_subexp.c
@@ -0,0 +1,9 @@
+int N = 0;
+void f() { N = 2; }
+int main() {
+ int a, b;
+ a = N + 1;
+ f();
+ b = N + 1;
+ printf("%d\n", b);
+}
diff --git a/compile_data/custom_subexp2.c b/compile_data/custom_subexp2.c
new file mode 100644
index 0000000..1e4af93
--- /dev/null
+++ b/compile_data/custom_subexp2.c
@@ -0,0 +1,10 @@
+int flag = 0;
+int check(int x, int y) {
+ return x > 0 && y > 0 && (flag ^= 1);
+}
+int main() {
+ int x = 1, y = 2;
+ printf("%d\n", check(x, y));
+ printf("%d\n", check(x, y));
+ printf("%d\n", check(x, y));
+}
diff --git a/compile_data/func_pointer.c b/compile_data/func_pointer.c
new file mode 100644
index 0000000..e7b6484
--- /dev/null
+++ b/compile_data/func_pointer.c
@@ -0,0 +1,19 @@
+typedef void (*Func_t)();
+void f(Func_t func, int step) {
+ if (!step) return;
+ printf("i'm f\n");
+ func(func, step - 1);
+}
+void g(void (*func)(), int step) {
+ if (!step) return;
+ printf("i'm g\n");
+ func(func, step - 1);
+}
+int main() {
+ void (*func)(void (*ifunc)(), int step);
+ int x = 1;
+ if (x) func = f;
+ else func = g;
+ func(func, 5);
+ return 0;
+}