Skip to content

Commit

Permalink
Push
Browse files Browse the repository at this point in the history
  • Loading branch information
clecat committed Mar 2, 2017
1 parent 5bc2e66 commit 863d954
Show file tree
Hide file tree
Showing 19 changed files with 67 additions and 13 deletions.
2 changes: 2 additions & 0 deletions include/AComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ namespace nts

public:
const std::string &getName() const;
const std::string &getType() const;
const std::vector<Pin> &getPins() const;
void setName(const std::string &);

protected:
std::string type;
std::string name;
std::vector<Pin> pins;
};
Expand Down
1 change: 1 addition & 0 deletions include/Parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# include <fstream>
# include <regex>
# include <map>
# include <vector>

#include "Create.hpp"

Expand Down
2 changes: 2 additions & 0 deletions src/components/AComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ namespace nts

const std::string &AComponent::getName() const {return (this->name);}

const std::string &AComponent::getType() const {return (this->type);}

const std::vector<Pin> &AComponent::getPins() const {return (this->pins);}
}
1 change: 1 addition & 0 deletions src/components/Clock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace nts
Clock::Clock(const std::string &)
{
this->name = "Clock";
this->type = "clock";
this->pins.push_back(Pin{nts::Pin::I});
this->pins[0].setState(FALSE);
}
Expand Down
1 change: 1 addition & 0 deletions src/components/False.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace nts
False::False(const std::string &)
{
this->name = "False";
this->type = "false";
this->pins.push_back(Pin{nts::Pin::I});
this->pins[0].setState(FALSE);
}
Expand Down
1 change: 1 addition & 0 deletions src/components/Input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace nts
Input::Input(const std::string &)
{
this->name = "Trigger";
this->type = "input";
this->pins.push_back(Pin{nts::Pin::I});
this->pins[0].setState(UNDEFINED);
}
Expand Down
1 change: 1 addition & 0 deletions src/components/Output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace nts
Output::Output(const std::string &)
{
this->name = "Output";
this->type = "output";
this->pins.push_back(Pin{nts::Pin::O});
}

