llvm.org GIT mirror llvm / b2a5bf2
Return ErrorOr<std::unique_ptr<Archive>> form getAsArchive. This is the same return type of Archive::create. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223827 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 5 years ago
5 changed file(s) with 36 addition(s) and 33 deletion(s). Raw diff Collapse all Expand all
5757
5858 ErrorOr> getAsObjectFile() const;
5959
60 std::error_code getAsArchive(std::unique_ptr &Result) const;
60 ErrorOr> getAsArchive() const;
6161 };
6262
6363 class object_iterator {
7878 return object_error::parse_failed;
7979 }
8080
81 std::error_code MachOUniversalBinary::ObjectForArch::getAsArchive(
82 std::unique_ptr &Result) const {
83 if (Parent) {
84 StringRef ParentData = Parent->getData();
85 StringRef ObjectData = ParentData.substr(Header.offset, Header.size);
86 StringRef ObjectName = Parent->getFileName();
87 MemoryBufferRef ObjBuffer(ObjectData, ObjectName);
88 ErrorOr> Obj = Archive::create(ObjBuffer);
89 if (std::error_code EC = Obj.getError())
90 return EC;
91 Result = std::move(Obj.get());
92 return object_error::success;
93 }
94 return object_error::parse_failed;
81 ErrorOr>
82 MachOUniversalBinary::ObjectForArch::getAsArchive() const {
83 if (!Parent)
84 return object_error::parse_failed;
85
86 StringRef ParentData = Parent->getData();
87 StringRef ObjectData = ParentData.substr(Header.offset, Header.size);
88 StringRef ObjectName = Parent->getFileName();
89 MemoryBufferRef ObjBuffer(ObjectData, ObjectName);
90 return Archive::create(ObjBuffer);
9591 }
9692
9793 void MachOUniversalBinary::anchor() { }
10681068 ArchFound = true;
10691069 ErrorOr> ObjOrErr =
10701070 I->getAsObjectFile();
1071 std::unique_ptr A;
10721071 std::string ArchiveName;
10731072 std::string ArchitectureName;
10741073 ArchiveName.clear();
10851084 }
10861085 dumpSymbolNamesFromObject(Obj, false, ArchiveName,
10871086 ArchitectureName);
1088 } else if (!I->getAsArchive(A)) {
1087 } else if (ErrorOr> AOrErr =
1088 I->getAsArchive()) {
1089 std::unique_ptr &A = *AOrErr;
10891090 for (Archive::child_iterator AI = A->child_begin(),
10901091 AE = A->child_end();
10911092 AI != AE; ++AI) {
11321133 I != E; ++I) {
11331134 if (HostArchName == I->getArchTypeName()) {
11341135 ErrorOr> ObjOrErr = I->getAsObjectFile();
1135 std::unique_ptr A;
11361136 std::string ArchiveName;
11371137 ArchiveName.clear();
11381138 if (ObjOrErr) {
11391139 ObjectFile &Obj = *ObjOrErr.get();
11401140 dumpSymbolNamesFromObject(Obj, false);
1141 } else if (!I->getAsArchive(A)) {
1141 } else if (ErrorOr> AOrErr =
1142 I->getAsArchive()) {
1143 std::unique_ptr &A = *AOrErr;
11421144 for (Archive::child_iterator AI = A->child_begin(),
11431145 AE = A->child_end();
11441146 AI != AE; ++AI) {
11691171 E = UB->end_objects();
11701172 I != E; ++I) {
11711173 ErrorOr> ObjOrErr = I->getAsObjectFile();
1172 std::unique_ptr A;
11731174 std::string ArchiveName;
11741175 std::string ArchitectureName;
11751176 ArchiveName.clear();
11881189 outs() << ":\n";
11891190 }
11901191 dumpSymbolNamesFromObject(Obj, false, ArchiveName, ArchitectureName);
1191 } else if (!I->getAsArchive(A)) {
1192 } else if (ErrorOr> AOrErr = I->getAsArchive()) {
1193 std::unique_ptr &A = *AOrErr;
11921194 for (Archive::child_iterator AI = A->child_begin(), AE = A->child_end();
11931195 AI != AE; ++AI) {
11941196 ErrorOr> ChildOrErr =
339339 ArchFound = true;
340340 ErrorOr> ObjOrErr =
341341 I->getAsObjectFile();
342 std::unique_ptr A;
343342 std::string ArchitectureName = "";
344343 if (ArchFlags.size() > 1)
345344 ArchitectureName = I->getArchTypeName();
347346 ObjectFile &O = *ObjOrErr.get();
348347 if (MachOObjectFile *MachOOF = dyn_cast(&O))
349348 DisassembleInputMachO2(Filename, MachOOF, "", ArchitectureName);
350 } else if (!I->getAsArchive(A)) {
349 } else if (ErrorOr> AOrErr =
350 I->getAsArchive()) {
351 std::unique_ptr &A = *AOrErr;
351352 outs() << "Archive : " << Filename;
352353 if (!ArchitectureName.empty())
353354 outs() << " (architecture " << ArchitectureName << ")";
383384 I != E; ++I) {
384385 if (HostArchName == I->getArchTypeName()) {
385386 ErrorOr> ObjOrErr = I->getAsObjectFile();
386 std::unique_ptr A;
387387 std::string ArchiveName;
388388 ArchiveName.clear();
389389 if (ObjOrErr) {
390390 ObjectFile &O = *ObjOrErr.get();
391391 if (MachOObjectFile *MachOOF = dyn_cast(&O))
392392 DisassembleInputMachO2(Filename, MachOOF);
393 } else if (!I->getAsArchive(A)) {
393 } else if (ErrorOr> AOrErr =
394 I->getAsArchive()) {
395 std::unique_ptr &A = *AOrErr;
394396 outs() << "Archive : " << Filename << "\n";
395397 for (Archive::child_iterator AI = A->child_begin(),
396398 AE = A->child_end();
414416 E = UB->end_objects();
415417 I != E; ++I) {
416418 ErrorOr> ObjOrErr = I->getAsObjectFile();
417 std::unique_ptr A;
418419 std::string ArchitectureName = "";
419420 if (moreThanOneArch)
420421 ArchitectureName = I->getArchTypeName();
422423 ObjectFile &Obj = *ObjOrErr.get();
423424 if (MachOObjectFile *MachOOF = dyn_cast(&Obj))
424425 DisassembleInputMachO2(Filename, MachOOF, "", ArchitectureName);
425 } else if (!I->getAsArchive(A)) {
426 } else if (ErrorOr> AOrErr = I->getAsArchive()) {
427 std::unique_ptr &A = *AOrErr;
426428 outs() << "Archive : " << Filename;
427429 if (!ArchitectureName.empty())
428430 outs() << " (architecture " << ArchitectureName << ")";
483483 if (ArchFlags[i] == I->getArchTypeName()) {
484484 ArchFound = true;
485485 ErrorOr> UO = I->getAsObjectFile();
486 std::unique_ptr UA;
487486 if (UO) {
488487 if (ObjectFile *o = dyn_cast(&*UO.get())) {
489488 MachOObjectFile *MachO = dyn_cast(o);
502501 outs() << "\n";
503502 }
504503 }
505 } else if (!I->getAsArchive(UA)) {
504 } else if (ErrorOr> AOrErr =
505 I->getAsArchive()) {
506 std::unique_ptr &UA = *AOrErr;
506507 // This is an archive. Iterate over each member and display its
507508 // sizes.
508509 for (object::Archive::child_iterator i = UA->child_begin(),
559560 I != E; ++I) {
560561 if (HostArchName == I->getArchTypeName()) {
561562 ErrorOr> UO = I->getAsObjectFile();
562 std::unique_ptr UA;
563563 if (UO) {
564564 if (ObjectFile *o = dyn_cast(&*UO.get())) {
565565 MachOObjectFile *MachO = dyn_cast(o);
578578 outs() << "\n";
579579 }
580580 }
581 } else if (!I->getAsArchive(UA)) {
581 } else if (ErrorOr> AOrErr =
582 I->getAsArchive()) {
583 std::unique_ptr &UA = *AOrErr;
582584 // This is an archive. Iterate over each member and display its
583585 // sizes.
584586 for (object::Archive::child_iterator i = UA->child_begin(),
622624 E = UB->end_objects();
623625 I != E; ++I) {
624626 ErrorOr> UO = I->getAsObjectFile();
625 std::unique_ptr UA;
626627 if (UO) {
627628 if (ObjectFile *o = dyn_cast(&*UO.get())) {
628629 MachOObjectFile *MachO = dyn_cast(o);
642643 outs() << "\n";
643644 }
644645 }
645 } else if (!I->getAsArchive(UA)) {
646 } else if (ErrorOr> AOrErr =
647 I->getAsArchive()) {
648 std::unique_ptr &UA = *AOrErr;
646649 // This is an archive. Iterate over each member and display its sizes.
647650 for (object::Archive::child_iterator i = UA->child_begin(),
648651 e = UA->child_end();