[llvm] r220346 - MRI scripts: Add addlib support.
Rafael Espindola
rafael.espindola at gmail.com
Tue Oct 21 16:18:51 PDT 2014
Author: rafael
Date: Tue Oct 21 18:18:51 2014
New Revision: 220346
URL: http://llvm.org/viewvc/llvm-project?rev=220346&view=rev
Log:
MRI scripts: Add addlib support.
Added:
llvm/trunk/test/Object/mri-addlib.test
Modified:
llvm/trunk/tools/llvm-ar/llvm-ar.cpp
Added: llvm/trunk/test/Object/mri-addlib.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/mri-addlib.test?rev=220346&view=auto
==============================================================================
--- llvm/trunk/test/Object/mri-addlib.test (added)
+++ llvm/trunk/test/Object/mri-addlib.test Tue Oct 21 18:18:51 2014
@@ -0,0 +1,17 @@
+; RUN: echo create %t.a > %t.mri
+; RUN: echo addlib %p/Inputs/GNU.a >> %t.mri
+; RUN: echo addlib %p/Inputs/archive-test.a-gnu-minimal >> %t.mri
+; RUN: echo save >> %t.mri
+; RUN: echo end >> %t.mri
+
+; RUN: llvm-ar -M < %t.mri
+; RUN: llvm-ar t %t.a | FileCheck %s
+
+; CHECK: evenlen
+; CHECK-NEXT: oddlen
+; CHECK-NEXT: very_long_bytecode_file_name.bc
+; CHECK-NEXT: IsNAN.o
+; CHECK-NEXT: test
+
+; line_iterator is incompatible to CRLF.
+; REQUIRES: shell
Modified: llvm/trunk/tools/llvm-ar/llvm-ar.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-ar/llvm-ar.cpp?rev=220346&r1=220345&r2=220346&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-ar/llvm-ar.cpp (original)
+++ llvm/trunk/tools/llvm-ar/llvm-ar.cpp Tue Oct 21 18:18:51 2014
@@ -947,19 +947,22 @@ static int performOperation(ArchiveOpera
}
static void runMRIScript() {
- enum class MRICommand { AddMod, Create, Save, End, Invalid };
+ enum class MRICommand { AddLib, AddMod, Create, Save, End, Invalid };
ErrorOr<std::unique_ptr<MemoryBuffer>> Buf = MemoryBuffer::getSTDIN();
failIfError(Buf.getError());
const MemoryBuffer &Ref = *Buf.get();
bool Saved = false;
std::vector<NewArchiveIterator> NewMembers;
+ std::vector<std::unique_ptr<MemoryBuffer>> ArchiveBuffers;
+ std::vector<std::unique_ptr<object::Archive>> Archives;
for (line_iterator I(Ref, /*SkipBlanks*/ true, ';'), E; I != E; ++I) {
StringRef Line = *I;
StringRef CommandStr, Rest;
std::tie(CommandStr, Rest) = Line.split(' ');
auto Command = StringSwitch<MRICommand>(CommandStr.lower())
+ .Case("addlib", MRICommand::AddLib)
.Case("addmod", MRICommand::AddMod)
.Case("create", MRICommand::Create)
.Case("save", MRICommand::Save)
@@ -967,6 +970,22 @@ static void runMRIScript() {
.Default(MRICommand::Invalid);
switch (Command) {
+ case MRICommand::AddLib: {
+ auto BufOrErr = MemoryBuffer::getFile(Rest, -1, false);
+ failIfError(BufOrErr.getError(), "Could not open library");
+ ArchiveBuffers.push_back(std::move(*BufOrErr));
+ auto LibOrErr =
+ object::Archive::create(ArchiveBuffers.back()->getMemBufferRef());
+ failIfError(LibOrErr.getError(), "Could not parse library");
+ Archives.push_back(std::move(*LibOrErr));
+ object::Archive &Lib = *Archives.back();
+ for (auto &Member : Lib.children()) {
+ ErrorOr<StringRef> NameOrErr = Member.getName();
+ failIfError(NameOrErr.getError());
+ addMember(NewMembers, Member, *NameOrErr);
+ }
+ break;
+ }
case MRICommand::AddMod:
addMember(NewMembers, Rest, sys::path::filename(Rest));
break;
More information about the llvm-commits
mailing list