#pragma once namespace NETLIST{ enum COMP_TYPE{ AND, OR, XOR, NOT, ONE, ZERO, DFF, TRIS, INPUT, OUTPUT, BUF, LUT, BROKEN }; class Pin{ public: std::string name; std::string type; int position; Pin(std::string n, std::string t, int p){ name = n; type = t; position = p; } }; class CompNet{ public: std::string name; std::string type; COMP_TYPE type_enum; std::vector< ::Pin> pins; CompNet(Component * c){ name = c->name; type = c->type; pins = c->pins; if(!type.compare("and")){ type_enum = AND; } else if(!type.compare("or")){ type_enum = OR; } else if(!type.compare("xor")){ type_enum = XOR; } else if(!type.compare("not")){ type_enum = NOT; } else if(!type.compare("evl_one")){ type_enum = ONE; } else if(!type.compare("evl_zero")){ type_enum = ZERO; } else if(!type.compare("evl_dff")){ type_enum = DFF; } else if(!type.compare("tris")){ type_enum = TRIS; } else if(!type.compare("evl_input")){ type_enum = INPUT; } else if(!type.compare("buf")){ type_enum = BUF; } else if(!type.compare("evl_lut")){ type_enum = LUT; } else if(!type.compare("evl_output")){ type_enum = OUTPUT; } else { type_enum = BROKEN; } } virtual std::string toString() = 0; friend std::ostream& operator<<(std::ostream& os, CompNet& cn){ return os << cn.toString(); } }; class BinaryOperator : public CompNet{ public: BinaryOperator(Component * c):CompNet(c){} std::string toString(){ std::string out = "\t\tcomponent " + type + (!name.compare("")?"":" "+name) + " "+patch::to_string(pins.size())+"\n"; for(std::vector< ::Pin>::iterator p = pins.begin(); p < pins.end(); ++p){ out += "\t\t\tpin "+patch::to_string(p->bus_msb - p->bus_lsb +1) + " " +p->name+(p->isBus?"["+patch::to_string(p->bus_msb)+"]":"")+"\n"; } return out; } }; class UnaryOperator : public CompNet{ public: UnaryOperator(Component * c):CompNet(c){} std::string toString(){ std::string out = "\t\tcomponent " + type + (!name.compare("")?"":" "+name) + " "+patch::to_string(pins.size())+"\n"; for(std::vector< ::Pin>::iterator p = pins.begin(); p < pins.end(); ++p){ out += "\t\t\tpin "+patch::to_string(p->bus_msb - p->bus_lsb +1) + " " +p->name+(p->isBus?"["+patch::to_string(p->bus_msb)+"]":"")+"\n"; } return out; } }; class EvlDiff : public CompNet{ public: EvlDiff(Component * c):CompNet(c){} std::string toString(){ std::string out = "\t\tcomponent " + type + (!name.compare("")?"":" "+name) + " "+patch::to_string(pins.size())+"\n"; for(std::vector< ::Pin>::iterator p = pins.begin(); p < pins.end(); ++p){ out += "\t\t\tpin "+patch::to_string(p->bus_msb - p->bus_lsb +1) + " " +p->name+(p->isBus?"["+patch::to_string(p->bus_msb)+"]":"")+"\n"; } return out; } }; class EvlClock : public CompNet{ public: EvlClock(Component * c):CompNet(c){} std::string toString(){ std::string out = "\t\tcomponent " + type + (!name.compare("")?"":" "+name) + " "+patch::to_string(pins.size())+"\n"; for(std::vector< ::Pin>::iterator p = pins.begin(); p < pins.end(); ++p){ out += "\t\t\tpin "+patch::to_string(p->bus_msb - p->bus_lsb +1) + " " +p->name+(p->isBus?"["+patch::to_string(p->bus_msb)+"]":"")+"\n"; } return out; } }; class EvlInput : public CompNet{ public: EvlInput(Component * c):CompNet(c){} std::string toString(){ std::string out = "\t\tcomponent " + type + (!name.compare("")?"":" "+name) + " "+patch::to_string(pins.size())+"\n"; for(std::vector< ::Pin>::iterator p = pins.begin(); p < pins.end(); ++p){ out += "\t\t\tpin "+patch::to_string(p->bus_msb - p->bus_lsb +1); for( int i = p->bus_lsb; i<= p->bus_msb; ++i){ out +=" " +p->name+(p->isBus?"["+patch::to_string(i)+"]":""); } out += "\n"; } return out; } }; class EvlOutput : public CompNet{ public: EvlOutput(Component * c):CompNet(c){} std::string toString(){ std::string out = "\t\tcomponent " + type + (!name.compare("")?"":" "+name) + " "+patch::to_string(pins.size())+"\n"; for(std::vector< ::Pin>::iterator p = pins.begin(); p < pins.end(); ++p){ out += "\t\t\tpin "+patch::to_string(p->bus_msb - p->bus_lsb +1); for( int i = p->bus_lsb; i<= p->bus_msb; ++i){ out +=" " +p->name+(p->isBus?"["+patch::to_string(i)+"]":""); } out += "\n"; } return out; } }; class PinNet{ public: std::string name; int position; bool isSingle; std::vector pins; std::string toString(){ std::string out = "\tnet " + name + (isSingle?" ":"[" + patch::to_string(position)+"] ")+patch::to_string(pins.size()) + "\n"; for(std::vector::iterator p = pins.begin(); p < pins.end(); ++p){ out += "\t\t"+(*p)->type+" "+(*p)->name+((*p)->name.compare("")?" ":"")+patch::to_string((*p)->position)+"\n"; } return out; } friend std::ostream& operator<<(std::ostream& os, PinNet& pn){ return os << pn.toString(); } }; PinNet * make_PinNet(Module * m, std::string w, int position, int width); CompNet * make_CompNet(Component * c); bool gen_netlist(std::vector & cn, std::vector & pn, std::vector& mods, std::string filename); }