summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Silva <silvas@purdue.edu>2013-06-05 23:32:27 +0000
committerSean Silva <silvas@purdue.edu>2013-06-05 23:32:27 +0000
commit63958fba58716ed435563321944f7d4663d2ee2d (patch)
tree5670637b121f3e1bfa1c4d5230a3f98e8df61e9b
parent2b1068952ade3a1d2c704e7589c54e3d32dc0eb8 (diff)
downloadllvm-63958fba58716ed435563321944f7d4663d2ee2d.tar.gz
llvm-63958fba58716ed435563321944f7d4663d2ee2d.tar.bz2
llvm-63958fba58716ed435563321944f7d4663d2ee2d.tar.xz
Add BinaryRef binary_size() method.
This avoids making assumptions about the data representation. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183349 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Object/YAML.h7
-rw-r--r--tools/yaml2obj/yaml2coff.cpp7
2 files changed, 10 insertions, 4 deletions
diff --git a/include/llvm/Object/YAML.h b/include/llvm/Object/YAML.h
index e6f1da1e1d..92811b04eb 100644
--- a/include/llvm/Object/YAML.h
+++ b/include/llvm/Object/YAML.h
@@ -43,6 +43,13 @@ public:
assert(isBinary);
return Data;
}
+ /// \brief The number of bytes that are represented by this BinaryRef.
+ /// This is the number of bytes that writeAsBinary() will write.
+ ArrayRef<uint8_t>::size_type binary_size() const {
+ if (!isBinary)
+ return Data.size() / 2;
+ return Data.size();
+ }
bool operator==(const BinaryRef &Ref) {
// Special case for default constructed BinaryRef.
if (Ref.Data.empty() && Data.empty())
diff --git a/tools/yaml2obj/yaml2coff.cpp b/tools/yaml2obj/yaml2coff.cpp
index 5b758471bd..d800b90791 100644
--- a/tools/yaml2obj/yaml2coff.cpp
+++ b/tools/yaml2obj/yaml2coff.cpp
@@ -129,9 +129,8 @@ static bool layoutCOFF(COFFParser &CP) {
for (std::vector<COFFYAML::Section>::iterator i = CP.Obj.Sections.begin(),
e = CP.Obj.Sections.end();
i != e; ++i) {
- StringRef SecData = i->SectionData.getHex();
- if (!SecData.empty()) {
- i->Header.SizeOfRawData = SecData.size()/2;
+ if (i->SectionData.binary_size() > 0) {
+ i->Header.SizeOfRawData = i->SectionData.binary_size();
i->Header.PointerToRawData = CurrentSectionDataOffset;
CurrentSectionDataOffset += i->Header.SizeOfRawData;
if (!i->Relocations.empty()) {
@@ -154,7 +153,7 @@ static bool layoutCOFF(COFFParser &CP) {
for (std::vector<COFFYAML::Symbol>::iterator i = CP.Obj.Symbols.begin(),
e = CP.Obj.Symbols.end();
i != e; ++i) {
- unsigned AuxBytes = i->AuxiliaryData.getHex().size() / 2;
+ unsigned AuxBytes = i->AuxiliaryData.binary_size();
if (AuxBytes % COFF::SymbolSize != 0) {
errs() << "AuxiliaryData size not a multiple of symbol size!\n";
return false;