comparison dmd/mtype.c @ 715:30b42a283c8e

Removed TypeOpaque from DMD. Changed runtime functions taking opaque[] to void[]. Implemented proper type painting, to avoid "resizing" array casts in runtime calls that previously took opaque[]. Implemented dynamic arrays as first class types, this implements proper ABI for these types on x86. Added dwarf region end after call to assert function, fixes some problems with llvm not allowing this to be missing. Reverted change to WithStatement from rev [704] it breaks MiniD, mini/with2.d needs to be fixed some other way... Fixed tango bug 1339 in runtime, problem with _adReverseChar on invalid UTF-8. Disabled .bc generation in the compiler runtime part, genobj.d triggers some llvm bug when using debug info. the .o seems to work fine.
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Wed, 22 Oct 2008 14:55:33 +0200
parents eef8ac26c66c
children a26b0c5d5942
comparison
equal deleted inserted replaced
714:1e98c99a87cb 715:30b42a283c8e
101 ClassDeclaration *Type::typeinfoenum; 101 ClassDeclaration *Type::typeinfoenum;
102 ClassDeclaration *Type::typeinfofunction; 102 ClassDeclaration *Type::typeinfofunction;
103 ClassDeclaration *Type::typeinfodelegate; 103 ClassDeclaration *Type::typeinfodelegate;
104 ClassDeclaration *Type::typeinfotypelist; 104 ClassDeclaration *Type::typeinfotypelist;
105 105
106 // LDC
107 Type* Type::topaque;
108
109 Type *Type::tvoidptr; 106 Type *Type::tvoidptr;
110 Type *Type::basic[TMAX]; 107 Type *Type::basic[TMAX];
111 unsigned char Type::mangleChar[TMAX]; 108 unsigned char Type::mangleChar[TMAX];
112 StringTable Type::stringtable; 109 StringTable Type::stringtable;
113 110
208 mangleChar[Terror] = '@'; 205 mangleChar[Terror] = '@';
209 mangleChar[Ttypeof] = '@'; 206 mangleChar[Ttypeof] = '@';
210 mangleChar[Ttuple] = 'B'; 207 mangleChar[Ttuple] = 'B';
211 mangleChar[Tslice] = '@'; 208 mangleChar[Tslice] = '@';
212 209
213 // LDC
214 mangleChar[Topaque] = 'O';
215
216 for (i = 0; i < TMAX; i++) 210 for (i = 0; i < TMAX; i++)
217 { if (!mangleChar[i]) 211 { if (!mangleChar[i])
218 fprintf(stdmsg, "ty = %d\n", i); 212 fprintf(stdmsg, "ty = %d\n", i);
219 assert(mangleChar[i]); 213 assert(mangleChar[i]);
220 } 214 }
231 for (i = 0; i < sizeof(basetab) / sizeof(basetab[0]); i++) 225 for (i = 0; i < sizeof(basetab) / sizeof(basetab[0]); i++)
232 basic[basetab[i]] = new TypeBasic(basetab[i]); 226 basic[basetab[i]] = new TypeBasic(basetab[i]);
233 basic[Terror] = basic[Tint32]; 227 basic[Terror] = basic[Tint32];
234 228
235 tvoidptr = tvoid->pointerTo(); 229 tvoidptr = tvoid->pointerTo();
236
237 // LDC
238 topaque = new TypeOpaque();
239 230
240 // set size_t / ptrdiff_t types and pointer size 231 // set size_t / ptrdiff_t types and pointer size
241 if (global.params.is64bit) 232 if (global.params.is64bit)
242 { 233 {
243 Tsize_t = Tuns64; 234 Tsize_t = Tuns64;
1623 //LDC: Build arguments. 1614 //LDC: Build arguments.
1624 static FuncDeclaration *adDup_fd = NULL; 1615 static FuncDeclaration *adDup_fd = NULL;
1625 if(!adDup_fd) { 1616 if(!adDup_fd) {
1626 Arguments* args = new Arguments; 1617 Arguments* args = new Arguments;
1627 args->push(new Argument(STCin, Type::typeinfo->type, NULL, NULL)); 1618 args->push(new Argument(STCin, Type::typeinfo->type, NULL, NULL));
1628 args->push(new Argument(STCin, Type::topaque->arrayOf(), NULL, NULL)); 1619 args->push(new Argument(STCin, Type::tvoid->arrayOf(), NULL, NULL));
1629 adDup_fd = FuncDeclaration::genCfunc(args, Type::topaque->arrayOf(), Id::adDup); 1620 adDup_fd = FuncDeclaration::genCfunc(args, Type::tvoid->arrayOf(), Id::adDup);
1630 } 1621 }
1631 static FuncDeclaration *adReverse_fd = NULL; 1622 static FuncDeclaration *adReverse_fd = NULL;
1632 if(!adReverse_fd) { 1623 if(!adReverse_fd) {
1633 Arguments* args = new Arguments; 1624 Arguments* args = new Arguments;
1634 args->push(new Argument(STCin, Type::topaque->arrayOf(), NULL, NULL)); 1625 args->push(new Argument(STCin, Type::tvoid->arrayOf(), NULL, NULL));
1635 args->push(new Argument(STCin, Type::tsize_t, NULL, NULL)); 1626 args->push(new Argument(STCin, Type::tsize_t, NULL, NULL));
1636 adReverse_fd = FuncDeclaration::genCfunc(args, Type::topaque->arrayOf(), Id::adReverse); 1627 adReverse_fd = FuncDeclaration::genCfunc(args, Type::tvoid->arrayOf(), Id::adReverse);
1637 } 1628 }
1638 1629
1639 if(dup) 1630 if(dup)
1640 ec = new VarExp(0, adDup_fd); 1631 ec = new VarExp(0, adDup_fd);
1641 else 1632 else
1642 ec = new VarExp(0, adReverse_fd); 1633 ec = new VarExp(0, adReverse_fd);
1643 e = e->castTo(sc, n->arrayOf()); // convert to dynamic array 1634 e = e->castTo(sc, n->arrayOf()); // convert to dynamic array
1644 arguments = new Expressions(); 1635 arguments = new Expressions();
1645 if (dup) 1636 if (dup)
1646 arguments->push(getTypeInfo(sc)); 1637 arguments->push(getTypeInfo(sc));
1647 arguments->push(e); 1638
1639 // LDC repaint array type to void[]
1640 if (n->ty != Tvoid) {
1641 e = new CastExp(e->loc, e, e->type);
1642 e->type = Type::tvoid->arrayOf();
1643 }
1644 arguments->push(e);
1645
1648 if (!dup) 1646 if (!dup)
1649 arguments->push(new IntegerExp(0, size, Type::tint32)); 1647 arguments->push(new IntegerExp(0, size, Type::tint32));
1650 e = new CallExp(e->loc, ec, arguments); 1648 e = new CallExp(e->loc, ec, arguments);
1651 e->type = next->arrayOf(); 1649 e->type = next->arrayOf();
1652 } 1650 }
1658 1656
1659 //LDC: Build arguments. 1657 //LDC: Build arguments.
1660 static FuncDeclaration *adSort_fd = NULL; 1658 static FuncDeclaration *adSort_fd = NULL;
1661 if(!adSort_fd) { 1659 if(!adSort_fd) {
1662 Arguments* args = new Arguments; 1660 Arguments* args = new Arguments;
1663 args->push(new Argument(STCin, Type::topaque->arrayOf(), NULL, NULL)); 1661 args->push(new Argument(STCin, Type::tvoid->arrayOf(), NULL, NULL));
1664 args->push(new Argument(STCin, Type::typeinfo->type, NULL, NULL)); 1662 args->push(new Argument(STCin, Type::typeinfo->type, NULL, NULL));
1665 adSort_fd = FuncDeclaration::genCfunc(args, Type::topaque->arrayOf(), "_adSort"); 1663 adSort_fd = FuncDeclaration::genCfunc(args, Type::tvoid->arrayOf(), "_adSort");
1666 } 1664 }
1667 static FuncDeclaration *adSortBit_fd = NULL; 1665 static FuncDeclaration *adSortBit_fd = NULL;
1668 if(!adSortBit_fd) { 1666 if(!adSortBit_fd) {
1669 Arguments* args = new Arguments; 1667 Arguments* args = new Arguments;
1670 args->push(new Argument(STCin, Type::topaque->arrayOf(), NULL, NULL)); 1668 args->push(new Argument(STCin, Type::tvoid->arrayOf(), NULL, NULL));
1671 args->push(new Argument(STCin, Type::typeinfo->type, NULL, NULL)); 1669 args->push(new Argument(STCin, Type::typeinfo->type, NULL, NULL));
1672 adSortBit_fd = FuncDeclaration::genCfunc(args, Type::topaque->arrayOf(), "_adSortBit"); 1670 adSortBit_fd = FuncDeclaration::genCfunc(args, Type::tvoid->arrayOf(), "_adSortBit");
1673 } 1671 }
1674 1672
1675 if(isBit) 1673 if(isBit)
1676 ec = new VarExp(0, adSortBit_fd); 1674 ec = new VarExp(0, adSortBit_fd);
1677 else 1675 else
1678 ec = new VarExp(0, adSort_fd); 1676 ec = new VarExp(0, adSort_fd);
1679 e = e->castTo(sc, n->arrayOf()); // convert to dynamic array 1677 e = e->castTo(sc, n->arrayOf()); // convert to dynamic array
1680 arguments = new Expressions(); 1678 arguments = new Expressions();
1681 arguments->push(e); 1679
1680 // LDC repaint array type to void[]
1681 if (n->ty != Tvoid) {
1682 e = new CastExp(e->loc, e, e->type);
1683 e->type = Type::tvoid->arrayOf();
1684 }
1685 arguments->push(e);
1686
1682 if (next->ty != Tbit) 1687 if (next->ty != Tbit)
1683 arguments->push(n->getTypeInfo(sc)); // LDC, we don't support the getInternalTypeInfo 1688 arguments->push(n->getTypeInfo(sc)); // LDC, we don't support the getInternalTypeInfo
1684 // optimization arbitrarily, not yet at least... 1689 // optimization arbitrarily, not yet at least...
1685 e = new CallExp(e->loc, ec, arguments); 1690 e = new CallExp(e->loc, ec, arguments);
1686 e->type = next->arrayOf(); 1691 e->type = next->arrayOf();
2348 2353
2349 //LDC: Build arguments. 2354 //LDC: Build arguments.
2350 static FuncDeclaration *aaLen_fd = NULL; 2355 static FuncDeclaration *aaLen_fd = NULL;
2351 if(!aaLen_fd) { 2356 if(!aaLen_fd) {
2352 Arguments* args = new Arguments; 2357 Arguments* args = new Arguments;
2353 args->push(new Argument(STCin, Type::topaque->pointerTo(), NULL, NULL)); 2358 args->push(new Argument(STCin, Type::tvoid->pointerTo(), NULL, NULL));
2354 aaLen_fd = FuncDeclaration::genCfunc(args, Type::tsize_t, Id::aaLen); 2359 aaLen_fd = FuncDeclaration::genCfunc(args, Type::tsize_t, Id::aaLen);
2355 } 2360 }
2356 2361
2357 ec = new VarExp(0, aaLen_fd); 2362 ec = new VarExp(0, aaLen_fd);
2358 arguments = new Expressions(); 2363 arguments = new Expressions();
2369 assert(size); 2374 assert(size);
2370 //LDC: Build arguments. 2375 //LDC: Build arguments.
2371 static FuncDeclaration *aaKeys_fd = NULL; 2376 static FuncDeclaration *aaKeys_fd = NULL;
2372 if(!aaKeys_fd) { 2377 if(!aaKeys_fd) {
2373 Arguments* args = new Arguments; 2378 Arguments* args = new Arguments;
2374 args->push(new Argument(STCin, Type::topaque->pointerTo(), NULL, NULL)); 2379 args->push(new Argument(STCin, Type::tvoid->pointerTo(), NULL, NULL));
2375 args->push(new Argument(STCin, Type::tsize_t, NULL, NULL)); 2380 args->push(new Argument(STCin, Type::tsize_t, NULL, NULL));
2376 aaKeys_fd = FuncDeclaration::genCfunc(args, Type::topaque->arrayOf(), Id::aaKeys); 2381 aaKeys_fd = FuncDeclaration::genCfunc(args, Type::tvoid->arrayOf(), Id::aaKeys);
2377 } 2382 }
2378 2383
2379 ec = new VarExp(0, aaKeys_fd); 2384 ec = new VarExp(0, aaKeys_fd);
2380 arguments = new Expressions(); 2385 arguments = new Expressions();
2381 arguments->push(e); 2386 arguments->push(e);
2390 2395
2391 //LDC: Build arguments. 2396 //LDC: Build arguments.
2392 static FuncDeclaration *aaValues_fd = NULL; 2397 static FuncDeclaration *aaValues_fd = NULL;
2393 if(!aaValues_fd) { 2398 if(!aaValues_fd) {
2394 Arguments* args = new Arguments; 2399 Arguments* args = new Arguments;
2395 args->push(new Argument(STCin, Type::topaque->pointerTo(), NULL, NULL)); 2400 args->push(new Argument(STCin, Type::tvoid->pointerTo(), NULL, NULL));
2396 args->push(new Argument(STCin, Type::tsize_t, NULL, NULL)); 2401 args->push(new Argument(STCin, Type::tsize_t, NULL, NULL));
2397 args->push(new Argument(STCin, Type::tsize_t, NULL, NULL)); 2402 args->push(new Argument(STCin, Type::tsize_t, NULL, NULL));
2398 aaValues_fd = FuncDeclaration::genCfunc(args, Type::topaque->arrayOf(), Id::aaValues); 2403 aaValues_fd = FuncDeclaration::genCfunc(args, Type::tvoid->arrayOf(), Id::aaValues);
2399 } 2404 }
2400 2405
2401 ec = new VarExp(0, aaValues_fd); 2406 ec = new VarExp(0, aaValues_fd);
2402 arguments = new Expressions(); 2407 arguments = new Expressions();
2403 arguments->push(e); 2408 arguments->push(e);
2415 2420
2416 //LDC: Build arguments. 2421 //LDC: Build arguments.
2417 static FuncDeclaration *aaRehash_fd = NULL; 2422 static FuncDeclaration *aaRehash_fd = NULL;
2418 if(!aaRehash_fd) { 2423 if(!aaRehash_fd) {
2419 Arguments* args = new Arguments; 2424 Arguments* args = new Arguments;
2420 args->push(new Argument(STCin, Type::topaque->pointerTo(), NULL, NULL)); 2425 args->push(new Argument(STCin, Type::tvoid->pointerTo(), NULL, NULL));
2421 args->push(new Argument(STCin, Type::typeinfo->type, NULL, NULL)); 2426 args->push(new Argument(STCin, Type::typeinfo->type, NULL, NULL));
2422 aaRehash_fd = FuncDeclaration::genCfunc(args, Type::tvoidptr, Id::aaRehash); 2427 aaRehash_fd = FuncDeclaration::genCfunc(args, Type::tvoidptr, Id::aaRehash);
2423 } 2428 }
2424 2429
2425 ec = new VarExp(0, aaRehash_fd); 2430 ec = new VarExp(0, aaRehash_fd);
5240 5245
5241 buf->printf("[%s .. ", lwr->toChars()); 5246 buf->printf("[%s .. ", lwr->toChars());
5242 buf->printf("%s]", upr->toChars()); 5247 buf->printf("%s]", upr->toChars());
5243 } 5248 }
5244 5249
5245 void TypeOpaque::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
5246 {
5247 //printf("TypeOpaquePtr::toCBuffer2()");
5248 if (mod != this->mod)
5249 { toCBuffer3(buf, hgs, mod);
5250 return;
5251 }
5252 buf->writestring("opaque");
5253 }
5254
5255 /***************************** Argument *****************************/ 5250 /***************************** Argument *****************************/
5256 5251
5257 Argument::Argument(unsigned storageClass, Type *type, Identifier *ident, Expression *defaultArg) 5252 Argument::Argument(unsigned storageClass, Type *type, Identifier *ident, Expression *defaultArg)
5258 { 5253 {
5259 this->type = type; 5254 this->type = type;