ArchiveReader.cpp (193323) | ArchiveReader.cpp (195340) |
---|---|
1//===-- ArchiveReader.cpp - Read LLVM archive files -------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// --- 313 unchanged lines hidden (view full) --- 322 At++; 323 } 324 } 325 return true; 326} 327 328// Open and completely load the archive file. 329Archive* | 1//===-- ArchiveReader.cpp - Read LLVM archive files -------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// --- 313 unchanged lines hidden (view full) --- 322 At++; 323 } 324 } 325 return true; 326} 327 328// Open and completely load the archive file. 329Archive* |
330Archive::OpenAndLoad(const sys::Path& file, std::string* ErrorMessage) 331{ 332 std::auto_ptr | 330Archive::OpenAndLoad(const sys::Path& file, LLVMContext& C, 331 std::string* ErrorMessage) { 332 std::auto_ptr<Archive> result ( new Archive(file, C)); |
333 if (result->mapToMemory(ErrorMessage)) 334 return 0; 335 if (!result->loadArchive(ErrorMessage)) 336 return 0; 337 return result.release(); 338} 339 340// Get all the bitcode modules from the archive 341bool | 333 if (result->mapToMemory(ErrorMessage)) 334 return 0; 335 if (!result->loadArchive(ErrorMessage)) 336 return 0; 337 return result.release(); 338} 339 340// Get all the bitcode modules from the archive 341bool |
342Archive::getAllModules(std::vector<Module*>& Modules, std::string* ErrMessage) { | 342Archive::getAllModules(std::vector 343 std::string* ErrMessage) { |
343 344 for (iterator I=begin(), E=end(); I != E; ++I) { 345 if (I->isBitcode()) { 346 std::string FullMemberName = archPath.toString() + 347 "(" + I->getPath().toString() + ")"; 348 MemoryBuffer *Buffer = 349 MemoryBuffer::getNewMemBuffer(I->getSize(), FullMemberName.c_str()); 350 memcpy((char*)Buffer->getBufferStart(), I->getData(), I->getSize()); 351 | 344 345 for (iterator I=begin(), E=end(); I != E; ++I) { 346 if (I->isBitcode()) { 347 std::string FullMemberName = archPath.toString() + 348 "(" + I->getPath().toString() + ")"; 349 MemoryBuffer *Buffer = 350 MemoryBuffer::getNewMemBuffer(I->getSize(), FullMemberName.c_str()); 351 memcpy((char*)Buffer->getBufferStart(), I->getData(), I->getSize()); 352 |
352 Module *M = ParseBitcodeFile(Buffer, ErrMessage); | 353 Module *M = ParseBitcodeFile(Buffer, Context, ErrMessage); |
353 delete Buffer; 354 if (!M) 355 return true; 356 357 Modules.push_back(M); 358 } 359 } 360 return false; --- 74 unchanged lines hidden (view full) --- 435 members.push_back(mbr); 436 } 437 438 firstFileOffset = FirstFile - base; 439 return true; 440} 441 442// Open the archive and load just the symbol tables | 354 delete Buffer; 355 if (!M) 356 return true; 357 358 Modules.push_back(M); 359 } 360 } 361 return false; --- 74 unchanged lines hidden (view full) --- 436 members.push_back(mbr); 437 } 438 439 firstFileOffset = FirstFile - base; 440 return true; 441} 442 443// Open the archive and load just the symbol tables |
443Archive* 444Archive::OpenAndLoadSymbols(const sys::Path& file, std::string* ErrorMessage) { 445 std::auto_ptr<Archive> result ( new Archive(file) ); | 444Archive* Archive::OpenAndLoadSymbols(const sys::Path& file, 445 LLVMContext& C, 446 std::string* ErrorMessage) { 447 std::auto_ptr<Archive> result ( new Archive(file, C) ); |
446 if (result->mapToMemory(ErrorMessage)) 447 return 0; 448 if (!result->loadSymbolTable(ErrorMessage)) 449 return 0; 450 return result.release(); 451} 452 453// Look up one symbol in the symbol table and return a ModuleProvider for the --- 29 unchanged lines hidden (view full) --- 483 484 // Now, load the bitcode module to get the ModuleProvider 485 std::string FullMemberName = archPath.toString() + "(" + 486 mbr->getPath().toString() + ")"; 487 MemoryBuffer *Buffer =MemoryBuffer::getNewMemBuffer(mbr->getSize(), 488 FullMemberName.c_str()); 489 memcpy((char*)Buffer->getBufferStart(), mbr->getData(), mbr->getSize()); 490 | 448 if (result->mapToMemory(ErrorMessage)) 449 return 0; 450 if (!result->loadSymbolTable(ErrorMessage)) 451 return 0; 452 return result.release(); 453} 454 455// Look up one symbol in the symbol table and return a ModuleProvider for the --- 29 unchanged lines hidden (view full) --- 485 486 // Now, load the bitcode module to get the ModuleProvider 487 std::string FullMemberName = archPath.toString() + "(" + 488 mbr->getPath().toString() + ")"; 489 MemoryBuffer *Buffer =MemoryBuffer::getNewMemBuffer(mbr->getSize(), 490 FullMemberName.c_str()); 491 memcpy((char*)Buffer->getBufferStart(), mbr->getData(), mbr->getSize()); 492 |
491 ModuleProvider *mp = getBitcodeModuleProvider(Buffer, ErrMsg); | 493 ModuleProvider *mp = getBitcodeModuleProvider(Buffer, Context, ErrMsg); |
492 if (!mp) 493 return 0; 494 495 modules.insert(std::make_pair(fileOffset, std::make_pair(mp, mbr))); 496 497 return mp; 498} 499 --- 31 unchanged lines hidden (view full) --- 531 // If it contains symbols 532 if (mbr->isBitcode()) { 533 // Get the symbols 534 std::vector<std::string> symbols; 535 std::string FullMemberName = archPath.toString() + "(" + 536 mbr->getPath().toString() + ")"; 537 ModuleProvider* MP = 538 GetBitcodeSymbols((const unsigned char*)At, mbr->getSize(), | 494 if (!mp) 495 return 0; 496 497 modules.insert(std::make_pair(fileOffset, std::make_pair(mp, mbr))); 498 499 return mp; 500} 501 --- 31 unchanged lines hidden (view full) --- 533 // If it contains symbols 534 if (mbr->isBitcode()) { 535 // Get the symbols 536 std::vector<std::string> symbols; 537 std::string FullMemberName = archPath.toString() + "(" + 538 mbr->getPath().toString() + ")"; 539 ModuleProvider* MP = 540 GetBitcodeSymbols((const unsigned char*)At, mbr->getSize(), |
539 FullMemberName, symbols, error); | 541 FullMemberName, Context, symbols, error); |
540 541 if (MP) { 542 // Insert the module's symbols into the symbol table 543 for (std::vector<std::string>::iterator I = symbols.begin(), 544 E=symbols.end(); I != E; ++I ) { 545 symTab.insert(std::make_pair(*I, offset)); 546 } 547 // Insert the ModuleProvider and the ArchiveMember into the table of --- 62 unchanged lines hidden (view full) --- 610 continue; 611 612 std::string FullMemberName = 613 archPath.toString() + "(" + I->getPath().toString() + ")"; 614 615 MemoryBuffer *Buffer = 616 MemoryBuffer::getNewMemBuffer(I->getSize(), FullMemberName.c_str()); 617 memcpy((char*)Buffer->getBufferStart(), I->getData(), I->getSize()); | 542 543 if (MP) { 544 // Insert the module's symbols into the symbol table 545 for (std::vector<std::string>::iterator I = symbols.begin(), 546 E=symbols.end(); I != E; ++I ) { 547 symTab.insert(std::make_pair(*I, offset)); 548 } 549 // Insert the ModuleProvider and the ArchiveMember into the table of --- 62 unchanged lines hidden (view full) --- 612 continue; 613 614 std::string FullMemberName = 615 archPath.toString() + "(" + I->getPath().toString() + ")"; 616 617 MemoryBuffer *Buffer = 618 MemoryBuffer::getNewMemBuffer(I->getSize(), FullMemberName.c_str()); 619 memcpy((char*)Buffer->getBufferStart(), I->getData(), I->getSize()); |
618 Module *M = ParseBitcodeFile(Buffer); | 620 Module *M = ParseBitcodeFile(Buffer, Context); |
619 delete Buffer; 620 if (!M) 621 return false; // Couldn't parse bitcode, not a bitcode archive. 622 delete M; 623 return true; 624 } 625 626 return false; 627} | 621 delete Buffer; 622 if (!M) 623 return false; // Couldn't parse bitcode, not a bitcode archive. 624 delete M; 625 return true; 626 } 627 628 return false; 629} |