From a8a9d1bbfa9563beea01d6da1dd9efe947e1a7f2 Mon Sep 17 00:00:00 2001 From: David Given Date: Tue, 26 Jul 2016 23:35:30 +0200 Subject: [PATCH] yacc, ncgg; platform ncg builds now. --- first/yacc.lua | 21 +++++++ h/build.lua | 1 + mach/proto/ncg/build.lua | 45 +++++++++++++++ plat/build.lua | 46 +++++++++++++++ plat/pc86/build.lua | 15 ++--- util/ncgg/build.lua | 122 +++++++++++++++++++++++++++++++++++++++ util/ncgg/cvtkeywords | 7 ++- 7 files changed, 243 insertions(+), 14 deletions(-) create mode 100644 mach/proto/ncg/build.lua create mode 100644 util/ncgg/build.lua diff --git a/first/yacc.lua b/first/yacc.lua index bb308003e..bffaeee4c 100644 --- a/first/yacc.lua +++ b/first/yacc.lua @@ -20,4 +20,25 @@ definerule("yacc", end ) +definerule("flex", + { + srcs = { type="targets" }, + commands = { + type="strings", + default={ + "flex -s -t %{ins} > %{outs[1]}" + } + } + }, + function (e) + return normalrule { + name = e.name, + cwd = e.cwd, + ins = e.srcs, + outleaves = { "lex.yy.c" }, + label = e.label, + commands = e.commands + } + end +) diff --git a/h/build.lua b/h/build.lua index 7fd9d6728..db9400fdc 100644 --- a/h/build.lua +++ b/h/build.lua @@ -25,6 +25,7 @@ clibrary { name = "emheaders", hdrs = { "./*.h", + "./con_float", "+em_path", "+local", } diff --git a/mach/proto/ncg/build.lua b/mach/proto/ncg/build.lua new file mode 100644 index 000000000..1553d3975 --- /dev/null +++ b/mach/proto/ncg/build.lua @@ -0,0 +1,45 @@ +include("util/ncgg/build.lua") + +definerule("build_ncg", + { + arch = { type="string" } + }, + function(e) + -- Remember this is executed from the caller's directory; local + -- target names will resolve there + local headers = clibrary { + name = e.name.."/headers", + srcs = {}, + hdrs = { + "mach/proto/ncg/*.h", + "mach/"..e.arch.."/ncg/mach*" + } + } + + local tables = ncgg { + name = e.name.."/tables", + srcs = { "mach/"..e.arch.."/ncg/table" } + } + + return cprogram { + name = e.name, + srcs = { + "mach/proto/ncg/*.c", + "mach/"..e.arch.."/ncg/mach.h", + archlib, -- for .c file + tables, -- for .c file + }, + deps = { + "h+emheaders", + "modules+headers", + "modules/src/flt_arith+lib", + "modules/src/object+lib", + "util/data+em_data", + archlib, -- for .h file + headers, + tables, -- for .h file + } + } + end +) + diff --git a/plat/build.lua b/plat/build.lua index e69de29bb..cd220bb9f 100644 --- a/plat/build.lua +++ b/plat/build.lua @@ -0,0 +1,46 @@ +include("mach/proto/as/build.lua") +include("mach/proto/ncg/build.lua") + +definerule("build_plat", + { + arch = { type = "string" }, + plat = { type = "string" }, + }, + function(e) + local descr = "plat/"..e.plat.."/descr" + + local as = build_as { + name = "as", + arch = e.arch + } + + local ncg = build_ncg { + name = "ncg", + 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, + } + } + end +) + diff --git a/plat/pc86/build.lua b/plat/pc86/build.lua index c3a70093e..5976b8933 100644 --- a/plat/pc86/build.lua +++ b/plat/pc86/build.lua @@ -1,14 +1,7 @@ -include("mach/proto/as/build.lua") +include("plat/build.lua") -build_as { - name = "as", - arch = "i86" -} - -installable { +build_plat { name = "pkg", - map = { - ["$(PLATDEP)/pc86/as"] = "+as" - } + arch = "i86", + plat = "pc86", } - diff --git a/util/ncgg/build.lua b/util/ncgg/build.lua new file mode 100644 index 000000000..110272b8b --- /dev/null +++ b/util/ncgg/build.lua @@ -0,0 +1,122 @@ +include("first/yacc.lua") + +local cggparser = yacc { + name = "cggparser", + srcs = { "./cgg.y" } +} + +flex { + name = "cgglexer", + srcs = { "./scan.l" } +} + +normalrule { + name = "keywords", + ins = { + "./cvtkeywords", + "./keywords", + unpack(filenamesof({cggparser}, "%.h$")) + }, + outleaves = { "enterkeyw.c" }, + commands = { + "%{ins[1]} %{ins[2]} %{ins[3]} %{outs[1]}" + } +} + +cprogram { + name = "ncgg", + srcs = { + "./*.c", + "+cggparser", -- for .c file + "+cgglexer", -- for .c file + "+keywords", + }, + deps = { + "+cggparser", -- for .h file + "+cgglexer", -- for .h file + "h+emheaders", + "util/data+em_data", + } +} + +definerule("ncgg", + { + srcs = { type="targets" } + }, + function(e) + -- Remember this is executed from the caller's directory; local + -- target names will resolve there + if (#e.srcs ~= 1) then + error("you must supply exactly one input file") + end + + local cpptable = cppfile { + name = e.name.."/cpptable", + outleaf = "cpptable", + srcs = e.srcs + } + + return normalrule { + name = e.name, + cwd = e.cwd, + outleaves = { + "tables.c", + "tables.h", + }, + ins = { + "util/ncgg+ncgg", + cpptable + }, + commands = { + "cd %{dir} && %{ins}", + "mv %{dir}/tables.H %{dir}/tables.h" + } + } + end +) + +--[[ +D := util/ncgg + +define build-ncgg-impl + +$(call reset) +$(eval cflags += -I$D) + +$(call yacc, $(OBJDIR)/$D, $D/cgg.y) + +$(call flex, $(OBJDIR)/$D, $D/scan.l) +$(call dependson, $(OBJDIR)/$D/y.tab.h) + +$(call cfile, $D/subr.c) +$(call cfile, $D/main.c) +$(call cfile, $D/coerc.c) +$(call cfile, $D/error.c) +$(call cfile, $D/emlookup.c) +$(call cfile, $D/expr.c) +$(call cfile, $D/instruct.c) +$(call cfile, $D/iocc.c) +$(call cfile, $D/lookup.c) +$(call cfile, $D/output.c) +$(call cfile, $D/set.c) +$(call cfile, $D/strlookup.c) +$(call cfile, $D/var.c) +$(call cfile, $D/hall.c) + +$(eval CLEANABLES += $(OBJDIR)/$D/enterkeyw.c) +$(OBJDIR)/$D/enterkeyw.c: $D/cvtkeywords $D/keywords $(OBJDIR)/$D/y.tab.h + @echo KEYWORDS $$@ + @mkdir -p $$(dir $$@) + $(hide) cd $$(dir $$@) && sh $(abspath $D/cvtkeywords) $(abspath $D/keywords) +$(call cfile, $(OBJDIR)/$D/enterkeyw.c) + +$(eval $q: $(INCDIR)/em_spec.h) + +$(call rawfile, $(LIBEM_DATA)) +$(call cprogram, $(BINDIR)/ncgg) +$(eval NCGG := $o) + +endef + +$(eval $(build-ncgg-impl)) +--]] diff --git a/util/ncgg/cvtkeywords b/util/ncgg/cvtkeywords index 85b7e035c..a478b3f1a 100755 --- a/util/ncgg/cvtkeywords +++ b/util/ncgg/cvtkeywords @@ -1,8 +1,8 @@ #!/bin/sh : '$Id$' -grep '^#' y.tab.h >tokendefs -ed -s $1 <<'!Funky!Stuff!' +grep '^#' $2 >tokendefs +ed -s $1 > $3 <<'!Funky!Stuff!' g/^#/d 1,$s/\([^ ]*\)[ ][ ]*\(.*\)/ sy_p=lookup("\1",symkeyw,newsymbol);sy_p->sy_value.syv_keywno=\2;/ 1i @@ -18,7 +18,8 @@ enterkeyw() { $a } . -w enterkeyw.c +,p q !Funky!Stuff! rm tokendefs +