Skip to contentSkip to conversation

Introduce new DTS language.

PATCH New Jon Loeliger 1 participant 1 message Sep 24, 2008 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH v2 7/8 Introduce new DTS language.

From: Jon Loeliger <jdl-CYoMK+44s/[email protected]>

Introduce function defs and statements.
Added support for expressions.
Added if, for, assign and return statements.
Added support for BUILTIN functions.
Added support for /const/ definitions.
Added support for command line defines, eg: -D x=1 Unified /memreserve/ into declaration list.
Add lexical support for column source position information.
Notably, this involved identifying all the newline characters to reset the column count. Had to rewrite the C comment rules, and break \n out of the {WS} set.
Add lexical source positions to all IR nodes. Change error reporting to use IR source positions.

Passes test suite.

---

Bah. Sent wrong version of this patch in V1. This version is the same, except it also has memreserves unified into declaration lists.

 Makefile     |    2 +-
 Makefile.dtc |   18 ++-
 dtc-lexer.l  |  259 +++++++++++++++++----
 dtc-parser.y |  711 ++++++++++++++++++++++++++++++++++++++++++++++------------
 dtc.c        |    7 +-
 dtc.h        |    1 +
 ir.h         |    1 -
 ir_dump.c    |    9 -
 ir_emit.c    |   67 +++---
 ir_eval.c    |    2 -
 ir_scope.c   |    3 +-
 livetree.c   |   16 ++
 nv.c         |  108 +++++++++
 nv.h         |   34 +++
 srcpos.c     |   47 ++++-
 srcpos.h     |   10 +-
 treesource.c |    3 +
 17 files changed, 1039 insertions(+), 259 deletions(-)
 create mode 100644 nv.c
 create mode 100644 nv.h
Makefile +1 -1
index 5ad0189..1ae5577 100644
@@ -18,7 +18,7 @@ CONFIG_LOCALVERSION =
 CPPFLAGS = -I libfdt
 CFLAGS = -Wall -g -Os -Wpointer-arith -Wcast-qual
 
-BISON = bison
+BISON = bison -v
 LEX = flex
 
 INSTALL = /usr/bin/install
Makefile.dtc +16 -2
index 6ddf9ec..dd53276 100644
@@ -3,7 +3,21 @@
 # This is not a complete Makefile of itself.  Instead, it is designed to
 # be easily embeddable into other systems of Makefiles.
 #
-DTC_SRCS = dtc.c flattree.c fstree.c data.c livetree.c treesource.c srcpos.c \
-	checks.c
+DTC_SRCS = \
+	checks.c \
+	data.c \
+	dtc.c \
+	flattree.c \
+	fstree.c \
+	ir.c \
+	ir_builtin.c \
+	ir_dump.c \
+	ir_emit.c \
+	ir_eval.c \
+	ir_scope.c \
+	livetree.c \
+	nv.c \
+	srcpos.c \
+	treesource.c
 DTC_GEN_SRCS = dtc-lexer.lex.c dtc-parser.tab.c
 DTC_OBJS = $(DTC_SRCS:%.c=%.o) $(DTC_GEN_SRCS:%.c=%.o)
dtc-lexer.l +212 -47

382 lines not on this page · raw message

dtc-parser.y +562 -149

871 lines not on this page · raw message

dtc.c +5 -2
index 84bee2d..ccaf89c 100644
@@ -20,6 +20,7 @@
 
 #include "dtc.h"
 #include "srcpos.h"
+#include "nv.h"
 
 #include "version_gen.h"
 
@@ -127,7 +128,7 @@ int main(int argc, char *argv[])
 	minsize    = 0;
 	padsize    = 0;
 
