degate  0.1.2
CodeTemplateGenerator.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 __CODETEMPLATEGENERATOR_H__
00023 #define __CODETEMPLATEGENERATOR_H__
00024 
00025 #include <memory>
00026 #include <map>
00027 #include <vector>
00028 #include <string>
00029 
00030 #include <boost/foreach.hpp>
00031 
00032 namespace degate {
00033 
00034   /**
00035    * Base class for code generators.
00036    */
00037   class CodeTemplateGenerator {
00038   public:
00039     typedef std::map<std::string, bool> port_direction_type;
00040 
00041     /**
00042      *
00043      */
00044     enum PORT_FUNCTION_TYPE {
00045       CLOCK,
00046       RESET,
00047       ENABLE,
00048       Q,
00049       NOT_Q,
00050       D,
00051       SELECT
00052     };
00053     
00054   protected:
00055     std::string entity_name, description, logic_class;
00056     port_direction_type port_direction;
00057 
00058     /**
00059      * Get a list of input ports.
00060      */
00061     virtual std::vector<std::string> get_inports() const;
00062 
00063     /**
00064      * Get a list of output ports.
00065      */
00066     virtual std::vector<std::string> get_outports() const;
00067 
00068     /**
00069      * Get a list of ports.
00070      */
00071     virtual std::vector<std::string> get_ports() const;
00072 
00073 
00074     /**
00075      * Get the name of the port, that is most likely of the type \p t.
00076      * @return Returns an empty string, if no port name matches.
00077      */
00078     std::string get_port_name_by_type(PORT_FUNCTION_TYPE t) const;
00079 
00080 
00081     /**
00082      * Get the first port name from \p ports that is not contained in \p blacklist.
00083      * @return Returns an empty string, if no port name matches.
00084      */
00085     std::string get_first_port_name_not_in(std::vector<std::string> const& ports,
00086                                            std::vector<std::string> const& blacklist) const;
00087 
00088     /**
00089      * Get the first port name from \p ports that is not equal to \p blacklist_item.
00090      * @return Returns an empty string, if no port name matches.
00091      */
00092     std::string get_first_port_name_not_in(std::vector<std::string> const& ports,
00093                                            std::string const& blacklist_item) const;  
00094 
00095 
00096 
00097     virtual std::string generate_identifier(std::string const& name, std::string const& prefix = "") const = 0;
00098 
00099     template<typename Container>
00100     Container generate_identifier(Container const& c, std::string const& prefix = "") const {
00101       Container new_c;
00102       BOOST_FOREACH(typename Container::value_type const& s, c) {
00103         new_c.push_back(generate_identifier(s, prefix));
00104       }
00105       return new_c;
00106     }
00107 
00108 
00109   public:
00110 
00111     CodeTemplateGenerator(std::string const& _entity_name,
00112                           std::string const& _description,
00113                           std::string const& _logic_class);
00114 
00115     virtual ~CodeTemplateGenerator();
00116 
00117     virtual void add_port(std::string const& port_name, bool is_inport);
00118 
00119     virtual std::string generate() const = 0;
00120   };
00121 
00122   typedef std::shared_ptr<CodeTemplateGenerator> CodeTemplateGenerator_shptr;
00123 }
00124 
00125 #endif