Explorar o código

Added dependency generator, reduced size of type structure

ceriel %!s(int64=34) %!d(string=hai) anos
pai
achega
a379e76138

+ 4 - 0
lang/cem/cemcom.ansi/Makefile

@@ -289,6 +289,7 @@ main.o: input.h
 main.o: inputtype.h
 main.o: level.h
 main.o: lint.h
+main.o: macro.h
 main.o: nobitfield.h
 main.o: nocross.h
 main.o: nopp.h
@@ -429,9 +430,12 @@ ch3bin.o: idf.h
 ch3bin.o: label.h
 ch3bin.o: lint.h
 ch3bin.o: nobitfield.h
+ch3bin.o: nocross.h
 ch3bin.o: nopp.h
+ch3bin.o: sizes.h
 ch3bin.o: spec_arith.h
 ch3bin.o: struct.h
+ch3bin.o: trgt_sizes.h
 ch3bin.o: type.h
 cstoper.o: Lpars.h
 cstoper.o: arith.h

+ 22 - 1
lang/cem/cemcom.ansi/cemcom.1

@@ -43,6 +43,23 @@ and at each return to call the routine
 .BE procexit .
 These routines are supplied with one parameter, a pointer to a
 string containing the name of the procedure.
+.IP \fB\-A\fR[\fIfile\fR]
+.br
+if \fIfile\fR is not given, generate a list
+of makefile dependencies and write them to the standard output.
+If \fIfile\fP is given,
+generate the list of makefile dependencies on file \fIfile\fP.
+.IP \fB-i\fR
+when generating makefile dependencies, do not include files from
+/usr/include.
+.IP \fB-m\fR
+when generating makefile dependencies, generate them in the following format:
+.RS
+.IP "file.o: file1.h"
+.RE
+.IP ""
+where "file.o" is derived from the source file name. Normally, only a list
+of files included is generated.
 .IP \fB\-R\fR
 interpret the input as restricted C (according to the language as 
 described in \fIThe C programming language\fR by Kernighan and Ritchie.)
@@ -61,7 +78,11 @@ Absence of \fIm\fR or \fIn\fR causes the default value to be retained.
 To specify that the bitfields should be right adjusted instead of the
 default left adjustment, specify \fBr\fR as \fIc\fR parameter.
 .IP \fB\-w\fR
-suppress warning messages
+suppress warning messages.
+.IP \fB\-s\fR
+suppress stricts.
+.IP \fB\-a\fR
+suppress warnings and stricts.
 .IP \fB\-\-\fItext\fR
 .br
 where \fItext\fR can be either of the above or

+ 5 - 0
lang/cem/cemcom.ansi/decspecs.c

@@ -155,7 +155,12 @@ qualifier_type(tp, typequal)
 		dtp->tp_size = tp->tp_size;
 		dtp->tp_pointer = tp->tp_pointer;
 		dtp->tp_array = tp->tp_array;
+#if 0
+/* The tp_function field does not exist now. See the comment in the
+   function_of() routine.
+*/
 		dtp->tp_function = tp->tp_function;
