From 2e986608ba9f5be46e65550e14f8c11d4f2ea3cf Mon Sep 17 00:00:00 2001 From: tangxifan Date: Sun, 12 Jan 2020 21:33:28 -0700 Subject: [PATCH] initial commit on parser for reading openfpga arch xml --- libopenfpga/libarchopenfpga/CMakeLists.txt | 1 + .../libarchopenfpga/src/read_openfpga_xml.cpp | 65 +++++++++++++++++++ .../libarchopenfpga/src/read_openfpga_xml.h | 10 +++ 3 files changed, 76 insertions(+) create mode 100644 libopenfpga/libarchopenfpga/src/read_openfpga_xml.cpp create mode 100644 libopenfpga/libarchopenfpga/src/read_openfpga_xml.h diff --git a/libopenfpga/libarchopenfpga/CMakeLists.txt b/libopenfpga/libarchopenfpga/CMakeLists.txt index ac392b2c0..919888e19 100644 --- a/libopenfpga/libarchopenfpga/CMakeLists.txt +++ b/libopenfpga/libarchopenfpga/CMakeLists.txt @@ -20,6 +20,7 @@ set_target_properties(libarchopenfpga PROPERTIES PREFIX "") #Avoid extra 'lib' p #Specify link-time dependancies target_link_libraries(libarchopenfpga libvtrutil + libarchfpga libpugixml libpugiutil) diff --git a/libopenfpga/libarchopenfpga/src/read_openfpga_xml.cpp b/libopenfpga/libarchopenfpga/src/read_openfpga_xml.cpp new file mode 100644 index 000000000..4b8fdbf4b --- /dev/null +++ b/libopenfpga/libarchopenfpga/src/read_openfpga_xml.cpp @@ -0,0 +1,65 @@ +/******************************************************************** + * This file includes the top-level function of this library + * which reads an XML modeling OpenFPGA architecture to the associated + * data structures + *******************************************************************/ + +/* Headers from pugi XML library */ +#include "pugixml.hpp" +#include "pugixml_util.hpp" + +/* Headers from libarchfpga */ +#include "arch_error.h" +#include "read_xml_util.h" + +#include "read_openfpga_xml.h" + +/******************************************************************** + * Parse XML codes about circuit models to circuit library + *******************************************************************/ +static +void read_xml_circuit_models(pugi::xml_node Node, + const pugiutil::loc_data& loc_data, + CircuitLibrary& circuit_lib) { + /* Iterate over the children under this node, + * each child should be named after circuit_model + */ + for (pugi::xml_node model_xml : Node.children()) { + /* Error out if the XML child has an invalid name! */ + if (model_xml.name() != std::string("circuit_model")) { + bad_tag(model_xml, loc_data, Node, {"circuit_model"}); + } + /* Add a new circuit model to circuit library */ + /* Process the XML attributes under the tag */ + for (pugi::xml_attribute attr : model_xml.attributes()) { + /* Find the type of the circuit model */ + if (attr.name() == std::string("type")) { + } + } + } +} + +/******************************************************************** + * Top-level function to parse an XML file and load data to : + * 1. circuit library + *******************************************************************/ +void read_xml_openfpga_arch(const char* arch_file_name, + CircuitLibrary& circuit_lib) { + pugi::xml_node Next; + + /* Parse the file */ + pugi::xml_document doc; + pugiutil::loc_data loc_data; + + try { + loc_data = pugiutil::load_xml(doc, arch_file_name); + + /* Parse circuit_models to circuit library */ + auto module_circuit_models = get_single_child(doc, "module_circuit_models", loc_data); + read_xml_circuit_models(module_circuit_models, loc_data, circuit_lib); + + } catch (pugiutil::XmlError& e) { + archfpga_throw(arch_file_name, e.line(), + "%s", e.what()); + } +} diff --git a/libopenfpga/libarchopenfpga/src/read_openfpga_xml.h b/libopenfpga/libarchopenfpga/src/read_openfpga_xml.h new file mode 100644 index 000000000..6dbb00682 --- /dev/null +++ b/libopenfpga/libarchopenfpga/src/read_openfpga_xml.h @@ -0,0 +1,10 @@ +#ifndef READ_OPENFPGA_XML_H +#define READ_OPENFPGA_XML_H + +#include +#include "circuit_library.h" + +void read_xml_openfpga_arch(const char* arch_file_name, + CircuitLibrary& circuit_lib); + +#endif