Commit graph

556 commits

Author SHA1 Message Date
carl 56e64a1fd0 Merge remote-tracking branch 'upstream/default' into carl-ansi-part1
# Conflicts:
#	util/arch/archiver.c
#	util/led/finish.c
#	util/led/output.c
2019-03-24 21:42:56 +08:00
carl 75394c93e1 Better ANSI C portability. 2019-03-24 17:40:27 +08:00
George Koehler bec236c108 Include more headers to declare functions.
This causes clang to give fewer warnings of implicit declarations of
functions.

In mach/pdp/cv/cv.c, rename wr_int2() to cv_int2() because it
conflicts with wr_int2() in <object.h>.

In util/ack, rename F_OK to F_TRANSFORM because it conflicts with F_OK
for access() in <unistd.h>.
2019-03-22 15:59:35 -04:00
George Koehler cdbff0dd1c Include <fcntl.h> or <unistd.h>
This silences some clang warnings of implicit declarations of
functions.  The `register int` silences a warning of implicit int.
2019-03-22 14:19:02 -04:00
George Koehler f8cbe04447 Include <unistd.h> for lseek()
This unbreaks my build in OpenBSD.  The old `long lseek()` conflicts
with `off_t lseek()` in OpenBSD headers, because long and off_t are
different types.  Commit b4df26e caused "system.h" to include some
headers where OpenBSD declares lseek().

Manuals for lseek() say to #include <unistd.h>.  Do so to be portable
to systems where other headers don't declare lseek().
2019-03-22 13:18:07 -04:00
carl 6bfac1d24d + Add sys_tmpnam() and sys_basename() 2019-03-17 22:46:31 +08:00
carl da71e5a018 Addition of tmpnam system function. 2019-03-17 22:46:31 +08:00
carl 91adc2849b + Have the DEBUG version compile 2019-03-17 22:46:31 +08:00
carl 9e93eb642b Better type checking on function callback. 2019-03-17 22:46:31 +08:00
carl 4b5de6c203 Remove unused variable. 2019-02-21 00:43:49 +08:00
carl f7ba3eec50 Remove CMake changes and generic sed scripts so they are move to a separate branch. 2019-02-21 00:43:04 +08:00
carl a80248f204 * Was trying to use the new system API which is not ready causing stack issues. 2019-02-20 00:44:32 +08:00
carl b4df26e79d Better ANSI C compatibility and portability - part 1:
+ Addition of function prototypes.
+ Change function definitions to ANSI C style.
+ Initial support for CMake
+ Added support for sys_tmpdir for better portability.
2019-02-19 00:54:23 +08:00
carl 7317ae3291 * Initial support of CMake 2019-02-19 00:54:23 +08:00
carl 3214ddfa68 Better ANSI C compatibility and portability - part 1:
+ Addition of function prototypes.
+ Change function definitions to ANSI C style.
2019-02-19 00:54:23 +08:00
carl 288e81355e * Add missing header file. 2019-02-19 00:54:23 +08:00
carl bd25701a3f * Initial support of CMake 2019-02-19 00:54:23 +08:00
carl 18730a361d * Adapt to new sys_filesize prototype. 2019-02-19 00:54:23 +08:00
carl 8c7de90005 * Initial support of CMake 2019-02-19 00:54:23 +08:00
carl 7c7379c46f Better ANSI C compatibility and portability - part 1:
+ Addition of function prototypes.
+ Change function definitions to ANSI C style.
+ Convert to sed scripts some shell scripts for better portability.
+ Reduce usage of em_path.h (TMPDIR is no longer hard coded)
2019-02-19 00:54:23 +08:00
carl a4650360a3 * Initial support of CMake
+ Generation of header files is now made through a C program to make it more portable.
2019-02-19 00:54:23 +08:00
carl 0ac16f6116 Better ANSI C compatibility and portability - part 1:
+ Addition of function prototypes.
+ Change function definitions to ANSI C style.
+ Convert to sed scripts some shell scripts for better portability.
+ Reduce usage of em_path.h
2019-02-19 00:54:23 +08:00
carl 90d4797ff7 * Initial support of CMake 2019-02-19 00:54:23 +08:00
carl 0f75cc09ad Better ANSI C compatibility and portability - part 1:
+ Addition of function prototypes.
+ Change function definitions to ANSI C style.
+ Convert to sed scripts some shell scripts for better portability.
+ Reduce usage of em_path.h
2019-02-19 00:54:23 +08:00
carl 4555c1c8cf Better ANSI C compatibility and portability - part 1:
+ Addition of function prototypes.
+ Change function definitions to ANSI C style.
+ Convert to sed scripts some shell scripts for better portability.
+ Reduce usage of em_path.h
2019-02-19 00:54:23 +08:00
David Given 58698bed19 Removed a whole bunch of old strcpy() prototypes in favour of <string.h>. 2019-02-10 13:20:04 +01:00
David Given 9e2d45b301 Rename all files called 'aux.*' to something else; Windows can't handle them. 2019-02-09 00:02:41 +01:00
David Given fa1ba55ad2 Convert CRLF into LF on read; this should avoid problems with parsing CRLF files.
Fixes #117.
2018-09-02 11:30:20 +02:00
David Given 05ddefad65 Adopt a copy of Minix 2's ed; this allows the ACK's antiquated ed scripts to
run with a minimum of tweaking. Rewriting them for modern ed looks really hard.

