Index: include/llvm/Support/DebugInfoBuilder.h
===================================================================
--- include/llvm/Support/DebugInfoBuilder.h	(revision 0)
+++ include/llvm/Support/DebugInfoBuilder.h	(revision 0)
@@ -0,0 +1,127 @@
+//===-- llvm/Support/DebugInfoBuilder.h - -----------------------*- C++ -*-===//
+// 
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+// 
+//===----------------------------------------------------------------------===//
+//
+// This file contains the declaration of the DebugInfoBuilder class, which is
+// a helper class used to construct source level debugging information.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_SUPPORT_DEBUGINFOBUILDER_H
+#define LLVM_SUPPORT_DEBUGINFOBUILDER_H
+
+#include <llvm/Module.h>
+#include <string>
+
+namespace llvm {
+    
+class Type;
+class IntegerType;
+class FloatType;
+class StructType;
+class PointerType;
+class Module;
+class GlobalVariable;
+class Constant;
+
+namespace sys {
+    class Path;
+}
+
+class DebugInfoBuilder {
+private:
+    Module * module;
+    PointerType * anyPtrType;    // Pointer to empty struct
+    StructType * anchorType;
+    GlobalVariable * compileUnit;
+    GlobalVariable * context;
+    GlobalVariable * compileUnitAnchor;
+    GlobalVariable * globalVariableAnchor;
+    GlobalVariable * subprogramAnchor;
+    GlobalVariable * compileUnitDescriptor;
+
+    // Create an anchor with the specified tag.
+    GlobalVariable * CreateAnchor(unsigned anchorTag, const char * anchorName);
+
+    // Calculate alignement for primitive types.
+    unsigned GetBasicAlignment(unsigned sizeInBits);
+
+    // Calculate the size of the specified LLVM type.
+    Constant * Sizeof(const Type * type);
+
+    // Calculate the alignment of the specified LLVM type.
+    Constant * Alignof(const Type * type);
+
+public:
+    // Constructor
+    DebugInfoBuilder();
+
+    // Return the type defined by llvm.dbg.anchor.type
+    StructType * GetAnchorType() const { return anchorType; }
+    
+    // Set the reference to the module where we will insert debugging information.
+    // Also defines the debug info types for the module and creates the initial anchors.
+    // Also changes the current context to the global context for that module.
+    void SetModule(Module * m);
+    
+    // Emit a compile unit descriptor. This should be done once for each module before
+    // any other debug descriptors are created. This also changes the current context
+    // to the global context for the compile unit.
+    GlobalVariable * CreateCompileUnitDescriptor(
+        unsigned langId,
+        const sys::Path & srcPath,
+        const std::string & producer);
+
+    // Set a new context, returning the previous context. The context is the debug descriptor
+    // representing the current scope (module, function, class, etc.)
+    GlobalVariable * SetContext(GlobalVariable * ctx) {
+        GlobalVariable * prev = context;
+        context = ctx;
+        return prev;
+    }
+    
+    // Emit a subprogram descriptor in the current context.
+    GlobalVariable * CreateSubProgramDescriptor(
+        const std::string & name,           // Name of the subprogram
+        const std::string & qualifiedName,  // Fully-qualified name
+        unsigned line,                      // Line number
+        GlobalVariable * typeDesc,          // Type descriptor
+        bool isInternalScoped,              // True if this has static scope (internal to module)
+        bool isDefined);                    // True if this is not externally-defined.
+
+    // Create a type descriptor for a primitive type.
+    GlobalVariable * CreateBasicTypeDescriptor(
+        std::string & name,
+        unsigned line,
+        unsigned sizeInBits,
+        unsigned alignmentInBits,
+        unsigned offsetInBits,
+        unsigned typeEncoding);
+
+    // Create a type descriptor for an integer type
+    GlobalVariable * CreateIntegerTypeDescriptor(
+        std::string & name, const IntegerType * type, bool isSigned);
+
+    // Create a type descriptor for an character type
+    GlobalVariable * CreateCharacterTypeDescriptor(
+        std::string & name, const IntegerType * type, bool isSigned);
+
+    // Create a type descriptor for an floating-point type
+    GlobalVariable * CreateFloatTypeDescriptor(std::string & name, const Type * type);
+
+    // Create a type descriptor for a pointer type.
+    GlobalVariable * CreatePointerTypeDescriptor(
+        std::string & name,                 // Name of the type
+        GlobalVariable * referenceType,     // Descriptor for what is pointed to
+        const PointerType * type,           // LLVM type of the pointer
+        unsigned line);                     // Line number of definition (0 if none)
+};
+
+}
+
+#endif
Index: lib/VMCore/DebugInfoBuilder.cpp
===================================================================
--- lib/VMCore/DebugInfoBuilder.cpp	(revision 0)
+++ lib/VMCore/DebugInfoBuilder.cpp	(revision 0)
@@ -0,0 +1,280 @@
+//===-- llvm/VMCore/DebugInfoBuilder.cpp - ----------------------*- C++ -*-===//
+// 
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+// 
+//===----------------------------------------------------------------------===//
+//
+// This file contains the definition of the DebugInfoBuilder class, which is
+// a helper class used to construct source level debugging information.
+//
+//===----------------------------------------------------------------------===//
+
+#include <llvm/Support/DebugInfoBuilder.h>
+#include <llvm/DerivedTypes.h>
+#include <llvm/Constants.h>
+#include <llvm/GlobalVariable.h>
+#include <llvm/Module.h>
+#include <llvm/Support/Dwarf.h>
+#include <llvm/System/Path.h>
+
+namespace llvm {
+    
+//===----------------------------------------------------------------------===//
+// Debug version -- copied from MachineModuleInfo (for now)
+// Need to move this to a better place...
+enum {
+  LLVMDebugVersion = (6 << 16),         // Current version of debug information.
+  LLVMDebugVersion5 = (5 << 16),        // Constant for version 5.
+  LLVMDebugVersion4 = (4 << 16),        // Constant for version 4.
+  LLVMDebugVersionMask = 0xffff0000     // Mask for version number.
+};
+
+const char ANCHOR_TYPE_NAME[] = "llvm.dbg.anchor.type";
+const char COMPILE_UNIT_ANCHOR_NAME[] = "llvm.dbg.compile_units";
+const char GLOBAL_VAR_ANCHOR_NAME[] = "llvm.dbg.global_variables";
+const char SUBPROGRAM_ANCHOR_NAME[] = "llvm.dbg.subprograms";
+const char COMPILE_UNIT_TYPE_NAME[] = "llvm.dbg.compile_unit.type";
+const char COMPILE_UNIT_NAME[] = "llvm.dbg.compile_unit";
+const char SUBPROGRAM_NAME[] = "llvm.dbg.subprogram";
+const char BASICTYPE_NAME[] = "llvm.dbg.basictype";
+const char DERIVEDTYPE_NAME[] = "llvm.dbg.derivedtype";
+
+DebugInfoBuilder::DebugInfoBuilder() {
+    anyPtrType = PointerType::getUnqual(StructType::get(NULL, NULL));
+    anchorType = StructType::get(Type::Int32Ty, Type::Int32Ty, NULL);
+}
+
+GlobalVariable * DebugInfoBuilder::CreateAnchor(unsigned anchorTag, const char * anchorName) {
+    std::vector<Constant *> values;
+    values.push_back(ConstantInt::get(Type::Int32Ty, LLVMDebugVersion));
+    values.push_back(ConstantInt::get(Type::Int32Ty, anchorTag));
+    
+    return new GlobalVariable(anchorType, true, GlobalValue::LinkOnceLinkage,
+        ConstantStruct::get(anchorType, values), anchorName, module);
+}
+
+// Calculate the size of the specified LLVM type.
+Constant * DebugInfoBuilder::Sizeof(const Type * type) {
+    Constant * one = ConstantInt::get(Type::Int32Ty, 1);
+    return ConstantExpr::getPtrToInt(
+        ConstantExpr::getGetElementPtr(
+            ConstantPointerNull::get(PointerType::getUnqual(type)),
+            &one, 1), Type::Int32Ty);
+}
+    
+Constant * DebugInfoBuilder::Alignof(const Type * type) {
+    // Calculates the alignment of T using "sizeof({i8, T}) - sizeof(T)"
+    return ConstantExpr::getSub(
+        Sizeof(StructType::get(Type::Int8Ty, type, NULL)),
+        Sizeof(type));
+}
+    
+void DebugInfoBuilder::SetModule(Module * m) {
+    module = m;
+    module->addTypeName(ANCHOR_TYPE_NAME, anchorType);
+    
+    compileUnitAnchor = module->getGlobalVariable(COMPILE_UNIT_ANCHOR_NAME);
+    if (compileUnitAnchor == NULL) {
+        compileUnitAnchor = CreateAnchor(dwarf::DW_TAG_compile_unit, COMPILE_UNIT_ANCHOR_NAME);
+    }
+
+    globalVariableAnchor = module->getGlobalVariable(GLOBAL_VAR_ANCHOR_NAME);
+    if (globalVariableAnchor == NULL) {
+        globalVariableAnchor = CreateAnchor(dwarf::DW_TAG_compile_unit, GLOBAL_VAR_ANCHOR_NAME);
+    }
+
+    subprogramAnchor = module->getGlobalVariable(SUBPROGRAM_ANCHOR_NAME);
+    if (subprogramAnchor == NULL) {
+        subprogramAnchor = CreateAnchor(dwarf::DW_TAG_compile_unit, SUBPROGRAM_ANCHOR_NAME);
+    }
+    
+    compileUnit = module->getGlobalVariable(COMPILE_UNIT_NAME);
+    SetContext(compileUnit);
+}
+    
+GlobalVariable * DebugInfoBuilder::CreateCompileUnitDescriptor(unsigned langId,
+    const sys::Path & srcPath, const std::string & producer) {
+
+    if (compileUnit == NULL) {
+        std::vector<Constant *> values;
+        values.push_back(ConstantInt::get(Type::Int32Ty, LLVMDebugVersion + dwarf::DW_TAG_compile_unit));
+        values.push_back(ConstantExpr::getBitCast(compileUnitAnchor, anyPtrType));
+        values.push_back(ConstantInt::get(Type::Int32Ty, langId));
+        values.push_back(ConstantArray::get(srcPath.getLast()));
+        values.push_back(ConstantArray::get(srcPath.getDirname() + "/"));
+        values.push_back(ConstantArray::get(producer));
+    
+        Constant * structVal = ConstantStruct::get(values, false);
+        compileUnit = new GlobalVariable(structVal->getType(), true,
+            GlobalValue::InternalLinkage, structVal, COMPILE_UNIT_NAME, module);
+    }
+
+    SetContext(compileUnit);
+    return compileUnit;
+}
+
+GlobalVariable * DebugInfoBuilder::CreateSubProgramDescriptor(
+    const std::string & name,
+    const std::string & qualifiedName,
+    unsigned line,
+    GlobalVariable * typeDesc,
+    bool isInternal,
+    bool isDefined) {
+        
+    assert(compileUnit != NULL);
+    assert(subprogramAnchor != NULL);
+        
+    std::vector<Constant *> values;
+    values.push_back(ConstantInt::get(Type::Int32Ty, LLVMDebugVersion + dwarf::DW_TAG_subprogram));
+    values.push_back(ConstantExpr::getBitCast(subprogramAnchor, anyPtrType));
+    values.push_back(ConstantExpr::getBitCast(context, anyPtrType));
+    values.push_back(ConstantArray::get(name));
+    values.push_back(ConstantArray::get(qualifiedName));
+    values.push_back(ConstantArray::get(qualifiedName));
+    values.push_back(ConstantExpr::getBitCast(compileUnit, anyPtrType));
+    values.push_back(ConstantInt::get(Type::Int32Ty, line));
+    values.push_back(typeDesc ?
+        ConstantExpr::getBitCast(typeDesc, anyPtrType) :
+        ConstantPointerNull::get(anyPtrType));
+    values.push_back(ConstantInt::get(Type::Int1Ty, isInternal));
+    values.push_back(ConstantInt::get(Type::Int1Ty, isDefined));
+    
+    Constant * structVal = ConstantStruct::get(values, false);
+    return new GlobalVariable(structVal->getType(), true,
+        GlobalValue::InternalLinkage, structVal, SUBPROGRAM_NAME, module);
+}
+
+GlobalVariable * DebugInfoBuilder::CreateBasicTypeDescriptor(
+    std::string & name,
+    unsigned line,
+    unsigned sizeInBits,
+    unsigned alignmentInBits,
+    unsigned offsetInBits,
+    unsigned typeEncoding) {
+
+    std::vector<Constant *> values;
+    values.push_back(ConstantInt::get(Type::Int32Ty, LLVMDebugVersion + dwarf::DW_TAG_base_type));
+    values.push_back(ConstantExpr::getBitCast(context, anyPtrType));
+    values.push_back(ConstantArray::get(name));
+    values.push_back(ConstantExpr::getBitCast(compileUnit, anyPtrType));
+    values.push_back(ConstantInt::get(Type::Int32Ty, line));
+    values.push_back(ConstantInt::get(Type::Int32Ty, sizeInBits));
+    values.push_back(ConstantInt::get(Type::Int32Ty, alignmentInBits));
+    values.push_back(ConstantInt::get(Type::Int32Ty, offsetInBits));
+    values.push_back(ConstantInt::get(Type::Int32Ty, typeEncoding));
+
+    Constant * structVal = ConstantStruct::get(values, false);
+    return new GlobalVariable(structVal->getType(), true,
+        GlobalValue::InternalLinkage, structVal, BASICTYPE_NAME, module);
+}
+
+GlobalVariable * DebugInfoBuilder::CreateIntegerTypeDescriptor(
+    std::string & name, const IntegerType * type, bool isSigned) {
+
+    std::vector<Constant *> values;
+    values.push_back(ConstantInt::get(Type::Int32Ty, LLVMDebugVersion + dwarf::DW_TAG_base_type));
+    values.push_back(ConstantPointerNull::get(anyPtrType));
+    values.push_back(ConstantArray::get(name));
+    values.push_back(ConstantPointerNull::get(anyPtrType));
+    values.push_back(ConstantInt::get(Type::Int32Ty, 0));
+    values.push_back(ConstantInt::get(Type::Int32Ty, type->getBitWidth()));
+    values.push_back(Alignof(type));
+    values.push_back(ConstantInt::get(Type::Int32Ty, 0));
+    values.push_back(ConstantInt::get(Type::Int32Ty,
+        isSigned ? dwarf::DW_ATE_signed_char : dwarf::DW_ATE_unsigned_char));
+
+    Constant * structVal = ConstantStruct::get(values, false);
+    return new GlobalVariable(structVal->getType(), true,
+        GlobalValue::InternalLinkage, structVal, BASICTYPE_NAME, module);
+}
+
+GlobalVariable * DebugInfoBuilder::CreateCharacterTypeDescriptor(
+    std::string & name, const IntegerType * type, bool isSigned) {
+
+    std::vector<Constant *> values;
+    values.push_back(ConstantInt::get(Type::Int32Ty, LLVMDebugVersion + dwarf::DW_TAG_base_type));
+    values.push_back(ConstantPointerNull::get(anyPtrType));
+    values.push_back(ConstantArray::get(name));
+    values.push_back(ConstantPointerNull::get(anyPtrType));
+    values.push_back(ConstantInt::get(Type::Int32Ty, 0));
+    values.push_back(ConstantInt::get(Type::Int32Ty, type->getBitWidth()));
+    values.push_back(Alignof(type));
+    values.push_back(ConstantInt::get(Type::Int32Ty, 0/*offsetInBits*/));
+    values.push_back(ConstantInt::get(Type::Int32Ty,
+        isSigned ? dwarf::DW_ATE_signed_char : dwarf::DW_ATE_unsigned_char));
+
+    Constant * structVal = ConstantStruct::get(values, false);
+    return new GlobalVariable(structVal->getType(), true,
+        GlobalValue::InternalLinkage, structVal, BASICTYPE_NAME, module);
+}
+
+GlobalVariable * DebugInfoBuilder::CreateFloatTypeDescriptor(
+    std::string & name, const Type * type) {
+
+    std::vector<Constant *> values;
+    values.push_back(ConstantInt::get(Type::Int32Ty, LLVMDebugVersion + dwarf::DW_TAG_base_type));
+    values.push_back(ConstantPointerNull::get(anyPtrType));
+    values.push_back(ConstantArray::get(name));
+    values.push_back(ConstantPointerNull::get(anyPtrType));
+    values.push_back(ConstantInt::get(Type::Int32Ty, 0));
+    values.push_back(Sizeof(type));
+    values.push_back(Alignof(type));
+    values.push_back(ConstantInt::get(Type::Int32Ty, 0/*offsetInBits*/));
+    values.push_back(ConstantInt::get(Type::Int32Ty, dwarf::DW_ATE_float));
+
+    Constant * structVal = ConstantStruct::get(values, false);
+    return new GlobalVariable(structVal->getType(), true,
+        GlobalValue::InternalLinkage, structVal, BASICTYPE_NAME, module);
+}
+
+GlobalVariable * DebugInfoBuilder::CreatePointerTypeDescriptor(
+    std::string & name,
+    GlobalVariable * referenceType,
+    const PointerType * type,
+    unsigned line) {
+
+    std::vector<Constant *> values;
+    values.push_back(ConstantInt::get(Type::Int32Ty, dwarf::DW_TAG_pointer_type + LLVMDebugVersion));
+    values.push_back(context ? ConstantExpr::getBitCast(context, anyPtrType) : NULL);
+    values.push_back(ConstantArray::get(name));
+    values.push_back(compileUnit ? ConstantExpr::getBitCast(compileUnit, anyPtrType) : NULL);
+    values.push_back(ConstantInt::get(Type::Int32Ty, line));
+    values.push_back(Sizeof(type));
+    values.push_back(Alignof(type));
+    values.push_back(ConstantInt::get(Type::Int32Ty, 0));
+    values.push_back(referenceType);
+
+    Constant * structVal = ConstantStruct::get(values, false);
+    return new GlobalVariable(structVal->getType(), true,
+        GlobalValue::InternalLinkage, structVal, DERIVEDTYPE_NAME, module);
+}
+
+/*
+GlobalVariable * DebugInfoBuilder::CreateDerivedTypeDescriptor(
+    unsigned tag, GlobalVariable * compileUnit, GlobalVariable * context,
+    std::string & name, unsigned line, unsigned sizeInBits,
+    unsigned alignmentInBits, unsigned offsetInBits, GlobalVariable * derivedFrom) {
+
+    std::vector<Constant *> values;
+    values.push_back(ConstantInt::get(Type::Int32Ty, tag + LLVMDebugVersion));
+    values.push_back(context ? ConstantExpr::getBitCast(context, anyPtrType) : NULL);
+    values.push_back(ConstantArray::get(name));
+    values.push_back(compileUnit ? ConstantExpr::getBitCast(compileUnit, anyPtrType) : NULL);
+    values.push_back(ConstantInt::get(Type::Int32Ty, line));
+    values.push_back(ConstantInt::get(Type::Int32Ty, sizeInBits));
+    values.push_back(ConstantInt::get(Type::Int32Ty, alignmentInBits));
+    values.push_back(ConstantInt::get(Type::Int32Ty, offsetInBits));
+    values.push_back(ConstantInt::get(Type::Int32Ty, sizeInBits));
+    values.push_back(derivedFrom ? ConstantExpr::getBitCast(derivedFrom, anyPtrType) : NULL);
+
+    Constant * structVal = ConstantStruct::get(values, false);
+    return new GlobalVariable(structVal->getType(), true,
+        GlobalValue::InternalLinkage, structVal, BASICTYPE_NAME, module);
+}
+
+*/
+
+}

Property changes on: lib/AsmParser
___________________________________________________________________
Name: svn:ignore
   - Debug
Release
Release-Asserts
llvmAsmParser.output
llvmAsmParser.cpp
llvmAsmParser.h

   + *.y


