[lld] r193478 - [PECOFF] Add COFF relocations to encode/decode to/from YAML files

Shankar Easwaran shankare at codeaurora.org
Sat Oct 26 12:38:31 PDT 2013


Author: shankare
Date: Sat Oct 26 14:38:31 2013
New Revision: 193478

URL: http://llvm.org/viewvc/llvm-project?rev=193478&view=rev
Log:
[PECOFF] Add COFF relocations to encode/decode to/from YAML files

Modified:
    lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp

Modified: lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp?rev=193478&r1=193477&r2=193478&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp Sat Oct 26 14:38:31 2013
@@ -172,13 +172,35 @@ StringRef PECOFFLinkingContext::searchLi
 
 Writer &PECOFFLinkingContext::writer() const { return *_writer; }
 
+#define LLD_CASE(name) .Case(#name, llvm::COFF::name)
+
 ErrorOr<Reference::Kind>
 PECOFFLinkingContext::relocKindFromString(StringRef str) const {
-  return make_error_code(YamlReaderError::illegal_value);
+  int32_t ret = llvm::StringSwitch<int32_t>(str)
+        LLD_CASE(IMAGE_REL_I386_ABSOLUTE)
+        LLD_CASE(IMAGE_REL_I386_DIR32)
+        LLD_CASE(IMAGE_REL_I386_DIR32NB)
+        LLD_CASE(IMAGE_REL_I386_REL32)
+        .Default(-1);
+  if (ret == -1)
+    return make_error_code(YamlReaderError::illegal_value);
+  return ret;
 }
 
+#undef LLD_CASE
+
+#define LLD_CASE(name)                                                         \
+  case llvm::COFF::name:                                                        \
+  return std::string(#name);
+
 ErrorOr<std::string>
 PECOFFLinkingContext::stringFromRelocKind(Reference::Kind kind) const {
+  switch (kind) {
+    LLD_CASE(IMAGE_REL_I386_ABSOLUTE)
+    LLD_CASE(IMAGE_REL_I386_DIR32)
+    LLD_CASE(IMAGE_REL_I386_DIR32NB)
+    LLD_CASE(IMAGE_REL_I386_REL32)
+  }
   return make_error_code(YamlReaderError::illegal_value);
 }
 





More information about the llvm-commits mailing list