Add a generalised 'case' construct.

Besides assigning edge weights, it will also be used by the cmd_line tool property.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@51727 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/llvmc2/Common.td b/tools/llvmc2/Common.td
index b04596f..2a6b54e 100644
--- a/tools/llvmc2/Common.td
+++ b/tools/llvmc2/Common.td
@@ -45,19 +45,26 @@
 def help;
 def required;
 
-// Possible edge properties
+// Marker for an empty DAG.
+def empty;
 
-// 'Atomic' properties.
+// The 'case' construct.
+def case;
+
+// Primitive tests.
 def switch_on;
 def parameter_equals;
 def element_in_list;
-def if_input_languages_contain;
+def input_languages_contain;
 
-// Edge property combinators.
-def weight;
+// Boolean operators.
 def and;
 def or;
 
+// Increase/decrease the edge weight.
+def inc_weight;
+def dec_weight;
+
 // Map from suffixes to language names
 
 class LangToSuffixes<string str, list<string> lst> {
@@ -71,19 +78,19 @@
 
 // Compilation graph
 
-class EdgeBase<Tool t1, Tool t2, list<dag> lst> {
+class EdgeBase<Tool t1, Tool t2, dag d> {
       Tool a = t1;
       Tool b = t2;
-      list<dag> props = lst;
+      dag weight = d;
 }
 
-class Edge<Tool t1, Tool t2> : EdgeBase<t1, t2, []>;
+class Edge<Tool t1, Tool t2> : EdgeBase<t1, t2, (empty)>;
 
 // Edge and SimpleEdge are synonyms.
-class SimpleEdge<Tool t1, Tool t2> : EdgeBase<t1, t2, []>;
+class SimpleEdge<Tool t1, Tool t2> : EdgeBase<t1, t2, (empty)>;
 
 // Optionally enabled edge.
-class OptionalEdge<Tool t1, Tool t2, list<dag> lst> : EdgeBase<t1, t2, lst>;
+class OptionalEdge<Tool t1, Tool t2, dag props> : EdgeBase<t1, t2, props>;
 
 class CompilationGraph<list<EdgeBase> lst> {
       list<EdgeBase> edges = lst;
diff --git a/tools/llvmc2/Graph.td b/tools/llvmc2/Graph.td
index 6fb998b..5c2902e 100644
--- a/tools/llvmc2/Graph.td
+++ b/tools/llvmc2/Graph.td
@@ -26,22 +26,24 @@
     Edge<llvm_gcc_cpp, llc>,
     Edge<llvm_as, llc>,
 
-    OptionalEdge<llvm_gcc_c, opt, [(switch_on "opt")]>,
-    OptionalEdge<llvm_gcc_cpp, opt, [(switch_on "opt")]>,
-    OptionalEdge<llvm_as, opt, [(switch_on "opt")]>,
+    OptionalEdge<llvm_gcc_c, opt, (case (switch_on "opt"), (inc_weight))>,
+    OptionalEdge<llvm_gcc_cpp, opt, (case (switch_on "opt"), (inc_weight))>,
+    OptionalEdge<llvm_as, opt, (case (switch_on "opt"), (inc_weight))>,
     Edge<opt, llc>,
 
     Edge<llc, llvm_gcc_assembler>,
     Edge<llvm_gcc_assembler, llvm_gcc_linker>,
     OptionalEdge<llvm_gcc_assembler, llvm_gcc_cpp_linker,
-                 [(if_input_languages_contain "c++"),
-                  (or (parameter_equals "linker", "g++"),
-                      (parameter_equals "linker", "c++"))]>,
+                 (case
+                     (input_languages_contain "c++"), (inc_weight),
+                     (or (parameter_equals "linker", "g++"),
+                         (parameter_equals "linker", "c++")), (inc_weight))>,
 
 
     Edge<root, llvm_gcc_linker>,
     OptionalEdge<root, llvm_gcc_cpp_linker,
-                 [(if_input_languages_contain "c++"),
-                  (or (parameter_equals "linker", "g++"),
-                      (parameter_equals "linker", "c++"))]>
+                 (case
+                     (input_languages_contain "c++"), (inc_weight),
+                     (or (parameter_equals "linker", "g++"),
+                         (parameter_equals "linker", "c++")), (inc_weight))>
     ]>;
diff --git a/tools/llvmc2/Makefile b/tools/llvmc2/Makefile
index 0c4782b..04cd954 100644
--- a/tools/llvmc2/Makefile
+++ b/tools/llvmc2/Makefile
@@ -14,15 +14,15 @@
 
 include $(LEVEL)/Makefile.common
 
-GRAPH = Graph.td
-TOOLS_SOURCE=$(GRAPH) Tools.td Common.td
+GRAPH=Graph.td
+TOOLS=Tools.td
+TOOLS_SOURCE=$(GRAPH) $(TOOLS) Common.td
 
 # TOFIX: integrate this part into Makefile.rules?
 # The degree of horrorshowness in that file is too much for me atm.
-$(ObjDir)/AutoGenerated.inc.tmp: $(TOOLS_SOURCE) $(ObjDir)/.dir
-	$(Echo) "Building LLVMCC configuration library with tblgen"
+$(ObjDir)/AutoGenerated.inc.tmp: $(TOOLS_SOURCE) $(ObjDir)/.dir $(TBLGEN)
+	$(Echo) "Building LLVMC configuration library with tblgen"
 	$(Verb) $(TableGen) -gen-llvmc -o $(call SYSPATH, $@) $<
 
 AutoGenerated.inc : $(ObjDir)/AutoGenerated.inc.tmp
 	$(Verb) $(CMP) -s $@ $< || $(CP) $< $@
-