diff --git a/compiler/luci/import/include/luci/Importer.h b/compiler/luci/import/include/luci/Importer.h index ebbc6d4d778..3111008de51 100644 --- a/compiler/luci/import/include/luci/Importer.h +++ b/compiler/luci/import/include/luci/Importer.h @@ -42,10 +42,14 @@ class Importer final } public: + // TODO move to private std::unique_ptr importModule(const circle::Model *model) const; + std::unique_ptr importModule(const uint8_t *data, size_t size); private: const GraphBuilderSource *_source = nullptr; + const uint8_t *_file_data = nullptr; + size_t _file_size = 0; }; } // namespace luci diff --git a/compiler/luci/import/src/Importer.cpp b/compiler/luci/import/src/Importer.cpp index 4d4db53fb46..eef4a739013 100644 --- a/compiler/luci/import/src/Importer.cpp +++ b/compiler/luci/import/src/Importer.cpp @@ -277,8 +277,17 @@ std::unique_ptr Importer::importModule(const circle::Model *model) const } CircleReader reader; - if (!reader.parse(model)) - return nullptr; + if (_file_data && _file_size) + { + if (!reader.parse(model, _file_data, _file_size)) + return nullptr; + } + else + { + // TODO remove this + if (!reader.parse(model)) + return nullptr; + } for (uint32_t g = 0; g < reader.num_subgraph(); ++g) { @@ -361,4 +370,19 @@ std::unique_ptr Importer::importModule(const circle::Model *model) const return module; } +std::unique_ptr Importer::importModule(const uint8_t *data, size_t size) +{ + if (data == nullptr || size == 0) + return nullptr; + + _file_data = data; + _file_size = size; + + const circle::Model *circle_model = circle::GetModel(_file_data); + if (circle_model == nullptr) + return nullptr; + + return importModule(circle_model); +} + } // namespace luci