#pragma once #include #include #include #include #include #include "token.h" #include //#define OUTPUT output_file //#define OUTPUT std::cout namespace patch { template < typename T > std::string to_string( const T& n ) { std::ostringstream stm ; stm << n ; return stm.str() ; } } class Wire{ public: std::string name; unsigned int width; Wire(){} Wire(std::string n, unsigned int w): name(n), width(w) {} std::string getName(){return name;}; unsigned int getWidth(){return width;}; }; class Pin{ public: std::string name; bool isBus; int bus_msb; int bus_lsb; }; class Component{ public: std::string name; std::string type; std::vector pins; Component(){} }; class Module{ public: std::string name; std::vector wires; std::vector components; Module(){} Module(std::string n): name(n){} void add_component(Component * c){ components.push_back(c); } std::string toString(){ std::string out = "module " + name + "\n"; if(wires.size() > 0){ out += "wires " + patch::to_string(wires.size()) + "\n"; for(std::vector::iterator i = wires.begin(); i < wires.end(); i++){ out += " wire " + (*i)->getName() + " " + patch::to_string((*i)->getWidth()) + "\n"; } } if(components.size() > 0){ out += "components " + patch::to_string(components.size()) + "\n"; for(std::vector::iterator i = components.begin(); i < components.end(); i++){ out += " component " + (*i)->type; if((*i)->name.compare("")){ out += " "+(*i)->name; } out += " "+patch::to_string((*i)->pins.size()) + "\n"; for(std::vector::iterator j = ((*i)->pins).begin(); j < ((*i)->pins).end(); j++){ out += " pin "+j->name; if(j-> bus_msb >= 0){ out += " "+patch::to_string(j->bus_msb); if(j-> bus_lsb >= 0){ out += " "+patch::to_string(j->bus_lsb); } } out +="\n"; } } } return out; } friend std::ostream& operator<<(std::ostream& os, Module& m){ return os << m.toString(); } }; namespace MODULE{ enum module_fsm_states{ INIT, NAME, ENDL, PARSE, WIRE_PARSER, COMPONENT_PARSER, END_MODULE }; bool parse_modules(std::vector &tokens, int * i, Module * module, module_fsm_states state ); void decode_modules(std::vector & modules, std::vector & tokens,std::string filename); } namespace WIRE{ enum wire_fsm_states{ INIT = 0, WIRE, BUS, BUS_MSB, BUS_COLON, BUS_LSB, BUS_DONE, WIRE_NAME, WIRES, DONE }; void wire_fsm_fail(); void parse_wires(std::vector * wires, Wire * wire, int width, std::vector &tokens, int * i, wire_fsm_states state); } namespace COMPONENT{ enum component_fsm_states{ INIT = 0, TYPE, NAME, PINS, PIN_NAME, BUS, BUS_MSB, BUS_COLON, BUS_LSB, BUS_DONE, PINS_DONE, DONE, }; void component_fsm_fail(); void component_fsm_parser(Component * comp, Pin * pin, std::vector &tokens, int * i, component_fsm_states state); } class Timer{ struct timespec start; public: Timer() { clock_gettime(CLOCK_MONOTONIC, &start); } ~Timer(){ struct timespec end; clock_gettime(CLOCK_MONOTONIC, &end); std::cout << "delta t" << float(end.tv_sec - start.tv_sec) + float(end.tv_nsec - start.tv_nsec)/1E9 << std::endl; } };