-/// getDescString - Return a string used to compose global names and labels.
-///
-const char *GlobalVariableDesc::getDescString() const {
- return "llvm.dbg.global_variable";
-}
-
-/// getTypeString - Return a string used to label this descriptors type.
-///
-const char *GlobalVariableDesc::getTypeString() const {
- return "llvm.dbg.global_variable.type";
-}
-
-/// getAnchorString - Return a string used to label this descriptor's anchor.
-///
-const char *const GlobalVariableDesc::AnchorString = "llvm.dbg.global_variables";
-const char *GlobalVariableDesc::getAnchorString() const {
- return AnchorString;
-}
-
-#ifndef NDEBUG
-void GlobalVariableDesc::dump() {
- cerr << getDescString() << " "
- << "Version(" << getVersion() << "), "
- << "Tag(" << getTag() << "), "
- << "Anchor(" << getAnchor() << "), "
- << "Name(\"" << getName() << "\"), "
- << "FullName(\"" << getFullName() << "\"), "
- << "LinkageName(\"" << getLinkageName() << "\"), "
- << "File(" << getFile() << "),"
- << "Line(" << getLine() << "),"
- << "Type(" << getType() << "), "
- << "IsStatic(" << (isStatic() ? "true" : "false") << "), "
- << "IsDefinition(" << (isDefinition() ? "true" : "false") << "), "
- << "Global(" << Global << ")\n";
-}
-#endif
-
-//===----------------------------------------------------------------------===//
-
-SubprogramDesc::SubprogramDesc()
-: GlobalDesc(DW_TAG_subprogram)
-{}
-
-// Implement isa/cast/dyncast.
-bool SubprogramDesc::classof(const DebugInfoDesc *D) {
- return D->getTag() == DW_TAG_subprogram;
-}
-
-/// ApplyToFields - Target the visitor to the fields of the
-/// SubprogramDesc.
-void SubprogramDesc::ApplyToFields(DIVisitor *Visitor) {
- GlobalDesc::ApplyToFields(Visitor);
-}
-
-/// getDescString - Return a string used to compose global names and labels.
-///
-const char *SubprogramDesc::getDescString() const {
- return "llvm.dbg.subprogram";
-}
-
-/// getTypeString - Return a string used to label this descriptors type.
-///
-const char *SubprogramDesc::getTypeString() const {
- return "llvm.dbg.subprogram.type";
-}
-
-/// getAnchorString - Return a string used to label this descriptor's anchor.
-///
-const char *const SubprogramDesc::AnchorString = "llvm.dbg.subprograms";
-const char *SubprogramDesc::getAnchorString() const {
- return AnchorString;
-}
-
-#ifndef NDEBUG
-void SubprogramDesc::dump() {
- cerr << getDescString() << " "
- << "Version(" << getVersion() << "), "
- << "Tag(" << getTag() << "), "
- << "Anchor(" << getAnchor() << "), "
- << "Name(\"" << getName() << "\"), "
- << "FullName(\"" << getFullName() << "\"), "
- << "LinkageName(\"" << getLinkageName() << "\"), "
- << "File(" << getFile() << "),"
- << "Line(" << getLine() << "),"
- << "Type(" << getType() << "), "
- << "IsStatic(" << (isStatic() ? "true" : "false") << "), "
- << "IsDefinition(" << (isDefinition() ? "true" : "false") << ")\n";
-}
-#endif
-
-//===----------------------------------------------------------------------===//
-
-BlockDesc::BlockDesc()
-: DebugInfoDesc(DW_TAG_lexical_block)
-, Context(NULL)
-{}
-
-// Implement isa/cast/dyncast.
-bool BlockDesc::classof(const DebugInfoDesc *D) {
- return D->getTag() == DW_TAG_lexical_block;
-}
-
-/// ApplyToFields - Target the visitor to the fields of the BlockDesc.
-///
-void BlockDesc::ApplyToFields(DIVisitor *Visitor) {
- DebugInfoDesc::ApplyToFields(Visitor);
-
- Visitor->Apply(Context);
-}
-
-/// getDescString - Return a string used to compose global names and labels.
-///
-const char *BlockDesc::getDescString() const {
- return "llvm.dbg.block";
-}
-
-/// getTypeString - Return a string used to label this descriptors type.
-///
-const char *BlockDesc::getTypeString() const {
- return "llvm.dbg.block.type";
-}
-
-#ifndef NDEBUG
-void BlockDesc::dump() {
- cerr << getDescString() << " "
- << "Version(" << getVersion() << "), "
- << "Tag(" << getTag() << "),"
- << "Context(" << Context << ")\n";
-}
-#endif
-
-//===----------------------------------------------------------------------===//
-
-DebugInfoDesc *DIDeserializer::Deserialize(Value *V) {
- return Deserialize(getGlobalVariable(V));
-}
-DebugInfoDesc *DIDeserializer::Deserialize(GlobalVariable *GV) {
- // Handle NULL.
- if (!GV) return NULL;
-
- // Check to see if it has been already deserialized.
- DebugInfoDesc *&Slot = GlobalDescs[GV];
- if (Slot) return Slot;
-
- // Get the Tag from the global.
- unsigned Tag = DebugInfoDesc::TagFromGlobal(GV);
-
- // Create an empty instance of the correct sort.
- Slot = DebugInfoDesc::DescFactory(Tag);
-
- // If not a user defined descriptor.
- if (Slot) {
- // Deserialize the fields.
- DIDeserializeVisitor DRAM(*this, GV);
- DRAM.ApplyToFields(Slot);
- }
-
- return Slot;
-}
-
-//===----------------------------------------------------------------------===//
-
-/// getStrPtrType - Return a "sbyte *" type.
-///
-const PointerType *DISerializer::getStrPtrType() {
- // If not already defined.
- if (!StrPtrTy) {
- // Construct the pointer to signed bytes.
- StrPtrTy = PointerType::getUnqual(Type::Int8Ty);
- }
-
- return StrPtrTy;
-}
-
-/// getEmptyStructPtrType - Return a "{ }*" type.
-///
-const PointerType *DISerializer::getEmptyStructPtrType() {
- // If not already defined.
- if (EmptyStructPtrTy) return EmptyStructPtrTy;
-
- // Construct the pointer to empty structure type.
- const StructType *EmptyStructTy = StructType::get(NULL, NULL);
-
- // Construct the pointer to empty structure type.
- EmptyStructPtrTy = PointerType::getUnqual(EmptyStructTy);
- return EmptyStructPtrTy;
-}
-
-/// getTagType - Return the type describing the specified descriptor (via tag.)
-///
-const StructType *DISerializer::getTagType(DebugInfoDesc *DD) {
- // Attempt to get the previously defined type.
- StructType *&Ty = TagTypes[DD->getTag()];
-
- // If not already defined.
- if (!Ty) {
- // Set up fields vector.
- std::vector<const Type*> Fields;
- // Get types of fields.
- DIGetTypesVisitor GTAM(*this, Fields);
- GTAM.ApplyToFields(DD);
-
- // Construct structured type.
- Ty = StructType::get(Fields);
-
- // Register type name with module.
- M->addTypeName(DD->getTypeString(), Ty);
- }
-
- return Ty;
-}
-
-/// getString - Construct the string as constant string global.
-///
-Constant *DISerializer::getString(const std::string &String) {
- // Check string cache for previous edition.
- Constant *&Slot = StringCache[String];
-
- // Return Constant if previously defined.
- if (Slot) return Slot;
-
- // If empty string then use a sbyte* null instead.
- if (String.empty()) {
- Slot = ConstantPointerNull::get(getStrPtrType());
- } else {
- // Construct string as an llvm constant.
- Constant *ConstStr = ConstantArray::get(String);
-
- // Otherwise create and return a new string global.
- GlobalVariable *StrGV = new GlobalVariable(ConstStr->getType(), true,
- GlobalVariable::InternalLinkage,
- ConstStr, ".str", M);
- StrGV->setSection("llvm.metadata");
-
- // Convert to generic string pointer.
- Slot = ConstantExpr::getBitCast(StrGV, getStrPtrType());
- }
-
- return Slot;
-
-}
-
-/// Serialize - Recursively cast the specified descriptor into a GlobalVariable
-/// so that it can be serialized to a .bc or .ll file.
-GlobalVariable *DISerializer::Serialize(DebugInfoDesc *DD) {
- // Check if the DebugInfoDesc is already in the map.
- GlobalVariable *&Slot = DescGlobals[DD];
-
- // See if DebugInfoDesc exists, if so return prior GlobalVariable.
- if (Slot) return Slot;
-
- // Get the type associated with the Tag.
- const StructType *Ty = getTagType(DD);
-
- // Create the GlobalVariable early to prevent infinite recursion.
- GlobalVariable *GV = new GlobalVariable(Ty, true, DD->getLinkage(),
- NULL, DD->getDescString(), M);
- GV->setSection("llvm.metadata");
-
- // Insert new GlobalVariable in DescGlobals map.
- Slot = GV;
-
- // Set up elements vector
- std::vector<Constant*> Elements;
- // Add fields.
- DISerializeVisitor SRAM(*this, Elements);
- SRAM.ApplyToFields(DD);
-
- // Set the globals initializer.
- GV->setInitializer(ConstantStruct::get(Ty, Elements));
-
- return GV;
-}
-
-/// addDescriptor - Directly connect DD with existing GV.
-void DISerializer::addDescriptor(DebugInfoDesc *DD,
- GlobalVariable *GV) {
- DescGlobals[DD] = GV;