Commit graph

1661 commits

Author SHA1 Message Date
George Koehler 2874806048 Tweak man syntax in aelflod.1 and aslod.1
Put end of sentence at end of line.  This is roff(7) syntax so the
formatter can make spacing between sentences.

Use the macro .PP to break paragraphs.  Use bold for the command name
in SYNOPSIS, to match other ack manuals.
2016-12-13 15:54:38 -05:00
David Given 3cce93586f Merge branch 'pr-osx' of https://github.com/kernigh/ack into kernigh-pr-osx 2016-12-05 20:14:54 +01:00
David Given 8c99e2b7ad Run all tests, even the ones which fail, and emit a test summary right at the
end of the build (and fail then).
2016-12-01 23:03:30 +01:00
David Given b7de58e34e Fix signal unsafety in testdriver.c. 2016-12-01 22:05:22 +01:00
David Given 90547157b4 Merge from default. 2016-11-30 22:07:29 +01:00
David Given d94c326465 Merge pull request #18 from kernigh/pr-util-ack
util/ack: use DEFAULT_PLATFORM, allow non-ASCII filenames, other changes
2016-11-30 22:00:55 +01:00
George Koehler 8ef7c31089 Write a powerpc.descr for ego and use it with osxppc.
No change to linuxppc and qemuppc.  They continue to run ego without
any descr file.

I copied m68020.descr to powerpc.descr and changed some numbers.  My
numbers are guesses; I know little about PowerPC cycle counts, and
almost nothing about ego.  This powerpc.descr causes most of the
example programs to shrink in size (without descr -> with descr):

  65429 -> 57237  hilo_b.osxppc        -8192
  36516 -> 32420  hilo_c.osxppc        -4096
  55782 -> 51686  hilo_mod.osxppc      -4096
  20096 -> 20096  hilo_p.osxppc            0
   8813 ->  8813  mandelbrot_c.osxppc      0
  93355 -> 89259  paranoia_c.osxppc    -4096
  92751 -> 84559  startrek_c.osxppc    -8192

(Each file has 2 Mach segments, then a symbol table.  Each segment
takes a multiple of 4096 bytes.  When the code shrinks, we lose a
multiple of 4096 bytes.)

I used "ack -mosxppc -O6 -c.so" to examine the assembly code for
hilo.mod and mandelbrot.c, both without and with descr.  This reveals
optimizations made only with descr, from 2 ego phases: SP (stack
pollution) and RA (register allocation).  In hilo.mod, SP deletes some
instructions that remove items from the stack.  These items get
removed when the function returns.  In both hilo.mod and mandelbrot.c,
RA moves some values into local variables, so ncg can make them into
register variables.  This shrinks code size, probably because register
variables get preserved across function calls.  More values stay in
registers, and ncg emits shorter code.

I believe that the ego descr file uses (time,space) tuples but the ncg
table uses (space,time) tuples.  This is confusing.  Perhaps I am
wrong, and some or all tuples are backwards.  My time values are the
cycle counts in latency from the MPC7450 Reference Manual (but not
including complications like "store serialization").

