[llvm] r270239 - [obj2yaml][yaml2obj] Adding enumFallback for MachO load commands
Chris Bieneman via llvm-commits
llvm-commits at lists.llvm.org
Fri May 20 10:20:42 PDT 2016
Author: cbieneman
Date: Fri May 20 12:20:42 2016
New Revision: 270239
URL: http://llvm.org/viewvc/llvm-project?rev=270239&view=rev
Log:
[obj2yaml][yaml2obj] Adding enumFallback for MachO load commands
This adds support for handling unknown load commands, and a bogus_load_command tests.
Unknown or unsupported load commands can be specified in YAML by their hex value.
Added:
llvm/trunk/test/ObjectYAML/MachO/bogus_load_command.yaml
Modified:
llvm/trunk/include/llvm/ObjectYAML/MachOYAML.h
llvm/trunk/include/llvm/Support/YAMLTraits.h
Modified: llvm/trunk/include/llvm/ObjectYAML/MachOYAML.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ObjectYAML/MachOYAML.h?rev=270239&r1=270238&r2=270239&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ObjectYAML/MachOYAML.h (original)
+++ llvm/trunk/include/llvm/ObjectYAML/MachOYAML.h Fri May 20 12:20:42 2016
@@ -95,6 +95,7 @@ template <> struct MappingTraits<MachOYA
template <> struct ScalarEnumerationTraits<MachO::LoadCommandType> {
static void enumeration(IO &io, MachO::LoadCommandType &value) {
#include "llvm/Support/MachO.def"
+ io.enumFallback<Hex32>(value);
}
};
Modified: llvm/trunk/include/llvm/Support/YAMLTraits.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/YAMLTraits.h?rev=270239&r1=270238&r2=270239&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/YAMLTraits.h (original)
+++ llvm/trunk/include/llvm/Support/YAMLTraits.h Fri May 20 12:20:42 2016
@@ -510,11 +510,11 @@ public:
template <typename FBT, typename T>
void enumFallback(T &Val) {
- if ( matchEnumFallback() ) {
+ if (matchEnumFallback()) {
// FIXME: Force integral conversion to allow strong typedefs to convert.
- FBT Res = (uint64_t)Val;
+ FBT Res = static_cast<typename FBT::BaseType>(Val);
yamlize(*this, Res, true);
- Val = (uint64_t)Res;
+ Val = static_cast<T>(static_cast<typename FBT::BaseType>(Res));
}
}
@@ -1168,6 +1168,7 @@ private:
bool operator==(const _base &rhs) const { return value == rhs; } \
bool operator<(const _type &rhs) const { return value < rhs.value; } \
_base value; \
+ typedef _base BaseType; \
};
///
Added: llvm/trunk/test/ObjectYAML/MachO/bogus_load_command.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ObjectYAML/MachO/bogus_load_command.yaml?rev=270239&view=auto
==============================================================================
--- llvm/trunk/test/ObjectYAML/MachO/bogus_load_command.yaml (added)
+++ llvm/trunk/test/ObjectYAML/MachO/bogus_load_command.yaml Fri May 20 12:20:42 2016
@@ -0,0 +1,51 @@
+# RUN: yaml2obj -format=macho %s | obj2yaml | FileCheck %s
+
+--- !mach-o
+FileHeader:
+ magic: 0xFEEDFACF
+ cputype: 0x01000007
+ cpusubtype: 0x80000003
+ filetype: 0x00000002
+ ncmds: 2
+ sizeofcmds: 56
+ flags: 0x00218085
+ reserved: 0x00000000
+LoadCommands:
+ - cmd: 0xDEADBEEF
+ cmdsize: 32
+ ZeroPadBytes: 24
+ - cmd: 0xDEADBEEF
+ cmdsize: 24
+ PayloadBytes:
+ - 0x01
+ - 0x02
+ - 0x03
+ - 0x04
+ - 0x05
+ - 0x06
+ - 0x07
+ - 0x08
+ - 0x09
+ - 0x0A
+ - 0x0B
+ - 0x0C
+...
+
+#CHECK: - cmd: 0xDEADBEEF
+#CHECK: cmdsize: 32
+#CHECK: ZeroPadBytes:
+#CHECK: - cmd: 0xDEADBEEF
+#CHECK: cmdsize: 24
+#CHECK: PayloadBytes:
+#CHECK: - 0x01
+#CHECK: - 0x02
+#CHECK: - 0x03
+#CHECK: - 0x04
+#CHECK: - 0x05
+#CHECK: - 0x06
+#CHECK: - 0x07
+#CHECK: - 0x08
+#CHECK: - 0x09
+#CHECK: - 0x0A
+#CHECK: - 0x0B
+#CHECK: - 0x0C
More information about the llvm-commits
mailing list