diff --git a/libopenfpga/libarchopenfpga/arch/sample_arch.xml b/libopenfpga/libarchopenfpga/arch/sample_arch.xml index 1ce55ad66..d9c845f45 100644 --- a/libopenfpga/libarchopenfpga/arch/sample_arch.xml +++ b/libopenfpga/libarchopenfpga/arch/sample_arch.xml @@ -42,7 +42,7 @@ - + @@ -256,5 +256,5 @@ - + diff --git a/libopenfpga/libarchopenfpga/src/read_openfpga_xml.h b/libopenfpga/libarchopenfpga/src/read_openfpga_xml.h deleted file mode 100644 index c1454954c..000000000 --- a/libopenfpga/libarchopenfpga/src/read_openfpga_xml.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef READ_OPENFPGA_XML_H -#define READ_OPENFPGA_XML_H - -#include -#include "circuit_library.h" -#include "circuit_settings.h" - -CircuitSettings read_xml_openfpga_arch(const char* arch_file_name); - -#endif diff --git a/libopenfpga/libarchopenfpga/src/read_openfpga_xml.cpp b/libopenfpga/libarchopenfpga/src/read_xml_circuit_library.cpp similarity index 73% rename from libopenfpga/libarchopenfpga/src/read_openfpga_xml.cpp rename to libopenfpga/libarchopenfpga/src/read_xml_circuit_library.cpp index bf8f0f65b..7e2c4f4db 100644 --- a/libopenfpga/libarchopenfpga/src/read_openfpga_xml.cpp +++ b/libopenfpga/libarchopenfpga/src/read_xml_circuit_library.cpp @@ -13,7 +13,7 @@ #include "arch_error.h" #include "read_xml_util.h" -#include "read_openfpga_xml.h" +#include "read_xml_circuit_library.h" /******************************************************************** * Convert string to the enumerate of model type @@ -103,10 +103,10 @@ void read_xml_circuit_model(pugi::xml_node& model_xml, /******************************************************************** * Parse XML codes about circuit models to circuit library *******************************************************************/ -static -CircuitLibrary read_xml_module_circuit_models(pugi::xml_node& Node, - const pugiutil::loc_data& loc_data) { +CircuitLibrary read_xml_circuit_library(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 */ @@ -121,35 +121,3 @@ CircuitLibrary read_xml_module_circuit_models(pugi::xml_node& Node, return circuit_lib; } -/******************************************************************** - * Top-level function to parse an XML file and load data to : - * 1. circuit library - *******************************************************************/ -CircuitSettings read_xml_openfpga_arch(const char* arch_file_name) { - CircuitSettings circuit_settings; - - 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); - - /* Root node should be */ - auto xml_circuit_settings = get_single_child(doc, "circuit_settings", loc_data); - - /* Parse circuit_models to circuit library - * under the node - */ - auto xml_module_circuit_models = get_single_child(xml_circuit_settings, "module_circuit_models", loc_data); - circuit_settings.circuit_lib = read_xml_module_circuit_models(xml_module_circuit_models, loc_data); - - } catch (pugiutil::XmlError& e) { - archfpga_throw(arch_file_name, e.line(), - "%s", e.what()); - } - - return circuit_settings; -} diff --git a/libopenfpga/libarchopenfpga/src/read_xml_circuit_library.h b/libopenfpga/libarchopenfpga/src/read_xml_circuit_library.h new file mode 100644 index 000000000..cfab2eae6 --- /dev/null +++ b/libopenfpga/libarchopenfpga/src/read_xml_circuit_library.h @@ -0,0 +1,17 @@ +#ifndef READ_XML_CIRCUIT_LIBRARY_H +#define READ_XML_CIRCUIT_LIBRARY_H + +/******************************************************************** + * Include header files that are required by function declaration + *******************************************************************/ +#include "pugixml_util.hpp" +#include "pugixml.hpp" +#include "circuit_library.h" + +/******************************************************************** + * Function declaration + *******************************************************************/ +CircuitLibrary read_xml_circuit_library(pugi::xml_node& Node, + const pugiutil::loc_data& loc_data); + +#endif diff --git a/libopenfpga/libarchopenfpga/src/read_xml_circuit_settings.cpp b/libopenfpga/libarchopenfpga/src/read_xml_circuit_settings.cpp new file mode 100644 index 000000000..b3aab5ae0 --- /dev/null +++ b/libopenfpga/libarchopenfpga/src/read_xml_circuit_settings.cpp @@ -0,0 +1,50 @@ +/******************************************************************** + * This file includes the top-level function of this library + * which reads an XML modeling OpenFPGA architecture to the associated + * data structures + *******************************************************************/ +#include + +/* 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_xml_circuit_library.h" +#include "read_xml_circuit_settings.h" + +/******************************************************************** + * Top-level function to parse an XML file and load data to : + * 1. circuit library + *******************************************************************/ +CircuitSettings read_xml_circuit_settings(const char* arch_file_name) { + CircuitSettings circuit_settings; + + 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); + + /* Root node should be */ + auto xml_circuit_settings = get_single_child(doc, "circuit_settings", loc_data); + + /* Parse circuit_models to circuit library + * under the node + */ + auto xml_circuit_models = get_single_child(xml_circuit_settings, "circuit_library", loc_data); + circuit_settings.circuit_lib = read_xml_circuit_library(xml_circuit_models, loc_data); + + } catch (pugiutil::XmlError& e) { + archfpga_throw(arch_file_name, e.line(), + "%s", e.what()); + } + + return circuit_settings; +} diff --git a/libopenfpga/libarchopenfpga/src/read_xml_circuit_settings.h b/libopenfpga/libarchopenfpga/src/read_xml_circuit_settings.h new file mode 100644 index 000000000..423e4ede2 --- /dev/null +++ b/libopenfpga/libarchopenfpga/src/read_xml_circuit_settings.h @@ -0,0 +1,9 @@ +#ifndef READ_XML_CIRCUIT_SETTINGS_H +#define READ_XML_CIRCUIT_SETTINGS_H + +#include +#include "circuit_settings.h" + +CircuitSettings read_xml_circuit_settings(const char* arch_file_name); + +#endif diff --git a/libopenfpga/libarchopenfpga/test/main.cpp b/libopenfpga/libarchopenfpga/test/main.cpp index 2bc37d5ba..2e54fafef 100644 --- a/libopenfpga/libarchopenfpga/test/main.cpp +++ b/libopenfpga/libarchopenfpga/test/main.cpp @@ -5,11 +5,11 @@ *******************************************************************/ #include "vtr_log.h" -#include "read_openfpga_xml.h" +#include "read_xml_circuit_settings.h" int main(int argc, const char** argv) { /* Parse the circuit library from an XML file */ - const CircuitSettings& circuit_settings = read_xml_openfpga_arch(argv[1]); + const CircuitSettings& circuit_settings = read_xml_circuit_settings(argv[1]); VTR_LOG("Parsed %lu circuit models from XML into circuit library.\n", circuit_settings.circuit_lib.num_models());