[llvm-commits] [llvm] r95825 - in /llvm/trunk: docs/CommandGuide/llvm-extract.pod tools/llvm-extract/llvm-extract.cpp

Dan Gohman gohman at apple.com
Wed Feb 10 15:58:53 PST 2010


Author: djg
Date: Wed Feb 10 17:58:53 2010
New Revision: 95825

URL: http://llvm.org/viewvc/llvm-project?rev=95825&view=rev
Log:
Add support to llvm-extract for extracting multiple functions and/or
multiple global variables at a time.

Modified:
    llvm/trunk/docs/CommandGuide/llvm-extract.pod
    llvm/trunk/tools/llvm-extract/llvm-extract.cpp

Modified: llvm/trunk/docs/CommandGuide/llvm-extract.pod
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/CommandGuide/llvm-extract.pod?rev=95825&r1=95824&r2=95825&view=diff

==============================================================================
--- llvm/trunk/docs/CommandGuide/llvm-extract.pod (original)
+++ llvm/trunk/docs/CommandGuide/llvm-extract.pod Wed Feb 10 17:58:53 2010
@@ -34,7 +34,13 @@
 
 =item B<--func> I<function-name>
 
-Extract the function named I<function-name> from the LLVM bitcode.
+Extract the function named I<function-name> from the LLVM bitcode. May be
+specified multiple times to extract multiple functions at once.
+
+=item B<--glob> I<global-name>
+
+Extract the global variable named I<global-name> from the LLVM bitcode. May be
+specified multiple times to extract multiple global variables at once.
 
 =item B<--help>
 

Modified: llvm/trunk/tools/llvm-extract/llvm-extract.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-extract/llvm-extract.cpp?rev=95825&r1=95824&r2=95825&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-extract/llvm-extract.cpp (original)
+++ llvm/trunk/tools/llvm-extract/llvm-extract.cpp Wed Feb 10 17:58:53 2010
@@ -49,15 +49,15 @@
 Relink("relink",
        cl::desc("Turn external linkage for callees of function to delete"));
 
-// ExtractFunc - The function to extract from the module... 
-static cl::opt<std::string>
-ExtractFunc("func", cl::desc("Specify function to extract"), cl::init(""),
-            cl::value_desc("function"));
-
-// ExtractGlobal - The global to extract from the module...
-static cl::opt<std::string>
-ExtractGlobal("glob", cl::desc("Specify global to extract"), cl::init(""),
-              cl::value_desc("global"));
+// ExtractFuncs - The functions to extract from the module... 
+static cl::list<std::string>
+ExtractFuncs("func", cl::desc("Specify function to extract"),
+             cl::ZeroOrMore, cl::value_desc("function"));
+
+// ExtractGlobals - The globals to extract from the module...
+static cl::list<std::string>
+ExtractGlobals("glob", cl::desc("Specify global to extract"),
+               cl::ZeroOrMore, cl::value_desc("global"));
 
 static cl::opt<bool>
 OutputAssembly("S",
@@ -81,28 +81,34 @@
     return 1;
   }
 
-  // Figure out which function we should extract
-  GlobalVariable *G = !ExtractGlobal.empty() ?
-    M.get()->getNamedGlobal(ExtractGlobal) : 0;
-
-  // Figure out which function we should extract
-  if (ExtractFunc.empty() && ExtractGlobal.empty()) ExtractFunc = "main";
-  Function *F = M.get()->getFunction(ExtractFunc);
-
-  if (F == 0 && G == 0) {
-    errs() << argv[0] << ": program doesn't contain function named '"
-           << ExtractFunc << "' or a global named '" << ExtractGlobal << "'!\n";
-    return 1;
+  std::vector<GlobalValue *> GVs;
+
+  // Figure out which globals we should extract.
+  for (size_t i = 0, e = ExtractGlobals.size(); i != e; ++i) {
+    GlobalValue *GV = M.get()->getNamedGlobal(ExtractGlobals[i]);
+    if (!GV) {
+      errs() << argv[0] << ": program doesn't contain global named '"
+             << ExtractGlobals[i] << "'!\n";
+      return 1;
+    }
+    GVs.push_back(GV);
+  }
+
+  // Figure out which functions we should extract.
+  for (size_t i = 0, e = ExtractFuncs.size(); i != e; ++i) {
+    GlobalValue *GV = M.get()->getFunction(ExtractFuncs[i]);
+    if (!GV) {
+      errs() << argv[0] << ": program doesn't contain function named '"
+             << ExtractFuncs[i] << "'!\n";
+      return 1;
+    }
+    GVs.push_back(GV);
   }
 
   // In addition to deleting all other functions, we also want to spiff it
   // up a little bit.  Do this now.
   PassManager Passes;
   Passes.add(new TargetData(M.get())); // Use correct TargetData
-  // Either isolate the function or delete it from the Module
-  std::vector<GlobalValue*> GVs;
-  if (F) GVs.push_back(F);
-  if (G) GVs.push_back(G);
 
   Passes.add(createGVExtractionPass(GVs, DeleteFn, Relink));
   if (!DeleteFn)





More information about the llvm-commits mailing list