scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 813bc56a038cc8699ebe923e19cf09caaf51eb5a
parent 1e2bd8326fecf0902ac5ed20b487a44ef9333e58
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri,  8 Oct 2021 13:07:24 +0200

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.

Diffstat:
Msrc/cmd/as/main.c | 38+++++++++++++++++++++-----------------
1 file changed, 21 insertions(+), 17 deletions(-)

diff --git 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 @@ writeout(char *fname) if (fclose(fp)) goto error; + outfile = NULL; + return; error: @@ -58,7 +60,7 @@ cmp(const void *f1, const void *f2) } static void -as(char *text, char *xargs) +translate(char *text, char *xargs) { int c; char *p; @@ -107,7 +109,7 @@ dopass(char *fname) 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 @@ dopass(char *fname) } 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 @@ usage(void) int main(int argc, char *argv[]) { - char **p; - - outfile = "a.out"; - ARGBEGIN { case 'o': outfile = EARGF(usage()); @@ -143,17 +156,8 @@ main(int argc, char *argv[]) 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; }