In powerpc.descr, I give the cost for saving and restoring registers
as if I was using chains of stw and lwz instructions.  Actually ncg
uses single stmw and lmw instructions with at least 2 instructions.
The (time,space) for stmw and lmw would be much less than the
(time,space) for chains of stw and lwz.  But this ignores the pipeline
of the MPC7450.  The chains of stw and lwz may run faster than stmw
and lmw in the pipeline, because the throughput may be better than the
latency.  By using the wrong values for (time,space), I'm trying to
tell ego that stmw and lmw are not better than chains of stw and lwz.
2016-11-30 15:29:19 -05:00
David Given 960584c0f3 Replace the hacky and broken pipeline in testdriver.sh with a custom-written
tool in C; much more robust and easier to understand, as well as avoiding the
dependency on timeout (which isn't Posix).
2016-11-29 20:59:43 +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
George Koehler 88c2ea63aa Use uint32_t in util/led/main.c
This uses uint32_t for the base, file offset, and alignment of each
section, to be consistent with the usage of uint32_t in h/out.h

Also declare setbit() as static.
2016-11-20 11:38:16 -05:00
David Given d5328492d7 Better handling of float conversions; more tests; converting to unsigned ints
works now.
2016-11-20 11:27:40 +01:00
David Given d31bc6a3f9 Made csa and csb work with mcg; adjust the libem functions and the
corresponding invocation in the ncg table so the same helpers can be used for
both mcg and ncg. Add a new IR opcode, FARJUMP, which jumps to a helper
function but saves volatile registers.
2016-11-19 10:55:41 +01:00
George Koehler 486c516242 Stop trying to remove core dumps.
unlink("core") doesn't work with OpenBSD, where core dumps have names
like "ncg.core".  Users who don't want core dumps can turn them off
with "ulimit -c 0" in sh(1).  Then the system doesn't write a core
dump.  That's better than writing core then unlinking it.
2016-11-15 11:58:13 -05:00
George Koehler 07b04c64c8 Let ack(1) compile files with non-ASCII names.
This commit changes how ack(1) parses backslashes in its descr files.
Before this commit, ack set the high bit of each character escaped by
a backslash, and later cleared all high bits in command arguments, but
this lost the high bits in non-ASCII filenames.  After this commit,
ack keeps backslashes in strings while processing them.  Functions
scanvars(), scanexpr(), doassign(), unravel(), addargs() now
understand backslashes.  I remove from ack_basename() the warning
about non-ASCII characters.

This commit makes some incompatible changes for backslashes in descr
files.  None of our descr files uses backslashes, except for those
backslashes that continue lines, and there are no changes for those
backslashes.  The problem with non-ASCII filenames had its cause in a
feature that we weren't using.

With this commit, ack now understands backslashes after the = sign in
both "var NAME=value" and "mapflag -flag NAME=value".  Before, ack
never scanned backslashes in "var" lines, so "var A=\{B}" failed to
prevent expansion of B.  Now it does.  Before, ack did scan for
backslashes in the "-flag NAME=" part of "mapflag" lines.  Now it
doesn't, so it is no longer possible to map a flag that contains a
literal space, tab, or star "*".

I removed the expansion of "{{" to "{".  One can use "\{" for a
literal "{", and "\{" now works in "var" lines.  Before and now, ack
never expanded "{" in flags for "mapflag", so the correct way to map a
literal flag "-{" remains "mapflag -{ ...", not "mapflag -{{ ...".
(The other way "mapflag -\{ ..." stops working with this commit.)

Backslashes in strange places, like "{NA\ME}", probably have different
behavior now.

Backslashes in "program" lines now work.  Before, ack scanned for
backslashes there but forgot to clear the high bits later.

Escaping < or > as \< or \> now works, and prevents substitution of
the input or output file paths.  Before, ack only expanded the first <
or > in each argument.  Now, it expands every unescaped < or > in an
argument, but this is an accident of how I rewrote the code.  I don't
suggest to put more than one each of < or > in a command.  The code no
longer optimizes away its recursive calls when the argument is "<".

The code continues to set or clear the high bit NO_SCAN on the first
characters of flags.  This doesn't seem to be a problem, because flags
usually begin with an ASCII hyphen '-'.
2016-11-15 11:33:35 -05:00
David Given 408b69b17d aelflod and aslod now default to not showing the memory dump. 2016-11-13 20:50:23 +01:00
George Koehler fafc8a0b8a Don't retry fork() in a loop.
If fork() fails, then report a fatal error.  Don't spin the cpu
retrying fork() until it succeeds.  It can fail when we reach a limit
on the number of processes.  Spinning on the cpu would slow down other
processes when we want them to exit.  This would get bad if we had a
parallel build with multiple ack processes spinning.
2016-11-13 12:45:01 -05:00
George Koehler e617f42503 Don't print a string after possibly freeing it.
new= newvar(name) takes ownership of the string and might free its
memory.  Don't print name.  Do print new->v_name.

Also #include <string.h> for strcmp().
2016-11-13 12:02:35 -05:00
George Koehler 65278bc9a9 In util/ack, add prototypes and static to functions.
Declare most functions before using them.  I declare some functions in
ack.h and some in trans.h (because trans.h declares type trf).  I
leave declarations of scanb() and scanvars() in .c files because they
need type growstring.  (I can't #include "grows.h" in another header
file as long as grows.h doesn't guard against multiple inclusion.)

Functions used within one file become static.  I remove a few tiny
functions.  I move a few functions or declarations to more convenient
places.  Some functions now return void instead of a garbage int.

I feel that keyword "register" is obsolete, so I removed it from where
I was editing.  This commit doesn't touch mktables.c
2016-11-12 21:12:45 -05:00
George Koehler 7b3f870f63 Don't build mktables.c in the ack binary.
It only worked by accident because main() in main.c was found before
main() in mktables.c.

Also add build dependencies on the local *.h files.
2016-11-11 17:06:25 -05:00
David Given 84ee75ec07 Merge from default. 2016-11-11 20:17:54 +01:00
David Given d82df74a7a Rename addr_t to address_t to avoid clashes with the system addr_t. 2016-11-11 20:17:10 +01: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 a8c4dac67c Merge from default (merging in George Koehler's PowerPC changes). 2016-10-29 22:40:40 +02:00
David Given a311e61360 Add support for preserved registers. 2016-10-29 20:22:44 +02:00
David Given 61349389fb More opcodes. sti can now cope with non-standard sizes (really need a better
fix for this). Hack in crude support for mismatched stack pushes and pops (ints
vs longs).
2016-10-29 12:48:05 +02:00
David Given 2cc2c0ae98 Lots more opcodes. Rearrange the stack layout so that fp->ab is a fixed value
(needed for CHAINFP and FPTOAB). Wire up lfrs to calls via a phi when
necessary, to allow call-bra-lfr chains.
2016-10-29 11:57:56 +02:00
David Given 9977ce841a Remove the bytes1, bytes2, bytes4, bytes8 attributes; remove the concept of a
register 'type'; now use int/float/long/double throughout to identify
registers. Lots of register allocator tweaks and table bugfixes --- we now get
through the dreading Mathlib.mod!
2016-10-25 23:04:20 +02:00
David Given abd0cedd61 Massive change to how IR types are handled; we use the type code for matching
rather than the size. Much cleaner and simpler.
2016-10-23 21:54:14 +02:00
David Given b1a3d76d6f Re-re-add the type inference layer, now I know more about how things work.
Remove that terrible float promotion code.
2016-10-22 23:04:13 +02:00
David Given 11b0bc1055 More opcodes. 2016-10-22 20:32:51 +02:00
David Given 2d52b1fdaa Remove GETRET; values are now returned directly by CALL. Fix a bug in
convertstackops which was resulting in duplicate IR groups.
2016-10-22 12:13:57 +02:00
David Given ceb938fb3c More opcodes. 2016-10-22 11:26:28 +02:00
David Given 7ae888b754 Hacky workaround the way the Modula-2 compiler generates non-standard sized
loads and saves. More opcodes; simplified table using macros.
2016-10-22 10:48:22 +02:00
David Given f851ab83af Better (and more correct) floating point conversions; fif; various new opcodes. 2016-10-22 00:48:26 +02:00
David Given 4db402f229 Add (pretty crummy) support for register aliases and static pairs of registers.
We should have enough functionality now for rather buggy 8-bit ints and
doubles. Rework the table and the platform.c to match.
2016-10-21 23:31:00 +02:00
David Given d6984d60ac Add parsing support for register aliases. 2016-10-20 21:47:28 +02:00
David Given e4fec71f9c Lots more opcodes; better eviction behaviour; better register moves. Lots more
PowerPC stuff (some working).
2016-10-19 23:29:05 +02:00
David Given d539389e81 Merge in the unfinished PowerPC branch. 2016-10-16 22:38:27 +02:00
David Given 6a06ce798b Add missing header that was causing builds to fail on Travis. 2016-10-16 17:58:01 +02:00
David Given 9504aec2bd Function termination gets routed through an exit block; we now have prologues
and epilogues. mcgg now exports some useful data as headers. Start factoring
out some of the architecture-specific bits into an architecture-specific file.
2016-10-15 18:38:46 +02:00
David Given 5ad3aa8595 Add a pile of new instructions used by Pascal; I'm going to need to think about
how locals and the local base are handled.
2016-10-15 13:07:59 +02:00
David Given 517120d0fb Allow asm names for registers which are different from the friendly names shown
in the tracing (because PowerPC register names are just numbers).
2016-10-15 11:42:47 +02:00
David Given bb17aea73a You can now mark a register as corrupting a certain register class; calls work,
or at least look like they work. The bad news is that the register allocator
has a rare talent for putting things in the wrong register.
2016-10-15 01:15:08 +02:00
David Given 98fe70a7de Output register equality constraints work. 2016-10-14 22:17:02 +02:00
David Given f06b51c981 Keep track of register types as well as attributes --- the type being how we
find new registers when evicting values. Input constraints work (they were
being ignored before). Various bug fixing so they actually work.
2016-10-12 22:58:46 +02:00
David Given 23c3575f0f The register allocator now makes a spirited attempt to honour register
attributes when allocating. Unfortunately, backward edges don't work (because
the limited def-use chain stuff doesn't work across basic blocks). Needs more
thought.
2016-10-09 15:09:34 +02:00
David Given cfe5312fcc Predicates can now take numeric arguments. The PowerPC predicates have been
turned into generic ones (as they'll be useful everywhere). Node arguments for
predicates require the '%' prefix for consistency. Hex numbers are permitted.
2016-10-09 12:32:36 +02:00
David Given 2198db69b1 Instruction predicates work now. 2016-10-08 11:35:33 +02:00
George Koehler 65c2a8a0ae Remove stackadjust and stackoffset() from ncg.
This feature has never been used since its introduction, more than 3
years ago, in David Given's commit c93cb69 of May 8, 2013.  The commit
was for "PowerPC and M68K work".  I am not undoing the entire commit.
I am only removing the stackadjust and stackoffset() feature.

This commit removes the feature from my branch kernigh-linuxppc.  This
removal includes the mach/proto/ncg parts.  The default branch already
removed most of the feature, but kept the mach/proto/ncg parts.  That
removal happened in commit 81778b6 of May 13, 2013 (which was a merge;
git diff af0dede 81778b6).  The branch dtrg-experimental-powerpc
merged the default branch but without the removal.  That merge was
commit 4703db0f of Sep 15, 2016 (git diff 8c94b13 4703db0).  My branch
kernigh-linuxppc is off branch dtrg-experimental-powerpc, so I can no
longer get the removal by merging default.

David Given described the stackadjust feature in
  https://sourceforge.net/p/tack/mailman/message/30814691/

The instruction stackadjust would add a value to the offset, and the
function stackoffset() would return this offset.  One would use this
to track sp - fp, then omit the frame pointer by not keeping fp in a
register.
2016-10-07 20:52:13 -04:00
David Given 7f901aa4d0 We're not using 'allocates' any more; clean up. 2016-10-06 21:33:43 +02:00