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.
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.
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_.
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.
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.
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'.
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
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.
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 *`.
*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.
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.
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.
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.
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.
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.
*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.
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.
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.
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.
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.
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.
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).
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.
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.
- 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=.
@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.
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.
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.
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.
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.