aboutsummaryrefslogtreecommitdiff
path: root/programs/src/kconfig_parser/output.c
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2015-03-22 18:53:50 +0100
committerKarel Kočí <cynerd@email.cz>2015-03-22 18:53:50 +0100
commite0b3ecbe06cb47d14ee64dbf1bdbd9cbc27ac648 (patch)
treea66c17e6a0253c966691d363dc32d7551464177a /programs/src/kconfig_parser/output.c
parent3e149e0d540e359ba66668452b8c137bfcb3112c (diff)
downloadlinux-conf-perf-e0b3ecbe06cb47d14ee64dbf1bdbd9cbc27ac648.tar.gz
linux-conf-perf-e0b3ecbe06cb47d14ee64dbf1bdbd9cbc27ac648.tar.bz2
linux-conf-perf-e0b3ecbe06cb47d14ee64dbf1bdbd9cbc27ac648.zip
kconfig_parser rewritten and now supports revers dependency
Most of the kconfig_parser is changed. Now dependency are not copied before transfer to CNF and CNF expression is direcly extracted from kconfíg parsed output structures.
Diffstat (limited to 'programs/src/kconfig_parser/output.c')
-rw-r--r--programs/src/kconfig_parser/output.c85
1 files changed, 32 insertions, 53 deletions
diff --git a/programs/src/kconfig_parser/output.c b/programs/src/kconfig_parser/output.c
index 5f8bbd6..942693b 100644
--- a/programs/src/kconfig_parser/output.c
+++ b/programs/src/kconfig_parser/output.c
@@ -1,80 +1,59 @@
#include "output.h"
-void fprint_rules(struct symlist *sl, char* output) {
+void fprint_rules_cnf(FILE * f, unsigned id, struct cnfexpr *cnf) {
+ unsigned i, y;
+ switch (cnf->type) {
+ case CT_FALSE:
+ // Never satisfiable
+ fprintf(f, "-%d\n", id);
+ break;
+ case CT_TRUE:
+ // Always satisfiable
+ break;
+ case CT_EXPR:
+ for (i = 0; i < cnf->size; i++) {
+ fprintf(f, "-%d ", id);
+ for (y = 0; y < cnf->sizes[i] - 1; y++) {
+ fprintf(f, "%d ", cnf->exprs[i][y]);
+ }
+ fprintf(f, "%d ", cnf->exprs[i][cnf->sizes[i] - 1]);
+ fprintf(f, "\n");
+ }
+ break;
+ }
+}
+
+void fprint_rules(struct symlist *sl, char *output) {
FILE *f;
f = fopen(output, "w");
if (f == NULL) {
fprintf(stderr, "Can't create file: %s\n", output);
return;
}
- int i;
+ size_t i;
struct symlist_el *el;
- struct boolexp *be;
- struct boolexp **stack;
- size_t stack_size = 2, stack_pos = 0;
- int count_or, count_and;
- stack = malloc(stack_size * sizeof(struct boolexp *));
for (i = 0; i < sl->pos; i++) {
if (sl->array[i].be != NULL) {
el = sl->array + i;
- be = el->be;
- stack_pos = 0;
- count_or = 0;
- count_and = 0;
- fprintf(f, "-%d ", el->id);
- while (be != NULL) {
- if (stack_pos >= stack_size) {
- stack_size *= 2;
- stack =
- realloc(stack,
- stack_size * sizeof(struct boolexp *));
- }
- switch (be->type) {
- case BE_NOT:
- fprintf(f, "-");
- be = be->left.be;
- break;
- case BE_AND:
- count_and++;
- stack[stack_pos++] = be->right.be;
- be = be->left.be;
- break;
- case BE_OR:
- count_or++;
- stack[stack_pos++] = be->right.be;
- be = be->left.be;
- break;
- case BE_LEAF:
- fprintf(f, "%d", be->left.id);
- if (count_or > 0) {
- fprintf(f, " ");
- count_or--;
- } else if (count_and > 0) {
- fprintf(f, "\n-%d ", el->id);
- count_and--;
- }
- if (stack_pos > 0)
- be = stack[--stack_pos];
- else
- be = NULL;
- break;
- }
+ if (el->be != NULL) {
+ fprint_rules_cnf(f, el->id, el->be);
+ }
+ if (el->re_be != NULL) {
+ fprint_rules_cnf(f, el->id, el->be);
}
- fprintf(f, "\n");
}
}
- free(stack);
fclose(f);
}
-void fprint_symbol_map(struct symlist *sl, char* output) {
+void fprint_symbol_map(struct symlist *sl, char *output) {
FILE *f;
f = fopen(output, "w");
if (f == NULL) {
fprintf(stderr, "Can't create file: %s\n", output);
return;
}
- int i;
+ size_t i;
for (i = 0; i < sl->pos; i++) {
fprintf(f, "%d:%s\n", sl->array[i].id, sl->array[i].name);
}