|
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 __LOOKUPSUBCIRCUIT_H__ 00023 #define __LOOKUPSUBCIRCUIT_H__ 00024 00025 #include <set> 00026 #include <tr1/memory> 00027 #include <string> 00028 00029 #include <degate.h> 00030 #include <LogicModelHelper.h> 00031 00032 #include <boost/foreach.hpp> 00033 00034 namespace degate { 00035 00036 00037 class LookupSubcircuit { 00038 00039 private: 00040 00041 LogicModel_shptr lmodel; 00042 std::list<Gate_shptr> openlist; 00043 00044 protected: 00045 00046 virtual void initialize_openlist() { 00047 // initialize openlist 00048 for(LogicModel::gate_collection::const_iterator iter = lmodel->gates_begin(); 00049 iter != lmodel->gates_end(); ++iter) { 00050 Gate_shptr gate = iter->second; 00051 assert(gate != NULL); 00052 00053 if(is_logic_class(gate, "flipflop") || 00054 is_logic_class(gate, "xor") || 00055 is_logic_class(gate, "xnor")) openlist.push_back(gate); 00056 } 00057 } 00058 00059 public: 00060 00061 00062 /** 00063 * Construct a new net. 00064 */ 00065 00066 LookupSubcircuit(LogicModel_shptr _lmodel) : lmodel(_lmodel) { 00067 } 00068 00069 /** 00070 * Destroy. 00071 */ 00072 virtual ~LookupSubcircuit() {} 00073 00074 virtual void search() { 00075 00076 initialize_openlist(); 00077 00078 00079 Gate_shptr g = openlist.front(); 00080 openlist.pop_front(); 00081 00082 /* 00083 trace_recursive(g); 00084 00085 BOOST_FOREACH(Gate_shptr gate, openlist) { 00086 00087 00088 } 00089 */ 00090 } 00091 00092 void trace_recursive(Gate_shptr start_gate, std::set<Gate_shptr> & closed_list) { 00093 std::cout << "Gate " << start_gate->get_descriptive_identifier() << " connected with: " << std::endl; 00094 00095 std::set<Gate_shptr> other_gates; 00096 00097 BOOST_FOREACH(Gate_shptr g, 00098 filter_connected_gates(start_gate, GateTemplatePort::PORT_TYPE_OUT, "Q", 00099 "flipflop", GateTemplatePort::PORT_TYPE_IN, "D")) 00100 if(closed_list.find(g) != closed_list.end()) { 00101 other_gates.insert(g); 00102 closed_list.insert(g); 00103 } 00104 00105 BOOST_FOREACH(Gate_shptr g, 00106 filter_connected_gates(start_gate, GateTemplatePort::PORT_TYPE_IN, "D", 00107 "flipflop", GateTemplatePort::PORT_TYPE_OUT, "Q")) 00108 if(closed_list.find(g) != closed_list.end()) { 00109 other_gates.insert(g); 00110 closed_list.insert(g); 00111 } 00112 00113 BOOST_FOREACH(Gate_shptr g2, other_gates) { 00114 std::cout << "\tGate " << g2->get_descriptive_identifier() << std::endl; 00115 00116 trace_recursive(g2, closed_list); 00117 } 00118 } 00119 00120 00121 /** 00122 * Check if there is a port on \p gate of type \p src_port_type 00123 * that shares a net with another gate of type \p logic_class. 00124 * 00125 */ 00126 std::set<Gate_shptr> filter_connected_gates(Gate_shptr gate, 00127 GateTemplatePort::PORT_TYPE src_port_type, 00128 std::string const& src_port_name, 00129 std::string const& logic_class, 00130 GateTemplatePort::PORT_TYPE dst_port_type, 00131 std::string const& dst_port_name) const { 00132 00133 std::set<Gate_shptr> connected; 00134 00135 for(Gate::port_iterator iter = gate->ports_begin(); 00136 iter != gate->ports_end(); ++iter) { 00137 00138 GatePort_shptr gport = *iter; 00139 if(get_port_type(gport) == src_port_type) { 00140 Net_shptr net = gport->get_net(); 00141 if(net != NULL) { 00142 BOOST_FOREACH(object_id_t oid, *net) { 00143 if(oid != gport->get_object_id()) { 00144 PlacedLogicModelObject_shptr plmo = lmodel->get_object(oid); 00145 assert(plmo != NULL); 00146 if(GatePort_shptr other_port = std::tr1::dynamic_pointer_cast<GatePort>(plmo)) { 00147 Gate_shptr other_gate = other_port->get_gate(); 00148 00149 if(is_logic_class(other_gate, logic_class) && 00150 get_port_type(other_port) == dst_port_type) { 00151 00152 00153 00154 if((src_port_name.empty() && dst_port_name.empty()) || 00155 (src_port_name.empty() && dst_port_name == get_template_port_name(other_port)) || 00156 (dst_port_name.empty() && src_port_name == get_template_port_name(gport)) || 00157 (src_port_name == get_template_port_name(gport) && 00158 dst_port_name == get_template_port_name(other_port))) 00159 connected.insert(other_gate); 00160 } 00161 } 00162 } 00163 00164 } 00165 } 00166 } 00167 } 00168 return connected; 00169 } 00170 00171 }; 00172 00173 } 00174 00175 #endif
1.7.4