Mercurial > hg > CbC > CbC_examples
view tmp1.c @ 17:a4f44624a253
asm longjmp (can return correct address but return value is wrong)
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 24 Jan 2016 06:01:43 +0900 |
parents | 175041088754 |
children | 586096c45873 |
line wrap: on
line source
/* easy test */ #ifdef GCC #define __environment _CbC_environment #define __return _CbC_return #endif extern int printf(const char *,...); __code (*ret)(int, void*); void *env; __code exit1(int ac,void *vp); __code code0(int ac,char *av[],__code (*ret)(int, void*)); __code code1(int ac,char *av[],__code (*exit)(int,void*)); __code code3(char a,char b,int c,int d,int e,int f); __code code4(char a,char b,int c,int d,int e,int f); int main0(int ac,char *av[]) { ret = __return; env = __environment; printf("#0017:main0 %d start.\n",ac); if (ac>=1) goto code0(ac,av,__return); goto code1(ac,av,exit1); // not reached. (warning?) printf("#0022:main0 %d end.\n",ac); return 0; } __code exit1(int ac,void *vp) { goto code3(0,1,2,3,4,5); } __code code3(char a,char b,int c,int d,int e,int f) { printf("#0035:code3: %d %d %d %d %d %d\n",a,b,c,d,e,f); if(a<10) goto code3(a+1,b,c,d,e,f); else goto code4(a+3,b+3,c+3,d+3,e+3,f+3); } __code code4(char a,char b,int c,int d,int e,int f) { int i=1,j=2; printf("#0047:code4: %d %d %d %d %d %d\n",a,b,c,d,e,f); if(a<20) // cyclic binary dependency goto code3(a+b,b+c,c+d,d+e,e+f,f+a); else if(a<30) goto code3(a,b,c,d,e,f); else if(a<40) // cyclic dependency goto code3(b,c,a,e,f,d); else if(a<50) goto code4(a+i,b+j,c+i,d+3,e+3,f+3); else goto ret(0,env); } __code code0(int ac,char *av[],__code (*ret)(int, void*)) { goto code1(ac,av,ret); } __code code1(int ac,char *av[], __code (*exit)(int,void*)) { __code (*f)(int,void *); printf("#0073:code1: %d\n",ac); f = exit; if (ac>3) goto code1(ac,av,f); else if (ac>2) goto code1((int)av,(char**)ac,f); else goto (*f)(ac,env); } int main(int ac,char *av[]) { main0(1,av); printf("#0087:main continue.\n"); main0(0,av); printf("#0089:main end.\n"); return 0; } /* end */