Squashed 'third_party/pico-sdk/' content from commit 2062372d2
Change-Id: Ic20f199d3ed0ea8d3a6a1bbf513f875ec7500cc6
git-subtree-dir: third_party/pico-sdk
git-subtree-split: 2062372d203b372849d573f252cf7c6dc2800c0a
Signed-off-by: Austin Schuh <austin.linux@gmail.com>
diff --git a/tools/pioasm/hex_output.cpp b/tools/pioasm/hex_output.cpp
new file mode 100644
index 0000000..39dd0fa
--- /dev/null
+++ b/tools/pioasm/hex_output.cpp
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include "output_format.h"
+#include <iostream>
+
+struct hex_output : public output_format {
+ struct factory {
+ factory() {
+ output_format::add(new hex_output());
+ }
+ };
+
+ hex_output() : output_format("hex") {}
+
+ std::string get_description() {
+ return "Raw hex output (only valid for single program inputs)";
+ }
+
+ 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;
+
+ if (source.programs.size() > 1) {
+ // todo don't have locations any more!
+ std::cerr << "error: hex output only supports a single program input\n";
+ return 1;
+ }
+ for (const auto &i : source.programs[0].instructions) {
+ fprintf(out, "%04x\n", i);
+ }
+ if (out != stdout) { fclose(out); }
+ return 0;
+ }
+};
+
+static hex_output::factory creator;