15 #include "fletchgen/schema.h"
17 #include <fletcher/common.h>
26 #include "fletchgen/bus.h"
33 return std::make_shared<SchemaSet>(name);
37 for (
const auto &fs : schemas_) {
38 if (fs->mode() == fletcher::Mode::READ) {
46 for (
const auto &fs : schemas_) {
47 if (fs->mode() == fletcher::Mode::WRITE) {
55 for (
const auto &fs : schemas_) {
56 if (fs->name() == name) {
64 auto name = fletcher::GetMeta(*arrow_schema, fletcher::meta::NAME);
66 FLETCHER_LOG(WARNING,
"Skipping anonymous schema with the following contents:\n" + arrow_schema->ToString());
67 FLETCHER_LOG(WARNING,
"Append {'fletcher_name' : '<name>'} kv-metadata to the schema "
68 "to include this schema in hardware generation.");
72 auto fs = std::make_shared<FletcherSchema>(arrow_schema);
73 schemas_.push_back(fs);
78 if ((*other)->arrow_schema()->Equals(*arrow_schema)) {
79 FLETCHER_LOG(INFO,
"Duplicate but equal schema in SchemaSet: " + name);
82 FLETCHER_LOG(FATAL,
"Duplicate schema detected in SchemaSet: " + name);
88 for (
const auto &fs : schemas_) {
89 if (fs->name() == name) {
97 std::vector<std::shared_ptr<FletcherSchema>> ret;
98 for (
const auto &s : schemas_) {
99 if (s->mode() == Mode::READ) {
107 std::vector<std::shared_ptr<FletcherSchema>> ret;
108 for (
const auto &s : schemas_) {
109 if (s->mode() == Mode::WRITE) {
118 bool operator()(
const std::shared_ptr<FletcherSchema> &a,
const std::shared_ptr<FletcherSchema> &b) {
119 return a->name() < b->name();
124 bool operator()(
const std::shared_ptr<FletcherSchema> &a,
const std::shared_ptr<FletcherSchema> &b) {
125 if (a->mode() == b->mode()) {
127 }
else if (a->mode() == Mode::WRITE) {
135 std::sort(schemas_.begin(), schemas_.end(), NameSort);
137 std::stable_sort(schemas_.begin(), schemas_.end(), ModeSort);
141 : arrow_schema_(arrow_schema), mode_(fletcher::GetMode(*arrow_schema)) {
144 name_ = fletcher::GetMeta(*arrow_schema_, fletcher::meta::NAME);
146 FLETCHER_LOG(FATAL,
"Schema has no name. Append {'fletcher_name' : '<name>'} kv-metadata to the schema. "
149 auto bus_spec_val = fletcher::GetMeta(*arrow_schema_, fletcher::meta::BUS_SPEC);
151 FLETCHER_LOG(DEBUG,
"Schema " +
name() +
":");
152 FLETCHER_LOG(DEBUG,
" Direction : " + cerata::Term::str(
mode2dir(mode_)));
153 FLETCHER_LOG(DEBUG,
" Bus spec : " + bus_dims_.
ToString());
157 const std::string &schema_name) {
158 return std::make_shared<FletcherSchema>(
arrow_schema, schema_name);
FletcherSchema(const std::shared_ptr< arrow::Schema > &arrow_schema, const std::string &schema_name="")
Construct a new Fletcher schema.
static std::shared_ptr< FletcherSchema > Make(const std::shared_ptr< arrow::Schema > &arrow_schema, const std::string &schema_name="")
Make a new FletcherSchema, returning a shared pointer to it.
std::shared_ptr< arrow::Schema > arrow_schema() const
Return the Arrow schema that this FletcherSchema was based on.
std::string name() const
Return the name of this FletcherSchema.
std::vector< std::shared_ptr< FletcherSchema > > read_schemas() const
Return all schemas with read mode.
SchemaSet(std::string name)
SchemaSet constructor.
bool RequiresReading() const
Determine whether any schema in this set requires reading from memory.
std::vector< std::shared_ptr< FletcherSchema > > write_schemas() const
Return all schemas with write mode.
void Sort()
Sort the schemas by name, then by read/write mode.
static std::shared_ptr< SchemaSet > Make(const std::string &name)
Make a new, empty SchemaSet, and return a shared pointer to it.
bool HasSchemaWithName(const std::string &name) const
Return true if set contains schema with some name, false otherwise.
void AppendSchema(const std::shared_ptr< arrow::Schema > &schema)
Append a schema.
std::optional< std::shared_ptr< FletcherSchema > > GetSchema(const std::string &name) const
Optionally return a schema with name, if it exists.
bool RequiresWriting() const
Determine whether any schema in this set requires writing to memory.
Contains all classes and functions related to Fletchgen.
cerata::Port::Dir mode2dir(fletcher::Mode mode)
Return a Cerata port direction from a Fletcher access mode.
Holds bus interface dimensions.
std::string ToString() const
Return a human-readable version of the bus dimensions.
static BusDim FromString(const std::string &str, BusDim default_to)
Returns a BusDim from a string. See [common/cpp/include/fletcher/arrow-utils.h] for more info.