ack.git
6 years agoAdd test for EM _rck_. Fix traps in PowerPC ncg.
George Koehler [Mon, 25 Dec 2017 03:37:52 +0000 (22:37 -0500)]
Add test for EM _rck_.  Fix traps in PowerPC ncg.

The new test rck_e.e segfaults on PowerPC unless I make some changes.
The inline code for _rck_ was wrong because it didn't allow the trap
handler to return.  _sig_ forgot to push the old trap handler.

Move plat/linuxppc/libsys/trap.s to mach/powerpc/libem/trp.s and
rewrite it with simplified/extended mnemonics.  Remove .trap alias for
.trp procedure.  Add a missing `mtspr lr, r0` so we can return from
the trap handler.  Call write() and _exit() so trp.s works with both
linuxppc and osxppc.  Before, Mac OS X was wrongly using the trap.s
for Linux.

In powerpc/libem, simplify .aar4; teach .csa and .csb to raise the
trap if the default target is zero.

C programs don't need these changes.  You may relink your C programs
with the changed .csa and .csb, but C code doesn't raise the trap.
Modula-2 code can raise traps, so you may want to relink your Modula-2
programs with the changed libem, but you might keep your old .o files
from Modula-2.  You may need to recompile your Pascal programs (delete
old .o files from Pascal) because the Pascal compiler might use _rck_.

6 years agoOptimize `mr. X, X` after some instructions.
George Koehler [Sat, 23 Dec 2017 03:32:16 +0000 (22:32 -0500)]
Optimize `mr. X, X` after some instructions.

For example, when ncg emits
    slw r9,r8,r5
    mr. r9,r9
then top simplifies the code to
    slw. r9,r8,r5

6 years agoRemove INT32 and such. Adjust indentation.
George Koehler [Sat, 23 Dec 2017 02:18:58 +0000 (21:18 -0500)]
Remove INT32 and such.  Adjust indentation.

I understand `loi 4` more easily than `loi INT32`, because `loi 4`
appears in .e files.  So remove INT8, INT16, INT32, INT64.

Add a comment to explain r3 during unconditional jumps.

6 years agoGenerate shorter code for ret 4 and ret 8.
George Koehler [Sat, 23 Dec 2017 01:37:39 +0000 (20:37 -0500)]
Generate shorter code for ret 4 and ret 8.

6 years agoRemove two obsolete patterns.
George Koehler [Sat, 23 Dec 2017 00:57:42 +0000 (19:57 -0500)]
Remove two obsolete patterns.

These patterns seem to have no effect on the generated code.

6 years agoAdd FRAME_V tokens for local variables.
George Koehler [Fri, 22 Dec 2017 22:04:16 +0000 (17:04 -0500)]
Add FRAME_V tokens for local variables.

When storing to a local, stop killing the tokens of other locals,
unless they might overlap with the stored local.  This helps some
procedures that juggle locals when the locals aren't in registers.

Also use FRAME_V tokens for locals in statically enclosing procedures.
Rewrite _lxa_ as _lxl_, to skip the `addi ?,?,8` if we can add 8 to
the next constant.  The PowerPC code from _lxl_ is now sometimes
better, sometimes worse than before.

The i386 table provided the idea to use %size to find overlapping
locals.

6 years agoRevise the comments in the EM tests.
George Koehler [Thu, 21 Dec 2017 23:19:26 +0000 (18:19 -0500)]
Revise the comments in the EM tests.

You can cheat these tests if _cms_ and _cmu_ always push zero.

6 years agoAdd some tests for Modula-2.
George Koehler [Thu, 21 Dec 2017 22:44:03 +0000 (17:44 -0500)]
Add some tests for Modula-2.

6 years agoPass 4 bytes to fail(uint32_t)
George Koehler [Tue, 19 Dec 2017 02:58:57 +0000 (21:58 -0500)]
Pass 4 bytes to fail(uint32_t)

This would become necessary if something failed on a platform with
16-bit int (EM_WSIZE == 2).

Remove unreachable `ret 0`.  If reached, it wouldn't work to return
from _m_a_i_n.

6 years agoSimplify code by using cms EM_WSIZE to compare bytes.
George Koehler [Tue, 19 Dec 2017 02:52:13 +0000 (21:52 -0500)]
Simplify code by using cms EM_WSIZE to compare bytes.

This should work because the C compiler does it.

6 years agoRemove '\0' from output. Fix a compiler warning.
George Koehler [Tue, 19 Dec 2017 02:17:42 +0000 (21:17 -0500)]
Remove '\0' from output.  Fix a compiler warning.

Don't output '\0' in "@@FINISHED\0".

Cast code to unsigned int.  This helps platforms with 16-bit int, by
doing only the low 16 bits of the bitwise-and.  It also removes the
"(warning) conversion of long to pointer loses accuracy".

6 years agoAdd splitting coercions for IND_ALL_D.
George Koehler [Tue, 19 Dec 2017 01:59:04 +0000 (20:59 -0500)]
Add splitting coercions for IND_ALL_D.

Delete my wrong comment (from commits cfbc537a8f62f45432bd0) which
claimed that such coercions are not possible.

6 years agoEnable conditional expressions in splitting coercions.
George Koehler [Tue, 19 Dec 2017 01:39:56 +0000 (20:39 -0500)]
Enable conditional expressions in splitting coercions.

