commit 98857fdfe653b04c16f4d3520fe4d1d24a3cb4f0
parent 6035e8511b69b44b65eb8771c3dd84ed21e50cb3
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Sun, 11 Feb 2024 12:34:44 +0100
as: Move writeout to binfmt.c
More changes are expected to be able to write out binaries
formats that are not just pure dumps.
Diffstat:
4 files changed, 40 insertions(+), 27 deletions(-)
diff --git a/src/cmd/as/Makefile b/src/cmd/as/Makefile
@@ -6,6 +6,7 @@ include $(PROJECTDIR)/scripts/rules.mk
MORE_CFLAGS = -I$(INCDIR)/$(STD)
OBJS = \
+ binfmt.o\
main.o\
symbol.o\
ins.o\
diff --git a/src/cmd/as/as.h b/src/cmd/as/as.h
@@ -199,6 +199,9 @@ extern Node *moperand(void);
/* ins.c */
extern char *tobytes(TUINT v, int n, int inc);
+/* binfmt.c */
+extern void writeout(char *fname);
+
/*
* Definition of global variables
*/
@@ -211,7 +214,7 @@ extern int pass;
extern TUINT maxaddr;
extern int endian;
extern Symbol *linesym, *symlist;
-extern char *infile;
+extern char *infile, *outfile;
extern int endpass;
extern int yytoken;
extern size_t yylen;
diff --git a/src/cmd/as/binfmt.c b/src/cmd/as/binfmt.c
@@ -0,0 +1,35 @@
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <scc/scc.h>
+
+#include "as.h"
+
+void
+writeout(char *fname)
+{
+ Section *sp;
+ FILE *fp;
+
+ if ((fp = fopen(fname, "wb")) == NULL)
+ goto error;
+
+ for (sp = seclist; sp; sp = sp->next) {
+ if (!sp->mem)
+ continue;
+ fwrite(sp->mem, sp->max - sp->base, 1, fp);
+ }
+
+ if (fclose(fp))
+ goto error;
+ outfile = NULL;
+
+ return;
+
+error:
+ fprintf(stderr, "as: %s: %s\n", fname, strerror(errno));
+ exit(EXIT_FAILURE);
+}
+
diff --git a/src/cmd/as/main.c b/src/cmd/as/main.c
@@ -14,32 +14,6 @@ char *outfile = "a.out", *infile;
int endpass;
static void
-writeout(char *fname)
-{
- Section *sp;
- FILE *fp;
-
- if ((fp = fopen(fname, "wb")) == NULL)
- goto error;
-
- for (sp = seclist; sp; sp = sp->next) {
- if (!sp->mem)
- continue;
- fwrite(sp->mem, sp->max - sp->base, 1, fp);
- }
-
- if (fclose(fp))
- goto error;
- outfile = NULL;
-
- return;
-
-error:
- fprintf(stderr, "as: %s: %s\n", fname, strerror(errno));
- exit(EXIT_FAILURE);
-}
-
-static void
cleanup(void)
{
if (outfile)