[coreboot-gerrit] Change in coreboot[master]: util/sconfig: Re-factor emitting of headers to static.c

Furquan Shaikh (Code Review) gerrit at coreboot.org
Thu May 31 08:49:24 CEST 2018


Furquan Shaikh has uploaded this change for review. ( https://review.coreboot.org/26726


Change subject: util/sconfig: Re-factor emitting of headers to static.c
......................................................................

util/sconfig: Re-factor emitting of headers to static.c

This change removes call to add_header from parsing functions and
moves it to a local function within main.c. It also adds a new
function emit_headers that is responsible for creating the linked list
for chip headers and emitting those to static.c

BUG=b:80081934
TEST=Verified that static.c for all files compiled using abuild is the
same with and without this change.

Change-Id: I24d526e81323115d3cc927242a4b9e49414afbe0
Signed-off-by: Furquan Shaikh <furquan at google.com>
---
M util/sconfig/main.c
M util/sconfig/sconfig.h
M util/sconfig/sconfig.tab.c_shipped
M util/sconfig/sconfig.y
4 files changed, 62 insertions(+), 56 deletions(-)



  git pull ssh://review.coreboot.org:29418/coreboot refs/changes/26/26726/1

diff --git a/util/sconfig/main.c b/util/sconfig/main.c
index f9019bc..264dd20 100644
--- a/util/sconfig/main.c
+++ b/util/sconfig/main.c
@@ -22,8 +22,6 @@
 
 struct device *head, *lastdev;
 
-struct header headers;
-
 static struct chip *chip_head;
 
 /*
@@ -244,30 +242,6 @@
 	return new_chip;
 }
 
-void add_header(struct chip *chip)
-{
-	int include_exists = 0;
-	struct header *h = &headers;
-	while (h->next) {
-		int result = strcmp(chip->name, h->next->name);
-		if (result == 0) {
-			include_exists = 1;
-			break;
-		}
-		if (result < 0)
-			break;
-		h = h->next;
-	}
-	if (!include_exists) {
-		struct header *tmp = h->next;
-		h->next = malloc(sizeof(struct header));
-		memset(h->next, 0, sizeof(struct header));
-		h->next->chiph_exists = chip->chiph_exists;
-		h->next->name = chip->name;
-		h->next->next = tmp;
-	}
-}
-
 struct device *new_device(struct device *parent, struct device *busdev,
 			  struct chip *chip, const int bus, const char *devnum,
 			  int enabled)
@@ -621,10 +595,70 @@
 	} while (ptr);
 }
 
+static void add_header(struct chip *chip, struct header *h)
+{
+	int include_exists = 0;
+
+	while (h->next) {
+		int result = strcmp(chip->name, h->next->name);
+		if (result == 0) {
+			include_exists = 1;
+			break;
+		}
+		if (result < 0)
+			break;
+		h = h->next;
+	}
+
+	if (!include_exists) {
+		struct header *tmp = h->next;
+		h->next = malloc(sizeof(struct header));
+		memset(h->next, 0, sizeof(struct header));
+		h->next->chiph_exists = chip->chiph_exists;
+		h->next->name = chip->name;
+		h->next->next = tmp;
+	}
+}
+
+static void emit_headers(FILE *fil)
+{
+	struct header *h;
+	struct chip *chip;
+	struct header headers = {};
+
+	fprintf(stderr, "emit_headers now!!\n");
+	for (chip = chip_head; chip; chip = chip->next)
+		add_header(chip, &headers);
+
+	fprintf(fil, "#include <device/device.h>\n");
+	fprintf(fil, "#include <device/pci.h>\n");
+	h = &headers;
+	while (h->next) {
+		h = h->next;
+		if (h->chiph_exists)
+			fprintf(fil, "#include \"%s/chip.h\"\n", h->name);
+	}
+	fprintf(fil, "\n#if !DEVTREE_EARLY\n");
+	fprintf(fil,
+		"__attribute__((weak)) struct chip_operations mainboard_ops = {};\n");
+	h = &headers;
+	while (h->next) {
+		h = h->next;
+		char *name_underscore = translate_name(h->name, UNSLASH);
+		fprintf(fil,
+			"__attribute__((weak)) struct chip_operations %s_ops = {};\n",
+			name_underscore);
+		free(name_underscore);
+	}
+	fprintf(fil, "#endif\n");
+}
+
 static void emit_chips(FILE *fil)
 {
 	struct chip *chip;
 
+	emit_headers(fil);
+
 	for (chip = chip_head; chip; chip = chip->next) {
 		if (!chip->chiph_exists)
 			continue;
@@ -692,8 +726,6 @@
 	char *devtree = argv[DEVICEFILE_ARG];
 	char *outputc = argv[OUTPUTFILE_ARG];
 
-	headers.next = 0;
-
 	FILE *filec = fopen(devtree, "r");
 	if (!filec) {
 		perror(NULL);
@@ -716,29 +748,6 @@
 		exit(1);
 	}
 
-	struct header *h;
-	fprintf(autogen, "#include <device/device.h>\n");
-	fprintf(autogen, "#include <device/pci.h>\n");
-	h = &headers;
-	while (h->next) {
-		h = h->next;
-		if (h->chiph_exists)
-			fprintf(autogen, "#include \"%s/chip.h\"\n", h->name);
-	}
-	fprintf(autogen, "\n#if !DEVTREE_EARLY\n");
-	fprintf(autogen,
-		"__attribute__((weak)) struct chip_operations mainboard_ops = {};\n");
-	h = &headers;
-	while (h->next) {
-		h = h->next;
-		char *name_underscore = translate_name(h->name, UNSLASH);
-		fprintf(autogen,
-			"__attribute__((weak)) struct chip_operations %s_ops = {};\n",
-			name_underscore);
-		free(name_underscore);
-	}
-	fprintf(autogen, "#endif\n");
-
 	emit_chips(autogen);
 
 	walk_device_tree(autogen, &root, inherit_subsystem_ids, NULL);
diff --git a/util/sconfig/sconfig.h b/util/sconfig/sconfig.h
index b1fbe37..b707448 100644
--- a/util/sconfig/sconfig.h
+++ b/util/sconfig/sconfig.h
@@ -110,7 +110,6 @@
 
 void postprocess_devtree(void);
 struct chip *new_chip(char *path);
-void add_header(struct chip *chip);
 struct device *new_device(struct device *parent, struct device *busdev,
 			  struct chip *chip, const int bus, const char *devnum,
 			  int enabled);
diff --git a/util/sconfig/sconfig.tab.c_shipped b/util/sconfig/sconfig.tab.c_shipped
index 7cc3f94..e0d63d4 100644
--- a/util/sconfig/sconfig.tab.c_shipped
+++ b/util/sconfig/sconfig.tab.c_shipped
@@ -487,8 +487,8 @@
 static const yytype_uint8 yyrline[] =
 {
        0,    36,    36,    36,    38,    38,    38,    38,    40,    40,
-      40,    40,    40,    40,    42,    42,    52,    52,    64,    67,
-      70,    73,    76
+      40,    40,    40,    40,    42,    42,    51,    51,    63,    66,
+      69,    72,    75
 };
 #endif
 
@@ -1311,7 +1311,6 @@
 
     {
 	cur_chip = pop_chip();
-	add_header((yyvsp[-2].chip));
 }
 
     break;
diff --git a/util/sconfig/sconfig.y b/util/sconfig/sconfig.y
index 25484d3..e8d6fd3 100755
--- a/util/sconfig/sconfig.y
+++ b/util/sconfig/sconfig.y
@@ -46,7 +46,6 @@
 }
 	chipchildren END {
 	cur_chip = pop_chip();
-	add_header($<chip>3);
 };
 
 device: DEVICE BUS NUMBER /* == devnum */ BOOL {

-- 
To view, visit https://review.coreboot.org/26726
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I24d526e81323115d3cc927242a4b9e49414afbe0
Gerrit-Change-Number: 26726
Gerrit-PatchSet: 1
Gerrit-Owner: Furquan Shaikh <furquan at google.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.coreboot.org/pipermail/coreboot-gerrit/attachments/20180531/ff1720b4/attachment-0001.html>


More information about the coreboot-gerrit mailing list