summaryrefslogtreecommitdiff
path: root/lisc
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-10-08 14:49:00 -0400
committerQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-10-08 14:49:00 -0400
commit25f7bc06e3c7ac93e1b2b06a9828c24471a5e7d2 (patch)
tree8fea4065d21224247ae59deed442d39632be2853 /lisc
parentbf3e6753f3ee28c33aa16dd9b0a65636e612eac1 (diff)
downloadroux-25f7bc06e3c7ac93e1b2b06a9828c24471a5e7d2.tar.gz
emit alignment directives properly
Diffstat (limited to 'lisc')
-rw-r--r--lisc/emit.c33
-rw-r--r--lisc/lisc.h2
-rw-r--r--lisc/parse.c12
3 files changed, 27 insertions, 20 deletions
diff --git a/lisc/emit.c b/lisc/emit.c
index 316c5f0..95d2346 100644
--- a/lisc/emit.c
+++ b/lisc/emit.c
@@ -315,7 +315,6 @@ emitfn(Fn *fn, FILE *f)
int *r, c, fs;
fprintf(f,
- "\n"
".text\n"
".globl %s\n"
".type %s, @function\n"
@@ -371,34 +370,34 @@ emitfn(Fn *fn, FILE *f)
void
emitdat(Dat *d, FILE *f)
{
+ static char *dtoa[] = {
+ [DAlign] = ".align",
+ [DB] = "\t.byte",
+ [DH] = "\t.value",
+ [DW] = "\t.long",
+ [DL] = "\t.quad"
+ };
+
switch (d->type) {
+ case DStart:
+ fprintf(f, ".data\n");
+ break;
+ case DEnd:
+ fprintf(f, "\n");
+ break;
case DName:
fprintf(f,
- "\n"
- ".data\n"
".globl %s\n"
".type %s, @object\n"
"%s:\n",
d->u.str, d->u.str, d->u.str
);
break;
- case DAlign:
- fprintf(f, ".align %"PRId64"\n", d->u.num);
- break;
case DA:
fprintf(f, "\t.string \"%s\"\n", d->u.str);
break;
- case DB:
- fprintf(f, "\t.byte %"PRId64"\n", d->u.num);
- break;
- case DH:
- fprintf(f, "\t.value %"PRId64"\n", d->u.num);
- break;
- case DW:
- fprintf(f, "\t.long %"PRId64"\n", d->u.num);
- break;
- case DL:
- fprintf(f, "\t.quad %"PRId64"\n", d->u.num);
+ default:
+ fprintf(f, "%s %"PRId64"\n", dtoa[d->type], d->u.num);
break;
}
}
diff --git a/lisc/lisc.h b/lisc/lisc.h
index 13aeb01..f83c56a 100644
--- a/lisc/lisc.h
+++ b/lisc/lisc.h
@@ -266,6 +266,8 @@ struct Typ {
struct Dat {
enum {
+ DStart,
+ DEnd,
DName,
DAlign,
DA,
diff --git a/lisc/parse.c b/lisc/parse.c
index 8793d32..b27e60c 100644
--- a/lisc/parse.c
+++ b/lisc/parse.c
@@ -728,14 +728,15 @@ parsetyp()
static void
parsedat(void cb(Dat *))
{
+ char s[NString];
int t;
Dat d;
+ d.type = DStart;
+ cb(&d);
if (nextnl() != TGlo || nextnl() != TEq)
err("data name, then = expected");
- d.type = DName;
- d.u.str = tokval.str;
- cb(&d);
+ strcpy(s, tokval.str);
t = nextnl();
if (t == TAlign) {
if (nextnl() != TNum)
@@ -745,6 +746,9 @@ parsedat(void cb(Dat *))
cb(&d);
t = nextnl();
}
+ d.type = DName;
+ d.u.str = s;
+ cb(&d);
if (t == TStr) {
d.type = DA;
d.u.str = tokval.str;
@@ -770,6 +774,8 @@ parsedat(void cb(Dat *))
if (t != TComma)
err(", or } expected");
}
+ d.type = DEnd;
+ cb(&d);
}
Fn *