ncgg has parsed the optional conditional expression (optexpr) of each
splitting coercion since commit 72b83cc in 1985; but for almost 33
years, ncg has ignored the expression in c2_expr.

Few tables had conditional coercions (I only found them in arm and
m68020), and no tables had conditional splitting coercions, so this
only becomes a problem now as I try to add a conditional splitting
coercion to powerpc.

6 years agoRename two tokens. CONST_HZ was not hertz (Hz).
George Koehler [Mon, 18 Dec 2017 17:36:10 +0000 (12:36 -0500)]
Rename two tokens.  CONST_HZ was not hertz (Hz).

6 years agoIn coercions, try to reuse a register with the same token.
George Koehler [Sun, 17 Dec 2017 17:45:27 +0000 (12:45 -0500)]
In coercions, try to reuse a register with the same token.

This reduces code size.

6 years agoRename ANY_BHW to INT_W; add FLOAT_W, FLOAT_D.
George Koehler [Thu, 14 Dec 2017 21:26:19 +0000 (16:26 -0500)]
Rename ANY_BHW to INT_W; add FLOAT_W, FLOAT_D.

INT_W, the integer set, continues to exclude FSREG, because we can't
easily move FSREG to GPR.

ANY4 becomes ISET+FLOAT_W and ANY8 becomes FLOAT_D.

6 years agoDelete rules for sti 8 with REG IND_RC_D, with REG IND_RR_D.
George Koehler [Tue, 12 Dec 2017 18:36:43 +0000 (13:36 -0500)]
Delete rules for sti 8 with REG IND_RC_D, with REG IND_RR_D.

Prefer the rule with REG FREG, by coercing IND_RC_D or IND_RR_D to
FREG.  This rule looks better to ncg.  When ncg chose between coercion
to REG IND_RC_D or coercion to REG FREG, it chose REG FREG.  It only
chose REG IND_RC_D if the stack had exact REG IND_RC_D.

6 years agoThese instructions write to the CR.
George Koehler [Sun, 10 Dec 2017 19:01:14 +0000 (14:01 -0500)]
These instructions write to the CR.

6 years agoRevise stack shuffles and integer conversions in PowerPC ncg.
George Koehler [Sat, 9 Dec 2017 22:21:06 +0000 (17:21 -0500)]
Revise stack shuffles and integer conversions in PowerPC ncg.

Allow asp 4, exg 4 to shuffle tokens without coercing them into
registers; but comment why dup 4, dup 8 coerce tokens into registers.

Allow dup, dus, exg with larger sizes; and add tests dup_e.e and
exg_e.e to check that dup 20, dus, exg 20 work as well in powerpc as
in i80 and i86.

Then powerpc failed to compile loc 2 loc 4 cuu in dup_e.e.  Revise the
integer conversions, so powerpc can compile and pass the test.

6 years agoAdd more chances to put results in register variables.
George Koehler [Fri, 8 Dec 2017 22:19:26 +0000 (17:19 -0500)]
Add more chances to put results in register variables.

When a rule `uses REG ... yields %a`, the result %a is always a
temporary, never a regvar.  If the EM code uses _stl_ to put the
result in a regvar, then ncg emits _mr_ to move %a to the regvar.

There are two ways to put the result in the regvar without %a:

  1. Yield a token, as in `yields {MUL_RR, %2, %1}`, so that _stl_
     can move the token to the regvar without using %a.

  2. Provide a pattern, like `sli stl`, that just puts the result
     in `{LOCAL, $2}` and not %a.

Allow some tokens, like SUM_RIS and XEQ, onto the stack; and add
tokens like MUL_RR, and patterns like `sli stl`.

Delete patterns for `stl lol` and `sdl ldl` to avoid an extra
temporary %a when the local is a regvar.  Delete `lal sti lal loi`
because it would emit wrong code.

6 years agoSplit C from CONST.
George Koehler [Fri, 8 Dec 2017 00:24:09 +0000 (19:24 -0500)]
Split C from CONST.

Rename token CONST to C.  Define set CONST = C + CONST_STACK.  The
instructions with CONST operands can now accept CONST_STACK tokens;
some cases of {CONST, %1.val} become %1.

Also simplify two of _rlwinm_ into _slwi_ and _srwi_.

6 years agoAdd test for EM rol, ror. Fix i80, i86, powerpc.
George Koehler [Thu, 7 Dec 2017 22:16:21 +0000 (17:16 -0500)]
Add test for EM rol, ror.  Fix i80, i86, powerpc.

EM instructions _rol_ and _ror_ do rotate an integer left or right.
Our compilers and optimizers never emit _rol_ nor _ror_, but I might
want to use them in the future.

Add _rol_ and _ror_ to powerpc.  Fix `rol 4` and `ror 4` in both i80
and i86, where the rules for `rol 4` and `ror 4` seem to have never
been tested until now.

6 years agoCorrect the stack pointer when i80 shrinks an integer.
George Koehler [Thu, 7 Dec 2017 20:39:41 +0000 (15:39 -0500)]
Correct the stack pointer when i80 shrinks an integer.

The code used `sphl` to set the stack pointer, but the correct value
was in de, not hl.  Fix by swapping the values of de and hl, so `sphl`
is now correct.  When we shrink an integer from 4 to 2 bytes, both
registers de and hl point to copies of the result, but only one
register preserves the stack below the result.

