comparison mc-codegen.c @ 335:4f98dc4b5fd8

bit-field continue... code-generation debug
author kono
date Fri, 25 Jun 2004 01:01:41 +0900
parents dc81596066df
children d488b72254fb
comparison
equal deleted inserted replaced
334:dc81596066df 335:4f98dc4b5fd8
2257 return n; 2257 return n;
2258 /* function and code segment are defined using fdecl/code_decl */ 2258 /* function and code segment are defined using fdecl/code_decl */
2259 /* in decl() */ 2259 /* in decl() */
2260 } 2260 }
2261 } 2261 }
2262 if (mode==GSDECL||mode==LSDECL|| mode==GUDECL||mode==LUDECL) { 2262 if (mode==GSDECL||mode==LSDECL) {
2263 /* Struct fields name lists are in the struct type or tag. */ 2263 /* Struct fields name lists are in the struct type or tag. */
2264 /* Only name in the table is used. Do not set n->ty! */ 2264 /* Only name in the table is used. Do not set n->ty! */
2265 if (car(type)==BIT_FIELD) { 2265 if (car(type)==BIT_FIELD) {
2266 bit_field_disp=sbit_f; // default is 0, recover only here. 2266 bit_field_disp=sbit_f; // default is 0, recover only here.
2267 // n->ty = list4(BIT_FIELD,type,bit_offset,bit_width); 2267 // n->ty = list4(BIT_FIELD,type,bit_offset,bit_width);
2270 /* bit_field_disp is next bit posision */ 2270 /* bit_field_disp is next bit posision */
2271 } else { 2271 } else {
2272 sz = size(type); 2272 sz = size(type);
2273 } 2273 }
2274 fields = list4(type,fields,(int)(n->nm),disp); 2274 fields = list4(type,fields,(int)(n->nm),disp);
2275 } else if (mode==GUDECL||mode==LUDECL) {
2276 if (car(type)==BIT_FIELD) {
2277 caddr(type) = 0; sz = size(cadr(type));
2278 } else {
2279 sz = size(type);
2280 }
2281 fields = list4(type,fields,(int)(n->nm),0);
2275 } else { 2282 } else {
2276 if (n->sc!=EMPTY && !(n->sc==EXTRN||n->sc==EXTRN1||n->sc==STATIC)) { 2283 if (n->sc!=EMPTY && !(n->sc==EXTRN||n->sc==EXTRN1||n->sc==STATIC)) {
2277 /* redefined case */ 2284 /* redefined case */
2278 if (mode==ADECL) { /* K&R arguments case */ 2285 if (mode==ADECL) { /* K&R arguments case */
2279 if (n->sc==LVAR && n->ty==INT); 2286 if (n->sc==LVAR && n->ty==INT);
2659 case CODE: 2666 case CODE:
2660 return e; 2667 return e;
2661 case POINTER: 2668 case POINTER:
2662 break; 2669 break;
2663 case BIT_FIELD: 2670 case BIT_FIELD:
2664 return list3(RBIT_FIELD,rvalue_t(cadr(e),cadr(type)),type); 2671 e = list3(RBIT_FIELD,rvalue_t(cadr(e),cadr(type)),type);
2665 /* byte rvalue, type */ 2672 /* byte rvalue, type */
2666 type = cadr(type); 2673 type = cadr(type);
2674 return e;
2667 break; 2675 break;
2668 default: 2676 default:
2669 error(TYERR); 2677 error(TYERR);
2670 } 2678 }
2671 } 2679 }
3205 static int 3213 static int
3206 bit_field_repl(int e1,int e2,int t) 3214 bit_field_repl(int e1,int e2,int t)
3207 { 3215 {
3208 /* e1 = e2 */ 3216 /* e1 = e2 */
3209 int lo = is_long_type(cadr(t)); 3217 int lo = is_long_type(cadr(t));
3218 g_expr(e1);
3219 if (lo) emit_lpush(); else emit_push();
3210 g_expr(e2); 3220 g_expr(e2);
3211 if (lo) emit_lpush(); else emit_push();
3212 g_expr(e1);
3213 code_bit_replace(USE_CREG,(e2=lo?emit_lpop():pop_register()), 3221 code_bit_replace(USE_CREG,(e2=lo?emit_lpop():pop_register()),
3214 t /* type */,caddr(t) /* bit offset */); 3222 t /* type */,caddr(t) /* bit offset */);
3215 if (lo) emit_lpop_free(e2); else emit_pop_free(e2); 3223 if (lo) emit_lpop_free(e2); else emit_pop_free(e2);
3216 return cadr(t); 3224 return cadr(t);
3217 } 3225 }
3218 3226
3219 static int 3227 static int
3220 bassop(int e2,int e3,int op,int t,int post) 3228 bassop(int e2,int e3,int op,int t,int post)
3221 { 3229 {
3222 int n; 3230 int n,e4;
3223 int type = cadr(t); 3231 int type = cadr(t);
3224 /* if op==NULL e2 = e3 */ 3232 /* if op==NULL e2 = e3 */
3225 /* e2 = e2 op e3; */ 3233 /* e2 = e2 op e3; */
3226 if (car(e2)==LREGISTER||car(e2)==REGISTER||car(e2)==LVAR||car(e2)==GVAR) { 3234 if (car(e2)==LREGISTER||car(e2)==REGISTER||car(e2)==LVAR||car(e2)==GVAR) {
3235 e4 = rvalue_t(e2,type);
3227 g_expr(assign_expr0(e2, 3236 g_expr(assign_expr0(e2,
3228 list4(BFD_REPL,e2,op?list3(op,rvalue_t(e2,t),e3):e3,t), 3237 list4(BFD_REPL,e4,op?list3(op,e4,e3):e3,t),
3229 type,type)); 3238 type,type));
3230 return type; 3239 return type;
3231 } 3240 }
3232 /* new = &e2 */ 3241 /* new = &e2 */
3233 /* *new = *new op e3 */ 3242 /* *new = *new op e3 */
3234 n = list2(LVAR,new_lvar(size_of_int)); 3243 // n = list2(LVAR,new_lvar(size_of_int));
3244 n = get_register_var(0);
3235 g_expr_u(assign_expr0(n,list2(ADDRESS,cadr(e2)),INT,INT)); 3245 g_expr_u(assign_expr0(n,list2(ADDRESS,cadr(e2)),INT,INT));
3246 e4 = rvalue_t(list2(INDIRECT,n),type);
3236 g_expr(assign_expr0(list2(INDIRECT,n), 3247 g_expr(assign_expr0(list2(INDIRECT,n),
3237 list4(BFD_REPL,n,op?list3(op,rvalue_t(list2(INDIRECT,n),t),e3):e3,t), 3248 list4(BFD_REPL,e4,op?list3(op,e4,e3):e3,t),
3238 type,type)); 3249 type,type));
3239 free_lvar(cadr(n)); 3250 if (car(n)==LVAR) free_lvar(cadr(n));
3251 else if (car(n)==REGISTER) free_register(cadr(n));
3240 return type; 3252 return type;
3241 } 3253 }
3242 3254
3243 static int 3255 static int
3244 bassign(int e2,int e3,int t) 3256 bassign(int e2,int e3,int t)