degate 0.1.1
GateTemplate.h
Go to the documentation of this file.
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 __GATETEMPLATE_H__
00023 #define __GATETEMPLATE_H__
00024 
00025 #include <degate.h>
00026 
00027 #include <Layer.h>
00028 #include <Image.h>
00029 #include <GateTemplatePort.h>
00030 
00031 #include <set>
00032 #include <tr1/memory>
00033 #include <map>
00034 
00035 namespace degate {
00036 
00037   /**
00038    * A gate template is a container for common properties, that physically placed gates of that type share.
00039    */
00040 
00041   class GateTemplate : public LogicModelObjectBase, public ColoredObject {
00042 
00043     friend class Gate;
00044 
00045   public:
00046 
00047     /**
00048      * Implementation types for a template.
00049      */
00050     enum IMPLEMENTATION_TYPE {
00051       UNDEFINED = 0,
00052       TEXT = 1,
00053       VHDL = 2,
00054       VHDL_TESTBENCH = 3,
00055       VERILOG = 4,
00056       VERILOG_TESTBENCH = 5
00057     };
00058 
00059     typedef std::map<IMPLEMENTATION_TYPE, std::string /* code */> implementation_collection;
00060     typedef implementation_collection::iterator implementation_iter;
00061 
00062     typedef std::map<Layer::LAYER_TYPE, GateTemplateImage_shptr> image_collection;
00063     typedef image_collection::iterator image_iterator;
00064 
00065   private:
00066 
00067     BoundingBox bounding_box;
00068     unsigned int reference_counter;
00069 
00070     std::set<GateTemplatePort_shptr> ports;
00071 
00072     implementation_collection implementations;
00073     image_collection images;
00074 
00075     std::string logic_class; // e.g. nand, xor, flipflop, buffer, oai
00076 
00077   protected:
00078 
00079     /**
00080      * Increment the reference counter.
00081      */
00082 
00083     virtual void increment_reference_counter();
00084 
00085     /**
00086      * Decrement the reference counter.
00087      */
00088 
00089     virtual void decrement_reference_counter();
00090 
00091 
00092   public:
00093 
00094     typedef std::set< GateTemplatePort_shptr >::iterator port_iterator;
00095 
00096     /**
00097      * The constructor to set up a new gate template.
00098      * @deprecated A gate template should not rely on positions. Instead it should
00099      *   have a the region as a copy.
00100      */
00101 
00102     GateTemplate(unsigned int width, unsigned int height);
00103 
00104 
00105     /**
00106      * The constructor to set up a new gate template.
00107      * @deprecated A gate template should not rely on positions. Instead it should
00108      *   have a the region as a copy.
00109      */
00110 
00111     GateTemplate(int _min_x, int _max_x, int _min_y, int _max_y);
00112 
00113     /**
00114      * Default constructor.
00115      */
00116 
00117     GateTemplate();
00118 
00119     /**
00120      * The destructor.
00121      */
00122 
00123     virtual ~GateTemplate();
00124 
00125     /**
00126      * Get the width of a gate template.
00127      */
00128 
00129     virtual unsigned int get_width() const;
00130 
00131     /**
00132      * Get the height of a gate template.
00133      */
00134 
00135     virtual unsigned int get_height() const;
00136 
00137 
00138     /**
00139      * Set the width of a gate template.
00140      * It does not adjust dimensions of gates that reference this template.
00141      */
00142 
00143     virtual void set_width(unsigned int width);
00144 
00145     /**
00146      * Set the height of a gate template.
00147      * It does not adjust dimensions of gates that reference this template.
00148      */
00149 
00150     virtual void set_height(unsigned int);
00151 
00152     /**
00153      * Get the bounding box of the template.
00154      * @deprecated
00155      */
00156 
00157     virtual BoundingBox const & get_bounding_box() const;
00158 
00159     /**
00160      * Set a reference image for the template.
00161      * You can store reference images for different layers, that is for
00162      * the transistor layer, for the logic layer and for a metal layer.
00163      * The images must have equal image dimensions. It is not checked here.
00164      *
00165      * @todo: Here we might need a hook for storing different image types,
00166      *   e.g. a template image that is an average image or sth. like that.
00167      * @exception InvalidPointerException Throws this excpetion, if \p img is NULL.
00168      */
00169 
00170     virtual void set_image(Layer::LAYER_TYPE layer_type, GateTemplateImage_shptr img);
00171 
00172     /**
00173      * Get a reference image for the template.
00174      * @see set_image()
00175      * @exception CollectionLookupException Throws this exception, if there is no image.
00176      */
00177 
00178     virtual GateTemplateImage_shptr get_image(Layer::LAYER_TYPE layer_type);
00179 
00180 
00181     /**
00182      * Check if there is a reference image for a layer type.
00183      */
00184 
00185     virtual bool has_image(Layer::LAYER_TYPE layer_type) const;
00186 
00187     /**
00188      * Add a template port to a gate template.
00189      * This is an isolated function. The port is just added to the gate template.
00190      * Nothing else. Adding a port to a template requires some updates in the logic
00191      * model. Therefore you should prefer the corresponding method from the LogicModel
00192      * class.
00193      * @exception InvalidObjectIDException This exception is thrown if the template port
00194      *   has no valid object ID.
00195      * @todo In order to make the API hard to misuse, this method might be made private.
00196      * @see LogicModel::add_template_port
00197      */
00198 
00199     virtual void add_template_port(GateTemplatePort_shptr template_port);
00200 
00201     /**
00202      * Remove a port from a gate template.
00203      * This is an isolated function. The port is just removed from the gate template.
00204      * Nothing else. Removing a port from a template requires some updates in the logic
00205      * model. Therefore you should prefer the corresponding method from the LogicModel
00206      * class.
00207      * @todo In order to make the API hard to misuse, this method might be made private.
00208      * @see LogicModel::remove_template_port
00209      */
00210 
00211     virtual bool remove_template_port(GateTemplatePort_shptr template_port);
00212 
00213     /**
00214      * Remove a port from a gate template.
00215      * @exception InvalidObjectIDException This exception is thrown if the template port
00216      *   has no valid object ID.
00217      * @see remove_template_port(GateTemplatePort_shptr template_port)
00218      */
00219 
00220     virtual bool remove_template_port(object_id_t object_id);
00221 
00222     /**
00223      * Get a template port.
00224      * @exception InvalidObjectIDException This exception is thrown if the
00225      *   object ID is invalid.
00226      * @exception CollectionLookupException This exception is thrown if a
00227      *   template port with object ID \p object_id was not found.
00228      */
00229 
00230     virtual GateTemplatePort_shptr get_template_port(object_id_t object_id);
00231 
00232 
00233     /**
00234      * Check if a template has a specific template port.
00235      * @exception InvalidObjectIDException This exception is thrown if the
00236      *   object ID is invalid.
00237      */
00238 
00239     virtual bool has_template_port(object_id_t object_id) const;
00240 
00241     /**
00242      * Get an iterator.
00243      */
00244 
00245     virtual port_iterator ports_begin();
00246 
00247 
00248     /**
00249      * Get end marker for the iteration over ports.
00250      */
00251 
00252     virtual port_iterator ports_end();
00253 
00254 
00255     /**
00256      * Get an iterator to iterate over images.
00257      */
00258 
00259     virtual image_iterator images_begin();
00260 
00261     /**
00262      * Get end marker for the iteration over images.
00263      */
00264 
00265     virtual image_iterator images_end();
00266 
00267     /**
00268      * Get the reference counter.
00269      * @return Returns how many gates reference this gate template.
00270      */
00271 
00272     virtual unsigned int get_reference_counter() const;
00273 
00274 
00275     /**
00276      * Get an iterator to iterate over implementations.
00277      */
00278 
00279     virtual implementation_iter implementations_begin();
00280 
00281     /**
00282      * Get an end marker for the iteration.
00283      */
00284 
00285     virtual implementation_iter implementations_end();
00286 
00287 
00288     /**
00289      * Set VHDL/Verilog implementation for the gate template.
00290      * @param impl_type Set VHDL or Verilog.
00291      * @param code The implementation.
00292      */
00293 
00294     virtual void set_implementation(IMPLEMENTATION_TYPE impl_type, std::string const& code);
00295 
00296     /**
00297      * Get code for an implementation type.
00298      * @exception CollectionLookupException Throws an exception, if there is no code for the requested type.
00299      */
00300 
00301     std::string get_implementation(IMPLEMENTATION_TYPE impl_type) const;
00302 
00303     /**
00304      * Print gate template's meta information to an output stream.
00305      */
00306 
00307     virtual void print(std::ostream & os);
00308 
00309 
00310     /**
00311      * Get number of defined ports.
00312      */
00313 
00314     virtual unsigned int get_number_of_ports() const;
00315 
00316 
00317     /**
00318      * Set logic class for a standard cell.
00319      *
00320      * There are two reasons for having this kind of tagging. First we
00321      * want to render dedicated electronic symbols for standard gates, e.g.
00322      * nands, xors and flipflops, independed of the standard cells name.
00323      * Second we want to search for common building blocks, e.g.
00324      * linear feedback shift registers, that we basically describe as
00325      * a set of connected flipflops with some xor gates between them,
00326      * independend of the gate's naming.
00327      */
00328 
00329     virtual void set_logic_class(std::string const& logic_class);
00330 
00331     /**
00332      * Get logic class for a standard cell.
00333      */
00334 
00335     virtual std::string get_logic_class() const;
00336 
00337 
00338     /**
00339      * Convert an implementation-type constant to a printable string.
00340      */
00341     static std::string get_impl_type_as_string(IMPLEMENTATION_TYPE impl_type);
00342 
00343     /**
00344      * Convert an implementation type string to a correspondig constant.
00345      * @exception DegateRuntimeException Throws this exception, if the string cannot be parsed.
00346      */
00347     static IMPLEMENTATION_TYPE get_impl_type_from_string(std::string const& impl_type_str);
00348 
00349   };
00350 
00351 
00352 
00353 }
00354 
00355 #endif