aboutsummaryrefslogtreecommitdiff
path: root/src/driver
diff options
context:
space:
mode:
authordos-reis <gdr@axiomatics.org>2010-11-30 14:47:54 +0000
committerdos-reis <gdr@axiomatics.org>2010-11-30 14:47:54 +0000
commit97f0a39f88241d2e1896c203e7559d56ef684409 (patch)
tree121787679e0a904458686bcab1f40b363b67773d /src/driver
parent816865ca0322b9d413aaf562cbf5dd648f9c1038 (diff)
downloadopen-axiom-97f0a39f88241d2e1896c203e7559d56ef684409.tar.gz
* driver/utils.cc: Commonalize some of option handling code.
Diffstat (limited to 'src/driver')
-rw-r--r--src/driver/utils.cc34
-rw-r--r--src/driver/utils.h6
2 files changed, 32 insertions, 8 deletions
diff --git a/src/driver/utils.cc b/src/driver/utils.cc
index 89e1ad4c..9bffe781 100644
--- a/src/driver/utils.cc
+++ b/src/driver/utils.cc
@@ -294,6 +294,30 @@ static void print_usage(void) {
print_line("Submit bug report to " PACKAGE_BUGREPORT);
}
+ // Map a option to the driver that implement that action.
+ struct DriverMap {
+ const char* action;
+ const Driver driver;
+ };
+
+ static const DriverMap driver_table[] = {
+ { "--script", script_driver },
+ { "--compile", compiler_driver },
+ { "--translate", compiler_driver },
+ { "--build-databases", compiler_driver },
+ { "--make", linker_driver },
+ };
+
+ // Obtain the driver that implement a specific action requested
+ // on command line.
+ static Driver
+ option_driver(const char* opt) {
+ for (int i = 0; i < length(driver_table); ++i)
+ if (strcmp(opt, driver_table[i].action) == 0)
+ return driver_table[i].driver;
+ return unknown_driver;
+ }
+
/* Determine driver to be used for executing `command'. */
Driver
preprocess_arguments(Command* command, int argc, char** argv)
@@ -331,14 +355,8 @@ preprocess_arguments(Command* command, int argc, char** argv)
else {
/* Apparently we will invoke the Core system; we need to
pass on this option. */
- if (strcmp(argv[i], "--script") == 0)
- driver = script_driver;
- else if(strcmp(argv[i], "--compile") == 0
- or strcmp(argv[i], "--translate") == 0
- or strcmp(argv[i], "--build-databases") == 0)
- driver = compiler_driver;
- else if (strcmp(argv[i], "--make") == 0)
- driver = linker_driver;
+ if (const Driver d = option_driver(argv[i]))
+ driver = d;
else {
if (argv[i][0] == '-')
/* Maybe option for the driver. */
diff --git a/src/driver/utils.h b/src/driver/utils.h
index 6c55f1c0..be31d208 100644
--- a/src/driver/utils.h
+++ b/src/driver/utils.h
@@ -100,6 +100,12 @@ namespace OpenAxiom {
void build_rts_options(Command*, Driver);
Driver preprocess_arguments(Command*, int, char**);
+
+ // Return the length of an array literal.
+ template<typename T, int N>
+ inline int length(T(&)[N]) {
+ return N;
+ }
}
#endif /* OPENAXIOM_UTILS_INCLUDED */