diff --git a/tensorflow/lite/micro/compression/metadata_test.cc b/tensorflow/lite/micro/compression/metadata_test.cc index a0d02165294..9a6abd963d9 100644 --- a/tensorflow/lite/micro/compression/metadata_test.cc +++ b/tensorflow/lite/micro/compression/metadata_test.cc @@ -81,8 +81,8 @@ metadata->subgraphs.push_back(std::move(subgraph0)); flatbuffers::FlatBufferBuilder builder; auto root = Metadata::Pack(builder, metadata.get()); builder.Finish(root); -auto flatbuffer = tflite::Span<const std::byte>{ - reinterpret_cast<const std::byte*>(builder.GetBufferPointer()), +auto flatbuffer = tflite::Span<const uint8_t>{ + reinterpret_cast<const uint8_t*>(builder.GetBufferPointer()), builder.GetSize()}; TF_LITE_MICRO_TEST(ReadbackEqualsWrite) { diff --git a/tensorflow/lite/micro/hexdump.cc b/tensorflow/lite/micro/hexdump.cc index 9cfaf21ab7f..072a12d6e27 100644 --- a/tensorflow/lite/micro/hexdump.cc +++ b/tensorflow/lite/micro/hexdump.cc @@ -17,9 +17,9 @@ #include <algorithm> #include <cctype> #include <cstdarg> +#include <cstdint> #include "tensorflow/lite/micro/micro_log.h" -#include "tensorflow/lite/micro/static_vector.h" namespace { @@ -53,7 +53,7 @@ tflite::Span<char> output(const tflite::Span<char>& buf, const char* format, } // end anonymous namespace -tflite::Span<char> tflite::hexdump(const tflite::Span<const std::byte> region, +tflite::Span<char> tflite::hexdump(const tflite::Span<const uint8_t> region, const tflite::Span<char> out) { tflite::Span<char> buffer{out}; std::size_t byte_nr = 0; @@ -61,7 +61,8 @@ tflite::Span<char> tflite::hexdump(const tflite::Span<const std::byte> region, const int lines = (region.size() + per_line - 1) / per_line; // round up for (int line = 0; line < lines; ++line) { - tflite::StaticVector<char, per_line> ascii; + char ascii[per_line]; + int ascii_nr = 0; // print address buffer = output(buffer, "%08X:", line); @@ -77,7 +78,7 @@ tflite::Span<char> tflite::hexdump(const tflite::Span<const std::byte> region, if (std::isprint(as_int)) { c = static_cast<char>(as_int); } - ascii.push_back(c); + ascii[ascii_nr++] = c; } else { buffer = output(buffer, " "); } @@ -90,8 +91,8 @@ tflite::Span<char> tflite::hexdump(const tflite::Span<const std::byte> region, // print the ascii value buffer = output(buffer, " "); - for (const auto& c : ascii) { - buffer = output(buffer, "%c", c); + for (int ascii_index = 0; ascii_index < ascii_nr; ascii_index++) { + buffer = output(buffer, "%c", ascii[ascii_index]); } buffer = output(buffer, "%c", '\n'); } @@ -99,6 +100,6 @@ tflite::Span<char> tflite::hexdump(const tflite::Span<const std::byte> region, return {out.data(), out.size() - buffer.size()}; } -void tflite::hexdump(const tflite::Span<const std::byte> region) { +void tflite::hexdump(const tflite::Span<const uint8_t> region) { hexdump(region, {nullptr, 0}); } diff --git a/tensorflow/lite/micro/hexdump.h b/tensorflow/lite/micro/hexdump.h index 0bdfcc47c05..07002e3b42f 100644 --- a/tensorflow/lite/micro/hexdump.h +++ b/tensorflow/lite/micro/hexdump.h @@ -16,6 +16,7 @@ #define TENSORFLOW_LITE_MICRO_HEXDUMP_H_ #include <cstddef> +#include <cstdint> #include "tensorflow/lite/micro/span.h" @@ -23,12 +24,12 @@ namespace tflite { // Displays the contents of a memory region, formatted in hexadecimal and ASCII // in a style matching Python's hexdump module, using DebugLog(). -void hexdump(Span<const std::byte> region); +void hexdump(Span<const uint8_t> region); // Writes the contents of a memory region, formatted in hexadecimal and ASCII // in a style matching Python's hexdump module, to a buffer. Returns the portion // of the buffer written. -Span<char> hexdump(Span<const std::byte> region, Span<char> buffer); +Span<char> hexdump(Span<const uint8_t> region, Span<char> buffer); } // end namespace tflite diff --git a/tensorflow/lite/micro/hexdump_test.cc b/tensorflow/lite/micro/hexdump_test.cc index 89d3a0404c5..2e7e7f4c29a 100644 --- a/tensorflow/lite/micro/hexdump_test.cc +++ b/tensorflow/lite/micro/hexdump_test.cc @@ -15,6 +15,7 @@ #include "tensorflow/lite/micro/hexdump.h" #include <array> +#include <cstdint> #include "tensorflow/lite/micro/span.h" #include "tensorflow/lite/micro/testing/micro_test.h" @@ -22,8 +23,8 @@ constexpr tflite::Span<const char> input{ "This is an input string for testing."}; -const tflite::Span<const std::byte> region{ - reinterpret_cast<const std::byte*>(input.data()), input.size()}; +const tflite::Span<const uint8_t> region{ + reinterpret_cast<const uint8_t*>(input.data()), input.size()}; // clang-format off constexpr tflite::Span<const char> expected{ diff --git a/tensorflow/lite/micro/tools/make/Makefile b/tensorflow/lite/micro/tools/make/Makefile index 091c0adc3d4..0bf5532badf 100644 --- a/tensorflow/lite/micro/tools/make/Makefile +++ b/tensorflow/lite/micro/tools/make/Makefile @@ -183,7 +183,6 @@ ifeq ($(TARGET), $(HOST_OS)) endif CXXFLAGS := \ - -std=c++17 \ -fno-rtti \ -fno-exceptions \ -fno-threadsafe-statics \ @@ -192,7 +191,6 @@ CXXFLAGS := \ CCFLAGS := \ -Wimplicit-function-declaration \ - -std=c17 \ $(COMMON_FLAGS) ARFLAGS := -r @@ -260,6 +258,14 @@ else ifeq ($(BUILD_TYPE), no_tf_lite_static_memory) CCFLAGS := $(filter-out -DTF_LITE_STATIC_MEMORY, $(CCFLAGS)) endif +ifeq ($(CC_VER11), true) + CXXFLAGS+=-std=c++11 + CCFLAGS+=-std=c11 +else + CXXFLAGS+=-std=c++17 + CCFLAGS+=-std=c17 +endif + # This library is the main target for this makefile. It will contain a minimal # runtime that can be linked in to other programs. MICROLITE_LIB_NAME := libtensorflow-microlite.a diff --git a/tensorflow/lite/micro/tools/make/targets/xtensa_makefile.inc b/tensorflow/lite/micro/tools/make/targets/xtensa_makefile.inc index 8a3ee7b6716..e9f940392b1 100644 --- a/tensorflow/lite/micro/tools/make/targets/xtensa_makefile.inc +++ b/tensorflow/lite/micro/tools/make/targets/xtensa_makefile.inc @@ -35,7 +35,6 @@ endif TARGET_ARCH_DEFINES := -D$(shell echo $(TARGET_ARCH) | tr [a-z] [A-Z]) PLATFORM_FLAGS = \ - -stdlib=libc++ \ -DTF_LITE_MCU_DEBUG_LOG \ -DTF_LITE_USE_CTIME \ --xtensa-core=$(XTENSA_CORE) \ @@ -48,6 +47,11 @@ TARGET_TOOLCHAIN_PREFIX := xt- CXX_TOOL := clang++ CC_TOOL := clang +# Building with C++17 requires libc++ +ifneq ($(CC_VER11), true) + PLATFORM_FLAGS += -stdlib=libc++ +endif + # Unused exception related symbols make their way into a binary that links # against TFLM as described in https://github.com/tensorflow/tensorflow/issues/47575. # We have two options to avoid this. The first involves using -stdlib=libc++ and