[llvm-commits] CVS: llvm/tools/opt/Makefile opt.cpp

Chris Lattner sabre at nondot.org
Sat May 5 19:42:21 PDT 2007



Changes in directory llvm/tools/opt:

Makefile updated: 1.61 -> 1.62
opt.cpp updated: 1.137 -> 1.138
---
Log message:

if -bitcode is specified, read and write a bitcode file instead of a bytecode file.


---
Diffs of the changes:  (+31 -5)

 Makefile |    2 +-
 opt.cpp  |   34 ++++++++++++++++++++++++++++++----
 2 files changed, 31 insertions(+), 5 deletions(-)


Index: llvm/tools/opt/Makefile
diff -u llvm/tools/opt/Makefile:1.61 llvm/tools/opt/Makefile:1.62
--- llvm/tools/opt/Makefile:1.61	Sat Feb  3 17:15:56 2007
+++ llvm/tools/opt/Makefile	Sat May  5 21:42:03 2007
@@ -10,6 +10,6 @@
 TOOLNAME = opt
 REQUIRES_EH := 1
 
-LINK_COMPONENTS := bcreader bcwriter instrumentation scalaropts ipo
+LINK_COMPONENTS := bcreader bcwriter bitreader bitwriter instrumentation scalaropts ipo
 
 include $(LEVEL)/Makefile.common


Index: llvm/tools/opt/opt.cpp
diff -u llvm/tools/opt/opt.cpp:1.137 llvm/tools/opt/opt.cpp:1.138
--- llvm/tools/opt/opt.cpp:1.137	Wed May  2 20:11:54 2007
+++ llvm/tools/opt/opt.cpp	Sat May  5 21:42:03 2007
@@ -16,6 +16,7 @@
 #include "llvm/PassManager.h"
 #include "llvm/Bytecode/Reader.h"
 #include "llvm/Bytecode/WriteBytecodePass.h"
+#include "llvm/Bitcode/ReaderWriter.h"
 #include "llvm/Assembly/PrintModulePass.h"
 #include "llvm/Analysis/Verifier.h"
 #include "llvm/Analysis/LoopPass.h"
@@ -24,6 +25,7 @@
 #include "llvm/Support/PassNameParser.h"
 #include "llvm/System/Signals.h"
 #include "llvm/Support/ManagedStatic.h"
+#include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/PluginLoader.h"
 #include "llvm/Support/Streams.h"
 #include "llvm/Support/SystemUtils.h"
@@ -35,6 +37,8 @@
 #include <algorithm>
 using namespace llvm;
 
+static cl::opt<bool> Bitcode("bitcode");
+
 // The OptimizationList is automatically populated with registered Passes by the
 // PassNameParser.
 //
@@ -262,8 +266,26 @@
     std::string ErrorMessage;
 
     // Load the input module...
-    std::auto_ptr<Module> M(ParseBytecodeFile(InputFilename, 
-                            Compressor::decompressToNewBuffer, &ErrorMessage));
+    std::auto_ptr<Module> M;
+    if (Bitcode) {
+      MemoryBuffer *Buffer;
+      if (InputFilename == "-") {
+        Buffer = MemoryBuffer::getSTDIN();
+      } else {
+        Buffer = MemoryBuffer::getFile(&InputFilename[0], InputFilename.size());
+      }
+      
+      if (Buffer == 0)
+        ErrorMessage = "Error reading file '" + InputFilename + "'";
+      else
+        M.reset(ParseBitcodeFile(Buffer, &ErrorMessage));
+      
+      delete Buffer;
+    } else {
+      M.reset(ParseBytecodeFile(InputFilename, 
+                                Compressor::decompressToNewBuffer,
+                                &ErrorMessage));
+    }
     if (M.get() == 0) {
       cerr << argv[0] << ": ";
       if (ErrorMessage.size())
@@ -355,8 +377,12 @@
 
     // Write bytecode out to disk or cout as the last step...
     OStream L(*Out);
-    if (!NoOutput && !AnalyzeOnly)
-      Passes.add(new WriteBytecodePass(&L, false, !NoCompress));
+    if (!NoOutput && !AnalyzeOnly) {
+      if (Bitcode)
+        Passes.add(CreateBitcodeWriterPass(*Out));
+      else
+        Passes.add(new WriteBytecodePass(&L, false, !NoCompress));
+    }
 
     // Now that we have all of the passes ready, run them.
     Passes.run(*M.get());






More information about the llvm-commits mailing list