util: Add stub unit tests for the call types in the m5 utility.
[gem5.git] / util / m5 / src / m5.cc
index 59930e30c57aa279d8fc725170578a0d8c3443df..0e86817e18ce1c2b3672abc1c5a6dd412bfb9103 100644 (file)
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <cstdlib>
-#include <cstring>
-
 #include "args.hh"
 #include "call_type.hh"
-#include "commands.hh"
+#include "command.hh"
 #include "usage.hh"
 
 int
@@ -51,25 +48,17 @@ main(int argc, const char *argv[])
 {
     Args args(argc, argv);
 
-    if (!args.size())
-        usage();
-
     progname = args.pop("{progname}");
 
-    const DispatchTable &dt = CallType::detect(args).getDispatch();
-
     if (!args.size())
         usage();
 
-    const std::string &command = args.pop();
-
-    for (int i = 0; i < num_commands; ++i) {
-        if (command != command_table[i].name)
-            continue;
+    CallType *ct = CallType::detect(args);
+    if (!ct)
+        usage();
 
-        command_table[i].func(dt, args);
-        exit(0);
-    }
+    if (!Command::run(ct->getDispatch(), args))
+        usage();
 
-    usage();
+    exit(0);
 }