[llvm-commits] [llvm] r50749 - in /llvm/trunk: test/LLVMC/together.c test/LLVMC/together.cpp test/LLVMC/together1.c tools/llvmc2/Action.cpp tools/llvmc2/CompilationGraph.cpp tools/llvmc2/CompilationGraph.h tools/llvmc2/Example.td tools/llvmc2/Tools.td

Mikhail Glushenkov foldr at codedgers.com
Tue May 6 11:10:20 PDT 2008


Author: foldr
Date: Tue May  6 13:10:20 2008
New Revision: 50749

URL: http://llvm.org/viewvc/llvm-project?rev=50749&view=rev
Log:
Take object file as input and handle files with the same name correctly.

Added:
    llvm/trunk/test/LLVMC/together.c
      - copied, changed from r50748, llvm/trunk/test/LLVMC/together1.c
Removed:
    llvm/trunk/test/LLVMC/together1.c
Modified:
    llvm/trunk/test/LLVMC/together.cpp
    llvm/trunk/tools/llvmc2/Action.cpp
    llvm/trunk/tools/llvmc2/CompilationGraph.cpp
    llvm/trunk/tools/llvmc2/CompilationGraph.h
    llvm/trunk/tools/llvmc2/Example.td
    llvm/trunk/tools/llvmc2/Tools.td

Copied: llvm/trunk/test/LLVMC/together.c (from r50748, llvm/trunk/test/LLVMC/together1.c)
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LLVMC/together.c?p2=llvm/trunk/test/LLVMC/together.c&p1=llvm/trunk/test/LLVMC/together1.c&r1=50748&r2=50749&rev=50749&view=diff

==============================================================================
    (empty)

Modified: llvm/trunk/test/LLVMC/together.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LLVMC/together.cpp?rev=50749&r1=50748&r2=50749&view=diff

==============================================================================
--- llvm/trunk/test/LLVMC/together.cpp (original)
+++ llvm/trunk/test/LLVMC/together.cpp Tue May  6 13:10:20 2008
@@ -1,6 +1,5 @@
 // Check that we can compile files of different types together.
-// TOFIX: compiling files with same names should work.
-// RUN: llvmc2 %s %p/together1.c -o %t
+// RUN: llvmc2 %s %p/together.c -o %t
 // RUN: ./%t | grep hello
 
 extern "C" void test();

Removed: llvm/trunk/test/LLVMC/together1.c
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LLVMC/together1.c?rev=50748&view=auto

==============================================================================
--- llvm/trunk/test/LLVMC/together1.c (original)
+++ llvm/trunk/test/LLVMC/together1.c (removed)
@@ -1,9 +0,0 @@
-/*
- * RUN: ignore
- */
-
-#include <stdio.h>
-
-void test() {
-  printf("hello\n");
-}

Modified: llvm/trunk/tools/llvmc2/Action.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvmc2/Action.cpp?rev=50749&r1=50748&r2=50749&view=diff

==============================================================================
--- llvm/trunk/tools/llvmc2/Action.cpp (original)
+++ llvm/trunk/tools/llvmc2/Action.cpp Tue May  6 13:10:20 2008
@@ -34,6 +34,7 @@
     if (!prog.canExecute())
       throw std::runtime_error("Program '" + name + "' is not executable.");
 
+    // Build the command line vector and redirects.
     const sys::Path* redirects[3] = {0,0,0};
     sys::Path stdout_redirect;
 
@@ -54,6 +55,7 @@
     }
     argv.push_back(0);  // null terminate list.
 
+    // Invoke the program.
     return sys::Program::ExecuteAndWait(prog, &argv[0], 0, &redirects[0]);
   }
 

Modified: llvm/trunk/tools/llvmc2/CompilationGraph.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvmc2/CompilationGraph.cpp?rev=50749&r1=50748&r2=50749&view=diff

==============================================================================
--- llvm/trunk/tools/llvmc2/CompilationGraph.cpp (original)
+++ llvm/trunk/tools/llvmc2/CompilationGraph.cpp Tue May  6 13:10:20 2008
@@ -121,42 +121,50 @@
   B.IncrInEdges();
 }
 
+// Make a temporary file named like BaseName-RandomDigits.Suffix
+sys::Path MakeTempFile(const sys::Path& TempDir, const std::string& BaseName,
+                       const std::string& Suffix) {
+  sys::Path Out = TempDir;
+  Out.appendComponent(BaseName);
+  Out.appendSuffix(Suffix);
+  Out.makeUnique(true, NULL);
+  Out.eraseFromDisk();
+  return Out;
+}
+
 // Pass input file through the chain until we bump into a Join node or
 // a node that says that it is the last.
