comparison dmd/mtype.c @ 389:722f5e90c39c

Made setup for runtime calls in dmd frontend allocate less.
author Christian Kamm <kamm incasoftware de>
date Thu, 24 Jul 2008 18:51:36 +0200
parents cbb65e65236b
children cc40db549aea
comparison
equal deleted inserted replaced
388:eb110c4730c0 389:722f5e90c39c
1537 printf("TypeArray::dotExp(e = '%s', ident = '%s')\n", e->toChars(), ident->toChars()); 1537 printf("TypeArray::dotExp(e = '%s', ident = '%s')\n", e->toChars(), ident->toChars());
1538 #endif 1538 #endif
1539 if (ident == Id::reverse && (n->ty == Tchar || n->ty == Twchar)) 1539 if (ident == Id::reverse && (n->ty == Tchar || n->ty == Twchar))
1540 { 1540 {
1541 Expression *ec; 1541 Expression *ec;
1542 FuncDeclaration *fd;
1543 Expressions *arguments; 1542 Expressions *arguments;
1544 char *nm; 1543
1545 static char *name[2] = { "_adReverseChar", "_adReverseWchar" };
1546
1547 nm = name[n->ty == Twchar];
1548 //LLVMDC: Build arguments. 1544 //LLVMDC: Build arguments.
1549 Arguments* args = new Arguments; 1545 static FuncDeclaration *adReverseChar_fd = NULL;
1550 Type* arrty = n->ty == Twchar ? Type::twchar->arrayOf() : Type::tchar->arrayOf(); 1546 if(!adReverseChar_fd) {
1551 args->push(new Argument(STCin, arrty, NULL, NULL)); 1547 Arguments* args = new Arguments;
1552 fd = FuncDeclaration::genCfunc(args, arrty, nm); 1548 Type* arrty = Type::tchar->arrayOf();
1553 1549 args->push(new Argument(STCin, arrty, NULL, NULL));
1554 ec = new VarExp(0, fd); 1550 adReverseChar_fd = FuncDeclaration::genCfunc(args, arrty, "_adReverseChar");
1551 }
1552 static FuncDeclaration *adReverseWchar_fd = NULL;
1553 if(!adReverseWchar_fd) {
1554 Arguments* args = new Arguments;
1555 Type* arrty = Type::twchar->arrayOf();
1556 args->push(new Argument(STCin, arrty, NULL, NULL));
1557 adReverseWchar_fd = FuncDeclaration::genCfunc(args, arrty, "_adReverseWchar");
1558 }
1559
1560 if(n->ty == Twchar)
1561 ec = new VarExp(0, adReverseWchar_fd);
1562 else
1563 ec = new VarExp(0, adReverseChar_fd);
1555 e = e->castTo(sc, n->arrayOf()); // convert to dynamic array 1564 e = e->castTo(sc, n->arrayOf()); // convert to dynamic array
1556 arguments = new Expressions(); 1565 arguments = new Expressions();
1557 arguments->push(e); 1566 arguments->push(e);
1558 e = new CallExp(e->loc, ec, arguments); 1567 e = new CallExp(e->loc, ec, arguments);
1559 e->type = next->arrayOf(); 1568 e->type = next->arrayOf();
1560 } 1569 }
1561 else if (ident == Id::sort && (n->ty == Tchar || n->ty == Twchar)) 1570 else if (ident == Id::sort && (n->ty == Tchar || n->ty == Twchar))
1562 { 1571 {
1563 Expression *ec; 1572 Expression *ec;
1564 FuncDeclaration *fd;
1565 Expressions *arguments; 1573 Expressions *arguments;
1566 char *nm; 1574
1567 static char *name[2] = { "_adSortChar", "_adSortWchar" };
1568
1569 nm = name[n->ty == Twchar];
1570 //LLVMDC: Build arguments. 1575 //LLVMDC: Build arguments.
1571 Arguments* args = new Arguments; 1576 static FuncDeclaration *adSortChar_fd = NULL;
1572 Type* arrty = n->ty == Twchar ? Type::twchar->arrayOf() : Type::tchar->arrayOf(); 1577 if(!adSortChar_fd) {
1573 args->push(new Argument(STCin, arrty, NULL, NULL)); 1578 Arguments* args = new Arguments;
1574 fd = FuncDeclaration::genCfunc(args, arrty, nm); 1579 Type* arrty = Type::tchar->arrayOf();
1575 1580 args->push(new Argument(STCin, arrty, NULL, NULL));
1576 ec = new VarExp(0, fd); 1581 adSortChar_fd = FuncDeclaration::genCfunc(args, arrty, "_adSortChar");
1582 }
1583 static FuncDeclaration *adSortWchar_fd = NULL;
1584 if(!adSortWchar_fd) {
1585 Arguments* args = new Arguments;
1586 Type* arrty = Type::twchar->arrayOf();
1587 args->push(new Argument(STCin, arrty, NULL, NULL));
1588 adSortWchar_fd = FuncDeclaration::genCfunc(args, arrty, "_adSortWchar");
1589 }
1590
1591 if(n->ty == Twchar)
1592 ec = new VarExp(0, adSortWchar_fd);
1593 else
1594 ec = new VarExp(0, adSortChar_fd);
1577 e = e->castTo(sc, n->arrayOf()); // convert to dynamic array 1595 e = e->castTo(sc, n->arrayOf()); // convert to dynamic array
1578 arguments = new Expressions(); 1596 arguments = new Expressions();
1579 arguments->push(e); 1597 arguments->push(e);
1580 e = new CallExp(e->loc, ec, arguments); 1598 e = new CallExp(e->loc, ec, arguments);
1581 e->type = next->arrayOf(); 1599 e->type = next->arrayOf();
1582 } 1600 }
1583 else if (ident == Id::reverse || ident == Id::dup) 1601 else if (ident == Id::reverse || ident == Id::dup)
1584 { 1602 {
1585 Expression *ec; 1603 Expression *ec;
1586 FuncDeclaration *fd;
1587 Expressions *arguments; 1604 Expressions *arguments;
1588 int size = next->size(e->loc); 1605 int size = next->size(e->loc);
1589 int dup; 1606 int dup;
1590 1607
1591 assert(size); 1608 assert(size);
1592 dup = (ident == Id::dup); 1609 dup = (ident == Id::dup);
1593 //LLVMDC: Build arguments. 1610 //LLVMDC: Build arguments.
1594 Arguments* args = new Arguments; 1611 static FuncDeclaration *adDup_fd = NULL;
1595 if(dup) { 1612 if(!adDup_fd) {
1613 Arguments* args = new Arguments;
1596 args->push(new Argument(STCin, Type::typeinfo->type, NULL, NULL)); 1614 args->push(new Argument(STCin, Type::typeinfo->type, NULL, NULL));
1597 args->push(new Argument(STCin, Type::topaque->arrayOf(), NULL, NULL)); 1615 args->push(new Argument(STCin, Type::topaque->arrayOf(), NULL, NULL));
1598 } else { 1616 adDup_fd = FuncDeclaration::genCfunc(args, Type::topaque->arrayOf(), Id::adDup);
1617 }
1618 static FuncDeclaration *adReverse_fd = NULL;
1619 if(!adReverse_fd) {
1620 Arguments* args = new Arguments;
1599 args->push(new Argument(STCin, Type::topaque->arrayOf(), NULL, NULL)); 1621 args->push(new Argument(STCin, Type::topaque->arrayOf(), NULL, NULL));
1600 args->push(new Argument(STCin, Type::tsize_t, NULL, NULL)); 1622 args->push(new Argument(STCin, Type::tsize_t, NULL, NULL));
1601 } 1623 adReverse_fd = FuncDeclaration::genCfunc(args, Type::topaque->arrayOf(), Id::adReverse);
1602 fd = FuncDeclaration::genCfunc(args, Type::topaque->arrayOf(), dup ? Id::adDup : Id::adReverse); 1624 }
1603 ec = new VarExp(0, fd); 1625
1626 if(dup)
1627 ec = new VarExp(0, adDup_fd);
1628 else
1629 ec = new VarExp(0, adReverse_fd);
1604 e = e->castTo(sc, n->arrayOf()); // convert to dynamic array 1630 e = e->castTo(sc, n->arrayOf()); // convert to dynamic array
1605 arguments = new Expressions(); 1631 arguments = new Expressions();
1606 if (dup) 1632 if (dup)
1607 arguments->push(getTypeInfo(sc)); 1633 arguments->push(getTypeInfo(sc));
1608 arguments->push(e); 1634 arguments->push(e);
1612 e->type = next->arrayOf(); 1638 e->type = next->arrayOf();
1613 } 1639 }
1614 else if (ident == Id::sort) 1640 else if (ident == Id::sort)
1615 { 1641 {
1616 Expression *ec; 1642 Expression *ec;
1617 FuncDeclaration *fd;
1618 Expressions *arguments; 1643 Expressions *arguments;
1644 bool isBit = (n->ty == Tbit);
1619 1645
1620 //LLVMDC: Build arguments. 1646 //LLVMDC: Build arguments.
1621 Arguments* args = new Arguments; 1647 static FuncDeclaration *adSort_fd = NULL;
1622 args->push(new Argument(STCin, Type::topaque->arrayOf(), NULL, NULL)); 1648 if(!adSort_fd) {
1623 args->push(new Argument(STCin, Type::typeinfo->type, NULL, NULL)); 1649 Arguments* args = new Arguments;
1624 fd = FuncDeclaration::genCfunc(args, Type::topaque->arrayOf(), 1650 args->push(new Argument(STCin, Type::topaque->arrayOf(), NULL, NULL));
1625 (char*)(n->ty == Tbit ? "_adSortBit" : "_adSort")); 1651 args->push(new Argument(STCin, Type::typeinfo->type, NULL, NULL));
1626 ec = new VarExp(0, fd); 1652 adSort_fd = FuncDeclaration::genCfunc(args, Type::topaque->arrayOf(), "_adSort");
1653 }
1654 static FuncDeclaration *adSortBit_fd = NULL;
1655 if(!adSortBit_fd) {
1656 Arguments* args = new Arguments;
1657 args->push(new Argument(STCin, Type::topaque->arrayOf(), NULL, NULL));
1658 args->push(new Argument(STCin, Type::typeinfo->type, NULL, NULL));
1659 adSortBit_fd = FuncDeclaration::genCfunc(args, Type::topaque->arrayOf(), "_adSortBit");
1660 }
1661
1662 if(isBit)
1663 ec = new VarExp(0, adSortBit_fd);
1664 else
1665 ec = new VarExp(0, adSort_fd);
1627 e = e->castTo(sc, n->arrayOf()); // convert to dynamic array 1666 e = e->castTo(sc, n->arrayOf()); // convert to dynamic array
1628 arguments = new Expressions(); 1667 arguments = new Expressions();
1629 arguments->push(e); 1668 arguments->push(e);
1630 if (next->ty != Tbit) 1669 if (next->ty != Tbit)
1631 arguments->push(n->ty == Tsarray 1670 arguments->push(n->ty == Tsarray
2291 printf("TypeAArray::dotExp(e = '%s', ident = '%s')\n", e->toChars(), ident->toChars()); 2330 printf("TypeAArray::dotExp(e = '%s', ident = '%s')\n", e->toChars(), ident->toChars());
2292 #endif 2331 #endif
2293 if (ident == Id::length) 2332 if (ident == Id::length)
2294 { 2333 {
2295 Expression *ec; 2334 Expression *ec;
2296 FuncDeclaration *fd;
2297 Expressions *arguments; 2335 Expressions *arguments;
2298 2336
2299 //LLVMDC: Build arguments. 2337 //LLVMDC: Build arguments.
2300 Arguments* args = new Arguments; 2338 static FuncDeclaration *aaLen_fd = NULL;
2301 args->push(new Argument(STCin, Type::topaque->pointerTo(), NULL, NULL)); 2339 if(!aaLen_fd) {
2302 fd = FuncDeclaration::genCfunc(args, Type::tsize_t, Id::aaLen); 2340 Arguments* args = new Arguments;
2303 ec = new VarExp(0, fd); 2341 args->push(new Argument(STCin, Type::topaque->pointerTo(), NULL, NULL));
2342 aaLen_fd = FuncDeclaration::genCfunc(args, Type::tsize_t, Id::aaLen);
2343 }
2344
2345 ec = new VarExp(0, aaLen_fd);
2304 arguments = new Expressions(); 2346 arguments = new Expressions();
2305 arguments->push(e); 2347 arguments->push(e);
2306 e = new CallExp(e->loc, ec, arguments); 2348 e = new CallExp(e->loc, ec, arguments);
2307 e->type = fd->type->next; 2349 e->type = aaLen_fd->type->next;
2308 } 2350 }
2309 else if (ident == Id::keys) 2351 else if (ident == Id::keys)
2310 { 2352 {
2311 Expression *ec; 2353 Expression *ec;
2312 FuncDeclaration *fd;
2313 Expressions *arguments; 2354 Expressions *arguments;
2314 int size = key->size(e->loc); 2355 int size = key->size(e->loc);
2315 2356
2316 assert(size); 2357 assert(size);
2317 //LLVMDC: Build arguments. 2358 //LLVMDC: Build arguments.
2318 Arguments* args = new Arguments; 2359 static FuncDeclaration *aaKeys_fd = NULL;
2319 args->push(new Argument(STCin, Type::topaque->pointerTo(), NULL, NULL)); 2360 if(!aaKeys_fd) {
2320 args->push(new Argument(STCin, Type::tsize_t, NULL, NULL)); 2361 Arguments* args = new Arguments;
2321 fd = FuncDeclaration::genCfunc(args, Type::topaque->arrayOf(), Id::aaKeys); 2362 args->push(new Argument(STCin, Type::topaque->pointerTo(), NULL, NULL));
2322 ec = new VarExp(0, fd); 2363 args->push(new Argument(STCin, Type::tsize_t, NULL, NULL));
2364 aaKeys_fd = FuncDeclaration::genCfunc(args, Type::topaque->arrayOf(), Id::aaKeys);
2365 }
2366
2367 ec = new VarExp(0, aaKeys_fd);
2323 arguments = new Expressions(); 2368 arguments = new Expressions();
2324 arguments->push(e); 2369 arguments->push(e);
2325 arguments->push(new IntegerExp(0, size, Type::tsize_t)); 2370 arguments->push(new IntegerExp(0, size, Type::tsize_t));
2326 e = new CallExp(e->loc, ec, arguments); 2371 e = new CallExp(e->loc, ec, arguments);
2327 e->type = index->arrayOf(); 2372 e->type = index->arrayOf();
2328 } 2373 }
2329 else if (ident == Id::values) 2374 else if (ident == Id::values)
2330 { 2375 {
2331 Expression *ec; 2376 Expression *ec;
2332 FuncDeclaration *fd;
2333 Expressions *arguments; 2377 Expressions *arguments;
2334 2378
2335 //LLVMDC: Build arguments. 2379 //LLVMDC: Build arguments.
2336 Arguments* args = new Arguments; 2380 static FuncDeclaration *aaValues_fd = NULL;
2337 args->push(new Argument(STCin, Type::topaque->pointerTo(), NULL, NULL)); 2381 if(!aaValues_fd) {
2338 args->push(new Argument(STCin, Type::tsize_t, NULL, NULL)); 2382 Arguments* args = new Arguments;
2339 args->push(new Argument(STCin, Type::tsize_t, NULL, NULL)); 2383 args->push(new Argument(STCin, Type::topaque->pointerTo(), NULL, NULL));
2340 fd = FuncDeclaration::genCfunc(args, Type::topaque->arrayOf(), Id::aaValues); 2384 args->push(new Argument(STCin, Type::tsize_t, NULL, NULL));
2341 ec = new VarExp(0, fd); 2385 args->push(new Argument(STCin, Type::tsize_t, NULL, NULL));
2386 aaValues_fd = FuncDeclaration::genCfunc(args, Type::topaque->arrayOf(), Id::aaValues);
2387 }
2388
2389 ec = new VarExp(0, aaValues_fd);
2342 arguments = new Expressions(); 2390 arguments = new Expressions();
2343 arguments->push(e); 2391 arguments->push(e);
2344 size_t keysize = key->size(e->loc); 2392 size_t keysize = key->size(e->loc);
2345 keysize = (keysize + 4 - 1) & ~(4 - 1); 2393 keysize = (keysize + 4 - 1) & ~(4 - 1);
2346 arguments->push(new IntegerExp(0, keysize, Type::tsize_t)); 2394 arguments->push(new IntegerExp(0, keysize, Type::tsize_t));
2349 e->type = next->arrayOf(); 2397 e->type = next->arrayOf();
2350 } 2398 }
2351 else if (ident == Id::rehash) 2399 else if (ident == Id::rehash)
2352 { 2400 {
2353 Expression *ec; 2401 Expression *ec;
2354 FuncDeclaration *fd;
2355 Expressions *arguments; 2402 Expressions *arguments;
2356 2403
2357 //LLVMDC: Build arguments. 2404 //LLVMDC: Build arguments.
2358 Arguments* args = new Arguments; 2405 static FuncDeclaration *aaRehash_fd = NULL;
2359 args->push(new Argument(STCin, Type::topaque->pointerTo(), NULL, NULL)); 2406 if(!aaRehash_fd) {
2360 args->push(new Argument(STCin, Type::typeinfo->type, NULL, NULL)); 2407 Arguments* args = new Arguments;
2361 fd = FuncDeclaration::genCfunc(args, Type::tvoidptr, Id::aaRehash); 2408 args->push(new Argument(STCin, Type::topaque->pointerTo(), NULL, NULL));
2362 ec = new VarExp(0, fd); 2409 args->push(new Argument(STCin, Type::typeinfo->type, NULL, NULL));
2410 aaRehash_fd = FuncDeclaration::genCfunc(args, Type::tvoidptr, Id::aaRehash);
2411 }
2412
2413 ec = new VarExp(0, aaRehash_fd);
2363 arguments = new Expressions(); 2414 arguments = new Expressions();
2364 arguments->push(e->addressOf(sc)); 2415 arguments->push(e->addressOf(sc));
2365 arguments->push(key->getInternalTypeInfo(sc)); 2416 arguments->push(key->getInternalTypeInfo(sc));
2366 e = new CallExp(e->loc, ec, arguments); 2417 e = new CallExp(e->loc, ec, arguments);
2367 e->type = this; 2418 e->type = this;