comparison final-thesis.tex @ 6:ca5f9cccece8

complete.
author kent
date Fri, 22 Feb 2008 13:46:59 +0900
parents 88409033cd91
children 01f8838d91fd
comparison
equal deleted inserted replaced
5:88409033cd91 6:ca5f9cccece8
1 % File: final.tex 1 % File: final.tex
2 % Created: 火 2 05 02:00 PM 2008 J 2 % Created: 火 2 05 02:00 PM 2008 J
3 % Last Change: 火 2 16 14:13 PM 2008 J 3 % Last Change: 火 2 22 13:35 PM 2008 J
4 % 4 %
5 \documentclass[a4j]{jreport} 5 \documentclass[a4j]{jreport}
6 \usepackage{graduate_paper} 6 \usepackage{graduate_paper}
7 \usepackage{graphicx} 7 \usepackage{graphicx}
8 \usepackage{verbatim} 8 \usepackage{verbatim}
9 \usepackage{multicol}
9 \usepackage{nonDefaultPackage/listings} 10 \usepackage{nonDefaultPackage/listings}
11
12
13 \jtitle{Continuation based CコンパイラのGCC-4.2による実装}
14 \etitle{The implementation of Continuation based C Compiler on GCC}
15 \year{平成19年度}
16 \thesis{卒業論文}
17 \logo{\includegraphics[width=15em]{figures/u-ryukyu-Mark.eps}}
18 \affiliation{琉球大学 工学部 情報工学科}
19 \author{045760E 与儀 健人\\ 指導教官 河野 真治}
20
10 21
11 \renewcommand{\lstlistingname}{リスト} 22 \renewcommand{\lstlistingname}{リスト}
12 \lstset{ 23 \lstset{
13 language=C,% 24 language=C,%
14 stringstyle=\ttfamily,% 25 stringstyle=\ttfamily,%
23 }% 34 }%
24 \def\lstlistingname{リスト} 35 \def\lstlistingname{リスト}
25 \def\lstlistlistingname{プログラムコード目次} 36 \def\lstlistlistingname{プログラムコード目次}
26 37
27 38
28 \jtitle{Continuation based CコンパイラのGCC-4.2による実装}
29 \etitle{The implementation of Continuation based C Compiler on GCC}
30 \year{平成19年度}
31 %\affiliation{琉球大学大学院理工学研究科\\ 情報工学専攻}
32 \author{045760E 与儀 健人\\ 指導教官 河野 真治}
33 %
34 %\title{Continuation based CコンパイラのGCC-4.2による実装}
35 %\author{琉球大学 工学部 情報工学科\\045760E 与儀健人 \and 指導教官 河野真治}
36 %\date{\today}
37 39
38 \begin{document} 40 \begin{document}
39 \maketitle 41 \maketitle
40 \tableofcontents 42 \tableofcontents
41 \break 43 \break
1229 ``http://gcc.gnu.org/onlinedocs/gccint/''. 1231 ``http://gcc.gnu.org/onlinedocs/gccint/''.
1230 \bibitem{takumi} 金城拓実. ``軽量継続を用いたゲームプログラムの分割と再構成の考察''. 1232 \bibitem{takumi} 金城拓実. ``軽量継続を用いたゲームプログラムの分割と再構成の考察''.
1231 琉球大学情報工学科 学位論文, Feb, 2006. 1233 琉球大学情報工学科 学位論文, Feb, 2006.
1232 \end{thebibliography} 1234 \end{thebibliography}
1233 1235
1236 \appendix
1237
1238 \chapter{conv1 プログラム}
1239 以下は第\ref{chp:appraising}章 評価で使用したプログラムconv1である。
1240 \setlength{\columnsep}{3em}
1241 \setlength{\columnseprule}{0pt}
1242 %\setlength{\columnwidth}{}
1243 \begin{multicols}{2}
1244 \begin{lstlisting}[breaklines=true,numbers=left,stepnumber=1,numberstyle=\footnotesize,framesep=5pt,frame=leftline]
1245 #include <stdio.h>
1246 #include <stdlib.h>
1247
1248 static int loop;
1249 #define CC_ONLY 0
1250
1251 /* classical function call case (0) */
1252 int f0(int);
1253 int g0(int);
1254 int h0(int);
1255
1256 f0(int i) {
1257 int k,j;
1258 k = 3+i;
1259 j = g0(i+3);
1260 return k+4+j;
1261 }
1262
1263 g0(int i) {
1264 return h0(i+4)+i;
1265 }
1266
1267 h0(int i) {
1268 return i+4;
1269 }
1270
1271 #if !CC_ONLY
1272
1273 /* straight conversion case (1) */
1274
1275 typedef char *stack;
1276
1277 struct cont_interface { // General Return Continuation
1278 __code (*ret)(int, stack);
1279 };
1280
1281 __code f_g0(int i,int k,stack sp) ;
1282 __code f_g1(int j,stack sp);
1283
1284 __code f(int i,stack sp) {
1285 int k,j;
1286 k = 3+i;
1287 goto f_g0(i,k,sp);
1288 }
1289
1290 struct f_g0_interface { // Specialized Return Continuation
1291 __code (*ret)(int, stack);
1292 int i_,k_,j_;
1293 };
1294
1295 __code g(int i,stack sp);
1296 __code f_g1(int j,stack sp) ;
1297
1298 __code f_g0(int i,int k,stack sp) { // Caller
1299 struct f_g0_interface *c =
1300 (struct f_g0_interface *)(sp -= sizeof(struct f_g0_interface));
1301
1302 c->ret = f_g1;
1303 c->k_ = k;
1304 c->i_ = i;
1305
1306 goto g(i+3,sp);
1307 }
1308
1309 __code f_g1(int j,stack sp) { // Continuation
1310 struct f_g0_interface *c = (void*)sp;
1311 int k = c->k_;
1312 __code (*ret)(int, stack);
1313
1314 sp+=sizeof(struct f_g0_interface);
1315 c = (struct f_g0_interface *)sp;
1316 ret = c->ret;
1317 goto ret(k+4+j,sp);
1318 }
1319
1320 __code g_h1(int j,stack sp);
1321 __code h(int i,stack sp);
1322 __code g_h1(int j,stack sp);
1323
1324 __code g(int i,stack sp) { // Caller
1325 struct f_g0_interface *c =
1326 (struct f_g0_interface *)(sp -= sizeof(struct f_g0_interface));
1327
1328 c->ret = g_h1;
1329 c->i_ = i;
1330
1331 goto h(i+3,sp);
1332 }
1333
1334 __code g_h1(int j,stack sp) { // Continuation
1335 struct f_g0_interface *c = (void*)sp;
1336 __code (*ret)(int, stack);
1337 int i = c->i_;
1338
1339 sp+=sizeof(struct f_g0_interface);
1340 c = (struct f_g0_interface *)sp;
1341 ret = c->ret;
1342 goto ret(j+i,sp);
1343 }
1344
1345 __code h(int i,stack sp) {
1346 struct f_g0_interface *c = (void*)sp;
1347 __code (*ret)(int, stack);
1348 ret = c->ret;
1349 goto ret(i+4,sp);
1350 }
1351
1352 struct main_continuation { // General Return Continuation
1353 __code (*ret)(int, stack);
1354 __code (*main_ret)();
1355 void *env;
1356 };
1357
1358 __code main_return(int i,stack sp) {
1359 if (loop-->0)
1360 goto f(233,sp);
1361 printf("#0103:%d?n",i);
1362 exit(0);
1363 }
1364
1365 /* little optimzation without stack continuation (2) */
1366
1367 __code g2(int i,int k,int j,char *sp) ;
1368 __code h2_1(int i,int k,int j,char *sp) ;
1369 __code h2(int i,int k,char *sp) ;
1370 __code main_return2(int i,stack sp) ;
1371 __code f2(int i,char *sp) ;
1372
1373
1374 __code f2(int i,char *sp)
1375 {
1376 int k,j;
1377 k = 3+i;
1378 goto g2(i,k,i+3,sp);
1379 }
1380
1381 __code g2(int i,int k,int j,char *sp) {
1382 j = j+4;
1383 goto h2(i,k+4+j,sp);
1384 }
1385
1386 __code h2_1(int i,int k,int j,char *sp) {
1387 goto main_return2(i+j,sp);
1388 }
1389
1390 __code h2(int i,int k,char *sp) {
1391 goto h2_1(i,k,i+4,sp);
1392 }
1393
1394 __code main_return2(int i,stack sp) {
1395 if (loop-->0)
1396 goto f2(233,sp);
1397 printf("#0132:%d?n",i);
1398 exit(0);
1399 }
1400
1401 /* little optimizaed case (3) */
1402 __code g2_1(int k,int i,char *sp) ;
1403 __code f2_0_1(int k,int j,char *sp);
1404 __code h2_1_1(int i,int k,int j,char *sp) ;
1405 __code h2_11(int i,int k,char *sp) ;
1406 __code f2_0_1(int k,int j,char *sp) ;
1407
1408 __code f2_1(int i,char *sp) {
1409 int k,j;
1410 k = 3+i;
1411 goto g2_1(k,i+3,sp);
1412 }
1413
1414 __code g2_1(int k,int i,char *sp) {
1415 goto h2_11(k,i+4,sp);
1416 }
1417
1418 __code h2_1_1(int i,int k,int j,char *sp) {
1419 goto f2_0_1(k,i+j,sp);
1420 }
1421
1422 __code h2_11(int i,int k,char *sp) {
1423 goto h2_1_1(i,k,i+4,sp);
1424 }
1425
1426 __code f2_0_1(int k,int j,char *sp) {
1427 __code (*ret)(int, stack);
1428 ret = ( (struct cont_interface *)sp)->ret;
1429 goto ret(k+4+j,sp);
1430 }
1431
1432 __code main_return2_1(int i,stack sp) {
1433 if (loop-->0)
1434 goto f2_1(233,sp);
1435 printf("#0165:%d?n",i);
1436 exit(0);
1437 }
1438
1439 #define STACK_SIZE 2048
1440 stack main_stack[STACK_SIZE];
1441 #define stack_last (&main_stack[STACK_SIZE])
1442
1443 #endif
1444
1445 #define LOOP_COUNT 0x10000000
1446
1447 void go_codesegment(int sw);
1448 main(int ac,char *av[])
1449 {
1450 int sw;
1451 if (ac==2) sw = atoi(av[1]);
1452 else sw=3;
1453
1454 go_codesegment(sw);
1455 return 0;
1456 }
1457
1458 void go_codesegment(int sw)
1459 {
1460 #if !CC_ONLY
1461 struct main_continuation *cont;
1462 stack sp = (void*)stack_last;
1463 #endif
1464
1465 int j=0;
1466 if (sw==0) {
1467 for(loop=0;loop<LOOP_COUNT;loop++) {
1468 j += f0(233+loop);
1469 }
1470 printf("#0193:%d?n",j);
1471 #if !CC_ONLY
1472 } else if (sw==1) {
1473 loop = LOOP_COUNT;
1474 sp -= sizeof(*cont);
1475 cont = (struct main_continuation *)sp;
1476 cont->ret = main_return;
1477 //cont->main_ret = return;
1478 //cont->env = environment;
1479 goto f(233,sp);
1480 } else if (sw==2) {
1481 loop = LOOP_COUNT;
1482 sp -= sizeof(*cont);
1483 cont = (struct main_continuation *)sp;
1484 cont->ret = main_return2;
1485 //cont->main_ret = return;
1486 //cont->env = environment;
1487 goto f2(233,sp);
1488 } else if (sw==3) {
1489 loop = LOOP_COUNT;
1490 sp -= sizeof(*cont);
1491 cont = (struct main_continuation *)sp;
1492 cont->ret = main_return2_1;
1493 //cont->main_ret = return;
1494 //cont->env = environment;
1495 goto f2_1(233,sp);
1496 #endif
1497 }
1498 }
1499
1500 /* end */
1501 \end{lstlisting}
1502 \end{multicols}
1503
1504
1505
1506
1234 \end{document} 1507 \end{document}
1235 1508
1236 1509
1237 TCCの評価結果 1510 TCCの評価結果
1238 conv1 0での評価 1511 conv1 0での評価