mirror of
https://github.com/apache/nuttx-apps.git
synced 2025-07-04 11:04:13 +08:00

Add configuration files of TFLite Micro, its dependent third-party libraries and CMSIS_NN. Signed-off-by: renzhiyuan1 <renzhiyuan1@xiaomi.com>
101 lines
3.9 KiB
Diff
101 lines
3.9 KiB
Diff
diff --git a/include/flatbuffers/base.h b/include/flatbuffers/base.h
|
|
index 5c4cae79..1a631641 100644
|
|
--- a/include/flatbuffers/base.h
|
|
+++ b/include/flatbuffers/base.h
|
|
@@ -1,6 +1,16 @@
|
|
#ifndef FLATBUFFERS_BASE_H_
|
|
#define FLATBUFFERS_BASE_H_
|
|
|
|
+// For TFLM, we always want FLATBUFFERS_LOCALE_INDEPENDENT to be defined as 0.
|
|
+// We could achieve this by adding -DFLATBUFFERS_LOCALE_INDEPENDENT=0 to the
|
|
+// TFLM Makefile. However, for (at least) the Arduino, adding additional build
|
|
+// flags during the compilation can be a bit awkward. As such, we have instead
|
|
+// made a decision to change the default to be FLATBUFFERS_LOCALE_INDEPENDENT=0
|
|
+// for TFLM to make it easier for external IDE integration.
|
|
+#ifndef FLATBUFFERS_LOCALE_INDEPENDENT
|
|
+#define FLATBUFFERS_LOCALE_INDEPENDENT 0
|
|
+#endif
|
|
+
|
|
// clang-format off
|
|
|
|
// If activate should be declared and included first.
|
|
diff --git a/include/flatbuffers/default_allocator.h b/include/flatbuffers/default_allocator.h
|
|
index d4724122..975d9380 100644
|
|
--- a/include/flatbuffers/default_allocator.h
|
|
+++ b/include/flatbuffers/default_allocator.h
|
|
@@ -39,24 +39,18 @@ class DefaultAllocator : public Allocator {
|
|
// This is to avoid having a statically or dynamically allocated default
|
|
// allocator, or having to move it between the classes that may own it.
|
|
inline uint8_t *Allocate(Allocator *allocator, size_t size) {
|
|
- return allocator ? allocator->allocate(size)
|
|
- : DefaultAllocator().allocate(size);
|
|
+ return allocator->allocate(size);
|
|
}
|
|
|
|
inline void Deallocate(Allocator *allocator, uint8_t *p, size_t size) {
|
|
- if (allocator)
|
|
- allocator->deallocate(p, size);
|
|
- else
|
|
- DefaultAllocator().deallocate(p, size);
|
|
+ allocator->deallocate(p, size);
|
|
}
|
|
|
|
inline uint8_t *ReallocateDownward(Allocator *allocator, uint8_t *old_p,
|
|
size_t old_size, size_t new_size,
|
|
size_t in_use_back, size_t in_use_front) {
|
|
- return allocator ? allocator->reallocate_downward(old_p, old_size, new_size,
|
|
- in_use_back, in_use_front)
|
|
- : DefaultAllocator().reallocate_downward(
|
|
- old_p, old_size, new_size, in_use_back, in_use_front);
|
|
+ return allocator->reallocate_downward(old_p, old_size, new_size, in_use_back,
|
|
+ in_use_front);
|
|
}
|
|
|
|
} // namespace flatbuffers
|
|
diff --git a/include/flatbuffers/flexbuffers.h b/include/flatbuffers/flexbuffers.h
|
|
index 8e8cac14..52dae316 100644
|
|
--- a/include/flatbuffers/flexbuffers.h
|
|
+++ b/include/flatbuffers/flexbuffers.h
|
|
@@ -495,9 +495,24 @@ class Reference {
|
|
return static_cast<double>(ReadUInt64(Indirect(), byte_width_));
|
|
case FBT_NULL: return 0.0;
|
|
case FBT_STRING: {
|
|
+#if 1
|
|
+#if !defined( _MSC_VER)
|
|
+#pragma GCC diagnostic push
|
|
+#pragma GCC diagnostic ignored "-Wnull-dereference"
|
|
+#endif
|
|
+ // See b/173239141 for additional context. Patched via
|
|
+ // micro/tools/make/flexbuffers_download.sh
|
|
+ // Introduce a segfault for an unsupported code path for TFLM.
|
|
+ return *(static_cast<double*>(nullptr));
|
|
+#if !defined( _MSC_VER)
|
|
+#pragma GCC diagnostic pop
|
|
+#endif
|
|
+#else
|
|
+ // This is the original code
|
|
double d;
|
|
flatbuffers::StringToNumber(AsString().c_str(), &d);
|
|
return d;
|
|
+#endif
|
|
}
|
|
case FBT_VECTOR: return static_cast<double>(AsVector().size());
|
|
case FBT_BOOL:
|
|
diff --git a/include/flatbuffers/util.h b/include/flatbuffers/util.h
|
|
index 1ccf3517..34a75193 100644
|
|
--- a/include/flatbuffers/util.h
|
|
+++ b/include/flatbuffers/util.h
|
|
@@ -23,6 +23,12 @@
|
|
#include "flatbuffers/base.h"
|
|
#include "flatbuffers/stl_emulation.h"
|
|
|
|
+// For TFLM we always want to use FLATBUFFERS_PREFER_PRINTF=1. See
|
|
+// http://b/211811553 for more context.
|
|
+#ifndef FLATBUFFERS_PREFER_PRINTF
|
|
+#define FLATBUFFERS_PREFER_PRINTF 1
|
|
+#endif
|
|
+
|
|
#ifndef FLATBUFFERS_PREFER_PRINTF
|
|
# include <iomanip>
|
|
# include <sstream>
|