|
degate 0.1.1
|
00001 /* -*-c++-*- 00002 00003 This file is part of the IC reverse engineering tool degate. 00004 00005 Copyright 2008, 2009, 2010 by Martin Schobert 00006 00007 Degate is free software: you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation, either version 3 of the License, or 00010 any later version. 00011 00012 Degate is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with degate. If not, see <http://www.gnu.org/licenses/>. 00019 00020 */ 00021 00022 #ifndef __LOGICMODEL_H__ 00023 #define __LOGICMODEL_H__ 00024 00025 #include <globals.h> 00026 #include <LogicModelObjectBase.h> 00027 #include <PlacedLogicModelObject.h> 00028 #include <Net.h> 00029 #include <Layer.h> 00030 00031 #include <Rectangle.h> 00032 00033 #include <Via.h> 00034 #include <Wire.h> 00035 #include <EMarker.h> 00036 #include <Gate.h> 00037 #include <GatePort.h> 00038 #include <GateTemplate.h> 00039 #include <GateTemplatePort.h> 00040 #include <GateLibrary.h> 00041 #include <Annotation.h> 00042 #include <Module.h> 00043 00044 #include <tr1/memory> 00045 #include <set> 00046 #include <map> 00047 #include <sstream> 00048 #include <iostream> 00049 00050 namespace degate { 00051 00052 /** 00053 * This class represents the logic model. 00054 * 00055 * Note: This class is central in degate. So it tends to be somehow bloated. 00056 * Convinient methods should go into LogicModelHelper.h 00057 * 00058 * @todo implement a move_object 00059 */ 00060 class LogicModel { 00061 00062 public: 00063 00064 typedef std::map<object_id_t, PlacedLogicModelObject_shptr> object_collection; 00065 typedef std::map<object_id_t, Net_shptr> net_collection; 00066 typedef std::map<object_id_t, Annotation_shptr> annotation_collection; 00067 typedef std::map<object_id_t, Via_shptr > via_collection; 00068 00069 typedef std::vector<Layer_shptr> layer_collection; 00070 typedef std::map<object_id_t, Gate_shptr > gate_collection; 00071 00072 private: 00073 00074 BoundingBox bounding_box; 00075 00076 layer_collection layers; // x 00077 Layer_shptr current_layer; 00078 00079 std::tr1::shared_ptr<GateLibrary> gate_library; // x 00080 00081 gate_collection gates; 00082 std::map<object_id_t, Wire_shptr > wires; 00083 via_collection vias; 00084 std::map<object_id_t, EMarker_shptr > emarkers; 00085 annotation_collection annotations; 00086 net_collection nets; 00087 Module_shptr main_module; 00088 00089 /** 00090 * Contains any placeable object. 00091 */ 00092 object_collection objects; 00093 00094 00095 /** 00096 * Counter to generate new object IDs. 00097 */ 00098 object_id_t object_id_counter; 00099 00100 00101 /** 00102 * List of remote objects, that were deleted from the logic model. 00103 */ 00104 std::list<object_id_t> removed_remote_oids; 00105 00106 typedef std::map<object_id_t, object_id_t> roid_mapping_t; 00107 00108 /** 00109 * Mapping from remote OIDs to local OIDs. 00110 */ 00111 roid_mapping_t roid_mapping; 00112 00113 diameter_t port_diameter; 00114 00115 private: 00116 00117 /** 00118 * Get a layer. Create the layer if it doesn't exists. 00119 * @see get_layer 00120 */ 00121 Layer_shptr get_create_layer(layer_position_t pos); 00122 00123 /** 00124 * Add a wire into the logic model. If the layer doesn't exists, the layer is created implicitly. 00125 * If the wire has no object ID, a new object ID for the wire is generated. 00126 * @param layer_pos The layer position (starting at 0). 00127 * @param o A shared pointer to the object. 00128 */ 00129 00130 void add_wire(int layer_pos, Wire_shptr o); 00131 00132 /** 00133 * Add a via into the logic model. If the layer doesn't exists, the layer is created implicitly. 00134 * If the via has no object ID, a new object ID for the via is generated. 00135 * @param layer_pos The layer position (starting at 0). 00136 * @param o A shared pointer to the object. 00137 */ 00138 00139 void add_via(int layer_pos, Via_shptr o); 00140 00141 /** 00142 * Add an emarker into the logic model. If the layer doesn't exists, the layer is created implicitly. 00143 * If the emarker has no object ID, a new object ID for the emarker is generated. 00144 * @param layer_pos The layer position (starting at 0). 00145 * @param o A shared pointer to the object. 00146 */ 00147 00148 void add_emarker(int layer_pos, EMarker_shptr o); 00149 00150 /** 00151 * Add an annotation into the logic model. If the layer doesn't exists, the layer is created implicitly. 00152 * If the annotation has no object ID, a new object ID for the via is generated. 00153 * @param layer_pos The layer position (starting at 0). 00154 * @param o A shared pointer to the object. 00155 */ 00156 00157 void add_annotation(int layer_pos, Annotation_shptr o); 00158 00159 00160 /** 00161 * Add a gate into the logic model. If the layer doesn't exists, the layer is 00162 * created implicitly. 00163 * If the gate has no object ID, a new object ID for the gate is generated. 00164 * Port are implicitly added, too. 00165 * @param layer_pos The layer position (starting at 0). 00166 * @param o A shared pointer to the object. 00167 */ 00168 00169 void add_gate(int layer_pos, Gate_shptr o); 00170 00171 00172 /** 00173 * Remove all ports from the logic model for a given gate. 00174 * @param o A shared pointer to the object. 00175 */ 00176 00177 void remove_gate_ports(Gate_shptr o); 00178 00179 /** 00180 * Remove a gate from the logic model. 00181 * This effects the module hierarchy, too. 00182 * @param o A shared pointer to the object. 00183 */ 00184 00185 void remove_gate(Gate_shptr o); 00186 00187 /** 00188 * Remove a wire from the logic model. 00189 * @param o A shared pointer to the object. 00190 */ 00191 00192 void remove_wire(Wire_shptr o); 00193 00194 /** 00195 * Remove a via from the logic model. 00196 * @param o A shared pointer to the object. 00197 */ 00198 00199 void remove_via(Via_shptr o); 00200 00201 /** 00202 * Remove an emarker from the logic model. 00203 * @param o A shared pointer to the object. 00204 */ 00205 00206 void remove_emarker(EMarker_shptr o); 00207 00208 /** 00209 * Remove an annotation from the logic model. 00210 * @param o A shared pointer to the object. 00211 */ 00212 00213 void remove_annotation(Annotation_shptr o); 00214 00215 00216 /** 00217 * Remove an onject from the logic model and control if the operation 00218 * should be remembered in delete log. 00219 */ 00220 void remove_object(PlacedLogicModelObject_shptr o, bool add_to_remove_list); 00221 00222 00223 /** 00224 * Create a new layer ID. 00225 */ 00226 layer_id_t get_new_layer_id(); 00227 00228 bool exists_layer_id(layer_collection const& layers, layer_id_t lid) const; 00229 00230 public: 00231 00232 /** 00233 * The constructor for the logic model. 00234 */ 00235 00236 LogicModel(unsigned int width, unsigned int height, unsigned int layers = 0); 00237 00238 00239 /** 00240 * The destructor. 00241 */ 00242 00243 virtual ~LogicModel(); 00244 00245 /** 00246 * Get the width of logic model. 00247 */ 00248 00249 unsigned int get_width() const; 00250 00251 /** 00252 * Get the height of logic model. 00253 */ 00254 00255 unsigned int get_height() const; 00256 00257 00258 /** 00259 * Get a new unique logic model object ID. 00260 */ 00261 00262 object_id_t get_new_object_id(); 00263 00264 00265 /** 00266 * Lookup an object from the logic model for a given object ID. 00267 * @exception CollectionLookupException Is thrown if there is 00268 * no logic model object with that object ID. 00269 * @return Returns a shared pointer to the logic model. 00270 */ 00271 00272 PlacedLogicModelObject_shptr get_object(object_id_t object_id); 00273 00274 00275 /** 00276 * Add a generic logic model object into the logic model. If the layer doesn't 00277 * exists, the layer is created implicitly. 00278 * If the object has no object ID, a new object ID is generated. 00279 * 00280 * This method will set a reference to the layer, where the object is placed, 00281 * into the object, such that each placed object knows, where on which 00282 * layer it is placed. 00283 * 00284 * @param layer_pos The layer position (starting at 0). 00285 * @param o A shared pointer to the object. 00286 * @exception DegateLogicException This exception is thrown, if an object with the 00287 * same object ID is already in the logic model. 00288 */ 00289 00290 void add_object(int layer_pos, PlacedLogicModelObject_shptr o); 00291 00292 void add_object(Layer_shptr layer, PlacedLogicModelObject_shptr o) { 00293 add_object(layer->get_layer_pos(), o); 00294 } 00295 00296 00297 /** 00298 * Remove a generic logic model object from the logic model. 00299 * @param o A shared pointer to the object. 00300 * @todo fix it 00301 */ 00302 00303 void remove_object(PlacedLogicModelObject_shptr o); 00304 00305 /** 00306 * Remove a remote object. 00307 * @exception InvalidObjectIDException This exception is thrown, if remote_id is invalid. 00308 */ 00309 00310 void remove_remote_object(object_id_t remote_id); 00311 00312 00313 /** 00314 * Add a gate template to the gate library and update the logic model. 00315 * All placed gates that already reference this gate template via an ID become updated. 00316 * If the template has no object ID defined, a new object ID for the template is set. 00317 * @exception DegateLogicException Is thrown if there is no gate library. 00318 * @see GateLibrary::add_gate_template 00319 * 00320 * @todo Implement update. 00321 * @todo should call add_object() for the port 00322 */ 00323 00324 void add_gate_template(GateTemplate_shptr tmpl); 00325 00326 /** 00327 * Remove a gate template from the gate library and all placed gates that refer 00328 * to the template. This will destroy gate ports as well. 00329 * 00330 * @see add_gate_template() 00331 * @see GateLibrary::remove_gate_template() 00332 * @see remove_object() 00333 * @exception DegateLogicException Is thrown, if there is no gate library. 00334 * @todo should call remove_object() for the port 00335 * @todo The method name does not express, that the gates are removed as well. 00336 * The method should be named remove_template_and_gates() and remove_gate_template() 00337 * should only unreference and destroy the template. 00338 */ 00339 00340 void remove_gate_template(GateTemplate_shptr tmpl); 00341 00342 /** 00343 * Remove the reference to a certain gate template from all gates. 00344 * This will destroy gate ports as well. 00345 * @exception DegateLogicException Is thrown, if there is no gate library. 00346 * @see Gate::remove_template() 00347 * @todo should call remove_object() for the port 00348 */ 00349 00350 void remove_template_references(GateTemplate_shptr tmpl); 00351 00352 00353 /** 00354 * Remove all gates, that reference a template. The template is preserved. 00355 * It will remove the gate ports as well. 00356 */ 00357 00358 void remove_gates_by_template_type(GateTemplate_shptr tmpl); 00359 00360 /** 00361 * Add a template port to a gate template and make relevant updates in the logic model. 00362 * If you add or remove ports from a gate template, the "real" gates of that type must be updated. 00363 * The corresponding ports must be added to or removed from the "real" gates. 00364 * @todo should call add_object() for the port 00365 */ 00366 00367 void add_template_port_to_gate_template(GateTemplate_shptr gate_template, 00368 GateTemplatePort_shptr template_port); 00369 00370 00371 /** 00372 * Remove a template port from a gate template and make relevant 00373 * updates in the logic model. If you add or remove ports from a 00374 * gate template, the "real" gates of that type must be updated. 00375 * The corresponding ports must be added to or removed from the 00376 * "real" gates. This method does this. 00377 * @todo should call add_object() for the port. 00378 */ 00379 00380 void remove_template_port_from_gate_template(GateTemplate_shptr gate_template, 00381 GateTemplatePort_shptr template_port); 00382 00383 00384 /** 00385 * Add an empty layer. 00386 * @exception DegateLogicException Throws an exception, if you add a layer 00387 * on a position where another layer object is already stored. 00388 * If the layer that should be added already contains logic model objects, this 00389 * exception is thrown, too. 00390 */ 00391 00392 void add_layer(layer_position_t pos, Layer_shptr new_layer); 00393 00394 /** 00395 * Add an empty layer. 00396 * @see add_layer() 00397 */ 00398 00399 void add_layer(layer_position_t pos); 00400 00401 /** 00402 * Get a layer by its posiion index. 00403 */ 00404 00405 Layer_shptr get_layer(layer_position_t pos); 00406 00407 /** 00408 * Get a layer by its ID. 00409 * @exception CollectionLookupException This exception is thrown, if there is no matching layer. 00410 */ 00411 Layer_shptr get_layer_by_id(layer_id_t lid); 00412 00413 00414 /** 00415 * Remove a layer. 00416 * @see remove_layer() 00417 */ 00418 00419 void remove_layer(layer_position_t pos); 00420 00421 /** 00422 * Set layers. 00423 */ 00424 00425 void set_layers(layer_collection layers); 00426 00427 /** 00428 * Remove a layer from the logic model. 00429 * A layer contains logical objects. These object are referred in other parts 00430 * of the logic model. References in other parts must be cleaned as well. 00431 * @todo Implement this. 00432 */ 00433 00434 void remove_layer(Layer_shptr layer); 00435 00436 /** 00437 * Set the current layer you are working on. 00438 */ 00439 00440 void set_current_layer(layer_position_t pos); 00441 00442 /** 00443 * Get the current layer. 00444 */ 00445 00446 Layer_shptr get_current_layer(); 00447 00448 00449 /** 00450 * Get the current gate library for this logic model. 00451 */ 00452 00453 GateLibrary_shptr get_gate_library(); 00454 00455 /** 00456 * Set the gate library. 00457 * @todo: Implement updates on the logic model. 00458 */ 00459 00460 void set_gate_library(GateLibrary_shptr new_gate_lib); 00461 00462 00463 /** 00464 * Add a net to the logic model. 00465 * If the net object has no object ID, a new object ID is set to the net. 00466 * @exception InvalidPointerException Is thrown, if an invalid pointer was 00467 * passed as argument. 00468 */ 00469 00470 void add_net(Net_shptr net); 00471 00472 00473 /** 00474 * Get a net from the logic model. 00475 * @exception CollectionLookupException Is thrown if there is 00476 * no logic model object with that object ID. 00477 */ 00478 00479 Net_shptr get_net(object_id_t net_id); 00480 00481 /** 00482 * Remove a net from the logic model. 00483 * @exception InvalidPointerException Is thrown, if an invalid pointer was 00484 * passed as argument. 00485 * @exception CollectionLookupException Is thrown if there is 00486 * no logic model object with that object ID. 00487 */ 00488 00489 void remove_net(Net_shptr net); 00490 00491 00492 /** 00493 * Get a iterator to iterate over all placeable objects. 00494 */ 00495 00496 object_collection::iterator objects_begin(); 00497 00498 00499 /** 00500 * Get an end iterator for the iteration over all placeable objects. 00501 */ 00502 00503 object_collection::iterator objects_end(); 00504 00505 00506 /** 00507 * Get a iterator to iterate over all gates. 00508 */ 00509 00510 gate_collection::iterator gates_begin(); 00511 00512 00513 /** 00514 * Get an end iterator for the iteration over all gates. 00515 */ 00516 00517 gate_collection::iterator gates_end(); 00518 00519 /** 00520 * Get a iterator to iterate over all vias. 00521 */ 00522 00523 via_collection::iterator vias_begin(); 00524 00525 /** 00526 * Get an end iterator for the iteration over all vias. 00527 */ 00528 00529 via_collection::iterator vias_end(); 00530 00531 /** 00532 * Get a iterator to iterate over all placeable objects. 00533 */ 00534 00535 layer_collection::iterator layers_begin(); 00536 00537 /** 00538 * Get an end iterator for the iteration over all placeable objects. 00539 */ 00540 00541 layer_collection::iterator layers_end(); 00542 00543 00544 /** 00545 * Get a iterator to iterate over all nets. 00546 */ 00547 00548 net_collection::iterator nets_begin(); 00549 00550 00551 /** 00552 * Get an end iterator for the iteration over all nets. 00553 */ 00554 00555 net_collection::iterator nets_end(); 00556 00557 00558 /** 00559 * Get a iterator to iterate over all annotations. 00560 */ 00561 00562 annotation_collection::iterator annotations_begin(); 00563 00564 00565 /** 00566 * Get an end iterator for the iteration over all annotations. 00567 */ 00568 00569 annotation_collection::iterator annotations_end(); 00570 00571 00572 /** 00573 * Print the content of the logic model into an ostream. 00574 */ 00575 void print(std::ostream & os = std::cout); 00576 00577 00578 /** 00579 * Get number of layers. 00580 */ 00581 unsigned int get_num_layers() const; 00582 00583 00584 /** 00585 * Compare ports of a gate with template ports of its associated 00586 * template and update them. 00587 */ 00588 00589 void update_ports(Gate_shptr gate); 00590 00591 /** 00592 * Compare ports of all gates that reference a given template 00593 * and update them. 00594 */ 00595 00596 void update_ports(GateTemplate_shptr gate_template); 00597 00598 00599 /** 00600 * Get the main module. 00601 */ 00602 00603 Module_shptr get_main_module() const; 00604 00605 /** 00606 * Set main module. 00607 */ 00608 void set_main_module(Module_shptr main_module); 00609 00610 /** 00611 * 00612 */ 00613 void reset_removed_remote_objetcs_list(); 00614 00615 std::list<object_id_t> const & get_removed_remote_objetcs_list(); 00616 00617 void update_roid_mapping(object_id_t remote_oid, object_id_t local_oid); 00618 00619 object_id_t get_local_oid_for_roid(object_id_t remote_oid); 00620 00621 00622 /** 00623 * Set default gate port diameter. 00624 */ 00625 void set_default_gate_port_diameter(diameter_t port_diameter); 00626 00627 }; 00628 00629 00630 00631 } 00632 00633 #endif
1.7.4