4
|
1 #include <stdio.h>
|
|
2 #include <stdlib.h>
|
|
3
|
|
4 #include "allocate.h"
|
|
5
|
|
6 #ifdef CLANG
|
|
7 #define _CbC_retrun __return
|
|
8 #define _CbC_environment __environment
|
|
9 #endif
|
|
10
|
5
|
11 #define SIZE 1024
|
|
12
|
4
|
13 typedef struct DataSegment1 {
|
6
|
14 int i; // 4 byte
|
|
15 char c[10]; // 10 byte
|
|
16 // padding 2 byte
|
|
17 } ds;
|
4
|
18
|
|
19 typedef struct metaDataSegment1 {
|
|
20 size_t size; // 8 byte
|
6
|
21 ds* ds; // 8 byte
|
|
22 } mds;
|
4
|
23
|
6
|
24 typedef struct Context_st {
|
|
25 ds* ds;
|
|
26 mds* mds;
|
|
27 ds* ds_heap;
|
|
28 mds* mds_heap;
|
|
29 } Context;
|
4
|
30
|
6
|
31 __code start_code(Context* context) {
|
4
|
32 goto meta_start_code(context);
|
|
33 }
|
|
34
|
6
|
35 __code meta_start_code(Context* context) {
|
4
|
36 goto code1(context);
|
|
37 }
|
|
38
|
6
|
39 __code code1(Context* context) {
|
4
|
40 goto meta_code1(context);
|
|
41 }
|
|
42
|
6
|
43 __code meta_code1(Context* context) {
|
5
|
44 goto allocate(context, SIZE);
|
4
|
45 }
|
|
46
|
6
|
47 __code allocate(Context* context, int size) {
|
|
48 ds* in = context->ds;
|
4
|
49 context->ds += size;
|
|
50 context->mds->ds = in;
|
|
51 context->mds->size = context->ds - in;
|
|
52 context->mds++;
|
|
53 goto meta_allocate(context, in);
|
|
54 }
|
|
55
|
6
|
56 __code meta_allocate(Context* context, ds* in) {
|
4
|
57 goto exit_code(context, in, 0);
|
|
58 }
|
|
59
|
6
|
60 __code exit_code(Context* context, ds* in, int i) {
|
4
|
61 in[i].i = i;
|
5
|
62 if (i == SIZE) {
|
|
63 free(context->ds_heap);
|
|
64 free(context->mds_heap);
|
4
|
65 goto exit(0);
|
5
|
66 }
|
4
|
67 goto exit_code(context, in, ++i);
|
|
68 }
|
|
69
|
|
70 int main() {
|
6
|
71 Context* context = (Context*)malloc(sizeof(Context));
|
|
72 context->ds_heap = (ds*)malloc(1024);
|
|
73 context->mds_heap = (mds*)malloc(1024);
|
4
|
74 context->ds = context->ds_heap;
|
|
75 context->mds = context->mds_heap;
|
|
76 goto start_code(context);
|
|
77 }
|