mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-04 17:11:44 +03:00
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:
parent
8d7f0bf0eb
commit
6fe28e1660
5 changed files with 46 additions and 88 deletions
|
@ -720,8 +720,6 @@ void DtoDeclareFunction(FuncDeclaration* fdecl)
|
||||||
Type* t = fdecl->type->toBasetype();
|
Type* t = fdecl->type->toBasetype();
|
||||||
TypeFunction* f = static_cast<TypeFunction*>(t);
|
TypeFunction* f = static_cast<TypeFunction*>(t);
|
||||||
|
|
||||||
IrFuncTy &irFty = fdecl->irFty;
|
|
||||||
|
|
||||||
if (!fdecl->ir.irFunc) {
|
if (!fdecl->ir.irFunc) {
|
||||||
fdecl->ir.irFunc = new IrFunction(fdecl);
|
fdecl->ir.irFunc = new IrFunction(fdecl);
|
||||||
}
|
}
|
||||||
|
@ -811,9 +809,9 @@ void DtoDeclareFunction(FuncDeclaration* fdecl)
|
||||||
AppendFunctionToLLVMGlobalCtorsDtors(func, fdecl->priority, fdecl->llvmInternal == LLVMglobal_crt_ctor);
|
AppendFunctionToLLVMGlobalCtorsDtors(func, fdecl->priority, fdecl->llvmInternal == LLVMglobal_crt_ctor);
|
||||||
}
|
}
|
||||||
|
|
||||||
// we never reference parameters of function prototypes
|
IrFuncTy &irFty = fdecl->irFty;
|
||||||
std::string str;
|
|
||||||
// if (!declareOnly)
|
// if (!declareOnly)
|
||||||
{
|
{
|
||||||
// name parameters
|
// name parameters
|
||||||
llvm::Function::arg_iterator iarg = func->arg_begin();
|
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
|
// parameters below, because it can be referred to in nested
|
||||||
// context types. Will be given storage in DtoDefineFunction.
|
// context types. Will be given storage in DtoDefineFunction.
|
||||||
assert(!v->ir.irParam);
|
assert(!v->ir.irParam);
|
||||||
IrParameter* p = new IrParameter(v);
|
v->ir.irParam = new IrParameter(v, iarg, irFty.arg_this, true);
|
||||||
p->isVthis = true;
|
|
||||||
p->value = iarg;
|
|
||||||
p->arg = irFty.arg_this;
|
|
||||||
|
|
||||||
v->ir.irParam = p;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
++iarg;
|
++iarg;
|
||||||
|
@ -861,8 +854,8 @@ void DtoDeclareFunction(FuncDeclaration* fdecl)
|
||||||
++iarg;
|
++iarg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// we never reference parameters of function prototypes
|
||||||
unsigned int k = 0;
|
unsigned int k = 0;
|
||||||
|
|
||||||
for (; iarg != func->arg_end(); ++iarg)
|
for (; iarg != func->arg_end(); ++iarg)
|
||||||
{
|
{
|
||||||
if (fdecl->parameters && fdecl->parameters->dim > k)
|
if (fdecl->parameters && fdecl->parameters->dim > k)
|
||||||
|
@ -873,13 +866,10 @@ void DtoDeclareFunction(FuncDeclaration* fdecl)
|
||||||
VarDeclaration* argvd = argsym->isVarDeclaration();
|
VarDeclaration* argvd = argsym->isVarDeclaration();
|
||||||
assert(argvd);
|
assert(argvd);
|
||||||
assert(!argvd->ir.irLocal);
|
assert(!argvd->ir.irLocal);
|
||||||
argvd->ir.irParam = new IrParameter(argvd);
|
std::string str(argvd->ident->toChars());
|
||||||
argvd->ir.irParam->value = iarg;
|
|
||||||
argvd->ir.irParam->arg = irFty.args[paramIndex];
|
|
||||||
|
|
||||||
str = argvd->ident->toChars();
|
|
||||||
str.append("_arg");
|
str.append("_arg");
|
||||||
iarg->setName(str);
|
iarg->setName(str);
|
||||||
|
argvd->ir.irParam = new IrParameter(argvd, iarg, irFty.args[paramIndex]);
|
||||||
|
|
||||||
k++;
|
k++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1121,8 +1121,7 @@ void DtoVarDeclaration(VarDeclaration* vd)
|
||||||
*/
|
*/
|
||||||
else if (gIR->func()->retArg && gIR->func()->decl->nrvo_can && gIR->func()->decl->nrvo_var == vd) {
|
else if (gIR->func()->retArg && gIR->func()->decl->nrvo_can && gIR->func()->decl->nrvo_var == vd) {
|
||||||
assert(!isSpecialRefVar(vd) && "Can this happen?");
|
assert(!isSpecialRefVar(vd) && "Can this happen?");
|
||||||
vd->ir.irLocal = new IrLocal(vd);
|
vd->ir.irLocal = new IrLocal(vd, gIR->func()->retArg);
|
||||||
vd->ir.irLocal->value = gIR->func()->retArg;
|
|
||||||
}
|
}
|
||||||
// normal stack variable, allocate storage on the stack if it has not already been done
|
// normal stack variable, allocate storage on the stack if it has not already been done
|
||||||
else {
|
else {
|
||||||
|
@ -1339,8 +1338,7 @@ LLValue* DtoRawVarDeclaration(VarDeclaration* var, LLValue* addr)
|
||||||
|
|
||||||
assert(!var->ir.isSet());
|
assert(!var->ir.isSet());
|
||||||
assert(addr);
|
assert(addr);
|
||||||
var->ir.irLocal = new IrLocal(var);
|
var->ir.irLocal = new IrLocal(var, addr);
|
||||||
var->ir.irLocal->value = addr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// return the alloca
|
// return the alloca
|
||||||
|
|
|
@ -26,27 +26,21 @@
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
IrAggr::IrAggr(AggregateDeclaration* aggr)
|
IrAggr::IrAggr(AggregateDeclaration* aggr)
|
||||||
: init_type(LLStructType::create(gIR->context(), std::string(aggr->toPrettyChars()) + "_init"))
|
: aggrdecl(aggr),
|
||||||
{
|
type(aggr->type),
|
||||||
aggrdecl = aggr;
|
packed((type->ty == Tstruct) ? type->alignsize() == 1 : false),
|
||||||
|
|
||||||
type = aggr->type;
|
|
||||||
|
|
||||||
packed = (type->ty == Tstruct)
|
|
||||||
? type->alignsize() == 1
|
|
||||||
: false;
|
|
||||||
|
|
||||||
// above still need to be looked at
|
// above still need to be looked at
|
||||||
|
init(0),
|
||||||
init = NULL;
|
constInit(0),
|
||||||
constInit = NULL;
|
init_type(LLStructType::create(gIR->context(), std::string(aggr->toPrettyChars()) + "_init")),
|
||||||
|
vtbl(0),
|
||||||
vtbl = NULL;
|
constVtbl(0),
|
||||||
constVtbl = NULL;
|
classInfo(0),
|
||||||
classInfo = NULL;
|
constClassInfo(0),
|
||||||
constClassInfo = NULL;
|
interfaceVtblMap(),
|
||||||
|
classInterfacesArray(0),
|
||||||
classInterfacesArray = NULL;
|
interfacesWithVtbls()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
45
ir/irvar.cpp
45
ir/irvar.cpp
|
@ -12,44 +12,6 @@
|
||||||
#include "gen/irstate.h"
|
#include "gen/irstate.h"
|
||||||
#include "ir/irvar.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;
|
index = 0;
|
||||||
unionOffset = v->offset;
|
unionOffset = v->offset;
|
||||||
}
|
}
|
||||||
constInit = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern LLConstant* get_default_initializer(
|
extern LLConstant* get_default_initializer(VarDeclaration* vd, Initializer* init);
|
||||||
VarDeclaration* vd,
|
|
||||||
Initializer* init);
|
|
||||||
|
|
||||||
llvm::Constant * IrField::getDefaultInit()
|
llvm::Constant* IrField::getDefaultInit()
|
||||||
{
|
{
|
||||||
if (constInit)
|
if (constInit)
|
||||||
return constInit;
|
return constInit;
|
||||||
|
|
25
ir/irvar.h
25
ir/irvar.h
|
@ -26,7 +26,10 @@ struct VarDeclaration;
|
||||||
|
|
||||||
struct IrVar
|
struct IrVar
|
||||||
{
|
{
|
||||||
IrVar(VarDeclaration* var);
|
IrVar(VarDeclaration* var)
|
||||||
|
: V(var), value(0) { }
|
||||||
|
IrVar(VarDeclaration* var, llvm::Value* value)
|
||||||
|
: V(var), value(value) { }
|
||||||
|
|
||||||
VarDeclaration* V;
|
VarDeclaration* V;
|
||||||
llvm::Value* value;
|
llvm::Value* value;
|
||||||
|
@ -35,7 +38,10 @@ struct IrVar
|
||||||
// represents a global variable
|
// represents a global variable
|
||||||
struct IrGlobal : IrVar
|
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::Type *type;
|
||||||
llvm::Constant* constInit;
|
llvm::Constant* constInit;
|
||||||
|
@ -44,7 +50,12 @@ struct IrGlobal : IrVar
|
||||||
// represents a local variable variable
|
// represents a local variable variable
|
||||||
struct IrLocal : IrVar
|
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.
|
// Used for hybrid nested context creation.
|
||||||
int nestedDepth;
|
int nestedDepth;
|
||||||
|
@ -54,7 +65,13 @@ struct IrLocal : IrVar
|
||||||
// represents a function parameter
|
// represents a function parameter
|
||||||
struct IrParameter : IrLocal
|
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;
|
IrFuncTyArg *arg;
|
||||||
bool isVthis; // true, if it is the 'this' parameter
|
bool isVthis; // true, if it is the 'this' parameter
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue