diff --git a/CMakeLists.txt b/CMakeLists.txt index 4555e27..67fcdc5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,8 @@ cmake_minimum_required(VERSION 3.12) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + project(essim LANGUAGES CXX VERSION 0.1 diff --git a/src/imports/import_base.hpp b/src/imports/import_base.hpp index 4954b5c..3656e09 100644 --- a/src/imports/import_base.hpp +++ b/src/imports/import_base.hpp @@ -4,27 +4,31 @@ #include #include -#include "system/connect.hpp" #include "system/parts.hpp" +#include "system/signals.hpp" class ImportBase { protected: Parts *prts; - virtual void parse(std::fstream lines) = 0; + Signals *sigs; + std::fstream file_lines; public: - ImportBase() + ImportBase(std::string file_name) : file_lines(std::fstream(file_name)) { prts = new Parts(); - } - void load(std::string file_name) { - std::ifstream file(file_name); - + sigs = new Signals(); }; - Parts *parts() + virtual void parse() = 0; + Parts * parts() { return prts; } + Signals * signals() + { + return sigs; + } + virtual ~ImportBase() = default; }; #endif // _IMPORT_BASE_HPP_ \ No newline at end of file diff --git a/src/imports/import_mentor.cpp b/src/imports/import_mentor.cpp index 92120d4..416e827 100644 --- a/src/imports/import_mentor.cpp +++ b/src/imports/import_mentor.cpp @@ -1,67 +1,93 @@ #include "import_mentor.hpp" -#include "system/parts.hpp" #include "system/pins.hpp" +#include "system/parts.hpp" +#include #include #include -enum class State { +using namespace std; + +enum class State +{ NO_PART, IS_PART, }; -ImportMentor::ImportMentor(): ImportBase() { +ImportMentor::ImportMentor(string filename) : ImportBase(filename) {} -} - -ImportMentor::~ImportMentor() { +ImportMentor::~ImportMentor() +{ ImportBase::~ImportBase(); } -void ImportMentor::parse(std::fstream lines) { - std::string line; +void ImportMentor::parse() +{ + string line; auto state = State::NO_PART; - const std::regex name_regex("\\'([^\\']*)\\'"); - const std::regex part_regex("^COMP:"); - const std::regex pin_regex("^Explicit Pin:"); + const regex name_regex("'([^'\\s][^']*)'"); + const regex part_regex("^COMP:"); + const regex pin_regex("^\\s*Explicit Pin:"); - while (std::getline(lines, line)) + bool is_name_match = false; + bool is_part_match = false; + bool is_pin_match = false; + Part *prt = nullptr; + while (getline(file_lines, line)) { - Part *prt = nullptr; - std::smatch name_match; - bool is_name_match = std::regex_match(line, name_match, part_regex); - bool is_part_match = std::regex_match(line, part_regex); - bool is_pin_match = std::regex_match(line, pin_regex); + vector names; + for (sregex_iterator it(line.begin(), line.end(), name_regex), end; it != end; ++it) + { + names.push_back((*it)[1]); + } + is_name_match = (names.size() > 0); + is_part_match = regex_search(line, part_regex); + is_pin_match = regex_search(line, pin_regex); switch (state) { case State::NO_PART: - if (is_part_match) { - if (is_name_match) { - prt = new Part(name_match[0]); + if (is_part_match) + { + if (is_name_match) + { + prt = new Part(names[1]); state = State::IS_PART; } } break; default: - if (is_part_match) { - if (is_name_match) { - prts->add(*prt); - prt = new Part(name_match[0]); + if (is_part_match) + { + if (is_name_match) + { + prts->add(prt); + prt = new Part(names[1]); } } else if (is_pin_match) { - if (is_name_match) { - auto pin = new Pin(name_match[0]); - prt->add(*pin); + if (is_name_match) + { + auto pin = new Pin(names[0]); + Signal *s = nullptr; + prt->add(pin); + if (!sigs->exists(names[2])) + { + s = new Signal(names[2]); + sigs->add(s); + } else { + s = sigs->get(names[2]); + }; + pin->connect(s); } } break; } - if (state == State::IS_PART) { - prts->add(*prt); - } + } + if (state == State::IS_PART) + { + prts->add(prt); } } \ No newline at end of file diff --git a/src/imports/import_mentor.hpp b/src/imports/import_mentor.hpp index 30547d4..f3d6886 100644 --- a/src/imports/import_mentor.hpp +++ b/src/imports/import_mentor.hpp @@ -7,9 +7,9 @@ class ImportMentor : public ImportBase { - void parse(std::fstream lines); public: - ImportMentor(); + ImportMentor(std::string filename); + void parse() override; ~ImportMentor(); }; diff --git a/src/main.cpp b/src/main.cpp index 4d81784..a8fad52 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,18 +1,10 @@ -#include "system/signals.hpp" +#include "system/system.hpp" using namespace std; int main() { - auto sigs = Signals(); - Signal *sig = nullptr; - int i=0; - string sname = ""; - - while (i < 10) { - sname = "signal" + to_string(i); - sig = new Signal(sname); - sigs.add(*sig); - i++; - } + System sys = System(); + string ment_filename = "/home/francois/Projets/twinsys/test/BPB-2177_Netlist_2_3.qcv"; + sys.Load("bpb", ment_filename, ImportType::IMPORT_MENTOR); }; diff --git a/src/system/connect.cpp b/src/system/connect.cpp index 784aeb2..d089558 100644 --- a/src/system/connect.cpp +++ b/src/system/connect.cpp @@ -4,4 +4,4 @@ Connection::Connection(std::string name) : SystemElement(name) {}; Connections::Connections(void): SystemElementContainer("connections") {} -Connections::Connections(std::vector conns): SystemElementContainer("connections", conns) {} \ No newline at end of file +Connections::Connections(std::vector conns): SystemElementContainer("connections", conns) {} \ No newline at end of file diff --git a/src/system/connect.hpp b/src/system/connect.hpp index aa00bcc..5b36e46 100644 --- a/src/system/connect.hpp +++ b/src/system/connect.hpp @@ -13,7 +13,7 @@ class Connections : public SystemElementContainer { public: Connections(void); - Connections(std::vector connections); + Connections(std::vector connections); }; #endif // _CONNECT_HPP_ \ No newline at end of file diff --git a/src/system/modules.cpp b/src/system/modules.cpp index 5b1d6c0..343f64c 100644 --- a/src/system/modules.cpp +++ b/src/system/modules.cpp @@ -1,7 +1,7 @@ #include "modules.hpp" -Module::Module(std::string name) : SystemElementContainer(name) {}; +Module::Module(std::string name) : SystemElementContainer(name) {} Modules::Modules(void): SystemElementContainer("modules") {} -Modules::Modules(std::vector modules): SystemElementContainer("modules", modules) {} \ No newline at end of file +Modules::Modules(std::vector modules): SystemElementContainer("modules", modules) {} \ No newline at end of file diff --git a/src/system/modules.hpp b/src/system/modules.hpp index 4a11a75..935133a 100644 --- a/src/system/modules.hpp +++ b/src/system/modules.hpp @@ -3,10 +3,12 @@ #include "syselmts.hpp" #include "parts.hpp" +#include "signals.hpp" class Module : public SystemElementContainer { public: + Signals sigs; Module(std::string name); }; @@ -14,7 +16,7 @@ class Modules : public SystemElementContainer { public: Modules(void); - Modules(std::vector pins); + Modules(std::vector pins); }; #endif // _MODULES_HPP_ \ No newline at end of file diff --git a/src/system/parts.cpp b/src/system/parts.cpp index 9e2ecc9..8542c20 100644 --- a/src/system/parts.cpp +++ b/src/system/parts.cpp @@ -4,4 +4,4 @@ Part::Part(std::string name) : SystemElementContainer(name) {}; Parts::Parts(void): SystemElementContainer("parts") {} -Parts::Parts(std::vector parts): SystemElementContainer("parts", parts) {} \ No newline at end of file +Parts::Parts(std::vector parts): SystemElementContainer("parts", parts) {} \ No newline at end of file diff --git a/src/system/parts.hpp b/src/system/parts.hpp index 6f4205c..d3485d1 100644 --- a/src/system/parts.hpp +++ b/src/system/parts.hpp @@ -14,7 +14,7 @@ class Parts : public SystemElementContainer { public: Parts(void); - Parts(std::vector parts); + Parts(std::vector parts); }; #endif // _PARTS_HPP_ \ No newline at end of file diff --git a/src/system/pins.cpp b/src/system/pins.cpp index 2a50a73..fa4fb6a 100644 --- a/src/system/pins.cpp +++ b/src/system/pins.cpp @@ -1,7 +1,16 @@ #include "pins.hpp" -Pin::Pin(std::string name) : SystemElement(name) {}; +Pin::Pin(std::string name) : SystemElement(name), sig(nullptr) {}; + +bool Pin::connected() { + return sig != nullptr; +} + +void Pin::connect(Signal *signal) +{ + sig = signal; +} Pins::Pins(void): SystemElementContainer("pins") {} -Pins::Pins(std::vector pins): SystemElementContainer("pins", pins) {} \ No newline at end of file +Pins::Pins(std::vector pins): SystemElementContainer("pins", pins) {} \ No newline at end of file diff --git a/src/system/pins.hpp b/src/system/pins.hpp index ea2fb68..dfa3169 100644 --- a/src/system/pins.hpp +++ b/src/system/pins.hpp @@ -2,18 +2,22 @@ #define _PINS_HPP_ #include "syselmts.hpp" +#include "signals.hpp" class Pin : public SystemElement { + Signal *sig; public: Pin(std::string name); + bool connected(); + void connect(Signal *signal); }; class Pins : public SystemElementContainer { public: Pins(void); - Pins(std::vector pins); + Pins(std::vector pins); }; #endif // _PINS_HPP_ \ No newline at end of file diff --git a/src/system/signals.cpp b/src/system/signals.cpp index 3d2f05d..5b15cd5 100644 --- a/src/system/signals.cpp +++ b/src/system/signals.cpp @@ -5,5 +5,5 @@ Signal::Signal(std::string name) : SystemElementContainer(name) {}; Signals::Signals(void): SystemElementContainer("signals") {} -Signals::Signals(std::vector signals): SystemElementContainer("signals", signals) {} +Signals::Signals(std::vector signals): SystemElementContainer("signals", signals) {} diff --git a/src/system/signals.hpp b/src/system/signals.hpp index d1649d6..c9493c6 100644 --- a/src/system/signals.hpp +++ b/src/system/signals.hpp @@ -2,7 +2,9 @@ #define _SIGNALS_HPP_ #include "syselmts.hpp" -#include "pins.hpp" + +#pragma once +class Pin; class Signal : public SystemElementContainer { @@ -14,7 +16,7 @@ class Signals : public SystemElementContainer { public: Signals(void); - Signals(std::vector signals); + Signals(std::vector signals); }; #endif // _SIGNALS_HPP_ \ No newline at end of file diff --git a/src/system/syselmts.hpp b/src/system/syselmts.hpp index e8807a6..ea259fe 100644 --- a/src/system/syselmts.hpp +++ b/src/system/syselmts.hpp @@ -6,65 +6,82 @@ #include #include +using namespace std; + class SystemElement { public: - std::string name; - SystemElement(std::string name) : name(name) {}; + string name; + SystemElement(string name) : name(name) {}; }; template class SystemElementContainer : public SystemElement { private: - static_assert(std::is_base_of::value, "T shall be a system element descendant !"); + //static_assert(is_base_of::value, "T shall be a system element descendant !"); unsigned int iter_count; - std::unordered_map content; + unordered_map content; - bool name_exists(std::string name) + void add(unordered_map el_content) { - return get(name) != nullptr; + for (const auto &[key, value] : el_content) + { + add(value); + } } public: - SystemElementContainer(std::string name) : SystemElement(name) {}; - SystemElementContainer(std::string name, std::vector elements) : SystemElement(name) + SystemElementContainer(string name) : SystemElement(name) {}; + SystemElementContainer(string name, vector elements) : SystemElement(name) { add(elements); } - void add(T element) + bool exists(string name) { - if ("" == element.name) + try { - throw std::runtime_error("System elements with empty names are forbidden"); + get(name); + return true; } - if (name_exists(element.name)) + catch (const exception &e) { - throw std::runtime_error("System elements of same names are forbidden"); + return false; } - content.insert({element.name, element}); } - void add(SystemElementContainer elements) + void add(T* element) { - add(elements.content); + 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}); } - void add(std::vector elements) + void add(SystemElementContainer *elements) + { + add(elements->content); + } + void add(vector elements) { for (auto &element : elements) { add(element); } } - T *get(std::string name) + T *get(string name) { auto it = content.find(name); if (it != content.end()) { - return &it->second; + return it->second; } else { - return nullptr; + throw runtime_error("System elements not found"); } } };