Expand Down
1 change: 1 addition & 0 deletions src/components/True.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace nts
True::True(const std::string &)
{
this->name = "True";
this->type = "true";
this->pins.push_back(Pin{nts::Pin::I});
this->pins[0].setState(TRUE);
}
Expand Down
1 change: 1 addition & 0 deletions src/components/c4001.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace nts
c4001::c4001(const std::string &)
{
this->name = "4001";
this->type = "4001";
this->pins.push_back(Pin{nts::Pin::I});
this->pins.push_back(Pin{nts::Pin::I});
this->pins.push_back(Pin{nts::Pin::O});
Expand Down
1 change: 1 addition & 0 deletions src/components/c4008.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace nts
c4008::c4008(const std::string &)
{
this->name = "4008";
this->type = "4008";
this->pins.push_back(Pin{nts::Pin::I});
this->pins.push_back(Pin{nts::Pin::I});
this->pins.push_back(Pin{nts::Pin::I});
Expand Down
1 change: 1 addition & 0 deletions src/components/c4011.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace nts
c4011::c4011(const std::string &)
{
this->name = "4011";
this->type = "4011";
this->pins.push_back(Pin{nts::Pin::I});
this->pins.push_back(Pin{nts::Pin::I});
this->pins.push_back(Pin{nts::Pin::O});
Expand Down
1 change: 1 addition & 0 deletions src/components/c4013.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace nts
c4013::c4013(const std::string &)
{
this->name = "4013";
this->type = "4013";
this->pins.push_back(Pin{nts::Pin::O});
this->pins.push_back(Pin{nts::Pin::O});
this->pins.push_back(Pin{nts::Pin::I});
Expand Down
1 change: 1 addition & 0 deletions src/components/c4017.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace nts
c4017::c4017(const std::string &) : value(0), prevClock0(FALSE), prevClock1(FALSE)
{
this->name = "4017";
this->type = "4017";
this->pins.push_back(Pin{nts::Pin::O});
this->pins.push_back(Pin{nts::Pin::O});
this->pins.push_back(Pin{nts::Pin::O});
Expand Down
1 change: 1 addition & 0 deletions src/components/c4030.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace nts
c4030::c4030(const std::string &)
{
this->name = "4030";
this->type = "4030";
this->pins.push_back(Pin{nts::Pin::I});
this->pins.push_back(Pin{nts::Pin::I});
this->pins.push_back(Pin{nts::Pin::O});
Expand Down
1 change: 1 addition & 0 deletions src/components/c4040.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace nts
c4040::c4040(const std::string &) : value(0), prevClock(FALSE)
{
this->name = "4040";
this->type = "4040";
this->pins.push_back(Pin{nts::Pin::O});
this->pins.push_back(Pin{nts::Pin::O});
this->pins.push_back(Pin{nts::Pin::O});
Expand Down
1 change: 1 addition & 0 deletions src/components/c4069.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace nts
c4069::c4069(const std::string &)
{
this->name = "4069";
this->type = "4069";
this->pins.push_back(Pin{nts::Pin::I});
this->pins.push_back(Pin{nts::Pin::O});
this->pins.push_back(Pin{nts::Pin::I});
Expand Down
1 change: 1 addition & 0 deletions src/components/c4071.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace nts
c4071::c4071(const std::string &)
{
this->name = "4071";
this->type = "4071";
this->pins.push_back(Pin{nts::Pin::I});
this->pins.push_back(Pin{nts::Pin::I});
this->pins.push_back(Pin{nts::Pin::O});
Expand Down
1 change: 1 addition & 0 deletions src/components/c4081.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace nts
c4081::c4081(const std::string &)
{
this->name = "4081";
this->type = "4081";
this->pins.push_back(Pin{nts::Pin::I});
this->pins.push_back(Pin{nts::Pin::I});
this->pins.push_back(Pin{nts::Pin::O});
Expand Down
60 changes: 47 additions & 13 deletions src/main_parser.cpp
Original file line number Diff line number Diff line change
@@ -1,31 +1,65 @@
#include <typeinfo>
#include "../include/Parser.hpp"
#include "../include/IComponent.hpp"
#include <algorithm>

void dump(std::map<std::string, nts::IComponent *> chipsets)
void dump(std::vector<nts::IComponent *> chipsets)
{
for(std::vector<nts::IComponent *>::iterator it = chipsets.begin(); it != chipsets.end(); ++it )
(*it)->Dump();
}

// void simulate()
// {

// }

void display(std::vector<nts::IComponent *> chipsets)
{
for(std::vector<nts::IComponent *>::iterator it = chipsets.begin(); it != chipsets.end(); ++it )
if (dynamic_cast<nts::AComponent *>(*it)->getType() == "output")
{
std::cout << dynamic_cast<nts::AComponent *>(*it)->getName() << "=";
nts::Tristate_dump((*it)->Compute(1));
std::cout << std::endl;
}
}

bool cmp_icmp(const nts::IComponent *c1, const nts::IComponent *c2)
{
return (dynamic_cast<const nts::AComponent *>(c1)->getName() == dynamic_cast<const nts::AComponent *>(c2)->getName());
}

std::vector<nts::IComponent *> map_to_vector(std::map<std::string, nts::IComponent *> &chipsets)
{
std::vector<nts::IComponent *> chipsets_v;
for(std::map<std::string, nts::IComponent *>::iterator it = chipsets.begin(); it != chipsets.end(); ++it )
it->second->Dump();
chipsets_v.push_back( it->second );
std::sort(chipsets_v.begin(), chipsets_v.end(), cmp_icmp);
return (chipsets_v);
}

int launch(std::map<std::string, nts::IComponent *> chipsets)
int launch(std::map<std::string, nts::IComponent *> chipsets_m, std::vector<nts::IComponent *> chipsets_v)
{
(void)chipsets_m;
std::string command;
while (1)
{
std::cout << "> ";
std::cin >> command;
if (command == "exit")
if (std::cin.eof() || command == "exit")
return (0);
else if (command == "display")
;
else if (command == "simulate")
;
else if (command == "loop")
;
display(chipsets_v);
// else if (command == "simulate")
// simulate();
// else if (command == "loop")
// while (1)
// simulate();
else if (command == "dump")
dump(chipsets);
else if (command == "input")
;
dump(chipsets_v);
// else if (command == "input")
// ;
}
}

Expand All @@ -34,5 +68,5 @@ int main(int ac, char **av)
if (ac < 2)
return (84);
std::map<std::string, nts::IComponent *> chipsets = parser(av[1]);
return (launch(chipsets));
return (launch(chipsets, map_to_vector(chipsets)));
}

0 comments on commit 863d954

Please sign in to comment.