007a63d529
Add long long type, but without literals; you can't say '123LL' yet. You can try constant operations, like `(long long)123 + 1`, but the compiler's `arith` type might not be wide enough. Conversions, shifts, and some other operations don't work in i386 ncg; I am using a union instead of conversions: union q { long long ll; unsigned long long ull; int i[2]; }; Hack plat/linux386/descr to enable long long (size 8, alignment 4) only for this platform. The default for other platforms is to disable long long (size -1). In lang/cem/cemcom.ansi, - BigPars, SmallPars: Add default size, alignment of long long. - align.h: Add lnglng_align. - arith.c: Convert arithmetic operands to long long or unsigned long long when necessary; avoid conversion from long long to long. Allow long long as an arithmetic, integral, or logical operand. - ch3.c: Handle long long like int and long when erroneously applying a selector, like `long long ll; ll.member` or `ll->member`. Add long long to integral and arithmetic types. - code.c: Add long long to type stabs for debugging. - conversion.c: Add long long to integral conversions. - cstoper.c: Write masks up to full_mask[8]. Add FIXME comment. - declar.g: Parse `long long` in code. - decspecs.c: Understand long long in type declarations. - eval.c: Add long long to operations, to generate code like `adi 8`. Don't use `ldc` with constant over 4 bytes. - ival.g: Allow long long in initializations. - main.c: Set lnglng_type and related values. - options.c: Add option like `-Vq8.4` to set long long to size 8, alignment 4. I chose 'q', because Perl's pack and Ruby's Array#pack use 'q' for 64-bit or long long values; it might be a reference to BSD's old quad_t alias for long long. - sizes.h: Add lnglng_size. - stab.c: Allow long long when writing the type stab for debugging. Switch from calculating the ranges to hardcoding them in strings; add 8-byte ranges as a special case. This also hardcodes the unsigned 4-byte range as "0;-1". Before it was either "0;-1" or "0;4294967295", depending on sizeof(long) in the compiler. - struct.c: Try long long bitfield, but it will probably give the error, "bit field type long long does not fit in a word". - switch.c: Update comment. - tokenname.c: Define LNGLNG (long long) like LNGDBL (long double). - type.c, type.str: Add lnglng_type and ulnglng_type. Add function no_long_long() to check if long long is disabled.
234 lines
4.9 KiB
C
234 lines
4.9 KiB
C
/*
|
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
*/
|
|
/* $Id$ */
|
|
/* U S E R O P T I O N - H A N D L I N G */
|
|
|
|
#include "parameters.h"
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <alloc.h>
|
|
#include "options.h"
|
|
#include "class.h"
|
|
#include "macro.h"
|
|
#include "idf.h"
|
|
#include "arith.h"
|
|
#include "sizes.h"
|
|
#include "align.h"
|
|
#include "error.h"
|
|
|
|
char options[128]; /* one for every char */
|
|
#ifdef LINT
|
|
char loptions[128]; /* one for every char */
|
|
#endif /* LINT */
|
|
|
|
extern int idfsize;
|
|
extern int density;
|
|
|
|
|
|
|
|
static int txt2int(register char **);
|
|
|
|
void do_option(char *text)
|
|
{
|
|
register char opt;
|
|
|
|
next_option: /* to allow combined one-char options */
|
|
switch (opt = *text++) {
|
|
|
|
case 0: /* to end the goto next_option loop */
|
|
break;
|
|
|
|
default:
|
|
#ifndef LINT
|
|
fatal("illegal option: %c", opt);
|
|
#else /* LINT */
|
|
warning("illegal option: %c", opt);
|
|
#endif /* LINT */
|
|
break;
|
|
|
|
case '-':
|
|
options[(int)*text++] = 1; /* flags, debug options etc. */
|
|
goto next_option;
|
|
|
|
#ifndef LINT
|
|
#endif /* LINT */
|
|
#ifdef DBSYMTAB
|
|
case 'g': /* symbol table for debugger */
|
|
options['g'] = 1;
|
|
options['n'] = 1;
|
|
break;
|
|
#endif /* DBSYMTAB */
|
|
|
|
#ifndef LINT
|
|
#ifdef DATAFLOW
|
|
case 'd':
|
|
#endif /* DATAFLOW */
|
|
case 'p': /* procentry/procexit */
|
|
case 'L' : /* no fil/lin */
|
|
case 'n': /* use no registers */
|
|
case 'w': /* no warnings will be given */
|
|
case 's': /* no stricts will be given */
|
|
case 'o': /* no complaints about old-style */
|
|
options[opt] = 1;
|
|
goto next_option;
|
|
case 'a': /* suppress all but errors diagnostics */
|
|
options['w'] = 1; /* implies -a */
|
|
options['s'] = 1;
|
|
goto next_option;
|
|
#endif /* LINT */
|
|
|
|
#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 */
|
|
case 'L': /* lintlibrary */
|
|
loptions[opt] = 1;
|
|
goto next_option;
|
|
#endif /* LINT */
|
|
|
|
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;
|
|
|
|
#ifdef LINT
|
|
case 'S' : { /* -Sint : static scope number for lint */
|
|
extern int stat_number;
|
|
stat_number = txt2int(&text);
|
|
break;
|
|
}
|
|
#endif /* LINT */
|
|
|
|
case 'T' : {
|
|
#ifdef USE_TMP
|
|
extern char *C_tmpdir;
|
|
if (*text)
|
|
C_tmpdir = text;
|
|
else
|
|
C_tmpdir = ".";
|
|
#else /* USE_TMP */
|
|
warning("-T option ignored");
|
|
#endif /* USE_TMP */
|
|
break;
|
|
}
|
|
|
|
#ifndef LINT
|
|
#ifndef NOCROSS
|
|
case 'V' : /* set object sizes and alignment requirements */
|
|
{
|
|
register arith sz, algn;
|
|
char c;
|
|
|
|
while ( (c = *text++) !=0) {
|
|
sz = txt2int(&text);
|
|
algn = 0;
|
|
if (*text == '.') {
|
|
text++;
|
|
algn = txt2int(&text);
|
|
}
|
|
switch (c) {
|
|
case 's': /* short */
|
|
if (sz != (arith)0)
|
|
short_size = sz;
|
|
if (algn != 0)
|
|
short_align = algn;
|
|
break;
|
|
case 'w': /* word */
|
|
if (sz != (arith)0)
|
|
dword_size = (word_size = sz) << 1;
|
|
if (algn != 0)
|
|
word_align = algn;
|
|
break;
|
|
case 'i': /* int */
|
|
if (sz != (arith)0)
|
|
int_size = sz;
|
|
if (algn != 0)
|
|
int_align = algn;
|
|
break;
|
|
case 'l': /* long */
|
|
if (sz != (arith)0)
|
|
long_size = sz;
|
|
if (algn != 0)
|
|
long_align = algn;
|
|
break;
|
|
case 'q': /* long long */
|
|
if (sz != (arith)0)
|
|
lnglng_size = sz;
|
|
if (algn != 0)
|
|
lnglng_align = algn;
|
|
break;
|
|
case 'f': /* float */
|
|
if (sz != (arith)0)
|
|
float_size = sz;
|
|
if (algn != 0)
|
|
float_align = algn;
|
|
break;
|
|
case 'd': /* double */
|
|
if (sz != (arith)0)
|
|
double_size = sz;
|
|
if (algn != 0)
|
|
double_align = algn;
|
|
break;
|
|
case 'x': /* long double */
|
|
if (sz != (arith)0)
|
|
lngdbl_size = sz;
|
|
if (algn != 0)
|
|
lngdbl_align = algn;
|
|
break;
|
|
case 'p': /* pointer */
|
|
if (sz != (arith)0)
|
|
pointer_size = sz;
|
|
if (algn != 0)
|
|
pointer_align = algn;
|
|
break;
|
|
case 'r': /* adjust bitfields right */
|
|
#ifndef NOBITFIELD
|
|
options['r'] = 1;
|
|
#else /* NOBITFIELD */
|
|
warning("bitfields are not implemented");
|
|
#endif /* NOBITFIELD */
|
|
break;
|
|
case 'S': /* initial struct alignment */
|
|
if (sz != (arith)0)
|
|
struct_align = sz;
|
|
break;
|
|
case 'U': /* initial union alignment */
|
|
if (sz != (arith)0)
|
|
union_align = sz;
|
|
break;
|
|
default:
|
|
error("-V: bad type indicator %c\n", c);
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
case 'S':
|
|
density = txt2int(&text);
|
|
break;
|
|
#endif /* NOCROSS */
|
|
#endif /* LINT */
|
|
}
|
|
}
|
|
|
|
static int txt2int(register char **tp)
|
|
{
|
|
/* the integer pointed to by *tp is read, while increasing
|
|
*tp; the resulting value is yielded.
|
|
*/
|
|
register int val = 0, ch;
|
|
|
|
while (ch = **tp, ch >= '0' && ch <= '9') {
|
|
val = val * 10 + ch - '0';
|
|
(*tp)++;
|
|
}
|
|
return val;
|
|
}
|