#include "module.h" #include "netlist.h" #include "simulator.h" namespace NETLIST{ bool gen_netlist(std::vector & cn, std::vector & pn, std::vector &mods, std::string filename){ std::string output_file_name = filename+".netlist"; std::ofstream output_file(output_file_name.c_str()); if (!output_file) { std::cerr << "I can't write " << filename << ".netlist ." << std::endl; exit(EXIT_FAILURE); } for(std::vector::iterator i = mods.begin() ; i::iterator w = (*i).wires.begin(); w < (*i).wires.end(); ++w){ net_num += (*(*w)).width; for(unsigned int wire_index = 0; wire_index< (*(*w)).width; wire_index++){ pn.push_back(make_PinNet(&(*i),(*(*w)).name, wire_index, (*(*w)).width)); } } if(net_num){ //OUTPUT << "nets " << net_num << std::endl; } for(std::vector::iterator curr_pin = pn.begin(); curr_pin < pn.end(); ++curr_pin){ //OUTPUT << **curr_pin; } for(std::vector::iterator c = (*i).components.begin(); c < (*i).components.end(); ++c){ cn.push_back(make_CompNet(*c)); } if(cn.size()){ //OUTPUT << "components " << patch::to_string(cn.size()) << std::endl; } for(std::vector::iterator c = cn.begin(); c < cn.end(); ++c){ //OUTPUT << **c; } } return true; } PinNet * make_PinNet(Module * m, std::string w, int position, int width){ PinNet * out = new PinNet(); out->name = w; out->position = position; out->isSingle = !(width > 1); //loop through components, adding those connected to the wire we care about for(std::vector::iterator comp = (*m).components.begin(); comp < (*m).components.end(); ++comp){ //loop through the pins of a component for(unsigned int i = 0; i < (*(*comp)).pins.size(); ++i){ if((*(*comp)).pins[i].name.compare(w) == 0){ (*(*comp)).pins[i].isBus = width>1; //fix unspecified msb,lsb to width-1,0 if(((*(*comp)).pins[i].bus_msb == -1) && ((*(*comp)).pins[i].bus_lsb == -1)){ (*(*comp)).pins[i].bus_msb = width -1; (*(*comp)).pins[i].bus_lsb = 0; } else { //if both are specified: //check width > msb >= lsb >= 0 // //if lsb is unspecified, set it to msb if((*(*comp)).pins[i].bus_lsb == -1){ (*(*comp)).pins[i].bus_lsb = (*(*comp)).pins[i].bus_msb; } //If the position we are looking for falls within } //the pins connected to the part, add it to the vector if(((*(*comp)).pins[i].bus_msb >= position) && (position >= (*(*comp)).pins[i].bus_lsb)){ out->pins.push_back(new NETLIST::Pin((*comp)->name,(*comp)->type,i)); } } } } return out; } CompNet * make_CompNet(Component * c){ if( (c->type.compare("and") == 0) || (c->type.compare("or") == 0) || (c->type.compare("xor") == 0) ){ return new BinaryOperator(c); } if( (c->type.compare("not") == 0) || (c->type.compare("buf") == 0)){ return new UnaryOperator(c); } if( (c->type.compare("evl_dff") == 0) || (c->type.compare("tris") == 0)){ return new EvlDiff(c); } if( (c->type.compare("evl_clock") == 0) ){ return new EvlClock(c); } if( (c->type.compare("evl_one") == 0) || (c->type.compare("evl_zero") == 0) || (c->type.compare("evl_input") == 0) || (c->type.compare("evl_lut") == 0)){ return new EvlInput(c); } if( (c->type.compare("evl_output") == 0) ){ return new EvlOutput(c); } return NULL; } }