From dc7bc46ccd54de9aa2f8a026bb4bd1c86d6a0d47 Mon Sep 17 00:00:00 2001 From: Davide Italiano Date: Mon, 12 Oct 2015 00:57:29 +0000 Subject: [PATCH 1/1] [llvm-rtdyld] General modernization/cleanup in preparation for (bigger) changes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@250004 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-rtdyld/llvm-rtdyld.cpp | 33 +++++++++++++------------------ 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/tools/llvm-rtdyld/llvm-rtdyld.cpp b/tools/llvm-rtdyld/llvm-rtdyld.cpp index 54b5aa03d7d..1bcd8900a27 100644 --- a/tools/llvm-rtdyld/llvm-rtdyld.cpp +++ b/tools/llvm-rtdyld/llvm-rtdyld.cpp @@ -197,13 +197,11 @@ uint8_t *TrivialMemoryManager::allocateDataSection(uintptr_t Size, } void TrivialMemoryManager::invalidateInstructionCache() { - for (int i = 0, e = FunctionMemory.size(); i != e; ++i) - sys::Memory::InvalidateInstructionCache(FunctionMemory[i].base(), - FunctionMemory[i].size()); + for (auto &FM : FunctionMemory) + sys::Memory::InvalidateInstructionCache(FM.base(), FM.size()); - for (int i = 0, e = DataMemory.size(); i != e; ++i) - sys::Memory::InvalidateInstructionCache(DataMemory[i].base(), - DataMemory[i].size()); + for (auto &DM : DataMemory) + sys::Memory::InvalidateInstructionCache(DM.base(), DM.size()); } static const char *ProgramName; @@ -240,7 +238,7 @@ static int printLineInfoForInput(bool LoadObjects, bool UseDebugObj) { // If we don't have any input files, read from stdin. if (!InputFileList.size()) InputFileList.push_back("-"); - for(unsigned i = 0, e = InputFileList.size(); i != e; ++i) { + for (auto &File : InputFileList) { // Instantiate a dynamic linker. TrivialMemoryManager MemMgr; RuntimeDyld Dyld(MemMgr, MemMgr); @@ -248,7 +246,7 @@ static int printLineInfoForInput(bool LoadObjects, bool UseDebugObj) { // Load the input memory buffer. ErrorOr> InputBuffer = - MemoryBuffer::getFileOrSTDIN(InputFileList[i]); + MemoryBuffer::getFileOrSTDIN(File); if (std::error_code EC = InputBuffer.getError()) return Error("unable to read input: '" + EC.message() + "'"); @@ -317,11 +315,9 @@ static int printLineInfoForInput(bool LoadObjects, bool UseDebugObj) { << ", Addr = " << Addr << "\n"; DILineInfoTable Lines = Context->getLineInfoForAddressRange(Addr, Size); - DILineInfoTable::iterator Begin = Lines.begin(); - DILineInfoTable::iterator End = Lines.end(); - for (DILineInfoTable::iterator It = Begin; It != End; ++It) { - outs() << " Line info @ " << It->first - Addr << ": " - << It->second.FileName << ", line:" << It->second.Line << "\n"; + for (auto &D : Lines) { + outs() << " Line info @ " << D.first - Addr << ": " + << D.second.FileName << ", line:" << D.second.Line << "\n"; } } } @@ -346,10 +342,10 @@ static int executeInput() { // If we don't have any input files, read from stdin. if (!InputFileList.size()) InputFileList.push_back("-"); - for(unsigned i = 0, e = InputFileList.size(); i != e; ++i) { + for (auto &File : InputFileList) { // Load the input memory buffer. ErrorOr> InputBuffer = - MemoryBuffer::getFileOrSTDIN(InputFileList[i]); + MemoryBuffer::getFileOrSTDIN(File); if (std::error_code EC = InputBuffer.getError()) return Error("unable to read input: '" + EC.message() + "'"); ErrorOr> MaybeObj( @@ -381,12 +377,11 @@ static int executeInput() { return Error("no definition for '" + EntryPoint + "'"); // Invalidate the instruction cache for each loaded function. - for (unsigned i = 0, e = MemMgr.FunctionMemory.size(); i != e; ++i) { - sys::MemoryBlock &Data = MemMgr.FunctionMemory[i]; + for (auto &FM : MemMgr.FunctionMemory) { // Make sure the memory is executable. std::string ErrorStr; - sys::Memory::InvalidateInstructionCache(Data.base(), Data.size()); - if (!sys::Memory::setExecutable(Data, &ErrorStr)) + sys::Memory::InvalidateInstructionCache(FM.base(), FM.size()); + if (!sys::Memory::setExecutable(FM, &ErrorStr)) return Error("unable to mark function executable: '" + ErrorStr + "'"); } -- 2.34.1