From ae3e9716f52d84308f2bc21f22a192483e9bba58 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 23 Jan 1990 15:25:21 +0000 Subject: [PATCH] Added some code for dependency generator --- util/cpp/Makefile | 7 ++++++- util/cpp/Parameters | 9 +++++++++ util/cpp/domacro.c | 9 +++++++++ util/cpp/idf.h | 8 ++++++-- util/cpp/macro.h | 1 + util/cpp/main.c | 40 ++++++++++++++++++++++++++++++++++++++++ util/cpp/preprocess.c | 15 +++++++++++++-- util/cpp/replace.c | 1 - 8 files changed, 84 insertions(+), 6 deletions(-) diff --git a/util/cpp/Makefile b/util/cpp/Makefile index 49ca7b298..e4b2f5340 100644 --- a/util/cpp/Makefile +++ b/util/cpp/Makefile @@ -62,7 +62,7 @@ GSRC = char.c symbol2str.c GHSRC = errout.h idfsize.h ifdepth.h lapbuf.h \ nparams.h numsize.h obufsize.h \ parbufsize.h pathlength.h strsize.h textsize.h \ - botch_free.h debug.h inputtype.h dobits.h line_prefix.h + botch_free.h debug.h inputtype.h dobits.h line_prefix.h mkdep.h # Other generated files, for 'make clean' only GENERATED = tokenfile.g Lpars.h LLfiles LL.output lint.out \ @@ -172,6 +172,7 @@ domacro.o: input.h domacro.o: inputtype.h domacro.o: interface.h domacro.o: macro.h +domacro.o: mkdep.h domacro.o: nparams.h domacro.o: parbufsize.h domacro.o: textsize.h @@ -188,7 +189,10 @@ input.o: file_info.h input.o: input.h input.o: inputtype.h main.o: file_info.h +main.o: idf.h main.o: idfsize.h +main.o: macro.h +main.o: mkdep.h options.o: charoffset.h options.o: class.h options.o: idf.h @@ -205,6 +209,7 @@ preprocess.o: idfsize.h preprocess.o: input.h preprocess.o: inputtype.h preprocess.o: line_prefix.h +preprocess.o: mkdep.h preprocess.o: obufsize.h replace.o: LLlex.h replace.o: charoffset.h diff --git a/util/cpp/Parameters b/util/cpp/Parameters index 35aa0331e..32ba2fd37 100644 --- a/util/cpp/Parameters +++ b/util/cpp/Parameters @@ -66,3 +66,12 @@ #define LINE_PREFIX "#" /* prefix for generated line directives, either "#" or "#line" */ + + +!File: mkdep.h +#undef MKDEP 1 /* if defined, preprocessor only outputs + names of files included (not finished yet) + */ + + + diff --git a/util/cpp/domacro.c b/util/cpp/domacro.c index d01140164..f0c0b2954 100644 --- a/util/cpp/domacro.c +++ b/util/cpp/domacro.c @@ -23,6 +23,7 @@ #include "class.h" #include "macro.h" #include "bits.h" +#include "mkdep.h" IMPORT char **inctable; /* list of include directories */ IMPORT char *getwdir(); @@ -273,9 +274,17 @@ do_include() inctable[0] = WorkingDir; if (filenm) { if (!InsertFile(filenm, &inctable[tok==FILESPECIFIER],&result)){ +#ifndef MKDEP error("cannot find include file \"%s\"", filenm); +#else + warning("cannot find include file \"%s\"", filenm); + add_file(filenm); +#endif } else { +#ifdef MKDEP + add_file(result); +#endif WorkingDir = getwdir(result); svnestlevel[++nestcount] = nestlevel; FileName = result; diff --git a/util/cpp/idf.h b/util/cpp/idf.h index 99883606d..ab926f9fa 100644 --- a/util/cpp/idf.h +++ b/util/cpp/idf.h @@ -4,13 +4,17 @@ * See the copyright notice in the ACK home directory, in the file "Copyright". */ struct id_usr { - struct macro *idu_macro; + union { + struct macro *idu_macro; + struct idf *idu_file; + } idu_x; int idu_resmac; }; #define IDF_TYPE struct id_usr #define IDF_HSIZE 6 -#define id_macro id_user.idu_macro +#define id_macro id_user.idu_x.idu_macro +#define id_file id_user.idu_x.idu_file #define id_resmac id_user.idu_resmac #include diff --git a/util/cpp/macro.h b/util/cpp/macro.h index b9b33838f..175d5e95e 100644 --- a/util/cpp/macro.h +++ b/util/cpp/macro.h @@ -75,3 +75,4 @@ extern char *std_alloc(); #define K_LINE 9 #define K_UNDEF 10 #define K_PRAGMA 11 +#define K_FILE 100 /* for dependency generator */ diff --git a/util/cpp/main.c b/util/cpp/main.c index 5ac7408d7..70852a383 100644 --- a/util/cpp/main.c +++ b/util/cpp/main.c @@ -7,13 +7,20 @@ #include #include +#include #include "file_info.h" #include "idfsize.h" +#include "mkdep.h" +#ifdef MKDEP +#include "idf.h" +#include "macro.h" +#endif extern char *symbol2str(); extern char *getwdir(); extern int err_occurred; int idfsize = IDFSIZE; +extern char options[]; arith ifval; @@ -49,6 +56,9 @@ main(argc, argv) do_option(par); argc--, argv++; } +#ifdef MKDEP + options['P'] = 1; +#endif compile(argc - 1, &argv[1]); exit(err_occurred); } @@ -79,4 +89,34 @@ compile(argc, argv) source ? source : "stdin"); if (source) WorkingDir = getwdir(dummy); preprocess(source); +#ifdef MKDEP + list_files(); +#endif } + +#ifdef MKDEP +struct idf *file_head; + +list_files() +{ + register struct idf *p = file_head; + + while (p) { + assert(p->id_resmac == K_FILE); + print("%s\n", p->id_text); + p = p->id_file; + } +} + +add_file(s) + char *s; +{ + register struct idf *p = str2idf(s, 0); + + if (! p->id_resmac) { + p->id_resmac = K_FILE; + p->id_file = file_head; + file_head = p; + } +} +#endif diff --git a/util/cpp/preprocess.c b/util/cpp/preprocess.c index 20dbaee6b..d3814b51a 100644 --- a/util/cpp/preprocess.c +++ b/util/cpp/preprocess.c @@ -14,31 +14,42 @@ #include "idfsize.h" #include "bits.h" #include "line_prefix.h" - -char _obuf[OBUFSIZE]; +#include "mkdep.h" #ifdef DOBITS char bits[128]; #endif +#ifndef MKDEP +char _obuf[OBUFSIZE]; + Xflush() { sys_write(STDOUT, _obuf, OBUFSIZE); } +#endif preprocess(fn) char *fn; { register int c; +#ifndef MKDEP register char *op = _obuf; register char *ob = &_obuf[OBUFSIZE]; +#endif char Xbuf[256]; int lineno = 0; extern char options[]; +#ifndef MKDEP #define flush(X) (sys_write(STDOUT,_obuf,X)) #define echo(ch) if (op == ob) { Xflush(); op = _obuf; } *op++ = (ch); #define newline() echo('\n') +#else +#define flush(X) +#define echo(ch) (ch) +#define newline() +#endif if (! options['P']) { /* Generate a line directive communicating the diff --git a/util/cpp/replace.c b/util/cpp/replace.c index 8c4dd96f3..abf830983 100644 --- a/util/cpp/replace.c +++ b/util/cpp/replace.c @@ -78,7 +78,6 @@ replace(idef) struct idf *param; char *nam; extern char *GetIdentifier(); - extern struct idf *str2idf(); UnknownIdIsZero = 0; nam = GetIdentifier(); -- 2.34.1