From cac4d1ce860e4f79b0669155c2cc25fd6802b71b Mon Sep 17 00:00:00 2001 From: David Given Date: Mon, 12 Aug 2024 12:36:39 +0200 Subject: [PATCH 1/3] Encode all the protos in one go (per library), as it's vastly faster. --- README.md | 2 +- doc/disk-tartu.md | 2 +- scripts/build.py | 25 +++++++++++++++++++++++-- scripts/protoencode.cc | 13 +++++++------ src/formats/build.py | 17 +++++++---------- src/gui/drivetypes/build.py | 26 +++++--------------------- tests/build.py | 4 ++-- 7 files changed, 46 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index 484b5935a..f02797ec1 100644 --- a/README.md +++ b/README.md @@ -136,7 +136,7 @@ choices because they can store multiple types of file system. | [`rolandd20`](doc/disk-rolandd20.md) | Roland D20: 3.5" electronic synthesiser disks | 🦄 | 🦖 | ROLAND | | [`rx50`](doc/disk-rx50.md) | Digital RX50: 400kB 5.25" 80-track 10-sector SSDD | 🦖 | 🦖 | | | [`smaky6`](doc/disk-smaky6.md) | Smaky 6: 308kB 5.25" 77-track 16-sector SSDD, hard sectored | 🦖 | | SMAKY6 | -| [`tartu`](doc/disk-tartu.md) | Tartu: The Palivere and variations | 🦄 | | CPMFS | +| [`tartu`](doc/disk-tartu.md) | Tartu: The Palivere and variations | 🦄 | 🦖 | CPMFS | | [`tids990`](doc/disk-tids990.md) | Texas Instruments DS990: 1126kB 8" DSSD | 🦖 | 🦖 | | | [`tiki`](doc/disk-tiki.md) | Tiki 100: CP/M | | | CPMFS | | [`victor9k`](doc/disk-victor9k.md) | Victor 9000 / Sirius One: 1224kB 5.25" DSDD GCR | 🦖 | 🦖 | | diff --git a/doc/disk-tartu.md b/doc/disk-tartu.md index ddfecbfb0..4831d4dbb 100644 --- a/doc/disk-tartu.md +++ b/doc/disk-tartu.md @@ -22,7 +22,7 @@ density, using MFM and with up to 780kB on a double-sided 80 track disk. The Tartu FDC with Soviet TTL logic chips. -FluxEngine supports reading Tartu disks with CP/M filesystem access. +FluxEngine supports reading and writing Tartu disks with CP/M filesystem access. ## Options diff --git a/scripts/build.py b/scripts/build.py index 652d52aa5..4cfc21164 100644 --- a/scripts/build.py +++ b/scripts/build.py @@ -1,11 +1,11 @@ -from build.ab import Rule, normalrule, Targets +from build.ab import Rule, normalrule, Targets, TargetsMap from build.c import cxxprogram, HostToolchain encoders = {} @Rule -def protoencode(self, name, srcs: Targets, proto, symbol): +def protoencode_single(self, name, srcs: Targets, proto, symbol): if proto not in encoders: r = cxxprogram( name="protoencode_" + proto, @@ -34,6 +34,27 @@ def protoencode(self, name, srcs: Targets, proto, symbol): ) +@Rule +def protoencode(self, name, proto, srcs: TargetsMap, symbol): + encoded = [ + protoencode_single( + name=f"{k}_cc", + srcs=[v], + proto=proto, + symbol=f"{symbol}_{k}_pb", + ) + for k, v in srcs.items() + ] + + normalrule( + replaces=self, + ins=encoded, + outs=[name + ".cc"], + commands=["cat {ins} > {outs}"], + label="CONCAT", + ) + + cxxprogram( name="mkdoc", srcs=["./mkdoc.cc"], diff --git a/scripts/protoencode.cc b/scripts/protoencode.cc index 48343441e..bd81f0e6e 100644 --- a/scripts/protoencode.cc +++ b/scripts/protoencode.cc @@ -121,11 +121,12 @@ int main(int argc, const char* argv[]) } auto data = message.SerializeAsString(); + auto name = argv[3]; output << "#include \"lib/globals.h\"\n" << "#include \"lib/proto.h\"\n" << "#include \n" - << "static const uint8_t rawData[] = {"; + << "static const uint8_t " << name << "_rawData[] = {"; int count = 0; for (char c : data) @@ -140,12 +141,12 @@ int main(int argc, const char* argv[]) } output << "\n};\n"; - output << "extern const std::string_view " << argv[3] << "_data;\n"; - output << "const std::string_view " << argv[3] - << "_data = std::string_view((const char*)rawData, " << data.size() + output << "extern const std::string_view " << name << "_data;\n"; + output << "const std::string_view " << name + << "_data = std::string_view((const char*)" << name << "_rawData, " << data.size() << ");\n"; - output << "extern const ConfigProto " << argv[3] << ";\n"; - output << "const ConfigProto " << argv[3] << " = parseConfigBytes(" + output << "extern const ConfigProto " << name << ";\n"; + output << "const ConfigProto " << name << " = parseConfigBytes(" << argv[3] << "_data);\n"; return 0; diff --git a/src/formats/build.py b/src/formats/build.py index 02412d6a4..7b9c26076 100644 --- a/src/formats/build.py +++ b/src/formats/build.py @@ -52,19 +52,16 @@ label="MKTABLE", ) -encoded = [ - protoencode( - name=f"{name}_cc", - srcs=[f"./{name}.textpb"], - proto="ConfigProto", - symbol=f"formats_{name}_pb", - ) - for name in formats -] +protoencode( + name="formats_cc", + srcs={name: f"./{name}.textpb" for name in formats}, + proto="ConfigProto", + symbol="formats", +) cxxlibrary( name="formats", - srcs=[".+table_cc"] + encoded, + srcs=[".+formats_cc"], deps=["+lib", "lib+config_proto_lib"], ) diff --git a/src/gui/drivetypes/build.py b/src/gui/drivetypes/build.py index 5e82721d9..212258674 100644 --- a/src/gui/drivetypes/build.py +++ b/src/gui/drivetypes/build.py @@ -8,27 +8,11 @@ "apple2", ] -normalrule( +protoencode( name="drivetypes_cc", - ins=[f"./{name}.textpb" for name in drivetypes], - deps=["scripts/mktable.sh"], - outs=["table.cc"], - commands=[ - "sh scripts/mktable.sh drivetypes " - + (" ".join(drivetypes)) - + " > {outs}" - ], - label="MKTABLE", + srcs={name: f"./{name}.textpb" for name in drivetypes}, + proto="ConfigProto", + symbol="drivetypes", ) -encoded = [ - protoencode( - name=f"{name}_cc", - srcs=[f"./{name}.textpb"], - proto="ConfigProto", - symbol=f"drivetypes_{name}_pb", - ) - for name in drivetypes -] - -cxxlibrary(name="drivetypes", srcs=[".+drivetypes_cc"] + encoded, deps=["+lib"]) +cxxlibrary(name="drivetypes", srcs=[".+drivetypes_cc"], deps=["+lib"]) diff --git a/tests/build.py b/tests/build.py index 1daea37ee..2ca8d10f3 100644 --- a/tests/build.py +++ b/tests/build.py @@ -2,7 +2,7 @@ from build.c import cxxprogram from build.protobuf import proto, protocc from build.utils import test -from scripts.build import protoencode +from scripts.build import protoencode_single proto( @@ -49,7 +49,7 @@ name="proto_test_exe", srcs=[ "./proto.cc", - protoencode( + protoencode_single( name="testproto_cc", srcs=["./testproto.textpb"], proto="TestProto", From 9a0b487f4b5340ca177c6e070fe399dc033a3590 Mon Sep 17 00:00:00 2001 From: David Given Date: Mon, 12 Aug 2024 17:26:28 +0200 Subject: [PATCH 2/3] Remember to build the formats table. --- src/formats/build.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/formats/build.py b/src/formats/build.py index 7b9c26076..06284aeaf 100644 --- a/src/formats/build.py +++ b/src/formats/build.py @@ -61,7 +61,7 @@ cxxlibrary( name="formats", - srcs=[".+formats_cc"], + srcs=[".+formats_cc", ".+table_cc"], deps=["+lib", "lib+config_proto_lib"], ) From dc6af483a58418823f7d5c1ae7d0f0f77ad50a91 Mon Sep 17 00:00:00 2001 From: David Given Date: Mon, 12 Aug 2024 17:32:13 +0200 Subject: [PATCH 3/3] Remember to build the drivetypes table. --- src/gui/drivetypes/build.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/gui/drivetypes/build.py b/src/gui/drivetypes/build.py index 212258674..4e5eb360c 100644 --- a/src/gui/drivetypes/build.py +++ b/src/gui/drivetypes/build.py @@ -8,6 +8,20 @@ "apple2", ] +normalrule( + name="drivetypes_table_cc", + ins=[f"./{name}.textpb" for name in drivetypes], + deps=["scripts/mktable.sh"], + outs=["table.cc"], + commands=[ + "sh scripts/mktable.sh drivetypes " + + (" ".join(drivetypes)) + + " > {outs}" + ], + label="MKTABLE", +) + + protoencode( name="drivetypes_cc", srcs={name: f"./{name}.textpb" for name in drivetypes}, @@ -15,4 +29,8 @@ symbol="drivetypes", ) -cxxlibrary(name="drivetypes", srcs=[".+drivetypes_cc"], deps=["+lib"]) +cxxlibrary( + name="drivetypes", + srcs=[".+drivetypes_cc", ".+drivetypes_table_cc"], + deps=["+lib"], +)