f92d5a98cef5a74d9cdccaed11fcda923ec04406
[oota-llvm.git] / include / llvm / DebugInfo / DWARFFormValue.h
1 //===-- DWARFFormValue.h ----------------------------------------*- 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 #ifndef LLVM_DEBUGINFO_DWARFFORMVALUE_H
11 #define LLVM_DEBUGINFO_DWARFFORMVALUE_H
12
13 #include "llvm/Support/DataExtractor.h"
14
15 namespace llvm {
16
17 class DWARFUnit;
18 class raw_ostream;
19
20 class DWARFFormValue {
21 public:
22   struct ValueType {
23     ValueType() : data(NULL), IsDWOIndex(false) {
24       uval = 0;
25     }
26
27     union {
28       uint64_t uval;
29       int64_t sval;
30       const char* cstr;
31     };
32     const uint8_t* data;
33     bool IsDWOIndex;
34   };
35
36   enum {
37     eValueTypeInvalid = 0,
38     eValueTypeUnsigned,
39     eValueTypeSigned,
40     eValueTypeCStr,
41     eValueTypeBlock
42   };
43
44 private:
45   uint16_t Form;   // Form for this value.
46   ValueType Value; // Contains all data for the form.
47
48 public:
49   DWARFFormValue(uint16_t form = 0) : Form(form) {}
50   uint16_t getForm() const { return Form; }
51   const ValueType& value() const { return Value; }
52   void dump(raw_ostream &OS, const DWARFUnit *U) const;
53   bool extractValue(DataExtractor data, uint32_t *offset_ptr,
54                     const DWARFUnit *u);
55   bool isInlinedCStr() const {
56     return Value.data != NULL && Value.data == (const uint8_t*)Value.cstr;
57   }
58   const uint8_t *BlockData() const;
59   uint64_t getReference(const DWARFUnit *U) const;
60
61   uint64_t getUnsigned() const { return Value.uval; }
62   int64_t getSigned() const { return Value.sval; }
63   const char *getAsCString(const DWARFUnit *U) const;
64   uint64_t getAsAddress(const DWARFUnit *U) const;
65   bool skipValue(DataExtractor debug_info_data, uint32_t *offset_ptr,
66                  const DWARFUnit *u) const;
67   static bool skipValue(uint16_t form, DataExtractor debug_info_data,
68                         uint32_t *offset_ptr, const DWARFUnit *u);
69   static bool isBlockForm(uint16_t form);
70   static bool isDataForm(uint16_t form);
71   static const uint8_t *getFixedFormSizes(uint8_t AddrSize, uint16_t Version);
72 };
73
74 }
75
76 #endif