]> rtime.felk.cvut.cz Git - linux-conf-perf.git/commitdiff
kconfig2sat: More features
authorMichal Sojka <sojkam1@fel.cvut.cz>
Sun, 18 Oct 2015 16:51:36 +0000 (18:51 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Sun, 18 Oct 2015 16:51:36 +0000 (18:51 +0200)
kconfig2sat/kconfig2sat.cc

index 62edfedc53029ea5bfa04526cf9497d652e10e48..b1f056fa5eea024321cda6fafb3721a3de6caedf 100644 (file)
@@ -16,6 +16,7 @@ enum options {
        OPT__START = 256,
        OPT_BASECONFIG,
        OPT_CNF,
+       OPT_DUMP,
        OPT_ENV,
        OPT_HELP,
        OPT_KCONFIG,
@@ -26,15 +27,56 @@ enum options {
 
 void print_help()
 {
-        printf("kconfig2sat [ options ]\n"
+        printf("Usage: kconfig2sat [options/actions]\n"
                "\n"
                "Options:\n"
-               "-b, --baseconf <.config>  Linux .config file with base configuration\n"
-              "--env <.conf.mk>          .conf.mk file for setting variables such as ARCH\n"
-               "-k, --kconfig <Kconfig>   Kconfig file (with path)\n"
-               "--varfile <file>          File listing variable options (one option per line)\n"
-              "--cnf <file>              Generate CNF representation to <file>\n"
-               );
+               "  -b, --baseconf <.config>  Linux .config file with base configuration\n"
+               "  --env <.conf.mk>          Set env. variables such as ARCH from .conf.mk\n"
+               "  -k, --kconfig <Kconfig>   Kconfig file (with path)\n"
+               "  --varfile <file>          File listing variable options (one option per line)\n"
+               "\n"
+               "Actions:\n"
+               "  --dump                    Dump internal data (for debugging)\n"
+               "  --cnf <file>              Generate CNF representation to <file>\n"
+                );
+}
+
+void do_dump()
+{
+    int i;
+    struct symbol *sym;
+    struct property *prop;
+    for_all_symbols(i, sym) {
+           const char *name = sym->name;
+           const char *type = NULL;
+           const char *prompt = NULL;
+           char val = '.';
+
+           switch (sym->type) {
+#define P(t) case t: type = #t; break
+                   P(S_UNKNOWN);
+                   P(S_BOOLEAN);
+                   P(S_TRISTATE);
+                   P(S_INT);
+                   P(S_HEX);
+                   P(S_STRING);
+                   P(S_OTHER);
+#undef P
+           }
+           if (sym->type == S_BOOLEAN || sym->type == S_TRISTATE) {
+                   switch (sym->curr.tri) {
+                   case no:  val = 'n'; break;
+                   case mod: val = 'm'; break;
+                   case yes: val = 'y'; break;
+                   }
+           }
+
+           for_all_properties(sym, prop, P_PROMPT) {
+                   prompt = prop->text;
+           }
+
+           printf("%-40s %c %-10s %s\n", name, val, type, prompt);
+    }
 }
 
 int main(int argc, char **argv)
@@ -45,19 +87,21 @@ int main(int argc, char **argv)
        char *cnf = NULL;
        char *kconfig = NULL;
        char *varfile = NULL;
+       int  dump = false;
 
        while (1) {
                int option_index = 0;
                static struct option long_options[] = {
-                       {"baseconf",    required_argument, 0,  OPT_BASECONFIG },
-                       {"cnf",         required_argument, 0,  OPT_CNF },
-                       {"env",         required_argument, 0,  OPT_ENV },
-                       {"help",        no_argument,       0,  OPT_HELP },
-                       {"kconfig",     required_argument, 0,  OPT_KCONFIG },
-                       {"varfile",     required_argument, 0,  OPT_VARFILE },
-//                     {"varopt",      required_argument, 0,  OPT_VAROPTION },
-                       {"verbose",     no_argument,       0,  OPT_VERBOSE },
-                       {0,             0,                 0,  0 }
+                       {"baseconf",    required_argument, 0,     OPT_BASECONFIG },
+                       {"cnf",         required_argument, 0,     OPT_CNF },
+                       {"env",         required_argument, 0,     OPT_ENV },
+                       {"dump",        no_argument,       &dump, true },
+                       {"help",        no_argument,       0,     OPT_HELP },
+                       {"kconfig",     required_argument, 0,     OPT_KCONFIG },
+                       {"varfile",     required_argument, 0,     OPT_VARFILE },
+//                     {"varopt",      required_argument, 0,     OPT_VAROPTION },
+                       {"verbose",     no_argument,       0,     OPT_VERBOSE },
+                       {0,             0,                 0,     0 }
                };
 
                c = getopt_long(argc, argv, "b:hk:v",
@@ -66,6 +110,8 @@ int main(int argc, char **argv)
                        break;
 
                switch (c) {
+               case 0: /* long option with flag != NULL */
+                       break;
                case 'b':
                case OPT_BASECONFIG:
                        baseconf = optarg;
@@ -117,6 +163,12 @@ int main(int argc, char **argv)
 
        conf_parse_path(kconfig);
 
+       if (baseconf)
+               conf_read(baseconf);
+
+       if (dump)
+               do_dump();
+
 //     char *rules_file, *symbol_map_file, *variable_count_file;
 //     asprintf(&rules_file, "%s/%s", folder, DEFAULT_RULES_FILE);
 //     asprintf(&symbol_map_file, "%s/%s", folder, DEFAULT_SYMBOL_MAP_FILE);