start developing XML parser for pb_type annotation

This commit is contained in:
tangxifan 2020-01-25 21:19:08 -07:00
parent b6f96e5a8f
commit bafd866cfc
5 changed files with 112 additions and 9 deletions

View File

@ -268,7 +268,7 @@
<direct_connection>
<direct name="adder" circuit_model_name="direct_interc"/>
</direct_connection>
<complex_blocks>
<pb_type_annotations>
<!-- physical pb_type binding in complex block IO -->
<pb_type name="io" physical_mode_name="io_phy"/>
<pb_type name="io[io_phy].iopad" circuit_model_name="iopad" mode_bits="1"/>
@ -293,26 +293,26 @@
<pb_type name="clb.fle[fle_phy].frac_logic.ff_phy" circuit_model_name="static_dff"/>
<pb_type name="clb.fle[n2_lut5].lut5_inter.ble5[blut5].flut5.lut5" mode_bits="01" physical_pb_type_name="clb.fle[fle_phy].frac_logic.frac_lut6" physical_pb_type_index_factor="0.5">
<!-- If not specified, we by default assume the physical mode pin share the same name -->
<input name="in" physical_mode_pin="in[4:0]"/>
<output name="out" physical_mode_pin="lut5_out" physical_mode_pin_rotate_offset="1"/>
<port name="in" physical_mode_pin="in[4:0]"/>
<port name="out" physical_mode_pin="lut5_out" physical_mode_pin_rotate_offset="1"/>
</pb_type>
<pb_type name="clb.fle[n2_lut5].lut5_inter.ble5[blut5].flut5.ff" physical_pb_type_name="clb.fle[fle_phy].frac_logic.ff_phy"/>
<pb_type name="clb.fle[n2_lut5].lut5_inter.ble5[arithmetic].arithemetic.lut4" mode_bits="11" physical_pb_type_name="clb.fle[fle_phy].frac_logic.frac_lut6">
<!-- If not specified, we by default assume the physical mode pin share the same name -->
<input name="in" physical_mode_pin="in[3:0]"/>
<output name="out" physical_mode_pin="lut4_out" physical_mode_pin_rotate_offset="1"/>
<port name="in" physical_mode_pin="in[3:0]"/>
<port name="out" physical_mode_pin="lut4_out" physical_mode_pin_rotate_offset="1"/>
</pb_type>
<pb_type name="clb.fle[n2_lut5].lut5_inter.ble5[arithmetic].arithemetic.adder" physical_pb_type_name="clb.fle[fle_phy].frac_logic.adder_phy"/>
<pb_type name="clb.fle[n2_lut5].lut5_inter.ble5[arithmetic].arithemetic.ff" physical_pb_type_name="clb.fle[fle_phy].frac_logic.ff_phy"/>
<pb_type name="clb.fle[n1_lut6].ble6.lut6" mode_bits="00" physical_pb_type_name="clb.fle[fle_phy].frac_logic.frac_lut6">
<!-- If not specified, we by default assume the physical mode pin share the same name -->
<input name="in" physical_mode_pin="in[5:0]"/>
<output name="out" physical_mode_pin="lut6_out"/>
<port name="in" physical_mode_pin="in[5:0]"/>
<port name="out" physical_mode_pin="lut6_out"/>
</pb_type>
<pb_type name="clb.fle[n1_lut6].ble6.ff" physical_pb_type_name="clb.fle[fle_phy].frac_logic.ff_phy" physical_pb_type_index_factor="2" physical_pb_type_index_offset="1"/>
<pb_type name="clb.fle[shift_register].ble6_shift.ff" physical_pb_type_name="clb.fle[fle_phy].frac_logic.ff_phy"/>
<!-- End physical pb_type binding in complex block IO -->
</complex_blocks>
</pb_type_annotations>
</openfpga_architecture>
<openfpga_simulation_setting>
<clock_setting>

View File

@ -1,12 +1,14 @@
#ifndef OPENFPGA_ARCH_H
#define OPENFPGA_ARCH_H
#include <vector>
#include <map>
#include "circuit_library.h"
#include "technology_library.h"
#include "simulation_setting.h"
#include "config_protocol.h"
#include "pb_type_annotation.h"
/* namespace openfpga begins */
namespace openfpga {
@ -47,6 +49,12 @@ struct Arch {
* to circuit models in circuit library
*/
std::map<std::string, CircuitModelId> direct2circuit;
/* Pb type annotations
* Bind from operating to physical
* Bind from physical to circuit model
*/
std::vector<PbTypeAnnotation> pb_type_annotations;
};
} /* namespace openfpga ends */