-const JoinTool*
-CompilationGraph::PassThroughGraph (sys::Path& In,
-                                    const Node* StartNode,
-                                    const sys::Path& TempDir) const {
+void CompilationGraph::PassThroughGraph (const sys::Path& InFile,
+                                         const Node* StartNode,
+                                         const sys::Path& TempDir) const {
   bool Last = false;
+  sys::Path In = InFile;
   const Node* CurNode = StartNode;
-  JoinTool* ret = 0;
 
   while(!Last) {
     sys::Path Out;
     Tool* CurTool = CurNode->ToolPtr.getPtr();
 
     if (CurTool->IsJoin()) {
-      ret = &dynamic_cast<JoinTool&>(*CurTool);
-      ret->AddToJoinList(In);
+      JoinTool& JT = dynamic_cast<JoinTool&>(*CurTool);
+      JT.AddToJoinList(In);
       break;
     }
 
-    // Is this the last tool?
+    // Since toolchains do not have to end with a Join node, we should
+    // check if this Node is the last.
     if (!CurNode->HasChildren() || CurTool->IsLast()) {
-      // Check if the first tool is also the last
-      if (Out.empty())
+      if (!OutputFilename.empty()) {
+        Out.set(OutputFilename);
+      }
+      else {
         Out.set(In.getBasename());
-      else
-        Out.appendComponent(In.getBasename());
-      Out.appendSuffix(CurTool->OutputSuffix());
+        Out.appendSuffix(CurTool->OutputSuffix());
+      }
       Last = true;
     }
     else {
-      Out = TempDir;
-      Out.appendComponent(In.getBasename());
-      Out.appendSuffix(CurTool->OutputSuffix());
-      Out.makeUnique(true, NULL);
-      Out.eraseFromDisk();
+      Out = MakeTempFile(TempDir, In.getBasename(), CurTool->OutputSuffix());
     }
 
     if (CurTool->GenerateAction(In, Out).Execute() != 0)
@@ -166,8 +174,6 @@
                                   CurNode->Name())->ToolName());
     In = Out; Out.clear();
   }
-
-  return ret;
 }
 
 // Sort the nodes in topological order.
@@ -215,7 +221,6 @@
   return &getNode(ChooseEdge(TV)->ToolName());
 }
 
