diff --git a/libopenfpga/libarchopenfpga/src/circuit_library.cpp b/libopenfpga/libarchopenfpga/src/circuit_library.cpp index cccc62e71..881035ee7 100644 --- a/libopenfpga/libarchopenfpga/src/circuit_library.cpp +++ b/libopenfpga/libarchopenfpga/src/circuit_library.cpp @@ -2,6 +2,7 @@ #include #include "vtr_assert.h" +#include "vtr_log.h" #include "openfpga_port_parser.h" #include "circuit_library.h" @@ -2108,6 +2109,23 @@ void CircuitLibrary::build_timing_graphs() { return; } +/* Automatically identify the default models for each type*/ +void CircuitLibrary::auto_detect_default_models() { + /* Go through the model fast look-up */ + for (const auto& curr_type_models : model_lookup_) { + if ( (1 == curr_type_models.size()) + && (false == model_is_default(curr_type_models[0]))) { + /* This is the only model in this type, + * it is safe to set it to be default + * Give a warning for users + */ + set_model_is_default(curr_type_models[0], true); + VTR_LOG_WARN("Automatically set circuit model '%s' to be default in its type.\n", + model_name(curr_type_models[0]).c_str()); + } + } +} + /************************************************************************ * Internal mutators: build timing graphs ***********************************************************************/ diff --git a/libopenfpga/libarchopenfpga/src/circuit_library.h b/libopenfpga/libarchopenfpga/src/circuit_library.h index abb03d1f8..5e023c665 100644 --- a/libopenfpga/libarchopenfpga/src/circuit_library.h +++ b/libopenfpga/libarchopenfpga/src/circuit_library.h @@ -461,6 +461,10 @@ class CircuitLibrary { public: /* Public Mutators: builders */ void build_model_links(); void build_timing_graphs(); + /* Automatically identify the default models for each type, + * suggest to do this after circuit library is built + */ + void auto_detect_default_models(); public: /* Internal mutators: build timing graphs */ void add_edge(const CircuitModelId& model_id, const CircuitPortId& from_port, const size_t& from_pin, diff --git a/libopenfpga/libarchopenfpga/src/read_xml_openfpga_arch.cpp b/libopenfpga/libarchopenfpga/src/read_xml_openfpga_arch.cpp index 6bc31ef46..e8ce6aeab 100644 --- a/libopenfpga/libarchopenfpga/src/read_xml_openfpga_arch.cpp +++ b/libopenfpga/libarchopenfpga/src/read_xml_openfpga_arch.cpp @@ -52,6 +52,9 @@ openfpga::Arch read_xml_openfpga_arch(const char* arch_file_name) { auto xml_circuit_models = get_single_child(xml_openfpga_arch, "circuit_library", loc_data); openfpga_arch.circuit_lib = read_xml_circuit_library(xml_circuit_models, loc_data); + /* Automatically identify the default models for circuit library */ + openfpga_arch.circuit_lib.auto_detect_default_models(); + /* Build the internal links for the circuit library */ openfpga_arch.circuit_lib.build_model_links();