scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit e353903fa9ba4bbd405ca46c6ac651c8c8fb3cc2
parent 028b46a65d31a4deb1c104c6f7a30a9e959e2a1d
Author: Quentin Rameau <quinq@fifth.space>
Date:   Fri,  3 Jun 2016 01:00:00 +0200

[driver] add support for building from intermediary files

Diffstat:
Mdriver/posix/scc.c | 27++++++++++++++++++++++-----
1 file changed, 22 insertions(+), 5 deletions(-)

diff --git a/driver/posix/scc.c b/driver/posix/scc.c @@ -99,6 +99,7 @@ inittool(int tool) strcat(t->cmd, t->bin); break; case AS: + t->nargs = 2; t->args[1] = "-o"; break; default: @@ -142,12 +143,10 @@ settool(int tool, char *input, int output) static int fdin; switch (tool) { - case CC1: - t->args[t->nargs + 1] = input; - break; case AS: outfiles[output] = newfileext(input, "o"); - t->args[2] = outfiles[output]; + t->args[t->nargs] = outfiles[output]; + t->args[3] = NULL; break; case TEE: switch (output) { @@ -171,6 +170,8 @@ settool(int tool, char *input, int output) if (fdin) { t->in = fdin; fdin = 0; + } else { + t->args[t->nargs + 1] = input; } if (output < NR_TOOLS) { @@ -208,6 +209,22 @@ spawn(int t) break; } } +static int +toolfor(char *file) +{ + char *dot = strrchr(file, '.'); + + if (dot) { + if (!strcmp(dot, ".c")) + return CC1; + if (!strcmp(dot, ".qbe")) + return QBE; + if (!strcmp(dot, ".as")) + return AS; + } + + die("scc: do not recognize filetype of %s", file); +} static void build(char *file) @@ -216,7 +233,7 @@ build(char *file) int i, st, tool, out, keepfile; static int preout; - for (tool = CC1; tool < NR_TOOLS; tool = out) { + for (tool = toolfor(file); tool < NR_TOOLS; tool = out) { keepfile = 0; switch (tool) {