comparison main.cbc @ 2:b15128ab0324

Fix dpp2 for cbc using LLVM 3.7
author Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
date Wed, 16 Dec 2015 17:16:29 +0900
parents d4bc23cb728b
children b7d63c5499e7
comparison
equal deleted inserted replaced
1:2874954d97b2 2:b15128ab0324
1 /* 1 /*
2 ** Dining Philosophers Problem's scheduler 2 ** Dining Philosophers Problem's scheduler
3 */ 3 */
4 #include "dpp.h" 4 #include "dpp.h"
5 __code die(char *err);
6 __code init_fork2(PhilsPtr self, int count, int id);
5 7
6 #define NUM_PHILOSOPHER 5 /* A number of philosophers must be more than 2. */ 8 #define NUM_PHILOSOPHER 5 /* A number of philosophers must be more than 2. */
7 9
8 code (*ret)(int); 10 __code (*ret)(int);
9 void *env; 11 void *env;
10 12
11 PhilsPtr phils_list = NULL; 13 PhilsPtr phils_list = NULL;
12 14
13 code run(PhilsPtr self) 15 __code run(PhilsPtr self)
14 { 16 {
15 goto thinking(self); 17 goto thinking(self);
16 } 18 }
17 19
18 code init_final(PhilsPtr self) 20 __code init_final(PhilsPtr self)
19 { 21 {
20 self->right = phils_list; 22 self->right = phils_list;
21 self->right_fork = phils_list->left_fork; 23 self->right_fork = phils_list->left_fork;
22 printf("init all\n"); 24 printf("init all\n");
23 25
24 goto run(phils_list); 26 goto run(phils_list);
25 } 27 }
26 28
27 code init_phils2(PhilsPtr self, int count, int id) 29 __code init_phils2(PhilsPtr self, int count, int id)
28 { 30 {
29 PhilsPtr tmp_self; 31 PhilsPtr tmp_self;
30 32
31 tmp_self = (PhilsPtr)malloc(sizeof(Phils)); 33 tmp_self = (PhilsPtr)malloc(sizeof(Phils));
32 if (!tmp_self) { 34 if (!tmp_self) {
48 } else { 50 } else {
49 goto init_fork2(tmp_self, count, id); 51 goto init_fork2(tmp_self, count, id);
50 } 52 }
51 } 53 }
52 54
53 code init_fork2(PhilsPtr self, int count, int id) 55 __code init_fork2(PhilsPtr self, int count, int id)
54 { 56 {
55 ForkPtr tmp_fork; 57 ForkPtr tmp_fork;
56 58
57 tmp_fork = (ForkPtr)malloc(sizeof(Fork)); 59 tmp_fork = (ForkPtr)malloc(sizeof(Fork));
58 if (!tmp_fork) { 60 if (!tmp_fork) {
63 self->right_fork = tmp_fork; 65 self->right_fork = tmp_fork;
64 66
65 goto init_phils2(self, count, id); 67 goto init_phils2(self, count, id);
66 } 68 }
67 69
68 code init_phils1(ForkPtr fork, int count, int id) 70 __code init_phils1(ForkPtr fork, int count, int id)
69 { 71 {
70 PhilsPtr self; 72 PhilsPtr self;
71 73
72 self = (PhilsPtr)malloc(sizeof(Phils)); 74 self = (PhilsPtr)malloc(sizeof(Phils));
73 if (!self) { 75 if (!self) {
85 id++; 87 id++;
86 88
87 goto init_fork2(self, count, id); 89 goto init_fork2(self, count, id);
88 } 90 }
89 91
90 code init_fork1(int count) 92 __code init_fork1(int count)
91 { 93 {
92 ForkPtr fork; 94 ForkPtr fork;
93 int id = 1; 95 int id = 1;
94 96
95 fork = (ForkPtr)malloc(sizeof(Fork)); 97 fork = (ForkPtr)malloc(sizeof(Fork));
100 fork->owner = NULL; 102 fork->owner = NULL;
101 103
102 goto init_phils1(fork, count, id); 104 goto init_phils1(fork, count, id);
103 } 105 }
104 106
105 code die(char *err) 107 __code die(char *err)
106 { 108 {
107 printf("%s\n", err); 109 printf("%s\n", err);
108 goto ret(1), env; 110 goto ret(1);
109 } 111 }
110 112
111 int main(void) 113 int main(void)
112 { 114 {
113 ret = return; 115 ret = __return;
114 env = environment; 116 env = __environment;
115 117
116 goto init_fork1(NUM_PHILOSOPHER); 118 goto init_fork1(NUM_PHILOSOPHER);
117 } 119 }
118 120
119 /* end */ 121 /* end */