00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "torc/physical/XdlExporter.hpp"
00020 #include <iosfwd>
00021
00022 namespace torc {
00023 namespace physical {
00024
00025 void XdlExporter::operator() (const DesignSharedPtr& inDesignPtr) {
00026
00027
00028
00029
00030
00031
00032
00033
00034 DesignSharedPtr designPtr(inDesignPtr);
00035 const Design& design = *designPtr;
00036 write(design);
00037
00038
00039 }
00040
00041 void XdlExporter::write(const Circuit& circuit) {
00042
00043 Circuit::InstanceSharedPtrConstIterator pi = circuit.instancesBegin();
00044 Circuit::InstanceSharedPtrConstIterator ei = circuit.instancesEnd();
00045 while(pi < ei) write(**pi++);
00046
00047
00048 Circuit::NetSharedPtrConstIterator pn = circuit.netsBegin();
00049 Circuit::NetSharedPtrConstIterator en = circuit.netsEnd();
00050 while(pn < en) write(**pn++);
00051 }
00052
00053 void XdlExporter::write(const Design& design) {
00054 indent();
00055 mStream << "design \"" << design.getName() << "\" " << design.getDevice()
00056 << design.getPackage() << design.getSpeedGrade() << " " << design.getXdlVersion();
00057 if(!design.configIsEmpty())
00058 { mStream << ", "; write(static_cast<const ConfigMap&>(design)); }
00059 mStream << ";" << std::endl;
00060
00061 Design::ModuleSharedPtrConstIterator p = design.modulesBegin();
00062 Design::ModuleSharedPtrConstIterator e = design.modulesEnd();
00063 while(p < e) write(**p++);
00064
00065 write(static_cast<Circuit>(design));
00066
00067 }
00068
00069 void XdlExporter::write(const Module& module) {
00070 indent();
00071 mStream << "module \"" << module.getName() << "\" \"" << module.getAnchor() << "\"";
00072 if(!module.configIsEmpty())
00073 { mStream << ", "; write(static_cast<const ConfigMap&>(module)); }
00074 mStream << ";" << std::endl;
00075
00076 mIndentCount++;
00077
00078 Module::PortSharedPtrConstIterator p = module.portsBegin();
00079 Module::PortSharedPtrConstIterator e = module.portsEnd();
00080 while(p < e) write(**p++);
00081
00082 write(static_cast<Circuit>(module));
00083
00084 mIndentCount--;
00085
00086 indent();
00087 mStream << "endmodule \"" << module.getName() << "\";" << std::endl;
00088 }
00089
00090 void XdlExporter::write(const Port& port) {
00091 indent();
00092 std::string instanceName = port.getInstancePtr().expired()
00093 ? "[expired instance]" : port.getInstancePtr().lock()->getName();
00094 mStream << "port \"" << port.getName() << "\" \"" << instanceName << "\" \""
00095 << port.getPinName() << "\";" << std::endl;
00096 }
00097
00098 void XdlExporter::write(const ConfigMap& configMap) {
00099
00100 if(configMap.configIsEmpty()) return;
00101
00102 mStream << "cfg \"";
00103
00104 ConfigMap::const_iterator p = configMap.configBegin();
00105 ConfigMap::const_iterator e = configMap.configEnd();
00106 while(p != e) {
00107 const std::string& setting = p->first;
00108 const Config& config = p->second;
00109 mStream << setting << ":" << config.getName() << ":" << config.getValue();
00110 p++;
00111 if(p != e) mStream << " ";
00112 }
00113
00114 mStream << "\"";
00115 }
00116
00117 void XdlExporter::write(const Instance& instance) {
00118 indent();
00119 mStream << "inst \"" << instance.getName() << "\" \"" << instance.getType() << "\", ";
00120 const std::string& site = instance.getSite();
00121 std::string tile = instance.getTile();
00122 EInstanceBonding bonding = instance.getBonding();
00123 if(site.empty()) {
00124 mStream << "unplaced";
00125
00126
00127 if(bonding != eInstanceBondingUnknown) {
00128 mStream << " " << (bonding == eInstanceBondingUnbonded ? "unbonded" : "bonded");
00129 }
00130 } else {
00131 if(tile.empty()) tile = "unknown";
00132 mStream << "placed " << tile << " " << site;
00133 }
00134 InstanceReferenceSharedPtr instanceReferencePtr = instance.getInstanceReferencePtr();
00135 if(instanceReferencePtr.get() != 0) {
00136 const InstanceReference& instanceReference = *instanceReferencePtr;
00137 std::string moduleName = instanceReference.getModulePtr().expired()
00138 ? "[expired module]" : instanceReference.getModulePtr().lock()->getName();
00139 std::string instanceName = instanceReference.getInstancePtr().expired()
00140 ? "[expired instance]" : instanceReference.getInstancePtr().lock()->getName();
00141 mStream << ", module \"" << instanceReference.getInstantiationName() << "\" \""
00142 << moduleName << "\" \"" << instanceName << "\"";
00143 }
00144 if(!instance.configIsEmpty())
00145 { mStream << ", "; write(static_cast<const ConfigMap&>(instance)); }
00146 mStream << ";" << std::endl;
00147 }
00148
00149 void XdlExporter::write(const Net& net) {
00150 indent();
00151
00152 mStream << "net \"" << net.getName() << "\"";
00153 switch(net.getNetType()) {
00154 case eNetTypePower: mStream << " power"; break;
00155 case eNetTypeGround: mStream << " ground"; break;
00156 default: break;
00157 }
00158 size_t left = net.getSourceCount() + net.getSinkCount() + net.getPipCount()
00159 + (net.configIsEmpty() ? 0 : 1);
00160 bool empty = (left == 0);
00161 mStream << (empty ? "" : ",") << std::endl;
00162
00163 Net::InstancePinSharedPtrConstIterator sop = net.sourcesBegin();
00164 Net::InstancePinSharedPtrConstIterator soe = net.sourcesEnd();
00165 while(sop < soe) write(**sop++, ePinDirectionOutpin, --left > 0);
00166
00167 Net::InstancePinSharedPtrConstIterator sip = net.sinksBegin();
00168 Net::InstancePinSharedPtrConstIterator sie = net.sinksEnd();
00169 while(sip < sie) write(**sip++, ePinDirectionInpin, --left > 0);
00170
00171 Net::PipConstIterator pip = net.pipsBegin();
00172 Net::PipConstIterator pie = net.pipsEnd();
00173 while(pip < pie) write(*pip++, --left > 0);
00174
00175 if(!net.configIsEmpty()) {
00176 indent();
00177 mStream << mIndentString;
00178 write(static_cast<const ConfigMap&>(net));
00179 mStream << std::endl;
00180 }
00181
00182 if(!empty) { indent(); mStream << mIndentString; }
00183 mStream << ";" << std::endl;
00184 }
00185
00186 void XdlExporter::write(const InstancePin& instancePin, EPinDirection pinDirection,
00187 bool comma) {
00188 indent();
00189 std::string instanceName = instancePin.getInstancePtr().expired()
00190 ? "[expired instance]" : instancePin.getInstancePtr().lock()->getName();
00191 mStream << mIndentString << (pinDirection == ePinDirectionInpin ? "inpin" : "outpin")
00192 << " \"" << instanceName << "\" " << instancePin.getPinName() << (comma ? "," : "")
00193 << std::endl;
00194 }
00195
00196 void XdlExporter::write(const Pip& pip, bool comma) {
00197 indent();
00198 mStream << mIndentString
00199 << "pip " << pip.getTileName() << " " << pip.getSourceWireName()
00200 << " " << pip.getDirectionString() << " " << pip.getSinkWireName()
00201 << (comma ? "," : "");
00202 if(pip.isRoutethrough()) write(*pip.getRoutethroughPtr());
00203 mStream << std::endl;
00204 }
00205
00206 void XdlExporter::write(const Routethrough& routethrough) {
00207 std::string instanceName = routethrough.getInstancePtr().expired()
00208 ? "[expired instance]" : routethrough.getInstancePtr().lock()->getName();
00209 mStream << " # " << routethrough.getSetting() << ":" << routethrough.getName() << ":"
00210 << routethrough.getValue() << " \"" << instanceName << "\" "
00211 << routethrough.getSourceWireName() << " -> " << routethrough.getSinkWireName();
00212 }
00213
00214 }
00215 }