OpenFPGA/libopenfpga/libfabrickey/src/write_xml_fabric_key.cpp

116 lines
3.4 KiB
C++
Raw Normal View History

2020-06-12 01:07:04 -05:00
/********************************************************************
* This file includes functions that outputs a configuration protocol to XML format
*******************************************************************/
/* Headers from system goes first */
#include <string>
#include <algorithm>
/* Headers from vtr util library */
#include "vtr_assert.h"
#include "vtr_log.h"
#include "vtr_time.h"
/* Headers from openfpga util library */
2020-06-12 01:07:04 -05:00
#include "openfpga_digest.h"
/* Headers from arch openfpga library */
#include "write_xml_utils.h"
/* Headers from fabrickey library */
#include "write_xml_fabric_key.h"
/********************************************************************
* A writer to output a component key to XML format
*
* Return 0 if successful
* Return 1 if there are more serious bugs in the architecture
* Return 2 if fail when creating files
2020-06-12 01:07:04 -05:00
*******************************************************************/
static
int write_xml_fabric_component_key(std::fstream& fp,
const FabricKey& fabric_key,
const FabricKeyId& component_key) {
2020-06-12 01:07:04 -05:00
/* Validate the file stream */
if (false == openfpga::valid_file_stream(fp)) {
return 2;
}
2020-06-12 01:07:04 -05:00
openfpga::write_tab_to_file(fp, 2);
fp << "<key";
2020-06-12 01:07:04 -05:00
if (false == fabric_key.valid_key_id(component_key)) {
return 1;
}
2020-06-12 01:07:04 -05:00
write_xml_attribute(fp, "id", size_t(component_key));
if (!fabric_key.key_name(component_key).empty()) {
write_xml_attribute(fp, "name", fabric_key.key_name(component_key).c_str());
}
2020-06-12 01:07:04 -05:00
write_xml_attribute(fp, "value", fabric_key.key_value(component_key));
2020-06-27 15:59:53 -05:00
if (!fabric_key.key_alias(component_key).empty()) {
write_xml_attribute(fp, "alias", fabric_key.key_alias(component_key).c_str());
}
vtr::Point<int> coord = fabric_key.key_coordinate(component_key);
if (fabric_key.valid_key_coordinate(coord)) {
write_xml_attribute(fp, "column", coord.x());
write_xml_attribute(fp, "row", coord.y());
}
2020-06-12 01:07:04 -05:00
fp << "/>" << "\n";
return 0;
2020-06-12 01:07:04 -05:00
}
/********************************************************************
* A writer to output a fabric key to XML format
*
* Return 0 if successful
* Return 1 if there are more serious bugs in the architecture
* Return 2 if fail when creating files
2020-06-12 01:07:04 -05:00
*******************************************************************/
int write_xml_fabric_key(const char* fname,
const FabricKey& fabric_key) {
2020-06-12 01:07:04 -05:00
vtr::ScopedStartFinishTimer timer("Write Fabric Key");
/* Create a file handler */
std::fstream fp;
/* Open the file stream */
fp.open(std::string(fname), std::fstream::out | std::fstream::trunc);
/* Validate the file stream */
openfpga::check_file_stream(fname, fp);
/* Write the root node */
fp << "<fabric_key>" << "\n";
int err_code = 0;
/* Write region by region */
for (const FabricRegionId& region : fabric_key.regions()) {
openfpga::write_tab_to_file(fp, 1);
fp << "<region id=\"" << size_t(region) << "\"" << ">\n";
/* Write component by component */
for (const FabricKeyId& key : fabric_key.region_keys(region)) {
err_code = write_xml_fabric_component_key(fp, fabric_key, key);
if (0 != err_code) {
return err_code;
}
}
openfpga::write_tab_to_file(fp, 1);
fp << "</region>" << "\n";
2020-06-12 01:07:04 -05:00
}
/* Finish writing the root node */
fp << "</fabric_key>" << "\n";
/* Close the file stream */
fp.close();
return err_code;
2020-06-12 01:07:04 -05:00
}