mirror of
https://github.com/raspberrypi/pico-sdk.git
synced 2025-04-16 23:43:15 +00:00
Add pioasm c++ constexpr output target
This commit is contained in:
parent
93ea261677
commit
8464e5eeb7
@ -27,6 +27,7 @@ add_executable(pioasm
|
||||
target_sources(pioasm PRIVATE c_sdk_output.cpp)
|
||||
target_sources(pioasm PRIVATE python_output.cpp)
|
||||
target_sources(pioasm PRIVATE hex_output.cpp)
|
||||
target_sources(pioasm PRIVATE constexpr_output.cpp)
|
||||
target_sources(pioasm PRIVATE json_output.cpp)
|
||||
target_sources(pioasm PRIVATE ada_output.cpp)
|
||||
target_sources(pioasm PRIVATE go_output.cpp)
|
||||
|
62
tools/pioasm/constexpr_output.cpp
Normal file
62
tools/pioasm/constexpr_output.cpp
Normal file
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include "output_format.h"
|
||||
#include "pio_disassembler.h"
|
||||
|
||||
struct constexpr_output : public output_format {
|
||||
struct factory {
|
||||
factory() { output_format::add(new constexpr_output()); }
|
||||
};
|
||||
|
||||
constexpr_output() : output_format("constexpr") {}
|
||||
|
||||
std::string get_description() {
|
||||
return "c++ constexpr array output (only raw program are output) ";
|
||||
}
|
||||
|
||||
virtual int output(std::string destination,
|
||||
std::vector<std::string> output_options,
|
||||
const compiled_source &source) {
|
||||
FILE *out = open_single_output(destination);
|
||||
if (!out)
|
||||
return 1;
|
||||
|
||||
fprintf(out, "#pragma once\n\n");
|
||||
fprintf(out, "#include <array>\n");
|
||||
fprintf(out, "#include <cstdint>\n\n");
|
||||
|
||||
fprintf(out, "namespace Pioasm {\n\n");
|
||||
|
||||
for (auto &p : source.programs) {
|
||||
fprintf(out, "inline constexpr std::array<uint16_t, %lu> %s = {\n",
|
||||
p.instructions.size(), p.name.c_str());
|
||||
for (auto i = 0u; i < p.instructions.size(); ++i) {
|
||||
const auto &inst = p.instructions[i];
|
||||
if (i == p.wrap_target) {
|
||||
fprintf(out, " // .wrap_target\n");
|
||||
}
|
||||
fprintf(out, " 0x%04x, // %2d: %s\n", inst, i,
|
||||
disassemble(inst, p.sideset_bits_including_opt.get(),
|
||||
p.sideset_opt)
|
||||
.c_str());
|
||||
if (i == p.wrap) {
|
||||
fprintf(out, " // .wrap\n");
|
||||
}
|
||||
}
|
||||
fprintf(out, "};\n\n");
|
||||
}
|
||||
|
||||
fprintf(out, "}");
|
||||
|
||||
if (out != stdout) {
|
||||
fclose(out);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
static constexpr_output::factory creator;
|
Loading…
x
Reference in New Issue
Block a user