2020-01-19 15:44:27 -06:00
|
|
|
/********************************************************************
|
|
|
|
* This file includes functions that outputs routing circuit definition
|
|
|
|
* to XML format
|
|
|
|
*******************************************************************/
|
|
|
|
/* Headers from system goes first */
|
|
|
|
#include <algorithm>
|
2022-10-06 19:08:50 -05:00
|
|
|
#include <string>
|
2020-01-19 15:44:27 -06:00
|
|
|
|
|
|
|
/* Headers from vtr util library */
|
2022-10-06 19:08:50 -05:00
|
|
|
#include "openfpga_digest.h"
|
2020-01-19 15:44:27 -06:00
|
|
|
#include "vtr_assert.h"
|
|
|
|
#include "vtr_log.h"
|
|
|
|
|
|
|
|
/* Headers from readarchopenfpga library */
|
|
|
|
#include "write_xml_routing_circuit.h"
|
2022-10-06 19:08:50 -05:00
|
|
|
#include "write_xml_utils.h"
|
2020-01-19 15:44:27 -06:00
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
* Write switch circuit model definition in XML format
|
|
|
|
*******************************************************************/
|
2022-10-06 19:08:50 -05:00
|
|
|
static void write_xml_routing_component_circuit(
|
|
|
|
std::fstream& fp, const char* fname,
|
|
|
|
const std::string& routing_component_name, const CircuitLibrary& circuit_lib,
|
|
|
|
const std::map<std::string, CircuitModelId>& switch2circuit) {
|
2020-01-19 15:44:27 -06:00
|
|
|
/* Validate the file stream */
|
|
|
|
openfpga::check_file_stream(fname, fp);
|
|
|
|
|
|
|
|
/* Iterate over the mapping */
|
2022-10-06 19:08:50 -05:00
|
|
|
for (std::map<std::string, CircuitModelId>::const_iterator it =
|
|
|
|
switch2circuit.begin();
|
|
|
|
it != switch2circuit.end(); ++it) {
|
|
|
|
fp << "\t\t"
|
|
|
|
<< "<" << routing_component_name;
|
|
|
|
write_xml_attribute(fp, "name", it->first.c_str());
|
|
|
|
write_xml_attribute(fp, "circuit_model_name",
|
|
|
|
circuit_lib.model_name(it->second).c_str());
|
|
|
|
fp << "/>"
|
|
|
|
<< "\n";
|
2020-01-19 15:44:27 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-14 18:40:59 -06:00
|
|
|
/********************************************************************
|
|
|
|
* Write switch circuit model definition in XML format
|
|
|
|
*******************************************************************/
|
2022-10-06 19:08:50 -05:00
|
|
|
static void write_xml_direct_component_circuit(
|
|
|
|
std::fstream& fp, const char* fname, const std::string& direct_tag_name,
|
|
|
|
const CircuitLibrary& circuit_lib, const ArchDirect& arch_direct,
|
|
|
|
const ArchDirectId& direct_id) {
|
2020-02-14 18:40:59 -06:00
|
|
|
/* Validate the file stream */
|
|
|
|
openfpga::check_file_stream(fname, fp);
|
|
|
|
|
|
|
|
/* Iterate over the mapping */
|
2022-10-06 19:08:50 -05:00
|
|
|
fp << "\t\t"
|
|
|
|
<< "<" << direct_tag_name;
|
|
|
|
write_xml_attribute(fp, "name", arch_direct.name(direct_id).c_str());
|
|
|
|
write_xml_attribute(
|
|
|
|
fp, "circuit_model_name",
|
|
|
|
circuit_lib.model_name(arch_direct.circuit_model(direct_id)).c_str());
|
|
|
|
write_xml_attribute(fp, "type",
|
2024-05-18 14:29:38 -05:00
|
|
|
DIRECT_TYPE_STRING[size_t(arch_direct.type(direct_id))]);
|
2022-10-06 19:08:50 -05:00
|
|
|
write_xml_attribute(fp, "x_dir",
|
|
|
|
DIRECT_DIRECTION_STRING[arch_direct.x_dir(direct_id)]);
|
|
|
|
write_xml_attribute(fp, "y_dir",
|
|
|
|
DIRECT_DIRECTION_STRING[arch_direct.y_dir(direct_id)]);
|
|
|
|
fp << "/>"
|
|
|
|
<< "\n";
|
2020-02-14 18:40:59 -06:00
|
|
|
}
|
|
|
|
|
2020-01-19 15:44:27 -06:00
|
|
|
/********************************************************************
|
|
|
|
* Write Connection block circuit models in XML format
|
|
|
|
*******************************************************************/
|
2022-10-06 19:08:50 -05:00
|
|
|
void write_xml_cb_switch_circuit(
|
|
|
|
std::fstream& fp, const char* fname, const CircuitLibrary& circuit_lib,
|
|
|
|
const std::map<std::string, CircuitModelId>& switch2circuit) {
|
2020-01-19 15:44:27 -06:00
|
|
|
/* Validate the file stream */
|
|
|
|
openfpga::check_file_stream(fname, fp);
|
2022-10-06 19:08:50 -05:00
|
|
|
|
2020-01-19 15:44:27 -06:00
|
|
|
/* Write the root node */
|
2022-10-06 19:08:50 -05:00
|
|
|
fp << "\t"
|
|
|
|
<< "<connection_block>"
|
|
|
|
<< "\n";
|
2020-01-19 15:44:27 -06:00
|
|
|
|
2022-10-06 19:08:50 -05:00
|
|
|
/* Write each switch circuit definition */
|
|
|
|
write_xml_routing_component_circuit(fp, fname, std::string("switch"),
|
|
|
|
circuit_lib, switch2circuit);
|
2020-01-19 15:44:27 -06:00
|
|
|
|
|
|
|
/* Finish writing the root node */
|
2022-10-06 19:08:50 -05:00
|
|
|
fp << "\t"
|
|
|
|
<< "</connection_block>"
|
|
|
|
<< "\n";
|
2020-01-19 15:44:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
* Write Switch block circuit models in XML format
|
|
|
|
*******************************************************************/
|
2022-10-06 19:08:50 -05:00
|
|
|
void write_xml_sb_switch_circuit(
|
|
|
|
std::fstream& fp, const char* fname, const CircuitLibrary& circuit_lib,
|
|
|
|
const std::map<std::string, CircuitModelId>& switch2circuit) {
|
2020-01-19 15:44:27 -06:00
|
|
|
/* Validate the file stream */
|
|
|
|
openfpga::check_file_stream(fname, fp);
|
2022-10-06 19:08:50 -05:00
|
|
|
|
2020-01-19 15:44:27 -06:00
|
|
|
/* Write the root node */
|
2022-10-06 19:08:50 -05:00
|
|
|
fp << "\t"
|
|
|
|
<< "<switch_block>"
|
|
|
|
<< "\n";
|
2020-01-19 15:44:27 -06:00
|
|
|
|
2022-10-06 19:08:50 -05:00
|
|
|
/* Write each switch circuit definition */
|
|
|
|
write_xml_routing_component_circuit(fp, fname, std::string("switch"),
|
|
|
|
circuit_lib, switch2circuit);
|
2020-01-19 15:44:27 -06:00
|
|
|
|
|
|
|
/* Finish writing the root node */
|
2022-10-06 19:08:50 -05:00
|
|
|
fp << "\t"
|
|
|
|
<< "</switch_block>"
|
|
|
|
<< "\n";
|
2020-01-19 15:44:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
* Write routing segment circuit models in XML format
|
|
|
|
*******************************************************************/
|
2022-10-06 19:08:50 -05:00
|
|
|
void write_xml_routing_segment_circuit(
|
|
|
|
std::fstream& fp, const char* fname, const CircuitLibrary& circuit_lib,
|
|
|
|
const std::map<std::string, CircuitModelId>& seg2circuit) {
|
2020-01-19 15:44:27 -06:00
|
|
|
/* Validate the file stream */
|
|
|
|
openfpga::check_file_stream(fname, fp);
|
2022-10-06 19:08:50 -05:00
|
|
|
|
2020-01-19 15:44:27 -06:00
|
|
|
/* Write the root node */
|
2022-10-06 19:08:50 -05:00
|
|
|
fp << "\t"
|
|
|
|
<< "<routing_segment>"
|
|
|
|
<< "\n";
|
2020-01-19 15:44:27 -06:00
|
|
|
|
2022-10-06 19:08:50 -05:00
|
|
|
/* Write each routing segment circuit definition */
|
|
|
|
write_xml_routing_component_circuit(fp, fname, std::string("segment"),
|
|
|
|
circuit_lib, seg2circuit);
|
2020-01-19 15:44:27 -06:00
|
|
|
|
|
|
|
/* Finish writing the root node */
|
2022-10-06 19:08:50 -05:00
|
|
|
fp << "\t"
|
|
|
|
<< "</routing_segment>"
|
|
|
|
<< "\n";
|
2020-01-19 15:44:27 -06:00
|
|
|
}
|
2020-01-19 16:00:19 -06:00
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
* Write direction connection circuit models in XML format
|
|
|
|
*******************************************************************/
|
2022-10-06 19:08:50 -05:00
|
|
|
void write_xml_direct_circuit(std::fstream& fp, const char* fname,
|
2020-01-19 16:00:19 -06:00
|
|
|
const CircuitLibrary& circuit_lib,
|
2020-02-14 18:40:59 -06:00
|
|
|
const ArchDirect& arch_direct) {
|
2020-01-19 16:00:19 -06:00
|
|
|
/* If the direct2circuit is empty, we do not output XML */
|
2020-02-14 18:40:59 -06:00
|
|
|
if (0 == arch_direct.directs().size()) {
|
2020-01-19 16:00:19 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Validate the file stream */
|
|
|
|
openfpga::check_file_stream(fname, fp);
|
2022-10-06 19:08:50 -05:00
|
|
|
|
2020-01-19 16:00:19 -06:00
|
|
|
/* Write the root node */
|
2022-10-06 19:08:50 -05:00
|
|
|
fp << "\t"
|
|
|
|
<< "<direct_connection>"
|
|
|
|
<< "\n";
|
2020-01-19 16:00:19 -06:00
|
|
|
|
2022-10-06 19:08:50 -05:00
|
|
|
/* Write each direct connection circuit definition */
|
2020-02-14 18:40:59 -06:00
|
|
|
for (const ArchDirectId& direct_id : arch_direct.directs()) {
|
2022-10-06 19:08:50 -05:00
|
|
|
write_xml_direct_component_circuit(fp, fname, std::string("direct"),
|
|
|
|
circuit_lib, arch_direct, direct_id);
|
2020-02-14 18:40:59 -06:00
|
|
|
}
|
2020-01-19 16:00:19 -06:00
|
|
|
|
|
|
|
/* Finish writing the root node */
|
2022-10-06 19:08:50 -05:00
|
|
|
fp << "\t"
|
|
|
|
<< "</direct_connection>"
|
|
|
|
<< "\n";
|
2020-01-19 16:00:19 -06:00
|
|
|
}
|