This fixes writehex() in tests/plat/lib/test.c, when I compile it with
ack -mcpm, so it preserves the pointer to "0123456789abcdef", so it
writes hexadecimal digits and not garbage.

This bug goes back to commit 157b243 of Mar 18, 1985, so the bug is
32 years old, and probably the oldest bug that I ever fixed.

6 years agoKill registers a, de, when i80 ncg does Call libem.
George Koehler [Thu, 7 Dec 2017 03:14:00 +0000 (22:14 -0500)]
Kill registers a, de, when i80 ncg does Call libem.

I compiled tests/plat/lib/test.c with ack -mcpm, but i80 ncg did emit
wrong code in writehex(uint32_t) for

    "0123456789abcdef"[code & 0xf]

The code called '.and' to evaluate `code & 0xf`, then tried to call
'.cii' to narrow the result from 4 to 2 bytes, but it passed garbage
instead of 4 to '.cii'.  The rule for '.and' was

    pat and defined($1)
    kills ALL
    uses dereg={const2,$1}
    gen Call {label,".and"}

This failed to kill register de={const2,4}, so ncg pushed de,
expecting to push 4, but actually pushing garbage.

Fix such rules using `mvi a,...` or `lxi de,...` so ncg doesn't track
the token in the register.  This is like the i86 table.  A different
fix would use a dummy instruction `killreg a` or `killreg de` like the
m68020 table.

Also correct 1 to $1 when calling '.exg'.

6 years agoUse <stdarg.h> in util/misc/convert.c
George Koehler [Wed, 6 Dec 2017 22:09:12 +0000 (17:09 -0500)]
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

6 years agoMerge pull request #69 from kernigh/kernigh-stdc
David Given [Sun, 19 Nov 2017 11:00:40 +0000 (12:00 +0100)]
Merge pull request #69 from kernigh/kernigh-stdc

use libc assert, strcmp; declare more functions; fewer clang warnings

6 years agoMerge pull request #66 from davidgiven/dtrg-warnings
David Given [Sun, 19 Nov 2017 10:39:45 +0000 (11:39 +0100)]
Merge pull request #66 from davidgiven/dtrg-warnings

lang/basic/lib: fewer warnings

6 years agoFix build with gcc. kernigh-stdc
George Koehler [Fri, 17 Nov 2017 22:52:37 +0000 (17:52 -0500)]
Fix build with gcc.

gcc gave an error because the `char *` parameter doesn't match the
`const char *` in the prototype of regsave().  clang didn't give an
error.  I added the prototype in commit 5301cce.

6 years agoFix my typo from commit 5bbbaf4.
George Koehler [Fri, 17 Nov 2017 20:46:24 +0000 (15:46 -0500)]
Fix my typo from commit 5bbbaf4.

6 years agoSwitch ego to libc <assert.h>
George Koehler [Thu, 16 Nov 2017 00:48:53 +0000 (19:48 -0500)]
Switch ego to libc <assert.h>

I also tried, in types.h, to switch ego to libc <stdbool.h>, but that
causes an infinite loop in the IL phase.

6 years agoAdd prototypes, void in util/ego/share
George Koehler [Wed, 15 Nov 2017 21:29:27 +0000 (16:29 -0500)]
Add prototypes, void in util/ego/share

This uncovers a problem in il/il_aux.c: it passes 3 arguments to
getlines(), but the function expects 4 arguments.  I add FALSE as the
4th argument.  TRUE would fill in the list of mesregs.  IL uses
mesregs during phase 1, but this call to getlines() is in phase 2.
TRUE would leak memory unless I added a call to Ldeleteset(mesregs).
So I pass FALSE.

Functions passed to go() now have a `void *` parameter because
no_action() now takes a `void *`.

6 years agoLLgen won't update the output file timestamp if the file contents doesn't
David Given [Wed, 15 Nov 2017 18:41:39 +0000 (19:41 +0100)]
LLgen won't update the output file timestamp if the file contents doesn't
change, which confuses ninja no end. Fix this.

Fixes: #68

6 years agoUse size_t and void with memory allocation in ego.
George Koehler [Wed, 15 Nov 2017 01:35:18 +0000 (20:35 -0500)]
Use size_t and void with memory allocation in ego.

alloc.h now needs to #include <stdlib.h> to find type size_t and
function free().

6 years agostrcmp, strncmp are in <string.h>
George Koehler [Tue, 14 Nov 2017 22:04:01 +0000 (17:04 -0500)]
strcmp, strncmp are in <string.h>

*Important:*  Do `make clean` to work around a problem and prevent
infinite rebuilds, https://github.com/davidgiven/ack/issues/68

I edit tokens.g in util/LLgen/src, so I regenerate tokens.c.  The
regeneration script bootstrap.sh can't find LLgen, but I can run the
same command by typing the path to llgen.

6 years agoFree buf in GetFile().
George Koehler [Tue, 14 Nov 2017 02:34:31 +0000 (21:34 -0500)]
Free buf in GetFile().

aprintf() returns a const char *; the assignment to char * caused both
clang and gcc to warn of the dropped const.

Commit 893471a introduced a tiny memory leak, because GetFile()
stopped freeing buf.  The const return type of aprintf() suggests that
the buffer must not be freed.

