Implemented switch_on edge property.
authorMikhail Glushenkov <foldr@codedgers.com>
Tue, 6 May 2008 17:22:03 +0000 (17:22 +0000)
committerMikhail Glushenkov <foldr@codedgers.com>
Tue, 6 May 2008 17:22:03 +0000 (17:22 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50729 91177308-0d34-0410-b5e6-96231b3b80d8

tools/llvmc2/Tools.td
utils/TableGen/LLVMCCConfigurationEmitter.cpp

index 4b84aef38557f266465d64def2cdb5a9c5eaad1b..67104ec2c7368f6af731e1d73b638c92306f6189 100644 (file)
@@ -38,6 +38,7 @@ def llvm_gcc_cpp : Tool<
 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")
 ]>;
index 606510ed0251ad7c8a536b76b54fa6a999826eb2..eb0755e3ddb7232db2eca5994bdf184fc1c70049 100644 (file)
@@ -58,6 +58,15 @@ std::string InitPtrToString(Init* ptr) {
   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 @@ struct GlobalOptionDescriptions {
   // 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 @@ public:
   // 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 @@ private:
     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 @@ void TypecheckGraph (Record* CompilationGraph,
 }
 
 // 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 @@ void EmitEdgeClasses (Record* CompilationGraph,
     O << "class Edge" << i << ": public Edge {\n"
       << "public:\n"
       << Indent1 << "Edge" << i << "() : Edge(\"" << B->getName()
-      << "\") {}\n";
-
-    O << Indent1 << "bool isEnabled() const { return true; }\n";
-
-    O << Indent1 << "bool isDefault() const { return false; }\n";
+      << "\") {}\n\n"
+      << Indent1 << "bool isEnabled() const {\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";
   }
 }