Fixes: #84
2018-06-02 18:02:51 +02:00
George Koehler 860df1b067 Read from new, not old, buffer after realloc.
This got caught by MALLOC_OPTIONS=S in OpenBSD.  The B compiler filled
the buffer while compiling hilo.b.  Then realloc moved the buffer and
unmapped the old buffer.  The compiler tried to read the old buffer
and segfaulted.
2018-03-08 12:04:02 -05:00
George Koehler 0720671f7a Fix wr_ranlib() for big-endian machines.
With this change, I built and ran ack on a big-endian PowerPC Linux
machine.  I used gcc 4.9.4 to build ack, and I only built the linuxppc
back end.

Before this change, wr_ranlib() corrupted a value by changing it from
0x66 to 0x66000066.  This value was too big, so led made a fatal
error, "bad ranlib string offset".
2018-03-08 11:49:40 -05:00
George Koehler 88207db638 Use <stdarg.h> in util/misc/convert.c
I made a syntax error in some .e file, and em_encode dumped core
because a 64-bit pointer didn't fit in a 32-bit int.  Now use stdarg
to pass pointers to error() and fatal().

Stop using the number of errors as the exit status.  Many systems use
only the low 8 bits of the exit status, so 256 errors would become 0.

Also change modules/src/print to accept const char *buf
2017-12-06 17:09:12 -05:00
David Given 6d91bdbbbd
Merge pull request #69 from kernigh/kernigh-stdc
use libc assert, strcmp; declare more functions; fewer clang warnings
2017-11-19 12:00:40 +01:00
David Given fb90b7b8d8
Merge pull request #66 from davidgiven/dtrg-warnings
lang/basic/lib: fewer warnings
2017-11-19 11:39:45 +01:00
George Koehler 805c916ab0 Add more const in <object.h>. 2017-11-11 13:08:13 -05:00
George Koehler 3463f0c944 bts2str(), long2str() are in <ack_string.h> 2017-11-10 18:00:00 -05:00
George Koehler b5b1da6f1a Adjust dependencies in modules/src{print,string,system}
Drop dependency on <ansi.h> in modules+headers; assume that compiler
knows ANSI C89.

Add missing dependency from print to string; #include <ack_string.h>.

Because <print.h> had commented out the declarations of sys_lock() and
sys_unlock(), I now stop building lock.c and unlock.c.
2017-11-10 17:56:42 -05:00
George Koehler 6367467499 Remove functions that also exist in libc.
Some of these functions were slightly different from libc:

 - This strncpy() didn't pad the buffer with '\0' bytes beyond the end
   of the string; libc does the padding.  This string.3 manual said
   that this strncpy() does "null-padding", but it didn't.

 - This strcmp() and strncmp() compared using char (which might be
   signed); libc compares using unsigned char.
