Mercurial > hg > CbC > old > device
changeset 301:60dba3ef1f69
ia32, mips case. incomplete.
author | kono |
---|---|
date | Mon, 07 Jun 2004 03:33:01 +0900 |
parents | 86255dd7f148 |
children | bea7ab2fb218 |
files | mc-code-ia32.c mc-code-mips.c |
diffstat | 2 files changed, 118 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mc-code-ia32.c Mon Jun 07 02:32:07 2004 +0900 +++ b/mc-code-ia32.c Mon Jun 07 03:33:01 2004 +0900 @@ -2926,5 +2926,65 @@ #endif + + + + +#if CASE_CODE + +int +code_table_jump_p() { return 1; } + +static int table_next; + +void +code_table_jump(int l,int csvalue,int delta,int max,int min) +{ + char *crn; + use_register(creg,csvalue,0); + crn = register_name(creg,0); + table_next = fwdlabel(); + printf("\tcmpl\t$%d,%s\n",min,crn); + printf("\tjb\t_%d\n",table_next); + printf("\tcmpl\t$%d,%s\n",max,crn); + printf("\tja\t_%d\n",table_next); + printf("\tsubl\t$%d,%s\n",min,crn); + switch(delta) { + case 1: printf("\tjmp\t*_%d(,%s,4)\n",l,crn); break; + case 2: printf("\tjmp\t*_%d(,%s,2)\n",l,crn); break; + case 4: printf("\tjmp\t*_%d(%s)\n",l,crn); break; + default: + if (csvalue!=REG_EAX) + printf("\tmovl %s,%%eax\n",crn); + printf("\tmovl $%d,%%ecx\n",delta); + printf("\tcltd\n\tidivl %%ecx\n"); + printf("\tjmp\t*_%d(,%%eax,4)\n",l); + } +} + +void +code_table_open(int l) +{ + output_mode=DATA_EMIT_MODE; + printf(" \t.section\t.rodata\n\t.align 4\n"); + fwddef(l); +} + +void +code_table_value(int label,int table_top) +{ + printf("\t.long _%d\n",label); +} + +void +code_table_close() +{ + text_mode(); + fwddef(table_next); +} + +#endif + + /* end */
--- a/mc-code-mips.c Mon Jun 07 02:32:07 2004 +0900 +++ b/mc-code-mips.c Mon Jun 07 03:33:01 2004 +0900 @@ -5135,5 +5135,63 @@ fclose(asi); asi=0; } +#if CASE_CODE + +static int table_close; + +int +code_table_jump_p() { return 1; } + +void +code_table_jump(int l,int csvalue,int delta,int max,int min) +{ + int t,s; + char *crn = register_name(csvalue); + char *trn = register_name(t=get_register()); + char *srn = register_name(s=get_register()); + + table_close = fwdlabel(); + printf("\taddu\t%s,%s,%d\n",trn,crn,-min); + printf("\tsltu\t%s,%s,%d\n",srn,trn,max-min); + printf("\tbeq\t%s,$0,$L%d\n",srn,table_close); + switch(delta) { + case 1: printf("\tsll %s,%s,2\n",trn,trn); break; + case 2: printf("\tsll %s,%s,1\n",trn,trn); + case 4: break; + default: + printf("\tdivu %s,%s,%d\n",trn,trn,delta); + printf("\tsll %s,%s,2\n",trn,trn); + } + printf("\tlw\t%s,$L%d(%s)\n",trn,l,trn); + printf("\t.cpadd %s\n",trn); + printf("\tj %s\n",trn); + + free_register(s); + free_register(t); +} + +void +code_table_open(int l) +{ + printf("\t.rdata\n"); + printf("\t.align 4\n"); + fwddef(l); +} + +void +code_table_value(int label,int table_top) +{ + printf("\t.long $L%d\n",label); +} + +void +code_table_close() +{ + text_mode(4); + fwddef(table_close); +} + +#endif + /* end */