comparison mc-codegen.c @ 577:7e0076617c76

env switch continue..
author kono
date Sun, 15 Jan 2006 18:28:39 +0900
parents 00e5ce0e341a
children dbde3b869a0f
comparison
equal deleted inserted replaced
576:00e5ce0e341a 577:7e0076617c76
708 code_cmp_rgvar(e1,USE_CREG,l1,cond); 708 code_cmp_rgvar(e1,USE_CREG,l1,cond);
709 return l1; 709 return l1;
710 case RLVAR: 710 case RLVAR:
711 code_cmp_rlvar(e2,USE_CREG,l1,cond); 711 code_cmp_rlvar(e2,USE_CREG,l1,cond);
712 return l1; 712 return l1;
713 #if FLOATC_DOE 713 #if 0 && FLOAT_CODE
714 case DRLVAR: 714 case DRLVAR:
715 code_cmp_drlvar(e2,USE_CREG,1,l1,cond); 715 code_cmp_drlvar(e2,USE_CREG,1,l1,cond);
716 return l1; 716 return l1;
717 case FRLVAR: 717 case FRLVAR:
718 code_cmp_drlvar(e2,USE_CREG,0,l1,cond); 718 code_cmp_drlvar(e2,USE_CREG,0,l1,cond);
731 return l1; 731 return l1;
732 case DCONST: 732 case DCONST:
733 case FCONST: 733 case FCONST:
734 if(control&&((dcadr(e2)!=0.0)^cond)) { 734 if(control&&((dcadr(e2)!=0.0)^cond)) {
735 gen_jmp(l1); return l1; 735 gen_jmp(l1); return l1;
736 else return 0; 736 } else return 0;
737 #endif 737 #endif
738 #if LONGLONG_DOE 738 #if 0 && LONGLONG_CODE
739 case LRLVAR: 739 case LRLVAR:
740 code_cmp_lrlvar(e2,1,l1,cond); 740 code_cmp_lrlvar(e2,USE_CREG,l1,cond);
741 return l1; 741 return l1;
742 case LRGVAR: 742 case LRGVAR:
743 code_cmp_lrgvar(e2,1,l1,cond); 743 code_cmp_lrgvar(e2,USE_CREG,l1,cond);
744 return l1; 744 return l1;
745 case LREGISTER: 745 case LREGISTER:
746 code_cmp_lregister(e2,1,l1,cond); 746 code_cmp_lregister(e2,l1,cond);
747 return l1; 747 return l1;
748 case LCONST: 748 case LCONST:
749 if(control&&((lcadr(e2)!=0)^cond)) { 749 if(control&&((lcadr(e2)!=0)^cond)) {
750 gen_jmp(l1); return l1; 750 gen_jmp(l1); return l1;
751 else return 0; 751 } else return 0;
752 #endif 752 #endif
753 case REGISTER: 753 case REGISTER:
754 code_cmp_register(e2,l1,cond); 754 code_cmp_register(e2,l1,cond);
755 return l1; 755 return l1;
756 case CONST: 756 case CONST:
1359 int t0,s0,r,reg; 1359 int t0,s0,r,reg;
1360 NMTBL *code0 = 0; 1360 NMTBL *code0 = 0;
1361 int target = 0; 1361 int target = 0;
1362 int processing = 0; 1362 int processing = 0;
1363 int use = 0; 1363 int use = 0;
1364 int envreg = 0;
1364 1365
1365 /* e1 = list4(FUNCTION,code_segment,arglist,ftype); */ 1366 /* e1 = list4(FUNCTION,code_segment,arglist,ftype); */
1367
1368 if (env) {
1369 envreg = get_register_var(0);
1370 g_expr_u(assign_expr0(envreg,env,INT,INT));
1371 }
1366 1372
1367 /* まず、サイズを計算しながら、target を決まった形に落す。 */ 1373 /* まず、サイズを計算しながら、target を決まった形に落す。 */
1368 /* list5(target,next,ty,source,source_dependency) */ 1374 /* list5(target,next,ty,source,source_dependency) */
1369 1375
1370 arg_size = 0; regs = 0; 1376 arg_size = 0; regs = 0;
1377 target=list5(r, target,ty,e2,0); fregs++; 1383 target=list5(r, target,ty,e2,0); fregs++;
1378 } else if (ty==DOUBLE && (r = get_input_dregister_var(fregs,0,1,1))) { 1384 } else if (ty==DOUBLE && (r = get_input_dregister_var(fregs,0,1,1))) {
1379 target=list5(r, target,ty,e2,0); fregs++; 1385 target=list5(r, target,ty,e2,0); fregs++;
1380 } else if ((ty==LONGLONG||ty==ULONGLONG) && (r = get_input_lregister_var(fregs,0,1))) { 1386 } else if ((ty==LONGLONG||ty==ULONGLONG) && (r = get_input_lregister_var(fregs,0,1))) {
1381 target=list5(r, target,ty,e2,0); regs+=2; 1387 target=list5(r, target,ty,e2,0); regs+=2;
1388 } else if (env) {
1389 while(car(e2)==RSTRUCT) e2=cadr(e2);
1390 g_expr_u(assign_expr0(
1391 list2(INDIRECT,
1392 list3(ADD,rvalue_t(envreg,INT),list2(CONST,-arg_size-sz))
1393 ),
1394 e2,ty,ty));
1382 } else { 1395 } else {
1383 while(car(e2)==RSTRUCT) e2=cadr(e2); 1396 while(car(e2)==RSTRUCT) e2=cadr(e2);
1384 target=list5(list3(LVAR,0,0), target,ty,e2,0); 1397 target=list5(list3(LVAR,0,0), target,ty,e2,0);
1385 } 1398 }
1386 /* keep arg space for register variables */ 1399 /* keep arg space for register variables */
1387 arg_size += sz; 1400 arg_size += sz;
1388 #if DEBUG_PARALLEL_ASSIGN 1401 #if DEBUG_PARALLEL_ASSIGN
1389 printf("## target %d ty %d+%d sz %d\n",car(car(target)),ty,cadr(car(target)),sz); 1402 printf("## target %d ty %d+%d sz %d\n",car(car(target)),ty,cadr(car(target)),sz);
1390 #endif 1403 #endif
1391 } 1404 }
1405 if (env) {
1406 /* change the frame pointer during parallel assignment */
1407 target=list5(code_frame_pointer_register(), target,INT,rvalue_t(envreg,INT),0);
1408 }
1409
1392 1410
1393 /* disp を飛び先似合わせて修正 */ 1411 /* disp を飛び先似合わせて修正 */
1394 if (is_code(fnptr)) { 1412 if (is_code(fnptr)) {
1395 if (-arg_size<disp) disp = -arg_size; 1413 if (-arg_size<disp) disp = -arg_size;
1396 } else { 1414 } else {
1404 for (e2 = target; e2; e2 = cadr(e2)) { 1422 for (e2 = target; e2; e2 = cadr(e2)) {
1405 t0=car(e2); s0=cadddr(e2); 1423 t0=car(e2); s0=cadddr(e2);
1406 sz=size(ty=caddr(e2)); 1424 sz=size(ty=caddr(e2));
1407 if(car(t0)==LVAR) { 1425 if(car(t0)==LVAR) {
1408 /* ここで、書込先アドレスを決める */ 1426 /* ここで、書込先アドレスを決める */
1427 if (envreg) error(-1);
1409 cadr(t0)=-arg_size; 1428 cadr(t0)=-arg_size;
1410 } 1429 }
1411 arg_size-=sz; 1430 arg_size-=sz;
1412 #ifdef SAVE_ALL_NON_MEMORY 1431 #ifdef SAVE_ALL_NON_MEMORY
1413 if (!is_simple(car(s0))) { 1432 if (!is_simple(car(s0))) {
1482 // if (!is_code(code0)) { error(TYERR); return; } 1501 // if (!is_code(code0)) { error(TYERR); return; }
1483 } else { /* indirect */ 1502 } else { /* indirect */
1484 g_expr(e2); 1503 g_expr(e2);
1485 emit_push(); 1504 emit_push();
1486 } 1505 }
1487 if (env) {
1488 g_expr(env);
1489 emit_push();
1490 }
1491 1506
1492 /* 並列代入を実行 */ 1507 /* 並列代入を実行 */
1493 parallel_assign(&target,&processing,&use); 1508 parallel_assign(&target,&processing,&use);
1494 while (use) { 1509 while (use) {
1495 reg = car(caddr(use)); 1510 reg = car(caddr(use));
1498 else if (car(caddr(use))==LVAR) 1513 else if (car(caddr(use))==LVAR)
1499 free_lvar(cadr(caddr(use))); 1514 free_lvar(cadr(caddr(use)));
1500 use=cadr(use); 1515 use=cadr(use);
1501 } 1516 }
1502 if(target) error(-1); 1517 if(target) error(-1);
1503 1518 if(env) {
1504 if (env) { 1519 if (car(envreg)==REGISTER)
1505 /* change the frame pointer */ 1520 free_register(cadr(envreg));
1506 e3 = emit_pop(0); 1521 else free_lvar(cadr(envreg));
1507 code_frame_pointer(e3); 1522 }
1508 emit_pop_free(e3); 1523
1509 } else if (is_function(fnptr)) { 1524 if (car(e2) == FNAME) {
1510 if (car(e2) != FNAME) { 1525 if (is_function(fnptr))
1511 e2 = emit_pop(0);
1512 code_fix_frame_pointer(disp_offset); 1526 code_fix_frame_pointer(disp_offset);
1513 code_indirect_jmp(e2);
1514 emit_pop_free(e2);
1515 return;
1516 }
1517 code_fix_frame_pointer(disp_offset);
1518 }
1519
1520 if (car(e2) == FNAME) {
1521 code_jmp(code0->nm); 1527 code_jmp(code0->nm);
1522 } else { 1528 } else {
1523 e2 = emit_pop(0); 1529 e2 = emit_pop(0);
1530 if (is_function(fnptr))
1531 code_fix_frame_pointer(disp_offset);
1524 code_indirect_jmp(e2); 1532 code_indirect_jmp(e2);
1525 emit_pop_free(e2); 1533 emit_pop_free(e2);
1526 } 1534 }
1527 } 1535 }
1528 1536