2017-11-09 23:35:54 -05: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 64f2fa9d46 Stop using mktemp() --- on Haiku, it always generates the same filenames,
pretty much guaranteeing temporary file overwrites on parallel builds. Use
mkstemp() instead which creates the files atomically.
2017-08-06 13:22:05 +02:00
David Given 789f79b369 Ansification, warning fixes, C89ification. 2017-08-06 12:42:17 +02:00
David Given 60e7d06d82 Ansification and warning fixes. 2017-08-06 11:58:36 +02:00
David Given fd10cf7ac2 Merge from trunk. 2017-08-06 10:42:16 +02:00
David Given 7ff0b65a0d Add missing headers. 2017-08-05 21:46:43 +02:00
David Given 0e020132f8 Fix a warning. 2016-12-12 21:17:01 +01:00
George Koehler ecdfb61c9d Merge branch 'default' into kernigh-osx
This brings in David Given's PowerPC changes, including the addition
of the modern code generator (mcg) for PowerPC.

Resolve minor conflicts in top build.lua and util/led/main.c
2016-11-28 16:20:56 -05:00
David Given 3e69d1185a Fix a whole lot more stray prototypes. 2016-11-24 21:47:40 +01:00
George Koehler 19310d2521 Make possible to #include <object.h>.
This header declares functions in libobject.  Our programs never
included object.h, but called functions in libobject without declaring
them.  So, our build system never put object.h in the include path;
any #include <object.h> would fail to find the header.

With this commit, a program may #include <object.h> if it has
modules/src/object+lib in its deps.

Declare structs in object.h so we can use them in prototypes without
gcc warning, "'struct whatever' declared inside parameter list".

Remove inclusion of ansi.h from object.h.  Programs would need to
depend on modules+headers to get ansi.h in the include path.
2016-11-22 11:13:14 -05:00
David Given 84ee75ec07 Merge from default. 2016-11-11 20:17:54 +01:00
David Given 57cb99ade1 Remove sys_time in favour of directly calling time(). 2016-11-09 21:52:04 +01:00
George Koehler e5e96d5226 Convert 1 to 1.0, not 0.0, for machines with 64-bit long.
This fixes flt_arith2flt() when sizeof(arith) != 4, where arith is
long.  When cemcom.ansi sees an expression like d + 1 (where d is some
double), it calls flt_arith2flt() to convert 1 to floating-point.  On
machines where sizeof(arith) != 4, the code did n >>= 1 when n should
not have been changed.  If n was 1, then n == 0 became true.  This
caused the code to convert 1 or -1 to 0.0.

My fix assumes sizeof(arith) >= 8, so I can use n >> 32.  Machines
with sizeof(arith) of 5 to 7 would need to do (uarith)n >> 32, where
uarith must be an unsigned integer type of same size as arith.

In startrek.c, the Enterprise can now dock with a starbase.  The
compiler no longer translates s1 - 1 to s1 - 0.0 and s1 + 1 to s1 +
0.0, so the game now looks for starbases next to the Enterprise.
2016-11-06 19:34:51 -05:00
George Koehler daeeb5aca3 Simplify flt_arith now that mantissa uses uint32_t.
It seems that someone wanted to build flt_arith with a compiler that
had long but not unsigned long.  This required extra code to
accomplish unsigned right shift, unsigned division, and unsigned
comparison using the signed operations.  Now that we use uint32_t, we
can simply use the unsigned operations and remove the ucmp() function.
We have similar code in mach/proto/fp/ and in
lang/cem/libcc.ansi/stdlib/ext_comp.c where we use the unsigned
operations.

Some long variables become uint32_t, and some masks with 0xFFFFFFFF
disappear because uint32_t has only 32 bits.

Update flt_arith.3 to show that mantissa uses uint32_t.

Provide a target to install modules/src/flt_arith/test.c as flt_test
so I can run the tests.
2016-11-05 21:51:53 -04:00
George Koehler 3bb41d3910 Switch flt_mantissa fields from long to uint32_t.
This seems to fix an error when flt_arith converts a literal
double-precision float to IEEE format.  For example, 0.5 and 0.75 got
converted to slightly below their correct values.

My host gcc for amd64 has 64-bit long, but flt_arith needs only 32
bits.  The code (at least flt_add.c) can make 32-bit overflows.  Such
overflows would set the higher bits of a 64-bit long, which might
cause problems later.

