please as with truncated constants

Apple's assembler actually hard
crashed on overflows.
This commit is contained in:
Quentin Carbonneaux 2026-01-06 20:42:31 +01:00
parent 0f6bbb1c7c
commit e0ded59639

18
emit.c
View File

@ -61,11 +61,14 @@ emitfnlnk(char *n, Lnk *l, FILE *f)
void void
emitdat(Dat *d, FILE *f) emitdat(Dat *d, FILE *f)
{ {
static char *dtoa[] = { static struct {
[DB] = "\t.byte", char decl[8];
[DH] = "\t.short", int64_t mask;
[DW] = "\t.int", } di[] = {
[DL] = "\t.quad" [DB] = {"\t.byte", 0xffL},
[DH] = {"\t.short", 0xffffL},
[DW] = {"\t.int", 0xffffffffL},
[DL] = {"\t.quad", -1L},
}; };
static int64_t zero; static int64_t zero;
char *p; char *p;
@ -111,12 +114,13 @@ emitdat(Dat *d, FILE *f)
else if (d->isref) { else if (d->isref) {
p = d->u.ref.name[0] == '"' ? "" : T.assym; p = d->u.ref.name[0] == '"' ? "" : T.assym;
fprintf(f, "%s %s%s%+"PRId64"\n", fprintf(f, "%s %s%s%+"PRId64"\n",
dtoa[d->type], p, d->u.ref.name, di[d->type].decl, p, d->u.ref.name,
d->u.ref.off); d->u.ref.off);
} }
else { else {
fprintf(f, "%s %"PRId64"\n", fprintf(f, "%s %"PRId64"\n",
dtoa[d->type], d->u.num); di[d->type].decl,
d->u.num & di[d->type].mask);
} }
break; break;
} }