[llvm-commits] [llvm] r50729 - in /llvm/trunk: tools/llvmc2/Tools.td utils/TableGen/LLVMCCConfigurationEmitter.cpp

Mikhail Glushenkov foldr at codedgers.com
Tue May 6 10:22:03 PDT 2008


Author: foldr
Date: Tue May  6 12:22:03 2008
New Revision: 50729

URL: http://llvm.org/viewvc/llvm-project?rev=50729&view=rev
Log:
Implemented switch_on edge property.

Modified:
    llvm/trunk/tools/llvmc2/Tools.td
    llvm/trunk/utils/TableGen/LLVMCCConfigurationEmitter.cpp

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

==============================================================================
--- llvm/trunk/tools/llvmc2/Tools.td (original)
+++ llvm/trunk/tools/llvmc2/Tools.td Tue May  6 12:22:03 2008
@@ -38,6 +38,7 @@
 def opt : Tool<
 [(in_language "llvm-bitcode"),
  (out_language "llvm-bitcode"),
+ (switch_option "opt", (help "Enable opt")),
  (output_suffix "bc"),
  (cmd_line "opt $INFILE -o $OUTFILE")
 ]>;

Modified: llvm/trunk/utils/TableGen/LLVMCCConfigurationEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/LLVMCCConfigurationEmitter.cpp?rev=50729&r1=50728&r2=50729&view=diff

==============================================================================
--- llvm/trunk/utils/TableGen/LLVMCCConfigurationEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/LLVMCCConfigurationEmitter.cpp Tue May  6 12:22:03 2008
@@ -58,6 +58,15 @@
   return val.getValue();
 }
 
+// Ensure that the number of args in d is <= min_arguments,
+// throw exception otherwise
+void checkNumberOfArguments (const DagInit* d, unsigned min_arguments) {
+  if (d->getNumArgs() < min_arguments)
+    throw "Property " + d->getOperator()->getAsString()
+      + " has too few arguments!";
+}
+
+
 //===----------------------------------------------------------------------===//
 /// Back-end specific code
 
@@ -187,6 +196,14 @@
   // Should the emitter generate a "cl::sink" option?
   bool HasSink;
 
+  const GlobalOptionDescription& FindOption(const std::string& OptName) const {
+    const_iterator I = Descriptions.find(OptName);
+    if (I != Descriptions.end())
+      return I->second;
+    else
+      throw OptName + ": no such option!";
+  }
+
   // Support for STL-style iteration
   const_iterator begin() const { return Descriptions.begin(); }
   const_iterator end() const { return Descriptions.end(); }
@@ -358,7 +375,7 @@
   // Just forwards to the corresponding property handler.
   void operator() (Init* i) {
     DagInit& d = dynamic_cast<DagInit&>(*i);
-    std::string property_name = d.getOperator()->getAsString();
+    const std::string& property_name = d.getOperator()->getAsString();
     PropertyHandlerMap::iterator method
       = propertyHandlers_.find(property_name);
 
@@ -470,14 +487,6 @@
     insertDescription(o);
   }
 
-  // Ensure that the number of args in d is <= min_arguments,
-  // throw exception otherwise
-  void checkNumberOfArguments (DagInit* d, unsigned min_arguments) {
-    if (d->getNumArgs() < min_arguments)
-      throw "Property " + d->getOperator()->getAsString()
-        + " has too few arguments!";
-  }
-
   // Insert new GlobalOptionDescription into GlobalOptionDescriptions list
   void insertDescription (const GlobalOptionDescription& o)
   {
@@ -897,7 +906,6 @@
 }
 
 // Emit Edge* classes that represent edges in the graph.
-// TOFIX: add edge properties.
 void EmitEdgeClasses (Record* CompilationGraph,
                       const GlobalOptionDescriptions& OptDescs,
                       std::ostream& O) {
@@ -914,13 +922,42 @@
     O << "class Edge" << i << ": public Edge {\n"
       << "public:\n"
       << Indent1 << "Edge" << i << "() : Edge(\"" << B->getName()
-      << "\") {}\n";
+      << "\") {}\n\n"
+      << Indent1 << "bool isEnabled() const {\n";
 
-    O << Indent1 << "bool isEnabled() const { return true; }\n";
-
-    O << Indent1 << "bool isDefault() const { return false; }\n";
+    for (unsigned i = 0; i < Props->size(); ++i) {
+      const DagInit& Prop = dynamic_cast<DagInit&>(*Props->getElement(i));
+      const std::string& PropName = Prop.getOperator()->getAsString();
+
+      if (PropName == "switch_on") {
+        checkNumberOfArguments(&Prop, 1);
+        const std::string& OptName = InitPtrToString(Prop.getArg(0));
+        const GlobalOptionDescription& OptDesc = OptDescs.FindOption(OptName);
+        if (OptDesc.Type != OptionType::Switch)
+          throw OptName + ": incorrect option type!";
+        O << Indent2 << "if (" << OptDesc.GenVariableName() << ")\n"
+          << Indent3 << "return true;\n";
+      }
+      else if (PropName == "parameter_equals") {
+        checkNumberOfArguments(&Prop, 2);
+        throw PropName + ": not implemented!";
+      }
+      else if (PropName == "element_in_list") {
+        checkNumberOfArguments(&Prop, 2);
+        throw PropName + ": not implemented!";
+      }
+      else if (PropName == "or") {
+        throw PropName + ": not implemented!";
+      }
+      else {
+        throw "No such edge property: " + PropName;
+      }
+    }
 
-    O << "};\n\n";
+    O << Indent2 << "return false;\n"
+      << Indent1 << "};\n\n"
+      << Indent1 << "bool isDefault() const { return false; }\n"
+      << "};\n\n";
   }
 }
 





More information about the llvm-commits mailing list