[llvm-commits] CVS: llvm/utils/TableGen/TableGen.cpp

Chris Lattner lattner at cs.uiuc.edu
Mon Jun 2 23:57:01 PDT 2003


Changes in directory llvm/utils/TableGen:

TableGen.cpp updated: 1.4 -> 1.5

---
Log message:

Make tablegen use more structured command line options



---
Diffs of the changes:

Index: llvm/utils/TableGen/TableGen.cpp
diff -u llvm/utils/TableGen/TableGen.cpp:1.4 llvm/utils/TableGen/TableGen.cpp:1.5
--- llvm/utils/TableGen/TableGen.cpp:1.4	Fri May 23 19:17:12 2003
+++ llvm/utils/TableGen/TableGen.cpp	Mon Jun  2 23:56:29 2003
@@ -3,9 +3,30 @@
 #include "CodeEmitterGen.h"
 #include <algorithm>
 
-static cl::opt<std::string> Class("class", cl::desc("Print Enum list for this class"));
-static cl::opt<bool>        Parse("parse");
-static cl::opt<bool>        GenEmitter("gen-emitter");
+enum ActionType {
+  PrintRecords,
+  GenEmitter,
+  PrintEnums,
+  Parse,
+};
+
+namespace {
+  cl::opt<ActionType>
+  Action(cl::desc("Action to perform:"),
+         cl::values(clEnumValN(PrintRecords, "print-records",
+                               "Print all records to stdout"),
+                    clEnumValN(GenEmitter, "gen-emitter",
+                               "Generate machine code emitter"),
+                    clEnumValN(PrintEnums, "print-enums",
+                               "Print enum values for a class"),
+                    clEnumValN(Parse, "parse",
+                               "Interpret machine code (testing only)"),
+                    0));
+
+  cl::opt<std::string>
+  Class("class", cl::desc("Print Enum list for this class"));
+}
+
 
 void ParseFile();
 
@@ -353,20 +374,15 @@
   cl::ParseCommandLineOptions(argc, argv);
   ParseFile();
 
-  if (Parse) {
-    ParseMachineCode();
-    return 0;
-  }
-
-  if (GenEmitter) {
-    CodeEmitterGen CEG(Records);
-    CEG.createEmitter(std::cout);
-    return 0;
-  }
-
-  if (Class == "") {
+  switch (Action) {
+  case Parse: ParseMachineCode(); break;
+  case GenEmitter:
+    CodeEmitterGen(Records).createEmitter(std::cout);
+    break;
+  case PrintRecords:
     std::cout << Records;           // No argument, dump all contents
-  } else {
+    break;
+  case PrintEnums:
     Record *R = Records.getClass(Class);
     if (R == 0) {
       std::cerr << "Cannot find class '" << Class << "'!\n";
@@ -381,6 +397,7 @@
       }
     }
     std::cout << "\n";
+    break;
   }
   return 0;
 }





More information about the llvm-commits mailing list