comparison mc-codegen.c @ 338:7fe7ce0a791f bit-field-done

bit-field done for IA32, PowerPC, MIPS. bit-field assop. No bit-field global init.
author kono
date Fri, 25 Jun 2004 14:30:43 +0900 (2004-06-25)
parents d488b72254fb
children 375d21a2b845
comparison
equal deleted inserted replaced
337:694cdf15c5bd 338:7fe7ce0a791f
469 return bit_field(e2,caddr(e1) /* type */); 469 return bit_field(e2,caddr(e1) /* type */);
470 case BASS: 470 case BASS:
471 return bassign(e2,caddr(e1),cadr(cadddr(e1))/* type */); 471 return bassign(e2,caddr(e1),cadr(cadddr(e1))/* type */);
472 case BPREINC: 472 case BPREINC:
473 return bassop(e2,list2(CONST,caddr(e1)),ADD, 473 return bassop(e2,list2(CONST,caddr(e1)),ADD,
474 cadr(cadddr(e1))/* type */,0); 474 cadddr(e1)/* type */,0);
475 case BPOSTINC: 475 case BPOSTINC:
476 return bassop(e2,list2(CONST,caddr(e1)),ADD, 476 return bassop(e2,list2(CONST,caddr(e1)),ADD,
477 cadr(cadddr(e1))/* type */,1); 477 cadddr(e1)/* type */,1);
478 case BASSOP: 478 case BASSOP:
479 return bassop(e2,caddr(e1),car(cadddr(e1)),/* op */ 479 return bassop(e2,caddr(e1),car(cadddr(e1)),/* op */
480 cadr(cadddr(e1))/* type */,0); 480 cadr(cadddr(e1))/* type */,0);
481 case BFD_REPL: 481 case BFD_REPL:
482 return bit_field_repl(e2,caddr(e1),cadddr(e1) /* type */); 482 return bit_field_repl(e2,caddr(e1),cadddr(e1) /* type */);
3224 if (lo) emit_lpop_free(e2); else emit_pop_free(e2); 3224 if (lo) emit_lpop_free(e2); else emit_pop_free(e2);
3225 return cadr(t); 3225 return cadr(t);
3226 } 3226 }
3227 3227
3228 static int 3228 static int
3229 bassop(int e2,int e3,int op,int t,int post) 3229 bassign(int e2,int e3,int t)
3230 { 3230 {
3231 int n,e4; 3231 int n,e4;
3232 int type = cadr(t); 3232 int type = cadr(t);
3233 /* if op==NULL e2 = e3 */ 3233 /* e2 = e3 */
3234 /* e2 = e2 op e3; */ 3234 if (car(e2)==BIT_FIELD) {
3235 printf("# bit_field_bug\n");
3236 e2 = cadr(e2);
3237 }
3235 if (car(e2)==LREGISTER||car(e2)==REGISTER||car(e2)==LVAR||car(e2)==GVAR) { 3238 if (car(e2)==LREGISTER||car(e2)==REGISTER||car(e2)==LVAR||car(e2)==GVAR) {
3236 e4 = rvalue_t(e2,type); 3239 e4 = rvalue_t(e2,type);
3237 g_expr(assign_expr0(e2, 3240 g_expr(assign_expr0(e2, list4(BFD_REPL,e4,e3,t), type,type));
3238 list4(BFD_REPL,e4,op?list3(op,e4,e3):e3,t), 3241 if (use)
3239 type,type)); 3242 code_bit_field(t, caddr(t) /* bit offset */, USE_CREG);
3240 return type; 3243 return type;
3241 } 3244 }
3242 /* new = &e2 */ 3245 /* new = &e2 */
3243 /* *new = *new op e3 */ 3246 /* *new = *new bit_repl e3 */
3244 // n = list2(LVAR,new_lvar(size_of_int)); 3247 n = list2(LVAR,new_lvar(size_of_int));
3245 n = get_register_var(0); 3248 // n = get_register_var(0);
3246 g_expr_u(assign_expr0(n,list2(ADDRESS,cadr(e2)),INT,INT)); 3249 g_expr_u(assign_expr0(n,list2(ADDRESS,cadr(e2)),INT,INT));
3247 e4 = rvalue_t(list2(INDIRECT,n),type); 3250 e4 = rvalue_t(list2(INDIRECT,rvalue_t(n,INT)),type);
3248 g_expr(assign_expr0(list2(INDIRECT,n), 3251 g_expr(assign_expr0(list2(INDIRECT,rvalue_t(n,INT)),
3249 list4(BFD_REPL,e4,op?list3(op,e4,e3):e3,t), 3252 list4(BFD_REPL,e4,e3,t),
3250 type,type)); 3253 type,type));
3251 if (car(n)==LVAR) free_lvar(cadr(n)); 3254 free_lvar(cadr(n));
3252 else if (car(n)==REGISTER) free_register(cadr(n)); 3255 if (use)
3256 code_bit_field(t, caddr(t) /* bit offset */, USE_CREG);
3253 return type; 3257 return type;
3254 } 3258 }
3255 3259
3256 static int 3260 static int
3257 bassign(int e2,int e3,int t) 3261 bassop(int e2,int e3,int op,int t,int post)
3258 { 3262 {
3259 return bassop(e2,e3,0,t,0); 3263 /*
3264 if (simple) {
3265 tmp_var1 = bit_field byte
3266 tmp_var2 = tmp_var = code_bit_field
3267 tmp_var op= operand
3268 bit_field = tmp_var1 bit-repl tmp_var
3269 } else {
3270 address = lvalue;
3271
3272 tmp_var1 = bit_field byte (*address)
3273 tmp_var2 = tmp_var = code_bit_field
3274 tmp_var op= operand
3275 bit_field (*address) = tmp_var1 bit-repl tmp_var
3276
3277 }
3278 if (post) tmp_var2;
3279 */
3280
3281 int n=-1,n1=-1,n2=-1,adr=-1,e4;
3282 int type = cadr(t);
3283 int byte;
3284 byte = size(type); if (byte==4) byte = 0;
3285
3286 n = list2(LVAR,new_lvar(size(type)));
3287 n1 = list2(LVAR,new_lvar(size(type)));
3288 if (post) n2 = list2(LVAR,new_lvar(size(type)));
3289 /* e2 = e3 */
3290 if (car(e2)==BIT_FIELD) {
3291 printf("# bit_field_bug\n");
3292 e2 = cadr(e2);
3293 }
3294 if (!(car(e2)==LREGISTER||car(e2)==REGISTER||car(e2)==LVAR||car(e2)==GVAR)) {
3295 adr = list2(LVAR,new_lvar(size(type)));
3296 g_expr_u(assign_expr0(adr,list2(ADDRESS,cadr(e2)),INT,INT));
3297 e4 = rvalue_t(list2(INDIRECT,rvalue_t(adr,INT)),type);
3298 e2 = list2(INDIRECT,rvalue_t(adr,INT));
3299 } else {
3300 e4 = rvalue_t(e2,type);
3301 }
3302 g_expr(e4);
3303 if (type==ULONGLONG||type==LONGLONG) {
3304 code_lassign_lvar(cadr(n1),USE_CREG);
3305 code_bit_field(t, caddr(t) /* bit offset */, USE_CREG);
3306 code_lassign_lvar(cadr(n),USE_CREG);
3307 if (post) code_lassign_lvar(cadr(n2),USE_CREG);
3308 } else {
3309 code_assign_lvar(cadr(n1),USE_CREG,byte);
3310 code_bit_field(t, caddr(t) /* bit offset */, USE_CREG);
3311 code_assign_lvar(cadr(n),USE_CREG,byte);
3312 if (post) code_assign_lvar(cadr(n2),USE_CREG,byte);
3313 }
3314
3315 switch(type) {
3316 case LONGLONG: lassop(list4(LASSOP,n,longlong_value(e3),op+LOP)); break;
3317 case ULONGLONG: lassop(list4(LUASSOP,n,longlong_value(e3),op+LOP)); break;
3318 case CHAR: iassop(list4(CASSOP,n,int_value(e3),op)); break;
3319 case UCHAR: iassop(list4(CUASSOP,n,unsigned_value(e3),op)); break;
3320 case SHORT: iassop(list4(SASSOP,n,int_value(e3),op)); break;
3321 case USHORT: iassop(list4(SUASSOP,n,unsigned_value(e3),op)); break;
3322 case UNSIGNED: iassop(list4(ASSOP,n,unsigned_value(e3),op)); break;
3323 case INT: iassop(list4(ASSOP,n,int_value(e3),op)); break;
3324 default: error(-1);
3325 }
3326
3327 g_expr(assign_expr0(e2,
3328 list4(BFD_REPL,rvalue_t(n1,type),rvalue_t(n,type),t),type,type));
3329
3330 if (post) { g_expr(rvalue_t(n2,type)); free_lvar(cadr(n2)); }
3331 else if (use) {
3332 code_bit_field(t, caddr(t) /* bit offset */, USE_CREG);
3333 }
3334 if (adr!=-1) free_lvar(cadr(adr));
3335 free_lvar(cadr(n));
3336 free_lvar(cadr(n1));
3337 return type;
3260 } 3338 }
3261 3339
3262 #endif 3340 #endif
3263 3341
3264 /* temporal local variable free list */ 3342 /* temporal local variable free list */