Now use Malloc() to allocate the buffer and free() to free it.  This
also checks if we are out of memory, because Malloc() does the check
and aprintf() currently doesn't.

6 years agoCheck each format string in tabgen.c
George Koehler [Tue, 14 Nov 2017 01:40:43 +0000 (20:40 -0500)]
Check each format string in tabgen.c

Silence warning from clang at `if (ch2 = ...)`

Delete `|| rm %{outs}` in build.lua, because it hid the exit status of
tabgen, so if tabgen failed, the build continued and failed later.

6 years agoSilence warning about pointer cast to int.
George Koehler [Mon, 13 Nov 2017 23:21:26 +0000 (18:21 -0500)]
Silence warning about pointer cast to int.

This cast was safe because the pointer is a small constant integer,
but it causes warning from gcc.

6 years agostrcpy() is in <string.h>
George Koehler [Mon, 13 Nov 2017 22:57:02 +0000 (17:57 -0500)]
strcpy() is in <string.h>

6 years agoDeclare machine-dependent functions in mach/proto/ncg
George Koehler [Mon, 13 Nov 2017 19:23:44 +0000 (14:23 -0500)]
Declare machine-dependent functions in mach/proto/ncg

This breaks all machines because the declared return type void
disagrees with the implicit return type int (when I compile mach.c
with clang).  Unbreak i386, i80, i86, m68020, powerpc, vc4 by adding
the return types to mach.c.  We don't build any other machines; they
are broken since commit a46ee91 (May 19, 2013) declared void prolog()
and commit fd91851 (Nov 10, 2016) declared void mes(), with both
declarations in mach/proto/ncg/fillem.c.

Also fix mach/vc4/ncg/mach.c where type full is long, so fprintf()
must use "%ld" not "%d" to print full nlocals.

6 years agoMore prototypes, less register in mach/proto/ncg
George Koehler [Mon, 13 Nov 2017 17:44:17 +0000 (12:44 -0500)]
More prototypes, less register in mach/proto/ncg

Files that #include "equiv.h" must do so after including "data.h", now
that a function prototype in equiv.h uses type rl_p from data.h.

Adjust style, changing some `for(...)` to `for (...)`.  The style in
mach/proto/ncg is less than consistent; the big annoyance now is that
some files want tabs at 4 spaces, others want tabs at 8 spaces.

6 years agoAdd prototypes to functions in subr.c
George Koehler [Sun, 12 Nov 2017 21:11:05 +0000 (16:11 -0500)]
Add prototypes to functions in subr.c

Put the declarations in "data.h", because that header declares the
types cost_t and token_p.  Also #include <cgg_cg.h> from "data.h" to
get types c3_p and set_p, and guard <cgg_cg.h> against multiple
inclusion.

6 years agoPrototypes for string functions. More static.
George Koehler [Sun, 12 Nov 2017 16:25:18 +0000 (11:25 -0500)]
Prototypes for string functions.  More static.

6 years agoRemove old "assert.h" in mach/proto/ncg
George Koehler [Sun, 12 Nov 2017 00:35:48 +0000 (19:35 -0500)]
Remove old "assert.h" in mach/proto/ncg

*Important:*  You must "make clean" after checking out this commit,
because the build had copied the old "assert.h" to several places in
obj/.  If you don't "make clean", then the compiler finds the old
"assert.h" before libc <assert.h>, and the build fails because this
commit removes badassertion() in subr.c.  After "make clean", the
compiler finds libc <assert.h> and the build succeeds.

6 years agoUse libc assert(); fix dependencies; unbreak isduo().
George Koehler [Sat, 11 Nov 2017 21:09:05 +0000 (16:09 -0500)]
Use libc assert(); fix dependencies; unbreak isduo().

Switch from custom assert() to libc assert() in mach/proto/as.
Continue to disable asserts if DEBUG == 0.

This change found a problem in the build system; comm2.y was missing
depedencies on comm0.h and comm1.h.  Add the missing dependencies to
the cppfile rule.  Allow the dependencies by modifying cppfile in
first/build.lua to act like cfile if t.dir is false.

Now that comm2.y gets rebuilt, I must fix the wrong prototype of
yyparse() in comm1.h.

I got unlucky as induo() in comm5.c was reading beyond the end of the
array.  It found an operator "= " ('=' then space) in the garbage, so
it returned a garbage token number, and "VAR = 123" became a syntax
error.  Unbreak induo() by terminating the array.

6 years agoMerge pull request #65 from kernigh/kernigh-qemu
David Given [Sat, 11 Nov 2017 20:00:16 +0000 (21:00 +0100)]
Merge pull request #65 from kernigh/kernigh-qemu

unbreak qemuppc

6 years agoAdd more const in <object.h>.
George Koehler [Sat, 11 Nov 2017 18:08:13 +0000 (13:08 -0500)]
Add more const in <object.h>.

6 years agoAdd more prototypes in mach/proto/as
George Koehler [Sat, 11 Nov 2017 04:30:46 +0000 (23:30 -0500)]
Add more prototypes in mach/proto/as

Change "register i;" to "int i;" to so clang stops warning about
implicit int.  Use function prototypes so clang stops warning about
implicitly declared functions.

