|
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 #include <CodeTemplateGenerator.h> 00023 #include <boost/foreach.hpp> 00024 #include <algorithm> 00025 #include <string> 00026 00027 using namespace degate; 00028 using namespace boost; 00029 00030 CodeTemplateGenerator::CodeTemplateGenerator(std::string const& _entity_name, 00031 std::string const& _description, 00032 std::string const& _logic_class) : 00033 entity_name(_entity_name), 00034 description(_description), 00035 logic_class(_logic_class) { 00036 } 00037 00038 CodeTemplateGenerator::~CodeTemplateGenerator() { 00039 } 00040 00041 00042 void CodeTemplateGenerator::add_port(std::string const& port_name, bool is_inport) { 00043 std::string lc = port_name; 00044 std::transform(lc.begin(), lc.end(), lc.begin(), ::tolower); 00045 port_direction[lc] = is_inport; 00046 } 00047 00048 00049 std::string CodeTemplateGenerator::get_port_name_by_type(CodeTemplateGenerator::PORT_FUNCTION_TYPE t) const { 00050 port_direction_type::const_iterator found; 00051 00052 if(t == CLOCK) { 00053 if((port_direction.end() != (found = port_direction.find("clock"))) || 00054 (port_direction.end() != (found = port_direction.find("clk")))) 00055 return found->first; 00056 } 00057 else if(t == RESET) { 00058 if((port_direction.end() != (found = port_direction.find("/reset"))) || 00059 (port_direction.end() != (found = port_direction.find("!reset"))) || 00060 (port_direction.end() != (found = port_direction.find("reset"))) || 00061 (port_direction.end() != (found = port_direction.find("/rst"))) || 00062 (port_direction.end() != (found = port_direction.find("!rst"))) || 00063 (port_direction.end() != (found = port_direction.find("rst")))) 00064 return found->first; 00065 } 00066 else if(t == ENABLE) { 00067 if((port_direction.end() != (found = port_direction.find("en"))) || 00068 (port_direction.end() != (found = port_direction.find("enable"))) || 00069 (port_direction.end() != (found = port_direction.find("/en"))) || 00070 (port_direction.end() != (found = port_direction.find("!en"))) || 00071 (port_direction.end() != (found = port_direction.find("/enable"))) || 00072 (port_direction.end() != (found = port_direction.find("!enable")))) 00073 return found->first; 00074 } 00075 else if(t == SELECT) { 00076 if((port_direction.end() != (found = port_direction.find("select"))) || 00077 (port_direction.end() != (found = port_direction.find("sel"))) || 00078 (port_direction.end() != (found = port_direction.find("s")))) 00079 return found->first; 00080 } 00081 else if(t == Q) { 00082 if((port_direction.end() != (found = port_direction.find("q"))) ) 00083 return found->first; 00084 } 00085 else if(t == NOT_Q) { 00086 if((port_direction.end() != (found = port_direction.find("!q"))) || 00087 (port_direction.end() != (found = port_direction.find("/q")))) 00088 return found->first; 00089 } 00090 else if(t == D) { 00091 if((port_direction.end() != (found = port_direction.find("d"))) ) 00092 return found->first; 00093 } 00094 00095 return ""; 00096 } 00097 00098 00099 00100 std::string CodeTemplateGenerator::get_first_port_name_not_in(std::vector<std::string> const& ports, 00101 std::vector<std::string> const& blacklist) const { 00102 00103 typedef std::vector<std::string>::const_iterator iter; 00104 00105 BOOST_FOREACH(std::string const& p_name, ports) { 00106 iter i = std::find(blacklist.begin(), blacklist.end(), p_name); 00107 if(i == blacklist.end()) return p_name; 00108 } 00109 00110 return ""; 00111 } 00112 00113 std::string CodeTemplateGenerator::get_first_port_name_not_in(std::vector<std::string> const& ports, 00114 std::string const& blacklist_item) const { 00115 std::vector<std::string> v(1); 00116 v[0] = blacklist_item; 00117 return get_first_port_name_not_in(ports, v); 00118 } 00119 00120 std::vector<std::string> CodeTemplateGenerator::get_inports() const { 00121 std::vector<std::string> ports; 00122 00123 BOOST_FOREACH(port_direction_type::value_type const& p, port_direction) 00124 if(p.second == true) ports.push_back(p.first); 00125 00126 std::sort(ports.begin(), ports.end()); 00127 return ports; 00128 } 00129 00130 std::vector<std::string> CodeTemplateGenerator::get_outports() const { 00131 std::vector<std::string> ports; 00132 00133 BOOST_FOREACH(port_direction_type::value_type const& p, port_direction) 00134 if(p.second == false) ports.push_back(p.first); 00135 00136 std::sort(ports.begin(), ports.end()); 00137 return ports; 00138 } 00139 00140 std::vector<std::string> CodeTemplateGenerator::get_ports() const { 00141 std::vector<std::string> ports; 00142 00143 BOOST_FOREACH(port_direction_type::value_type const& p, port_direction) 00144 ports.push_back(p.first); 00145 00146 std::sort(ports.begin(), ports.end()); 00147 return ports; 00148 }
1.7.4