Skip to content

Commit

Permalink
Instance changes: Net defition and sanity checks (#1539)
Browse files Browse the repository at this point in the history
* Making Instance a base class (not derived from Block) and constructing instance features

* Creating instance nets out of module nets and ports

* Creating new nets with ports through signals

* Creating the new nets in instances and solving week_ptr problem

* Code formatting fixes

* Adding nets to blocks and verifying existance of older nets with same name or driber and loads

* Incremented patch version

---------

Co-authored-by: manadher <[email protected]>
Co-authored-by: alaindargelas <[email protected]>
  • Loading branch information
3 people authored Apr 11, 2024
1 parent e6aa31e commit 4c5cba4
Show file tree
Hide file tree
Showing 8 changed files with 410 additions and 289 deletions.
8 changes: 1 addition & 7 deletions src/DeviceModeling/DeviceModeling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,7 @@ bool DeviceModeling::RegisterCommands(TclInterpreter* interp, bool batchMode) {

auto define_net = [](void* clientData, Tcl_Interp* interp, int argc,
const char* argv[]) -> int {
// TODO: Implement this API
DeviceModeling* device_modeling = (DeviceModeling*)clientData;
Compiler* compiler = device_modeling->GetCompiler();
bool status = true;
std::string cmd(argv[0]);
std::string ret = "__Not Yet Integrated " + cmd;
compiler->TclInterp()->setResult(ret);
bool status = Model::get_modler().define_net(argc, argv);
return (status) ? TCL_OK : TCL_ERROR;
};
interp->registerCmd("define_net", define_net, this, 0);
Expand Down
252 changes: 122 additions & 130 deletions src/DeviceModeling/device_block.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,14 @@ class device_block {
*/
void add_port(std::shared_ptr<device_port> port) {
const std::string &port_name = port->get_name();
if (ports_map_.find(port_name) != end(ports_map_)) {
throw std::runtime_error("Port " + port_name + " does already exist in " +
block_name_);
}
ports_map_[port_name] = port;
for (auto &nt : port->get_signal()->get_net_vector()) {
add_net(nt);
}
}

/**
Expand All @@ -85,7 +92,7 @@ class device_block {
* @return Pointer to the found device_port object. Returns nullptr if the
* port is not found.
*/
std::shared_ptr<device_port> get_port(const std::string &port_name) const {
std::shared_ptr<device_port> get_port(const std::string &port_name) {
auto it = ports_map_.find(port_name);
return it != ports_map_.end() ? it->second : nullptr;
}
Expand Down Expand Up @@ -180,7 +187,15 @@ class device_block {
* @param net_name Name of the net.
* @param net Pointer to the device_net object to be added.
*/
void add_net(const std::string &net_name, std::shared_ptr<device_net> net) {
void add_net(std::shared_ptr<device_net> net) {
if (!net) {
throw std::runtime_error("Can't add a null net");
}
std::string net_name = net->get_net_name();
if (net_name.empty() || nets_map_.find(net_name) != end(nets_map_)) {
throw std::runtime_error("Net " + net_name + " already exists in block " +
block_name_);
}
nets_map_[net_name] = net;
}

Expand Down Expand Up @@ -1014,134 +1029,111 @@ class device_block {
return false; // Property not found
}

// // Overload of the operator <<
// friend ostream &operator<<(ostream &os, const device_block &block)
// {
// os << "Device block: " << block.block_name() << "\n";

// os << "Ports:\n";
// for (const auto &port : block.ports())
// {
// os << " " << port.first << " = ";
// if (port.second != nullptr)
// {
// os << *port.second;
// }
// else
// {
// os << "nullptr";
// }
// os << "\n";
// }

// os << "Signals:\n";
// for (const auto &signal : block.signals())
// {
// os << " " << signal.first << " = ";
// if (signal.second != nullptr)
// {
// os << *signal.second;
// }
// else
// {
// os << "nullptr";
// }
// os << "\n";
// }

// os << "Double parameters:\n";
// for (const auto &parameter : block.double_parameters())
// {
// os << " " << parameter.first << " = ";
// if (parameter.second != nullptr)
// {
// os << *parameter.second;
// }
// else
// {
// os << "nullptr";
// }
// os << "\n";
// }

// os << "Int parameters:\n";
// for (const auto &parameter : block.int_parameters())
// {
// os << " " << parameter.first << " = ";
// if (parameter.second != nullptr)
// {
// os << *parameter.second;
// }
// else
// {
// os << "nullptr";
// }
// os << "\n";
// }

// os << "String parameters:\n";
// for (const auto &parameter : block.string_parameters())
// {
// os << " " << parameter.first << " = ";
// if (parameter.second != nullptr)
// {
// os << *parameter.second;
// }
// else
// {
// os << "nullptr";
// }
// os << "\n";
// }

// os << "Attributes:\n";
// for (const auto &attribute : block.attributes())
// {
// os << " " << attribute.first << " = ";
// if (attribute.second != nullptr)
// {
// os << *attribute.second;
// }
// else
// {
// os << "nullptr";
// }
// os << "\n";
// }

// os << "Instances:\n";
// for (const auto &instance : block.instances())
// {
// os << " " << instance.first << " = ";
// if (instance.second != nullptr)
// {
// os << "__INSTANCE__"; // Assuming instance.second can't be
// printed directly
// }
// else
// {
// os << "nullptr";
// }
// os << "\n";
// }

// os << "Constraints:\n";
// for (const auto &constraint : block.constraints())
// {
// os << " " << constraint.first << " = ";
// if (constraint.second != nullptr)
// {
// os << *constraint.second;
// }
// else
// {
// os << "nullptr";
// }
// os << "\n";
// }

// return os;
// }
// Overload of the operator <<
friend ostream &operator<<(ostream &os, device_block &block) {
os << "Device block: " << block.block_name() << "\n";

os << "Ports:\n";
for (const auto &port : block.ports()) {
os << " " << port.first << " = ";
if (port.second != nullptr) {
os << *port.second;
} else {
os << "nullptr";
}
os << "\n";
}

os << "Signals:\n";
for (const auto &signal : block.device_signals()) {
os << " " << signal.first << " = ";
if (signal.second != nullptr) {
os << *signal.second;
} else {
os << "nullptr";
}
os << "\n";
}
os << "Nets:\n";
for (const auto &net : block.nets()) {
os << " " << net.first << " = ";
if (net.second != nullptr) {
os << *net.second;
} else {
os << "nullptr";
}
os << "\n";
}

os << "Double parameters:\n";
for (const auto &parameter : block.double_parameters()) {
os << " " << parameter.first << " = ";
if (parameter.second != nullptr) {
os << *parameter.second;
} else {
os << "nullptr";
}
os << "\n";
}

os << "Int parameters:\n";
for (const auto &parameter : block.int_parameters()) {
os << " " << parameter.first << " = ";
if (parameter.second != nullptr) {
os << *parameter.second;
} else {
os << "nullptr";
}
os << "\n";
}

os << "String parameters:\n";
for (const auto &parameter : block.string_parameters()) {
os << " " << parameter.first << " = ";
if (parameter.second != nullptr) {
os << *parameter.second;
} else {
os << "nullptr";
}
os << "\n";
}

os << "Attributes:\n";
for (const auto &attribute : block.attributes()) {
os << " " << attribute.first << " = ";
if (attribute.second != nullptr) {
os << *attribute.second;
} else {
os << "nullptr";
}
os << "\n";
}

os << "Instances:\n";
for (const auto &instance : block.instances()) {
os << " Instnce : " << instance.first; // << " = ";
// if (instance.second != nullptr) {
// os << (instance.second); // Assuming instance.second can't be
// // printed directly
// } else {
// os << "nullptr";
// }
os << "\n";
}

os << "Constraints:\n";
for (const auto &constraint : block.constraints()) {
os << " " << constraint.first << " = ";
if (constraint.second != nullptr) {
os << *constraint.second;
} else {
os << "nullptr";
}
os << "\n";
}

return os;
}
/**
* @brief Adds a mapping between a model name and a customer name.
*
Expand Down
Loading

0 comments on commit 4c5cba4

Please sign in to comment.