Nico Huber has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/30583
Change subject: util/kconfig: Implement Ada spec generation ......................................................................
util/kconfig: Implement Ada spec generation
Write Kconfig values into an Ada spec file alongside the usual C header.
Change-Id: Ic58e4e81179214ef66c26a8a8614fbb5794c6a9c Signed-off-by: Nico Huber nico.h@gmx.de --- M util/kconfig/confdata.c 1 file changed, 129 insertions(+), 1 deletion(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/83/30583/1
diff --git a/util/kconfig/confdata.c b/util/kconfig/confdata.c index fc4a07a..a4c602c 100644 --- a/util/kconfig/confdata.c +++ b/util/kconfig/confdata.c @@ -634,6 +634,99 @@ };
/* + * Ada spec printer + */ +static void +spec_print_symbol(FILE *fp, struct symbol *sym, const char *value, void *arg) +{ + switch (sym->type) { + case S_BOOLEAN: + case S_TRISTATE: + switch (*value) { + case 'n': + if (getenv("KCONFIG_NEGATIVES")) { + fprintf(fp, + " %-37s : constant boolean := false;\n", + sym->name); + } + break; + case 'm': + fprintf(fp, " %s_MODULE : constant boolean := true;\n", + sym->name); + break; + default: + fprintf(fp, " %-37s : constant boolean := true;\n", + sym->name); + break; + } + break; + case S_HEX: { + unsigned int hexlen; + + if (!value || (value[0] == '\0')) + value = "0"; + else if (value[0] == '0' && (value[1] == 'x' || value[1] == 'X')) + value += 2; + + fprintf(fp, " %-37s : constant := 16#", + sym->name); + for (hexlen = strlen(value); hexlen > 0;) { + const unsigned int len = hexlen % 4 ? : 4; + char quad[] = "0000"; + unsigned int i; + + for (i = 0; i < len; ++i) + quad[4 - len + i] = value[i]; + fprintf(fp, "%s", quad); + + value += len; + hexlen -= len; + if (hexlen > 0) + fprintf(fp, "_"); + } + fprintf(fp, "#;\n"); + break; + } + case S_INT: + if (!value || (value[0] == '\0')) + value = "0"; + fprintf(fp, " %-37s : constant := %s;\n", sym->name, value); + break; + case S_STRING: + fprintf(fp, " %-37s : constant string := %s;\n", sym->name, value); + break; + default: + break; + } +} + +static void +spec_print_comment(FILE *fp, const char *value, void *arg) +{ + const char *p = value; + size_t l; + + for (;;) { + l = strcspn(p, "\n"); + fprintf(fp, "--"); + if (l) { + fprintf(fp, " "); + xfwrite(p, l, 1, fp); + p += l; + } + fprintf(fp, "\n"); + if (*p++ == '\0') + break; + } +} + +static struct conf_printer spec_printer_cb = +{ + .print_symbol = spec_print_symbol, + .print_comment = spec_print_comment, +}; + +/* * Tristate printer * * This printer is used when generating the `include/config/tristate.conf' file. @@ -985,7 +1078,7 @@ { struct symbol *sym; const char *name; - FILE *out, *tristate, *out_h; + FILE *out, *tristate, *out_h, *out_ads; int i; int print_negatives;
@@ -1045,12 +1138,36 @@ return 1; }
+ char *tmpconfig_ads = malloc(PATH_MAX); + if (getenv("COREBOOT_BUILD_DIR")) { + sprintf(tmpconfig_ads, "%s/.tmpconfig_tristate.XXXXXX", + getenv("COREBOOT_BUILD_DIR")); + } else { + sprintf(tmpconfig_ads, ".tmpconfig_tristate.XXXXXX"); + } + if ((i = mkstemp(tmpconfig_ads)) == -1) + return 1; + out_ads = fdopen(i, "w"); + if (!out_ads) { + fclose(out_h); + fclose(out); + fclose(tristate); + return 1; + } + conf_write_heading(out, &kconfig_printer_cb, NULL);
conf_write_heading(tristate, &tristate_printer_cb, NULL);
conf_write_heading(out_h, &header_printer_cb, NULL);
+ conf_write_heading(out_ads, &spec_printer_cb, NULL); + + const char *package = getenv("KCONFIG_PACKAGE"); + if (!package) + package = "KConfig"; + fprintf(out_ads, "\npackage %s is\n\n", package); + for_all_symbols(i, sym) { sym_calc_value(sym); if (!sym->name) @@ -1072,11 +1189,22 @@ conf_write_symbol(tristate, sym, &tristate_printer_cb, print_negatives?NULL:(void *)1);
conf_write_symbol(out_h, sym, &header_printer_cb, NULL); + + conf_write_symbol(out_ads, sym, &spec_printer_cb, NULL); } + + fprintf(out_ads, "\nend %s;\n", package); + fclose(out); fclose(tristate); fclose(out_h); + fclose(out_ads);
+ name = getenv("KCONFIG_AUTOADS"); + if (!name) + name = "include/generated/autoconf.ads"; + if (rename(tmpconfig_ads, name)) + return 1; name = getenv("KCONFIG_AUTOHEADER"); if (!name) name = "include/generated/autoconf.h";
Patrick Georgi has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/30583 )
Change subject: util/kconfig: Implement Ada spec generation ......................................................................
Patch Set 2:
It's rather unlikely that this will ever land in upstream kconfig. Maybe a separate tool that converts kconfig output into ada is more reliable?
Nico Huber has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/30583 )
Change subject: util/kconfig: Implement Ada spec generation ......................................................................
Patch Set 2:
It's rather unlikely that this will ever land in upstream kconfig. Maybe a separate tool that converts kconfig output into ada is more reliable?
Well, I thought it's in in good company there with our other Kconfig changes. :) I can try a separate tool. Our `auto.conf` might have just enough type information left... not sure if I'd call it more reliable, though.
Matt DeVillier has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/30583 )
Change subject: util/kconfig: Implement Ada spec generation ......................................................................
Patch Set 2:
verified working with 30584/30585 on google/link
Nico Huber has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/30583 )
Change subject: util/kconfig: Implement Ada spec generation ......................................................................
Patch Set 2:
It's rather unlikely that this will ever land in upstream kconfig. Maybe a separate tool that converts kconfig output into ada is more reliable?
Well, I thought it's in in good company there with our other Kconfig changes. :) I can try a separate tool. Our `auto.conf` might have just enough type information left... not sure if I'd call it more reliable, though.
Alternative tool implemented in CB:31053
Nico Huber has abandoned this change. ( https://review.coreboot.org/c/coreboot/+/30583 )
Change subject: util/kconfig: Implement Ada spec generation ......................................................................
Abandoned
implemented as separate tool