ref: ab6baaad01837cda74039cf85019aaf789d1f5cc
parent: 934e2128978ff00ff47a6bd148e209f73b4b6252
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Oct 8 09:07:24 EDT 2021
as: Simplify main() This patch move out of main some of the logic of the process keeping main() simple and easier to get an overall view of how as works.
--- a/src/cmd/as/main.c
+++ b/src/cmd/as/main.c
@@ -10,7 +10,7 @@
#include "as.h"
char *argv0;
-char *outfile, *infile;
+char *outfile = "a.out", *infile;
int endpass;
static void
@@ -30,6 +30,8 @@
if (fclose(fp))
goto error;
+ outfile = NULL;
+
return;
error:
@@ -58,7 +60,7 @@
}
static void
-as(char *text, char *xargs)
+translate(char *text, char *xargs)
{
int c;
char *p;
@@ -107,7 +109,7 @@
linesym = deflabel(line.label);
if (line.op)
- as(line.op, line.args);
+ translate(line.op, line.args);
else if (line.args)
error("arguments without an opcode");
}
@@ -116,6 +118,21 @@
}
static void
+asm(char *argv[])
+{
+ char **p;
+
+ for (pass = 1; pass <= 2; pass++) {
+ for (p = argv; infile = *p; ++p) {
+ if (!dopass(infile))
+ exit(EXIT_FAILURE);
+ }
+ if (pass == 1)
+ killtmp();
+ }
+}
+
+static void
usage(void)
{
fputs("usage: as [-o outfile] filename ...\n", stderr);
@@ -125,10 +142,6 @@
int
main(int argc, char *argv[])
{
- char **p;
-
- outfile = "a.out";
-
ARGBEGIN {
case 'o':
outfile = EARGF(usage());
@@ -143,17 +156,8 @@
atexit(cleanup);
iarch();
isecs();
-
- for (pass = 1; pass <= 2; pass++) {
- for (p = argv; infile = *p; ++p) {
- if (!dopass(infile))
- return EXIT_FAILURE;
- }
- if (pass == 1)
- killtmp();
- }
+ asm(argv);
writeout(outfile);
- outfile = NULL;
return 0;
}