View File

@ -21,6 +21,7 @@
#include "read_xml_simulation_setting.h"
#include "read_xml_config_protocol.h"
#include "read_xml_routing_circuit.h"
#include "read_xml_pb_type_annotation.h"
#include "read_xml_openfpga_arch.h"
#include "openfpga_arch_linker.h"
@ -85,10 +86,13 @@ openfpga::Arch read_xml_openfpga_arch(const char* arch_file_name) {
openfpga_arch.routing_seg2circuit = read_xml_routing_segment_circuit(xml_openfpga_arch, loc_data,
openfpga_arch.circuit_lib);
/* Parse the routing segment circuit definition */
/* Parse the direct circuit definition */
openfpga_arch.direct2circuit = read_xml_direct_circuit(xml_openfpga_arch, loc_data,
openfpga_arch.circuit_lib);
/* Parse the pb_type annotation */
openfpga_arch.pb_type_annotations = read_xml_pb_type_annotations(xml_openfpga_arch, loc_data);
/* Second node should be <openfpga_simulation_setting> */
auto xml_simulation_settings = get_single_child(doc, "openfpga_simulation_setting", loc_data);

View File

@ -0,0 +1,74 @@
/********************************************************************
* This file includes the top-level function of this library
* which reads an XML modeling OpenFPGA architecture to the associated
* data structures
*******************************************************************/
#include <string>
/* Headers from pugi XML library */
#include "pugixml.hpp"
#include "pugixml_util.hpp"
/* Headers from vtr util library */
#include "vtr_assert.h"
/* Headers from libarchfpga */
#include "arch_error.h"
#include "read_xml_util.h"
#include "read_xml_pb_type_annotation.h"
/********************************************************************
* Parse XML description for a pb_type annotation under a <pb_type> XML node
*******************************************************************/
static
void read_xml_pb_type_annotation(pugi::xml_node& xml_pb_type,
const pugiutil::loc_data& loc_data,
std::vector<openfpga::PbTypeAnnotation>& pb_type_annotations) {
openfpga::PbTypeAnnotation pb_type_annotation;
/* Find the name of pb_type */
const std::string& name_attr = get_attribute(xml_pb_type, "name", loc_data).as_string();
const std::string& physical_name_attr = get_attribute(xml_pb_type, "physical_pb_type_name", loc_data, pugiutil::ReqOpt::OPTIONAL).as_string();
/* If both names are not empty, this is a operating pb_type */
if ( (false == name_attr.empty())
&& (false == physical_name_attr.empty()) ) {
/* Parse the attributes for operating pb_type */
pb_type_annotation.set_operating_pb_type_name(name_attr);
pb_type_annotation.set_physical_pb_type_name(physical_name_attr);
}
/* If there is only a name, this is a physical pb_type */
if ( (false == name_attr.empty())
&& (true == physical_name_attr.empty()) ) {
pb_type_annotation.set_physical_pb_type_name(name_attr);
}
/* Finish parsing and add it to the vector */
pb_type_annotations.push_back(pb_type_annotation);
}
/********************************************************************
* Top function to parse XML description about pb_type annotation
*******************************************************************/
std::vector<openfpga::PbTypeAnnotation> read_xml_pb_type_annotations(pugi::xml_node& Node,
const pugiutil::loc_data& loc_data) {
std::vector<openfpga::PbTypeAnnotation> pb_type_annotations;
/* Parse configuration protocol root node */
pugi::xml_node xml_annotations = get_single_child(Node, "pb_type_annotations", loc_data);
/* Iterate over the children under this node,
* each child should be named after <pb_type>
*/
for (pugi::xml_node xml_pb_type : xml_annotations.children()) {
/* Error out if the XML child has an invalid name! */
if (xml_pb_type.name() != std::string("pb_type")) {
bad_tag(xml_pb_type, loc_data, xml_annotations, {"pb_type"});
}
read_xml_pb_type_annotation(xml_pb_type, loc_data, pb_type_annotations);
}
return pb_type_annotations;
}

View File

@ -0,0 +1,17 @@
#ifndef READ_XML_PB_TYPE_ANNOTATION_H
#define READ_XML_PB_TYPE_ANNOTATION_H
/********************************************************************
* Include header files that are required by function declaration
*******************************************************************/
#include "pugixml_util.hpp"
#include "pugixml.hpp"
#include "pb_type_annotation.h"
/********************************************************************
* Function declaration
*******************************************************************/
std::vector<openfpga::PbTypeAnnotation> read_xml_pb_type_annotations(pugi::xml_node& Node,
const pugiutil::loc_data& loc_data);
#endif