shithub: scc

Download patch

ref: bcc4c2b84232c42faead193fc05879867f7dc7f2
parent: a88a10c38215e4bd6317d65a33e3bb0dac02dfd8
author: Roberto E. Vargas Caballero <[email protected]>
date: Mon Oct 5 18:37:45 EDT 2015

Add option -D option to cc1

This option allows define a variable to the user.

--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -401,6 +401,7 @@
 extern bool expand(char *begin, Symbol *sym);
 extern void incdir(char *dir);
 extern void outcpp(void);
+extern Symbol *defmacro(char *s);
 
 /*
  * Definition of global variables
--- a/cc1/cpp.c
+++ b/cc1/cpp.c
@@ -25,10 +25,17 @@
 unsigned cppctx;
 int disexpand;
 
-static Symbol *
+Symbol *
 defmacro(char *s)
 {
-	return install(NS_CPP, lookup(NS_CPP, s));
+	char *p;
+	Symbol *sym;
+
+	if ((p = strchr(s, '=')) != NULL)
+		*p++='\0';
+	sym = install(NS_CPP, lookup(NS_CPP, s));
+	sym->u.s = p;
+	return sym;
 }
 
 void
--- a/cc1/main.c
+++ b/cc1/main.c
@@ -28,7 +28,7 @@
 usage(void)
 {
 	fprintf(stderr,
-	        "usage: %s [-E] [-Idir] [-w] [-d] [-o output] [input]\n",
+	        "usage: %s [-E] [-Dmacro[=value]] [-Idir] [-w] [-d] [-o output] [input]\n",
 	        arg0);
 	exit(1);
 }
@@ -43,6 +43,7 @@
 	arg0 = (cp = strrchr(*argv, '/')) ? cp+1 : *argv;
 	if (!strcmp(arg0, "cpp"))
 		onlycpp = 1;
+
 	for (;;) {
 	nextiter:
 		--argc, ++argv;
@@ -56,6 +57,9 @@
 			case 'E':
 				onlycpp = 1;
 				break;
+			case 'D':
+				defmacro(cp+1);
+				goto nextiter;
 			case 'd':
 				DBGON();
 				break;