comparison mc-codegen.c @ 105:7e3d59e56a53

save register ( incomplete )
author kono
date Tue, 18 Mar 2003 01:54:46 +0900
parents c21aeb12b78b
children 06f72222d6b5
comparison
equal deleted inserted replaced
104:c21aeb12b78b 105:7e3d59e56a53
24 regv[] value in virtual register flag 24 regv[] value in virtual register flag
25 freg current floating point register 25 freg current floating point register
26 fregv calue in floating point register 26 fregv calue in floating point register
27 */ 27 */
28 28
29 void remove0(int *parent,int e) ; 29 static void remove0(int *parent,int e) ;
30 void remove0_all(int *parent,int e) ; 30 /* static void remove0_all(int *parent,int e) ; */
31 int is_same_type(int e1,int e2); 31 static int is_same_type(int e1,int e2);
32 void jump(int e1, int env); 32 static void jump(int e1, int env);
33 void machinop(int e1); 33 static void machinop(int e1);
34 void sassign(int e1); 34 static void sassign(int e1);
35 void assign(int e1); 35 static void assign(int e1);
36 void assop(int e1); 36 static void assop(int e1);
37 int g_expr0(int e1); 37 static int g_expr0(int e1);
38 static int register_to_lvar(int e);
38 39
39 void 40 void
40 codegen_init() 41 codegen_init()
41 { 42 {
42 code_init(); 43 code_init();
163 return g_expr0(e2); 164 return g_expr0(e2);
164 case RINDIRECT: case CRINDIRECT: 165 case RINDIRECT: case CRINDIRECT:
165 case DRINDIRECT: case FRINDIRECT: 166 case DRINDIRECT: case FRINDIRECT:
166 return rindirect(e1); 167 return rindirect(e1);
167 case ADDRESS: 168 case ADDRESS:
168 return g_expr0(e2); 169 if (car(e2)==REGISTER||car(e2)==DREGISTER)
170 return register_to_lvar(e2);
171 else
172 return g_expr0(e2);
169 case MINUS: /* レジスタに対し、neglを実行すれば実現可能 */ 173 case MINUS: /* レジスタに対し、neglを実行すれば実現可能 */
170 g_expr0(e2); code_neg(); 174 g_expr0(e2); code_neg();
171 return INT; 175 return INT;
172 case DMINUS: 176 case DMINUS:
173 g_expr0(e2); code_dneg(); 177 g_expr0(e2); code_dneg();
467 n = (NMTBL*)caddr(args); 471 n = (NMTBL*)caddr(args);
468 type = n->ty; 472 type = n->ty;
469 if (scalar(type)) { 473 if (scalar(type)) {
470 if(reg_var<max_input_register_var) { 474 if(reg_var<max_input_register_var) {
471 n->sc = REGISTER; 475 n->sc = REGISTER;
472 n->dsp = cadr(get_input_register_var(reg_var)); 476 n->dsp = cadr(get_input_register_var(reg_var,n));
473 regv[reg_var]= 1; 477 regv[n->dsp]= 1;
474 regs[reg_var]= INPUT_REG; 478 regs[n->dsp]= INPUT_REG;
475 reg_var++; 479 reg_var++;
476 cadddr(fnptr->dsp)=size_of_int; 480 cadddr(args)=size_of_int; /* why we need this? */
477 } 481 }
478 } else if ((type==FLOAT||type==DOUBLE)&&stmode==REGISTER) { 482 } else if ((type==FLOAT||type==DOUBLE)&&stmode==REGISTER) {
479 if(freg_var<max_input_fregister_var) { 483 if(freg_var<max_input_fregister_var) {
480 n->sc = DREGISTER; 484 n->sc = DREGISTER;
481 n->dsp = cadr(get_input_fregister_var(freg_var)); 485 n->dsp = cadr(get_input_fregister_var(freg_var,n));
482 fregv[reg_var]= 1; 486 fregv[n->dsp]= 1;
483 fregs[reg_var]= INPUT_REG; 487 fregs[n->dsp]= INPUT_REG;
484 freg_var++; 488 freg_var++;
485 cadddr(fnptr->dsp)=size_of_double; 489 cadddr(args)=size_of_double; /* why we need this? */
486 } 490 }
487 } 491 }
488 args = cadr(args); 492 args = cadr(args);
489 } 493 }
494 }
495
496 static int
497 register_to_lvar(int e)
498 {
499 error(REG_ERR);
500 return 0;
501 #if 0
502 途中でレジスタからLVARに変更しても、間に合わない。
503
504 NMTBL *n = (NMTBL*)caddr(e);
505 int reg = cadr(e);
506 int tag = car(e);
507 int lvar;
508 int t;
509 if (!n||n==&null_nptr) error(REG_ERR);
510 if (tag==REGISTER) {
511 /* regs[reg]==INPUT_REG case should be considered */
512 n->dsp = new_lvar(size_of_int);
513 t = INT;
514 } else if (tag==DREGISTER) {
515 /* fregs[reg]==INPUT_REG case should be considered */
516 n->dsp = new_lvar(size_of_double);
517 t = DOUBLE;
518 } else error(-1);
519 n->sc = LVAR;
520 lvar = list2(LVAR,n->dsp);
521 g_expr_u(assign_expr0(list2(LVAR,n->dsp),list3(tag,reg,(int)n),t,t));
522 if (tag==REGISTER) {
523 free_register(reg);
524 } else if (tag==DREGISTER) {
525 free_fregister(reg);
526 }
527 return g_expr0(lvar);
528 #endif
490 } 529 }
491 530
492 /* goto arguments list */ 531 /* goto arguments list */
493 /* target list4(list2(tag,disp),cdr,ty,source_expr) */ 532 /* target list4(list2(tag,disp),cdr,ty,source_expr) */
494 /* source expr=listn(tag,...) */ 533 /* source expr=listn(tag,...) */
541 save_target(int t,int s,int *target,int *use,int sz,int ty) 580 save_target(int t,int s,int *target,int *use,int sz,int ty)
542 { 581 {
543 int e1; 582 int e1;
544 /*新しいレジスタ(or スタック)を取得する*/ 583 /*新しいレジスタ(or スタック)を取得する*/
545 if (sz==size_of_int && (e1=get_register())!=-1) { 584 if (sz==size_of_int && (e1=get_register())!=-1) {
546 e1=list2(REGISTER,e1); 585 e1=list3(REGISTER,e1,0);
547 *use=list3(t,*use,e1); 586 *use=list3(t,*use,e1);
548 g_expr_u(assign_expr0(e1,s,ty,ty)); 587 g_expr_u(assign_expr0(e1,s,ty,ty));
549 *target = append4(*target,t,ty,e1); 588 *target = append4(*target,t,ty,e1);
550 } else if (sz==size_of_double && (e1=get_fregister())!=-1) { 589 } else if (sz==size_of_double && (e1=get_fregister())!=-1) {
551 e1=list2(DREGISTER,e1); 590 e1=list3(DREGISTER,e1,0);
552 *use=list3(t,*use,e1); 591 *use=list3(t,*use,e1);
553 g_expr_u(assign_expr0(e1,s,ty,ty)); 592 g_expr_u(assign_expr0(e1,s,ty,ty));
554 *target = append4(*target,t,ty,e1); 593 *target = append4(*target,t,ty,e1);
555 } else { 594 } else {
556 g_expr_u(assign_expr0((e1=list2(LVAR,new_lvar(sz))),s,ty,ty)); 595 g_expr_u(assign_expr0((e1=list2(LVAR,new_lvar(sz))),s,ty,ty));
632 parent=&cadr(list); 671 parent=&cadr(list);
633 } 672 }
634 } 673 }
635 } 674 }
636 675
676 /*
637 void 677 void
638 remove0_all(int *parent,int e) 678 remove0_all(int *parent,int e)
639 { 679 {
640 int list; 680 int list;
641 while ((list=*parent)) { 681 while ((list=*parent)) {
644 } else { 684 } else {
645 parent=&cadr(list); 685 parent=&cadr(list);
646 } 686 }
647 } 687 }
648 } 688 }
689 */
649 690
650 int 691 int
651 is_simple(int e1) 692 is_simple(int e1)
652 { 693 {
653 return ( 694 return (
713 fregs = 0; 754 fregs = 0;
714 for (e3 = reverse0(caddr(e1)); e3; e3 = cadr(e3)) { 755 for (e3 = reverse0(caddr(e1)); e3; e3 = cadr(e3)) {
715 e2 = car(e3); sz = size(ty=caddr(e3)); 756 e2 = car(e3); sz = size(ty=caddr(e3));
716 if (scalar(ty) && 757 if (scalar(ty) &&
717 regs < MAX_CODE_INPUT_REGISTER_VAR) { 758 regs < MAX_CODE_INPUT_REGISTER_VAR) {
718 target=list4(get_input_register_var(regs++), 759 target=list4(get_input_register_var(regs++,0),
719 target,ty,e2); 760 target,ty,e2);
720 } else if ((ty==DOUBLE||ty==FLOAT) && 761 } else if ((ty==DOUBLE||ty==FLOAT) &&
721 fregs < MAX_CODE_INPUT_DREGISTER_VAR) { 762 fregs < MAX_CODE_INPUT_DREGISTER_VAR) {
722 target=list4(get_input_fregister_var(fregs++), 763 target=list4(get_input_fregister_var(fregs++,0),
723 target,ty,e2); 764 target,ty,e2);
724 } else { 765 } else {
725 target=list4(list2(LVAR,0), target,ty,e2); 766 target=list4(list2(LVAR,0), target,ty,e2);
726 arg_size += sz; 767 arg_size += sz;
727 } 768 }