Changeset 814
- Timestamp:
- 12/23/10 07:38:11 (14 years ago)
- Files:
-
- branches/dmd-1.x/src/backend/cod2.c (modified) (1 diff)
- branches/dmd-1.x/src/backend/cod4.c (modified) (1 diff)
- branches/dmd-1.x/src/imphint.c (modified) (1 diff)
- branches/dmd-1.x/src/template.c (modified) (1 diff)
- trunk/src/template.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/dmd-1.x/src/backend/cod2.c
r810 r814 1695 1695 1696 1696 if (op1 != OPcond && op1 != OPandand && op1 != OPoror && 1697 1697 op1 != OPnot && op1 != OPbool && 1698 1698 e21->Eoper == OPconst && 1699 1699 sz1 <= REGSIZE && 1700 1700 *pretregs & (mBP | ALLREGS) && 1701 1701 tysize(e21->Ety) <= REGSIZE && !tyfloating(e21->Ety)) 1702 1702 { // Recognize (e ? c : f) 1703 1703 unsigned reg; 1704 1704 regm_t retregs; 1705 1705 1706 1706 cnop1 = gennop(CNIL); 1707 1707 retregs = mPSW; 1708 1708 jop = jmpopcode(e1); // get jmp condition 1709 1709 c = codelem(e1,&retregs,FALSE); 1710 1710 1711 1711 // Set the register with e21 without affecting the flags 1712 1712 retregs = *pretregs & (ALLREGS | mBP); 1713 1713 if (retregs & ~regcon.mvar) 1714 1714 retregs &= ~regcon.mvar; // don't disturb register variables 1715 c = regwithvalue(c,retregs,e21->EV.Vint,®,sz1 == 8 ? 64|8 : 8); 1715 // NOTE: see my email (sign extension bug? possible fix, some questions 1716 c = regwithvalue(c,retregs,e21->EV.Vint,®,tysize(e21->Ety) == 8 ? 64|8 : 8); 1716 1717 retregs = mask[reg]; 1717 1718 1718 1719 c = cat(c,cse_flush(1)); // flush CSE's to memory 1719 1720 c = genjmp(c,jop,FLcode,(block *)cnop1); 1720 1721 freenode(e21); 1721 1722 1722 1723 regconsave = regcon; 1723 1724 stackpushsave = stackpush; 1724 1725 1725 1726 c2 = codelem(e22,&retregs,FALSE); 1726 1727 1727 1728 andregcon(®consave); 1728 1729 assert(stackpushsave == stackpush); 1729 1730 1730 1731 freenode(e2); 1731 1732 c = cat6(cc,c,c2,cnop1,fixresult(e,retregs,pretregs),NULL); 1732 1733 goto Lret; 1733 1734 } 1734 1735 1735 1736 cnop1 = gennop(CNIL); branches/dmd-1.x/src/backend/cod4.c
r807 r814 3216 3216 3217 3217 /************************************* 3218 3218 * Generate code for OPbsf and OPbsr. 3219 3219 */ 3220 3220 3221 3221 code *cdbscan(elem *e, regm_t *pretregs) 3222 3222 { 3223 3223 regm_t retregs; 3224 3224 unsigned reg; 3225 3225 int sz; 3226 3226 tym_t tyml; 3227 3227 code *cl,*cg; 3228 3228 code cs; 3229 3229 3230 3230 //printf("cdbscan()\n"); 3231 3231 //elem_print(e); 3232 3232 if (*pretregs == 0) 3233 3233 return codelem(e->E1,pretregs,FALSE); 3234 3234 tyml = tybasic(e->E1->Ety); 3235 3235 sz = tysize[tyml]; 3236 assert(sz == 2 || sz == 4 );3236 assert(sz == 2 || sz == 4 || sz == 8); 3237 3237 3238 3238 if ((e->E1->Eoper == OPind && !e->E1->Ecount) || e->E1->Eoper == OPvar) 3239 3239 { 3240 3240 cl = getlvalue(&cs, e->E1, RMload); // get addressing mode 3241 3241 } 3242 3242 else 3243 3243 { 3244 3244 retregs = allregs; 3245 3245 cl = codelem(e->E1, &retregs, FALSE); 3246 3246 reg = findreg(retregs); 3247 3247 cs.Irm = modregrm(3,0,reg & 7); 3248 3248 cs.Iflags = 0; 3249 3249 cs.Irex = 0; 3250 3250 if (reg & 8) 3251 3251 cs.Irex |= REX_B; 3252 3252 } 3253 3253 3254 3254 retregs = *pretregs & allregs; 3255 3255 if (!retregs) 3256 3256 retregs = allregs; 3257 3257 cg = allocreg(&retregs, ®, e->Ety); 3258 3258 3259 3259 cs.Iop = (e->Eoper == OPbsf) ? 0x0FBC : 0x0FBD; // BSF/BSR reg,EA 3260 3260 code_newreg(&cs, reg); 3261 3261 if (!I16 && sz == SHORTSIZE) 3262 3262 cs.Iflags |= CFopsize; 3263 3263 cg = gen(cg,&cs); 3264 if (sz == 8) 3265 code_orrex(cg, REX_W); 3264 3266 3265 3267 return cat3(cl,cg,fixresult(e,retregs,pretregs)); 3266 3268 } 3267 3269 3268 3270 /******************************************* 3269 3271 * Generate code for OPpair, OPrpair. 3270 3272 */ 3271 3273 3272 3274 code *cdpair(elem *e, regm_t *pretregs) 3273 3275 { 3274 3276 regm_t retregs; 3275 3277 regm_t regs1; 3276 3278 regm_t regs2; 3277 3279 unsigned reg; 3278 3280 code *cg; 3279 3281 code *c1; 3280 3282 code *c2; 3281 3283 3282 3284 if (*pretregs == 0) // if don't want result 3283 3285 { c1 = codelem(e->E1,pretregs,FALSE); // eval left leaf branches/dmd-1.x/src/imphint.c
r767 r814 29 29 { 30 30 #if DMDV1 31 31 static const char *modules[] = 32 32 { "std.c.stdio", 33 33 "std.stdio", 34 34 "std.math", 35 35 "std.c.stdarg", 36 36 }; 37 37 static const char *names[] = 38 38 { 39 39 "printf", NULL, 40 40 "writefln", NULL, 41 41 "sin", "cos", "sqrt", "fabs", NULL, 42 42 "__va_argsave_t", NULL, 43 43 }; 44 44 #else 45 45 static const char *modules[] = 46 46 { "core.stdc.stdio", 47 47 "std.stdio", 48 48 "std.math", 49 " std.c.stdarg",49 "core.vararg", 50 50 }; 51 51 static const char *names[] = 52 52 { 53 53 "printf", NULL, 54 54 "writeln", NULL, 55 55 "sin", "cos", "sqrt", "fabs", NULL, 56 56 "__va_argsave_t", NULL, 57 57 }; 58 58 #endif 59 59 int m = 0; 60 60 for (int n = 0; n < sizeof(names)/sizeof(names[0]); n++) 61 61 { 62 62 const char *p = names[n]; 63 63 if (p == NULL) 64 64 { m++; 65 65 continue; 66 66 } 67 67 assert(m < sizeof(modules)/sizeof(modules[0])); 68 68 if (strcmp(s, p) == 0) 69 69 return modules[m]; branches/dmd-1.x/src/template.c
r801 r814 2256 2256 * This is complicated, because there may be more than one base class which 2257 2257 * matches. In such cases, one or more parameters remain ambiguous. 2258 2258 * For example, 2259 2259 * 2260 2260 * interface I(X, Y) {} 2261 2261 * class C : I(uint, double), I(char, double) {} 2262 2262 * C x; 2263 2263 * foo(T, U)( I!(T, U) x) 2264 2264 * 2265 2265 * deduces that U is double, but T remains ambiguous (could be char or uint). 2266 2266 * 2267 2267 * Given a baseclass b, and initial deduced types 'dedtypes', this function 2268 2268 * tries to match tparam with b, and also tries all base interfaces of b. 2269 2269 * If a match occurs, numBaseClassMatches is incremented, and the new deduced 2270 2270 * types are ANDed with the current 'best' estimate for dedtypes. 2271 2271 */ 2272 2272 void deduceBaseClassParameters(BaseClass *b, 2273 2273 Scope *sc, Type *tparam, TemplateParameters *parameters, Objects *dedtypes, 2274 2274 Objects *best, int &numBaseClassMatches) 2275 2275 { 2276 TemplateInstance *parti = b->base ->parent->isTemplateInstance();2276 TemplateInstance *parti = b->base ? b->base->parent->isTemplateInstance() : NULL; 2277 2277 if (parti) 2278 2278 { 2279 2279 // Make a temporary copy of dedtypes so we don't destroy it 2280 2280 Objects *tmpdedtypes = new Objects(); 2281 2281 tmpdedtypes->setDim(dedtypes->dim); 2282 2282 memcpy(tmpdedtypes->data, dedtypes->data, dedtypes->dim * sizeof(void *)); 2283 2283 2284 2284 TypeInstance *t = new TypeInstance(0, parti); 2285 2285 MATCH m = t->deduceType(sc, tparam, parameters, tmpdedtypes); 2286 2286 if (m != MATCHnomatch) 2287 2287 { 2288 2288 // If this is the first ever match, it becomes our best estimate 2289 2289 if (numBaseClassMatches==0) 2290 2290 memcpy(best->data, tmpdedtypes->data, tmpdedtypes->dim * sizeof(void *)); 2291 2291 else for (size_t k = 0; k < tmpdedtypes->dim; ++k) 2292 2292 { 2293 2293 // If we've found more than one possible type for a parameter, 2294 2294 // mark it as unknown. 2295 2295 if (tmpdedtypes->data[k] != best->data[k]) 2296 2296 best->data[k] = dedtypes->data[k]; trunk/src/template.c
r811 r814 2516 2516 * This is complicated, because there may be more than one base class which 2517 2517 * matches. In such cases, one or more parameters remain ambiguous. 2518 2518 * For example, 2519 2519 * 2520 2520 * interface I(X, Y) {} 2521 2521 * class C : I(uint, double), I(char, double) {} 2522 2522 * C x; 2523 2523 * foo(T, U)( I!(T, U) x) 2524 2524 * 2525 2525 * deduces that U is double, but T remains ambiguous (could be char or uint). 2526 2526 * 2527 2527 * Given a baseclass b, and initial deduced types 'dedtypes', this function 2528 2528 * tries to match tparam with b, and also tries all base interfaces of b. 2529 2529 * If a match occurs, numBaseClassMatches is incremented, and the new deduced 2530 2530 * types are ANDed with the current 'best' estimate for dedtypes. 2531 2531 */ 2532 2532 void deduceBaseClassParameters(BaseClass *b, 2533 2533 Scope *sc, Type *tparam, TemplateParameters *parameters, Objects *dedtypes, 2534 2534 Objects *best, int &numBaseClassMatches) 2535 2535 { 2536 TemplateInstance *parti = b->base ->parent->isTemplateInstance();2536 TemplateInstance *parti = b->base ? b->base->parent->isTemplateInstance() : NULL; 2537 2537 if (parti) 2538 2538 { 2539 2539 // Make a temporary copy of dedtypes so we don't destroy it 2540 2540 Objects *tmpdedtypes = new Objects(); 2541 2541 tmpdedtypes->setDim(dedtypes->dim); 2542 2542 memcpy(tmpdedtypes->data, dedtypes->data, dedtypes->dim * sizeof(void *)); 2543 2543 2544 2544 TypeInstance *t = new TypeInstance(0, parti); 2545 2545 MATCH m = t->deduceType(sc, tparam, parameters, tmpdedtypes); 2546 2546 if (m != MATCHnomatch) 2547 2547 { 2548 2548 // If this is the first ever match, it becomes our best estimate 2549 2549 if (numBaseClassMatches==0) 2550 2550 memcpy(best->data, tmpdedtypes->data, tmpdedtypes->dim * sizeof(void *)); 2551 2551 else for (size_t k = 0; k < tmpdedtypes->dim; ++k) 2552 2552 { 2553 2553 // If we've found more than one possible type for a parameter, 2554 2554 // mark it as unknown. 2555 2555 if (tmpdedtypes->data[k] != best->data[k]) 2556 2556 best->data[k] = dedtypes->data[k];
