Small code modifications to Ir-Classes.

Adds some constructors and moves the code to the header file. Uses some of the new constructors.

A big problem with the source are the different strategies used for otherwise similar classes.
E.g. a IrField registers itself with the VarDeclaration. Same is required for IrParameter, but
in this case it is done by the caller.
This commit is contained in:
kai 2013-11-05 10:31:14 +01:00
parent 8d7f0bf0eb
commit 6fe28e1660
5 changed files with 46 additions and 88 deletions

View file

@ -720,8 +720,6 @@ void DtoDeclareFunction(FuncDeclaration* fdecl)
Type* t = fdecl->type->toBasetype();
TypeFunction* f = static_cast<TypeFunction*>(t);
IrFuncTy &irFty = fdecl->irFty;
if (!fdecl->ir.irFunc) {
fdecl->ir.irFunc = new IrFunction(fdecl);
}
@ -811,8 +809,8 @@ void DtoDeclareFunction(FuncDeclaration* fdecl)
AppendFunctionToLLVMGlobalCtorsDtors(func, fdecl->priority, fdecl->llvmInternal == LLVMglobal_crt_ctor);
}
// we never reference parameters of function prototypes
std::string str;
IrFuncTy &irFty = fdecl->irFty;
// if (!declareOnly)
{
// name parameters
@ -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++;
}

View file

@ -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

View file

@ -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()
{
}
//////////////////////////////////////////////////////////////////////////////

View file

@ -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;

View file

@ -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
};