From 1310337d6e3b873ade545e0d83207164c2fe75b4 Mon Sep 17 00:00:00 2001 From: kai Date: Sat, 2 Nov 2013 19:56:47 +0100 Subject: [PATCH] Add more IN_LLVM sections and minimize more differences to DMD. --- dmd2/declaration.c | 11 +++++++--- dmd2/declaration.h | 2 +- dmd2/expression.h | 3 --- dmd2/mtype.c | 54 ++++++++++++++++++++++++++++++---------------- 4 files changed, 44 insertions(+), 26 deletions(-) diff --git a/dmd2/declaration.c b/dmd2/declaration.c index 0b7c6489..6c4bb067 100644 --- a/dmd2/declaration.c +++ b/dmd2/declaration.c @@ -735,7 +735,11 @@ void AliasDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { if (haliassym) { +#if IN_LLVM buf->writestring(haliassym->toChars()); +#else + haliassym->toCBuffer(buf, hgs); +#endif buf->writeByte(' '); buf->writestring(ident->toChars()); } @@ -747,10 +751,10 @@ void AliasDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { if (aliassym) { -#if !IN_LLVM - aliassym->toCBuffer(buf, hgs); -#else +#if IN_LLVM buf->writestring(aliassym->toChars()); +#else + aliassym->toCBuffer(buf, hgs); #endif buf->writeByte(' '); buf->writestring(ident->toChars()); @@ -2661,3 +2665,4 @@ Dsymbol *ThisDeclaration::syntaxCopy(Dsymbol *s) assert(0); // should never be produced by syntax return NULL; } + \ No newline at end of file diff --git a/dmd2/declaration.h b/dmd2/declaration.h index 53f6a44c..687b14db 100644 --- a/dmd2/declaration.h +++ b/dmd2/declaration.h @@ -105,7 +105,7 @@ enum PURE; const StorageClass STCStorageClass = (STCauto | STCscope | STCstatic | STCextern | STCconst | STCfinal | STCabstract | STCsynchronized | STCdeprecated | STCoverride | STClazy | STCalias | STCout | STCin | - STCmanifest | STCimmutable | STCshared | STCnothrow | STCpure | STCref | STCtls | + STCmanifest | STCimmutable | STCshared | STCwild | STCnothrow | STCpure | STCref | STCtls | STCgshared | STCproperty | STCsafe | STCtrusted | STCsystem | STCdisable); struct Match diff --git a/dmd2/expression.h b/dmd2/expression.h index 5bb7395d..07816a4f 100644 --- a/dmd2/expression.h +++ b/dmd2/expression.h @@ -47,9 +47,6 @@ struct InterState; #if IN_DMD struct Symbol; // back end symbol #endif -struct OverloadSet; -struct Initializer; -struct StringExp; class OverloadSet; class Initializer; class StringExp; diff --git a/dmd2/mtype.c b/dmd2/mtype.c index e3b535c4..a51f08be 100644 --- a/dmd2/mtype.c +++ b/dmd2/mtype.c @@ -3788,10 +3788,13 @@ Expression *TypeArray::dotExp(Scope *sc, Expression *e, Identifier *ident, int f e = e->castTo(sc, n->arrayOf()); // convert to dynamic array arguments = new Expressions(); arguments->push(e); +#if IN_LLVM // LDC, we don't support the getInternalTypeInfo // optimization arbitrarily, not yet at least... arguments->push(n->getTypeInfo(sc)); - e = new CallExp(e->loc, ec, arguments); +#else arguments->push(n->ty == Tsarray + ? n->getTypeInfo(sc) // don't convert to dynamic array + : n->getInternalTypeInfo(sc)); #endif e = new CallExp(e->loc, ec, arguments); e->type = next->arrayOf(); } else @@ -5426,10 +5429,10 @@ void TypeFunction::toDecoBuffer(OutBuffer *buf, int flag) case LINKwindows: mc = 'W'; break; case LINKpascal: mc = 'V'; break; case LINKcpp: mc = 'R'; break; - +#if IN_LLVM // LDC - case LINKintrinsic: mc = 'Q'; break; - + case LINKintrinsic: mc = 'Q'; break; +#endif default: assert(0); } @@ -5521,10 +5524,10 @@ void TypeFunction::toCBufferWithAttributes(OutBuffer *buf, Identifier *ident, Hd case LINKwindows: p = "Windows"; break; case LINKpascal: p = "Pascal"; break; case LINKcpp: p = "C++"; break; - - // LDC - case LINKintrinsic: p = "Intrinsic"; break; - +#if IN_LLVM + // LDC + case LINKintrinsic: p = "Intrinsic"; break; +#endif default: assert(0); } @@ -5578,10 +5581,10 @@ void functionToCBuffer2(TypeFunction *t, OutBuffer *buf, HdrGenState *hgs, int m case LINKwindows: p = "Windows"; break; case LINKpascal: p = "Pascal"; break; case LINKcpp: p = "C++"; break; - - // LDC - case LINKintrinsic: p = "Intrinsic"; break; - +#if IN_LLVM + // LDC + case LINKintrinsic: p = "Intrinsic"; break; +#endif default: assert(0); } @@ -6487,14 +6490,30 @@ Expression *TypeDelegate::dotExp(Scope *sc, Expression *e, Identifier *ident, in #endif if (ident == Id::ptr) { +#if IN_LLVM e = new GEPExp(e->loc, e, ident, 0); - e->type = tvoidptr; +#endif e->type = tvoidptr; return e; } else if (ident == Id::funcptr) { +#if IN_LLVM e = new GEPExp(e->loc, e, ident, 1); - e->type = next->pointerTo(); +#else if (!e->isLvalue()) + { + Identifier *idtmp = Lexer::uniqueId("__dgtmp"); + VarDeclaration *tmp = new VarDeclaration(e->loc, this, idtmp, new ExpInitializer(Loc(), e)); + tmp->storage_class |= STCctfe; + e = new DeclarationExp(e->loc, tmp); + e = new CommaExp(e->loc, e, new VarExp(e->loc, tmp)); + e = e->semantic(sc); + } + e = e->addressOf(sc); + e->type = tvoidptr; + e = new AddExp(e->loc, e, new IntegerExp(Target::ptrsize)); + e->type = tvoidptr; + e = new PtrExp(e->loc, e); + #endif e->type = next->pointerTo(); return e; } else @@ -9590,11 +9609,8 @@ void Parameter::argsToCBuffer(OutBuffer *buf, HdrGenState *hgs, Parameters *argu StorageClass stc = arg->storageClass; if (arg->type && arg->type->mod & MODshared) stc &= ~STCshared; - - StorageClassDeclaration::stcToCBuffer(buf, - stc & (STCconst | STCimmutable | STCshared | STCscope)); - - argbuf.reset(); + StorageClassDeclaration::stcToCBuffer(buf, + stc & (STCconst | STCimmutable | STCwild | STCshared | STCscope)); argbuf.reset(); if (arg->storageClass & STCalias) { if (arg->ident) argbuf.writestring(arg->ident->toChars());