Commit graph

36 commits

Author SHA1 Message Date
George Koehler 15950f9c95 Add long long literals like 123LL to ACK C.
For now, a long long literal must have the 'LL' or 'll' suffix.  A
literal without 'LL' or 'll' acts as before: it may become unsigned
long but not long long.  (For targets where int and long have the same
size, some literals change from unsigned int to unsigned long.)

Type `arith` may be too narrow for long long values.  Add a second
type `writh` for wide arithmetic, and change some variables from arith
to writh.  This may cause bugs if I forget to use writh, or if a
conversion from writh to arith overflows.  I mark some conversions
with (arith) or (writh) casts.

 - BigPars, SmallPars: Remove SPECIAL_ARITHMETICS.  This feature
   would change arith to a different type, but can't work, because it
   would conflict with definitions of arith in both <em_arith.h> and
   <flt_arith.h>.
 - LLlex.c: Understand 'LL' or 'll' suffix.  Cut size of constant when
   it overflows writh, not only when it overflows the target machine's
   types.  (This cut might not be necessary, because we might cut it
   again later.)  When picking signed long or unsigned long, check the
   target's long type, not the compiler's arith type; the old check
   for `val >= 0` was broken where sizeof(arith) > 4.
 - LLlex.h: Change struct token's tok_ival to writh, so it can hold a
   long long literal.
 - arith.c: Adjust to VL_VALUE being writh.  Don't convert between
   float and integer at compile-time if the integer might be too wide
   for <flt_arith.h>.  Add writh2str(), because writh might be too
   wide for long2str().
 - arith.h: Remove SPECIAL_ARITHMETICS.  Declare full_mask[] here,
   not in several *.c files.  Declare writh2str().
 - ch3.c, ch3bin.c, ch3mon.c, declarator.c, statement.g: Remove
   obsolete casts.  Adjust to VL_VALUE being writh.
 - conversion.c, stab.c: Don't declare full_mask[].
 - cstoper.c: Use writh for constant operations on VL_VALUE, and for
   full_mask[].
 - declar., field.c, ival.g: Add casts.
 - dumpidf.c: Need to #include "parameters.h" before checking DEBUG.
   Use writh2str, because "%ld" might not work.
 - eval.c, eval.h: Add casts.  Use writh when writing a wide constant
   in EM.
 - expr.c: Add and remove casts.  In fill_int_expr(), make expression
   from long long literal.  In chk_cst_expr(), allow long long as
   constant expression, so the compiler may accept `case 123LL:` in a
   switch statement.
 - expr.str: Change struct value's vl_value and struct expr's VL_VALUE
   to writh, so an expression may have a long long value at compile
   time.
 - statement.g: Remove obsolete casts.
 - switch.c, switch.str: Use writh in case entries for switch
   statements, so `switch (ll) {...}` with long long ll works.
 - tokenname.c: Add ULNGLNG so LLlex.c can use it for literals.
2019-09-04 22:14:38 -04:00
George Koehler 007a63d529 Begin to add long long to C compiler for linux386.
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.
2019-09-02 11:24:44 -04:00
carl 750a6bc684 Better ANSI C compatibility and portability:
+ Addition of function prototypes and include files.
+ Change function definitions to ANSI C style.
+ Initial support for CMake
+ Scripts to generate compiler header is now sed based.
2019-02-19 00:54:23 +08:00
George Koehler ca4bd38206 Delete old "assert.h" files; use libc <assert.h>.
Edit build.lua for programs losing their private assert.h, so they
depend on a list of .h files excluding assert.h.

Remove modules/src/assert; it would be a dependency of cpp.ansi but we
didn't build it, so cpp.ansi uses the libc assert.

