Skip to content

Commit

Permalink
[luci/import] Add importModule with raw data/size
Browse files Browse the repository at this point in the history
This will add importModule method with raw data/size arguments.

ONE-DCO-1.0-Signed-off-by: SaeHie Park <[email protected]>
  • Loading branch information
seanshpark committed Aug 26, 2024
1 parent e8f73f8 commit 4ecfeb6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 4 additions & 0 deletions compiler/luci/import/include/luci/Importer.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,14 @@ class Importer final
}

public:
// TODO move to private
std::unique_ptr<Module> importModule(const circle::Model *model) const;
std::unique_ptr<Module> 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
Expand Down
28 changes: 26 additions & 2 deletions compiler/luci/import/src/Importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,17 @@ std::unique_ptr<Module> 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)
{
Expand Down Expand Up @@ -361,4 +370,19 @@ std::unique_ptr<Module> Importer::importModule(const circle::Model *model) const
return module;
}

std::unique_ptr<Module> 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

0 comments on commit 4ecfeb6

Please sign in to comment.