Run dos2unix against llvm-pdbdump.
[oota-llvm.git] / tools / llvm-pdbdump / DIAExtras.h
1 //===- DIAExtras.h - Helper classes and functions for accessing DIA C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Defines helper types, classes, and functions for working with DIA.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_TOOLS_LLVMPDBDUMP_DIAEXTRAS_H
15 #define LLVM_TOOLS_LLVMPDBDUMP_DIAEXTRAS_H
16
17 #include "llvm/ADT/SmallString.h"
18 #include "llvm/Support/raw_ostream.h"
19
20 #include "COMExtras.h"
21
22 namespace llvm {
23 namespace sys {
24 namespace windows {
25
26 typedef llvm::SmallString<16> DIAString;
27
28 template <class T> class DIAResult {
29 public:
30   DIAResult() : IsValid(false) {}
31   DIAResult(const T &ResultValue) : Result(ResultValue), IsValid(true) {}
32
33   bool hasValue() const { return IsValid; }
34   T value() const { return Result; }
35
36   void dump(StringRef Name, unsigned IndentLevel) const {
37     if (!hasValue())
38       return;
39     outs().indent(IndentLevel);
40     outs() << Name << ": " << value() << "\n";
41   }
42
43 private:
44   T Result;
45   bool IsValid;
46 };
47
48 template <>
49 void DIAResult<BOOL>::dump(StringRef Name, unsigned IndentLevel) const {
50   if (!hasValue())
51     return;
52   outs().indent(IndentLevel);
53   outs() << Name << ": " << (value() ? "true" : "false") << "\n";
54 }
55
56 template <>
57 void DIAResult<GUID>::dump(StringRef Name, unsigned IndentLevel) const {
58   if (!hasValue())
59     return;
60   std::string Guid8;
61   CComBSTR GuidBSTR(value());
62   BSTRToUTF8(GuidBSTR.m_str, Guid8);
63
64   outs().indent(IndentLevel);
65   outs() << Name << ": " << Guid8 << "\n";
66 }
67
68 // MSDN documents the IDiaSymbol::get_machineType method as returning a value
69 // from the CV_CPU_TYPE_e enumeration.  This documentation is wrong, however,
70 // and this method actually returns a value from the IMAGE_FILE_xxx set of
71 // defines from winnt.h.  These correspond to the platform magic number in
72 // the COFF file.  This enumeration is built from the set of values in winnt.h
73 enum MachineTypeEnum {
74   MachineTypeUnknown = IMAGE_FILE_MACHINE_UNKNOWN,
75   MachineTypeX86 = IMAGE_FILE_MACHINE_I386,
76   MachineTypeR3000 = IMAGE_FILE_MACHINE_R3000,
77   MachineTypeR4000 = IMAGE_FILE_MACHINE_R4000,
78   MachineTypeR10000 = IMAGE_FILE_MACHINE_R10000,
79   MachineTypeWCEMIPSv2 = IMAGE_FILE_MACHINE_WCEMIPSV2,
80   MachineTypeAlpha = IMAGE_FILE_MACHINE_ALPHA,
81   MachineTypeSH3 = IMAGE_FILE_MACHINE_SH3,
82   MachineTypeSH3DSP = IMAGE_FILE_MACHINE_SH3DSP,
83   MachineTypeSH3E = IMAGE_FILE_MACHINE_SH3E,
84   MachineTypeSH4 = IMAGE_FILE_MACHINE_SH4,
85   MachineTypeSH5 = IMAGE_FILE_MACHINE_SH5,
86   MachineTypeArm = IMAGE_FILE_MACHINE_ARM,
87   MachineTypeThumb = IMAGE_FILE_MACHINE_THUMB,
88   MachineTypeArmNT = IMAGE_FILE_MACHINE_ARMNT,
89   MachineTypeAM33 = IMAGE_FILE_MACHINE_AM33,
90   MachineTypePowerPC = IMAGE_FILE_MACHINE_POWERPC,
91   MachineTypePowerPCFP = IMAGE_FILE_MACHINE_POWERPCFP,
92   MachineTypeIa64 = IMAGE_FILE_MACHINE_IA64,
93   MachineTypeMips16 = IMAGE_FILE_MACHINE_MIPS16,
94   MachineTypeAlpha64 = IMAGE_FILE_MACHINE_ALPHA64,
95   MachineTypeMipsFpu = IMAGE_FILE_MACHINE_MIPSFPU,
96   MachineTypeMipsFpu16 = IMAGE_FILE_MACHINE_MIPSFPU16,
97   MachineTypeTriCore = IMAGE_FILE_MACHINE_TRICORE,
98   MachineTypeCEF = IMAGE_FILE_MACHINE_CEF,
99   MachineTypeEBC = IMAGE_FILE_MACHINE_EBC,
100   MachineTypeAmd64 = IMAGE_FILE_MACHINE_AMD64,
101   MachineTypeM32R = IMAGE_FILE_MACHINE_M32R,
102   MachineTypeCEE = IMAGE_FILE_MACHINE_CEE,
103 };
104
105 // SymTagEnum has the unfortunate property that it is not only the name of
106 // the enum, but also the name of one of the values of the enum.  So that we
107 // don't have to always type "enum SymTagEnum", we typedef this to a different
108 // name so that we can refer to it more easily.
109 typedef enum SymTagEnum DiaSymTagEnum;
110
111 typedef CComPtr<IDiaSymbol> DiaSymbolPtr;
112
113 } // namespace windows
114 } // namespace sys
115 } // namespace llvm
116
117 namespace llvm {
118 class raw_ostream;
119
120 raw_ostream &operator<<(raw_ostream &Stream,
121                         llvm::sys::windows::DiaSymTagEnum SymTag);
122 raw_ostream &operator<<(raw_ostream &Stream, CV_CPU_TYPE_e CpuType);
123 raw_ostream &operator<<(raw_ostream &Stream,
124                         llvm::sys::windows::MachineTypeEnum CpuType);
125 }
126
127 #endif