From db503ffebf6de18c179df8d48d72d787ad1c9858 Mon Sep 17 00:00:00 2001 From: tangxifan Date: Mon, 13 Jan 2020 21:05:58 -0700 Subject: [PATCH] add openfpga read xml executable and start min unit test --- CMakeLists.txt | 6 ++ .../libarchopenfpga/src/read_openfpga_xml.cpp | 55 +++++++++++-------- libopenfpga/libarchopenfpga/test/main.cpp | 6 +- 3 files changed, 43 insertions(+), 24 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bdb69f00a..5c8fc97b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -232,6 +232,12 @@ set_target_properties(libvpr vpr_shell LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/vpr7_x2p/vpr" RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/vpr7_x2p/vpr") +set_target_properties(libarchopenfpga read_arch_openfpga + PROPERTIES + ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/libopenfpga/libarchopenfpga" + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/libopenfpga/libarchopenfpga" + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/libopenfpga/libarchopenfpga") + set_target_properties(libvpr8 vpr8 PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/vpr" diff --git a/libopenfpga/libarchopenfpga/src/read_openfpga_xml.cpp b/libopenfpga/libarchopenfpga/src/read_openfpga_xml.cpp index 694ac8c11..a14ed3547 100644 --- a/libopenfpga/libarchopenfpga/src/read_openfpga_xml.cpp +++ b/libopenfpga/libarchopenfpga/src/read_openfpga_xml.cpp @@ -72,12 +72,40 @@ e_circuit_model_type string_to_circuit_model_type(const std::string& type_string return NUM_CIRCUIT_MODEL_TYPES; } +/******************************************************************** + * Parse XML codes of a circuit model to circuit library + *******************************************************************/ +static +void read_xml_circuit_model(pugi::xml_node& model_xml, + const pugiutil::loc_data& loc_data, + CircuitLibrary& circuit_lib) { + /* Find the type of the circuit model + * so that we can add a new circuit model to circuit library + */ + const char* type_attr = get_attribute(model_xml, "type", loc_data).value(); + + /* Translate the type of circuit model to enumerate */ + e_circuit_model_type model_type = string_to_circuit_model_type(std::string(type_attr)); + + if (NUM_CIRCUIT_MODEL_TYPES == model_type) { + archfpga_throw(loc_data.filename_c_str(), loc_data.line(model_xml), + "Invalid 'type' attribute '%s'\n", + type_attr); + } + + CircuitModelId model = circuit_lib.add_model(model_type); + + /* Find the name of the circuit model */ + const char* name_attr = get_attribute(model_xml, "name", loc_data).value(); + circuit_lib.set_model_name(model, std::string(name_attr)); +} + /******************************************************************** * Parse XML codes about circuit models to circuit library *******************************************************************/ static -CircuitLibrary read_xml_circuit_models(pugi::xml_node& Node, - const pugiutil::loc_data& loc_data) { +CircuitLibrary read_xml_module_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 @@ -87,26 +115,7 @@ CircuitLibrary read_xml_circuit_models(pugi::xml_node& Node, if (model_xml.name() != std::string("circuit_model")) { bad_tag(model_xml, loc_data, Node, {"circuit_model"}); } - - /* Find the type of the circuit model - * so that we can add a new circuit model to circuit library - */ - const char* type_attr = get_attribute(model_xml, "type", loc_data).value(); - - /* Translate the type of circuit model to enumerate */ - e_circuit_model_type model_type = string_to_circuit_model_type(std::string(type_attr)); - - if (NUM_CIRCUIT_MODEL_TYPES == model_type) { - archfpga_throw(loc_data.filename_c_str(), loc_data.line(Node), - "Invalid 'type' attribute '%s'\n", - type_attr); - } - - CircuitModelId model = circuit_lib.add_model(model_type); - - /* Find the name of the circuit model */ - const char* name_attr = get_attribute(model_xml, "name", loc_data).value(); - circuit_lib.set_model_name(model, std::string(name_attr)); + read_xml_circuit_model(model_xml, loc_data, circuit_lib); } return circuit_lib; @@ -135,7 +144,7 @@ CircuitSettings read_xml_openfpga_arch(const char* arch_file_name) { * 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_circuit_models(xml_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(), diff --git a/libopenfpga/libarchopenfpga/test/main.cpp b/libopenfpga/libarchopenfpga/test/main.cpp index 7f45ab30e..cf76e7a5b 100644 --- a/libopenfpga/libarchopenfpga/test/main.cpp +++ b/libopenfpga/libarchopenfpga/test/main.cpp @@ -3,11 +3,15 @@ * 1. parser of data structures * 2. writer of data structures *******************************************************************/ +#include "vtr_log.h" + #include "read_openfpga_xml.h" int main(int argc, const char** argv) { /* Parse the circuit library from an XML file */ - const CircuitSettings& circuit_setting = read_xml_openfpga_arch(argv[1]); + const CircuitSettings& circuit_settings = read_xml_openfpga_arch(argv[1]); + VTR_LOG("Parsed %s circuit models from XML into circuit library.\n", + circuit_settings.circuit_lib.num_models()); /* Check the circuit library */