[lld] r210974 - llvm::sys::SwapByteOrder() renamed to llvm::sys::getSwappedBytes()

Artyom Skrobov Artyom.Skrobov at arm.com
Sat Jun 14 05:14:26 PDT 2014


Author: askrobov
Date: Sat Jun 14 07:14:25 2014
New Revision: 210974

URL: http://llvm.org/viewvc/llvm-project?rev=210974&view=rev
Log:
llvm::sys::SwapByteOrder() renamed to llvm::sys::getSwappedBytes()

Further to this, llvm::sys::swapByteOrder() will be added, acting in-place


Modified:
    lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryUtils.h

Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryUtils.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryUtils.h?rev=210974&r1=210973&r2=210974&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryUtils.h (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryUtils.h Sat Jun 14 07:14:25 2014
@@ -25,169 +25,169 @@ namespace lld {
 namespace mach_o {
 namespace normalized {
 
-using llvm::sys::SwapByteOrder;
+using llvm::sys::getSwappedBytes;
 
 inline void swapStruct(llvm::MachO::mach_header &mh) {
-  mh.magic      = SwapByteOrder(mh.magic);
-  mh.cputype    = SwapByteOrder(mh.cputype);
-  mh.cpusubtype = SwapByteOrder(mh.cpusubtype);
-  mh.filetype   = SwapByteOrder(mh.filetype);
-  mh.ncmds      = SwapByteOrder(mh.ncmds);
-  mh.sizeofcmds = SwapByteOrder(mh.sizeofcmds);
-  mh.flags      = SwapByteOrder(mh.flags);
+  mh.magic      = getSwappedBytes(mh.magic);
+  mh.cputype    = getSwappedBytes(mh.cputype);
+  mh.cpusubtype = getSwappedBytes(mh.cpusubtype);
+  mh.filetype   = getSwappedBytes(mh.filetype);
+  mh.ncmds      = getSwappedBytes(mh.ncmds);
+  mh.sizeofcmds = getSwappedBytes(mh.sizeofcmds);
+  mh.flags      = getSwappedBytes(mh.flags);
 }
 
 inline void swapStruct(llvm::MachO::load_command &lc) {
-  lc.cmd      = SwapByteOrder(lc.cmd);
-  lc.cmdsize  = SwapByteOrder(lc.cmdsize);
+  lc.cmd      = getSwappedBytes(lc.cmd);
+  lc.cmdsize  = getSwappedBytes(lc.cmdsize);
 }
 
 inline void swapStruct(llvm::MachO::symtab_command &lc) {
-  lc.cmd      = SwapByteOrder(lc.cmd);
-  lc.cmdsize  = SwapByteOrder(lc.cmdsize);
-  lc.symoff   = SwapByteOrder(lc.symoff);
-  lc.nsyms    = SwapByteOrder(lc.nsyms);
-  lc.stroff   = SwapByteOrder(lc.stroff);
-  lc.strsize  = SwapByteOrder(lc.strsize);
+  lc.cmd      = getSwappedBytes(lc.cmd);
+  lc.cmdsize  = getSwappedBytes(lc.cmdsize);
+  lc.symoff   = getSwappedBytes(lc.symoff);
+  lc.nsyms    = getSwappedBytes(lc.nsyms);
+  lc.stroff   = getSwappedBytes(lc.stroff);
+  lc.strsize  = getSwappedBytes(lc.strsize);
 }
 
 inline void swapStruct(llvm::MachO::segment_command_64 &seg) {
-  seg.cmd      = SwapByteOrder(seg.cmd);
-  seg.cmdsize  = SwapByteOrder(seg.cmdsize);
-  seg.vmaddr   = SwapByteOrder(seg.vmaddr);
-  seg.vmsize   = SwapByteOrder(seg.vmsize);
-  seg.fileoff  = SwapByteOrder(seg.fileoff);
-  seg.filesize = SwapByteOrder(seg.filesize);
-  seg.maxprot  = SwapByteOrder(seg.maxprot);
-  seg.initprot = SwapByteOrder(seg.initprot);
-  seg.nsects   = SwapByteOrder(seg.nsects);
-  seg.flags    = SwapByteOrder(seg.flags);
+  seg.cmd      = getSwappedBytes(seg.cmd);
+  seg.cmdsize  = getSwappedBytes(seg.cmdsize);
+  seg.vmaddr   = getSwappedBytes(seg.vmaddr);
+  seg.vmsize   = getSwappedBytes(seg.vmsize);
+  seg.fileoff  = getSwappedBytes(seg.fileoff);
+  seg.filesize = getSwappedBytes(seg.filesize);
+  seg.maxprot  = getSwappedBytes(seg.maxprot);
+  seg.initprot = getSwappedBytes(seg.initprot);
+  seg.nsects   = getSwappedBytes(seg.nsects);
+  seg.flags    = getSwappedBytes(seg.flags);
 }
 
 inline void swapStruct(llvm::MachO::segment_command &seg) {
-  seg.cmd      = SwapByteOrder(seg.cmd);
-  seg.cmdsize  = SwapByteOrder(seg.cmdsize);
-  seg.vmaddr   = SwapByteOrder(seg.vmaddr);
-  seg.vmsize   = SwapByteOrder(seg.vmsize);
-  seg.fileoff  = SwapByteOrder(seg.fileoff);
-  seg.filesize = SwapByteOrder(seg.filesize);
-  seg.maxprot  = SwapByteOrder(seg.maxprot);
-  seg.initprot = SwapByteOrder(seg.initprot);
-  seg.nsects   = SwapByteOrder(seg.nsects);
-  seg.flags    = SwapByteOrder(seg.flags);
+  seg.cmd      = getSwappedBytes(seg.cmd);
+  seg.cmdsize  = getSwappedBytes(seg.cmdsize);
+  seg.vmaddr   = getSwappedBytes(seg.vmaddr);
+  seg.vmsize   = getSwappedBytes(seg.vmsize);
+  seg.fileoff  = getSwappedBytes(seg.fileoff);
+  seg.filesize = getSwappedBytes(seg.filesize);
+  seg.maxprot  = getSwappedBytes(seg.maxprot);
+  seg.initprot = getSwappedBytes(seg.initprot);
+  seg.nsects   = getSwappedBytes(seg.nsects);
+  seg.flags    = getSwappedBytes(seg.flags);
 }
 
 inline void swapStruct(llvm::MachO::section_64 &sect) {
-  sect.addr      = SwapByteOrder(sect.addr);
-  sect.size      = SwapByteOrder(sect.size);
-  sect.offset    = SwapByteOrder(sect.offset);
-  sect.align     = SwapByteOrder(sect.align);
-  sect.reloff    = SwapByteOrder(sect.reloff);
-  sect.nreloc    = SwapByteOrder(sect.nreloc);
-  sect.flags     = SwapByteOrder(sect.flags);
-  sect.reserved1 = SwapByteOrder(sect.reserved1);
-  sect.reserved2 = SwapByteOrder(sect.reserved2);
+  sect.addr      = getSwappedBytes(sect.addr);
+  sect.size      = getSwappedBytes(sect.size);
+  sect.offset    = getSwappedBytes(sect.offset);
+  sect.align     = getSwappedBytes(sect.align);
+  sect.reloff    = getSwappedBytes(sect.reloff);
+  sect.nreloc    = getSwappedBytes(sect.nreloc);
+  sect.flags     = getSwappedBytes(sect.flags);
+  sect.reserved1 = getSwappedBytes(sect.reserved1);
+  sect.reserved2 = getSwappedBytes(sect.reserved2);
 }
 
 inline void swapStruct(llvm::MachO::section &sect) {
-  sect.addr      = SwapByteOrder(sect.addr);
-  sect.size      = SwapByteOrder(sect.size);
-  sect.offset    = SwapByteOrder(sect.offset);
-  sect.align     = SwapByteOrder(sect.align);
-  sect.reloff    = SwapByteOrder(sect.reloff);
-  sect.nreloc    = SwapByteOrder(sect.nreloc);
-  sect.flags     = SwapByteOrder(sect.flags);
-  sect.reserved1 = SwapByteOrder(sect.reserved1);
-  sect.reserved2 = SwapByteOrder(sect.reserved2);
+  sect.addr      = getSwappedBytes(sect.addr);
+  sect.size      = getSwappedBytes(sect.size);
+  sect.offset    = getSwappedBytes(sect.offset);
+  sect.align     = getSwappedBytes(sect.align);
+  sect.reloff    = getSwappedBytes(sect.reloff);
+  sect.nreloc    = getSwappedBytes(sect.nreloc);
+  sect.flags     = getSwappedBytes(sect.flags);
+  sect.reserved1 = getSwappedBytes(sect.reserved1);
+  sect.reserved2 = getSwappedBytes(sect.reserved2);
 }
 
 inline void swapStruct(llvm::MachO::dyld_info_command &info) {
-  info.cmd            = SwapByteOrder(info.cmd);
-  info.cmdsize        = SwapByteOrder(info.cmdsize);
-  info.rebase_off     = SwapByteOrder(info.rebase_off);
-  info.rebase_size    = SwapByteOrder(info.rebase_size);
-  info.bind_off       = SwapByteOrder(info.bind_off);
-  info.bind_size      = SwapByteOrder(info.bind_size);
-  info.weak_bind_off  = SwapByteOrder(info.weak_bind_off);
-  info.weak_bind_size = SwapByteOrder(info.weak_bind_size);
-  info.lazy_bind_off  = SwapByteOrder(info.lazy_bind_off);
-  info.lazy_bind_size = SwapByteOrder(info.lazy_bind_size);
-  info.export_off     = SwapByteOrder(info.export_off);
-  info.export_size    = SwapByteOrder(info.export_size);
+  info.cmd            = getSwappedBytes(info.cmd);
+  info.cmdsize        = getSwappedBytes(info.cmdsize);
+  info.rebase_off     = getSwappedBytes(info.rebase_off);
+  info.rebase_size    = getSwappedBytes(info.rebase_size);
+  info.bind_off       = getSwappedBytes(info.bind_off);
+  info.bind_size      = getSwappedBytes(info.bind_size);
+  info.weak_bind_off  = getSwappedBytes(info.weak_bind_off);
+  info.weak_bind_size = getSwappedBytes(info.weak_bind_size);
+  info.lazy_bind_off  = getSwappedBytes(info.lazy_bind_off);
+  info.lazy_bind_size = getSwappedBytes(info.lazy_bind_size);
+  info.export_off     = getSwappedBytes(info.export_off);
+  info.export_size    = getSwappedBytes(info.export_size);
 }
 
 inline void swapStruct(llvm::MachO::dylib_command &d) {
-  d.cmd                         = SwapByteOrder(d.cmd);
-  d.cmdsize                     = SwapByteOrder(d.cmdsize);
-  d.dylib.name                  = SwapByteOrder(d.dylib.name);
-  d.dylib.timestamp             = SwapByteOrder(d.dylib.timestamp);
-  d.dylib.current_version       = SwapByteOrder(d.dylib.current_version);
-  d.dylib.compatibility_version = SwapByteOrder(d.dylib.compatibility_version);
+  d.cmd                         = getSwappedBytes(d.cmd);
+  d.cmdsize                     = getSwappedBytes(d.cmdsize);
+  d.dylib.name                  = getSwappedBytes(d.dylib.name);
+  d.dylib.timestamp             = getSwappedBytes(d.dylib.timestamp);
+  d.dylib.current_version       = getSwappedBytes(d.dylib.current_version);
+  d.dylib.compatibility_version = getSwappedBytes(d.dylib.compatibility_version);
 }
 
 inline void swapStruct(llvm::MachO::dylinker_command &d) {
-  d.cmd       = SwapByteOrder(d.cmd);
-  d.cmdsize   = SwapByteOrder(d.cmdsize);
-  d.name      = SwapByteOrder(d.name);
+  d.cmd       = getSwappedBytes(d.cmd);
+  d.cmdsize   = getSwappedBytes(d.cmdsize);
+  d.name      = getSwappedBytes(d.name);
 }
 
 inline void swapStruct(llvm::MachO::entry_point_command &e) {
-  e.cmd        = SwapByteOrder(e.cmd);
-  e.cmdsize    = SwapByteOrder(e.cmdsize);
-  e.entryoff   = SwapByteOrder(e.entryoff);
-  e.stacksize  = SwapByteOrder(e.stacksize);
+  e.cmd        = getSwappedBytes(e.cmd);
+  e.cmdsize    = getSwappedBytes(e.cmdsize);
+  e.entryoff   = getSwappedBytes(e.entryoff);
+  e.stacksize  = getSwappedBytes(e.stacksize);
 }
 
 inline void swapStruct(llvm::MachO::dysymtab_command &dst) {
-  dst.cmd             = SwapByteOrder(dst.cmd);
-  dst.cmdsize         = SwapByteOrder(dst.cmdsize);
-  dst.ilocalsym       = SwapByteOrder(dst.ilocalsym);
-  dst.nlocalsym       = SwapByteOrder(dst.nlocalsym);
-  dst.iextdefsym      = SwapByteOrder(dst.iextdefsym);
-  dst.nextdefsym      = SwapByteOrder(dst.nextdefsym);
-  dst.iundefsym       = SwapByteOrder(dst.iundefsym);
-  dst.nundefsym       = SwapByteOrder(dst.nundefsym);
-  dst.tocoff          = SwapByteOrder(dst.tocoff);
-  dst.ntoc            = SwapByteOrder(dst.ntoc);
-  dst.modtaboff       = SwapByteOrder(dst.modtaboff);
-  dst.nmodtab         = SwapByteOrder(dst.nmodtab);
-  dst.extrefsymoff    = SwapByteOrder(dst.extrefsymoff);
-  dst.nextrefsyms     = SwapByteOrder(dst.nextrefsyms);
-  dst.indirectsymoff  = SwapByteOrder(dst.indirectsymoff);
-  dst.nindirectsyms   = SwapByteOrder(dst.nindirectsyms);
-  dst.extreloff       = SwapByteOrder(dst.extreloff);
-  dst.nextrel         = SwapByteOrder(dst.nextrel);
-  dst.locreloff       = SwapByteOrder(dst.locreloff);
-  dst.nlocrel         = SwapByteOrder(dst.nlocrel);
+  dst.cmd             = getSwappedBytes(dst.cmd);
+  dst.cmdsize         = getSwappedBytes(dst.cmdsize);
+  dst.ilocalsym       = getSwappedBytes(dst.ilocalsym);
+  dst.nlocalsym       = getSwappedBytes(dst.nlocalsym);
+  dst.iextdefsym      = getSwappedBytes(dst.iextdefsym);
+  dst.nextdefsym      = getSwappedBytes(dst.nextdefsym);
+  dst.iundefsym       = getSwappedBytes(dst.iundefsym);
+  dst.nundefsym       = getSwappedBytes(dst.nundefsym);
+  dst.tocoff          = getSwappedBytes(dst.tocoff);
+  dst.ntoc            = getSwappedBytes(dst.ntoc);
+  dst.modtaboff       = getSwappedBytes(dst.modtaboff);
+  dst.nmodtab         = getSwappedBytes(dst.nmodtab);
+  dst.extrefsymoff    = getSwappedBytes(dst.extrefsymoff);
+  dst.nextrefsyms     = getSwappedBytes(dst.nextrefsyms);
+  dst.indirectsymoff  = getSwappedBytes(dst.indirectsymoff);
+  dst.nindirectsyms   = getSwappedBytes(dst.nindirectsyms);
+  dst.extreloff       = getSwappedBytes(dst.extreloff);
+  dst.nextrel         = getSwappedBytes(dst.nextrel);
+  dst.locreloff       = getSwappedBytes(dst.locreloff);
+  dst.nlocrel         = getSwappedBytes(dst.nlocrel);
 }
 
 
 inline void swapStruct(llvm::MachO::any_relocation_info &reloc) {
-  reloc.r_word0 = SwapByteOrder(reloc.r_word0);
-  reloc.r_word1 = SwapByteOrder(reloc.r_word1);
+  reloc.r_word0 = getSwappedBytes(reloc.r_word0);
+  reloc.r_word1 = getSwappedBytes(reloc.r_word1);
 }
 
 inline void swapStruct(llvm::MachO::nlist &sym) {
-  sym.n_strx = SwapByteOrder(sym.n_strx);
-  sym.n_desc = SwapByteOrder(sym.n_desc);
-  sym.n_value = SwapByteOrder(sym.n_value);
+  sym.n_strx = getSwappedBytes(sym.n_strx);
+  sym.n_desc = getSwappedBytes(sym.n_desc);
+  sym.n_value = getSwappedBytes(sym.n_value);
 }
 
 inline void swapStruct(llvm::MachO::nlist_64 &sym) {
-  sym.n_strx = SwapByteOrder(sym.n_strx);
-  sym.n_desc = SwapByteOrder(sym.n_desc);
-  sym.n_value = SwapByteOrder(sym.n_value);
+  sym.n_strx = getSwappedBytes(sym.n_strx);
+  sym.n_desc = getSwappedBytes(sym.n_desc);
+  sym.n_value = getSwappedBytes(sym.n_value);
 }
 
 
 
 
 inline uint32_t read32(bool swap, uint32_t value) {
-    return (swap ? SwapByteOrder(value) : value);
+    return (swap ? getSwappedBytes(value) : value);
 }
 
 inline uint64_t read64(bool swap, uint64_t value) {
-    return (swap ? SwapByteOrder(value) : value);
+    return (swap ? getSwappedBytes(value) : value);
 }
 
 
@@ -265,8 +265,8 @@ packRelocation(const Relocation &r, bool
   }
 
   llvm::MachO::any_relocation_info result;
-  result.r_word0 = swap ? SwapByteOrder(r0) : r0;
-  result.r_word1 = swap ? SwapByteOrder(r1) : r1;
+  result.r_word0 = swap ? getSwappedBytes(r0) : r0;
+  result.r_word1 = swap ? getSwappedBytes(r1) : r1;
   return result;
 }
 





More information about the llvm-commits mailing list