commit 1d6a2a973016cdd636ca66132a559896e5817bab
Author:     Quentin Rameau <[email protected]>
AuthorDate: Wed Jun 1 18:56:00 2016 +0200
Commit:     Quentin Rameau <[email protected]>
CommitDate: Wed Jun 1 18:56:00 2016 +0200

    [driver] add a build function to manage build sequence
    
    This will help us set more complex sequences in the future (notably for
    writing intermediary files).

diff --git a/driver/posix/scc.c b/driver/posix/scc.c
index d558734..faf27ee 100644
--- a/driver/posix/scc.c
+++ b/driver/posix/scc.c
@@ -87,19 +87,17 @@ inittool(int tool)
 }
 
 int
-settool(int t, int pipeout)
+settool(int t, int output)
 {
        struct tool *tool = &tools[t];
        int fds[2], n;
        static int fdin;
 
-       inittool(t);
-
        if (fdin) {
                tool->in = fdin;
                fdin = 0;
        }
-       if (pipeout) {
+       if (output < NR_TOOLS) {
                if (pipe(fds))
                        die("scc: pipe: %s", strerror(errno));
                tool->out = fds[1];
@@ -135,6 +133,31 @@ spawn(int t)
        }
 }
 
+void
+build(char *file)
+{
+       int tool, out;
+
+       for (tool = CC1; tool < NR_TOOLS; tool = out) {
+               switch (tool) {
+               case CC1:
+                       out = CC2;
+                       ADDARG(tool, file);
+                       break;
+               case CC2:
+                       out = (!arch || strcmp(arch, "qbe")) ? NR_TOOLS : QBE;
+                       break;
+               case QBE:
+                       out = NR_TOOLS;
+                       break;
+               default:
+                       break;
+               }
+
+               spawn(settool(inittool(tool), out));
+       }
+}
+
 static void
 usage(void)
 {
@@ -169,20 +192,7 @@ main(int argc, char *argv[])
        if (!argc)
                die("scc: fatal error: no input files");
 
-       ADDARG(CC1, *argv);
-
-       if (Eflag) {
-               spawn(settool(CC1, 0));
-       } else {
-               spawn(settool(CC1, 1));
-
-               if (!arch || strcmp(arch, "qbe")) {
-                       spawn(settool(CC2, 0));
-               } else {
-                       spawn(settool(CC2, 1));
-                       spawn(settool(QBE, 0));
-               }
-       }
+       build(*argv);
 
        for (i = 0; i < NR_TOOLS; ++i) {
                if ((pid = wait(&st)) < 0)

Reply via email to