Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions tools/pioasm/c_sdk_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ struct c_sdk_output : public output_format {
fprintf(out, "#endif\n");
fprintf(out, "\n");

fprintf(out, "#ifdef __cplusplus\n");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://en.cppreference.com/w/cpp/language/constexpr.html says that constexpr was only added in C++11, so should this line perhaps be

Suggested change
fprintf(out, "#ifdef __cplusplus\n");
fprintf(out, "#if defined(__cplusplus) && defined(__cpp_constexpr)\n");

so that it doesn't break older C++ compilers? (Or perhaps simply #ifdef __cpp_constexpr is sufficient?)

fprintf(out, "#define PIO_CONST constexpr\n");
fprintf(out, "#else\n");
fprintf(out, "#define PIO_CONST const\n");
fprintf(out, "#endif\n");
fprintf(out, "\n");

output_symbols(out, "", source.global_symbols);

for (const auto &program : source.programs) {
Expand All @@ -93,7 +100,7 @@ struct c_sdk_output : public output_format {

output_symbols(out, prefix, program.symbols);

fprintf(out, "static const uint16_t %sprogram_instructions[] = {\n", prefix.c_str());
fprintf(out, "static PIO_CONST uint16_t %sprogram_instructions[] = {\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) {
Expand All @@ -109,7 +116,7 @@ struct c_sdk_output : public output_format {
fprintf(out, "\n");

fprintf(out, "#if !PICO_NO_HARDWARE\n");
fprintf(out, "static const struct pio_program %sprogram = {\n", prefix.c_str());
fprintf(out, "static PIO_CONST struct pio_program %sprogram = {\n", prefix.c_str());
fprintf(out, " .instructions = %sprogram_instructions,\n", prefix.c_str());
fprintf(out, " .length = %d,\n", (int) program.instructions.size());
fprintf(out, " .origin = %d,\n", program.origin.get());
Expand Down