I need to use uint32_t and not int32_t because the code still uses
long, and the sign extension from int32_t to long would cause
problems.  The mantissa represents a value in [0, 2) that can't be
negative, so unsigned type is better.  Also, signed overflow is
undefined behavior in C, so flt_add.c better make overflows with
uint32_t and not int32_t.

This commit doesn't touch lang/cem/libcc.ansi/stdlib/ext_fmt.h which
continues to use unsigned long for its mantissa fields.
2016-11-05 17:00:24 -04:00
George Koehler 5c62ec2d8f Assume ANSI C in modules/src/flt_arith
Remove the #include "ansi.h" and always use the prototypes.
2016-11-05 16:24:18 -04:00
David Given 4ba409eb74 Ensure the modules properly depend on their headers. 2016-11-05 11:52:54 +01:00
David Given fee47b25c3 Merge from default. 2016-11-05 11:47:53 +01:00
David Given 7f64fe96c7 Properly declare the library headers as dependencies. 2016-11-05 11:47:36 +01:00
David Given ff58a6100f Add pmap_remove(). 2016-10-09 22:03:44 +02:00
David Given 4261744537 Replace pmap_get() with pmap_findleft() and pmap_findright(), to allow lookups
in both directions.
2016-10-08 23:32:13 +02:00
David Given b7af003dbb Add array_{appendall,removeall,appendallu}. 2016-10-08 00:20:26 +02:00
David Given b11f96e8fe Add array push/pop; fix ghastly memory overrun bug. 2016-10-02 17:24:31 +02:00
David Given a3cfe6047f More rigorous dealing of IR groups; no need for is_generated and is_root any
more (but now passes are required to set IR roots properly when changing
instructions).
2016-10-01 22:58:29 +02:00
David Given 4a3a9a98dc It doesn't really make a lot of sense to have BURG nonterminal names different
to register classes, so combine them. Refactor the map code.
2016-10-01 12:17:14 +02:00
David Given 3a973a19f3 Move fatal(), warning() and aprintf() into the new data module (because they're
really useful).
2016-09-30 19:10:30 +02:00
David Given ba1a3656a1 You can tell whether an item already exists in the array when calling
array_appendu() now.
2016-09-28 23:39:00 +02:00
David Given f552c9c7c6 Move map into the data module. 2016-09-26 23:03:04 +02:00
David Given c4b8e00ae2 Revamp the array module not to use nasty macros any more. Slightly more verbose
to use, but definitely cleaner.
2016-09-26 22:48:58 +02:00
David Given 3671892c34 Move the array library into the data module. 2016-09-26 22:24:49 +02:00
David Given bcc74ba18d Stupid stringlist is stupid. Use a proper data structure, properly abstracted
out (so other things can use it).
2016-09-25 12:18:39 +02:00
David Given f992eb28ac ANSIise to fix warnings. 2016-09-18 00:23:42 +02:00
David Given 24380e2a93 Abstract out the EM reader; skeleton of the tree builder. 2016-09-18 00:02:16 +02:00
David Given f67c98e239 Distributions are a pain --- let's not bother any more. Instead, we just tag
the repository and download a complete snapshot, old and ancient stuff and all.
2016-09-02 23:00:38 +02:00
David Given 612e38f1c6 Remove the old make-based build system, plus some big chunks of horribly
obsolete protomake build system.
2016-09-02 22:17:51 +02:00
David Given 2dab95eced Move the em_code headers into the em_code module. 2016-08-14 14:17:35 +02:00
David Given 4d24666432 Move util/data into modules/src/em_data, for consistency with the other
modules.
2016-08-14 14:09:38 +02:00
David Given 0d77cb8279 We can build our first C file. 2016-08-07 21:56:53 +02:00
David Given f9c77fca03 Replace the hacky cflags variable with an equally hacky but vastly
more useful magic vars variable.
2016-07-27 00:10:15 +02:00
David Given 2770a83837 More programs, more libraries. src/modules build files are now saner. 2016-07-23 00:30:31 +02:00
David Given 1fdc69fb97 cemcom.ansi now builds. 2016-07-19 23:43:14 +02:00
David Given bcf3408e36 More stuff builds; almost the C compiler now. 2016-07-14 23:54:13 +02:00
David Given d805052205 All the amisc binaries now build. 2016-06-19 09:32:45 +02:00
David Given 09554cb324 installable works, although it's a bit kludgy. Change the : separator to +
because : is special in make and non of the others I could think of would work.
2016-06-14 07:34:14 +02:00
David Given 015804afce cprogram works. 2016-06-09 07:14:41 +02:00
David Given f47bb49c1f Multiple build files work. Use deps intelligently. clibraries. 2016-06-09 06:55:44 +02:00
David Given 88bd7ce126 Remove defunct pmfiles.
--HG--
branch : default-branch
2016-06-03 13:56:50 +02:00
David Given ef8e6e25e0 Fix a whole pile of issues related to the failed attempt to increase
the number of types of relocation possible in the object file. (Now,
hopefully, working.)

