|
14 | 14 |
|
15 | 15 | #include <cerata/api.h> |
16 | 16 | #include <cerata/vhdl/vhdl.h> |
| 17 | +#include <cerata/yaml/yaml.h> |
17 | 18 |
|
18 | 19 | #include <string> |
19 | 20 | #include <vector> |
|
27 | 28 | #include "fletchgen/mmio.h" |
28 | 29 | #include "fletchgen/profiler.h" |
29 | 30 | #include "fletchgen/bus.h" |
| 31 | +#include "fletchgen/external.h" |
30 | 32 |
|
31 | 33 | namespace fletchgen { |
32 | 34 |
|
@@ -160,6 +162,7 @@ Design::Design(const std::shared_ptr<Options> &opts) { |
160 | 162 | // Analyze schemas and recordbatches to get schema_set and batch_desc |
161 | 163 | AnalyzeSchemas(); |
162 | 164 | AnalyzeRecordBatches(); |
| 165 | + AnalyzeExternalIO(); |
163 | 166 | // Sanity check our design for equal number of schemas and recordbatch descriptions. |
164 | 167 | if (schema_set->schemas().size() != batch_desc.size()) { |
165 | 168 | FLETCHER_LOG(FATAL, "Number of Schemas and RecordBatchDescriptions does not match."); |
@@ -250,4 +253,27 @@ std::vector<cerata::OutputSpec> Design::GetOutputSpec() { |
250 | 253 | return result; |
251 | 254 | } |
252 | 255 |
|
| 256 | +void Design::AnalyzeExternalIO() { |
| 257 | + if (!options->externals_yaml.empty()) { |
| 258 | + // Read YAML |
| 259 | + auto fs = std::ifstream(options->externals_yaml); |
| 260 | + std::stringstream yaml; |
| 261 | + yaml << fs.rdbuf(); |
| 262 | + |
| 263 | + // Convert to field |
| 264 | + std::shared_ptr<cerata::Field> field; |
| 265 | + auto converter = cerata::yaml::YamlConverter(yaml.str(), &field); |
| 266 | + auto status = converter.Convert(); |
| 267 | + if (!status.ok()) { |
| 268 | + FLETCHER_LOG(FATAL, status.msg()); |
| 269 | + } |
| 270 | + |
| 271 | + // Extract and store type |
| 272 | + auto ext_type = field->type(); |
| 273 | + ext_type->SetName("_external"); |
| 274 | + cerata::default_type_pool()->Add(ext_type); |
| 275 | + external = ext_type; |
| 276 | + } |
| 277 | +} |
| 278 | + |
253 | 279 | } // namespace fletchgen |
0 commit comments