annotate src/allocate/allocate_test.c @ 8:714d0ce1efd7

change configuring directory
author Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
date Wed, 01 Apr 2015 22:56:51 +0900
parents
children 14c604cfa711
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include <stdio.h>
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #include <stdlib.h>
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 #include "allocate.h"
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 #ifdef CLANG
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 #define _CbC_retrun __return
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 #define _CbC_environment __environment
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 #endif
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 #define NUM 100
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 __code start_code(Context* context) {
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 goto meta_start_code(context);
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 }
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 __code meta_start_code(Context* context) {
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 goto code1(context);
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 }
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 __code code1(Context* context) {
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 goto meta_code1(context);
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 }
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 __code meta_code1(Context* context) {
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 goto allocate(context, (int)sizeof(data1), NUM, code2);
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 }
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 __code allocate(Context* context, int size, int num, __code (*next)()) {
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 goto meta_allocate(context, size, num, next);
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 }
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 __code meta_allocate(Context* context, int size, int num, __code (*next)()) {
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 context->next = next;
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 void* ds = context->ds;
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 context->ds += size*num;
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 ((mdata*)context->mds)->ds = ds;
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 ((mdata*)context->mds)->size = size;
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 context->mds = (mdata*)context->mds+1;
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 goto context->next(context, (data1*)ds, 0);
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 }
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 __code code2(Context* context, data1* out, int loop) {
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 out->i = loop;
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 if (loop == NUM) {
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 goto meta_code2(context);
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 }
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 printf("%d\n",out->i);
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 goto code2(context, out+1, loop+1);
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 }
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 __code meta_code2(Context* context) {
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 goto exit_code(context);
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 }
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 __code exit_code(Context* context) {
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 free(context->ds_heap);
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 free(context->mds_heap);
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 goto exit(0);
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 }
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 int main() {
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 Context* context = (Context*)malloc(sizeof(Context));
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 context->ds_heap = malloc(sizeof(data1)*1024);
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 context->mds_heap = malloc(sizeof(mdata)*1024);
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 context->ds = context->ds_heap;
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 context->mds = context->mds_heap;
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 goto start_code(context);
714d0ce1efd7 change configuring directory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 }