[PATCH] [PECOFF] Fix Reference <-> String conversion.
Rui Ueyama
ruiu at google.com
Fri Oct 25 14:26:57 PDT 2013
This patch fixes most of the tests failing with YAML round-trip pass, by making
COFF references serializable. Some tests are still failing. I'll address them
in a different patch.
http://llvm-reviews.chandlerc.com/D2028
Files:
lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp
Index: lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp
===================================================================
--- lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp
+++ lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp
@@ -14,6 +14,7 @@
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/Allocator.h"
+#include "llvm/Support/COFF.h"
#include "llvm/Support/Path.h"
#include "lld/Core/PassManager.h"
#include "lld/Passes/LayoutPass.h"
@@ -121,11 +122,45 @@
ErrorOr<Reference::Kind>
PECOFFLinkingContext::relocKindFromString(StringRef str) const {
- return make_error_code(YamlReaderError::illegal_value);
+#define CASE(name) Case(#name, llvm::COFF::name)
+ int32_t ret = llvm::StringSwitch<int32_t>(str)
+ .CASE(IMAGE_REL_I386_ABSOLUTE)
+ .CASE(IMAGE_REL_I386_DIR16)
+ .CASE(IMAGE_REL_I386_REL16)
+ .CASE(IMAGE_REL_I386_DIR32)
+ .CASE(IMAGE_REL_I386_DIR32NB)
+ .CASE(IMAGE_REL_I386_SEG12)
+ .CASE(IMAGE_REL_I386_SECTION)
+ .CASE(IMAGE_REL_I386_SECREL)
+ .CASE(IMAGE_REL_I386_TOKEN)
+ .CASE(IMAGE_REL_I386_SECREL7)
+ .CASE(IMAGE_REL_I386_REL32)
+ .Default(-1);
+#undef CASE
+ if (ret == -1)
+ return make_error_code(YamlReaderError::illegal_value);
+ return ret;
}
ErrorOr<std::string>
PECOFFLinkingContext::stringFromRelocKind(Reference::Kind kind) const {
+ switch (kind) {
+#define CASE(name) \
+ case llvm::COFF::name: \
+ return std::string(#name)
+ CASE(IMAGE_REL_I386_ABSOLUTE);
+ CASE(IMAGE_REL_I386_DIR16);
+ CASE(IMAGE_REL_I386_REL16);
+ CASE(IMAGE_REL_I386_DIR32);
+ CASE(IMAGE_REL_I386_DIR32NB);
+ CASE(IMAGE_REL_I386_SEG12);
+ CASE(IMAGE_REL_I386_SECTION);
+ CASE(IMAGE_REL_I386_SECREL);
+ CASE(IMAGE_REL_I386_TOKEN);
+ CASE(IMAGE_REL_I386_SECREL7);
+ CASE(IMAGE_REL_I386_REL32);
+#undef CASE
+ }
return make_error_code(YamlReaderError::illegal_value);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2028.1.patch
Type: text/x-patch
Size: 1936 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131025/93c0b843/attachment.bin>
More information about the llvm-commits
mailing list