Mentor import done.
This commit is contained in:
70
doc/classes.puml
Normal file
70
doc/classes.puml
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
@startuml
|
||||||
|
|
||||||
|
' Base class
|
||||||
|
class SystemElement {
|
||||||
|
- string name
|
||||||
|
+ SystemElement(string name)
|
||||||
|
}
|
||||||
|
|
||||||
|
' Template container class
|
||||||
|
class SystemElementContainer<T> {
|
||||||
|
- unsigned int iter_count
|
||||||
|
- unordered_map<string, T*> content
|
||||||
|
+ SystemElementContainer(string name)
|
||||||
|
+ SystemElementContainer(string name, vector<T*> elements)
|
||||||
|
+ bool exists(string name)
|
||||||
|
+ void add(T* element)
|
||||||
|
+ void add(SystemElementContainer<T>* elements)
|
||||||
|
+ void add(vector<T*> elements)
|
||||||
|
+ T* get(string name)
|
||||||
|
+ T* merge(string name)
|
||||||
|
+ iterator begin()
|
||||||
|
+ iterator end()
|
||||||
|
+ const_iterator begin() const
|
||||||
|
+ const_iterator end() const
|
||||||
|
}
|
||||||
|
|
||||||
|
SystemElementContainer --|> SystemElement
|
||||||
|
|
||||||
|
' Part and Pin classes
|
||||||
|
class Part {
|
||||||
|
+ Part(string name)
|
||||||
|
+ void add(Pin* pin)
|
||||||
|
}
|
||||||
|
|
||||||
|
class Pin {
|
||||||
|
+ Pin(string name)
|
||||||
|
+ void connect(Signal* signal)
|
||||||
|
}
|
||||||
|
|
||||||
|
Part --* Pin
|
||||||
|
|
||||||
|
' Signal class
|
||||||
|
class Signal {
|
||||||
|
+ Signal(string name)
|
||||||
|
+ void connect(Pin* pin)
|
||||||
|
}
|
||||||
|
|
||||||
|
Pin --> Signal
|
||||||
|
|
||||||
|
' Module and Modules classes
|
||||||
|
class Module {
|
||||||
|
+ Signals* signals
|
||||||
|
+ Modules* prnt
|
||||||
|
+ Module(string name)
|
||||||
|
+ ~Module()
|
||||||
|
}
|
||||||
|
|
||||||
|
class Modules {
|
||||||
|
+ Modules()
|
||||||
|
+ Modules(vector<Module*> parts)
|
||||||
|
+ void add(Module* module)
|
||||||
|
+ ~Modules()
|
||||||
|
}
|
||||||
|
|
||||||
|
Module --|> SystemElementContainer
|
||||||
|
Modules --|> SystemElementContainer
|
||||||
|
Module --> Modules
|
||||||
|
Module --> Signals
|
||||||
|
|
||||||
|
@enduml
|
||||||
@@ -106,7 +106,9 @@ void ImportMentor::parse(Signals *signals)
|
|||||||
auto pin = new Pin(names[0]); // Create a new pin with the first name.
|
auto pin = new Pin(names[0]); // Create a new pin with the first name.
|
||||||
Signal *s = nullptr;
|
Signal *s = nullptr;
|
||||||
prt->add(pin); // Add the pin to the current part.
|
prt->add(pin); // Add the pin to the current part.
|
||||||
pin->connect(signals->merge(names[2])); // Connect the pin to a signal.
|
s = signals->merge(names[2]); // Merge the signal with module signals.
|
||||||
|
s->add(pin); // Add the pin to the signal pins list.
|
||||||
|
pin->connect(s); // Connect the pin to a signal.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -3,8 +3,9 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
System sys = System();
|
System *sys = new System();
|
||||||
string ment_filename = "/home/francois/Projets/twinsys/test/BPB-2177_Netlist_2_3.qcv";
|
string ment_filename = "/home/francois/Projets/twinsys/test/BPB-2177_Netlist_2_3.qcv";
|
||||||
|
|
||||||
sys.Load("bpb", ment_filename, ImportType::IMPORT_MENTOR);
|
sys->Load("bpb", ment_filename, ImportType::IMPORT_MENTOR);
|
||||||
|
delete sys;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,7 +1,30 @@
|
|||||||
#include "modules.hpp"
|
#include "modules.hpp"
|
||||||
|
|
||||||
Module::Module(std::string name) : SystemElementContainer<Part>(name) {}
|
#include "signals.hpp"
|
||||||
|
|
||||||
|
Module::Module(std::string name) : SystemElementContainer<Part>(name), prnt(nullptr) {
|
||||||
|
signals = new Signals();
|
||||||
|
}
|
||||||
|
|
||||||
|
Module::~Module() {
|
||||||
|
for (const auto& [key, value] : content) {
|
||||||
|
delete value;
|
||||||
|
}
|
||||||
|
delete signals;
|
||||||
|
}
|
||||||
|
|
||||||
Modules::Modules(void): SystemElementContainer<Module>("modules") {}
|
Modules::Modules(void): SystemElementContainer<Module>("modules") {}
|
||||||
|
|
||||||
Modules::Modules(std::vector<Module *> modules): SystemElementContainer<Module>("modules", modules) {}
|
Modules::Modules(std::vector<Module *> modules): SystemElementContainer<Module>("modules", modules) {}
|
||||||
|
|
||||||
|
void Modules::add(Module *module)
|
||||||
|
{
|
||||||
|
SystemElementContainer<Module>::add(module);
|
||||||
|
module->prnt = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
Modules::~Modules() {
|
||||||
|
for (const auto& [key, value] : content) {
|
||||||
|
delete value;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,20 +3,28 @@
|
|||||||
|
|
||||||
#include "syselmts.hpp"
|
#include "syselmts.hpp"
|
||||||
#include "parts.hpp"
|
#include "parts.hpp"
|
||||||
#include "signals.hpp"
|
|
||||||
|
#pragma once
|
||||||
|
class Modules; ///< Forward declaration of the Modules class.
|
||||||
|
class Signals; ///< Forward declaration of the Signals class.
|
||||||
|
|
||||||
|
|
||||||
class Module : public SystemElementContainer<Part>
|
class Module : public SystemElementContainer<Part>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Signals sigs;
|
Signals *signals;
|
||||||
|
Modules *prnt;
|
||||||
Module(std::string name);
|
Module(std::string name);
|
||||||
|
~Module();
|
||||||
};
|
};
|
||||||
|
|
||||||
class Modules : public SystemElementContainer<Module>
|
class Modules : public SystemElementContainer<Module>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Modules(void);
|
Modules(void);
|
||||||
Modules(std::vector<Module *> pins);
|
Modules(std::vector<Module *> parts);
|
||||||
|
void add(Module *module);
|
||||||
|
~Modules();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _MODULES_HPP_
|
#endif // _MODULES_HPP_
|
||||||
@@ -1,6 +1,18 @@
|
|||||||
#include "parts.hpp"
|
#include "parts.hpp"
|
||||||
|
|
||||||
Part::Part(std::string name) : SystemElementContainer<Pin>(name) {};
|
Part::Part(std::string name) : SystemElementContainer<Pin>(name), prnt(nullptr) {};
|
||||||
|
|
||||||
|
void Part::add(Pin *pin)
|
||||||
|
{
|
||||||
|
SystemElementContainer<Pin>::add(pin);
|
||||||
|
pin->prnt = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
Part::~Part() {
|
||||||
|
for (const auto& [key, value] : content) {
|
||||||
|
delete value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Parts::Parts(void): SystemElementContainer<Part>("parts") {}
|
Parts::Parts(void): SystemElementContainer<Part>("parts") {}
|
||||||
|
|
||||||
|
|||||||
@@ -4,10 +4,16 @@
|
|||||||
#include "syselmts.hpp"
|
#include "syselmts.hpp"
|
||||||
#include "pins.hpp"
|
#include "pins.hpp"
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
class Module; ///< Forward declaration of the Module class.
|
||||||
|
|
||||||
class Part : public SystemElementContainer<Pin>
|
class Part : public SystemElementContainer<Pin>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Part(std::string name);
|
Part(std::string name);
|
||||||
|
~Part();
|
||||||
|
Module *prnt; ///< Pointer to the parent module.
|
||||||
|
void add(Pin *pin) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Parts : public SystemElementContainer<Part>
|
class Parts : public SystemElementContainer<Part>
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
#include "pins.hpp"
|
#include "pins.hpp"
|
||||||
|
#include "parts.hpp"
|
||||||
|
#include "signals.hpp"
|
||||||
|
|
||||||
Pin::Pin(std::string name) : SystemElement(name), sig(nullptr) {};
|
Pin::Pin(std::string name) : SystemElement(name), sig(nullptr), prnt(nullptr) {};
|
||||||
|
|
||||||
bool Pin::connected() {
|
bool Pin::connected()
|
||||||
|
{
|
||||||
return sig != nullptr;
|
return sig != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,13 +2,19 @@
|
|||||||
#define _PINS_HPP_
|
#define _PINS_HPP_
|
||||||
|
|
||||||
#include "syselmts.hpp"
|
#include "syselmts.hpp"
|
||||||
#include "signals.hpp"
|
|
||||||
|
#pragma once
|
||||||
|
class Part;
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
class Signal;
|
||||||
|
|
||||||
class Pin : public SystemElement
|
class Pin : public SystemElement
|
||||||
{
|
{
|
||||||
Signal *sig;
|
Signal *sig;
|
||||||
public:
|
public:
|
||||||
Pin(std::string name);
|
Pin(std::string name);
|
||||||
|
Part *prnt; ///< Pointer to the parent part.
|
||||||
bool connected();
|
bool connected();
|
||||||
void connect(Signal *signal);
|
void connect(Signal *signal);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,11 +1,27 @@
|
|||||||
|
|
||||||
#include "signals.hpp"
|
#include "signals.hpp"
|
||||||
|
#include "parts.hpp"
|
||||||
|
|
||||||
Signal::Signal(std::string name) : SystemElementContainer<Pin>(name) {};
|
Signal::Signal(std::string name) : SystemElementContainer<Pin>(name), prnt(nullptr) {};
|
||||||
|
|
||||||
|
void Signal::add(Pin *pin)
|
||||||
|
{
|
||||||
|
string pname = pin->prnt->name + "." + pin->name;
|
||||||
|
SystemElementContainer<Pin>::add(pname, pin);
|
||||||
|
}
|
||||||
|
|
||||||
Signals::Signals(void): SystemElementContainer<Signal>("signals") {}
|
Signals::Signals(void): SystemElementContainer<Signal>("signals") {}
|
||||||
|
|
||||||
Signals::Signals(std::vector<Signal *> signals): SystemElementContainer<Signal>("signals", signals) {}
|
Signals::Signals(std::vector<Signal *> signals): SystemElementContainer<Signal>("signals", signals) {}
|
||||||
|
|
||||||
Signals::~Signals() {}
|
Signals::~Signals() {
|
||||||
|
for (const auto& [key, value] : content) {
|
||||||
|
delete value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Signals::add(Signal *signal)
|
||||||
|
{
|
||||||
|
SystemElementContainer<Signal>::add(signal);
|
||||||
|
signal->prnt = this;
|
||||||
|
}
|
||||||
@@ -2,14 +2,17 @@
|
|||||||
#define _SIGNALS_HPP_
|
#define _SIGNALS_HPP_
|
||||||
|
|
||||||
#include "syselmts.hpp"
|
#include "syselmts.hpp"
|
||||||
|
#include "pins.hpp"
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
class Pin;
|
class Signals;
|
||||||
|
|
||||||
class Signal : public SystemElementContainer<Pin>
|
class Signal : public SystemElementContainer<Pin>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
Signals *prnt; ///< Pointer to the parent signals object.
|
||||||
Signal(std::string name);
|
Signal(std::string name);
|
||||||
|
void add(Pin *pin) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Signals : public SystemElementContainer<Signal>
|
class Signals : public SystemElementContainer<Signal>
|
||||||
@@ -17,6 +20,7 @@ class Signals : public SystemElementContainer<Signal>
|
|||||||
public:
|
public:
|
||||||
Signals(void);
|
Signals(void);
|
||||||
Signals(std::vector<Signal *> signals);
|
Signals(std::vector<Signal *> signals);
|
||||||
|
void add(Signal *signal) override;
|
||||||
~Signals();
|
~Signals();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ public:
|
|||||||
using iterator = typename MapType::iterator; // Iterator for the map.
|
using iterator = typename MapType::iterator; // Iterator for the map.
|
||||||
using const_iterator = typename MapType::const_iterator; // Const iterator for the map.
|
using const_iterator = typename MapType::const_iterator; // Const iterator for the map.
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
unsigned int iter_count; // Counter for iterations (currently unused).
|
unsigned int iter_count; // Counter for iterations (currently unused).
|
||||||
MapType content; // Container for storing elements.
|
MapType content; // Container for storing elements.
|
||||||
|
|
||||||
@@ -69,6 +69,35 @@ public:
|
|||||||
add(elements);
|
add(elements);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Adds a single element to the container with a given name.
|
||||||
|
* @param name Name of the element to add.
|
||||||
|
* @param element Pointer to the element to add.
|
||||||
|
* @throws runtime_error If the element's name is empty or already exists.
|
||||||
|
*/
|
||||||
|
virtual void add(string name, T *element)
|
||||||
|
{
|
||||||
|
if ("" == name)
|
||||||
|
{
|
||||||
|
throw runtime_error("System elements with empty names are forbidden");
|
||||||
|
}
|
||||||
|
if (exists(name))
|
||||||
|
{
|
||||||
|
throw runtime_error("System elements of same names are forbidden");
|
||||||
|
}
|
||||||
|
content.insert({name, element});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Adds a single element to the container.
|
||||||
|
* @param element Pointer to the element to add.
|
||||||
|
* @throws runtime_error If the element's name is empty or already exists.
|
||||||
|
*/
|
||||||
|
virtual void add(T *element)
|
||||||
|
{
|
||||||
|
add (element->name, element);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Checks if an element exists in the container.
|
* @brief Checks if an element exists in the container.
|
||||||
* @param name Name of the element to check.
|
* @param name Name of the element to check.
|
||||||
@@ -87,24 +116,6 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Adds a single element to the container.
|
|
||||||
* @param element Pointer to the element to add.
|
|
||||||
* @throws runtime_error If the element's name is empty or already exists.
|
|
||||||
*/
|
|
||||||
void add(T *element)
|
|
||||||
{
|
|
||||||
if ("" == element->name)
|
|
||||||
{
|
|
||||||
throw runtime_error("System elements with empty names are forbidden");
|
|
||||||
}
|
|
||||||
if (exists(element->name))
|
|
||||||
{
|
|
||||||
throw runtime_error("System elements of same names are forbidden");
|
|
||||||
}
|
|
||||||
content.insert({element->name, element});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Adds elements from another container.
|
* @brief Adds elements from another container.
|
||||||
* @param elements Pointer to another container.
|
* @param elements Pointer to another container.
|
||||||
@@ -152,7 +163,8 @@ public:
|
|||||||
*/
|
*/
|
||||||
T *merge(string name)
|
T *merge(string name)
|
||||||
{
|
{
|
||||||
if (exists(name)) {
|
if (exists(name))
|
||||||
|
{
|
||||||
return get(name);
|
return get(name);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -167,25 +179,25 @@ public:
|
|||||||
* @brief Returns an iterator to the beginning of the container.
|
* @brief Returns an iterator to the beginning of the container.
|
||||||
* @return Iterator to the beginning.
|
* @return Iterator to the beginning.
|
||||||
*/
|
*/
|
||||||
iterator begin() { return content.begin(); }
|
iterator begin() { return std::begin(content); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns an iterator to the end of the container.
|
* @brief Returns an iterator to the end of the container.
|
||||||
* @return Iterator to the end.
|
* @return Iterator to the end.
|
||||||
*/
|
*/
|
||||||
iterator end() { return content.end(); }
|
iterator end() { return std::end(content); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns a constant iterator to the beginning of the container.
|
* @brief Returns a constant iterator to the beginning of the container.
|
||||||
* @return Constant iterator to the beginning.
|
* @return Constant iterator to the beginning.
|
||||||
*/
|
*/
|
||||||
const_iterator begin() const { return content.begin(); }
|
const_iterator begin() const { return std::begin(content); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns a constant iterator to the end of the container.
|
* @brief Returns a constant iterator to the end of the container.
|
||||||
* @return Constant iterator to the end.
|
* @return Constant iterator to the end.
|
||||||
*/
|
*/
|
||||||
const_iterator end() const { return content.end(); }
|
const_iterator end() const { return std::end(content); }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,28 +1,43 @@
|
|||||||
|
|
||||||
#include "system.hpp"
|
#include "system.hpp"
|
||||||
|
|
||||||
|
#include "connect.hpp"
|
||||||
|
#include "modules.hpp"
|
||||||
#include "imports/import_mentor.hpp"
|
#include "imports/import_mentor.hpp"
|
||||||
|
|
||||||
System::System(): mods(nullptr), conns(nullptr) {
|
System::System() : mods(nullptr), conns(nullptr)
|
||||||
|
{
|
||||||
mods = new Modules();
|
mods = new Modules();
|
||||||
conns = new Connections();
|
conns = new Connections();
|
||||||
}
|
}
|
||||||
|
|
||||||
System::~System() {
|
System::~System()
|
||||||
|
{
|
||||||
delete mods;
|
delete mods;
|
||||||
delete conns;
|
delete conns;
|
||||||
}
|
}
|
||||||
|
|
||||||
void System::Load(std::string module_name, std::string file_name, ImportType type) {
|
void System::Load(std::string module_name, std::string file_name, ImportType type)
|
||||||
|
{
|
||||||
ImportBase *imp;
|
ImportBase *imp;
|
||||||
|
Module *mod = nullptr;
|
||||||
Parts *prts = nullptr;
|
Parts *prts = nullptr;
|
||||||
Module mod = Module(module_name);
|
if (!mods->exists(module_name))
|
||||||
|
{
|
||||||
|
mod = new Module(module_name);
|
||||||
|
mods->add(mod);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mod = mods->get(module_name);
|
||||||
|
}
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case ImportType::IMPORT_MENTOR:
|
case ImportType::IMPORT_MENTOR:
|
||||||
imp = new ImportMentor(file_name);
|
imp = new ImportMentor(file_name);
|
||||||
imp->parse();
|
imp->parse(mod->signals);
|
||||||
prts = imp->parts();
|
prts = imp->parts();
|
||||||
mod.add(prts);
|
mod->add(prts);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
#ifndef _SYSTEM_HPP_
|
#ifndef _SYSTEM_HPP_
|
||||||
#define _SYSTEM_HPP_
|
#define _SYSTEM_HPP_
|
||||||
|
|
||||||
#include "connect.hpp"
|
#include "imports/import_base.hpp"
|
||||||
#include "modules.hpp"
|
|
||||||
|
#pragma once
|
||||||
|
class Modules; ///< Forward declaration of the Modules class.
|
||||||
|
class Connections; ///< Forward declaration of the Connections class.
|
||||||
|
|
||||||
|
|
||||||
enum class ImportType {
|
enum class ImportType {
|
||||||
IMPORT_MENTOR,
|
IMPORT_MENTOR,
|
||||||
|
|||||||
Reference in New Issue
Block a user