-	while ((opt = getopt(argc, argv, "hI:O:o:V:R:S:p:fcqb:v")) != EOF) {
+	while ((opt = getopt(argc, argv, "hD:I:O:o:V:R:S:p:fcqb:v")) != EOF) {
 		switch (opt) {
 		case 'I':
 			inform = optarg;
@@ -162,6 +163,9 @@ int main(int argc, char *argv[])
 		case 'b':
 			cmdline_boot_cpuid = strtoll(optarg, NULL, 0);
 			break;
+		case 'D':
+			nv_note_define(optarg);
+			break;
 		case 'v':
 			printf("Version: %s\n", DTC_VERSION);
 			exit(0);
@@ -203,7 +207,6 @@ int main(int argc, char *argv[])
 	fill_fullpaths(bi->dt, "");
 	process_checks(force, bi);
 
-
 	if (streq(outname, "-")) {
 		outf = stdout;
 	} else {
dtc.h +1 -0
index ec636f8..327fc15 100644
@@ -187,6 +187,7 @@ struct property *reverse_properties(struct property *first);
 struct node *build_node(struct property *proplist, struct node *children);
 struct node *name_node(struct node *node, char *name, char *label);
 struct node *chain_node(struct node *first, struct node *list);
+struct node *reverse_nodes(struct node *first);
 
 void add_property(struct node *node, struct property *prop);
 void add_child(struct node *parent, struct node *child);
ir.h +0 -1
index 7d27fe7..4bb342c 100644
@@ -100,7 +100,6 @@ struct ir {
 	struct ir *ir_expr2;
 	struct ir *ir_expr3;
 
-	struct ir *ir_mem_reserves;
 	struct ir *ir_statements;
 	struct ir *ir_statements2;
 	struct ir *ir_declarations;
ir_dump.c +0 -9
index f949423..edf11a7 100644
@@ -152,15 +152,6 @@ ir_dump_node(struct ir *ir, unsigned int level)
 		       indent, "", ir->ir_prev);
 
 	/*
-	 * Dump mem-reserves.
-	 */
-	if (ir->ir_mem_reserves) {
-		printf("%*sir_mem_reserves: %p\n",
-		       indent, "", ir->ir_mem_reserves);
-		ir_dump_node(ir->ir_mem_reserves, level + 1);
-	}
-
-	/*
 	 * Dump sub-expressions
 	 */
 	if (ir->ir_expr1) {
ir_emit.c +33 -34

93 lines not on this page · raw message

ir_eval.c +0 -2
index bd667cb..ba6da6a 100644
@@ -1461,8 +1461,6 @@ ir_simplify(struct ir *ir, unsigned int ctxt)
 
 	case IR_ROOT:
 		ir_new = ir_copy(ir);
-		ir_new->ir_mem_reserves =
-			ir_simplify(ir->ir_mem_reserves, ctxt);
 		ir_new->ir_declarations =
 			ir_simplify(ir->ir_declarations, ctxt);
 		ir_new->ir_statements =
ir_scope.c +1 -2
index c9a52e8..20d784d 100644
@@ -97,8 +97,7 @@ irs_append_reserve(struct reserve_info *ri)
 	struct ir_scope *irs;
 
 	irs = irs_find_scope(IRS_ROOT);
-	irs->irs_reserve_list = chain_reserve_entry(ri,
-						    irs->irs_reserve_list);
+	irs->irs_reserve_list = add_reserve_entry(irs->irs_reserve_list, ri);
 }
 
 
livetree.c +16 -0
index 0ca3de5..fec33b4 100644
@@ -97,6 +97,22 @@ struct node *chain_node(struct node *first, struct node *list)
 	return first;
 }
 
+struct node *reverse_nodes(struct node *first)
+{
+	struct node *p = first;
+	struct node *head = NULL;
+	struct node *next;
+
+	while (p) {
+		next = p->next_sibling;
+		p->next_sibling = head;
+		head = p;
+		p = next;
+	}
+	return head;
+}
+
+
 void add_property(struct node *node, struct property *prop)
 {
 	struct property **p;
nv.c new file +108 -0

108 lines not on this page · raw message

nv.h new file +34 -0
new file mode 100644
index 0000000..70ed718
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2008 Jon Loeliger, Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
+ *                                                                   USA
+ */
+
+#ifndef _NV_H_
+#define _NV_H_
+
+
+struct nv_pair {
+	char *nv_name;
+	char *nv_value;
+	struct nv_pair *nv_next;
+};
+
+extern struct nv_pair *nv_list;
+
+extern void nv_note_define(char *defstr);
+
+#endif /* _NV_H_ */
srcpos.c +42 -5

70 lines not on this page · raw message

srcpos.h +5 -5
index 3c39dd0..a6d0077 100644
@@ -81,11 +81,6 @@ typedef YYLTYPE srcpos;
  */
 extern srcpos srcpos_empty;
 
-
-
-extern void yyerror(char const *);
-extern void yyerrorf(char const *, ...) __attribute__((format(printf, 1, 2)));
-
 extern struct dtc_file *srcpos_file;
 
 struct search_path {
@@ -101,4 +96,9 @@ extern srcpos *srcpos_copy(srcpos *pos);
 extern char *srcpos_string(srcpos *pos);
 extern void srcpos_dump(srcpos *pos);
 
+extern void srcpos_error(srcpos *pos, char const *, ...)
+     __attribute__((format(printf, 2, 3)));
+extern void srcpos_warn(srcpos *pos, char const *, ...)
+     __attribute__((format(printf, 2, 3)));
+
 #endif /* _SRCPOS_H_ */
treesource.c +3 -0
index 1521ff1..5d69878 100644
@@ -20,6 +20,7 @@
 
 #include "dtc.h"
 #include "srcpos.h"
+#include "ir.h"
 
 extern FILE *yyin;
 extern int yyparse(void);
@@ -41,6 +42,8 @@ struct boot_info *dt_from_source(const char *fname)
 	if (treesource_error)
 		die("Syntax error parsing input tree\n");
 
+	ir_process();
+
 	return the_boot_info;
 }
 
Signature · 1 line
1.6.0.2.g2ebc0