C preprocessor; tabgen; now the pc86 boot.s builds using the ack

toolchain.
This commit is contained in:
David Given 2016-07-29 00:22:49 +02:00
parent c6292642c6
commit 363d13cc2f
8 changed files with 190 additions and 151 deletions

View file

@ -1,6 +1,9 @@
vars.cflags = {
"-g", "-O"
}
vars.ackcflags = {
"-O"
}
installable {
name = "ack",

View file

@ -48,24 +48,20 @@ definerule("cfile",
}
},
function (e)
local csrcs = filenamesof(e.srcs, "%.c$")
if (#csrcs ~= 1) then
error("you must have exactly one .c file")
end
local hsrcs = filenamesof(e.srcs, "%.h$")
local hdrpaths = {}
for _, t in pairs(e.deps) do
hdrpaths[#hdrpaths+1] = "-I"..t.dir
if t.dir then
hdrpaths[#hdrpaths+1] = "-I"..t.dir
end
end
hdrpaths = uniquify(hdrpaths)
local outleaf = basename(csrcs[1]):gsub("%.c$", ".o")
local outleaf = basename(e.name)..".o"
return normalrule {
name = e.name,
cwd = e.cwd,
ins = {csrcs[1]},
ins = e.srcs,
deps = e.deps,
outleaves = {outleaf},
label = e.label,

View file

@ -3,7 +3,7 @@ normalrule {
ins = {},
outleaves = { "em_path.h" },
commands = {
"echo '#define TMP_DIR \"$(ACK_TEMP_DIR)\"' > %{outs}",
"echo '#define TMP_DIR \"/tmp\"' > %{outs}",
"echo '#define EM_DIR \"$(PREFIX)\"' >> %{outs}",
"echo '#define ACK_PATH \"share/ack/descr\"' >> %{outs}",
}

View file

@ -135,123 +135,3 @@ installable {
["$(PLATDEP)/em_cemcom.ansi"] = "+cemcom"
}
}
--[[
D := lang/cem/cemcom.ansi
define build-cemcom-ansi-allocd-header
$(eval g := $(OBJDIR)/$D/$(strip $1).h)
$g: $D/$(strip $1).str $D/make.allocd
@echo ALLOCD $$@
@mkdir -p $$(dir $$@)
$(hide) $D/make.allocd < $$^ > $$@
$(eval CLEANABLES += $g)
$(eval $q: $g)
endef
define build-cemcom-ansi-next
$(eval CLEANABLES += $(OBJDIR)/$D/next.c)
$(OBJDIR)/$D/next.c: $D/make.next $1
@echo NEXT $$@
@mkdir -p $$(dir $$@)
$(hide) $$^ > $$@
$(call cfile, $(OBJDIR)/$D/next.c)
$(foreach f, $1, $(call build-cemcom-ansi-allocd-header, \
$(basename $(notdir $f))))
endef
define build-cemcom-ansi-impl
$(call reset)
$(eval cflags += -I$(OBJDIR)/$D -I$D)
$(call cfile, $D/arith.c)
$(call dependson, $(INCDIR)/flt_arith.h)
$(call cfile, $D/blocks.c)
$(call dependson, $(INCDIR)/em_codeEK.h)
$(call cfile, $D/LLlex.c)
$(call cfile, $D/LLmessage.c)
$(call llgen, $(OBJDIR)/$D, \
$(OBJDIR)/$D/tokenfile.g \
$D/program.g \
$D/declar.g \
$D/expression.g \
$D/statement.g \
$D/ival.g)
$(eval CLEANABLES += $(OBJDIR)/$D/tokenfile.g)
$(OBJDIR)/$D/tokenfile.g: $D/make.tokfile $D/tokenname.c
@echo TOKENFILE $$@
@mkdir -p $$(dir $$@)
$(hide) sh $D/make.tokfile < $D/tokenname.c > $$@
$(call tabgen, $D/char.tab)
$(eval $q: $(OBJDIR)/$D/parameters.h)
$(eval CLEANABLES += $(OBJDIR)/$D/parameters.h)
$(OBJDIR)/$D/parameters.h: $D/BigPars
@echo PARAMETERS $$@
@mkdir -p $$(dir $$@)
$(hide) echo '#ifndef PARAMETERS_H' > $$@
$(hide) echo '#define PARAMETERS_H' >> $$@
$(hide) grep -v '^!' < $D/BigPars >> $$@
$(hide) echo '#endif' >> $$@
$(eval CLEANABLES += $(OBJDIR)/$D/symbol2str.c)
$(OBJDIR)/$D/symbol2str.c: $D/make.tokcase $D/tokenname.c
@echo TOKCASE $$@
@mkdir -p $$(dir $$@)
$(hide) $D/make.tokcase < $D/tokenname.c > $$@
$(call cfile, $(OBJDIR)/$D/symbol2str.c)
$(call build-cemcom-ansi-next, \
$D/code.str \
$D/declar.str \
$D/def.str \
$D/expr.str \
$D/field.str \
$D/estack.str \
$D/util.str \
$D/proto.str \
$D/replace.str \
$D/idf.str \
$D/macro.str \
$D/stack.str \
$D/stmt.str \
$D/struct.str \
$D/switch.str \
$D/type.str \
$D/l_brace.str \
$D/l_state.str \
$D/l_outdef.str)
$(eval $q: $(OBJDIR)/$D/Lpars.h)
$(call rawfile, $(LIBEM_MES))
$(call rawfile, $(LIBEMK))
$(call rawfile, $(LIBEM_DATA))
$(call rawfile, $(LIBINPUT))
$(call rawfile, $(LIBASSERT))
$(call rawfile, $(LIBALLOC))
$(call rawfile, $(LIBFLT_ARITH))
$(call rawfile, $(LIBPRINT))
$(call rawfile, $(LIBSYSTEM))
$(call rawfile, $(LIBSTRING))
$(call cprogram, $(BINDIR)/cemcom.ansi)
$(call installto, $(PLATDEP)/em_cemcom.ansi)
$(eval CEMCOMANSI := $o)
$(call reset)
$(eval q := $D/cemcom.ansi.1)
$(call installto, $(INSDIR)/share/man/man1/cemcom.6)
endef
$(eval $(build-cemcom-ansi-impl))
--]]

110
lang/cem/cpp.ansi/build.lua Normal file
View file

@ -0,0 +1,110 @@
include("util/cmisc/build.lua")
local allocd_header = definerule(null,
{
srcs = { type="targets" }
},
function (e)
return normalrule {
name = e.name,
ins = {
"./make.allocd",
unpack(e.srcs)
},
outleaves = replace(basename(e.srcs), "%.str$", ".h"),
commands = {
"%{ins[1]} < %{ins[2]} > %{outs}"
}
}
end
)
allocd_header {
name = "macro_h",
srcs = { "./macro.str" }
}
allocd_header {
name = "replace_h",
srcs = { "./replace.str" }
}
normalrule {
name = "tokenfile_g",
ins = {
"./make.tokfile",
"./tokenname.c",
},
outleaves = { "tokenfile.g" },
commands = {
"sh %{ins[1]} < %{ins[2]} > %{outs}"
}
}
normalrule {
name = "symbol2str_c",
ins = {
"./make.tokcase",
"./tokenname.c",
},
outleaves = { "symbol2str.c" },
commands = {
"sh %{ins[1]} < %{ins[2]} > %{outs}"
}
}
normalrule {
name = "next_c",
ins = {
"./make.next",
"./*.str",
},
outleaves = { "next.c" },
commands = {
"sh %{ins} > %{outs}"
}
}
llgen {
name = "llgen",
srcs = {
"+tokenfile_g",
"./expression.g"
}
}
tabgen {
name = "tabgen_c",
srcs = { "./char.tab" }
}
cprogram {
name = "cpp",
srcs = {
"./*.c",
"+llgen",
"+next_c",
"+symbol2str_c",
"+tabgen_c",
},
deps = {
"+llgen",
"+macro_h",
"+replace_h",
"modules+headers",
"modules/src/alloc+lib",
"modules/src/idf+lib",
"modules/src/input+lib",
"modules/src/print+lib",
"modules/src/string+lib",
"modules/src/system+lib",
}
}
installable {
name = "pkg",
map = {
["$(PLATDEP)/cpp.ansi"] = "+cpp"
}
}

View file

@ -1,7 +1,32 @@
include("mach/proto/as/build.lua")
include("mach/proto/ncg/build.lua")
definerule("build_plat",
definerule("ackfile",
{
srcs = { type="targets" },
deps = { type="targets", default={} },
},
function (e)
local plat = e.vars.plat
return cfile {
name = e.name,
srcs = e.srcs,
deps = {
"plat/"..plat.."+tools",
"util/ack+pkg",
"lang/cem/cpp.ansi+pkg",
unpack(e.deps)
},
commands = {
"ACKDIR=$(INSDIR) $(INSDIR)/bin/ack -m%{plat} -c -o %{outs} %{ins} %{hdrpaths} %{ackcflags}"
}
}
end
)
definerule("build_plat_tools",
{
arch = { type = "string" },
plat = { type = "string" },
@ -19,28 +44,13 @@ definerule("build_plat",
arch = e.arch,
}
local tools = installable {
name = "tools",
map = {
["$(PLATDEP)/"..e.arch.."/as"] = as,
["$(PLATDEP)/"..e.plat.."/ncg"] = ncg,
["$(PLATIND)/descr/"..e.plat.."/descr"] = descr,
}
}
local libraries = installable {
name = "libraries",
map = {
}
}
return installable {
name = e.name,
map = {
tools,
libraries,
["$(PLATDEP)/"..e.plat.."/as"] = as,
["$(PLATDEP)/"..e.plat.."/ncg"] = ncg,
["$(PLATIND)/descr/"..e.plat] = descr,
}
}
end
)

View file

@ -1,7 +1,22 @@
include("plat/build.lua")
build_plat {
name = "pkg",
build_plat_tools {
name = "tools",
arch = "i86",
plat = "pc86",
}
ackfile {
name = "boot",
srcs = { "./boot.s" },
vars = { plat = "pc86" }
}
installable {
name = "pkg",
map = {
"+tools",
["$(PLATIND)/pc86/boot.o"] = "+boot"
}
}

25
util/cmisc/build.lua Normal file
View file

@ -0,0 +1,25 @@
cprogram {
name = "tabgen",
srcs = { "./tabgen.c" }
}
definerule("tabgen",
{
srcs = { type="targets" },
},
function(e)
local symname = replace(basename(e.srcs[1]), "%.tab$", "")
return normalrule {
name = e.name,
ins = {
"util/cmisc+tabgen",
unpack(e.srcs)
},
outleaves = { symname..".c" },
commands = {
"%{ins[1]} -f%{ins[2]} > %{outs} || rm %{outs}"
}
}
end
)