6 years agobts2str(), long2str() are in <ack_string.h>
George Koehler [Fri, 10 Nov 2017 22:31:11 +0000 (17:31 -0500)]
bts2str(), long2str() are in <ack_string.h>

6 years agoAdjust dependencies in modules/src{print,string,system}
George Koehler [Fri, 10 Nov 2017 21:26:27 +0000 (16:26 -0500)]
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.

6 years agoRemove functions that also exist in libc.
George Koehler [Fri, 10 Nov 2017 04:25:17 +0000 (23:25 -0500)]
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.

6 years agoDelete old "assert.h" files; use libc <assert.h>.
George Koehler [Fri, 10 Nov 2017 03:22:13 +0000 (22:22 -0500)]
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.

6 years agoIncrease time-out from 5 to 15 seconds.
George Koehler [Wed, 8 Nov 2017 20:02:56 +0000 (15:02 -0500)]
Increase time-out from 5 to 15 seconds.

My computer is too slow, so qemuppc tests randomly timed out.  With
this commit, my machine passes the qemuppc tests (if I also edit the
top build.lua to enable qemuppc).

6 years agoShow tests that @@TIMEDOUT.
George Koehler [Wed, 8 Nov 2017 19:08:43 +0000 (14:08 -0500)]
Show tests that @@TIMEDOUT.

A `set -e` in testdriver.sh caused it to exit early and hide the
output of a @@TIMEDOUT test, so I never saw the @@TIMEDOUT marker.
Then build.lua added a @@FAIL marker.

6 years agoRestore an assignment deleted in commit 789f79b.
George Koehler [Wed, 8 Nov 2017 04:52:52 +0000 (23:52 -0500)]
Restore an assignment deleted in commit 789f79b.

Because of the accidental deletion, mcgg on my machine followed a
garbage pointer, and never wrote calls to emit_fragment.

A wrong call to `data->emit_reg(0, 0)` instead of the correct
`data->emit_fragment(0)` caused PowerPC mcg to emit an empty string
instead of `8(fp)`, causing a syntax error in PowerPC as.

The wrong `data->emit_reg(0, 0)` called the function emit_reg() in
mach/proto/mcg/pass_instructionselection.c, but that function
unfortunately has `if (vreg) { ... }`.  The call had vreg == NULL
because the fragment wasn't a vreg, but emit_reg() ignored the problem
and emit nothing.

6 years agoMerge pull request #63 from kernigh/kernigh-rm-fix
David Given [Tue, 31 Oct 2017 10:33:52 +0000 (11:33 +0100)]
Merge pull request #63 from kernigh/kernigh-rm-fix

small changes to C, Pascal, Modula-2, em_opt, getopt(), Makefile

6 years agoUpdate comment after commit 9a965ef.
George Koehler [Tue, 31 Oct 2017 01:24:18 +0000 (21:24 -0400)]
Update comment after commit 9a965ef.

6 years agoImprove how Makefile handles multiple goals.
George Koehler [Mon, 30 Oct 2017 21:09:19 +0000 (17:09 -0400)]
Improve how Makefile handles multiple goals.

 - Don't run BUILDSYSTEM more than once if there is more than one goal
   with '+'.
 - Don't pass goals without '+' to BUILDSYSTEM.
 - Use $(MAKE) because "make" might not be GNU make.  For me, "make"
   is BSD make.
 - Add a comment so readers know MAKECMDGOALS is special.

Over in README, remove Lua from requirements; we always ignore any
installed Lua and build our own.  Increase guesses for free space
because we build more platforms.  Don't need to type MAKEFLAGS=.

6 years agoDon't use '-' in option string to getopt().
George Koehler [Mon, 30 Oct 2017 02:00:43 +0000 (22:00 -0400)]
Don't use '-' in option string to getopt().

@dram reported a build failure in FreeBSD at
https://github.com/davidgiven/ack/issues/1#issuecomment-273668299

Linux manual for getopt(3) says:
> If the first character of optstring is '-', then each nonoption
> argv-element is handled as if it were the argument of an option with
> character code 1....
>
> The use of '+' and '-' in optstring is a GNU extension.

GNU/Linux and OpenBSD handle '-' in this special way, but FreeBSD
seems not to.  If '-' is not special, then em_ego can't find its input
file, so the build must fail.  This commit stops using '-' in both
em_b and em_ego, but doesn't change mcg.

Also fix em_ego -O3 to not act like -O4.

6 years agoUse (arith) 1 << ... when getting the sign bit.
George Koehler [Sun, 29 Oct 2017 21:45:10 +0000 (17:45 -0400)]
Use (arith) 1 << ... when getting the sign bit.

This prevents an overflow reported by @hexcoder- in
https://github.com/davidgiven/ack/issues/56

lang/cem/cpp.ansi/LLlex.c used a plain 1 << ... and caused an overflow
on machines where sizeof(int) < sizeof(long).  Using 1L << ... would
work for now but might fail later if arith became long long.

C doesn't specify whether negative integers use 2's complement or some
other format.  Therefore, (arith) 1 << ... has an undefined value.  It
should still work because the value is some integer where the sign bit
is set and all other bits are clear.

(unsigned arith) 1 << ... would also get the sign bit, but casting it
from unsigned back to signed would make the same undefined value.

(arith) -1 << ... would assume 2's complement.

