From a876fa7367341b5af53cb3159385aa304eb46887 Mon Sep 17 00:00:00 2001 From: Michal Sojka Date: Sun, 25 Oct 2015 22:09:21 +0100 Subject: [PATCH] kconfig2sat: Implement --varopt --- kconfig2sat/kconfig2sat.cc | 67 +++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 26 deletions(-) diff --git a/kconfig2sat/kconfig2sat.cc b/kconfig2sat/kconfig2sat.cc index fa65b8c..07c9c83 100644 --- a/kconfig2sat/kconfig2sat.cc +++ b/kconfig2sat/kconfig2sat.cc @@ -14,6 +14,7 @@ #include #include #include +#include using namespace std; @@ -195,6 +196,32 @@ void do_dump() } } +void mark_symbol_variable(const char *sym_name, const char *file, int lineno) +{ + struct symbol *sym = sym_find(sym_name); + if (!sym) { + fprintf(stderr, "%s:%d: Error: Invalid symbol: %s\n", file, lineno, sym_name); + exit(EXIT_FAILURE); + } +// if (!(sym->flags & SYMBOL_WRITE)) { +// fprintf(stderr, "%s:%d: Error: Symbol %s not visible\n", varfile, lineno, sym_name); +// exit(EXIT_FAILURE); +// } + if (sym->flags & (SYMBOL_CHOICEVAL | SYMBOL_CHOICE)) { + fprintf(stderr, "%s:%d: Error: Choice values not yet supported: %s", file, lineno, sym_name); + exit(EXIT_FAILURE); + } + struct property *prop; + const char *prompt = NULL; + for_all_properties(sym, prop, P_PROMPT) { + prompt = prop->text; + } + if (!prompt) { + fprintf(stderr, "%s:%d: Warning: Symbol %s is internal (has no prompt)\n", file, lineno, sym_name); + } + sym->lcp.variable = 1; +} + void read_varfile(const char *varfile) { FILE *f = fopen(varfile, "r"); @@ -216,28 +243,7 @@ void read_varfile(const char *varfile) p += strlen(CONFIG_); const char *sym_name = strtok(p, " =\n"); - struct symbol *sym = sym_find(sym_name); - if (!sym) { - fprintf(stderr, "%s:%d: Error: Invalid symbol: %s\n", varfile, lineno, sym_name); - exit(EXIT_FAILURE); - } -// if (!(sym->flags & SYMBOL_WRITE)) { -// fprintf(stderr, "%s:%d: Error: Symbol %s not visible\n", varfile, lineno, sym_name); -// exit(EXIT_FAILURE); -// } - if (sym->flags & (SYMBOL_CHOICEVAL | SYMBOL_CHOICE)) { - fprintf(stderr, "%s:%d: Error: Choice values not yet supported: %s", varfile, lineno, sym_name); - exit(EXIT_FAILURE); - } - struct property *prop; - const char *prompt = NULL; - for_all_properties(sym, prop, P_PROMPT) { - prompt = prop->text; - } - if (!prompt) { - fprintf(stderr, "%s:%d: Warning: Symbol %s is internal (has no prompt)\n", varfile, lineno, sym_name); - } - sym->lcp.variable = 1; + mark_symbol_variable(sym_name, varfile, lineno); } fclose(f); } @@ -945,6 +951,7 @@ int main(int argc, char **argv) char *kconfig = NULL; char *varfile = NULL; int dump = false; + deque varopts; while (1) { int option_index = 0; @@ -957,7 +964,7 @@ int main(int argc, char **argv) {"help", no_argument, 0, OPT_HELP }, {"kconfig", required_argument, 0, OPT_KCONFIG }, {"varfile", required_argument, 0, OPT_VARFILE }, -// {"varopt", required_argument, 0, OPT_VAROPTION }, + {"varopt", required_argument, 0, OPT_VAROPTION }, {"verbose", no_argument, 0, OPT_VERBOSE }, {0, 0, 0, 0 } }; @@ -998,6 +1005,9 @@ int main(int argc, char **argv) case OPT_VARFILE: varfile = optarg; break; + case OPT_VAROPTION: + varopts.push_back(string(optarg)); + break; case '?': default: print_help(); @@ -1026,10 +1036,15 @@ int main(int argc, char **argv) if (baseconf) conf_read(baseconf); - if (varfile) - read_varfile(varfile); - else + if (!varfile && varopts.empty()) set_all_symbols_variable(); + else { + if (varfile) + read_varfile(varfile); + if (!varopts.empty()) + for (auto o: varopts) + mark_symbol_variable(o.c_str(), NULL, 0); + } mark_variable_expressions(); check_dep_consistency(); -- 2.39.2