Mercurial > hg > CbC > old > device
comparison mc-code-powerpc.c @ 320:183726ccd83d
asm minor fix. ia32 table jmp fix.
author | kono |
---|---|
date | Sat, 19 Jun 2004 00:13:36 +0900 |
parents | 88cf6512fa1b |
children | 575481408653 |
comparison
equal
deleted
inserted
replaced
319:88cf6512fa1b | 320:183726ccd83d |
---|---|
2997 } else if(car(e)==FNAME) { | 2997 } else if(car(e)==FNAME) { |
2998 printf("\t.long _%s\n",((NMTBL *)cadr(e))->nm); | 2998 printf("\t.long _%s\n",((NMTBL *)cadr(e))->nm); |
2999 } else if(car(e)==GVAR) { | 2999 } else if(car(e)==GVAR) { |
3000 printf("\t.long _%s\n",((NMTBL *)cadr(e))->nm); | 3000 printf("\t.long _%s\n",((NMTBL *)cadr(e))->nm); |
3001 } else if(car(e)==STRING) { | 3001 } else if(car(e)==STRING) { |
3002 if (car(n->ty)!=ARRAY || cadr(n->ty)!=CHAR) { | 3002 if (car(n->ty)!=ARRAY || cadr(n->ty)!=CHAR) { |
3003 l = emit_string_label(); | 3003 l = emit_string_label(); |
3004 } | 3004 ascii((char *)cadr(e)); |
3005 ascii((char *)cadr(e)); | 3005 data_mode(0); |
3006 printf("\t.long L_%d\n",l); | |
3007 } else | |
3008 ascii((char *)cadr(e)); | |
3006 } else error(TYERR); | 3009 } else error(TYERR); |
3007 } else error(TYERR); | 3010 } else error(TYERR); |
3008 } | 3011 } |
3009 | 3012 |
3010 void | 3013 void |
4936 #endif | 4939 #endif |
4937 | 4940 |
4938 #if ASM_CODE | 4941 #if ASM_CODE |
4939 | 4942 |
4940 /* | 4943 /* |
4941 __asm__ __volatile__ ("sthbrx %1,0,%2" : "=m" (*addr) : "r" (val), "r" (a | 4944 print an operand |
4942 ddr)); | |
4943 asm string : output constraint parameter : input constraint parameter : opt | |
4944 | |
4945 1: asm string %1,%2 will be replaced by register or value | |
4946 2: constraint gcc constraint sting | |
4947 prefix | |
4948 = overwrite by this asm for output | |
4949 & overwrite by this asm and can't be used as input register | |
4950 ignored in this compiler | |
4951 constraints | |
4952 m value expression is modified (no coresponding register) | |
4953 information for compiler | |
4954 r register for input or output | |
4955 input register, output register can be shared | |
4956 0-9 same operands as outout register in input constraints | |
4957 3: opt "cc", "memory" | |
4958 ignored in this compiler | |
4959 */ | 4945 */ |
4960 | 4946 |
4961 | |
4962 #define MAX_ASM_REG 30 | |
4963 | |
4964 static void | 4947 static void |
4965 print_asm_reg(int rstr) | 4948 emit_asm_operand(int rstr) |
4966 { | 4949 { |
4967 if (car(rstr)==REGISTER) { | 4950 if (car(rstr)==REGISTER) { |
4968 printf("%s",register_name(cadr(rstr))); | 4951 printf("%s",register_name(cadr(rstr))); |
4969 } else if (car(rstr)==CONST) { | 4952 } else if (car(rstr)==CONST) { |
4970 printf("%d",cadr(rstr)); | 4953 printf("%d",cadr(rstr)); |
4975 } else { | 4958 } else { |
4976 error(-1); | 4959 error(-1); |
4977 } | 4960 } |
4978 } | 4961 } |
4979 | 4962 |
4980 static void | 4963 /* |
4981 replace_asm_string(char *asm_str,int repl) | 4964 prepare asm operands |
4982 { | 4965 |
4983 int c,i,rstr,val; | 4966 char *constraints sgtring |
4984 char *p; | 4967 int oeprand expre |
4985 int reg[MAX_ASM_REG]; | 4968 int mode (ASM_INPUT,ASM_OUTPUT) |
4986 | 4969 int replacement list |
4987 text_mode(); | 4970 int output operands count |
4988 c = *asm_str; | 4971 int output operands replacement list |
4989 if (c!='\t'&&c!=' ') printf("\t"); | 4972 |
4990 for(i=0;repl && i<MAX_ASM_REG;i++) { | 4973 retrun replacement list |
4991 reg[i] = car(repl); | 4974 list3( operands, next, clobber ) |
4992 repl = cadr(repl); | 4975 0 can be shared in input/output |
4993 } | 4976 1 can't be used in input |
4994 p = asm_str; | 4977 */ |
4995 while((c = *p++)) { | 4978 |
4996 if (c=='%') { | 4979 int |
4997 c = *p++; | |
4998 if (!c) { break; | |
4999 } else if (c=='%') { | |
5000 printf("%%"); continue; | |
5001 } else if (!digit(c)) { | |
5002 printf("%%%c",c); continue; | |
5003 } | |
5004 val = 0; | |
5005 do { val = val*10 + c-'0'; } while (digit(c=*p++)) ; | |
5006 p--; | |
5007 if (val>MAX_ASM_REG) error(-1); // too large register | |
5008 rstr = reg[val]; | |
5009 print_asm_reg(rstr); | |
5010 } else { | |
5011 printf("%c",c); | |
5012 } | |
5013 } | |
5014 printf("\n"); | |
5015 } | |
5016 | |
5017 #define ASM_INPUT 1 | |
5018 #define ASM_OUTPUT 2 | |
5019 #define ASM_USED 3 | |
5020 | |
5021 static int | |
5022 asm_operand(char *p,int e1,int mode,int repl,int n,int repl0) | 4980 asm_operand(char *p,int e1,int mode,int repl,int n,int repl0) |
5023 { | 4981 { |
5024 int r; | 4982 int r; |
5025 int c; | 4983 int c; |
5026 int val; | 4984 int val; |
5071 repl = list3(car(nth(n-val-1,repl0)),repl,clobber); | 5029 repl = list3(car(nth(n-val-1,repl0)),repl,clobber); |
5072 } else error(-1); | 5030 } else error(-1); |
5073 return repl; | 5031 return repl; |
5074 } | 5032 } |
5075 | 5033 |
5076 static void | 5034 void |
5077 free_asm_operand(int repl) | 5035 free_asm_operand(int repl) |
5078 { | 5036 { |
5079 for(;repl;repl=cadr(repl)) { | 5037 for(;repl;repl=cadr(repl)) { |
5080 if (car(car(repl))==REGISTER) | 5038 if (car(car(repl))==REGISTER) |
5081 free_register(cadr(car(repl))); | 5039 free_register(cadr(car(repl))); |
5082 } | 5040 } |
5083 } | 5041 } |
5084 | 5042 |
5085 void | 5043 |
5086 code_asm(int asm0,int in,int out,int opt,int e) | 5044 extern void |
5087 { | 5045 replace_asm_string(char *asm_str,int repl) |
5088 int i,e1,n; | 5046 { |
5089 int repl = 0; | 5047 int c,i,rstr,val; |
5090 int repl0; | |
5091 int assign = 0; | |
5092 char *p; | 5048 char *p; |
5093 | 5049 int reg[MAX_ASM_REG]; |
5094 printf("# asm\n"); | 5050 |
5095 in = reverse0(in); | 5051 text_mode(); |
5096 out = reverse0(out); | 5052 c = *asm_str; |
5097 e = reverse0(e); | 5053 if (c!='\t'&&c!=' ') printf("\t"); |
5098 for(i=out;i;i=cadr(i)) { | 5054 for(i=0;repl && i<MAX_ASM_REG;i++) { |
5099 p = (char*)cadr(car(i)); | 5055 reg[i] = car(repl); |
5100 e1 = car(e); e = cadr(e); | 5056 repl = cadr(repl); |
5101 repl = asm_operand(p,e1,ASM_OUTPUT,repl,0,0); | 5057 } |
5102 if (car(car(repl))==REGISTER) { | 5058 p = asm_str; |
5103 assign = list2(assign_expr0(e1,car(repl),INT,INT),assign); | 5059 while((c = *p++)) { |
5060 if (c=='%') { | |
5061 c = *p++; | |
5062 if (!c) { break; | |
5063 } else if (c=='%') { | |
5064 printf("%%"); continue; | |
5065 } else if (!digit(c)) { | |
5066 printf("%%%c",c); continue; | |
5067 } | |
5068 val = 0; | |
5069 do { val = val*10 + c-'0'; } while (digit(c=*p++)) ; | |
5070 p--; | |
5071 if (val>MAX_ASM_REG) error(-1); // too large register | |
5072 rstr = reg[val]; | |
5073 emit_asm_operand(rstr); | |
5074 } else { | |
5075 printf("%c",c); | |
5104 } | 5076 } |
5105 } | 5077 } |
5106 repl0 = repl; | 5078 printf("\n"); |
5107 n = length(repl0); | |
5108 for(i=in;i;i=cadr(i)) { | |
5109 p = (char*)cadr(car(i)); | |
5110 e1 = car(e); e = cadr(e); | |
5111 repl = asm_operand(p,e1,ASM_INPUT,repl,n,repl0); | |
5112 if (car(car(repl))==REGISTER) { | |
5113 g_expr_u(assign_expr0(car(repl),e1,INT,INT)); | |
5114 } | |
5115 } | |
5116 repl = reverse0(repl); | |
5117 replace_asm_string((char*)cadr(asm0),repl); | |
5118 for(i=assign;i;i=cadr(i)) { | |
5119 g_expr_u(car(i)); | |
5120 } | |
5121 free_asm_operand(repl); | |
5122 // no check for opt | |
5123 } | 5079 } |
5124 | 5080 |
5125 #endif | 5081 #endif |
5126 | 5082 |
5127 | 5083 |