summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--gas.c6
-rw-r--r--parse.c27
-rw-r--r--tools/lexh.c6
3 files changed, 26 insertions, 13 deletions
diff --git a/gas.c b/gas.c
index 339154e..f8f4051 100644
--- a/gas.c
+++ b/gas.c
@@ -19,7 +19,11 @@ gasemitdat(Dat *d, FILE *f)
 	switch (d->type) {
 	case DStart:
 		align = 0;
-		fprintf(f, ".data\n");
+		if (d->u.str) {
+			fprintf(f, ".section %s\n", d->u.str);
+		} else {
+			fprintf(f, ".data\n");
+		}
 		break;
 	case DEnd:
 		break;
diff --git a/parse.c b/parse.c
index b279ff4..48f2f6e 100644
--- a/parse.c
+++ b/parse.c
@@ -41,6 +41,7 @@ enum {
 	Tfunc,
 	Ttype,
 	Tdata,
+	Tsection,
 	Talign,
 	Tl,
 	Tw,
@@ -90,6 +91,7 @@ static char *kwmap[Ntok] = {
 	[Tfunc] = "function",
 	[Ttype] = "type",
 	[Tdata] = "data",
+	[Tsection] = "section",
 	[Talign] = "align",
 	[Tl] = "l",
 	[Tw] = "w",
@@ -984,29 +986,36 @@ parsedatstr(Dat *d)
 static void
 parsedat(void cb(Dat *), int export)
 {
-	char s[NString];
+	char name[NString] = {0};
 	int t;
 	Dat d;
 
-	d.type = DStart;
-	d.isstr = 0;
-	d.isref = 0;
-	d.export = export;
-	cb(&d);
 	if (nextnl() != Tglo || nextnl() != Teq)
 		err("data name, then = expected");
-	strcpy(s, tokval.str);
+	strncpy(name, tokval.str, NString-1);
 	t = nextnl();
+	d.u.str = 0;
+	if (t == Tsection) {
+		if (nextnl() != Tstr)
+			err("section \"name\" expected");
+		d.u.str = tokval.str;
+		t = nextnl();
+	}
+	d.type = DStart;
+	cb(&d);
 	if (t == Talign) {
 		if (nextnl() != Tint)
 			err("alignment expected");
 		d.type = DAlign;
 		d.u.num = tokval.num;
+		d.isstr = 0;
+		d.isref = 0;
 		cb(&d);
 		t = nextnl();
 	}
 	d.type = DName;
-	d.u.str = s;
+	d.u.str = name;
+	d.export = export;
 	cb(&d);
 
 	if (t != Tlbrace)
@@ -1025,8 +1034,8 @@ parsedat(void cb(Dat *), int export)
 		}
 		t = nextnl();
 		do {
-			d.isref = 0;
 			d.isstr = 0;
+			d.isref = 0;
 			memset(&d.u, 0, sizeof d.u);
 			if (t == Tflts)
 				d.u.flts = tokval.flts;
diff --git a/tools/lexh.c b/tools/lexh.c
index 9e8016a..2ebb022 100644
--- a/tools/lexh.c
+++ b/tools/lexh.c
@@ -25,9 +25,9 @@ char *tok[] = {
 	"vaarg", "vastart", "...", "env",
 
 	"call", "phi", "jmp", "jnz", "ret", "export",
-	"function", "type", "data", "align", "l", "w",
-	"h", "b", "d", "s", "z", "loadw", "loadl", "loads",
-	"loadd", "alloc1", "alloc2",
+	"function", "type", "data", "section", "align",
+	"l", "w", "h", "b", "d", "s", "z", "loadw", "loadl",
+	"loads", "loadd", "alloc1", "alloc2",
 
 };
 enum {