Mercurial > hg > CbC > CbC_gcc
annotate CbC-examples/c-next.c @ 140:4e440907fcbf
copy CbC goto flang in cfgexpand
remove some CbC unnecessary code
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 14 Nov 2018 00:24:45 +0900 |
parents | fc828634a951 |
children | ce508c72660f |
rev | line source |
---|---|
134 | 1 #define NEXT_OP(i) (i->op = *(MVMuint16 *)(i->cur_op), i->cur_op += 2, i->op) |
2 | |
3 typedef unsigned short MVMuint16; | |
4 typedef unsigned char MVMuint8; | |
5 typedef long* MVMRegister; | |
6 typedef void* MVMCompUnit; | |
7 typedef void* MVMCallsite; | |
135 | 8 //typedef void* MVMThreadContext; |
134 | 9 |
10 typedef struct MVMThreadContext { | |
11 MVMuint8 **interp_cur_op; | |
12 MVMuint8 **interp_bytecode_start; | |
13 MVMRegister **interp_reg_base; | |
14 MVMCompUnit **interp_cu; | |
15 } MVMThreadContext; | |
16 | |
135 | 17 |
134 | 18 typedef struct interp { |
19 MVMuint16 op; | |
20 /* Points to the place in the bytecode right after the current opcode. */ | |
21 /* See the NEXT_OP macro for making sense of this */ | |
22 MVMuint8 *cur_op; | |
23 | |
24 /* The current frame's bytecode start. */ | |
25 MVMuint8 *bytecode_start; | |
26 | |
27 /* Points to the base of the current register set for the frame we | |
28 * * are presently in. */ | |
29 MVMRegister *reg_base; | |
30 | |
31 /* Points to the current compilation unit. */ | |
32 MVMCompUnit *cu; | |
33 | |
34 /* The current call site we're constructing. */ | |
35 MVMCallsite *cur_callsite; | |
36 | |
37 MVMThreadContext *tc; | |
38 | |
135 | 39 //__code (*ret)(); |
40 //__code (*main_ret)(); | |
134 | 41 __code (*ret)(int, void*); |
42 __code (*main_ret)(int, void*); | |
43 void *env; | |
44 | |
45 } INTER,*INTERP; | |
46 | |
135 | 47 __code cbc_no_op(INTERP); |
48 __code cbc_exit(INTERP); | |
134 | 49 |
135 | 50 __code (* CODES[])(INTERP) = { |
134 | 51 cbc_no_op, |
52 cbc_no_op, | |
53 cbc_exit, | |
54 }; | |
55 | |
56 __code cbc_next(INTERP i){ | |
57 __code (*c)(INTERP); | |
58 c = CODES[NEXT_OP(i)]; | |
140
4e440907fcbf
copy CbC goto flang in cfgexpand
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
138
diff
changeset
|
59 //c(i); |
134 | 60 goto c(i); |
61 } | |
62 | |
135 | 63 __code cbc_no_op(INTERP i){ |
64 goto cbc_next(i); | |
65 } | |
66 | |
67 __code cbc_exit(INTERP i){ | |
68 goto i->main_ret(0,i->env); | |
134 | 69 } |
70 | |
135 | 71 //__code main_return(int i,stack sp) { |
72 // if (loop-->0) | |
73 // goto f(233,sp); | |
74 // printf("#0103:%d\n",i); | |
75 // goto (( (struct main_continuation *)sp)->main_ret)(0, | |
76 // ((struct main_continuation *)sp)->env); | |
77 //} | |
78 | |
79 int interp_run(MVMThreadContext *tc){ | |
134 | 80 INTER inter = {0,0,0,0,0,0,0,0,0}; |
81 INTERP i = &inter; | |
135 | 82 MVMuint8 cur_op[] = {0,1,1,0,1,2}; |
83 // i->ret = main_return; | |
134 | 84 i->main_ret = _CbC_return; |
85 i->env = _CbC_environment; | |
135 | 86 i->cur_op = cur_op; |
134 | 87 |
88 tc->interp_cur_op = &i->cur_op; | |
89 tc->interp_bytecode_start = &i->bytecode_start; | |
90 tc->interp_reg_base = &i->reg_base; | |
91 tc->interp_cu = &i->cu; | |
92 goto cbc_next(i); | |
135 | 93 return 0; |
134 | 94 } |
135 | 95 |
96 int main(int argc, char **argv){ | |
97 MVMThreadContext tct = {0,0,0,0}; | |
98 MVMThreadContext* tc = &tct; | |
99 interp_run(tc); | |
100 } |