6 years agoRemove UNSIGNED_ARITH from a few more files.
George Koehler [Sun, 29 Oct 2017 21:03:51 +0000 (17:03 -0400)]
Remove UNSIGNED_ARITH from a few more files.

I missed these in commits 649410b and 1ab1306.

6 years agoAlways use unsigned long in lang/cem
George Koehler [Sun, 29 Oct 2017 21:01:29 +0000 (17:01 -0400)]
Always use unsigned long in lang/cem

Same reason as commit 649410b.

6 years agoFix pattern that was rewriting func(! var, var) as func(1).
George Koehler [Sun, 29 Oct 2017 18:53:33 +0000 (14:53 -0400)]
Fix pattern that was rewriting func(! var, var) as func(1).

Bug reported by Rune, see
 - https://sourceforge.net/p/tack/mailman/message/35809953/
 - https://github.com/davidgiven/ack/issues/62

In EM code, beq and bne pop 2 values and compare them, but teq and tne
pop only 1 value and compare it with zero.  We need cms to compare 2
values; other patterns may convert cmi or cmu to cms.

6 years agoFor DIAGOPT, change outshort(patno) to outshort(lino - 1).
George Koehler [Sun, 29 Oct 2017 18:18:47 +0000 (14:18 -0400)]
For DIAGOPT, change outshort(patno) to outshort(lino - 1).

This is more useful when looking for patterns; lino - 1 is probably
the line number in the patterns file.  DIAGOPT is off by default but
one can edit optim.h to enable it.

The other changes just clean up whitespace.

6 years agomktab depends on some of the *.h files.
George Koehler [Sun, 29 Oct 2017 01:41:59 +0000 (21:41 -0400)]
mktab depends on some of the *.h files.

If I edit optim.h to #define DIAGOPT then mktab must get rebuilt.

6 years agoGet correct sign of a MOD b when (a > 0) and (b < 0).
George Koehler [Sat, 28 Oct 2017 23:55:06 +0000 (19:55 -0400)]
Get correct sign of a MOD b when (a > 0) and (b < 0).

Reported by me in https://github.com/davidgiven/ack/issues/60

This doesn't change DIV.  Right now a DIV b does floor division and
a MOD b has the sign of b.  This is the same as Lua, Python, Ruby,
Tcl; but is different from other Modula-2 implementations.

6 years agoAlways use unsigned long.
George Koehler [Sat, 28 Oct 2017 21:56:20 +0000 (17:56 -0400)]
Always use unsigned long.

Traditional C compilers had long but not unsigned long.  I now assume
that everyone can compile unsigned long.  Remove macro UNSIGNED_ARITH
and act like it is always defined.  The type `unsigned arith` works
because arith is a macro for long.

6 years agoTerminal now writes to fd 1, not fd 0.
George Koehler [Sat, 28 Oct 2017 21:20:39 +0000 (17:20 -0400)]
Terminal now writes to fd 1, not fd 0.

Fixes problem where `./program </dev/null` didn't show output.

6 years agoDon't check ferror(fp) when reading fp.
George Koehler [Sat, 28 Oct 2017 20:20:48 +0000 (16:20 -0400)]
Don't check ferror(fp) when reading fp.

If feof(fp) or ferror(fp) was set, then our libc returned EOF for all
later reads without trying to read.  Our libc now behaves like BSD
(and probably Illumos and musl) by checking only feof(fp).  For
difference, glibc doesn't check feof(fp).

I described the difference between our libc and BSD libc in
https://sourceforge.net/p/tack/mailman/message/35430300/

6 years agoDelete unused misc/getpw.c from libc.
George Koehler [Sat, 28 Oct 2017 18:25:39 +0000 (14:25 -0400)]
Delete unused misc/getpw.c from libc.

@hexcoder- reported in https://github.com/davidgiven/ack/issues/57
that our getpw() has bugs.

I don't fix these bugs, because Illumos and Linux manual pages say
that getpw() is obsolete.  The function can overflow its buffer, so it
is never safe to use.  Our libc did not build getpw().

6 years agoDelete malloc.h and tgmath.h from libc.
George Koehler [Sat, 28 Oct 2017 17:57:10 +0000 (13:57 -0400)]
Delete malloc.h and tgmath.h from libc.

This malloc.h might get confused with the private malloc.h in our
libc.  C programs should #include <stdlib.h> for malloc().

This tgmath.h has no useful content, and never worked because
complex.h is missing.

Touch build.lua (by deleting some whitespace) so the *.h globs see
the deletions.

6 years agoBuild fdopen(), hypot(), putenv() in libc.
George Koehler [Sat, 28 Oct 2017 17:06:38 +0000 (13:06 -0400)]
Build fdopen(), hypot(), putenv() in libc.

These functions are in POSIX; hypot() is in C99.  Also build cabs()
because it rides with hypot(), but don't declare cabs() in any header
file, because our compiler can't parse C99 "double complex" type.

Touch build.lua so it sees that .c files moved.

6 years agoAdd .pas as a Pascal suffix.
George Koehler [Sat, 28 Oct 2017 15:59:35 +0000 (11:59 -0400)]
Add .pas as a Pascal suffix.

Requested by @dram in https://github.com/davidgiven/ack/issues/41

6 years agoRemove old files: TakeAction config.pm
George Koehler [Sat, 28 Oct 2017 14:55:51 +0000 (10:55 -0400)]
Remove old files: TakeAction config.pm

