ack/util/LLgen/build.lua
George Koehler 8bb395b147 LLgen: use size_t, reduce warnings, other small changes
Use C89 size_t for sizes from sizeof() or to malloc() or realloc().
Remove obsolete (unsigned) casts.  Sizes were unsigned int in
traditional C but are size_t in C89.

Silence some clang warnings.  Add the second pair of round brackets in
`while ((ff = ff->ff_next))` to silence -Wparentheses.  Change
`if (nc_first(...))/*nothing*/;` to `(void)nc_first(...);` to silence
-Wempty-body.  The code in compute.c nc_first() had the form
`if (x) if (y) s; else t;`.  The old indentation (before 10717cc)
suggests that the "else" belongs to the 2nd "if", so add braces like
`if (x) { if (y) s; else t; }` to silence -Wdangling-else.

Shuffle extern function declarations.  Add missing declaration for
LLparse().  Stop declaring RENAME(); it doesn't exist.  Move some
declarations from main.c to extern.h, so the C compiler may check that
the declarations are compatible with the function definitions.

Assume that standard C89 remove() is available and doesn't need the
UNLINK() wrapper.

In lib/incl, don't need to include <stdio.h> nor <stdlib.h> to use
assert().

Remove alloc.h.  If you don't clean your build, then an outdated
BUILDDIR/obj/util/LLgen/headers/alloc.h will survive but should not
cause harm, because nothing includes it.  Don't need to remove alloc.h
from util/LLgen/distr.sh, because it isn't there.

Run the bootstrap to rebuild LLgen.c, Lpars.c, tokens.c.
2019-10-22 15:32:23 -04:00

64 lines
1.3 KiB
Lua

clibrary {
name = "headers",
hdrs = { "./src/*.h" } -- rm alloc.h
}
cprogram {
name = "llgen",
-- These use pre-LLgen'd versions of LLgen.c, Lpars.c, Lpars.h, and
-- tokens.c. If LLgen.g or tokens.g gets updated, they need
-- rebuilding. Use the bootstrap target to do this.
srcs = { "./src/*.c" },
deps = { "+headers" },
vars = {
["+cflags"] = {
"-DLIBDIR=\\\""..posix.getcwd().."/"..cwd().."/lib\\\"",
"-DNON_CORRECTING"
},
}
}
-- This bootstrap target rebuilds LLgen's own parser with LLgen.
-- It acts like ./bootstrap.sh but without installing LLgen in PATH.
normalrule {
name = "bootstrap",
ins = "+llgen",
outleaves = { "phony" },
commands = {
"cd %{abspath(cwd()..\"/src\")}",
"%{abspath(ins)} -vvv -x tokens.g LLgen.g",
"echo",
"echo You should now be able to rebuild LLgen with the new parser.",
}
}
definerule("llgen",
{
srcs = { type="targets" },
},
function(e)
-- Remember this is executed from the caller's directory; local
-- target names will resolve there
local fs = replace(basename(filenamesof(e.srcs)), "%.g$", "")
return normalrule {
name = e.name,
cwd = e.cwd,
outleaves = {
"Lpars.c",
"Lpars.h",
replace(fs, "$", ".c")
},
ins = {
"util/LLgen+llgen",
e.srcs,
},
commands = {
"cd %{dir} && rm -f %{outs} && %{abspath(ins)}"
}
}
end
)