[llvm] r183349 - Add BinaryRef binary_size() method.
Sean Silva
silvas at purdue.edu
Wed Jun 5 16:32:27 PDT 2013
Author: silvas
Date: Wed Jun 5 18:32:27 2013
New Revision: 183349
URL: http://llvm.org/viewvc/llvm-project?rev=183349&view=rev
Log:
Add BinaryRef binary_size() method.
This avoids making assumptions about the data representation.
Modified:
llvm/trunk/include/llvm/Object/YAML.h
llvm/trunk/tools/yaml2obj/yaml2coff.cpp
Modified: llvm/trunk/include/llvm/Object/YAML.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/YAML.h?rev=183349&r1=183348&r2=183349&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/YAML.h (original)
+++ llvm/trunk/include/llvm/Object/YAML.h Wed Jun 5 18:32:27 2013
@@ -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())
Modified: llvm/trunk/tools/yaml2obj/yaml2coff.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/yaml2obj/yaml2coff.cpp?rev=183349&r1=183348&r2=183349&view=diff
==============================================================================
--- llvm/trunk/tools/yaml2obj/yaml2coff.cpp (original)
+++ llvm/trunk/tools/yaml2obj/yaml2coff.cpp Wed Jun 5 18:32:27 2013
@@ -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;
More information about the llvm-commits
mailing list