mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-08 11:56:12 +03:00
Make DtoIndexAggregate
return a DLValue
(#4112)
This commit is contained in:
parent
78c37450d6
commit
7d8638c27a
4 changed files with 14 additions and 13 deletions
|
@ -1878,7 +1878,7 @@ FuncDeclaration *getParentFunc(Dsymbol *sym) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
LLValue *DtoIndexAggregate(LLValue *src, AggregateDeclaration *ad,
|
DLValue *DtoIndexAggregate(LLValue *src, AggregateDeclaration *ad,
|
||||||
VarDeclaration *vd) {
|
VarDeclaration *vd) {
|
||||||
IF_LOG Logger::println("Indexing aggregate field %s:", vd->toPrettyChars());
|
IF_LOG Logger::println("Indexing aggregate field %s:", vd->toPrettyChars());
|
||||||
LOG_SCOPE;
|
LOG_SCOPE;
|
||||||
|
@ -1924,7 +1924,7 @@ LLValue *DtoIndexAggregate(LLValue *src, AggregateDeclaration *ad,
|
||||||
val = DtoBitCast(val, DtoPtrToType(vd->type));
|
val = DtoBitCast(val, DtoPtrToType(vd->type));
|
||||||
|
|
||||||
IF_LOG Logger::cout() << "Value: " << *val << '\n';
|
IF_LOG Logger::cout() << "Value: " << *val << '\n';
|
||||||
return val;
|
return new DLValue(vd->type, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned getFieldGEPIndex(AggregateDeclaration *ad, VarDeclaration *vd) {
|
unsigned getFieldGEPIndex(AggregateDeclaration *ad, VarDeclaration *vd) {
|
||||||
|
|
|
@ -132,7 +132,7 @@ void findDefaultTarget();
|
||||||
/// Returns a pointer to the given member field of an aggregate.
|
/// Returns a pointer to the given member field of an aggregate.
|
||||||
///
|
///
|
||||||
/// 'src' is a pointer to the start of the memory of an 'ad' instance.
|
/// 'src' is a pointer to the start of the memory of an 'ad' instance.
|
||||||
LLValue *DtoIndexAggregate(LLValue *src, AggregateDeclaration *ad,
|
DLValue *DtoIndexAggregate(LLValue *src, AggregateDeclaration *ad,
|
||||||
VarDeclaration *vd);
|
VarDeclaration *vd);
|
||||||
|
|
||||||
/// Returns the index of a given member variable in the resulting LLVM type of
|
/// Returns the index of a given member variable in the resulting LLVM type of
|
||||||
|
|
|
@ -145,7 +145,7 @@ LLValue *DtoUnpaddedStruct(Type *dty, LLValue *v) {
|
||||||
LLValue *newval = llvm::UndefValue::get(DtoUnpaddedStructType(dty));
|
LLValue *newval = llvm::UndefValue::get(DtoUnpaddedStructType(dty));
|
||||||
|
|
||||||
for (unsigned i = 0; i < fields.length; i++) {
|
for (unsigned i = 0; i < fields.length; i++) {
|
||||||
LLValue *fieldptr = DtoIndexAggregate(v, sty->sym, fields[i]);
|
LLValue *fieldptr = DtoLVal(DtoIndexAggregate(v, sty->sym, fields[i]));
|
||||||
LLValue *fieldval;
|
LLValue *fieldval;
|
||||||
if (fields[i]->type->ty == TY::Tstruct) {
|
if (fields[i]->type->ty == TY::Tstruct) {
|
||||||
// Nested structs are the only members that can contain padding
|
// Nested structs are the only members that can contain padding
|
||||||
|
@ -165,7 +165,7 @@ void DtoPaddedStruct(Type *dty, LLValue *v, LLValue *lval) {
|
||||||
VarDeclarations &fields = sty->sym->fields;
|
VarDeclarations &fields = sty->sym->fields;
|
||||||
|
|
||||||
for (unsigned i = 0; i < fields.length; i++) {
|
for (unsigned i = 0; i < fields.length; i++) {
|
||||||
LLValue *fieldptr = DtoIndexAggregate(lval, sty->sym, fields[i]);
|
LLValue *fieldptr = DtoLVal(DtoIndexAggregate(lval, sty->sym, fields[i]));
|
||||||
LLValue *fieldval = DtoExtractValue(v, i);
|
LLValue *fieldval = DtoExtractValue(v, i);
|
||||||
if (fields[i]->type->ty == TY::Tstruct) {
|
if (fields[i]->type->ty == TY::Tstruct) {
|
||||||
// Nested structs are the only members that can contain padding
|
// Nested structs are the only members that can contain padding
|
||||||
|
|
17
gen/toir.cpp
17
gen/toir.cpp
|
@ -129,16 +129,16 @@ static void write_struct_literal(Loc loc, LLValue *mem, StructDeclaration *sd,
|
||||||
// get a pointer to this field
|
// get a pointer to this field
|
||||||
assert(!isSpecialRefVar(vd) && "Code not expected to handle special ref "
|
assert(!isSpecialRefVar(vd) && "Code not expected to handle special ref "
|
||||||
"vars, although it can easily be made to.");
|
"vars, although it can easily be made to.");
|
||||||
DLValue field(vd->type, DtoIndexAggregate(mem, sd, vd));
|
DLValue *field = DtoIndexAggregate(mem, sd, vd);
|
||||||
|
|
||||||
// initialize the field
|
// initialize the field
|
||||||
if (expr) {
|
if (expr) {
|
||||||
IF_LOG Logger::println("expr = %s", expr->toChars());
|
IF_LOG Logger::println("expr = %s", expr->toChars());
|
||||||
// try to construct it in-place
|
// try to construct it in-place
|
||||||
if (!toInPlaceConstruction(&field, expr)) {
|
if (!toInPlaceConstruction(field, expr)) {
|
||||||
DtoAssign(loc, &field, toElem(expr), EXP::blit);
|
DtoAssign(loc, field, toElem(expr), EXP::blit);
|
||||||
if (expr->isLvalue())
|
if (expr->isLvalue())
|
||||||
callPostblit(loc, expr, DtoLVal(&field));
|
callPostblit(loc, expr, DtoLVal(field));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
assert(vd == sd->vthis);
|
assert(vd == sd->vthis);
|
||||||
|
@ -146,7 +146,7 @@ static void write_struct_literal(Loc loc, LLValue *mem, StructDeclaration *sd,
|
||||||
LOG_SCOPE
|
LOG_SCOPE
|
||||||
DImValue val(vd->type,
|
DImValue val(vd->type,
|
||||||
DtoBitCast(DtoNestedContext(loc, sd), DtoType(vd->type)));
|
DtoBitCast(DtoNestedContext(loc, sd), DtoType(vd->type)));
|
||||||
DtoAssign(loc, &field, &val, EXP::blit);
|
DtoAssign(loc, field, &val, EXP::blit);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure to zero out padding bytes counted as being part of the type in
|
// Make sure to zero out padding bytes counted as being part of the type in
|
||||||
|
@ -917,7 +917,7 @@ public:
|
||||||
// Logger::cout() << *DtoType(e1type) << '\n';
|
// Logger::cout() << *DtoType(e1type) << '\n';
|
||||||
|
|
||||||
if (VarDeclaration *vd = e->var->isVarDeclaration()) {
|
if (VarDeclaration *vd = e->var->isVarDeclaration()) {
|
||||||
LLValue *arrptr;
|
DLValue *arrptr;
|
||||||
// indexing struct pointer
|
// indexing struct pointer
|
||||||
if (e1type->ty == TY::Tpointer) {
|
if (e1type->ty == TY::Tpointer) {
|
||||||
assert(e1type->nextOf()->ty == TY::Tstruct);
|
assert(e1type->nextOf()->ty == TY::Tstruct);
|
||||||
|
@ -937,8 +937,9 @@ public:
|
||||||
llvm_unreachable("Unknown DotVarExp type for VarDeclaration.");
|
llvm_unreachable("Unknown DotVarExp type for VarDeclaration.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Logger::cout() << "mem: " << *arrptr << '\n';
|
// Logger::cout() << "mem: " << *DtoLVal(arrptr) << '\n';
|
||||||
result = new DLValue(e->type, DtoBitCast(arrptr, DtoPtrToType(e->type)));
|
result = new DLValue(e->type, DtoBitCast(DtoLVal(arrptr),
|
||||||
|
DtoPtrToType(e->type)));
|
||||||
} else if (FuncDeclaration *fdecl = e->var->isFuncDeclaration()) {
|
} else if (FuncDeclaration *fdecl = e->var->isFuncDeclaration()) {
|
||||||
// This is a bit more convoluted than it would need to be, because it
|
// This is a bit more convoluted than it would need to be, because it
|
||||||
// has to take templated interface methods into account, for which
|
// has to take templated interface methods into account, for which
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue