8 #include <kconfig/lkc.h>
18 struct symlist *gsymlist;
24 int main(int argc, char **argv) {
27 for (i = 1; i < argc; i++) {
28 if (!strcmp(argv[i], "-v"))
30 else if (file == NULL)
32 else if (folder == NULL)
35 Eprintf("Unknown parameter: %s\n", argv[i]);
41 Eprintf("No Kconfig input file specified\n");
45 Eprintf("No output folder specified\n");
49 setlocale(LC_ALL, "");
50 bindtextdomain(PACKAGE, LOCALEDIR);
54 //sym_clear_all_valid();
56 gsymlist = symlist_create();
58 char *rules_file, *symbol_map_file, *variable_count_file;
59 asprintf(&rules_file, "%s/%s", folder, DEFAULT_RULES_FILE);
60 asprintf(&symbol_map_file, "%s/%s", folder, DEFAULT_SYMBOL_MAP_FILE);
61 asprintf(&variable_count_file, "%s/%s", folder,
62 DEFAULT_VARIABLE_COUNT_FILE);
63 output_init(rules_file, symbol_map_file);
68 output_write_variable_count(variable_count_file,
69 gsymlist->lastsym - 1, gsymlist->pos);
75 void build_symlist() {
78 struct property *prop;
79 for_all_symbols(i, sym) {
80 if (sym->type == S_BOOLEAN || sym->type == S_TRISTATE) {
81 if (sym->name == NULL)
82 asprintf(&sym->name, "NONAMEGEN%d", noname_num++);
84 symlist_add(gsymlist, sym->name);
87 symlist_closesym(gsymlist);
93 struct property *prop;
94 struct symlist_el *el;
96 struct boolexpr *boolsym;
97 for_all_symbols(i, sym) {
98 if (sym->type != S_BOOLEAN && sym->type != S_TRISTATE)
100 el_id = symlist_id(gsymlist, sym->name);
101 el = &(gsymlist->array[el_id - 1]);
102 boolsym = boolexpr_sym(gsymlist, sym, false, NULL);
103 Iprintf("Processing: %s\n", sym->name);
105 for_all_prompts(sym, prop) {
106 Dprintf(" Prompt: %s\n", prop->text);
107 if (prop->visible.expr != NULL) {
108 doutput_expr(prop->visible.expr);
109 struct boolexpr *vis =
110 boolexpr_kconfig(gsymlist, prop->visible.expr,
112 if (el->vis == NULL) {
115 el->vis = boolexpr_or(el->vis, vis);
117 } else if (el->vis == NULL) {
118 el->vis = boolexpr_true();
122 el->vis = boolexpr_false();
123 // Symbol is choice.. special treatment required
124 if (sym_is_choice(sym)) {
125 Dprintf(" Is Choice\n");
126 goto choice_exception;
129 struct boolexpr **defexpr = NULL;
130 size_t defexpr_size = 0;
132 bool exitdef = false;
133 for_all_defaults(sym, prop) {
134 Dprintf(" Default value:\n");
135 doutput_expr(prop->expr);
136 struct boolexpr *def =
137 boolexpr_kconfig(gsymlist, prop->expr, true, NULL);
138 struct boolexpr *vis;
139 if (prop->visible.expr != NULL)
140 vis = boolexpr_kconfig(gsymlist, prop->visible.expr,
143 vis = boolexpr_true();
144 if (vis->type != BT_TRUE) {
145 defexpr = realloc(defexpr,
146 ++defexpr_size * sizeof(struct boolexpr *));
147 defexpr[defexpr_size - 1] = boolexpr_copy(vis);
152 def = boolexpr_and(def, vis);
153 for (z = 0; z < ((int)defexpr_size - 1); z++) {
154 def = boolexpr_and(def, boolexpr_not(
155 boolexpr_copy(defexpr[z])));
160 el->def = boolexpr_or(el->def, def);
164 if (defexpr != NULL) {
165 for (z = 0; z < defexpr_size - 1; z++) {
166 boolexpr_free(defexpr[z]);
171 el->def = boolexpr_false();
172 // Dependency expression
173 if (sym->dir_dep.expr != NULL) {
174 Dprintf(" Dependency:\n");
175 doutput_expr(sym->dir_dep.expr);
177 boolexpr_kconfig(gsymlist, sym->dir_dep.expr, false, NULL);
179 el->dep = boolexpr_true();
180 // Reverse dependency expression
181 if (sym->rev_dep.expr != NULL) {
182 Dprintf(" Reverse dependency:\n");
183 doutput_expr(sym->rev_dep.expr);
185 boolexpr_kconfig(gsymlist, sym->rev_dep.expr, false, NULL);
187 el->rev_dep = boolexpr_false();
189 if (el->dep->type != BT_FALSE && el->dep->type != BT_TRUE)
190 cnf_boolexpr(gsymlist, el->dep);
191 if (el->rev_dep->type != BT_FALSE
192 && el->rev_dep->type != BT_TRUE)
193 cnf_boolexpr(gsymlist, el->rev_dep);
194 if (el->def->type != BT_FALSE && el->def->type != BT_TRUE)
195 cnf_boolexpr(gsymlist, el->def);
196 if (el->vis->type != BT_FALSE && el->vis->type != BT_TRUE)
197 cnf_boolexpr(gsymlist, el->vis);
198 // (!sym || dep) && (sym || !rev_dep) &&
199 // && (sym || !dep || !def || vis) &&
200 // (!sym || rev_dep || def || vis)
201 if (el->dep->type != BT_TRUE) {
202 output_rules_symbol(-1 * boolsym->id);
203 if (el->dep->type != BT_FALSE) {
204 output_rules_symbol(el->dep->id);
206 output_rules_endterm();
208 if (el->rev_dep->type != BT_FALSE) {
209 output_rules_symbol(boolsym->id);
210 if (el->rev_dep->type != BT_TRUE) {
211 output_rules_symbol(-1 * el->rev_dep->id);
213 output_rules_endterm();
215 if (el->dep->type != BT_FALSE && el->def->type != BT_FALSE
216 && el->vis->type != BT_TRUE) {
217 output_rules_symbol(boolsym->id);
218 if (el->dep->type != BT_TRUE) {
219 output_rules_symbol(-1 * el->dep->id);
221 if (el->def->type != BT_TRUE) {
222 output_rules_symbol(-1 * el->def->id);
224 if (el->vis->type != BT_FALSE) {
225 output_rules_symbol(el->vis->id);
227 output_rules_endterm();
229 if (el->rev_dep->type != BT_TRUE && el->def->type != BT_TRUE
230 && el->vis->type != BT_TRUE) {
231 output_rules_symbol(-1 * boolsym->id);
232 if (el->rev_dep->type != BT_FALSE) {
233 output_rules_symbol(el->rev_dep->id);
235 if (el->def->type != BT_FALSE) {
236 output_rules_symbol(el->def->id);
238 if (el->vis->type != BT_FALSE) {
239 output_rules_symbol(el->vis->id);
241 output_rules_endterm();
244 boolexpr_free(el->def);
245 boolexpr_free(el->vis);
246 boolexpr_free(el->dep);
247 boolexpr_free(el->rev_dep);
252 // Add exclusive rules for choice symbol
253 if (sym->rev_dep.expr != NULL) {
254 Dprintf(" Dependency:\n");
255 doutput_expr(sym->rev_dep.expr);
257 boolexpr_kconfig(gsymlist, sym->rev_dep.expr, true, NULL);
259 el->rev_dep = boolexpr_true();
260 for_all_choices(sym, prop) {
263 unsigned *symx = NULL;
264 size_t symx_size = 0;
266 expr_list_for_each_sym(prop->expr, exprw, symw) {
268 symx = realloc(symx, symx_size * sizeof(unsigned));
269 symx[symx_size - 1] = symlist_id(gsymlist, symw->name);
270 output_rules_symbol(symx[symx_size - 1]);
272 output_rules_symbol(-(int)
274 output_rules_endterm();
275 for (x = 0; x < symx_size - 1; x++) {
276 for (y = x + 1; y < symx_size; y++) {
277 output_rules_symbol(-(int)
279 output_rules_symbol(-(int)
281 output_rules_endterm();
287 if (el->rev_dep->type != BT_FALSE && el->rev_dep->type != BT_TRUE)
288 cnf_boolexpr(gsymlist, el->rev_dep);
289 if (el->vis->type != BT_FALSE && el->vis->type != BT_TRUE)
290 cnf_boolexpr(gsymlist, el->vis);
291 // (!sym || rev_dep) && (!sym || !rev_dep || vis)
292 // For nonoptional per list symbol add:
293 // (sym || !rev_dep || !vis || !dir_dep_of_list))
294 if (el->rev_dep->type != BT_TRUE) {
295 output_rules_symbol(-1 * boolsym->id);
296 if (el->rev_dep->type != BT_FALSE) {
297 output_rules_symbol(el->rev_dep->id);
299 output_rules_endterm();
301 if (el->rev_dep->type != BT_FALSE && el->vis->type != BT_TRUE) {
302 output_rules_symbol(-1 * boolsym->id);
303 if (el->rev_dep->type != BT_TRUE) {
304 output_rules_symbol(-1 * el->rev_dep->id);
306 if (el->vis != BT_FALSE) {
307 output_rules_symbol(el->vis->id);
309 output_rules_endterm();
311 if (!sym_is_optional(sym)) {
312 for_all_choices(sym, prop) {
315 expr_list_for_each_sym(prop->expr, exprw, symw) {
316 struct boolexpr *wdep;
317 if (symw->dir_dep.expr != NULL) {
318 struct symbol *settrue[] = {sym, NULL};
320 boolexpr_kconfig(gsymlist, symw->dir_dep.expr,
323 wdep = boolexpr_true();
324 cnf_boolexpr(gsymlist, wdep);
325 if (el->rev_dep->type != BT_FALSE
326 && el->vis->type != BT_FALSE
327 && wdep->type != BT_FALSE) {
328 output_rules_symbol(boolsym->id);
329 if (el->rev_dep->type != BT_TRUE) {
330 output_rules_symbol(-1 * el->rev_dep->id);
332 if (el->vis->type != BT_TRUE) {
333 output_rules_symbol(-1 * el->vis->id);
335 if (wdep->type != BT_TRUE
336 && wdep->id != boolsym->id) {
337 output_rules_symbol(-1 * wdep->id);
339 output_rules_endterm();