1987-03-10 17:51:10 +00:00
|
|
|
/*
|
|
|
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
|
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
|
|
*/
|
1986-03-10 13:07:55 +00:00
|
|
|
/* $Header$ */
|
1991-11-08 15:12:28 +00:00
|
|
|
/* U S E R O P T I O N - H A N D L I N G */
|
1986-03-10 13:07:55 +00:00
|
|
|
|
1988-09-20 16:44:27 +00:00
|
|
|
#include "lint.h"
|
1987-01-24 00:25:56 +00:00
|
|
|
#include "botch_free.h"
|
|
|
|
#include <alloc.h>
|
1986-09-24 13:53:16 +00:00
|
|
|
#include "nofloat.h"
|
1986-03-10 13:07:55 +00:00
|
|
|
#include "nopp.h"
|
|
|
|
#include "idfsize.h"
|
|
|
|
#include "nobitfield.h"
|
|
|
|
#include "class.h"
|
|
|
|
#include "macro.h"
|
|
|
|
#include "idf.h"
|
|
|
|
#include "arith.h"
|
|
|
|
#include "sizes.h"
|
|
|
|
#include "align.h"
|
1986-07-29 11:46:00 +00:00
|
|
|
#include "use_tmp.h"
|
1987-02-09 23:19:42 +00:00
|
|
|
#include "dataflow.h"
|
1987-03-25 23:14:43 +00:00
|
|
|
#include "noRoption.h"
|
1991-11-08 15:12:28 +00:00
|
|
|
#include "dbsymtab.h"
|
1986-03-10 13:07:55 +00:00
|
|
|
|
|
|
|
#ifndef NOPP
|
1987-05-11 14:08:58 +00:00
|
|
|
extern char **inctable;
|
1986-03-10 13:07:55 +00:00
|
|
|
extern int inc_pos;
|
1987-05-11 14:08:58 +00:00
|
|
|
extern int inc_max;
|
|
|
|
extern int inc_total;
|
1990-06-06 14:42:53 +00:00
|
|
|
int do_dependencies = 0;
|
|
|
|
char *dep_file = 0;
|
|
|
|
|
1991-12-17 14:11:15 +00:00
|
|
|
#endif /* NOPP */
|
1986-03-10 13:07:55 +00:00
|
|
|
|
1988-08-29 15:51:48 +00:00
|
|
|
char options[128]; /* one for every char */
|
1988-09-20 16:44:27 +00:00
|
|
|
#ifdef LINT
|
|
|
|
char loptions[128]; /* one for every char */
|
1991-12-17 14:11:15 +00:00
|
|
|
#endif /* LINT */
|
1988-09-20 16:44:27 +00:00
|
|
|
|
1986-03-10 13:07:55 +00:00
|
|
|
extern int idfsize;
|
1991-03-05 17:52:37 +00:00
|
|
|
extern int density;
|
1986-03-10 13:07:55 +00:00
|
|
|
|
1988-09-16 23:19:50 +00:00
|
|
|
static int txt2int();
|
1986-03-10 13:07:55 +00:00
|
|
|
|
|
|
|
do_option(text)
|
|
|
|
char *text;
|
|
|
|
{
|
1988-08-29 15:51:48 +00:00
|
|
|
register char opt;
|
|
|
|
|
1988-09-16 23:19:50 +00:00
|
|
|
next_option: /* to allow combined one-char options */
|
1988-08-29 15:51:48 +00:00
|
|
|
switch (opt = *text++) {
|
1986-03-10 13:07:55 +00:00
|
|
|
|
1988-09-16 23:19:50 +00:00
|
|
|
case 0: /* to end the goto next_option loop */
|
|
|
|
break;
|
|
|
|
|
1986-03-10 13:07:55 +00:00
|
|
|
default:
|
1988-09-20 16:44:27 +00:00
|
|
|
#ifndef LINT
|
1988-08-29 15:51:48 +00:00
|
|
|
fatal("illegal option: %c", opt);
|
1991-12-17 14:11:15 +00:00
|
|
|
#else /* LINT */
|
1988-09-20 16:44:27 +00:00
|
|
|
warning("illegal option: %c", opt);
|
1991-12-17 14:11:15 +00:00
|
|
|
#endif /* LINT */
|
1988-08-19 13:55:22 +00:00
|
|
|
break;
|
1988-09-16 23:19:50 +00:00
|
|
|
|
1986-12-04 16:29:44 +00:00
|
|
|
case '-':
|
1988-09-16 23:19:50 +00:00
|
|
|
options[*text++] = 1; /* flags, debug options etc. */
|
|
|
|
goto next_option;
|
1986-03-10 13:07:55 +00:00
|
|
|
|
1988-09-20 16:44:27 +00:00
|
|
|
#ifndef LINT
|
1988-08-19 13:55:22 +00:00
|
|
|
#ifdef DATAFLOW
|
1987-02-09 23:19:42 +00:00
|
|
|
case 'd':
|
1991-12-17 14:11:15 +00:00
|
|
|
#endif /* DATAFLOW */
|
1987-02-09 23:19:42 +00:00
|
|
|
case 'p': /* procentry/procexit */
|
|
|
|
case 'L' : /* no fil/lin */
|
|
|
|
case 'n': /* use no registers */
|
|
|
|
case 'w': /* no warnings will be given */
|
1988-08-29 15:51:48 +00:00
|
|
|
options[opt] = 1;
|
1988-09-16 23:19:50 +00:00
|
|
|
goto next_option;
|
1991-12-17 14:11:15 +00:00
|
|
|
#endif /* LINT */
|
1988-09-20 16:44:27 +00:00
|
|
|
|
|
|
|
#ifdef LINT
|
|
|
|
case 'h': /* heuristic tests */
|
|
|
|
case 'v': /* no complaints about unused arguments */
|
|
|
|
case 'a': /* check long->int int->long conversions */
|
|
|
|
case 'b': /* don't report unreachable break-statements */
|
|
|
|
case 'x': /* complain about unused extern declared variables */
|
|
|
|
case 'u': /* no "used but not defined"; for pass 2 */
|
1988-11-03 15:18:46 +00:00
|
|
|
case 'L': /* lintlibrary */
|
1988-09-20 16:44:27 +00:00
|
|
|
loptions[opt] = 1;
|
|
|
|
goto next_option;
|
1991-12-17 14:11:15 +00:00
|
|
|
#endif /* LINT */
|
1988-09-20 16:44:27 +00:00
|
|
|
|
1990-06-06 14:42:53 +00:00
|
|
|
#ifndef LINT
|
|
|
|
#ifndef NOPP
|
1991-11-08 15:12:28 +00:00
|
|
|
case 'A' : /* Amake dependency generation */
|
1990-06-06 14:42:53 +00:00
|
|
|
do_dependencies = 1;
|
|
|
|
if (*text) {
|
|
|
|
dep_file = text;
|
|
|
|
}
|
|
|
|
break;
|
1990-06-06 16:00:28 +00:00
|
|
|
case 'i':
|
1990-06-06 14:42:53 +00:00
|
|
|
case 'm':
|
|
|
|
options[opt] = 1;
|
|
|
|
break;
|
1991-12-17 14:11:15 +00:00
|
|
|
#endif /* NOPP */
|
|
|
|
#endif /* LINT */
|
1991-11-08 15:12:28 +00:00
|
|
|
#ifdef DBSYMTAB
|
|
|
|
case 'g': /* symbol table for debugger */
|
|
|
|
options['g'] = 1;
|
|
|
|
options['n'] = 1;
|
|
|
|
break;
|
|
|
|
#endif /* DBSYMTAB */
|
|
|
|
|
1988-09-20 16:44:27 +00:00
|
|
|
case 'R': /* strict version */
|
|
|
|
#ifndef NOROPTION
|
|
|
|
options[opt] = 1;
|
1991-12-17 14:11:15 +00:00
|
|
|
#else /* NOROPTION */
|
1987-03-25 23:14:43 +00:00
|
|
|
warning("-R option not implemented");
|
1991-12-17 14:11:15 +00:00
|
|
|
#endif /* NOROPTION */
|
1988-09-16 23:19:50 +00:00
|
|
|
goto next_option;
|
1987-02-09 23:19:42 +00:00
|
|
|
|
1988-08-19 13:55:22 +00:00
|
|
|
#ifdef ___XXX___
|
1987-02-09 23:19:42 +00:00
|
|
|
deleted, is now a debug-flag
|
1986-03-10 13:07:55 +00:00
|
|
|
case 'C' : /* E option + comment output */
|
1988-08-19 13:55:22 +00:00
|
|
|
#ifndef NOPP
|
1986-03-10 13:07:55 +00:00
|
|
|
options['E'] = 1;
|
|
|
|
warning("-C: comment is not output");
|
1991-12-17 14:11:15 +00:00
|
|
|
#else /* NOPP */
|
1986-03-10 13:07:55 +00:00
|
|
|
warning("-C option ignored");
|
1991-12-17 14:11:15 +00:00
|
|
|
#endif /* NOPP */
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
1991-12-17 14:11:15 +00:00
|
|
|
#endif /* ___XXX___ */
|
1986-03-10 13:07:55 +00:00
|
|
|
|
|
|
|
case 'D' : { /* -Dname : predefine name */
|
|
|
|
#ifndef NOPP
|
|
|
|
register char *cp = text, *name, *mactext;
|
|
|
|
|
|
|
|
if (class(*cp) != STIDF) {
|
|
|
|
error("identifier missing in -D%s", text);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
name = cp;
|
|
|
|
|
|
|
|
while (*cp && in_idf(*cp)) {
|
|
|
|
++cp;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!*cp) { /* -Dname */
|
|
|
|
mactext = "1";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (*cp == '=') { /* -Dname=text */
|
|
|
|
*cp++ = '\0'; /* end of name */
|
|
|
|
mactext = cp;
|
|
|
|
}
|
|
|
|
else { /* -Dname?? */
|
|
|
|
error("malformed option -D%s", text);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_def(str2idf(name), mactext, -1, strlen(mactext),
|
|
|
|
NOFLAG);
|
1991-12-17 14:11:15 +00:00
|
|
|
#else /* NOPP */
|
1986-03-10 13:07:55 +00:00
|
|
|
warning("-D option ignored");
|
1991-12-17 14:11:15 +00:00
|
|
|
#endif /* NOPP */
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1987-02-09 23:19:42 +00:00
|
|
|
#ifdef ___XXX___
|
1987-11-13 16:21:33 +00:00
|
|
|
deleted, is now a debug-flag
|
1986-03-10 13:07:55 +00:00
|
|
|
case 'E' : /* run preprocessor only, with #<int> */
|
|
|
|
#ifndef NOPP
|
|
|
|
options['E'] = 1;
|
1991-12-17 14:11:15 +00:00
|
|
|
#else /* NOPP */
|
1986-03-10 13:07:55 +00:00
|
|
|
warning("-E option ignored");
|
1991-12-17 14:11:15 +00:00
|
|
|
#endif /* NOPP */
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
1991-12-17 14:11:15 +00:00
|
|
|
#endif /* ___XXX___ */
|
1986-03-10 13:07:55 +00:00
|
|
|
|
|
|
|
case 'I' : /* -Ipath : insert "path" into include list */
|
|
|
|
#ifndef NOPP
|
|
|
|
if (*text) {
|
1987-05-11 14:08:58 +00:00
|
|
|
int i;
|
1986-03-10 13:07:55 +00:00
|
|
|
register char *new = text;
|
1991-11-08 15:12:28 +00:00
|
|
|
|
1987-05-11 14:08:58 +00:00
|
|
|
if (++inc_total > inc_max) {
|
1990-06-28 18:06:16 +00:00
|
|
|
inctable = (char **)
|
|
|
|
Realloc(inctable,(inc_max+=10)*sizeof(char *));
|
1987-05-11 14:08:58 +00:00
|
|
|
}
|
1991-11-08 15:12:28 +00:00
|
|
|
|
1990-09-27 17:50:52 +00:00
|
|
|
for (i = inc_pos++; i < inc_total; i++) {
|
1987-03-25 23:14:43 +00:00
|
|
|
char *tmp = inctable[i];
|
1991-11-08 15:12:28 +00:00
|
|
|
|
1990-06-28 18:06:16 +00:00
|
|
|
inctable[i] = new;
|
1986-03-10 13:07:55 +00:00
|
|
|
new = tmp;
|
|
|
|
}
|
|
|
|
}
|
1986-12-04 16:29:44 +00:00
|
|
|
else inctable[inc_pos] = 0;
|
1991-12-17 14:11:15 +00:00
|
|
|
#else /* NOPP */
|
1986-03-10 13:07:55 +00:00
|
|
|
warning("-I option ignored");
|
1991-12-17 14:11:15 +00:00
|
|
|
#endif /* NOPP */
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'M': /* maximum identifier length */
|
|
|
|
idfsize = txt2int(&text);
|
|
|
|
if (*text || idfsize <= 0)
|
|
|
|
fatal("malformed -M option");
|
|
|
|
if (idfsize > IDFSIZE)
|
|
|
|
fatal("maximum identifier length is %d", IDFSIZE);
|
|
|
|
break;
|
|
|
|
|
1987-02-09 23:19:42 +00:00
|
|
|
#ifdef ___XXX___
|
1987-11-13 16:21:33 +00:00
|
|
|
deleted, is now a debug-flag
|
1986-03-10 13:07:55 +00:00
|
|
|
case 'P' : /* run preprocessor stand-alone, without #'s */
|
|
|
|
#ifndef NOPP
|
|
|
|
options['E'] = 1;
|
|
|
|
options['P'] = 1;
|
1991-12-17 14:11:15 +00:00
|
|
|
#else /* NOPP */
|
1986-03-10 13:07:55 +00:00
|
|
|
warning("-P option ignored");
|
1991-12-17 14:11:15 +00:00
|
|
|
#endif /* NOPP */
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
1991-12-17 14:11:15 +00:00
|
|
|
#endif /* ___XXX___ */
|
1986-12-04 16:29:44 +00:00
|
|
|
|
1988-09-20 16:44:27 +00:00
|
|
|
#ifdef LINT
|
|
|
|
case 'S' : { /* -Sint : static scope number for lint */
|
|
|
|
extern int stat_number;
|
|
|
|
stat_number = txt2int(&text);
|
|
|
|
break;
|
|
|
|
}
|
1991-12-17 14:11:15 +00:00
|
|
|
#endif /* LINT */
|
1988-09-20 16:44:27 +00:00
|
|
|
|
1987-07-16 13:27:37 +00:00
|
|
|
case 'T' : {
|
1987-11-13 16:21:33 +00:00
|
|
|
#ifdef USE_TMP
|
1987-07-16 13:27:37 +00:00
|
|
|
extern char *C_tmpdir;
|
1986-07-29 11:46:00 +00:00
|
|
|
if (*text)
|
1987-07-16 13:27:37 +00:00
|
|
|
C_tmpdir = text;
|
1986-07-29 11:46:00 +00:00
|
|
|
else
|
1987-07-16 13:27:37 +00:00
|
|
|
C_tmpdir = ".";
|
1991-12-17 14:11:15 +00:00
|
|
|
#else /* USE_TMP */
|
1986-07-29 11:46:00 +00:00
|
|
|
warning("-T option ignored");
|
1991-12-17 14:11:15 +00:00
|
|
|
#endif /* USE_TMP */
|
1986-07-29 11:46:00 +00:00
|
|
|
break;
|
1987-07-16 13:27:37 +00:00
|
|
|
}
|
1991-11-08 15:12:28 +00:00
|
|
|
|
1986-03-10 13:07:55 +00:00
|
|
|
case 'U' : { /* -Uname : undefine predefined */
|
|
|
|
#ifndef NOPP
|
1987-03-25 23:14:43 +00:00
|
|
|
register struct idf *idef;
|
1986-03-10 13:07:55 +00:00
|
|
|
|
|
|
|
if (*text) {
|
|
|
|
if ((idef = str2idf(text))->id_macro) {
|
|
|
|
free_macro(idef->id_macro);
|
|
|
|
idef->id_macro = (struct macro *) 0;
|
|
|
|
}
|
|
|
|
}
|
1991-12-17 14:11:15 +00:00
|
|
|
#else /* NOPP */
|
1986-03-10 13:07:55 +00:00
|
|
|
warning("-U option ignored");
|
1991-12-17 14:11:15 +00:00
|
|
|
#endif /* NOPP */
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1988-09-20 16:44:27 +00:00
|
|
|
#ifndef LINT
|
1986-03-10 13:07:55 +00:00
|
|
|
case 'V' : /* set object sizes and alignment requirements */
|
1987-03-25 23:14:43 +00:00
|
|
|
#ifdef NOCROSS
|
|
|
|
warning("-V option ignored");
|
|
|
|
break;
|
1991-12-17 14:11:15 +00:00
|
|
|
#else /* NOCROSS */
|
1986-03-10 13:07:55 +00:00
|
|
|
{
|
1988-08-29 15:51:48 +00:00
|
|
|
register arith sz, algn;
|
1986-03-10 13:07:55 +00:00
|
|
|
char c;
|
|
|
|
|
|
|
|
while (c = *text++) {
|
1988-08-29 15:51:48 +00:00
|
|
|
sz = txt2int(&text);
|
|
|
|
algn = 0;
|
1986-03-10 13:07:55 +00:00
|
|
|
if (*text == '.') {
|
|
|
|
text++;
|
1988-08-29 15:51:48 +00:00
|
|
|
algn = txt2int(&text);
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
|
|
|
switch (c) {
|
|
|
|
case 's': /* short */
|
1988-08-29 15:51:48 +00:00
|
|
|
if (sz != (arith)0)
|
|
|
|
short_size = sz;
|
|
|
|
if (algn != 0)
|
|
|
|
short_align = algn;
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
|
|
|
case 'w': /* word */
|
1988-08-29 15:51:48 +00:00
|
|
|
if (sz != (arith)0)
|
|
|
|
dword_size = (word_size = sz) << 1;
|
|
|
|
if (algn != 0)
|
|
|
|
word_align = algn;
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
|
|
|
case 'i': /* int */
|
1988-08-29 15:51:48 +00:00
|
|
|
if (sz != (arith)0)
|
|
|
|
int_size = sz;
|
|
|
|
if (algn != 0)
|
|
|
|
int_align = algn;
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
|
|
|
case 'l': /* long */
|
1988-08-29 15:51:48 +00:00
|
|
|
if (sz != (arith)0)
|
|
|
|
long_size = sz;
|
|
|
|
if (algn != 0)
|
|
|
|
long_align = algn;
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
|
|
|
case 'f': /* float */
|
1986-09-12 09:16:07 +00:00
|
|
|
#ifndef NOFLOAT
|
1988-08-29 15:51:48 +00:00
|
|
|
if (sz != (arith)0)
|
|
|
|
float_size = sz;
|
|
|
|
if (algn != 0)
|
|
|
|
float_align = algn;
|
1991-12-17 14:11:15 +00:00
|
|
|
#endif /* NOFLOAT */
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
|
|
|
case 'd': /* double */
|
1986-09-12 09:16:07 +00:00
|
|
|
#ifndef NOFLOAT
|
1988-08-29 15:51:48 +00:00
|
|
|
if (sz != (arith)0)
|
|
|
|
double_size = sz;
|
|
|
|
if (algn != 0)
|
|
|
|
double_align = algn;
|
1991-12-17 14:11:15 +00:00
|
|
|
#endif /* NOFLOAT */
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
|
|
|
case 'p': /* pointer */
|
1988-08-29 15:51:48 +00:00
|
|
|
if (sz != (arith)0)
|
|
|
|
pointer_size = sz;
|
|
|
|
if (algn != 0)
|
|
|
|
pointer_align = algn;
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
|
|
|
case 'r': /* adjust bitfields right */
|
|
|
|
#ifndef NOBITFIELD
|
|
|
|
options['r'] = 1;
|
1991-12-17 14:11:15 +00:00
|
|
|
#else /* NOBITFIELD */
|
1986-03-10 13:07:55 +00:00
|
|
|
warning("bitfields are not implemented");
|
1991-12-17 14:11:15 +00:00
|
|
|
#endif /* NOBITFIELD */
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
|
|
|
case 'S': /* initial struct alignment */
|
1988-08-29 15:51:48 +00:00
|
|
|
if (sz != (arith)0)
|
|
|
|
struct_align = sz;
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
|
|
|
case 'U': /* initial union alignment */
|
1988-08-29 15:51:48 +00:00
|
|
|
if (sz != (arith)0)
|
|
|
|
union_align = sz;
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error("-V: bad type indicator %c\n", c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
1991-12-17 14:11:15 +00:00
|
|
|
#endif /* NOCROSS */
|
1991-03-05 17:52:37 +00:00
|
|
|
case 'S':
|
|
|
|
density = txt2int(&text);
|
|
|
|
break;
|
1991-12-17 14:11:15 +00:00
|
|
|
#endif /* LINT */
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1988-09-16 23:19:50 +00:00
|
|
|
static int
|
1986-03-10 13:07:55 +00:00
|
|
|
txt2int(tp)
|
1987-03-25 23:14:43 +00:00
|
|
|
register char **tp;
|
1986-03-10 13:07:55 +00:00
|
|
|
{
|
|
|
|
/* the integer pointed to by *tp is read, while increasing
|
|
|
|
*tp; the resulting value is yielded.
|
|
|
|
*/
|
1986-09-24 13:53:16 +00:00
|
|
|
register int val = 0, ch;
|
1991-11-08 15:12:28 +00:00
|
|
|
|
1986-03-10 13:07:55 +00:00
|
|
|
while (ch = **tp, ch >= '0' && ch <= '9') {
|
|
|
|
val = val * 10 + ch - '0';
|
|
|
|
(*tp)++;
|
|
|
|
}
|
|
|
|
return val;
|
|
|
|
}
|