Mercurial > projects > ldc
diff gen/llvmhelpers.cpp @ 419:023fa78c1203
Fixed delegate casts.
author | Tomas Lindquist Olsen <tomas.l.olsen@gmail.com> |
---|---|
date | Mon, 28 Jul 2008 08:05:21 +0200 |
parents | 0e6b4d65d3f8 |
children | c8d98ccad0cc |
line wrap: on
line diff
--- a/gen/llvmhelpers.cpp Mon Jul 28 07:25:13 2008 +0200 +++ b/gen/llvmhelpers.cpp Mon Jul 28 08:05:21 2008 +0200 @@ -810,6 +810,25 @@ return new DImValue(to, rval); } +DValue* DtoCastDelegate(Loc& loc, DValue* val, Type* to) +{ + LLValue* res = 0; + to = to->toBasetype(); + + if (to->ty == Tdelegate) + { + const LLType* toll = getPtrToType(DtoType(to)); + res = DtoBitCast(val->getRVal(), toll); + } + else + { + error(loc, "invalid cast from '%s' to '%s'", val->getType()->toChars(), to->toChars()); + fatal(); + } + + return new DImValue(to, res); +} + DValue* DtoCast(Loc& loc, DValue* val, Type* to) { Type* fromtype = DtoDType(val->getType()); @@ -832,6 +851,9 @@ else if (fromtype->ty == Tpointer || fromtype->ty == Tfunction) { return DtoCastPtr(loc, val, to); } + else if (fromtype->ty == Tdelegate) { + return DtoCastDelegate(loc, val, to); + } else { error(loc, "invalid cast from '%s' to '%s'", val->getType()->toChars(), to->toChars()); fatal();