commit d35d5fe22f66775de64c768ab1271430dbbf9eb5
parent fba444a27d3a288a7180c980f48a0cd1bfdd88ee
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Thu, 15 Feb 2024 07:52:47 +0100
as: Remove binfmt.c
This file was a bad idea because it was going to have only
one function and it was suffering because it couldn't see
the definition of the lsection structure.
Diffstat:
4 files changed, 40 insertions(+), 71 deletions(-)
diff --git a/src/cmd/as/Makefile b/src/cmd/as/Makefile
@@ -6,7 +6,6 @@ include $(PROJECTDIR)/scripts/rules.mk
MORE_CFLAGS = -I$(INCDIR)/$(STD)
OBJS = \
- binfmt.o\
expr.o\
ins.o\
main.o\
diff --git a/src/cmd/as/as.h b/src/cmd/as/as.h
@@ -118,7 +118,6 @@ extern Symbol *tmpsym(TUINT);
extern void killtmp(void);
extern int toobig(Node *, int);
extern void dumpstab(char *);
-int forallsecs(int (*)(Section *, void *), void *);
extern Symbol *lookup(char *);
extern Symbol *deflabel(char *);
diff --git a/src/cmd/as/binfmt.c b/src/cmd/as/binfmt.c
@@ -1,64 +0,0 @@
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <scc/mach.h>
-#include <scc/scc.h>
-
-#include "as.h"
-
-/*
- * FIXME: Horrible hack, just the data structure copied here
- * To be able to continue working and not breaking the tests
- * but it should be removed from here as soon as posible.
- */
-struct lsection {
- Section sec;
- FILE *fp;
-};
-
-static int
-dumpsec(Section *sec, void *dst)
-{
- int c;
- struct lsection *lsec = (struct lsection *) sec;
- FILE *src = lsec->fp;
-
- if (!src)
- return 0;
-
- rewind(src);
- while ((c = getc(src)) != EOF)
- putc(c, dst);
-
- if (ferror(src))
- return -1;
-
- return 0;
-}
-
-void
-writeout(char *fname)
-{
- FILE *fp;
-
- if ((fp = fopen(fname, "wb")) == NULL)
- goto error;
-
- if (forallsecs(dumpsec, fp) < 0)
- goto error;
- fflush(fp);
-
- if (ferror(fp))
- goto error;
-
- fclose(fp);
- outfile = NULL;
-
- return;
-
-error:
- fprintf(stderr, "as: %s: %s\n", fname, strerror(errno));
- exit(EXIT_FAILURE);
-}
diff --git a/src/cmd/as/symbol.c b/src/cmd/as/symbol.c
@@ -1,4 +1,5 @@
#include <ctype.h>
+#include <errno.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
@@ -364,15 +365,49 @@ killtmp(void)
tmpalloc = NULL;
}
-int
-forallsecs(int (*fn)(Section *, void *), void *arg)
+static int
+dumpsec(FILE *src, FILE *dst)
{
+ int c;
+
+ if (!src)
+ return 0;
+
+ rewind(src);
+ while ((c = getc(src)) != EOF)
+ putc(c, dst);
+
+ if (ferror(src))
+ return -1;
+
+ return 0;
+}
+
+void
+writeout(char *fname)
+{
+ FILE *fp;
struct lsection *lp;
+ if ((fp = fopen(fname, "wb")) == NULL)
+ goto error;
+
+
for (lp = seclist; lp; lp = lp->next) {
- if ((*fn)(&lp->sec, arg) < 0)
- return -1;
+ if (dumpsec(lp->fp, fp) < 0)
+ goto error;
}
+ fflush(fp);
- return 0;
+ if (ferror(fp))
+ goto error;
+
+ fclose(fp);
+ outfile = NULL;
+
+ return;
+
+error:
+ fprintf(stderr, "as: %s: %s\n", fname, strerror(errno));
+ exit(EXIT_FAILURE);
}