Also change the object serialiser/deserialiser to never try to read or
write raw structures; it's way safer this way and we don't need the
performance boost any more.

--HG--
branch : default-branch
2016-03-18 21:46:55 +01:00
David Given 11377070fd Update distribution files.
--HG--
branch : dtrg-buildsystem
2013-05-15 23:46:15 +01:00
David Given 66aebcdd91 Pascal compiler now runs.
--HG--
branch : dtrg-buildsystem
rename : lang/basic/build.mk => lang/pc/build.mk
rename : lang/cem/cemcom.ansi/build.mk => lang/pc/comp/build.mk
rename : lang/basic/lib/build.mk => lang/pc/libpc/build.mk
2013-05-14 20:47:04 +01:00
David Given b0c238eb5d Made a start on building the runtimes for each platform and language; the
Linuxes all build.

--HG--
branch : dtrg-buildsystem
rename : modules/src/em_mes/build.mk => modules/src/read_em/build.mk
rename : plat/pc86/build.mk => plat/linux386/build.mk
rename : plat/pc86/build.mk => plat/linux68k/build.mk
rename : plat/pc86/build.mk => plat/linuxppc/build.mk
rename : util/ack/build.mk => util/misc/build.mk
2013-05-12 23:51:55 +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
George Koehler 7ef9b79c11 Merge deletion of many undead files. 2012-09-23 15:31:16 -04:00
George Koehler 0131ca4d46 Delete 689 undead files.
These files "magically reappeared" after the conversion from CVS to
Mercurial.  The old CVS repository deleted these files but did not
record *when* it deleted these files.  The conversion resurrected these
files because they have no history of deletion.  These files were
probably deleted before year 1995.  The CVS repository begins to record
deletions around 1995.

These files may still appear in older revisions of this Mercurial
repository, when they should already be deleted.  There is no way to fix
this, because the CVS repository provides no dates of deletion.

See http://sourceforge.net/mailarchive/message.php?msg_id=29823032
2012-09-20 22:26:32 -04:00
George Koehler be234ea759 *Again* fix fit16i() for systems with 64-bit long.
I already did this in abebf1586c06, but I edited the wrong file.  Then
in edddc6b7cd17, I deleted that file.

By fixing fit16i(), I can now compile ACK for OpenBSD/amd64.
2012-09-19 23:39:51 -04:00
George Koehler 8bf34937f1 Delete old and unused files from modules/src/em_code 2012-09-17 16:04:55 -04:00
George Koehler 99eb12a282 Fix fit16i() for systems with 64-bit long.
(long)0xFFFF8000 had expanded to 0x00000000FFFF8000.
With (long)(-0x8000), the compiler now extends the negative sign.
2012-09-16 19:57:07 -04:00
dtrg 67c4f3de87 Modified to allow a space between the sign and the first digit of a constant. 2007-04-23 23:24:46 +00:00
dtrg b611731ec3 Updated .distr files for the new release. 2007-02-25 12:51:55 +00:00
dtrg 6d58210806 em_table is now in /h, not /etc. 2007-02-25 12:51:21 +00:00
dtrg 6e509e22dd Added shell magic. 2007-02-25 12:46:11 +00:00
dtrg dbe10d2c19 Updated to the version 0.1 of Prime Mover (which involves some syntax changes). 2006-10-15 00:28:12 +00:00