shithub: scc

Download patch

ref: a16181de44abd57ab0d6a699ea8dabf823a01868
parent: 4cf31fcfe6db15aa70c8cb1f38894651ef168c16
author: Quentin Rameau <quinq@fifth.space>
date: Thu Jun 2 21:00:00 EDT 2016

[driver] add support for building from intermediary files

--- a/driver/posix/scc.c
+++ b/driver/posix/scc.c
@@ -99,6 +99,7 @@
 			strcat(t->cmd, t->bin);
 			break;
 		case AS:
+			t->nargs = 2;
 			t->args[1] = "-o";
 			break;
 		default:
@@ -142,12 +143,10 @@
 	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 @@
 	if (fdin) {
 		t->in = fdin;
 		fdin = 0;
+	} else {
+		t->args[t->nargs + 1] = input;
 	}
 
 	if (output < NR_TOOLS) {
@@ -208,7 +209,23 @@
 		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 @@
 	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) {