These files come from old build systems, and are useless since the old
build systems got deleted.  TakeAction is from proto.make system and
config.pm is from pmfile system.

6 years agoMerge pull request #59 from kernigh/kernigh-ppc-regs
David Given [Thu, 26 Oct 2017 14:15:55 +0000 (15:15 +0100)]
Merge pull request #59 from kernigh/kernigh-ppc-regs

PowerPC ncg: register allocation, floats, lxl

6 years agolwzu writes to the register in the token.
George Koehler [Thu, 19 Oct 2017 16:44:46 +0000 (12:44 -0400)]
lwzu writes to the register in the token.

6 years agoAdd a few more error checks and adjustments to reglap.
George Koehler [Thu, 19 Oct 2017 02:00:12 +0000 (22:00 -0400)]
Add a few more error checks and adjustments to reglap.

In util/ncgg, add two more errors for tables using reglap:
 - "Two sizes of reg_float can't be same size"
 - "Missing reg_float of size %d to contain %s"

In mach/proto/ncg, rename macro isregvar_size() to PICK_REGVAR(), so
the macro doesn't look like a function.  This macro sometimes doesn't
evaluate its second argument.

In mach/powerpc/ncg/mach.c, change type of lfs_set to uint32_t, and
change the left shifts from 1U<<regno to (uint32_t)1<<regno, because
1U would be too small for machines with 16-bit int.

6 years agoRename RELOLIS to RELOPPC_LIS.
George Koehler [Wed, 18 Oct 2017 19:39:31 +0000 (15:39 -0400)]
Rename RELOLIS to RELOPPC_LIS.

This relocation is specific to PowerPC.  @davidgiven suggested the
name RELOPPC_LIS in
https://github.com/davidgiven/ack/pull/52#issuecomment-279856501

Reindent the list in h/out.h and util/led/ack.out.5 because
RELOLIS_PPC is a long name.  I use spaces and no tabs because the tabs
looked bad in the manual page.

6 years agoEdit descr for linuxppc. Use powerpc.descr of ego.
George Koehler [Wed, 18 Oct 2017 17:23:01 +0000 (13:23 -0400)]
Edit descr for linuxppc.  Use powerpc.descr of ego.

ack -mlinuxppc -O4 now runs more phases of ego, including the register
allocation phase, so ncg emits better code.

Set MACHOPT_F=-m3 as I did it for osxppc; see commit 0c2b6f5.

Remove CC_ALIGN=-Vr so bitfields agree with gcc for PowerPC Linux.

Remove unused C_LIB and OLD_C_LIB.

6 years agoUse lwzu, stwu to tighten more loops.
George Koehler [Wed, 18 Oct 2017 16:12:42 +0000 (12:12 -0400)]
Use lwzu, stwu to tighten more loops.

Because lwzu or stwu moves the pointer, I can remove an addi
instruction from the loop, so the loop is slightly faster.

I wrote a benchmark in Modula-2 that exercises some of these loops.  I
measured its time on my old PowerPC Mac.  Its user time decreases from
8.401s to 8.217s with the tighter loops.

6 years agoAdd more rules for single-precision reg_float.
George Koehler [Tue, 17 Oct 2017 21:53:03 +0000 (17:53 -0400)]
Add more rules for single-precision reg_float.

The result of single-precision fadds, fsubs, and such can go into a
register variable, like we already do with double precision.  This
avoids an extra fmr from a temporary register to the regvar.

6 years agoStop inlining code to convert integers to floats.
George Koehler [Tue, 17 Oct 2017 21:00:28 +0000 (17:00 -0400)]
Stop inlining code to convert integers to floats.

Do the conversion by calling .cif8 or .cuf8 in libem, as it was done
before my commit 1de1e8f.  I used the inline conversion to experiment
with the register allocator, which was too slow until c5bb3be.

Now that libem has the only copy of the code, move some comments and
code changes there.

6 years agoUse my new regvar_w() and regvar_d() in PowerPC ncg.
George Koehler [Tue, 17 Oct 2017 18:15:33 +0000 (14:15 -0400)]
Use my new regvar_w() and regvar_d() in PowerPC ncg.

Rename GPRE to GPR_EXPR, then define FPR_EXPR and FSREG_EXPR.  Use
them for moves to register variables.

Keep "kills regvar($1)", because deleting it and recompiling libc
would cause many failures in my test programs.  Add comment to warn,
  /* ncg fails to infer that regvar($1) is dead! */

Remove "kills LOCAL %off==$1" because it seems to have no effect.

6 years agoAdd regvar_w() and regvar_d() for use with reglap.
George Koehler [Tue, 17 Oct 2017 16:05:41 +0000 (12:05 -0400)]
Add regvar_w() and regvar_d() for use with reglap.

If the ncg table uses reglap, then regvar($1, reg_float) would have
two sizes of registers.  An error from ncgg would happen if regvar()
was in a token that allows only one size.  Now one can pick a size
with regvar_w() for word size or regvar_d() for double-word size.

Add regvar_d and regvar_w as keywords in ncgg.  Modify EX_REGVAR to
include the register size.  In ncg, add some checks for the register
size.  In tables without reglap, regvar() works as before, and ncg
ignores the register size in EX_REGVAR.

