diff --git a/include/llvm/CodeGen/AsmPrinter.h b/include/llvm/CodeGen/AsmPrinter.h
index 751199b..ea89de1 100644
--- a/include/llvm/CodeGen/AsmPrinter.h
+++ b/include/llvm/CodeGen/AsmPrinter.h
@@ -22,6 +22,7 @@
 #include "llvm/Support/ErrorHandling.h"
 
 namespace llvm {
+  class AsmDebug;
   class BlockAddress;
   class GCStrategy;
   class Constant;
@@ -108,7 +109,7 @@ namespace llvm {
     MachineLoopInfo *LI;
 
     /// DD - If the target supports dwarf debug info, this pointer is non-null.
-    DwarfDebug *DD;
+    AsmDebug *DD;
 
     /// DE - If the target supports dwarf exception info, this pointer is
     /// non-null.
diff --git a/include/llvm/MC/MCAsmInfo.h b/include/llvm/MC/MCAsmInfo.h
index 97aad71..dbe190e 100644
--- a/include/llvm/MC/MCAsmInfo.h
+++ b/include/llvm/MC/MCAsmInfo.h
@@ -28,6 +28,10 @@ namespace llvm {
   class MCSymbol;
   class MCContext;
 
+  namespace DebugInformation {
+      enum DebugInformationType { None, Dwarf, CodeView };
+  }
+
   namespace ExceptionHandling {
     enum ExceptionsType { None, DwarfCFI, SjLj, ARM, Win64 };
   }
@@ -301,9 +305,9 @@ namespace llvm {
     /// HasLEB128 - True if target asm supports leb128 directives.
     bool HasLEB128;                          // Defaults to false.
 
-    /// SupportsDebugInformation - True if target supports emission of debugging
-    /// information.
-    bool SupportsDebugInformation;           // Defaults to false.
+    /// DebugInformationType - Contains type of debug information to emit.
+    /// Defaults to None.
+    DebugInformation::DebugInformationType DebugInformationType;
 
     /// SupportsExceptionHandling - True if target supports exception handling.
     ExceptionHandling::ExceptionsType ExceptionsType; // Defaults to None
@@ -521,7 +525,10 @@ namespace llvm {
       return HasLEB128;
     }
     bool doesSupportDebugInformation() const {
-      return SupportsDebugInformation;
+      return DebugInformationType != DebugInformation::None;
+    }
+    DebugInformation::DebugInformationType getDebugInformationType() const {
+        return DebugInformationType;
     }
     bool doesSupportExceptionHandling() const {
       return ExceptionsType != ExceptionHandling::None;
diff --git a/include/llvm/MC/MCObjectFileInfo.h b/include/llvm/MC/MCObjectFileInfo.h
index 23e5513..7139321 100644
--- a/include/llvm/MC/MCObjectFileInfo.h
+++ b/include/llvm/MC/MCObjectFileInfo.h
@@ -107,6 +107,10 @@ protected:
   const MCSection *DwarfRangesSection;
   const MCSection *DwarfMacroInfoSection;
 
+  // CodeView debug sections - COFF only.
+  const MCSection *CodeViewSymbolInformationSection;
+  const MCSection *CodeViewTypeInformationSection;
+
   // Extra TLS Variable Data section.  If the target needs to put additional
   // information for a TLS variable, it'll go here.
   const MCSection *TLSExtraDataSection;
@@ -222,6 +226,13 @@ public:
   const MCSection *getDwarfMacroInfoSection() const {
     return DwarfMacroInfoSection;
   }
+  const MCSection *getCodeViewSymbolInformationSection() const {
+    return CodeViewSymbolInformationSection;
+  }
+  const MCSection *getCodeViewTypeInformationSection() const {
+    return CodeViewTypeInformationSection;
+  }
+
   const MCSection *getTLSExtraDataSection() const {
     return TLSExtraDataSection;
   }
diff --git a/include/llvm/Support/CodeView.h b/include/llvm/Support/CodeView.h
new file mode 100644
index 0000000..ea551ef
--- /dev/null
+++ b/include/llvm/Support/CodeView.h
@@ -0,0 +1,496 @@
+//===-- llvm/Support/CodeView.h --- CodeView Constants-----------*- 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 constants and structures used for implementing
+// CodeView debug information on Windows platforms. For more information, see
+// Visual C++ 5.0 Symbolic Debug Information Specification, Revision 5.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_SUPPORT_CODEVIEW_H
+#define LLVM_SUPPORT_CODEVIEW_H
+
+#include "llvm/Support/DataTypes.h"
+
+namespace llvm {
+namespace CodeView {
+
+/*
+ * The .debug$S segments contains the symbol information. It starts with the
+ * CodeView version (0x0004, 4 bytes).
+ * Then follows a sequence of subsections. General layout of a subsection is:
+ * 
+ * +-----------------+ 4-byte aligned
+ * | type (4 bytes)  |
+ * +-----------------+
+ * | length (4bytes) | does not include type, length and padding
+ * +-----------------+
+ * | ...             |
+ * +-----------------+
+ * | padding (0x00)  | only if required, repeated until next
+ * +-----------------+ address is 4-byte aligned
+ *
+ * Currently are 4 subsections defined.
+ *
+ * Type = 0x000f1. Contains the symbol information. 
+ *   See CodeViewSymbol below.
+ *
+ * Type = 0x000f2. Line numbers for section.
+ * +-------------------------------------------------------------+
+ * | start offset in section (SECREL to section start) (4 bytes) |
+ * +-------------------------------------------------------------+
+ * | section index (SECTION to section start) (2 bytes)          |
+ * +-------------------------------------------------------------+
+ * | pad/align (0) (2 bytes)                                     |
+ * +-------------------------------------------------------------+
+ * | section length covered by line number info (4 bytes)        |
+ * +-------------------------------------------------------------+
+ * | offset of source file in source file info table (4 bytes)   |
+ * +-------------------------------------------------------------+
+ * | number of line number pairs (4 bytes)                       |
+ * +-------------------------------------------------------------+
+ * | number of bytes of line number pairs + 12 (4 bytes)         |
+ * +-------------------------------------------------------------+
+ *
+ * followed by repeated sequence of
+ *
+ * +-------------------------------------------------------------+
+ * | offset in section (4bytes)                                  |
+ * +-------------------------------------------------------------+
+ * | line number (4bytes)                                        |
+ * +-------------------------------------------------------------+
+
+    followed by pairs of:
+      4 bytes - offset in section
+      4 bytes - line number; if high bit is set,
+                end of statement/breakpointable (?) - e.g. lines containing
+	        just labels should have line numbers
+
+ *
+ * Type = 0x000f3. Source filename string table.
+    1 byte - 0 (0th filename)
+    0-terminated filename strings, 1 for each source file
+ *
+ *
+ * Type = 0x000f4. Info about source files.
+    for each source file:
+        4 bytes - offset of filename in source filename string table
+	{2 bytes - checksum type/length? (0x0110)
+	 16 bytes - MD5 checksum of source file} OR
+	{2 bytes - no checksum (0)}
+	2 bytes - 0 (padding?)
+ */
+
+typedef unsigned long   CV_uoff32_t;
+typedef          long   CV_off32_t;
+typedef unsigned short  CV_uoff16_t;
+typedef          short  CV_off16_t;
+typedef unsigned short  CV_typ_t;
+
+enum {
+  CV_SIGNATURE_C7 = 0x0001,
+  CV_SIGNATURE_C8 = 0x0004
+};
+
+enum {
+    Symbol_Section = 0x00f1,
+    Line_Number_Section = 0x00f2,
+    Sourcefile_Table_Section = 0x00f3,
+    Sourcefile_Info_Section = 0x00f4
+};
+
+enum CodeViewSymbolId {
+  S_COMPILE_V1 = 0x0001,     // Compile flags symbol
+  S_REGISTER_V1 = 0x0002,    // Register variable
+  S_CONSTANT_V1 = 0x0003,    // Constant symbol
+  S_UDT_V1 = 0x0004,         // User-defined Type
+  S_SSEARCH_V1 = 0x0005,     // Start search
+  S_END_V1 = 0x0006,         // End block, procedure, with, or thunk
+  S_SKIP_V1 = 0x0007,        // Skip - Reserve symbol space
+  S_CVRESERVE_V1 = 0x0008,   // Reserved for CodeView internal use
+  S_OBJNAME_V1 = 0x0009,     // Specify name of object file
+  S_ENDARG_V1 = 0x000a,      // Specify end of arguments in function symbols
+  S_COBOLUDT_V1 = 0x000b,    // Microfocus COBOL user-defined type
+  S_MANYREG_V1 = 0x000c,     // Many register symbol
+  S_RETURN_V1 = 0x000d,      // Function return description
+  S_ENTRYTHIS_V1 = 0x000e,   // Description of this pointer at entry
+
+  /* 16 bit entry omitted */
+
+  S_BPREL_V1 = 0x0200,       // BP relative 16:32
+  S_LDATA_V1 = 0x0201,       // Local data 16:32
+  S_GDATA_V1 = 0x0202,       // Global data 16:32
+  S_PUB_V1 = 0x0203,         // Public symbol 16:32
+  S_LPROC_V1 = 0x0204,       // Local procedure start 16:32
+  S_GPROC_V1 = 0x0205,       // Global procedure start 16:32
+  S_THUNK_V1 = 0x0206,       // Thunk start 16:32
+  S_BLOCK_V1 = 0x0207,       // Block start 16:32
+  S_WITH_V1 = 0x0208,        // With start 16:32
+  S_LABEL_V1 = 0x0209,       // Label 16:32
+  S_VFTPATH_V1 = 0x020b,     // Virtual function table path descriptor 16:32
+  S_REGREL_V1 = 0x020c,      // 16:32 offset relative to arbitrary register
+  S_LTHREAD_V1 = 0x020d,     // Local Thread Storage data
+  S_GTHREAD_V1 = 0x020e,     // Global Thread Storage data
+
+  S_LPROCMIPS_V1 = 0x0300,   // Local procedure start MIPS
+  S_GPROCMIPS_V1 = 0x0301,   // Global procedure start MIPS
+
+  S_PROCREF = 0x0400,        // Reference to a procedure
+  S_DATAREF = 0x0401,        // Reference to data
+  S_ALIGN = 0x0402,          // Page align symbols
+  S_LPROCREF_V1 = 0x0403,
+
+  S_REGISTER_V2 = 0x1001,    // Register variable
+  S_CONSTANT_V2 = 0x1002,    // Constant symbol
+  S_UDT_V2 = 0x1003,         // User-defined type
+  S_COBOLUDT_V2 = 0x1004,    // Microfocus COBOL user-defined type
+  S_MANYREG_V2 = 0x1005,     // Many register symbol
+  S_BPREL_V2 = 0x1006,       // BP relative 16:32
+  S_LDATA_V2 = 0x1007,       // Local data 16:32
+  S_GDATA_V2 = 0x1008,       // Global data 16:32
+  S_PUB_V2 = 0x1009,         // Public symbol 16:32
+  S_LPROC_V2 = 0x100a,       // Local procedure start 16:32
+  S_GPROC_V2 = 0x100b,       // Global procedure start 16:32
+  S_VFTTABLE_V2 = 0x100c,    // Virtual function table path descriptor 16:32
+  S_REGREL_V2 = 0x100d,      // 16:32 offset relative to arbitrary register
+  S_LTHREAD_V2 = 0x100e,     // Local Thread Storage data
+  S_GTHREAD_V2 = 0x100f,     // Global Thread Storage data
+  S_LPROCMIPS_V2 = 0x1010,   // Local procedure start MIPS
+  S_GPROCMIPS_V2 = 0x1011,   // Global procedure start MIPS
+  S_FRAMEINFO_V2 = 0x1012,
+  S_COMPILAND_V2 = 0x1013,
+
+  S_OBJNAME_V2 = 0x1101,
+  S_THUNK_V3 = 0x1102,
+  S_BLOCK_V3 = 0x1103,
+  S_LABEL_V3 = 0x1105,
+  S_REGISTER_V3 = 0x1106,
+  S_CONSTANT_V3 = 0x1107,
+  S_UDT_V3 = 0x1108,
+  S_BPREL_V3 = 0x110B,
+  S_LDATA_V3 = 0x110C,
+  S_GDATA_V3 = 0x110D,
+  S_PUB_V3 = 0x110E,
+  S_LPROC_V3 = 0x110F,
+  S_GPROC_V3 = 0x1110,
+  S_REGREL_V3 = 0x1111,
+  S_LTHREAD_V3 = 0x1112,
+  S_GTHREAD_V3 = 0x1113,
+  S_MSTOOL_V3 = 0x1116,
+  S_PUB_FUNC1_V3 = 0x1125,
+  S_PUB_FUNC2_V3 = 0x1127,
+  S_SECTINFO_V3 = 0x1136,
+  S_SUBSECTINFO_V3 = 0x1137,
+  S_ENTRYPOINT_V3 = 0x1138,
+  S_SECUCOOKIE_V3 = 0x113A,
+  S_MSTOOLINFO_V3 = 0x113C,
+  S_MSTOOLENV_V3 = 0x113D
+};
+
+union CodeViewSymbol {
+  struct {
+    uint16_t Length;
+    uint16_t SymbolId;
+  } Generic;
+  struct {
+    uint16_t Length;
+    uint16_t SymbolId; // == S_OBJNAME_V2
+    uint32_t Signature;
+    char Objname[1];
+  } Objname_V2;
+};
+
+
+/*
+struct CodeViewLineNumer { 
+  uint32_t Offset; 
+  uint32_t LinenumStart; 
+  uint32_t DeltaLineEnd; 
+  uint32_t FStatement; 
+};
+
+typedef struct CodeViewColumn { 
+  uint16_t offColumnStart;
+  uint16_t offColumnEnd;
+};
+*/
+
+/*
+ * The .debug$T segments contains the type information. It starts with the
+ * CodeView version (0x0004, 4 bytes). Then follows a sequence of type
+ * records. A type record has the following structure:
+ *
+ * +----------------+-------------------------------+
+ * | type (2 bytes) | type string (0 or more bytes) |
+ * +----------------+-------------------------------+
+ *
+ * A type string is a repeated sequence of leaf structures:
+ *
+ * +----------------+------------------------+
+ * | leaf (2 bytes) | data (0 or more bytes) | (possible repeated)
+ * +----------------+------------------------+
+ *
+ *
+ */
+
+enum {
+  LF_MODIFIER_V1 = 0x0001,
+  LF_POINTER_V1 = 0x0002,
+  LF_ARRAY_V1 = 0x0003,
+  LF_CLASS_V1 = 0x0004,
+  LF_STRUCTURE_V1 = 0x0005,
+  LF_UNION_V1 = 0x0006,
+  LF_ENUM_V1 = 0x0007,
+  LF_PROCEDURE_V1 = 0x0008,
+  LF_MFUNCTION_V1 = 0x0009,
+  LF_VTSHAPE_V1 = 0x000a,
+  LF_COBOL0_V1 = 0x000b,
+  LF_COBOL1_V1 = 0x000c,
+  LF_BARRAY_V1 = 0x000d,
+  LF_LABEL_V1 = 0x000e,
+  LF_NULL_V1 = 0x000f,
+  LF_NOTTRAN_V1 = 0x0010,
+  LF_DIMARRAY_V1 = 0x0011,
+  LF_VFTPATH_V1 = 0x0012,
+  LF_PRECOMP_V1 = 0x0013,
+  LF_ENDPRECOMP_V1 = 0x0014,
+  LF_OEM_V1 = 0x0015,
+  LF_TYPESERVER_V1 = 0x0016,
+
+  LF_MODIFIER_V2 = 0x1001,     /* variants with new 32-bit type indices (V2) */
+  LF_POINTER_V2 = 0x1002,
+  LF_ARRAY_V2 = 0x1003,
+  LF_CLASS_V2 = 0x1004,
+  LF_STRUCTURE_V2 = 0x1005,
+  LF_UNION_V2 = 0x1006,
+  LF_ENUM_V2 = 0x1007,
+  LF_PROCEDURE_V2 = 0x1008,
+  LF_MFUNCTION_V2 = 0x1009,
+  LF_COBOL0_V2 = 0x100a,
+  LF_BARRAY_V2 = 0x100b,
+  LF_DIMARRAY_V2 = 0x100c,
+  LF_VFTPATH_V2 = 0x100d,
+  LF_PRECOMP_V2 = 0x100e,
+  LF_OEM_V2 = 0x100f,
+
+  LF_SKIP_V1 = 0x0200,
+  LF_ARGLIST_V1 = 0x0201,
+  LF_DEFARG_V1 = 0x0202,
+  LF_LIST_V1 = 0x0203,
+  LF_FIELDLIST_V1 = 0x0204,
+  LF_DERIVED_V1 = 0x0205,
+  LF_BITFIELD_V1 = 0x0206,
+  LF_METHODLIST_V1 = 0x0207,
+  LF_DIMCONU_V1 = 0x0208,
+  LF_DIMCONLU_V1 = 0x0209,
+  LF_DIMVARU_V1 = 0x020a,
+  LF_DIMVARLU_V1 = 0x020b,
+  LF_REFSYM_V1 = 0x020c,
+
+  LF_SKIP_V2 = 0x1200,    /* variants with new 32-bit type indices (V2) */
+  LF_ARGLIST_V2 = 0x1201,
+  LF_DEFARG_V2 = 0x1202,
+  LF_FIELDLIST_V2 = 0x1203,
+  LF_DERIVED_V2 = 0x1204,
+  LF_BITFIELD_V2 = 0x1205,
+  LF_METHODLIST_V2 = 0x1206,
+  LF_DIMCONU_V2 = 0x1207,
+  LF_DIMCONLU_V2 = 0x1208,
+  LF_DIMVARU_V2 = 0x1209,
+  LF_DIMVARLU_V2 = 0x120a,
+
+  /* Field lists */
+  LF_BCLASS_V1 = 0x0400,
+  LF_VBCLASS_V1 = 0x0401,
+  LF_IVBCLASS_V1 = 0x0402,
+  LF_ENUMERATE_V1 = 0x0403,
+  LF_FRIENDFCN_V1 = 0x0404,
+  LF_INDEX_V1 = 0x0405,
+  LF_MEMBER_V1 = 0x0406,
+  LF_STMEMBER_V1 = 0x0407,
+  LF_METHOD_V1 = 0x0408,
+  LF_NESTTYPE_V1 = 0x0409,
+  LF_VFUNCTAB_V1 = 0x040a,
+  LF_FRIENDCLS_V1 = 0x040b,
+  LF_ONEMETHOD_V1 = 0x040c,
+  LF_VFUNCOFF_V1 = 0x040d,
+  LF_NESTTYPEEX_V1 = 0x040e,
+  LF_MEMBERMODIFY_V1 = 0x040f,
+
+  LF_BCLASS_V2 = 0x1400,    /* variants with new 32-bit type indices (V2) */
+  LF_VBCLASS_V2 = 0x1401,
+  LF_IVBCLASS_V2 = 0x1402,
+  LF_FRIENDFCN_V2 = 0x1403,
+  LF_INDEX_V2 = 0x1404,
+  LF_MEMBER_V2 = 0x1405,
+  LF_STMEMBER_V2 = 0x1406,
+  LF_METHOD_V2 = 0x1407,
+  LF_NESTTYPE_V2 = 0x1408,
+  LF_VFUNCTAB_V2 = 0x1409,
+  LF_FRIENDCLS_V2 = 0x140a,
+  LF_ONEMETHOD_V2 = 0x140b,
+  LF_VFUNCOFF_V2 = 0x140c,
+  LF_NESTTYPEEX_V2 = 0x140d,
+
+  LF_ENUMERATE_V3 = 0x1502,
+  LF_ARRAY_V3 = 0x1503,
+  LF_CLASS_V3 = 0x1504,
+  LF_STRUCTURE_V3 = 0x1505,
+  LF_UNION_V3 = 0x1506,
+  LF_ENUM_V3 = 0x1507,
+  LF_MEMBER_V3 = 0x150d,
+  LF_STMEMBER_V3 = 0x150e,
+  LF_METHOD_V3 = 0x150f,
+  LF_NESTTYPE_V3 = 0x1510,
+  LF_ONEMETHOD_V3 = 0x1511,
+
+  LF_NUMERIC = 0x8000,    /* numeric leaf types */
+  LF_CHAR = 0x8000,
+  LF_SHORT = 0x8001,
+  LF_USHORT = 0x8002,
+  LF_LONG = 0x8003,
+  LF_ULONG = 0x8004,
+  LF_REAL32 = 0x8005,
+  LF_REAL64 = 0x8006,
+  LF_REAL80 = 0x8007,
+  LF_REAL128 = 0x8008,
+  LF_QUADWORD = 0x8009,
+  LF_UQUADWORD = 0x800a,
+  LF_REAL48 = 0x800b,
+  LF_COMPLEX32 = 0x800c,
+  LF_COMPLEX64 = 0x800d,
+  LF_COMPLEX80 = 0x800e,
+  LF_COMPLEX128 = 0x800f,
+  LF_VARSTRING = 0x8010
+};
+
+enum {
+  CV_FIRST_NONPRIM = 0x1000
+};
+
+enum {
+  T_Size_Mask = 0x0007,
+  T_Mode_Mask = 0x0700,
+  T_ModeShift = 8,
+  T_Type_Mask = 0x00f0,
+  T_Type_Shift = 4,
+
+  // types
+  T_Special = 0x00,
+  T_Signed_integral_value = 0x01,
+  T_Unsigned_integral_value = 0x02,
+  T_Boolean = 0x03,
+  T_Real = 0x04,
+  T_Complex = 0x05,
+  T_Special2 = 0x06,
+  T_Real_int_value = 0x07,
+  // 0x08 - 0x0e Reserved
+  // 0x0f Reserved for debugger expression evaluator
+
+  // Size
+  // Type = special
+  T_No_type = 0x00,
+  T_Absolute_symbol = 0x01,
+  T_Segment = 0x02,
+  T_Void = 0x03,
+  T_Basic_8_byte_currency_value = 0x04,
+  T_Near_Basic_string = 0x05,
+  T_Far_Basic_string = 0x06,
+  T_Untranslated_type_from_previous_Microsoft_symbol_formats = 0x07,
+};
+
+//      enumeration for LF_MODIFIER values
+
+
+struct CV_modifier_t {
+    unsigned short  MOD_const       :1;
+    unsigned short  MOD_volatile    :1;
+    unsigned short  MOD_unaligned   :1;
+    unsigned short  MOD_unused      :13;
+};
+
+
+//      bit field structure describing class/struct/union/enum properties
+
+struct CV_prop_t {
+    unsigned short  packed      :1;     // true if structure is packed
+    unsigned short  ctor        :1;     // true if constructors or destructors present
+    unsigned short  ovlops      :1;     // true if overloaded operators present
+    unsigned short  isnested    :1;     // true if this is a nested class
+    unsigned short  cnested     :1;     // true if this class contains nested types
+    unsigned short  opassign    :1;     // true if overloaded assignment (=)
+    unsigned short  opcast      :1;     // true if casting methods
+    unsigned short  fwdref      :1;     // true if forward reference (incomplete defn)
+    unsigned short  scoped      :1;     // scoped definition
+    unsigned short  reserved    :7;
+};
+
+
+
+
+//      class field attribute
+
+struct CV_fldattr_t {
+    unsigned short  access      :2;     // access protection CV_access_t
+    unsigned short  mprop       :3;     // method properties CV_methodprop_t
+    unsigned short  pseudo      :1;     // compiler generated fcn and does not exist
+    unsigned short  noinherit   :1;     // true if class cannot be inherited
+    unsigned short  noconstruct :1;     // true if class cannot be constructed
+    unsigned short  unused      :8;     // unused
+};
+
+  struct Arglist_V2 {
+    uint16_t leaf;           // LF_PROCEDURE
+    uint32_t argcount;       // type index of return value
+    uint32_t indices[1];        // type indices of argument types
+  };
+  struct Procedure_V1 {
+    uint16_t leaf;           // LF_PROCEDURE
+    uint16_t rvtype;         // type index of return value
+    uint8_t  calltype;       // calling convention (CV_call_t)
+    uint8_t  reserved;       // reserved for future use
+    uint16_t parmcount;      // number of parameters
+    uint16_t arglist;        // type index of argument list
+  };
+  struct Procedure_V2 {
+    uint16_t leaf;           // LF_PROCEDURE
+    uint32_t rvtype;         // type index of return value
+    uint8_t calltype;       // calling convention (CV_call_t)
+    uint8_t reserved;       // reserved for future use
+    uint16_t parmcount;      // number of parameters
+    uint32_t arglist;        // type index of argument list
+  };
+
+union Leaf {
+  struct {
+    uint16_t Leaf;
+    uint8_t Data;
+  } Generic;
+  struct {
+    unsigned short  leaf;           // LF_MODIFIER
+    CV_modifier_t   attr;           // modifier attribute modifier_t
+    CV_typ_t        type;           // modified type
+  } Modifier;
+  struct {
+    unsigned short  leaf;           // LF_ENUM
+    unsigned short  count;          // count of number of elements in class
+    CV_typ_t        utype;          // underlying type of the enum
+    CV_typ_t        field;          // type index of LF_FIELD descriptor list
+    CV_prop_t       property;       // property attribute field
+    unsigned char   Name[1];        // length prefixed name of enum
+  } Enum; 
+  Arglist_V2 Arglist_V2;
+  Procedure_V1 Procedure_V1;
+  Procedure_V2 Procedure_V2;
+};
+
+} // End of namespace CodeView
+} // End of namespace llvm
+
+#endif
diff --git a/lib/CodeGen/AsmPrinter/AsmDebug.h b/lib/CodeGen/AsmPrinter/AsmDebug.h
new file mode 100644
index 0000000..ed63e44
--- /dev/null
+++ b/lib/CodeGen/AsmPrinter/AsmDebug.h
@@ -0,0 +1,69 @@
+//===-- llvm/CodeGen/AsmDebug.h - Asm Debug Framework ----------*- 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 support interface for writing debug information
+// into asm files.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef CODEGEN_ASMPRINTER_ASMDEBUG_H__
+#define CODEGEN_ASMPRINTER_ASMDEBUG_H__
+
+#include "llvm/DebugInfo.h"
+#include "llvm/CodeGen/AsmPrinter.h"
+#include "llvm/CodeGen/LexicalScopes.h"
+#include "llvm/MC/MachineLocation.h"
+
+namespace llvm {
+
+class MachineFrameInfo;
+class MachineModuleInfo;
+class MachineOperand;
+class MCAsmInfo;
+
+class AsmDebug {
+protected:
+  /// Asm - Target of Dwarf emission.
+  AsmPrinter *Asm;
+
+  /// MMI - Collected machine module information.
+  MachineModuleInfo *MMI;
+
+public:
+  //===--------------------------------------------------------------------===//
+  // Main entry points.
+  //
+  AsmDebug(AsmPrinter *A) : Asm(A), MMI(Asm->MMI) {}
+  virtual ~AsmDebug() {}
+
+  /// beginModule - Emit all Dwarf sections that should come prior to the
+  /// content.
+  virtual void beginModule(Module *M) = 0;
+
+  /// endModule - Emit all Dwarf sections that should come after the content.
+  ///
+  virtual void endModule() = 0;
+
+  /// beginFunction - Gather pre-function debug information.  Assumes being
+  /// emitted immediately after the function entry point.
+  virtual void beginFunction(const MachineFunction *MF) = 0;
+
+  /// endFunction - Gather and emit post-function debug information.
+  ///
+  virtual void endFunction(const MachineFunction *MF) = 0;
+
+  /// beginInstruction - Process beginning of an instruction.
+  virtual void beginInstruction(const MachineInstr *MI) = 0;
+
+  /// endInstruction - Prcess end of an instruction.
+  virtual void endInstruction(const MachineInstr *MI) = 0;
+};
+} // End of namespace llvm
+
+#endif
diff --git a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index d74a703..1936976 100644
--- a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -13,6 +13,8 @@
 
 #define DEBUG_TYPE "asm-printer"
 #include "llvm/CodeGen/AsmPrinter.h"
+#include "AsmDebug.h"
+#include "CodeViewDebug.h"
 #include "DwarfDebug.h"
 #include "DwarfException.h"
 #include "llvm/DebugInfo.h"
@@ -187,8 +189,16 @@ bool AsmPrinter::doInitialization(Module &M) {
     OutStreamer.AddBlankLine();
   }
 
-  if (MAI->doesSupportDebugInformation())
+  switch (MAI->getDebugInformationType()) {
+  case DebugInformation::None:
+    break;
+  case DebugInformation::Dwarf:
     DD = new DwarfDebug(this, &M);
+    break;
+  case DebugInformation::CodeView:
+    DD = new CodeViewDebug(this, &M);
+    break;
+  }
 
   switch (MAI->getExceptionHandlingType()) {
   case ExceptionHandling::None:
diff --git a/lib/CodeGen/AsmPrinter/CMakeLists.txt b/lib/CodeGen/AsmPrinter/CMakeLists.txt
index 58fe2ed..213cd22 100644
--- a/lib/CodeGen/AsmPrinter/CMakeLists.txt
+++ b/lib/CodeGen/AsmPrinter/CMakeLists.txt
@@ -3,6 +3,7 @@ add_llvm_library(LLVMAsmPrinter
   AsmPrinter.cpp
   AsmPrinterDwarf.cpp
   AsmPrinterInlineAsm.cpp
+  CodeViewDebug.cpp
   DIE.cpp
   DwarfAccelTable.cpp
   DwarfCFIException.cpp
diff --git a/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp b/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
new file mode 100644
index 0000000..d34f9db
--- /dev/null
+++ b/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
@@ -0,0 +1,413 @@
+//===-- llvm/CodeGen/DwarfDebug.cpp - Dwarf Debug Framework ---------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file contains support for writing codeview debug info into asm files.
+//
+//===----------------------------------------------------------------------===//
+
+#define DEBUG_TYPE "codeviewdebug"
+#include "CodeViewDebug.h"
+#include "llvm/Constants.h"
+#include "llvm/DebugInfo.h"
+#include "llvm/DIBuilder.h"
+#include "llvm/Module.h"
+#include "llvm/Instructions.h"
+#include "llvm/CodeGen/MachineFunction.h"
+#include "llvm/CodeGen/MachineModuleInfo.h"
+#include "llvm/MC/MCAsmInfo.h"
+#include "llvm/MC/MCSection.h"
+#include "llvm/MC/MCStreamer.h"
+#include "llvm/MC/MCSymbol.h"
+#include "llvm/DataLayout.h"
+#include "llvm/Target/TargetFrameLowering.h"
+#include "llvm/Target/TargetLoweringObjectFile.h"
+#include "llvm/Target/TargetMachine.h"
+#include "llvm/Target/TargetRegisterInfo.h"
+#include "llvm/Target/TargetOptions.h"
+#include "llvm/ADT/Statistic.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/Triple.h"
+#include "llvm/Support/Debug.h"
+#include "llvm/Support/Dwarf.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/ValueHandle.h"
+#include "llvm/Support/FormattedStream.h"
+#include "llvm/Support/Timer.h"
+#include "llvm/Support/Path.h"
+#include <string>
+#include <vector>
+using namespace llvm;
+
+namespace {
+  const char *CodeViewGroupName = "CodeView Emission";
+  const char *DbgTimerName = "CodeView Debug Writer";
+} // end anonymous namespace
+
+
+
+    // Add a new leaf record, returns index
+    uint16_t TypeStringManager::Add(LeafRecord *Record) {
+      uint16_t idx = CodeView::CV_FIRST_NONPRIM + NextIndex;
+      TypesString.push_back(Record);
+      ++NextIndex;
+      return idx;
+    }
+
+    uint32_t TypeStringManager::Size() {
+      uint64_t size = 0;
+      for (LeafVector::const_iterator i = TypesString.cbegin(), 
+                                      e =  TypesString.cend();
+                                      i != e;
+                                      ++i) {
+        LeafRecord *Rec = *i;
+        size += (2 /*Size of Leaf Type*/ + Rec->Length);
+      }
+      assert(size <= UINT32_MAX && "Type string is oversized");
+      return static_cast<uint32_t>(size);
+    }
+
+    // Emit the records
+    void TypeStringManager::Emit(AsmPrinter *Asm) {
+      for (LeafVector::const_iterator i = TypesString.cbegin(), 
+                                      e =  TypesString.cend();
+                                      i != e;
+                                      ++i) {
+        LeafRecord *Rec = *i;
+        if (Asm->isVerbose())
+          Asm->OutStreamer.AddComment("Leaf type"); // FIXME: Print Leaf Type Name
+        Asm->EmitInt16(Rec->Leaf.Generic.Leaf);
+        if (Asm->isVerbose())
+          Asm->OutStreamer.AddComment("Data");
+        Asm->OutStreamer.EmitBytes(StringRef(reinterpret_cast<const char *>(&Rec->Leaf.Generic.Data), Rec->Length - sizeof(uint16_t)), 0/*addrspace*/);
+      }
+    }
+
+    uint16_t TypeStringManager::toReservedType(const DIBasicType& type) {
+      enum {
+        SV = CodeView::T_Signed_integral_value << CodeView::T_Type_Shift,
+        UV = CodeView::T_Unsigned_integral_value << CodeView::T_Type_Shift,
+        BV = CodeView::T_Boolean << CodeView::T_Type_Shift,
+        RV = CodeView::T_Real << CodeView::T_Type_Shift,
+        RiV = CodeView::T_Real_int_value << CodeView::T_Type_Shift,
+
+      };
+      uint16_t res = 0U;
+      // Encode size
+      switch (type.getEncoding())
+      {
+      case dwarf::DW_ATE_boolean:
+      case dwarf::DW_ATE_signed:
+      case dwarf::DW_ATE_signed_char:
+      case dwarf::DW_ATE_unsigned:
+      case dwarf::DW_ATE_unsigned_char:
+      case dwarf::DW_ATE_UTF:
+        switch (type.getSizeInBits()) {
+        default: llvm_unreachable("wrong bit size");
+        case  8: res |= 0; break;
+        case 16: res |= 1; break;
+        case 32: res |= 2; break;
+        case 64: res |= 3; break;
+        }
+        break;
+      case dwarf::DW_ATE_float:
+      case dwarf::DW_ATE_complex_float:
+      case dwarf::DW_ATE_imaginary_float:
+        switch (type.getSizeInBits()) {
+        default: llvm_unreachable("wrong bit size");
+        case 32: res |= 0; break;
+        case 64: res |= 1; break;
+        case 80: res |= 2; break;
+        case 128: res |= 3; break;
+        case 48: res |= 4; break;
+        }
+        break;
+      }
+      // Encode type
+      switch (type.getEncoding())
+      {
+      case dwarf::DW_ATE_address:
+        break;
+      case dwarf::DW_ATE_boolean:
+        res |= CodeView::T_Boolean << CodeView::T_Type_Shift;
+        break;
+      case dwarf::DW_ATE_complex_float:
+        res |= CodeView::T_Complex << CodeView::T_Type_Shift;
+        break;
+      case dwarf::DW_ATE_float:
+        res |= CodeView::T_Real << CodeView::T_Type_Shift;
+        break;
+      case dwarf::DW_ATE_signed:
+        res |= CodeView::T_Signed_integral_value << CodeView::T_Type_Shift;
+        break;
+      case dwarf::DW_ATE_signed_char:
+        break;
+      case dwarf::DW_ATE_unsigned:
+        res |= CodeView::T_Unsigned_integral_value << CodeView::T_Type_Shift;
+        break;
+      case dwarf::DW_ATE_unsigned_char:
+        break;
+      case dwarf::DW_ATE_imaginary_float:
+      case dwarf::DW_ATE_packed_decimal:
+      case dwarf::DW_ATE_numeric_string:
+      case dwarf::DW_ATE_edited:
+      case dwarf::DW_ATE_signed_fixed:
+      case dwarf::DW_ATE_unsigned_fixed:
+      case dwarf::DW_ATE_decimal_float:
+      case dwarf::DW_ATE_UTF:
+      case dwarf::DW_ATE_lo_user:
+      case dwarf::DW_ATE_hi_user:
+        llvm_unreachable("Not yet implemented.");
+        break;
+      }
+      assert(res < CodeView::CV_FIRST_NONPRIM && "Primitive type index not lower than CV_FIRST_NONPRIM");
+      return res;
+    }
+
+    uint32_t TypeStringManager::toTypeIdx(const DIType& Type) {
+      uint32_t res = 0;
+      if (Type.isBasicType()) {
+        return toReservedType(DIBasicType(Type));
+      }
+      else if (Type.isCompositeType()) {
+        DICompositeType dct(Type);
+        //dct.
+        outs() << "CompositeType :Tag: " << Type.getTag() << "\n";
+        outs().flush();
+      }
+      else
+        llvm_unreachable("Not yet implemented.");
+      return res;
+    }
+
+    uint32_t TypeStringManager::ParameterToTypeIdx(const DIArray& Vars) {
+      LeafRecord *Rec = LeafRecord::Create(CodeView::LF_ARGLIST_V2, sizeof(CodeView::Arglist_V2) + ((Vars.getNumElements()-1) * sizeof(uint32_t)));
+      Rec->Leaf.Arglist_V2.argcount = Vars.getNumElements();
+      uint32_t *Data = reinterpret_cast<uint32_t *>(&Rec->Leaf.Arglist_V2.indices);
+      for (unsigned i = 0, e = Vars.getNumElements(); i != e; ++i) {
+        DIVariable v(Vars.getElement(i));
+      outs() << "Parameter type\n";
+        *Data++ = toTypeIdx(v.getType());
+      }
+      return Add(Rec);
+    }
+
+    uint32_t TypeStringManager::ProcedureToTypeIdx(const DISubprogram& Proc) {
+      LeafRecord *Rec = LeafRecord::Create(CodeView::LF_PROCEDURE_V2, sizeof(CodeView::Procedure_V2));
+      outs() << "Return type\n";
+      Rec->Leaf.Procedure_V2.rvtype = toTypeIdx(Proc.getType());
+      Rec->Leaf.Procedure_V2.calltype = 0; // Calling convention
+      Rec->Leaf.Procedure_V2.reserved = 0;
+      Rec->Leaf.Procedure_V2.parmcount = Proc.getVariables().getNumElements();
+      Rec->Leaf.Procedure_V2.arglist = ParameterToTypeIdx(Proc.getVariables());
+      return Add(Rec);
+    }
+
+
+
+CodeViewDebug::CodeViewDebug(AsmPrinter *A, Module *M)
+  : AsmDebug(A), TypeString(TypeStringManager()) {
+  {
+    NamedRegionTimer T(DbgTimerName, CodeViewGroupName, TimePassesIsEnabled);
+    beginModule(M);
+  }
+}
+
+CodeViewDebug::~CodeViewDebug() {
+}
+
+/// beginModule - Emit all Dwarf sections that should come prior to the
+/// content. Create global DIEs and emit initial debug info sections.
+/// This is invoked by the target AsmPrinter.
+void CodeViewDebug::beginModule(Module *M) {
+  // Gather source modules.
+  std::vector<Sourcefile> Srcfiles;
+  // If module has named metadata anchors then use them, otherwise scan the
+  // module using debug info finder to collect debug info.
+  NamedMDNode *CU_Nodes = M->getNamedMetadata("llvm.dbg.cu");
+  if (CU_Nodes) {
+    Srcfiles.reserve(CU_Nodes->getNumOperands());
+    for (unsigned i = 0, e = CU_Nodes->getNumOperands(); i != e; ++i) {
+      DICompileUnit CUNode(CU_Nodes->getOperand(i));
+
+      // FIXME:
+      // - create the type records from the metadata (includes type indices used in symbols)
+      // - create mapping MDNode -> type record / type index
+      {
+        outs() << "DICompileUnit: " << CUNode.getFilename() << "\n";
+        DIArray SPs = CUNode.getSubprograms();
+        for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i) {
+          DISubprogram sub(SPs.getElement(i));
+          outs() << "DISubprogram.getDisplayName(): " << sub.getDisplayName() << "\n";
+          outs() << "DISubprogram.getName(): " << sub.getName() << "\n";
+          outs() << "DISubprogram.getLinkageName(): " << sub.getLinkageName() << "\n";
+          outs() << "DISubprogram.getReturnTypeName(): " << sub.getReturnTypeName() << "\n";
+
+          DIArray Vs = sub.getVariables();
+          for (unsigned ii = 0, ee = Vs.getNumElements(); ii != ee; ++ii) {
+            DIVariable v(Vs.getElement(ii));
+            outs() << "  DIVariable.getName(): " << v.getName() << "\n";
+            //v.getType();
+          }
+          TypeString.ProcedureToTypeIdx(sub);
+        }
+      }
+
+      sys::Path AbsolutePath(CUNode.getDirectory());
+      AbsolutePath.appendComponent(CUNode.getFilename());
+      uint32_t ofs = 1;
+      if (!Srcfiles.empty()) {
+        Sourcefile& prev = Srcfiles[Srcfiles.size()-1];
+        ofs = prev.Offset + prev.Filename.length() + 1;
+      }
+      Srcfiles.push_back(Sourcefile(AbsolutePath.str(), ofs));
+    }
+  } //else if (!collectLegacyDebugInfo(M))
+    //return;
+
+  // Emit .debug$S section
+  Asm->OutStreamer.SwitchSection(
+    Asm->getObjFileLowering().getCodeViewSymbolInformationSection());
+  if (Asm->isVerbose())
+    Asm->OutStreamer.AddComment("CodeView Version");
+  Asm->EmitInt32(CodeView::CV_SIGNATURE_C8);
+  // FIXME: emit S_OBJNAME_V2 symbol
+  // FIXME: emit tool info symbol
+  if (!Srcfiles.empty()) {
+    emitSourcefileTable(Srcfiles);
+    emitSourcefileInfo(Srcfiles);
+  }
+}
+
+/// endModule - Emit all type information.
+///
+void CodeViewDebug::endModule() {
+  if (!MMI->hasDebugInfo()) return;
+  // Emit type information for the module
+
+  // Emit .debug$T section
+  Asm->OutStreamer.SwitchSection(
+    Asm->getObjFileLowering().getCodeViewTypeInformationSection());
+  if (Asm->isVerbose())
+    Asm->OutStreamer.AddComment("CodeView Version");
+  Asm->EmitInt32(CodeView::CV_SIGNATURE_C8);
+  TypeString.Emit(Asm);
+}
+
+/// beginInstruction - Process beginning of an instruction.
+void CodeViewDebug::beginInstruction(const MachineInstr *MI) {
+  if (!MMI->hasDebugInfo()) return;
+}
+
+/// endInstruction - Process end of an instruction.
+void CodeViewDebug::endInstruction(const MachineInstr *MI) {
+  if (!MMI->hasDebugInfo()) return;
+}
+
+/// beginFunction - Gather pre-function debug information.  Assumes being
+/// emitted immediately after the function entry point.
+void CodeViewDebug::beginFunction(const MachineFunction *MF) {
+  if (!MMI->hasDebugInfo()) return;
+
+  MCSymbol* FunctionBeginSym = Asm->GetTempSymbol("func_begin",
+                                        Asm->getFunctionNumber());
+  // Assumes in correct section after the entry point.
+  Asm->OutStreamer.EmitLabel(FunctionBeginSym);
+
+  //MF->
+
+  // Record function type
+  // Length, leaf, data, leaf, data, ....
+  // Record symbol data
+}
+
+/// endFunction - Gather and emit post-function debug information.
+///
+void CodeViewDebug::endFunction(const MachineFunction *MF) {
+  if (!MMI->hasDebugInfo()) return;
+  // Emit symbol information for the function
+
+  // Emit .debug$S section
+  Asm->OutStreamer.SwitchSection(
+    Asm->getObjFileLowering().getCodeViewSymbolInformationSection());
+  if (Asm->isVerbose())
+    Asm->OutStreamer.AddComment("CodeView Version");
+  Asm->EmitInt32(CodeView::CV_SIGNATURE_C8);
+}
+
+//===----------------------------------------------------------------------===//
+// Emit Methods
+//===----------------------------------------------------------------------===//
+
+void CodeViewDebug::emitSourcefileTable(std::vector<Sourcefile> Srcfiles) {
+  // Calculate length
+  uint32_t length = 1;
+  for (std::vector<Sourcefile>::const_iterator it = Srcfiles.begin();
+                                               it != Srcfiles.end(); ++it) {
+    length += (*it).Filename.size() + 1;
+  }
+
+  // Emit
+  if (Asm->isVerbose())
+    Asm->OutStreamer.AddComment("Sourcefile string table");
+  Asm->EmitInt32(CodeView::Sourcefile_Table_Section);
+  if (Asm->isVerbose())
+    Asm->OutStreamer.AddComment("Length of data");
+  Asm->EmitInt32(length);
+  if (Asm->isVerbose())
+    Asm->OutStreamer.AddComment("0th filename");
+  Asm->EmitInt8(0);
+
+  for (std::vector<Sourcefile>::const_iterator it = Srcfiles.begin();
+                                               it != Srcfiles.end(); ++it) {
+    const std::string& Filename = (*it).Filename;
+    if (Asm->isVerbose())
+      Asm->OutStreamer.AddComment("Filename");
+    emitStringZ(Filename);
+  }
+  emitPadding(length);
+}
+
+void CodeViewDebug::emitSourcefileInfo(std::vector<Sourcefile> Srcfiles) {
+  // Emit
+  if (Asm->isVerbose())
+    Asm->OutStreamer.AddComment("Sourcefile information");
+  Asm->EmitInt32(CodeView::Sourcefile_Info_Section);
+  if (Asm->isVerbose())
+    Asm->OutStreamer.AddComment("Length of data");
+  Asm->EmitInt32(Srcfiles.size() * 8);
+
+  for (std::vector<Sourcefile>::const_iterator it = Srcfiles.begin(); 
+                                               it != Srcfiles.end(); ++it) {
+    Sourcefile t = *it;
+    if (Asm->isVerbose())
+      Asm->OutStreamer.AddComment("Offset into Sourcefile string table");
+    Asm->EmitInt32(t.Offset);
+    if (Asm->isVerbose())
+      Asm->OutStreamer.AddComment("Checksum");
+    Asm->EmitInt16(0);
+    if (Asm->isVerbose())
+      Asm->OutStreamer.AddComment("Padding");
+    Asm->EmitInt16(0);
+  }
+}
+
+void CodeViewDebug::emitStringZ(const std::string& str) {
+  Asm->OutStreamer.EmitBytes(StringRef(str.c_str(), str.size()+1), 0/*addrspace*/);
+}
+
+void CodeViewDebug::emitPadding(uint32_t length) {
+  if (length % 4) {
+    static const char zero[4] = { 0, 0, 0, 0 };
+
+    if (Asm->isVerbose())
+      Asm->OutStreamer.AddComment("Padding");
+    Asm->OutStreamer.EmitBytes(StringRef(zero, 4-(length%4)), 0/*addrspace*/);
+  }
+}
\ No newline at end of file
diff --git a/lib/CodeGen/AsmPrinter/CodeViewDebug.h b/lib/CodeGen/AsmPrinter/CodeViewDebug.h
new file mode 100644
index 0000000..9603512
--- /dev/null
+++ b/lib/CodeGen/AsmPrinter/CodeViewDebug.h
@@ -0,0 +1,125 @@
+//===-- llvm/CodeGen/DwarfDebug.h - Dwarf Debug Framework ------*- 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 support for writing codeview debug info into asm files.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef CODEGEN_ASMPRINTER_CODEVIEWDEBUG_H__
+#define CODEGEN_ASMPRINTER_CODEVIEWDEBUG_H__
+
+#include "AsmDebug.h"
+#include "llvm/CodeGen/AsmPrinter.h"
+#include "llvm/CodeGen/LexicalScopes.h"
+#include "llvm/DebugInfo.h"
+#include "llvm/MC/MachineLocation.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/FoldingSet.h"
+#include "llvm/ADT/SetVector.h"
+#include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/ADT/StringMap.h"
+#include "llvm/Support/Allocator.h"
+#include "llvm/Support/CodeView.h"
+#include "llvm/Support/DebugLoc.h"
+#include <string>
+#include <vector>
+
+namespace llvm {
+
+class MachineFrameInfo;
+class MachineModuleInfo;
+class MachineOperand;
+class MCAsmInfo;
+
+  // A single type records
+  struct LeafRecord {
+    static LeafRecord *Create(uint16_t LeafType, uint32_t Length) {
+      void *Rec = new uint8_t[Length];
+      return new (Rec) LeafRecord(LeafType, Length);
+    }
+
+    LeafRecord(uint16_t LeafType, uint32_t Length)
+      : Length(Length)
+    {
+      Leaf.Generic.Leaf = LeafType;
+    }
+
+    uint32_t Length;   // Overall Length (not emitted)
+    union CodeView::Leaf Leaf;
+  };
+
+  class TypeStringManager {
+    typedef std::vector<LeafRecord *> LeafVector;
+
+    LeafVector TypesString;
+    uint32_t NextIndex;
+
+  public:
+    TypeStringManager() {}
+
+    // Add a new leaf record, returns index
+    uint16_t Add(LeafRecord *Record);
+    uint32_t Size();
+    void Emit(AsmPrinter *Asm);
+    uint16_t toReservedType(const DIBasicType& type);
+    uint32_t toTypeIdx(const DIType& Type);
+    uint32_t ParameterToTypeIdx(const DIArray& Vars);
+    uint32_t ProcedureToTypeIdx(const DISubprogram& Proc);
+  };
+
+
+struct Sourcefile {
+  std::string Filename;
+  uint32_t Offset;
+
+  Sourcefile(std::string f, uint32_t ofs)
+    : Filename(f), Offset(ofs)
+  {}
+};
+
+class CodeViewDebug : public AsmDebug {
+  TypeStringManager TypeString;
+
+  void emitSourcefileTable(std::vector<Sourcefile> Srcfiles);
+  void emitSourcefileInfo(std::vector<Sourcefile> Srcfiles);
+  void emitPadding(uint32_t length);
+  void emitStringZ(const std::string& str);
+
+public:
+  //===--------------------------------------------------------------------===//
+  // Main entry points.
+  //
+  CodeViewDebug(AsmPrinter *A, Module *M);
+  ~CodeViewDebug();
+
+  /// beginModule - Emit all Dwarf sections that should come prior to the
+  /// content.
+  void beginModule(Module *M);
+
+  /// endModule - Emit all Dwarf sections that should come after the content.
+  ///
+  void endModule();
+
+  /// beginFunction - Gather pre-function debug information.  Assumes being
+  /// emitted immediately after the function entry point.
+  void beginFunction(const MachineFunction *MF);
+
+  /// endFunction - Gather and emit post-function debug information.
+  ///
+  void endFunction(const MachineFunction *MF);
+
+  /// beginInstruction - Process beginning of an instruction.
+  void beginInstruction(const MachineInstr *MI);
+
+  /// endInstruction - Prcess end of an instruction.
+  void endInstruction(const MachineInstr *MI);
+};
+} // End of namespace llvm
+
+#endif
diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index 742a779..76f2fd1 100644
--- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -153,7 +153,7 @@ DIType DbgVariable::getType() const {
 } // end llvm namespace
 
 DwarfDebug::DwarfDebug(AsmPrinter *A, Module *M)
-  : Asm(A), MMI(Asm->MMI), FirstCU(0),
+  : AsmDebug(A), FirstCU(0),
     AbbreviationsSet(InitAbbreviationsSetSize),
     SourceIdMap(DIEValueAllocator), StringPool(DIEValueAllocator),
     PrevLabel(NULL) {
diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.h b/lib/CodeGen/AsmPrinter/DwarfDebug.h
index 1188ffa..d4ad03e 100644
--- a/lib/CodeGen/AsmPrinter/DwarfDebug.h
+++ b/lib/CodeGen/AsmPrinter/DwarfDebug.h
@@ -14,6 +14,7 @@
 #ifndef CODEGEN_ASMPRINTER_DWARFDEBUG_H__
 #define CODEGEN_ASMPRINTER_DWARFDEBUG_H__
 
+#include "AsmDebug.h"
 #include "DIE.h"
 #include "llvm/DebugInfo.h"
 #include "llvm/CodeGen/AsmPrinter.h"
@@ -190,12 +191,7 @@ public:
   DIType getType() const;
 };
 
-class DwarfDebug {
-  /// Asm - Target of Dwarf emission.
-  AsmPrinter *Asm;
-
-  /// MMI - Collected machine module information.
-  MachineModuleInfo *MMI;
+class DwarfDebug : public AsmDebug {
 
   /// DIEValueAllocator - All DIEValues are allocated through this allocator.
   BumpPtrAllocator DIEValueAllocator;
diff --git a/lib/MC/MCAsmInfo.cpp b/lib/MC/MCAsmInfo.cpp
index 7ea0f3b..a5b573f 100644
--- a/lib/MC/MCAsmInfo.cpp
+++ b/lib/MC/MCAsmInfo.cpp
@@ -81,7 +81,7 @@ MCAsmInfo::MCAsmInfo() {
   HiddenDeclarationVisibilityAttr = MCSA_Hidden;
   ProtectedVisibilityAttr = MCSA_Protected;
   HasLEB128 = false;
-  SupportsDebugInformation = false;
+  DebugInformationType = DebugInformation::None;
   ExceptionsType = ExceptionHandling::None;
   DwarfUsesInlineInfoSection = false;
   DwarfSectionOffsetDirective = 0;
diff --git a/lib/MC/MCAsmInfoCOFF.cpp b/lib/MC/MCAsmInfoCOFF.cpp
index fd79193..03ecdcc 100644
--- a/lib/MC/MCAsmInfoCOFF.cpp
+++ b/lib/MC/MCAsmInfoCOFF.cpp
@@ -35,7 +35,7 @@ MCAsmInfoCOFF::MCAsmInfoCOFF() {
 
   // Set up DWARF directives
   HasLEB128 = true;  // Target asm supports leb128 directives (little-endian)
-  SupportsDebugInformation = true;
+  DebugInformationType = DebugInformation::Dwarf;
   DwarfSectionOffsetDirective = "\t.secrel32\t";
   HasMicrosoftFastStdCallMangling = true;
 }
diff --git a/lib/MC/MCObjectFileInfo.cpp b/lib/MC/MCObjectFileInfo.cpp
index 2e1604d..a3c8497 100644
--- a/lib/MC/MCObjectFileInfo.cpp
+++ b/lib/MC/MCObjectFileInfo.cpp
@@ -541,6 +541,18 @@ void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
                         COFF::IMAGE_SCN_MEM_READ |
                         COFF::IMAGE_SCN_MEM_WRITE,
                         SectionKind::getDataRel());
+  CodeViewSymbolInformationSection =
+    Ctx->getCOFFSection(".debug$S",
+                        COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
+                        COFF::IMAGE_SCN_MEM_READ |
+                        COFF::IMAGE_SCN_MEM_DISCARDABLE,
+                        SectionKind::getDataRel());
+  CodeViewTypeInformationSection =
+    Ctx->getCOFFSection(".debug$T",
+                        COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
+                        COFF::IMAGE_SCN_MEM_READ |
+                        COFF::IMAGE_SCN_MEM_DISCARDABLE,
+                        SectionKind::getDataRel());
 }
 
 void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model relocm,
diff --git a/lib/Target/ARM/MCTargetDesc/ARMMCAsmInfo.cpp b/lib/Target/ARM/MCTargetDesc/ARMMCAsmInfo.cpp
index c1aab9c..d522471 100644
--- a/lib/Target/ARM/MCTargetDesc/ARMMCAsmInfo.cpp
+++ b/lib/Target/ARM/MCTargetDesc/ARMMCAsmInfo.cpp
@@ -31,7 +31,7 @@ ARMMCAsmInfoDarwin::ARMMCAsmInfoDarwin() {
   Code32Directive = ".code\t32";
   UseDataRegionDirectives = true;
 
-  SupportsDebugInformation = true;
+  DebugInformationType = DebugInformation::Dwarf;
 
   // Exceptions handling
   ExceptionsType = ExceptionHandling::SjLj;
@@ -52,7 +52,7 @@ ARMELFMCAsmInfo::ARMELFMCAsmInfo() {
   WeakRefDirective = "\t.weak\t";
 
   HasLEB128 = true;
-  SupportsDebugInformation = true;
+  DebugInformationType = DebugInformation::Dwarf;
 
   // Exceptions handling
   if (EnableARMEHABI)
diff --git a/lib/Target/PowerPC/MCTargetDesc/PPCMCAsmInfo.cpp b/lib/Target/PowerPC/MCTargetDesc/PPCMCAsmInfo.cpp
index 215aa40..c679836 100644
--- a/lib/Target/PowerPC/MCTargetDesc/PPCMCAsmInfo.cpp
+++ b/lib/Target/PowerPC/MCTargetDesc/PPCMCAsmInfo.cpp
@@ -29,7 +29,7 @@ PPCMCAsmInfoDarwin::PPCMCAsmInfoDarwin(bool is64Bit) {
     Data64bitsDirective = 0;      // We can't emit a 64-bit unit in PPC32 mode.
 
   AssemblerDialect = 1;           // New-Style mnemonics.
-  SupportsDebugInformation= true; // Debug information.
+  DebugInformationType = DebugInformation::Dwarf; // Debug information.
 }
 
 void PPCLinuxMCAsmInfo::anchor() { }
@@ -51,7 +51,7 @@ PPCLinuxMCAsmInfo::PPCLinuxMCAsmInfo(bool is64Bit) {
   UsesELFSectionDirectiveForBSS = true;  
 
   // Debug Information
-  SupportsDebugInformation = true;
+  DebugInformationType = DebugInformation::Dwarf;
 
   PCSymbol = ".";
 
diff --git a/lib/Target/X86/MCTargetDesc/X86MCAsmInfo.cpp b/lib/Target/X86/MCTargetDesc/X86MCAsmInfo.cpp
index 16488eb..39032ec 100644
--- a/lib/Target/X86/MCTargetDesc/X86MCAsmInfo.cpp
+++ b/lib/Target/X86/MCTargetDesc/X86MCAsmInfo.cpp
@@ -61,7 +61,7 @@ X86MCAsmInfoDarwin::X86MCAsmInfoDarwin(const Triple &T) {
   CommentString = "##";
   PCSymbol = ".";
 
-  SupportsDebugInformation = true;
+  DebugInformationType = DebugInformation::Dwarf;
   DwarfUsesInlineInfoSection = true;
   UseDataRegionDirectives = MarkedJTDataRegions;
 
@@ -91,7 +91,7 @@ X86ELFMCAsmInfo::X86ELFMCAsmInfo(const Triple &T) {
   HasLEB128 = true;  // Target asm supports leb128 directives (little-endian)
 
   // Debug Information
-  SupportsDebugInformation = true;
+  DebugInformationType = DebugInformation::Dwarf;
 
   // Exceptions handling
   ExceptionsType = ExceptionHandling::DwarfCFI;
@@ -131,6 +131,8 @@ X86MCAsmInfoMicrosoft::X86MCAsmInfoMicrosoft(const Triple &Triple) {
   AssemblerDialect = AsmWriterFlavor;
 
   TextAlignFillValue = 0x90;
+
+  DebugInformationType = DebugInformation::CodeView;
 }
 
 void X86MCAsmInfoGNUCOFF::anchor() { }
