diff options
author | Frederic Riss <friss@apple.com> | 2015-03-04 22:07:41 +0000 |
---|---|---|
committer | Frederic Riss <friss@apple.com> | 2015-03-04 22:07:41 +0000 |
commit | 77f850e3368f4f33dcab2067b98fab8a22beedcf (patch) | |
tree | 88fa9b6035a0b63e8abd52b980ef637f9c6b824c /llvm/lib/DebugInfo/DWARF/DWARFFormValue.cpp | |
parent | ee17fb9b0ebbfcd579cf2d95caff9a53ceffe06e (diff) | |
download | bcm5719-llvm-77f850e3368f4f33dcab2067b98fab8a22beedcf.tar.gz bcm5719-llvm-77f850e3368f4f33dcab2067b98fab8a22beedcf.zip |
DWARFFormValue: Add getAsSignedConstant method.
The implementation accepts explicitely signed forms (DW_FORM_sdata),
but also unsigned forms as long as they fit in an int64_t.
llvm-svn: 231299
Diffstat (limited to 'llvm/lib/DebugInfo/DWARF/DWARFFormValue.cpp')
-rw-r--r-- | llvm/lib/DebugInfo/DWARF/DWARFFormValue.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFFormValue.cpp b/llvm/lib/DebugInfo/DWARF/DWARFFormValue.cpp index 45bd1973a76..6946f833424 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFFormValue.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFFormValue.cpp @@ -18,6 +18,7 @@ #include "llvm/Support/Format.h" #include "llvm/Support/raw_ostream.h" #include <cassert> +#include <climits> using namespace llvm; using namespace dwarf; using namespace syntax; @@ -557,6 +558,24 @@ Optional<uint64_t> DWARFFormValue::getAsUnsignedConstant() const { return Value.uval; } +Optional<int64_t> DWARFFormValue::getAsSignedConstant() const { + if ((!isFormClass(FC_Constant) && !isFormClass(FC_Flag)) || + (Form == DW_FORM_udata && uint64_t(LLONG_MAX) < Value.uval)) + return None; + switch (Form) { + case DW_FORM_data4: + return int32_t(Value.uval); + case DW_FORM_data2: + return int16_t(Value.uval); + case DW_FORM_data1: + return int8_t(Value.uval); + case DW_FORM_sdata: + case DW_FORM_data8: + default: + return Value.sval; + } +} + Optional<ArrayRef<uint8_t>> DWARFFormValue::getAsBlock() const { if (!isFormClass(FC_Block) && !isFormClass(FC_Exprloc)) return None; |