6 years agoDo a move when coercing FREG to FREG or FSREG to FSREG.
George Koehler [Mon, 16 Oct 2017 16:07:55 +0000 (12:07 -0400)]
Do a move when coercing FREG to FREG or FSREG to FSREG.

6 years agoPowerPC ncg never uses the rules to stack LOCAL or DLOCAL.
George Koehler [Sun, 15 Oct 2017 19:22:52 +0000 (15:22 -0400)]
PowerPC ncg never uses the rules to stack LOCAL or DLOCAL.

6 years agoFix reglap for procedures that use both sizes of reg_float.
George Koehler [Sun, 15 Oct 2017 17:15:03 +0000 (13:15 -0400)]
Fix reglap for procedures that use both sizes of reg_float.

After the RA phase of ego, a procedure may put single-word and
double-word values in the same reg_float.  Then ncg will use both
LOCAL and DLOCAL tokens at the same offset.

I add isregvar_size() to ncg.  It receives the size of the LOCAL or
DLOCAL token, and picks the register of the correct size.  This fixes
a problem where ncg got the wrong-size register and corrupted the
stack.  This problem caused one of my test programs to segfault from
stack underflow.

Also adjust how fixregvars() handles both sizes.

6 years agoAdd function prototypes to mach/proto/ncg/regvar.c
George Koehler [Sun, 15 Oct 2017 15:01:18 +0000 (11:01 -0400)]
Add function prototypes to mach/proto/ncg/regvar.c

6 years agoMerge branch 'default' into kernigh-linuxppc
George Koehler [Sat, 14 Oct 2017 17:50:49 +0000 (13:50 -0400)]
Merge branch 'default' into kernigh-linuxppc

This merges several fixes and improvements from upstream.  This
includes commit 5f6a773 to turn off qemuppc.  I see several failing
tests from qemuppc; this merge will hide the test failures.

6 years agoAdd reglap to ncg. Add 4-byte reg_float to PowerPC ncg.
George Koehler [Sat, 14 Oct 2017 16:40:04 +0000 (12:40 -0400)]
Add reglap to ncg.  Add 4-byte reg_float to PowerPC ncg.

The new feature "reglap" allows two sizes of floating-point register
variables (reg_float), if each register overlaps a single register of
the other size.  PowerPC ncg uses reglap to define 4-byte instances
of f14 to f31 that overlap the 8-byte instances.

When ncgg sees the definition of fs14("f14")=f14, it removes the
8-byte f14 from its rvnumbers array, and adds the 4-byte fs14 in its
place.  Later, when ncg puts a variable in fs14, if it is an 8-byte
variable, then ncg switches to the 8-byte f14.  The code has
/* reglap */ comments in util/ncgg or #ifdef REGLAP in mach/proto/ncg

reglap became necessary because my commit a20b87c caused PowerPC ego
to allocate reg_float in both 4-byte and 8-byte sizes.

7 years agoMore ansification.
David Given [Sun, 6 Aug 2017 13:57:49 +0000 (15:57 +0200)]
More ansification.

7 years agoDon't try to run the tests on Travis.
David Given [Sun, 6 Aug 2017 12:27:15 +0000 (14:27 +0200)]
Don't try to run the tests on Travis.

7 years agomkstemp() is a bit more complex than it looks; because ego wants to use the
David Given [Sun, 6 Aug 2017 12:25:12 +0000 (14:25 +0200)]
mkstemp() is a bit more complex than it looks; because ego wants to use the
same base name and generate multiple files based on it, we can't really use
mkstemp() for every temporary file. Instead, use mkstemp() once on a
placeholder, then generate temporary names based on this. (And delete the
placeholder once we've finished.)

7 years agoDon't build mcg as part of linuxppc; it's not used and crashes Travis.
David Given [Sun, 6 Aug 2017 11:54:07 +0000 (13:54 +0200)]
Don't build mcg as part of linuxppc; it's not used and crashes Travis.

7 years agoTurn of qemuppc for now; it's crashing on Travis builds.
David Given [Sun, 6 Aug 2017 11:48:01 +0000 (13:48 +0200)]
Turn of qemuppc for now; it's crashing on Travis builds.

7 years agoFix Travis syntax error...
David Given [Sun, 6 Aug 2017 11:39:21 +0000 (13:39 +0200)]
Fix Travis syntax error...

7 years agoStop using mktemp() --- on Haiku, it always generates the same filenames,
David Given [Sun, 6 Aug 2017 11:22:05 +0000 (13:22 +0200)]
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.

7 years agoAnsification, warning fixes, C89ification.
David Given [Sun, 6 Aug 2017 10:42:17 +0000 (12:42 +0200)]
Ansification, warning fixes, C89ification.

7 years agoTurn off OSX Travis builds --- this is going to be hard to make work.
David Given [Sun, 6 Aug 2017 10:38:38 +0000 (12:38 +0200)]
Turn off OSX Travis builds --- this is going to be hard to make work.

7 years agoAnsification and warning fixes.
David Given [Sun, 6 Aug 2017 09:58:36 +0000 (11:58 +0200)]
Ansification and warning fixes.

7 years agoAttempt to correct file system case sensitivity.
David Given [Sun, 6 Aug 2017 09:15:53 +0000 (11:15 +0200)]
Attempt to correct file system case sensitivity.