[hackers] [scc] [driver] add k flag for keeping intermediary files || Quentin Rameau
commit ce844747c2ee341327c4189efe1deaf12b0dd841
Author: Quentin Rameau <quinq_AT_fifth.space>
AuthorDate: Wed Jun 1 19:21:57 2016 +0200
Commit: Quentin Rameau <quinq_AT_fifth.space>
CommitDate: Wed Jun 1 19:21:57 2016 +0200
[driver] add k flag for keeping intermediary files
We'll use tee (at least for the time being) to write tools output to
files.
The build sequence is set as normal, but we insert tee when needed.
diff --git a/driver/posix/scc.c b/driver/posix/scc.c
index faf27ee..b237718 100644
--- a/driver/posix/scc.c
+++ b/driver/posix/scc.c
_AT_@ -21,6 +21,8 @@ enum {
CC1,
CC2,
QBE,
+ AS,
+ TEE,
NR_TOOLS,
};
_AT_@ -34,11 +36,13 @@ static struct tool {
[CC1] = { .bin = "cc1", .cmd = PREFIX "/libexec/scc/", },
[CC2] = { .bin = "cc2", .cmd = PREFIX "/libexec/scc/", },
[QBE] = { .bin = "qbe", .bin = "qbe", .cmd = "qbe", },
+ [AS] = { .bin = "cat", .bin = "cat", .cmd = "cat", },
+ [TEE] = { .bin = "tee", .bin = "tee", .cmd = "tee", },
};
char *argv0;
static char *arch;
-static int Eflag;
+static int Eflag, kflag;
static void
terminate(void)
_AT_@ -87,24 +91,28 @@ inittool(int tool)
}
int
-settool(int t, int output)
+settool(int tool, int output)
{
- struct tool *tool = &tools[t];
- int fds[2], n;
+ struct tool *t = &tools[tool];
+ int fds[2];
static int fdin;
+ if (tool == TEE)
+ t->args[1] = "out.ir";
+
if (fdin) {
- tool->in = fdin;
+ t->in = fdin;
fdin = 0;
}
+
if (output < NR_TOOLS) {
if (pipe(fds))
die("scc: pipe: %s", strerror(errno));
- tool->out = fds[1];
+ t->out = fds[1];
fdin = fds[0];
}
- return t;
+ return tool;
}
void
_AT_@ -136,25 +144,46 @@ spawn(int t)
void
build(char *file)
{
- int tool, out;
+ int tool, out, keepfile;
+ static int in = NR_TOOLS, preout;
for (tool = CC1; tool < NR_TOOLS; tool = out) {
+ keepfile = 0;
+
switch (tool) {
case CC1:
- out = CC2;
+ in = NR_TOOLS;
+ out = Eflag ? NR_TOOLS : CC2;
+ if (!Eflag)
+ keepfile = kflag;
ADDARG(tool, file);
break;
case CC2:
- out = (!arch || strcmp(arch, "qbe")) ? NR_TOOLS : QBE;
+ out = (!arch || strcmp(arch, "qbe")) ? AS : QBE;
+ if (out != QBE)
+ keepfile = kflag;
break;
case QBE:
+ out = AS;
+ keepfile = kflag;
+ break;
+ case AS:
out = NR_TOOLS;
break;
+ case TEE:
+ out = preout;
+ break;
default:
break;
}
+ if (keepfile) {
+ preout = out;
+ out = TEE;
+ }
+
spawn(settool(inittool(tool), out));
+ in = tool;
}
}
_AT_@ -179,6 +208,9 @@ main(int argc, char *argv[])
Eflag = 1;
ADDARG(CC1, "-E");
break;
+ case 'k':
+ kflag = 1;
+ break;
case 'm':
arch = EARGF(usage());
break;
Received on Wed Jun 01 2016 - 19:24:41 CEST
This archive was generated by hypermail 2.3.0
: Wed Jun 01 2016 - 19:36:13 CEST