8 #include <kconfig/lkc.h>
9 #include <build_files.h>
15 #define STRINGIFY(val) #val
16 #define TOSTRING(val) STRINGIFY(val)
17 #define CHECK(cmd) ({ int ret = (cmd); if (ret == -1) { perror(#cmd " line " TOSTRING(__LINE__)); exit(1); }; ret; })
18 #define CHECKPTR(cmd) ({ void *ptr = (cmd); if (ptr == (void*)-1) { perror(#cmd " line " TOSTRING(__LINE__)); exit(1); }; ptr; })
19 #define CHECKNULL(cmd) ({ void *ptr = (cmd); if (ptr == NULL) { perror(#cmd " line " TOSTRING(__LINE__)); exit(1); }; ptr; })
21 #define ARRAY_SIZE(x) (sizeof(x)/sizeof(*(x)))
27 /* char *input_config_file; */
29 const char *interesting_opts[] = {
31 "BRANCH_PROFILE_NONE",
35 "ENABLE_DEFAULT_TRACERS",
36 "EVENT_TRACE_TEST_SYSCALLS",
38 "FTRACE_MCOUNT_RECORD",
40 "FTRACE_STARTUP_TEST",
42 "FUNCTION_GRAPH_TRACER",
47 "HIBERNATE_CALLBACKS",
55 "MISSED_TIMER_OFFSETS_HIST",
71 "PROFILE_ANNOTATED_BRANCHES",
72 "RING_BUFFER_ALLOW_SWAP",
73 "RING_BUFFER_BENCHMARK",
74 "RING_BUFFER_STARTUP_TEST",
79 "TRACER_SNAPSHOT_PER_CPU_SWAP",
80 "TRACE_BRANCH_PROFILING",
83 "WAKEUP_LATENCY_HIST",
84 "WQ_POWER_EFFICIENT_DEFAULT",
87 bool is_interesting(struct symbol *sym)
94 for (i = 0; i < ARRAY_SIZE(interesting_opts); i++) {
95 if (strcmp(sym->name, interesting_opts[i]) == 0)
103 void print_expr(FILE *f, struct expr *e, const char *parent, const char *suffix, const char *edge_opts);
104 void print_symbol(FILE *f, struct symbol *sym);
107 void print_oper(FILE *f, struct expr *e, const char *parent, const char *label)
110 static set<string> seen_expr;
112 fprintf(f, "\"%s\" -> \"%s\";\n", parent, e->id);
114 if (seen_expr.find(e->id) == seen_expr.end()) {
115 seen_expr.insert(e->id);
116 fprintf(f, "\"%s\" [shape=diamond,label=\"%s\"];\n", e->id, label);
117 print_expr(f, e->left.expr, e->id, "l", "");
118 print_expr(f, e->right.expr, e->id, "r", "");
122 void print_expr(FILE *f, struct expr *e, const char *parent, const char *suffix, const char *edge_opts)
129 print_oper(f, e, parent, "|");
132 print_oper(f, e, parent, "&");
135 print_expr(f, e->left.expr, parent, suffix, "arrowhead=odot");
138 print_oper(f, e, parent, "=");
141 print_oper(f, e, parent, "!=");
147 if (e->left.sym->name) {
148 fprintf(f, "\"%s\" -> \"%s\" [%s];\n", parent, e->left.sym->name, edge_opts);
149 print_symbol(f, e->left.sym);
160 void print_symbol(FILE *f, struct symbol *sym)
162 #define SYMBOL_PRINTED 0x80000000
163 if (sym->flags & SYMBOL_PRINTED)
165 sym->flags |= SYMBOL_PRINTED;
167 const char *opts = "";
168 if (is_interesting(sym))
169 opts = " [penwidth=3]";
171 opts = " [color=gray]";
172 fprintf(f, "\"%s\"%s;\n", sym->name, opts);
173 print_expr(f, sym->dir_dep.expr, sym->name, "", "");
174 if (sym->rev_dep.expr) {
175 // TODO: revese dependencies
176 // printf("REVDEP %s: %s\n", sym->name, sym->rev_dep.expr->id);
177 // print_expr(f, sym->rev_dep.expr, sym->name, "", "color=green");
182 void generate_expr_id(struct expr *e);
184 void generate_expr_id_oper(struct expr *e, const char *op_str)
186 generate_expr_id(e->left.expr);
187 generate_expr_id(e->right.expr);
188 asprintf(&e->id, "(%s %s %s)", e->left.expr->id, op_str, e->right.expr->id);
191 void generate_expr_id(struct expr *e)
198 generate_expr_id_oper(e, "||");
201 generate_expr_id_oper(e, "&&");
204 generate_expr_id(e->left.expr);
205 asprintf(&e->id, "!%s", e->left.expr->id);
208 generate_expr_id_oper(e, "==");
211 generate_expr_id_oper(e, "!=");
214 printf("LIST not implemented\n");
217 if (e->left.sym->name && !e->id) {
218 asprintf(&e->id, e->left.sym->name);
219 generate_expr_id(e->left.sym->dir_dep.expr);
220 generate_expr_id(e->left.sym->rev_dep.expr);
225 printf("RANGE not implemented\n");
231 void generate_expr_ids()
236 for_all_symbols(i, sym) {
237 if ((sym->type == S_BOOLEAN || sym->type == S_TRISTATE)
238 && sym->name != NULL) {
239 if (is_interesting(sym)) {
240 generate_expr_id(sym->dir_dep.expr);
241 generate_expr_id(sym->rev_dep.expr);
248 int main(int argc, char **argv)
252 for (i = 1; i < argc; i++) {
253 if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h")) {
256 } else if (!strcmp(argv[i], "-v") || !strcmp(argv[i], "--verbose")) {
258 /* } else if (!strcmp(argv[i], "--all")) { */
259 /* full_config = true; */
260 /* } else if (!strcmp(argv[i], "--inv")) { */
261 /* inv_config = true; */
262 } else if (kconfig_file == NULL) {
263 kconfig_file = argv[i];
264 } else if (dot_file == NULL) {
266 /* } else if (output_config_file == NULL) { */
267 /* output_config_file = argv[i]; */
269 Eprintf("Unknown parameter: %s\n", argv[i]);
274 if (dot_file == NULL || kconfig_file == NULL
275 /* || input_config_file == NULL */) {
276 Eprintf("Missing mandatroy arguments.\n");
281 setlocale(LC_ALL, "");
282 bindtextdomain(PACKAGE, LOCALEDIR);
285 setenv("ARCH", "powerpc", /*overwrite*/0);
286 setenv("KERNELVERSION", "1.2.3", /*overwrite*/0);
287 setenv("SRCARCH", "powerpc", /*overwrite*/0);
290 if (strcmp(dot_file, "-") == 0) {
293 f = fopen(dot_file, "w");
300 char *slash = strrchr(kconfig_file, '/');
303 if (chdir(kconfig_file)) {
304 perror(kconfig_file);
307 kconfig_file = slash + 1;
310 conf_parse(kconfig_file);
311 /* conf_read(input_config_file); */
315 fprintf(f, "digraph conf {\n");
318 for_all_symbols(i, sym) {
319 if ((sym->type == S_BOOLEAN || sym->type == S_TRISTATE)
320 && sym->name != NULL) {
321 if (is_interesting(sym)) {
322 print_symbol(f, sym);
335 ("Usage: allconfig [-v] [-h] [--all] [--inv] Kconfig Input Output\n");
336 printf(" This is generating full configuration.\n");
337 printf(" Output configuration has all configuration options.\n");
339 printf(" Options:\n");
340 printf(" -v, --verbose Increase level of verbose output.\n");
341 printf(" -h, --help Print this help text.\n");
343 (" --all Genetate full configuration. Including non dependency\n");
344 printf(" configuration options");
346 (" --inv Generate configuration of missing configratuon options.\n");
349 /* Local Variables: */
350 /* c-basic-offset: 4 */