forked from OSchip/llvm-project
Add support to create vector, array, enums etc...
llvm-svn: 121224
This commit is contained in:
parent
21e71e948b
commit
89ea4f27a8
|
@ -35,6 +35,8 @@ namespace llvm {
|
|||
class DIGlobalVariable;
|
||||
class DINameSpace;
|
||||
class DIVariable;
|
||||
class DISubrange;
|
||||
class DILexicalBlock;
|
||||
|
||||
class DIBuilder {
|
||||
private:
|
||||
|
@ -141,11 +143,73 @@ namespace llvm {
|
|||
unsigned Flags, DIType Ty);
|
||||
|
||||
/// CreateStructType - Create debugging information entry for a struct.
|
||||
DIType CreateStructType(DIDescriptor Context, StringRef Name, DIFile F,
|
||||
/// @param Scope Scope in which this struct is defined.
|
||||
/// @param Name Struct name.
|
||||
/// @param File File where this member is defined.
|
||||
/// @param LineNo Line number.
|
||||
/// @param SizeInBits Member size.
|
||||
/// @param AlignInBits Member alignment.
|
||||
/// @param OffsetInBits Member offset.
|
||||
/// @param Flags Flags to encode member attribute, e.g. private
|
||||
/// @param Elements Struct elements.
|
||||
/// @param RunTimeLang Optional parameter, Objective-C runtime version.
|
||||
DIType CreateStructType(DIDescriptor Scope, StringRef Name, DIFile File,
|
||||
unsigned LineNumber, uint64_t SizeInBits,
|
||||
uint64_t AlignInBits, unsigned Flags,
|
||||
DIArray Elements, unsigned RunTimeLang = 0);
|
||||
|
||||
/// CreateUnionType - Create debugging information entry for an union.
|
||||
/// @param Scope Scope in which this union is defined.
|
||||
/// @param Name Union name.
|
||||
/// @param File File where this member is defined.
|
||||
/// @param LineNo Line number.
|
||||
/// @param SizeInBits Member size.
|
||||
/// @param AlignInBits Member alignment.
|
||||
/// @param OffsetInBits Member offset.
|
||||
/// @param Flags Flags to encode member attribute, e.g. private
|
||||
/// @param Elements Union elements.
|
||||
/// @param RunTimeLang Optional parameter, Objective-C runtime version.
|
||||
DIType CreateUnionType(DIDescriptor Scope, StringRef Name, DIFile File,
|
||||
unsigned LineNumber, uint64_t SizeInBits,
|
||||
uint64_t AlignInBits, unsigned Flags,
|
||||
DIArray Elements, unsigned RunTimeLang = 0);
|
||||
|
||||
/// CreateArrayType - Create debugging information entry for an array.
|
||||
/// @param Size Array size.
|
||||
/// @param AlignInBits Alignment.
|
||||
/// @param Ty Element type.
|
||||
/// @param Subscripts Subscripts.
|
||||
DIType CreateArrayType(uint64_t Size, uint64_t AlignInBits,
|
||||
DIType Ty, DIArray Subscripts);
|
||||
|
||||
/// CreateVectorType - Create debugging information entry for a vector type.
|
||||
/// @param Size Array size.
|
||||
/// @param AlignInBits Alignment.
|
||||
/// @param Ty Element type.
|
||||
/// @param Subscripts Subscripts.
|
||||
DIType CreateVectorType(uint64_t Size, uint64_t AlignInBits,
|
||||
DIType Ty, DIArray Subscripts);
|
||||
|
||||
/// CreateEnumerationType - Create debugging information entry for an
|
||||
/// enumeration.
|
||||
/// @param Scope Scope in which this enumeration is defined.
|
||||
/// @param Name Union name.
|
||||
/// @param File File where this member is defined.
|
||||
/// @param LineNo Line number.
|
||||
/// @param SizeInBits Member size.
|
||||
/// @param AlignInBits Member alignment.
|
||||
/// @param Elements Enumeration elements.
|
||||
DIType CreateEnumerationType(DIDescriptor Scope, StringRef Name,
|
||||
DIFile File, unsigned LineNumber,
|
||||
uint64_t SizeInBits,
|
||||
uint64_t AlignInBits, DIArray Elements);
|
||||
|
||||
/// CreateSubroutineType - Create subroutine type.
|
||||
/// @param File File in which this subroutine is defined.
|
||||
/// @param ParamterTypes An array of subroutine parameter types. This
|
||||
/// includes return type at 0th index.
|
||||
DIType CreateSubroutineType(DIFile File, DIArray ParameterTypes);
|
||||
|
||||
/// CreateArtificialType - Create a new DIType with "artificial" flag set.
|
||||
DIType CreateArtificialType(DIType Ty);
|
||||
|
||||
|
@ -153,9 +217,21 @@ namespace llvm {
|
|||
DIType CreateTemporaryType();
|
||||
DIType CreateTemporaryType(DIFile F);
|
||||
|
||||
/// RetainType - Retain DIType in a module even if it is not referenced
|
||||
/// through debug info anchors.
|
||||
void RetainType(DIType T);
|
||||
|
||||
/// CreateUnspecifiedParameter - Create unspeicified type descriptor
|
||||
/// for a subroutine type.
|
||||
DIDescriptor CreateUnspecifiedParameter();
|
||||
|
||||
/// GetOrCreateArray - Get a DIArray, create one if required.
|
||||
DIArray GetOrCreateArray(Value *const *Elements, unsigned NumElements);
|
||||
|
||||
/// GetOrCreateSubrange - Create a descriptor for a value range. This
|
||||
/// implicitly uniques the values returned.
|
||||
DISubrange GetOrCreateSubrange(int64_t Lo, int64_t Hi);
|
||||
|
||||
/// CreateGlobalVariable - Create a new descriptor for the specified global.
|
||||
/// @param Name Name of the variable.
|
||||
/// @param File File where this variable is defined.
|
||||
|
@ -232,6 +308,15 @@ namespace llvm {
|
|||
DIFile File, unsigned LineNo);
|
||||
|
||||
|
||||
/// CreateLexicalBlock - This creates a descriptor for a lexical block
|
||||
/// with the specified parent context.
|
||||
/// @param Scope Parent lexical scope.
|
||||
/// @param File Source file
|
||||
/// @param Line Line number
|
||||
/// @param Col Column number
|
||||
DILexicalBlock CreateLexicalBlock(DIDescriptor Scope, DIFile File,
|
||||
unsigned Line, unsigned Col);
|
||||
|
||||
/// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
|
||||
/// @param Storage llvm::Value of the variable
|
||||
/// @param VarInfo Variable's debug info descriptor.
|
||||
|
|
|
@ -237,19 +237,21 @@ DIType DIBuilder::CreateMemberType(StringRef Name,
|
|||
}
|
||||
|
||||
/// CreateStructType - Create debugging information entry for a struct.
|
||||
DIType DIBuilder::CreateStructType(DIDescriptor Context, StringRef Name, DIFile F,
|
||||
unsigned LineNumber, uint64_t SizeInBits,
|
||||
uint64_t AlignInBits, unsigned Flags,
|
||||
DIArray Elements, unsigned RunTimeLang) {
|
||||
DIType DIBuilder::CreateStructType(DIDescriptor Context, StringRef Name,
|
||||
DIFile File, unsigned LineNumber,
|
||||
uint64_t SizeInBits, uint64_t AlignInBits,
|
||||
unsigned Flags, DIArray Elements,
|
||||
unsigned RunTimeLang) {
|
||||
// TAG_structure_type is encoded in DICompositeType format.
|
||||
Value *Elts[] = {
|
||||
GetTagConstant(VMContext, dwarf::DW_TAG_structure_type),
|
||||
Context,
|
||||
MDString::get(VMContext, Name),
|
||||
F,
|
||||
File,
|
||||
ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
|
||||
ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
|
||||
ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
|
||||
ConstantInt::get(Type::getInt32Ty(VMContext), 0),
|
||||
ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
|
||||
llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)),
|
||||
Elements,
|
||||
|
@ -259,6 +261,123 @@ DIType DIBuilder::CreateStructType(DIDescriptor Context, StringRef Name, DIFile
|
|||
return DIType(MDNode::get(VMContext, &Elts[0], array_lengthof(Elts)));
|
||||
}
|
||||
|
||||
/// CreateUnionType - Create debugging information entry for an union.
|
||||
DIType DIBuilder::CreateUnionType(DIDescriptor Scope, StringRef Name,
|
||||
DIFile File,
|
||||
unsigned LineNumber, uint64_t SizeInBits,
|
||||
uint64_t AlignInBits, unsigned Flags,
|
||||
DIArray Elements, unsigned RunTimeLang) {
|
||||
// TAG_union_type is encoded in DICompositeType format.
|
||||
Value *Elts[] = {
|
||||
GetTagConstant(VMContext, dwarf::DW_TAG_union_type),
|
||||
Scope,
|
||||
MDString::get(VMContext, Name),
|
||||
File,
|
||||
ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
|
||||
ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
|
||||
ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
|
||||
ConstantInt::get(Type::getInt64Ty(VMContext), 0),
|
||||
ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
|
||||
llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)),
|
||||
Elements,
|
||||
ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeLang),
|
||||
llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)),
|
||||
};
|
||||
return DIType(MDNode::get(VMContext, &Elts[0], array_lengthof(Elts)));
|
||||
}
|
||||
|
||||
/// CreateSubroutineType - Create subroutine type.
|
||||
DIType DIBuilder::CreateSubroutineType(DIFile File, DIArray ParameterTypes) {
|
||||
// TAG_subroutine_type is encoded in DICompositeType format.
|
||||
Value *Elts[] = {
|
||||
GetTagConstant(VMContext, dwarf::DW_TAG_subroutine_type),
|
||||
File,
|
||||
MDString::get(VMContext, ""),
|
||||
File,
|
||||
ConstantInt::get(Type::getInt32Ty(VMContext), 0),
|
||||
ConstantInt::get(Type::getInt64Ty(VMContext), 0),
|
||||
ConstantInt::get(Type::getInt64Ty(VMContext), 0),
|
||||
ConstantInt::get(Type::getInt32Ty(VMContext), 0),
|
||||
ConstantInt::get(Type::getInt32Ty(VMContext), 0),
|
||||
llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)),
|
||||
ParameterTypes,
|
||||
ConstantInt::get(Type::getInt32Ty(VMContext), 0),
|
||||
llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)),
|
||||
};
|
||||
return DIType(MDNode::get(VMContext, &Elts[0], array_lengthof(Elts)));
|
||||
}
|
||||
|
||||
/// CreateEnumerationType - Create debugging information entry for an
|
||||
/// enumeration.
|
||||
DIType DIBuilder::CreateEnumerationType(DIDescriptor Scope, StringRef Name,
|
||||
DIFile File, unsigned LineNumber,
|
||||
uint64_t SizeInBits,
|
||||
uint64_t AlignInBits, DIArray Elements) {
|
||||
// TAG_enumeration_type is encoded in DICompositeType format.
|
||||
Value *Elts[] = {
|
||||
GetTagConstant(VMContext, dwarf::DW_TAG_enumeration_type),
|
||||
Scope,
|
||||
MDString::get(VMContext, Name),
|
||||
File,
|
||||
ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
|
||||
ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
|
||||
ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
|
||||
ConstantInt::get(Type::getInt32Ty(VMContext), 0),
|
||||
ConstantInt::get(Type::getInt32Ty(VMContext), 0),
|
||||
llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)),
|
||||
Elements,
|
||||
ConstantInt::get(Type::getInt32Ty(VMContext), 0),
|
||||
llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)),
|
||||
};
|
||||
MDNode *Node = MDNode::get(VMContext, &Elts[0], array_lengthof(Elts));
|
||||
NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.enum");
|
||||
NMD->addOperand(Node);
|
||||
return DIType(Node);
|
||||
}
|
||||
|
||||
/// CreateArrayType - Create debugging information entry for an array.
|
||||
DIType DIBuilder::CreateArrayType(uint64_t Size, uint64_t AlignInBits,
|
||||
DIType Ty, DIArray Subscripts) {
|
||||
// TAG_array_type is encoded in DICompositeType format.
|
||||
Value *Elts[] = {
|
||||
GetTagConstant(VMContext, dwarf::DW_TAG_array_type),
|
||||
TheCU,
|
||||
MDString::get(VMContext, ""),
|
||||
TheCU,
|
||||
ConstantInt::get(Type::getInt32Ty(VMContext), 0),
|
||||
ConstantInt::get(Type::getInt64Ty(VMContext), Size),
|
||||
ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
|
||||
ConstantInt::get(Type::getInt32Ty(VMContext), 0),
|
||||
ConstantInt::get(Type::getInt32Ty(VMContext), 0),
|
||||
Ty,
|
||||
Subscripts,
|
||||
ConstantInt::get(Type::getInt32Ty(VMContext), 0),
|
||||
llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)),
|
||||
};
|
||||
return DIType(MDNode::get(VMContext, &Elts[0], array_lengthof(Elts)));
|
||||
}
|
||||
|
||||
/// CreateVectorType - Create debugging information entry for a vector.
|
||||
DIType DIBuilder::CreateVectorType(uint64_t Size, uint64_t AlignInBits,
|
||||
DIType Ty, DIArray Subscripts) {
|
||||
// TAG_vector_type is encoded in DICompositeType format.
|
||||
Value *Elts[] = {
|
||||
GetTagConstant(VMContext, dwarf::DW_TAG_vector_type),
|
||||
TheCU,
|
||||
MDString::get(VMContext, ""),
|
||||
TheCU,
|
||||
ConstantInt::get(Type::getInt32Ty(VMContext), 0),
|
||||
ConstantInt::get(Type::getInt64Ty(VMContext), Size),
|
||||
ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
|
||||
ConstantInt::get(Type::getInt32Ty(VMContext), 0),
|
||||
ConstantInt::get(Type::getInt32Ty(VMContext), 0),
|
||||
Ty,
|
||||
Subscripts,
|
||||
ConstantInt::get(Type::getInt32Ty(VMContext), 0),
|
||||
llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)),
|
||||
};
|
||||
return DIType(MDNode::get(VMContext, &Elts[0], array_lengthof(Elts)));
|
||||
}
|
||||
|
||||
/// CreateArtificialType - Create a new DIType with "artificial" flag set.
|
||||
DIType DIBuilder::CreateArtificialType(DIType Ty) {
|
||||
|
@ -284,6 +403,22 @@ DIType DIBuilder::CreateArtificialType(DIType Ty) {
|
|||
return DIType(MDNode::get(VMContext, Elts.data(), Elts.size()));
|
||||
}
|
||||
|
||||
/// RetainType - Retain DIType in a module even if it is not referenced
|
||||
/// through debug info anchors.
|
||||
void DIBuilder::RetainType(DIType T) {
|
||||
NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.ty");
|
||||
NMD->addOperand(T);
|
||||
}
|
||||
|
||||
/// CreateUnspecifiedParameter - Create unspeicified type descriptor
|
||||
/// for the subroutine type.
|
||||
DIDescriptor DIBuilder::CreateUnspecifiedParameter() {
|
||||
Value *Elts[] = {
|
||||
GetTagConstant(VMContext, dwarf::DW_TAG_unspecified_parameters)
|
||||
};
|
||||
return DIDescriptor(MDNode::get(VMContext, &Elts[0], 1));
|
||||
}
|
||||
|
||||
/// CreateTemporaryType - Create a temporary forward-declared type.
|
||||
DIType DIBuilder::CreateTemporaryType() {
|
||||
// Give the temporary MDNode a tag. It doesn't matter what tag we
|
||||
|
@ -316,6 +451,18 @@ DIArray DIBuilder::GetOrCreateArray(Value *const *Elements, unsigned NumElements
|
|||
return DIArray(MDNode::get(VMContext, Elements, NumElements));
|
||||
}
|
||||
|
||||
/// GetOrCreateSubrange - Create a descriptor for a value range. This
|
||||
/// implicitly uniques the values returned.
|
||||
DISubrange DIBuilder::GetOrCreateSubrange(int64_t Lo, int64_t Hi) {
|
||||
Value *Elts[] = {
|
||||
GetTagConstant(VMContext, dwarf::DW_TAG_subrange_type),
|
||||
ConstantInt::get(Type::getInt64Ty(VMContext), Lo),
|
||||
ConstantInt::get(Type::getInt64Ty(VMContext), Hi)
|
||||
};
|
||||
|
||||
return DISubrange(MDNode::get(VMContext, &Elts[0], 3));
|
||||
}
|
||||
|
||||
/// CreateGlobalVariable - Create a new descriptor for the specified global.
|
||||
DIGlobalVariable DIBuilder::
|
||||
CreateGlobalVariable(StringRef Name, DIFile F, unsigned LineNumber,
|
||||
|
@ -419,7 +566,6 @@ DIVariable DIBuilder::CreateComplexVariable(unsigned Tag, DIDescriptor Scope,
|
|||
return DIVariable(MDNode::get(VMContext, Elts.data(), Elts.size()));
|
||||
}
|
||||
|
||||
|
||||
/// CreateNameSpace - This creates new descriptor for a namespace
|
||||
/// with the specified parent scope.
|
||||
DINameSpace DIBuilder::CreateNameSpace(DIDescriptor Scope, StringRef Name,
|
||||
|
@ -434,6 +580,21 @@ DINameSpace DIBuilder::CreateNameSpace(DIDescriptor Scope, StringRef Name,
|
|||
return DINameSpace(MDNode::get(VMContext, &Elts[0], array_lengthof(Elts)));
|
||||
}
|
||||
|
||||
DILexicalBlock DIBuilder::CreateLexicalBlock(DIDescriptor Scope, DIFile File,
|
||||
unsigned Line, unsigned Col) {
|
||||
// Defeat MDNode uniqing for lexical blocks by using unique id.
|
||||
static unsigned int unique_id = 0;
|
||||
Value *Elts[] = {
|
||||
GetTagConstant(VMContext, dwarf::DW_TAG_lexical_block),
|
||||
Scope,
|
||||
ConstantInt::get(Type::getInt32Ty(VMContext), Line),
|
||||
ConstantInt::get(Type::getInt32Ty(VMContext), Col),
|
||||
File,
|
||||
ConstantInt::get(Type::getInt32Ty(VMContext), unique_id++)
|
||||
};
|
||||
return DILexicalBlock(MDNode::get(VMContext, &Elts[0], array_lengthof(Elts)));
|
||||
}
|
||||
|
||||
/// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
|
||||
Instruction *DIBuilder::InsertDeclare(Value *Storage, DIVariable VarInfo,
|
||||
Instruction *InsertBefore) {
|
||||
|
|
|
@ -309,6 +309,8 @@ bool DIType::Verify() const {
|
|||
if (!isBasicType() && Tag != dwarf::DW_TAG_const_type &&
|
||||
Tag != dwarf::DW_TAG_volatile_type && Tag != dwarf::DW_TAG_pointer_type &&
|
||||
Tag != dwarf::DW_TAG_reference_type && Tag != dwarf::DW_TAG_restrict_type
|
||||
&& Tag != dwarf::DW_TAG_vector_type && Tag != dwarf::DW_TAG_array_type
|
||||
&& Tag != dwarf::DW_TAG_enumeration_type
|
||||
&& getFilename().empty())
|
||||
return false;
|
||||
return true;
|
||||
|
|
Loading…
Reference in New Issue