|
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 <degate.h> 00023 #include <GateTemplate.h> 00024 00025 using namespace degate; 00026 00027 void GateTemplate::increment_reference_counter() { 00028 reference_counter++; 00029 } 00030 00031 void GateTemplate::decrement_reference_counter() { 00032 reference_counter--; 00033 } 00034 00035 00036 GateTemplate::GateTemplate(int _min_x, int _max_x, int _min_y, int _max_y) : 00037 bounding_box(_min_x, _max_x, _min_y, _max_y), reference_counter(0) { 00038 } 00039 00040 GateTemplate::GateTemplate(unsigned int width, unsigned int height) : 00041 bounding_box(0, width, 0, height), reference_counter(0) { 00042 } 00043 00044 GateTemplate::GateTemplate() : 00045 bounding_box(0, 0, 0, 0), reference_counter(0) { 00046 } 00047 00048 00049 GateTemplate::~GateTemplate() { 00050 } 00051 00052 unsigned int GateTemplate::get_width() const { 00053 return bounding_box.get_width(); 00054 } 00055 00056 unsigned int GateTemplate::get_height() const { 00057 return bounding_box.get_height(); 00058 } 00059 00060 void GateTemplate::set_width(unsigned int width) { 00061 bounding_box.set_max_x(bounding_box.get_min_x() + width); 00062 } 00063 00064 void GateTemplate::set_height(unsigned int height) { 00065 bounding_box.set_max_y(bounding_box.get_min_y() + height); 00066 } 00067 00068 BoundingBox const & GateTemplate::get_bounding_box() const { 00069 return bounding_box; 00070 } 00071 00072 00073 void GateTemplate::set_image(Layer::LAYER_TYPE layer_type, GateTemplateImage_shptr img) { 00074 if(img == NULL) throw InvalidPointerException("Invalid pointer for image."); 00075 debug(TM, "set image for template."); 00076 images[layer_type] = img; 00077 } 00078 00079 00080 GateTemplateImage_shptr GateTemplate::get_image(Layer::LAYER_TYPE layer_type) { 00081 image_collection::iterator found = images.find(layer_type); 00082 if(found == images.end()) 00083 throw CollectionLookupException("Can't find reference image."); 00084 else return (*found).second; 00085 } 00086 00087 bool GateTemplate::has_image(Layer::LAYER_TYPE layer_type) const { 00088 return images.find(layer_type) != images.end(); 00089 } 00090 00091 void GateTemplate::add_template_port(GateTemplatePort_shptr template_port) { 00092 if(!template_port->has_valid_object_id()) 00093 throw InvalidObjectIDException("Error in GateTemplate::add_template_port(). " 00094 "The object ID is invalid."); 00095 ports.insert(template_port); 00096 } 00097 00098 00099 bool GateTemplate::remove_template_port(GateTemplatePort_shptr template_port) { 00100 assert(template_port->has_valid_object_id()); 00101 return ports.erase(template_port) > 0; 00102 } 00103 00104 00105 bool GateTemplate::remove_template_port(object_id_t object_id) { 00106 if(object_id == 0) 00107 throw InvalidObjectIDException("Error in GateTemplate::remove_template_port(). " 00108 "The object ID is invalid."); 00109 00110 for(port_iterator iter = ports.begin(); iter != ports.end(); ++iter) { 00111 if((*iter)->get_object_id() == object_id) { 00112 ports.erase(iter); 00113 return true; 00114 } 00115 } 00116 assert(1 == 0); // should not reach this line 00117 return false; 00118 } 00119 00120 00121 00122 GateTemplatePort_shptr GateTemplate::get_template_port(object_id_t object_id) { 00123 00124 if(object_id == 0) 00125 throw InvalidObjectIDException("Error in GateTemplate::get_template_port(). " 00126 "The object ID is invalid."); 00127 00128 for(port_iterator iter = ports.begin(); iter != ports.end(); ++iter) { 00129 if((*iter)->get_object_id() == object_id) { 00130 return *iter; 00131 } 00132 } 00133 throw CollectionLookupException("The gate template has no template port with that ID."); 00134 } 00135 00136 bool GateTemplate::has_template_port(object_id_t object_id) const { 00137 if(object_id == 0) 00138 throw InvalidObjectIDException("Error in GateTemplate::get_template_port(). " 00139 "The object ID is invalid."); 00140 00141 for(port_iterator iter = ports.begin(); iter != ports.end(); ++iter) { 00142 if((*iter)->get_object_id() == object_id) { 00143 return true; 00144 } 00145 } 00146 return false; 00147 } 00148 00149 GateTemplate::port_iterator GateTemplate::ports_begin() { 00150 return ports.begin(); 00151 } 00152 00153 GateTemplate::port_iterator GateTemplate::ports_end() { 00154 return ports.end(); 00155 } 00156 00157 GateTemplate::image_iterator GateTemplate::images_begin() { 00158 return images.begin(); 00159 } 00160 00161 GateTemplate::image_iterator GateTemplate::images_end() { 00162 return images.end(); 00163 } 00164 00165 00166 00167 unsigned int GateTemplate::get_reference_counter() const { 00168 return reference_counter; 00169 } 00170 00171 00172 void GateTemplate::set_implementation(IMPLEMENTATION_TYPE impl_type, std::string const& code) { 00173 implementations[impl_type] = code; 00174 } 00175 00176 std::string GateTemplate::get_implementation(IMPLEMENTATION_TYPE impl_type) const { 00177 00178 implementation_collection::const_iterator found = implementations.find(impl_type); 00179 if(found == implementations.end()) { 00180 throw CollectionLookupException("There is no implementation for the requested type"); 00181 } 00182 else 00183 return found->second; 00184 } 00185 00186 GateTemplate::implementation_iter GateTemplate::implementations_begin() { 00187 return implementations.begin(); 00188 } 00189 00190 GateTemplate::implementation_iter GateTemplate::implementations_end() { 00191 return implementations.end(); 00192 } 00193 00194 void GateTemplate::print(std::ostream & os) { 00195 os 00196 << "Gate template name : " << get_name() << std::endl 00197 << "Gate template descr. : " << get_description() << std::endl 00198 << "Gate object ID : " << get_object_id() << std::endl 00199 << std::endl 00200 ; 00201 00202 for(image_iterator img_i = images_begin(); img_i != images_end(); ++img_i) { 00203 Layer::LAYER_TYPE layer_type = (*img_i).first; 00204 00205 os 00206 << "Image for layer of type : " << Layer::get_layer_type_as_string(layer_type) << std::endl 00207 << std::endl 00208 ; 00209 } 00210 00211 } 00212 00213 00214 unsigned int GateTemplate::get_number_of_ports() const { 00215 return ports.size(); 00216 } 00217 00218 00219 00220 std::string GateTemplate::get_impl_type_as_string(IMPLEMENTATION_TYPE impl_type) { 00221 switch(impl_type) { 00222 case TEXT: 00223 return std::string("text"); 00224 case VHDL: 00225 return std::string("vhdl"); 00226 case VHDL_TESTBENCH: 00227 return std::string("vhdl-testbench"); 00228 case VERILOG: 00229 return std::string("verilog"); 00230 case VERILOG_TESTBENCH: 00231 return std::string("verilog-testbench"); 00232 default: 00233 return std::string("undefined"); 00234 } 00235 } 00236 00237 GateTemplate::IMPLEMENTATION_TYPE GateTemplate::get_impl_type_from_string(std::string const& impl_type_str) { 00238 00239 if(impl_type_str == "text") return TEXT; 00240 else if(impl_type_str == "vhdl") return VHDL; 00241 else if(impl_type_str == "vhdl-testbench") return VHDL_TESTBENCH; 00242 else if(impl_type_str == "verilog") return VERILOG; 00243 else if(impl_type_str == "verilog-testbench") return VERILOG_TESTBENCH; 00244 else if(impl_type_str == "undefined" || 00245 impl_type_str == "") return UNDEFINED; 00246 else { 00247 boost::format f("Can't parse implementation type '%1%'."); 00248 f % impl_type_str; 00249 throw DegateRuntimeException(f.str()); 00250 } 00251 } 00252 00253 void GateTemplate::set_logic_class(std::string const& logic_class) { 00254 this->logic_class = logic_class; 00255 } 00256 00257 00258 std::string GateTemplate::get_logic_class() const { 00259 return logic_class; 00260 }
1.7.4