dtc: implement labels on property data

Extend the parser grammer to allow labels before or after any
property data (string, cell list, or byte list), and any
byte or cell within the property data.

Store the labels using the same linked list structure as node
references, but using a parallel list.

When writing assembly output emit global labels as offsets from
the start of the definition of the data.

Note that the alignment for a cell list is done as part of the
opening < delimiter, not the = or , before it.  To label a cell
after a string or byte list put the label inside the cell list.

For example,
	prop = zero: [ aa bb ], two: < four: 1234 > eight: ;
will produce labels with offsets 0, 2, 4, and 8 bytes from
the beginning of the data for property prop.

Signed-off-by: Milton Miller <[email protected]>
diff --git a/data.c b/data.c
index 3d68792..3e96d11 100644
--- a/data.c
+++ b/data.c
@@ -29,12 +29,17 @@
 
 void data_free(struct data d)
 {
-	struct fixup *f;
+	struct fixup *f, *nf;
 
 	f = d.refs;
 	while (f) {
-		struct fixup *nf;
+		nf = f->next;
+		fixup_free(f);
+		f = nf;
+	}
 
+	f = d.labels;
+	while (f) {
 		nf = f->next;
 		fixup_free(f);
 		f = nf;
@@ -198,27 +203,36 @@
 	return d;
 }
 
-struct data data_merge(struct data d1, struct data d2)
+void fixup_merge(struct fixup **fd, struct fixup **fd2, int d1_len)
 {
-	struct data d;
 	struct fixup **ff;
 	struct fixup *f, *f2;
 
-	d = data_append_data(d1, d2.val, d2.len);
-
 	/* Extract d2's fixups */
-	f2 = d2.refs;
-	d2.refs = NULL;
+	f2 = *fd2;
+	*fd2 = NULL;
 
 	/* Tack them onto d's list of fixups */
-	ff = &d.refs;
+	ff = fd;
 	while (*ff)
 		ff = &((*ff)->next);
 	*ff = f2;
 
 	/* And correct them for their new position */
 	for (f = f2; f; f = f->next)
-		f->offset += d1.len;
+		f->offset += d1_len;
+
+
+}
+
+struct data data_merge(struct data d1, struct data d2)
+{
+	struct data d;
+
+	d = data_append_data(d1, d2.val, d2.len);
+
+	fixup_merge(&d.refs, &d2.refs, d1.len);
+	fixup_merge(&d.labels, &d2.labels, d1.len);
 
 	data_free(d2);
 
@@ -285,6 +299,22 @@
 	return nd;
 }
 
+struct data data_add_label(struct data d, char *label)
+{
+	struct fixup *f;
+	struct data nd;
+
+	f = xmalloc(sizeof(*f));
+	f->offset = d.len;
+	f->ref = label;
+	f->next = d.labels;
+
+	nd = d;
+	nd.labels = f;
+
+	return nd;
+}
+
 int data_is_one_string(struct data d)
 {
 	int i;