From cb58c78c1aebe00d2bbf412eec8d03cdd932b215 Mon Sep 17 00:00:00 2001 From: Matt Pharr Date: Wed, 29 Jun 2011 05:38:42 +0100 Subject: [PATCH] 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 --- decl.cpp | 8 +++++--- decl.h | 7 ++++--- parse.yy | 13 +++++++++---- type.cpp | 34 ++++++++++++++++++---------------- type.h | 6 +++++- 5 files changed, 41 insertions(+), 27 deletions(-) diff --git a/decl.cpp b/decl.cpp index 849347f4..fd14cfb6 100644 --- a/decl.cpp +++ b/decl.cpp @@ -318,9 +318,10 @@ Declaration::Print() const { /////////////////////////////////////////////////////////////////////////// void -GetStructTypesAndNames(const std::vector &sd, - std::vector *elementTypes, - std::vector *elementNames) { +GetStructTypesNamesPositions(const std::vector &sd, + std::vector *elementTypes, + std::vector *elementNames, + std::vector *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 &sd, elementTypes->push_back(d->sym->type); elementNames->push_back(d->sym->name); + elementPositions->push_back(d->sym->pos); } } } diff --git a/decl.h b/decl.h index 84f6147e..dca751ba 100644 --- a/decl.h +++ b/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 &sd, - std::vector *elementTypes, - std::vector *elementNames); +extern void GetStructTypesNamesPositions(const std::vector &sd, + std::vector *elementTypes, + std::vector *elementNames, + std::vector *elementPositions); #endif // ISPC_DECL_H diff --git a/parse.yy b/parse.yy index 333f2992..106ade17 100644 --- a/parse.yy +++ b/parse.yy @@ -564,9 +564,11 @@ struct_or_union_specifier { std::vector elementTypes; std::vector elementNames; - GetStructTypesAndNames(*$4, &elementTypes, &elementNames); + std::vector 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 elementTypes; std::vector elementNames; - GetStructTypesAndNames(*$3, &elementTypes, &elementNames); - $$ = new StructType("", elementTypes, elementNames, false, true, @1); + std::vector elementPositions; + GetStructTypesNamesPositions(*$3, &elementTypes, &elementNames, + &elementPositions); + $$ = new StructType("", elementTypes, elementNames, elementPositions, + false, true, @1); } | struct_or_union '{' '}' { diff --git a/type.cpp b/type.cpp index 0cbdba38..e7f9c7b5 100644 --- a/type.cpp +++ b/type.cpp @@ -961,9 +961,10 @@ VectorType::getVectorMemoryCount() const { StructType::StructType(const std::string &n, const std::vector &elts, const std::vector &en, + const std::vector &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 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 diff --git a/type.h b/type.h index 0fec0bfb..186c4ad6 100644 --- a/type.h +++ b/type.h @@ -442,7 +442,8 @@ private: class StructType : public Type { public: StructType(const std::string &name, const std::vector &elts, - const std::vector &eltNames, bool isConst, + const std::vector &eltNames, + const std::vector &eltPositions, bool isConst, bool isUniform, SourcePos pos); bool IsUniformType() const; @@ -501,6 +502,9 @@ private: */ const std::vector elementTypes; const std::vector elementNames; + /** Source file position at which each structure element declaration + appeared. */ + const std::vector elementPositions; const bool isUniform; const bool isConst; const SourcePos pos;