add functions for command line handling
authorMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Fri, 31 Mar 2006 15:41:31 +0000 (15:41 +0000)
committerMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Fri, 31 Mar 2006 15:41:31 +0000 (15:41 +0000)
more comments added

ir/be/be.h
ir/be/bemain.c

index 17fe081..a12f9a5 100644 (file)
@@ -2,6 +2,19 @@
 #ifndef _BE_MAIN_H
 #define _BE_MAIN_H
 
+/**
+ * Register the Firm backend command line options.
+ */
+void be_opt_register(void);
+
+/**
+ * Parse one backend argument.
+ */
+int be_parse_arg(const char *arg);
+
+/**
+ * Initialize the Firm backend. Must be run BEFORE init_firm()!
+ */
 void be_init(void);
 
 /**
index 15c8118..51dcb5c 100644 (file)
@@ -145,23 +145,39 @@ void be_opt_register(void)
 #ifdef WITH_LIBCORE
        int i;
        lc_opt_entry_t *be_grp_ra;
+       static int run_once = 0;
+
+       if (! run_once) {
+               run_once    = 1;
+               be_grp_root = lc_opt_get_grp(firm_opt_get_root(), "be");
+               be_grp_ra   = lc_opt_get_grp(be_grp_root, "ra");
+
+               lc_opt_add_table(be_grp_root, be_main_options);
+
+               /* register allocator options */
+               for(i = 0; ra_items[i].name != NULL; ++i) {
+                       const be_ra_t *ra = ra_items[i].value;
+                       ra->register_options(be_grp_ra);
+               }
+
+               /* register isa options */
+               for(i = 0; isa_items[i].name != NULL; ++i) {
+                       const arch_isa_if_t *isa = isa_items[i].value;
+                       isa->register_options(be_grp_root);
+               }
+       }
+#endif /* WITH_LIBCORE */
+}
 
-       be_grp_root = lc_opt_get_grp(firm_opt_get_root(), "be");
-       be_grp_ra   = lc_opt_get_grp(be_grp_root, "ra");
-
-       lc_opt_add_table(be_grp_root, be_main_options);
+static int be_opt_error_handler(const char *prefix, const lc_opt_err_info_t *err)
+{
 
-       /* register allocator options */
-       for(i = 0; ra_items[i].name != NULL; ++i) {
-               const be_ra_t *ra = ra_items[i].value;
-               ra->register_options(be_grp_ra);
-       }
+}
 
-       /* register isa options */
-       for(i = 0; isa_items[i].name != NULL; ++i) {
-               const arch_isa_if_t *isa = isa_items[i].value;
-               isa->register_options(be_grp_root);
-       }
+/* Parse one argument. */
+int be_parse_arg(const char *arg) {
+#ifdef WITH_LIBCORE
+       return lc_opt_from_single_arg(be_grp_root, NULL, arg, be_opt_error_handler);
 #endif /* WITH_LIBCORE */
 }
 
@@ -212,7 +228,7 @@ static void be_done_env(be_main_env_t *env)
 }
 
 static void dump(int mask, ir_graph *irg, const char *suffix,
-                                void (*dumper)(ir_graph *, const char *))
+                 void (*dumper)(ir_graph *, const char *))
 {
        if(dump_flags & mask)
                be_dump(irg, suffix, dumper);