-// TOFIX: merge some parts with PassThroughGraph.
 // Build the targets. Command-line options are passed through
 // temporary variables.
 int CompilationGraph::Build (const sys::Path& TempDir) {
@@ -243,10 +248,12 @@
     JoinTool* JT = &dynamic_cast<JoinTool&>(*CurNode->ToolPtr.getPtr());
     bool IsLast = false;
 
-    // Has files pending?
+    // Are there any files to be joined?
     if (JT->JoinListEmpty())
       continue;
 
+    // Is this the last tool in the chain?
+    // NOTE: we can process several chains in parallel.
     if (!CurNode->HasChildren() || JT->IsLast()) {
       if (OutputFilename.empty()) {
         Out.set("a");
@@ -257,11 +264,7 @@
       IsLast = true;
     }
     else {
-      Out = TempDir;
-      Out.appendComponent("tmp");
-      Out.appendSuffix(JT->OutputSuffix());
-      Out.makeUnique(true, NULL);
-      Out.eraseFromDisk();
+      Out = MakeTempFile(TempDir, "tmp", JT->OutputSuffix());
     }
 
     if (JT->GenerateAction(Out).Execute() != 0)

Modified: llvm/trunk/tools/llvmc2/CompilationGraph.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvmc2/CompilationGraph.h?rev=50749&r1=50748&r2=50749&view=diff

==============================================================================
--- llvm/trunk/tools/llvmc2/CompilationGraph.h (original)
+++ llvm/trunk/tools/llvmc2/CompilationGraph.h Tue May  6 13:10:20 2008
@@ -28,7 +28,7 @@
 
 namespace llvmc {
 
-  // An edge in the graph.
+  // An edge of the compilation graph.
   class Edge : public llvm::RefCountedBaseVPTR<Edge> {
   public:
     Edge(const std::string& T) : ToolName_(T) {}
@@ -41,7 +41,7 @@
     std::string ToolName_;
   };
 
-  // Edges with no properties are instances of this class.
+  // Edges that have no properties are instances of this class.
   class SimpleEdge : public Edge {
   public:
     SimpleEdge(const std::string& T) : Edge(T) {}
@@ -49,8 +49,9 @@
     bool isDefault() const { return true;}
   };
 
-  // A node in the graph.
+  // A node of the compilation graph.
   struct Node {
+    // A Node holds a list of the outward edges.
     typedef llvm::SmallVector<llvm::IntrusiveRefCntPtr<Edge>, 3> container_type;
     typedef container_type::iterator iterator;
     typedef container_type::const_iterator const_iterator;
@@ -74,10 +75,9 @@
     void AddEdge(Edge* E)
     { OutEdges.push_back(llvm::IntrusiveRefCntPtr<Edge>(E)); }
 
-    // Inward edge counter. Used by Build() to implement topological
-    // sort.
-    // TOTHINK: Move the counter back into Tool classes? Makes us more
-    // const-correct.
+    // Inward edge counter. Used to implement topological sort.
+    // TOTHINK: Move the mutable counter back into Tool classes? Makes
+    // us more const-correct.
     void IncrInEdges() { ++InEdges; }
     void DecrInEdges() { --InEdges; }
     bool HasNoInEdges() const { return InEdges == 0; }
@@ -85,11 +85,12 @@
     // Needed to implement NodeChildIterator/GraphTraits
     CompilationGraph* OwningGraph;
     // The corresponding Tool.
-    // WARNING: For the root node, ToolPtr is NULL.
+    // WARNING: ToolPtr can be NULL (for the root node).
     llvm::IntrusiveRefCntPtr<Tool> ToolPtr;
     // Links to children.
     container_type OutEdges;
-    // Number of parents. Used for topological sorting.
+    // Inward edge counter. Updated in
+    // CompilationGraph::insertEdge(). Used for topological sorting.
     unsigned InEdges;
   };
 
@@ -99,8 +100,9 @@
   class CompilationGraph {
     // Main data structure.
     typedef llvm::StringMap<Node> nodes_map_type;
-    // These are used to map from language names-> tools. (We can have
-    // several tools associated with each language name.)
+    // These are used to map from language names to tools. (We can
+    // have several tools associated with each language name, hence
+    // the need for a vector of Edges.)
     typedef
     llvm::SmallVector<llvm::IntrusiveRefCntPtr<Edge>, 3> tools_vector_type;
     typedef llvm::StringMap<tools_vector_type> tools_map_type;
@@ -159,9 +161,8 @@
     const tools_vector_type& getToolsVector(const std::string& LangName) const;
 
     // Pass the input file through the toolchain.
-    const JoinTool* PassThroughGraph (llvm::sys::Path& In,
-                                      const Node* StartNode,
-                                      const llvm::sys::Path& TempDir) const;
+    void PassThroughGraph (const llvm::sys::Path& In, const Node* StartNode,
+                           const llvm::sys::Path& TempDir) const;
 
     // Find head of the toolchain corresponding to the given file.
     const Node* FindToolChain(const llvm::sys::Path& In) const;

Modified: llvm/trunk/tools/llvmc2/Example.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvmc2/Example.td?rev=50749&r1=50748&r2=50749&view=diff

==============================================================================
--- llvm/trunk/tools/llvmc2/Example.td (original)
+++ llvm/trunk/tools/llvmc2/Example.td Tue May  6 13:10:20 2008
@@ -32,5 +32,7 @@
     Edge<opt, llc>,
 
     Edge<llc, llvm_gcc_assembler>,
-    Edge<llvm_gcc_assembler, llvm_gcc_linker>
+    Edge<llvm_gcc_assembler, llvm_gcc_linker>,
+
+    Edge<root, llvm_gcc_linker>
     ]>;

Modified: llvm/trunk/tools/llvmc2/Tools.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvmc2/Tools.td?rev=50749&r1=50748&r2=50749&view=diff

==============================================================================
--- llvm/trunk/tools/llvmc2/Tools.td (original)
+++ llvm/trunk/tools/llvmc2/Tools.td Tue May  6 13:10:20 2008
@@ -11,19 +11,21 @@
 //
 //===----------------------------------------------------------------------===//
 
-// Open issue: should we use DAG lists in Tool specifications
+// TOTHINK: Open issue: should we use DAG lists in Tool specifications
 // or change to something like
+
 // def LLVMGccC : < Tool<
 // [ InLanguage<"c">,
 //   PrefixListOption<"Wl", [UnpackValues, PropertyName<Arg>, ...]>
 //  ...] ?
+
 // DAG lists look more aesthetically pleasing to me.
 
 def llvm_gcc_c : Tool<
 [(in_language "c"),
  (out_language "llvm-bitcode"),
  (output_suffix "bc"),
- (cmd_line "llvm-gcc -c $INFILE -o $OUTFILE -emit-llvm"),
+ (cmd_line "llvm-gcc -c -x c $INFILE -o $OUTFILE -emit-llvm"),
  (sink)
 ]>;
 
@@ -31,7 +33,7 @@
 [(in_language "c++"),
  (out_language "llvm-bitcode"),
  (output_suffix "bc"),
- (cmd_line "llvm-g++ -c $INFILE -o $OUTFILE -emit-llvm"),
+ (cmd_line "llvm-g++ -c -x c++ $INFILE -o $OUTFILE -emit-llvm"),
  (sink)
 ]>;
 
@@ -61,7 +63,8 @@
 [(in_language "assembler"),
  (out_language "object-code"),
  (output_suffix "o"),
- (cmd_line "llvm-gcc -c $INFILE -o $OUTFILE"),
+ (cmd_line "llvm-gcc -c -x assembler $INFILE -o $OUTFILE"),
+ (switch_option "c", (stop_compilation)),
  (prefix_list_option "Wa", (unpack_values), (help "pass options to assembler"))
 ]>;
 
@@ -85,4 +88,5 @@
      LangToSuffixes<"llvm-assembler", ["ll"]>,
      LangToSuffixes<"llvm-bitcode", ["bc"]>,
      LangToSuffixes<"object-code", ["o"]>,
-     LangToSuffixes<"executable", ["out"]>]>;
+     LangToSuffixes<"executable", ["out"]>
+     ]>;





More information about the llvm-commits mailing list