+#endif
 		switch (fund) {
 		case ARRAY:
 			if (typequal) {

+ 2 - 0
lang/cem/cemcom.ansi/domacro.c

@@ -293,8 +293,10 @@ do_include()
 	if (filenm) {
 		if (!InsertFile(filenm, &inctable[tok==FILESPECIFIER],&result)){
 			error("cannot open include file \"%s\"", filenm);
+			add_dependency(filenm);
 		}
 		else {
+			add_dependency(result);
 			WorkingDir = getwdir(result);
 			File_Inserted = 1;
 			FileName = result;

+ 1 - 0
lang/cem/cemcom.ansi/macro.str

@@ -48,4 +48,5 @@ struct macro	{
 #define	K_LINE		10
 #define	K_PRAGMA	11
 #define	K_UNDEF		12
+#define K_FILE          100     /* for dependency generator */
 #endif NOPP

+ 76 - 0
lang/cem/cemcom.ansi/main.c

@@ -27,6 +27,8 @@
 #include	"nocross.h"
 #include	"sizes.h"
 #include	"align.h"
+#include	"macro.h"
+#include	"assert.h"
 
 extern struct tokenname tkidf[];
 extern char *symbol2str();
@@ -38,6 +40,10 @@ int inc_total = 0;
 int inc_max;
 char **inctable;
 
+extern int do_dependencies;
+extern char *dep_file;
+static File *dep_fd = STDOUT;
+
 extern char *getwdir();
 #endif NOPP
 
@@ -119,10 +125,80 @@ main(argc, argv)
 	if (options['m']) Info();
 #endif	DEBUG
 
+#ifndef NOPP
+	if (do_dependencies) {
+	    extern char *source;
+
+	    list_dependencies(source);
+	}
+#endif
 	sys_stop(err_occurred ? S_EXIT : S_END);
 	/*NOTREACHED*/
 }
 
+#ifndef NOPP
+
+struct idf    *file_head;
+extern char *strrindex();
+
+list_dependencies(source)
+char *source;
+{
+    register struct idf *p = file_head;
+
+    if (source) {
+	register char *s = strrindex(source, '.');
+
+	if (s && *(s+1)) {
+	    s++;
+	    *s++ = 'o';
+	    *s = '\0';
+	    /* the source may be in another directory than the
+	     * object generated, so don't include the pathname
+	     * leading to it.
+             */
+            if (s = strrindex(source, '/')) {
+		source = s + 1;
+	    }
+	}
+	else source = 0;
+    }
+    if (dep_file && !sys_open(dep_file, OP_WRITE, &dep_fd)) {
+	fatal("could not open %s", dep_file);
+    }
+    while (p) {
+	ASSERT(p->id_resmac == K_FILE);
+	dependency(p->id_text, source);
+	p = (struct idf *) (p->id_file);
+    }
+}
+
+add_dependency(s)
+char *s;
+{
+    register struct idf *p = str2idf(s, 0);
+    
+    if (! p->id_resmac) {
+	p->id_resmac = K_FILE;
+	p->id_file = (char *) file_head;
+	file_head = p;
+    }
+}
+
+dependency(s, source)
+char *s, *source;
+{
+    if (options['i'] && !strncmp(s, "/usr/include/", 13)) {
+	return;
+    }
+    if (options['m'] && source) {
+	fprint(dep_fd, "%s: %s\n", source, s);
+    }
+    else    fprint(dep_fd, "%s\n", s);
+}
+
+#endif NOPP
+
 char *source = 0;
 
 #ifdef GEN_NM_LIST

+ 8 - 4
lang/cem/cemcom.ansi/options

@@ -1,14 +1,20 @@
 User options:
+a	no warnings or stricts
+A	while running preprocessor, generate makefile dependencies
 C	while running preprocessor, copy comment
+d	perform a small dataflow analysis
 D	see identifier following as a macro
 E	run preprocessor only
+i	suppress /usr/include include files in dependency list
 I	expand include table with directory name following
+m	generate file.o: file1.h format dependency lines
 M	set identifier length
 n	don't generate register messages
-p	generate linenumbers and filename indications
-	while generating EM code
+L	don't generate linenumbers and filename indications
+p	trace
 P	in running the preprocessor do not output '# line' lines
 R	restricted C
+s	no stricts
 T	take path following as directory for storing temporary file(s)
 U	undefine predefined name
 V	set objectsize and alignment requirements
@@ -17,11 +23,9 @@ w	suppress warning diagnostics
 
 Debug options:
 
-d	perform a small dataflow analysis
 f	dump whole identifier table, including macros and reserved words
 h	supply hash table statistics
 i	print name of include files
-m	supply memory allocation statistics
 r	right-adjust bitfield
 t	dump table of identifiers
 u	unstack L_UNIVERSAL

+ 18 - 0
lang/cem/cemcom.ansi/options.c

@@ -25,6 +25,9 @@ extern char **inctable;
 extern int inc_pos;
 extern int inc_max;
 extern int inc_total;
+int do_dependencies = 0;
+char *dep_file = 0;
+
 #endif NOPP
 
 char options[128];			/* one for every char	*/
@@ -59,6 +62,21 @@ next_option:			/* to allow combined one-char options */
 		options[*text++] = 1;	/* flags, debug options etc.	*/
 		goto next_option;
 
+#ifndef LINT
+#ifndef NOPP
+        case 'A' :      /* Amake dependency generation */
+                do_dependencies = 1;
+                if (*text) {
+                        dep_file = text;
+                }
+                break;
+        case 'i':
+        case 'm':
+             	options[opt] = 1;
+            	break;
+#endif NOPP
+#endif LINT
+
 #ifndef	LINT
 #ifdef	DATAFLOW
 	case 'd':

+ 10 - 0
lang/cem/cemcom.ansi/type.c

@@ -126,7 +126,12 @@ function_of(tp, pl, qual)
 	struct proto *pl;
 	int qual;
 {
+#if 0
+/* See comment below */
 	register struct type *dtp = tp->tp_function;
+#else
+	register struct type *dtp;
+#endif
 
 	/* look for a type with the right qualifier */
 #if 0
@@ -136,6 +141,8 @@ function_of(tp, pl, qual)
    because updating the type works inside the data-structures for that type
    thus, a new type is created for very function. This may change in the
    future, when declarations with empty parameter lists become obsolete.
+   When it does, change type.str, decspecs.c, and this routine. Search for
+   the function_of pattern to find the places.
 */
 	while (dtp && (dtp->tp_typequal != qual || dtp->tp_proto != pl))
 		dtp = dtp->next;
@@ -151,8 +158,11 @@ function_of(tp, pl, qual)
 		dtp->tp_align = pointer_align;
 		dtp->tp_typequal = qual;
 		dtp->tp_proto = pl;
+#if 0
+/* See comment above */
 		dtp->next = tp->tp_function;
 		tp->tp_function = dtp;
+#endif
 	}
 	return dtp;
 }

+ 5 - 2
lang/cem/cemcom.ansi/type.str

@@ -10,13 +10,16 @@
 struct type	{
 	struct type *next;	/* used for ARRAY and for qualifiers */
 	short tp_fund;		/* fundamental type */
-	short tp_unsigned;
+	char tp_unsigned;
+	char tp_typequal;	/* type qualifier */
 	int tp_align;
-	int tp_typequal;	/* type qualifier */
 	arith tp_size;		/* -1 if declared but not defined */
 	struct type *tp_pointer;	/* to POINTER */
 	struct type *tp_array;		/* to ARRAY */
+#if 0
+/* This field is not needed now; see comment in function_of() routine. */
 	struct type *tp_function;	/* to FUNCTION */
+#endif
 	union {
 	    struct {
 		struct idf *tp__idf;	/* name of STRUCT, UNION or ENUM */