summary refs log tree commit diff
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2020-08-10 12:28:48 -0400
committerQuentin Carbonneaux <quentin@c9x.me>2021-03-02 10:00:08 +0100
commit83c210834197b7ad3208214a4f9d8669134c4a3c (patch)
tree82b5e49cf07c1f4453819ad9a317480d0cddc328
parentcdee1d81c4c73113eb293bf2ac816bee53047f36 (diff)
downloadroux-83c210834197b7ad3208214a4f9d8669134c4a3c.tar.gz
add data $name = section "section" ...
This allows you to explicitly specify the section to emit the data
directive for, allowing for sections other than .data: for example, .bss
or .init_array.
-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 {