From b78cbb44a022ca758413f66a57bfa84ffad59f99 Mon Sep 17 00:00:00 2001 From: soypat Date: Fri, 27 Oct 2023 23:29:30 -0300 Subject: [PATCH 1/6] remove package and import declaration --- tools/pioasm/go_output.cpp | 41 +++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/tools/pioasm/go_output.cpp b/tools/pioasm/go_output.cpp index 809e306c3..69f4cca40 100644 --- a/tools/pioasm/go_output.cpp +++ b/tools/pioasm/go_output.cpp @@ -77,13 +77,16 @@ struct go_output : public output_format { header(out, "Code generated by pioasm; DO NOT EDIT."); - fprintf(out, "// +build rp2040\n\n"); - fprintf(out, "package %s\n\n", package.c_str()); - fprintf(out, "import \"machine\"\n\n"); - - output_symbols(out, "", source.global_symbols); - for (const auto &program : source.programs) { + // todo maybe have some code blocks inside or outside here? + for(const auto& o : program.code_blocks) { + if (o.first == name) { + for(const auto &contents : o.second) { + fprintf(out, "%s", contents.c_str()); + } + } + } + header(out, program.name); std::string prefix = program.name; @@ -94,8 +97,7 @@ struct go_output : public output_format { output_symbols(out, prefix, program.symbols); - fprintf(out, "var %sProgram = machine.PIOProgram{\n", prefix.c_str()); - fprintf(out, "\tInstructions: []uint16{\n"); + fprintf(out, "var %sInstructions = []uint16{\n", prefix.c_str()); for (int i = 0; i < (int)program.instructions.size(); i++) { const auto &inst = program.instructions[i]; if (i == program.wrap_target) { @@ -107,12 +109,11 @@ struct go_output : public output_format { fprintf(out, "\t\t// .wrap\n"); } } - fprintf(out, "\t},\n"); - fprintf(out, "\tOrigin: %d,\n", program.origin.get()); fprintf(out, "}\n"); - fprintf(out, "\n"); - fprintf(out, "func %sProgramDefaultConfig(offset uint8) machine.PIOStateMachineConfig {\n", prefix.c_str()); - fprintf(out, "\tcfg := machine.DefaultStateMachineConfig()\n"); + fprintf(out, "const %sOrigin = %d\n", prefix.c_str(), program.origin.get()); + + fprintf(out, "func %sProgramDefaultConfig(offset uint8) pio.StateMachineConfig {\n", prefix.c_str()); + fprintf(out, "\tcfg := pio.DefaultStateMachineConfig()\n"); fprintf(out, "\tcfg.SetWrap(offset+%sWrapTarget, offset+%sWrap)\n", prefix.c_str(), prefix.c_str()); if (program.sideset_bits_including_opt.is_specified()) { @@ -122,19 +123,13 @@ struct go_output : public output_format { } fprintf(out, "\treturn cfg;\n"); fprintf(out, "}\n\n"); - - // todo maybe have some code blocks inside or outside here? - for(const auto& o : program.code_blocks) { - if (o.first == name) { - for(const auto &contents : o.second) { - fprintf(out, "%s", contents.c_str()); - } - } - } } + + output_symbols(out, "", source.global_symbols); + if (out != stdout) { fclose(out); } return 0; } }; -static go_output::factory creator; +static go_output::factory creator; \ No newline at end of file From 5f419d5531bdf6040656d7931d8b483bcf73e181 Mon Sep 17 00:00:00 2001 From: soypat Date: Fri, 27 Oct 2023 23:32:34 -0300 Subject: [PATCH 2/6] add the newline --- tools/pioasm/go_output.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/pioasm/go_output.cpp b/tools/pioasm/go_output.cpp index 69f4cca40..ce50b7b94 100644 --- a/tools/pioasm/go_output.cpp +++ b/tools/pioasm/go_output.cpp @@ -132,4 +132,4 @@ struct go_output : public output_format { } }; -static go_output::factory creator; \ No newline at end of file +static go_output::factory creator; From 0231c4df4d36770df1a2ffd8b0a0002c345efbfb Mon Sep 17 00:00:00 2001 From: soypat Date: Sat, 28 Oct 2023 12:51:37 -0300 Subject: [PATCH 3/6] rename cfg.SetSideSet -> cfg.SetSidesetParams --- tools/pioasm/go_output.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/pioasm/go_output.cpp b/tools/pioasm/go_output.cpp index ce50b7b94..95e529ec3 100644 --- a/tools/pioasm/go_output.cpp +++ b/tools/pioasm/go_output.cpp @@ -117,7 +117,7 @@ struct go_output : public output_format { fprintf(out, "\tcfg.SetWrap(offset+%sWrapTarget, offset+%sWrap)\n", prefix.c_str(), prefix.c_str()); if (program.sideset_bits_including_opt.is_specified()) { - fprintf(out, "\tcfg.SetSideSet(%d, %s, %s)\n", program.sideset_bits_including_opt.get(), + fprintf(out, "\tcfg.SetSidesetParams(%d, %s, %s)\n", program.sideset_bits_including_opt.get(), program.sideset_opt ? "true" : "false", program.sideset_pindirs ? "true" : "false"); } From b1c86c6a9c4ba447ad2f92a7c097697c2eadea6e Mon Sep 17 00:00:00 2001 From: soypat Date: Mon, 30 Oct 2023 23:01:48 -0300 Subject: [PATCH 4/6] make user code precede all other --- tools/pioasm/go_output.cpp | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/tools/pioasm/go_output.cpp b/tools/pioasm/go_output.cpp index 95e529ec3..9c30dde5c 100644 --- a/tools/pioasm/go_output.cpp +++ b/tools/pioasm/go_output.cpp @@ -57,28 +57,15 @@ struct go_output : public output_format { int output(std::string destination, std::vector output_options, const compiled_source &source) override { - std::string package = "main"; - - for (const auto &program : source.programs) { - for(const auto &p : program.lang_opts) { - if (p.first.size() >= name.size() && p.first.compare(0, name.size(), name) == 0) { - for (const auto &opt : p.second) { - if (opt.first.compare("package") == 0) { - package.assign(opt.second); - } else { - std::cerr << "warning: " << name << " does not support output option " << opt.first << ", ignored.\n"; - } - } - } - } - } FILE *out = open_single_output(destination); if (!out) return 1; header(out, "Code generated by pioasm; DO NOT EDIT."); - + + // First we give priority to user's code blocks since + // 1. In Go our imports always precede our code. + // 2. We give users freedom to use their own PIO implementation. for (const auto &program : source.programs) { - // todo maybe have some code blocks inside or outside here? for(const auto& o : program.code_blocks) { if (o.first == name) { for(const auto &contents : o.second) { @@ -86,7 +73,9 @@ struct go_output : public output_format { } } } + } + for (const auto &program : source.programs) { header(out, program.name); std::string prefix = program.name; From 7f0a5b1adb1717ce785db18e579ed493e5d5eee2 Mon Sep 17 00:00:00 2001 From: Patricio Whittingslow Date: Wed, 1 Nov 2023 21:00:14 -0300 Subject: [PATCH 5/6] Update tools/pioasm/go_output.cpp Co-authored-by: Christian Ege --- tools/pioasm/go_output.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/pioasm/go_output.cpp b/tools/pioasm/go_output.cpp index 9c30dde5c..b1415a6d4 100644 --- a/tools/pioasm/go_output.cpp +++ b/tools/pioasm/go_output.cpp @@ -64,7 +64,7 @@ struct go_output : public output_format { // First we give priority to user's code blocks since // 1. In Go our imports always precede our code. - // 2. We give users freedom to use their own PIO implementation. + // 2. We give users the freedom to use their own PIO implementation. for (const auto &program : source.programs) { for(const auto& o : program.code_blocks) { if (o.first == name) { From ca86b516b752aa71200ee5bafd20f7a10d9b680f Mon Sep 17 00:00:00 2001 From: soypat Date: Tue, 13 Feb 2024 18:16:13 -0300 Subject: [PATCH 6/6] Add TinyGo reference --- tools/pioasm/go_output.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/pioasm/go_output.cpp b/tools/pioasm/go_output.cpp index b1415a6d4..b1748d77a 100644 --- a/tools/pioasm/go_output.cpp +++ b/tools/pioasm/go_output.cpp @@ -1,12 +1,15 @@ /* - * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. + * Copyright (c) 2024 Raspberry Pi (Trading) Ltd. * * SPDX-License-Identifier: BSD-3-Clause * + * Contributed by the TinyGo authors. + * * Go generated by this assembler is compatible with TinyGo. * * https://tinygo.org * https://github.com/tinygo-org/tinygo + * https://github.com/tinygo-org/pio */ #include @@ -24,7 +27,7 @@ struct go_output : public output_format { go_output() : output_format("go") {} std::string get_description() override { - return "Go file suitable for use with TinyGo"; + return "Go file suitable for use with TinyGo. See https://github.com/tinygo-org/pio."; } void output_symbols(FILE *out, std::string prefix, const std::vector &symbols) {