Pipe through source file locations of structure element declarations; these are now supplied to the llvm::DIBuilder::createMemberType() method rather than giving it the position of the overall struct declaration for each one. Fixes issue #31
This commit is contained in:
6
decl.cpp
6
decl.cpp
@@ -318,9 +318,10 @@ Declaration::Print() const {
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void
|
||||
GetStructTypesAndNames(const std::vector<StructDeclaration *> &sd,
|
||||
GetStructTypesNamesPositions(const std::vector<StructDeclaration *> &sd,
|
||||
std::vector<const Type *> *elementTypes,
|
||||
std::vector<std::string> *elementNames) {
|
||||
std::vector<std::string> *elementNames,
|
||||
std::vector<SourcePos> *elementPositions) {
|
||||
for (unsigned int i = 0; i < sd.size(); ++i) {
|
||||
const Type *type = sd[i]->type;
|
||||
// FIXME: making this fake little DeclSpecs here is really
|
||||
@@ -343,6 +344,7 @@ GetStructTypesAndNames(const std::vector<StructDeclaration *> &sd,
|
||||
|
||||
elementTypes->push_back(d->sym->type);
|
||||
elementNames->push_back(d->sym->name);
|
||||
elementPositions->push_back(d->sym->pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
5
decl.h
5
decl.h
@@ -196,8 +196,9 @@ struct StructDeclaration {
|
||||
|
||||
/** Given a set of StructDeclaration instances, this returns the types of
|
||||
the elements of the corresponding struct and their names. */
|
||||
extern void GetStructTypesAndNames(const std::vector<StructDeclaration *> &sd,
|
||||
extern void GetStructTypesNamesPositions(const std::vector<StructDeclaration *> &sd,
|
||||
std::vector<const Type *> *elementTypes,
|
||||
std::vector<std::string> *elementNames);
|
||||
std::vector<std::string> *elementNames,
|
||||
std::vector<SourcePos> *elementPositions);
|
||||
|
||||
#endif // ISPC_DECL_H
|
||||
|
||||
13
parse.yy
13
parse.yy
@@ -564,9 +564,11 @@ struct_or_union_specifier
|
||||
{
|
||||
std::vector<const Type *> elementTypes;
|
||||
std::vector<std::string> elementNames;
|
||||
GetStructTypesAndNames(*$4, &elementTypes, &elementNames);
|
||||
std::vector<SourcePos> elementPositions;
|
||||
GetStructTypesNamesPositions(*$4, &elementTypes, &elementNames,
|
||||
&elementPositions);
|
||||
StructType *st = new StructType($2, elementTypes, elementNames,
|
||||
false, true, @2);
|
||||
elementPositions, false, true, @2);
|
||||
m->symbolTable->AddType($2, st, @2);
|
||||
$$ = st;
|
||||
}
|
||||
@@ -574,8 +576,11 @@ struct_or_union_specifier
|
||||
{
|
||||
std::vector<const Type *> elementTypes;
|
||||
std::vector<std::string> elementNames;
|
||||
GetStructTypesAndNames(*$3, &elementTypes, &elementNames);
|
||||
$$ = new StructType("", elementTypes, elementNames, false, true, @1);
|
||||
std::vector<SourcePos> elementPositions;
|
||||
GetStructTypesNamesPositions(*$3, &elementTypes, &elementNames,
|
||||
&elementPositions);
|
||||
$$ = new StructType("", elementTypes, elementNames, elementPositions,
|
||||
false, true, @1);
|
||||
}
|
||||
| struct_or_union '{' '}'
|
||||
{
|
||||
|
||||
34
type.cpp
34
type.cpp
@@ -961,9 +961,10 @@ VectorType::getVectorMemoryCount() const {
|
||||
|
||||
StructType::StructType(const std::string &n, const std::vector<const Type *> &elts,
|
||||
const std::vector<std::string> &en,
|
||||
const std::vector<SourcePos> &ep,
|
||||
bool ic, bool iu, SourcePos p)
|
||||
: name(n), elementTypes(elts), elementNames(en), isUniform(iu), isConst(ic),
|
||||
pos(p) {
|
||||
: name(n), elementTypes(elts), elementNames(en), elementPositions(ep),
|
||||
isUniform(iu), isConst(ic), pos(p) {
|
||||
}
|
||||
|
||||
|
||||
@@ -1014,8 +1015,8 @@ StructType::GetAsVaryingType() const {
|
||||
if (IsVaryingType())
|
||||
return this;
|
||||
else
|
||||
return new StructType(name, elementTypes, elementNames, isConst,
|
||||
false, pos);
|
||||
return new StructType(name, elementTypes, elementNames, elementPositions,
|
||||
isConst, false, pos);
|
||||
}
|
||||
|
||||
|
||||
@@ -1024,8 +1025,8 @@ StructType::GetAsUniformType() const {
|
||||
if (IsUniformType())
|
||||
return this;
|
||||
else
|
||||
return new StructType(name, elementTypes, elementNames, isConst,
|
||||
true, pos);
|
||||
return new StructType(name, elementTypes, elementNames, elementPositions,
|
||||
isConst, true, pos);
|
||||
}
|
||||
|
||||
|
||||
@@ -1038,7 +1039,8 @@ StructType::GetSOAType(int width) const {
|
||||
const Type *t = GetMemberType(i);
|
||||
et.push_back(t->GetSOAType(width));
|
||||
}
|
||||
return new StructType(name, et, elementNames, isConst, isUniform, pos);
|
||||
return new StructType(name, et, elementNames, elementPositions,
|
||||
isConst, isUniform, pos);
|
||||
}
|
||||
|
||||
|
||||
@@ -1047,8 +1049,8 @@ StructType::GetAsConstType() const {
|
||||
if (IsConstType())
|
||||
return this;
|
||||
else
|
||||
return new StructType(name, elementTypes, elementNames, true,
|
||||
isUniform, pos);
|
||||
return new StructType(name, elementTypes, elementNames,
|
||||
elementPositions, true, isUniform, pos);
|
||||
}
|
||||
|
||||
|
||||
@@ -1057,8 +1059,8 @@ StructType::GetAsNonConstType() const {
|
||||
if (!IsConstType())
|
||||
return this;
|
||||
else
|
||||
return new StructType(name, elementTypes, elementNames, false,
|
||||
isUniform, pos);
|
||||
return new StructType(name, elementTypes, elementNames, elementPositions,
|
||||
false, isUniform, pos);
|
||||
}
|
||||
|
||||
|
||||
@@ -1138,7 +1140,6 @@ StructType::GetDIType(llvm::DIDescriptor scope) const {
|
||||
return llvm::DIType();
|
||||
#else
|
||||
uint64_t currentSize = 0, align = 0;
|
||||
llvm::DIFile diFile = pos.GetDIFile();
|
||||
|
||||
std::vector<llvm::Value *> elementLLVMTypes;
|
||||
// Walk through the elements of the struct; for each one figure out its
|
||||
@@ -1159,17 +1160,17 @@ StructType::GetDIType(llvm::DIDescriptor scope) const {
|
||||
currentSize += eltAlign - (currentSize % eltAlign);
|
||||
assert((currentSize == 0) || (currentSize % eltAlign) == 0);
|
||||
|
||||
// FIXME: we should pass this actual file/line number for the
|
||||
// member, not the position of the struct declaration
|
||||
llvm::DIFile diFile = elementPositions[i].GetDIFile();
|
||||
int line = elementPositions[i].first_line;
|
||||
#ifdef LLVM_2_9
|
||||
llvm::DIType fieldType =
|
||||
m->diBuilder->createMemberType(elementNames[i], diFile, pos.first_line,
|
||||
m->diBuilder->createMemberType(elementNames[i], diFile, line,
|
||||
eltSize, eltAlign, currentSize, 0,
|
||||
eltType);
|
||||
#else
|
||||
llvm::DIType fieldType =
|
||||
m->diBuilder->createMemberType(scope, elementNames[i], diFile,
|
||||
pos.first_line, eltSize, eltAlign,
|
||||
line, eltSize, eltAlign,
|
||||
currentSize, 0, eltType);
|
||||
#endif // LLVM_2_9
|
||||
elementLLVMTypes.push_back(fieldType);
|
||||
@@ -1188,6 +1189,7 @@ StructType::GetDIType(llvm::DIDescriptor scope) const {
|
||||
#else
|
||||
llvm::DIArray elements = m->diBuilder->getOrCreateArray(elementLLVMTypes);
|
||||
#endif
|
||||
llvm::DIFile diFile = pos.GetDIFile();
|
||||
return m->diBuilder->createStructType(scope, name, diFile, pos.first_line, currentSize,
|
||||
align, 0, elements);
|
||||
#endif // LLVM_2_8
|
||||
|
||||
6
type.h
6
type.h
@@ -442,7 +442,8 @@ private:
|
||||
class StructType : public Type {
|
||||
public:
|
||||
StructType(const std::string &name, const std::vector<const Type *> &elts,
|
||||
const std::vector<std::string> &eltNames, bool isConst,
|
||||
const std::vector<std::string> &eltNames,
|
||||
const std::vector<SourcePos> &eltPositions, bool isConst,
|
||||
bool isUniform, SourcePos pos);
|
||||
|
||||
bool IsUniformType() const;
|
||||
@@ -501,6 +502,9 @@ private:
|
||||
*/
|
||||
const std::vector<const Type *> elementTypes;
|
||||
const std::vector<std::string> elementNames;
|
||||
/** Source file position at which each structure element declaration
|
||||
appeared. */
|
||||
const std::vector<SourcePos> elementPositions;
|
||||
const bool isUniform;
|
||||
const bool isConst;
|
||||
const SourcePos pos;
|
||||
|
||||
Reference in New Issue
Block a user