diff --git a/gen/functions.cpp b/gen/functions.cpp index 8dc20e7f..e67c7e25 100644 --- a/gen/functions.cpp +++ b/gen/functions.cpp @@ -720,8 +720,6 @@ void DtoDeclareFunction(FuncDeclaration* fdecl) Type* t = fdecl->type->toBasetype(); TypeFunction* f = static_cast(t); - IrFuncTy &irFty = fdecl->irFty; - if (!fdecl->ir.irFunc) { fdecl->ir.irFunc = new IrFunction(fdecl); } @@ -811,9 +809,9 @@ void DtoDeclareFunction(FuncDeclaration* fdecl) AppendFunctionToLLVMGlobalCtorsDtors(func, fdecl->priority, fdecl->llvmInternal == LLVMglobal_crt_ctor); } - // we never reference parameters of function prototypes - std::string str; - // if (!declareOnly) + IrFuncTy &irFty = fdecl->irFty; + + // if (!declareOnly) { // name parameters llvm::Function::arg_iterator iarg = func->arg_begin(); @@ -835,12 +833,7 @@ void DtoDeclareFunction(FuncDeclaration* fdecl) // parameters below, because it can be referred to in nested // context types. Will be given storage in DtoDefineFunction. assert(!v->ir.irParam); - IrParameter* p = new IrParameter(v); - p->isVthis = true; - p->value = iarg; - p->arg = irFty.arg_this; - - v->ir.irParam = p; + v->ir.irParam = new IrParameter(v, iarg, irFty.arg_this, true); } ++iarg; @@ -861,8 +854,8 @@ void DtoDeclareFunction(FuncDeclaration* fdecl) ++iarg; } + // we never reference parameters of function prototypes unsigned int k = 0; - for (; iarg != func->arg_end(); ++iarg) { if (fdecl->parameters && fdecl->parameters->dim > k) @@ -873,13 +866,10 @@ void DtoDeclareFunction(FuncDeclaration* fdecl) VarDeclaration* argvd = argsym->isVarDeclaration(); assert(argvd); assert(!argvd->ir.irLocal); - argvd->ir.irParam = new IrParameter(argvd); - argvd->ir.irParam->value = iarg; - argvd->ir.irParam->arg = irFty.args[paramIndex]; - - str = argvd->ident->toChars(); + std::string str(argvd->ident->toChars()); str.append("_arg"); iarg->setName(str); + argvd->ir.irParam = new IrParameter(argvd, iarg, irFty.args[paramIndex]); k++; } diff --git a/gen/llvmhelpers.cpp b/gen/llvmhelpers.cpp index 0819f2ed..f3f7f9ba 100644 --- a/gen/llvmhelpers.cpp +++ b/gen/llvmhelpers.cpp @@ -1121,8 +1121,7 @@ void DtoVarDeclaration(VarDeclaration* vd) */ else if (gIR->func()->retArg && gIR->func()->decl->nrvo_can && gIR->func()->decl->nrvo_var == vd) { assert(!isSpecialRefVar(vd) && "Can this happen?"); - vd->ir.irLocal = new IrLocal(vd); - vd->ir.irLocal->value = gIR->func()->retArg; + vd->ir.irLocal = new IrLocal(vd, gIR->func()->retArg); } // normal stack variable, allocate storage on the stack if it has not already been done else { @@ -1339,8 +1338,7 @@ LLValue* DtoRawVarDeclaration(VarDeclaration* var, LLValue* addr) assert(!var->ir.isSet()); assert(addr); - var->ir.irLocal = new IrLocal(var); - var->ir.irLocal->value = addr; + var->ir.irLocal = new IrLocal(var, addr); } // return the alloca diff --git a/ir/iraggr.cpp b/ir/iraggr.cpp index 2f457b1d..9cb8017e 100644 --- a/ir/iraggr.cpp +++ b/ir/iraggr.cpp @@ -26,27 +26,21 @@ ////////////////////////////////////////////////////////////////////////////// IrAggr::IrAggr(AggregateDeclaration* aggr) -: init_type(LLStructType::create(gIR->context(), std::string(aggr->toPrettyChars()) + "_init")) -{ - aggrdecl = aggr; - - type = aggr->type; - - packed = (type->ty == Tstruct) - ? type->alignsize() == 1 - : false; - +: aggrdecl(aggr), + type(aggr->type), + packed((type->ty == Tstruct) ? type->alignsize() == 1 : false), // above still need to be looked at - - init = NULL; - constInit = NULL; - - vtbl = NULL; - constVtbl = NULL; - classInfo = NULL; - constClassInfo = NULL; - - classInterfacesArray = NULL; + init(0), + constInit(0), + init_type(LLStructType::create(gIR->context(), std::string(aggr->toPrettyChars()) + "_init")), + vtbl(0), + constVtbl(0), + classInfo(0), + constClassInfo(0), + interfaceVtblMap(), + classInterfacesArray(0), + interfacesWithVtbls() +{ } ////////////////////////////////////////////////////////////////////////////// diff --git a/ir/irvar.cpp b/ir/irvar.cpp index 5b8ec6b0..98caaeed 100644 --- a/ir/irvar.cpp +++ b/ir/irvar.cpp @@ -12,44 +12,6 @@ #include "gen/irstate.h" #include "ir/irvar.h" - -////////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////////// - -IrVar::IrVar(VarDeclaration* var) -{ - V = var; - value = NULL; -} - -////////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////////// - -IrGlobal::IrGlobal(VarDeclaration* v): IrVar(v) -{ - type = NULL; - constInit = NULL; -} - -////////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////////// - -IrLocal::IrLocal(VarDeclaration* v) : IrVar(v) -{ - nestedIndex = -1; -} - -////////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////////// - -IrParameter::IrParameter(VarDeclaration* v) : IrLocal(v), arg(0), isVthis(false) -{ -} - ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// @@ -69,14 +31,11 @@ IrField::IrField(VarDeclaration* v) : IrVar(v) index = 0; unionOffset = v->offset; } - constInit = NULL; } -extern LLConstant* get_default_initializer( - VarDeclaration* vd, - Initializer* init); +extern LLConstant* get_default_initializer(VarDeclaration* vd, Initializer* init); -llvm::Constant * IrField::getDefaultInit() +llvm::Constant* IrField::getDefaultInit() { if (constInit) return constInit; diff --git a/ir/irvar.h b/ir/irvar.h index d4b00663..cf90e323 100644 --- a/ir/irvar.h +++ b/ir/irvar.h @@ -26,7 +26,10 @@ struct VarDeclaration; struct IrVar { - IrVar(VarDeclaration* var); + IrVar(VarDeclaration* var) + : V(var), value(0) { } + IrVar(VarDeclaration* var, llvm::Value* value) + : V(var), value(value) { } VarDeclaration* V; llvm::Value* value; @@ -35,7 +38,10 @@ struct IrVar // represents a global variable struct IrGlobal : IrVar { - IrGlobal(VarDeclaration* v); + IrGlobal(VarDeclaration* v) + : IrVar(v), type(0), constInit(0) { } + IrGlobal(VarDeclaration* v, llvm::Type *type, llvm::Constant* constInit = 0) + : IrVar(v), type(type), constInit(constInit) { } llvm::Type *type; llvm::Constant* constInit; @@ -44,7 +50,12 @@ struct IrGlobal : IrVar // represents a local variable variable struct IrLocal : IrVar { - IrLocal(VarDeclaration* v); + IrLocal(VarDeclaration* v) + : IrVar(v), nestedDepth(0), nestedIndex(-1) { } + IrLocal(VarDeclaration* v, llvm::Value* value) + : IrVar(v, value), nestedDepth(0), nestedIndex(-1) { } + IrLocal(VarDeclaration* v, int nestedDepth, int nestedIndex) + : IrVar(v), nestedDepth(nestedDepth), nestedIndex(nestedIndex) { } // Used for hybrid nested context creation. int nestedDepth; @@ -54,7 +65,13 @@ struct IrLocal : IrVar // represents a function parameter struct IrParameter : IrLocal { - IrParameter(VarDeclaration* v); + IrParameter(VarDeclaration* v) + : IrLocal(v), arg(0), isVthis(false) { } + IrParameter(VarDeclaration* v, llvm::Value* value) + : IrLocal(v, value), arg(0), isVthis(false) { } + IrParameter(VarDeclaration* v, llvm::Value* value, IrFuncTyArg *arg, bool isVthis = false) + : IrLocal(v, value), arg(arg), isVthis(isVthis) { } + IrFuncTyArg *arg; bool isVthis; // true, if it is the 'this' parameter };