I hope that libc <assert.h> can better report failed assertions.  Some
old "assert.h" files didn't report the expression.  Some reported a
literal "x", because traditional C expanded the macro parameter x in
"x", but ANSI C89 doesn't expand macro parameters in string literals.
2017-11-09 22:22:13 -05:00
David Given fd91851005 Add enough return types to the K&R C that the ACK builds (on Linux) using clang
now.
2016-11-10 22:04:18 +01:00
David Given c1aca7dae5 First milestone of replacing the build system.
--HG--
branch : dtrg-buildsystem
rename : lang/cem/cpp.ansi/Parameters => lang/cem/cpp.ansi/parameters.h
2013-05-12 20:45:55 +01:00
ceriel 8636e9d10a Changed Header into Id 1994-06-27 08:03:14 +00:00
ceriel 661597162d Bug fix in old-style/new-style mixing 1992-03-02 14:37:37 +00:00
ceriel a38be6605e Do not use '#endif/#else xxx'; it is not allowed for ANSI C 1991-12-17 13:12:22 +00:00
ceriel 82bad86ee6 a few minor fixes 1991-10-17 13:27:53 +00:00
ceriel 3a074a6f99 FIxed problem with volatile structs and the ./-> operators 1991-06-13 15:56:14 +00:00
ceriel ba2043808d correction: mixture of old-fashioned with ellipsis is always wrong 1991-04-03 10:02:40 +00:00
ceriel 8a25f4e66b Some minor mods in mixed mode checking 1991-03-27 12:46:37 +00:00
ceriel 3e16cf5116 Fix: prevent incorrect error messages 1991-03-26 09:45:20 +00:00
eck d7c15759ee added warning about old-fashioned declarations
cleaned up error reporting
changed implicit declaration handling
1990-11-02 09:23:27 +00:00
eck ba0cc3a57d fixed small bug (void expr. cast to void), squeezing for MINIX 1990-10-23 14:13:10 +00:00
eck c3f305bea1 fixed bug with undefined structs
ceriel changed debugging information
1990-10-19 11:21:43 +00:00
ceriel 0c6f2f490f the tp_sdef field of the type structure may only be used after checking tp_fund 1990-05-15 15:28:01 +00:00
eck aa4de95f26 various bug fixes & improvements 1990-04-06 15:37:16 +00:00
eck 84b8c8a6ca improved volatiles, added warning for possibly nested comments 1990-04-02 15:57:51 +00:00
eck ed2516a57a bug fixes after test-suite 1990-03-29 10:41:46 +00:00
eck 00876cd9df added alloction dump
shrunk some data structures
changed some ALLOCDEF's
changed setjmp to __setjmp
1990-01-10 17:33:35 +00:00
eck b3a142e244 fixed null-pointer constants and SkipToNewLine() 1989-12-12 12:52:03 +00:00
eck 5f3e4693e6 array type-checking was wrong 1989-11-28 15:28:52 +00:00
eck 671556cfc4 improved type-checking, fixed preprocessor bug, fixed syntax bug 1989-11-27 11:37:11 +00:00
eck 96da16ce33 fixed bugs, added dynamic buffer allocation to preprocessor 1989-11-22 13:58:36 +00:00
ceriel 676fee0a3e fixed bug which caused unsigned bitfield problems 1989-11-17 11:28:38 +00:00
eck 776233c718 improved qualifier checking 1989-11-13 14:01:50 +00:00
ceriel 67f9f2a74f many little changes: removed some lint complaints; max_int and max_unsigned
are now constants if NOCROSS is defined; added lexstrict and expr_strict,
and changed calls where needed
1989-11-08 16:52:34 +00:00
eck 7a18c01a7c relaxed typechecking a little bit 1989-10-31 10:48:20 +00:00
eck b6a7d4fa0f Minix again 1989-10-20 13:06:10 +00:00
ceriel 3d5569183e some more squeezing for Minix 1989-10-19 19:29:39 +00:00
ceriel e4857c2446 many minor modifications (it still will not fit on Minix!) 1989-10-19 14:53:25 +00:00
eck 8ff400fd0f squeezing for MINIX 1989-10-18 13:12:31 +00:00
eck 4bde31f78a minor changes concerning void and pre-processor 1989-09-29 16:20:38 +00:00
eck 00027d3893 some minor fixes, renamed ch7 stuff to ch3 1989-09-25 14:28:10 +00:00