OpenFPGA/openfpga/src/fabric/build_module_graph_utils.cpp

104 lines
4.3 KiB
C++
Raw Normal View History

2020-02-12 20:45:14 -06:00
/********************************************************************
* This file includes most utilized functions that are used to
* build module graphs
********************************************************************/
#include <vector>
/* Headers from vtrutil library */
#include "build_module_graph_utils.h"
#include "openfpga_naming.h"
2020-02-12 20:45:14 -06:00
#include "vtr_assert.h"
/* begin namespace openfpga */
namespace openfpga {
/********************************************************************
* Find input port of a buffer/inverter module
********************************************************************/
ModulePortId find_inverter_buffer_module_port(
const ModuleManager& module_manager, const ModuleId& module_id,
const CircuitLibrary& circuit_lib, const CircuitModelId& model_id,
const e_circuit_model_port_type& port_type) {
2020-02-12 20:45:14 -06:00
/* We must have a valid module id */
VTR_ASSERT(true == module_manager.valid_module_id(module_id));
/* Check the type of model */
2020-02-12 20:45:14 -06:00
VTR_ASSERT(CIRCUIT_MODEL_INVBUF == circuit_lib.model_type(model_id));
/* Add module nets to wire to the buffer module */
/* To match the context, Buffer should have only 2 non-global ports: 1 input
* port and 1 output port */
std::vector<CircuitPortId> model_ports =
circuit_lib.model_ports_by_type(model_id, port_type, true);
2020-02-12 20:45:14 -06:00
VTR_ASSERT(1 == model_ports.size());
/* Find the input and output module ports */
ModulePortId module_port_id = module_manager.find_module_port(
module_id, circuit_lib.port_prefix(model_ports[0]));
VTR_ASSERT(true ==
module_manager.valid_module_port_id(module_id, module_port_id));
2020-02-12 20:45:14 -06:00
return module_port_id;
2020-02-12 20:45:14 -06:00
}
/********************************************************************
* Add inverter/buffer module to a parent module
* and complete the wiring to the input port of inverter/buffer
* This function will return the wire created for the output port of
*inverter/buffer
2020-02-12 20:45:14 -06:00
*
* parent_module
* +-----------------------------------------------------------------
* |
2020-02-12 20:45:14 -06:00
* | input_net output_net
* | | |
* | v +---------------+ v
* | src_module_port --------->| child_module |-------->
2020-02-12 20:45:14 -06:00
* | +---------------+
*
********************************************************************/
ModuleNetId add_inverter_buffer_child_module_and_nets(
ModuleManager& module_manager, const ModuleId& parent_module,
const CircuitLibrary& circuit_lib, const CircuitModelId& model_id,
const ModuleNetId& input_net) {
2020-02-12 20:45:14 -06:00
/* We must have a valid module id */
VTR_ASSERT(true == module_manager.valid_module_id(parent_module));
std::string module_name = circuit_lib.model_name(model_id);
ModuleId child_module = module_manager.find_module(module_name);
VTR_ASSERT(true == module_manager.valid_module_id(child_module));
ModulePortId module_input_port_id =
find_inverter_buffer_module_port(module_manager, child_module, circuit_lib,
model_id, CIRCUIT_MODEL_PORT_INPUT);
ModulePortId module_output_port_id =
find_inverter_buffer_module_port(module_manager, child_module, circuit_lib,
model_id, CIRCUIT_MODEL_PORT_OUTPUT);
2020-02-12 20:45:14 -06:00
/* Port size should be 1 ! */
VTR_ASSERT(
1 ==
module_manager.module_port(child_module, module_input_port_id).get_width());
VTR_ASSERT(1 ==
module_manager.module_port(child_module, module_output_port_id)
.get_width());
2020-02-12 20:45:14 -06:00
/* Instanciate a child module */
size_t child_instance =
module_manager.num_instance(parent_module, child_module);
2020-02-12 20:45:14 -06:00
module_manager.add_child_module(parent_module, child_module);
/* Use the net to connect to the input net of buffer */
module_manager.add_module_net_sink(parent_module, input_net, child_module,
child_instance, module_input_port_id, 0);
2020-02-12 20:45:14 -06:00
/* Create a net to bridge the input inverter and LUT MUX */
2020-02-12 20:45:14 -06:00
ModuleNetId output_net = module_manager.create_module_net(parent_module);
module_manager.add_module_net_source(parent_module, output_net, child_module,
child_instance, module_output_port_id,
0);
2020-02-12 20:45:14 -06:00
return output_net;
}
} /* end namespace openfpga */