shithub: scc

Download patch

ref: 73484d036e8ddffd310884ab93be6ce4ae04a53c
parent: 6f62daf42e5a640e1250ae7322d920a9d6ae81fa
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Tue Jun 14 08:31:06 EDT 2016

[cc1] Add support for -U in cc1

POSIX indicates that -U remove any definition of a macro,
and it means that we have to parse -U options after having
initialized the preprocessor and having parsed -D options.

--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -4,6 +4,8 @@
 
 #define GLOBALCTX 0
 
+#define NR_USWITCHES 20
+
 /*
  * Definition of enumerations
  */
@@ -417,6 +419,7 @@
 extern void incdir(char *dir);
 extern void outcpp(void);
 extern Symbol *defmacro(char *s);
+extern void undefmacro(char *s);
 
 /*
  * Definition of global variables
--- a/cc1/cpp.c
+++ b/cc1/cpp.c
@@ -39,6 +39,12 @@
 }
 
 void
+undefmacro(char *s)
+{
+	killsym(lookup(NS_CPP, s));
+}
+
+void
 icpp(void)
 {
 	static char sdate[17], stime[14];
--- a/cc1/main.c
+++ b/cc1/main.c
@@ -38,8 +38,10 @@
 main(int argc, char *argv[])
 {
 	char *base;
+	static char *uvec[NR_USWITCHES], **umacro = uvec;
 
 	atexit(clean);
+	icpp();
 
 	ARGBEGIN {
 	case 'w':
@@ -51,6 +53,11 @@
 	case 'D':
 		defmacro(EARGF(usage()));
 		break;
+	case 'U':
+		if (umacro == &uvec[NR_USWITCHES])
+			die("too many -U switches");
+		*umacro++ = EARGF(usage());
+		break;
 	case 'd':
 		DBGON();
 		break;
@@ -64,6 +71,9 @@
 		usage();
 	} ARGEND
 
+	for (umacro = uvec; *umacro; umacro++)
+		undefmacro(*umacro);
+
 	if (argc > 1)
 		usage();
 
@@ -78,9 +88,7 @@
 	if (output && !freopen(output, "w", stdout))
 		die("error opening output: %s", strerror(errno));
 
-	icpp();
 	ilex(*argv);
-
 	if (onlycpp) {
 		outcpp();
 	} else {
--