scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit bcc4c2b84232c42faead193fc05879867f7dc7f2
parent a88a10c38215e4bd6317d65a33e3bb0dac02dfd8
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon,  5 Oct 2015 22:37:45 +0200

Add option -D option to cc1

This option allows define a variable to the user.

Diffstat:
Mcc1/cc1.h | 1+
Mcc1/cpp.c | 11+++++++++--
Mcc1/main.c | 6+++++-
3 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/cc1/cc1.h b/cc1/cc1.h @@ -401,6 +401,7 @@ extern bool cpp(void); 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 diff --git a/cc1/cpp.c b/cc1/cpp.c @@ -25,10 +25,17 @@ static char **dirinclude; 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 diff --git a/cc1/main.c b/cc1/main.c @@ -28,7 +28,7 @@ static void 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 @@ main(int argc, char *argv[]) arg0 = (cp = strrchr(*argv, '/')) ? cp+1 : *argv; if (!strcmp(arg0, "cpp")) onlycpp = 1; + for (;;) { nextiter: --argc, ++argv; @@ -56,6 +57,9 @@ main(int argc, char *argv[]) case 'E': onlycpp = 1; break; + case 'D': + defmacro(cp+1); + goto nextiter; case 'd': DBGON(); break;