110448Snilay@cs.wisc.edu/* Copyright (c) 2012 Massachusetts Institute of Technology 210448Snilay@cs.wisc.edu * 310448Snilay@cs.wisc.edu * Permission is hereby granted, free of charge, to any person obtaining a copy 410448Snilay@cs.wisc.edu * of this software and associated documentation files (the "Software"), to deal 510448Snilay@cs.wisc.edu * in the Software without restriction, including without limitation the rights 610448Snilay@cs.wisc.edu * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 710448Snilay@cs.wisc.edu * copies of the Software, and to permit persons to whom the Software is 810448Snilay@cs.wisc.edu * furnished to do so, subject to the following conditions: 910448Snilay@cs.wisc.edu * 1010448Snilay@cs.wisc.edu * The above copyright notice and this permission notice shall be included in 1110448Snilay@cs.wisc.edu * all copies or substantial portions of the Software. 1210448Snilay@cs.wisc.edu * 1310448Snilay@cs.wisc.edu * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1410448Snilay@cs.wisc.edu * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1510448Snilay@cs.wisc.edu * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1610448Snilay@cs.wisc.edu * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 1710448Snilay@cs.wisc.edu * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 1810448Snilay@cs.wisc.edu * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 1910448Snilay@cs.wisc.edu * THE SOFTWARE. 2010448Snilay@cs.wisc.edu */ 2110448Snilay@cs.wisc.edu 2210447Snilay@cs.wisc.edu#ifndef __DSENT_MODEL_MODEL_H__ 2310447Snilay@cs.wisc.edu#define __DSENT_MODEL_MODEL_H__ 2410447Snilay@cs.wisc.edu 2510447Snilay@cs.wisc.edu#include <vector> 2610447Snilay@cs.wisc.edu 2710447Snilay@cs.wisc.edu#include "util/CommonType.h" 2810447Snilay@cs.wisc.edu 2910447Snilay@cs.wisc.edunamespace DSENT 3010447Snilay@cs.wisc.edu{ 3110447Snilay@cs.wisc.edu using std::vector; 3210447Snilay@cs.wisc.edu 3310447Snilay@cs.wisc.edu class TechModel; 3410447Snilay@cs.wisc.edu class Result; 3510447Snilay@cs.wisc.edu 3610447Snilay@cs.wisc.edu // Base class for all the models 3710447Snilay@cs.wisc.edu class Model 3810447Snilay@cs.wisc.edu { 3910447Snilay@cs.wisc.edu protected: 4010447Snilay@cs.wisc.edu class SubModel 4110447Snilay@cs.wisc.edu { 4210447Snilay@cs.wisc.edu public: 4310447Snilay@cs.wisc.edu SubModel(Model* model_, double num_models_); 4410447Snilay@cs.wisc.edu ~SubModel(); 4510447Snilay@cs.wisc.edu 4610447Snilay@cs.wisc.edu public: 4710447Snilay@cs.wisc.edu Model* getModel(); 4810447Snilay@cs.wisc.edu const Model* getModel() const; 4910447Snilay@cs.wisc.edu double getNumModels() const; 5010447Snilay@cs.wisc.edu 5110447Snilay@cs.wisc.edu SubModel* clone() const; 5210447Snilay@cs.wisc.edu 5310447Snilay@cs.wisc.edu protected: 5410447Snilay@cs.wisc.edu SubModel(const SubModel& sub_model_); 5510447Snilay@cs.wisc.edu 5610447Snilay@cs.wisc.edu private: 5710447Snilay@cs.wisc.edu // Pointer to the actual model instance 5810447Snilay@cs.wisc.edu Model* m_model_; 5910447Snilay@cs.wisc.edu // Number of models are added 6010447Snilay@cs.wisc.edu double m_num_models_; 6110447Snilay@cs.wisc.edu }; 6210447Snilay@cs.wisc.edu 6310447Snilay@cs.wisc.edu public: 6410447Snilay@cs.wisc.edu // Model Constants 6510447Snilay@cs.wisc.edu static const char TYPE_SEPARATOR[]; 6610447Snilay@cs.wisc.edu static const char HIERARCHY_SEPARATOR[]; 6710447Snilay@cs.wisc.edu static const char SUBFIELD_SEPARATOR[]; 6810447Snilay@cs.wisc.edu static const char DETAIL_SEPARATOR[]; 6910447Snilay@cs.wisc.edu 7010447Snilay@cs.wisc.edu public: 7110447Snilay@cs.wisc.edu Model(const String& instance_name_, const TechModel* tech_model_); 7210447Snilay@cs.wisc.edu virtual ~Model(); 7310447Snilay@cs.wisc.edu 7410447Snilay@cs.wisc.edu public: 7510447Snilay@cs.wisc.edu // Set the name of this instance 7610447Snilay@cs.wisc.edu void setInstanceName(const String& instance_name_); 7710447Snilay@cs.wisc.edu // Get the name of this instance 7810447Snilay@cs.wisc.edu const String& getInstanceName() const; 7910447Snilay@cs.wisc.edu 8010447Snilay@cs.wisc.edu // Set if the model is the top model 8110447Snilay@cs.wisc.edu void setIsTopModel(bool is_top_model_); 8210447Snilay@cs.wisc.edu bool getIsTopModel() const; 8310447Snilay@cs.wisc.edu 8410447Snilay@cs.wisc.edu // Add a parameter name (with and without default) 8510447Snilay@cs.wisc.edu void addParameterName(const String& parameter_name_); 8610447Snilay@cs.wisc.edu void addParameterName(const String& parameter_name_, const String& parameter_default_); 8710447Snilay@cs.wisc.edu const vector<String>* getParameterNames() const; 8810447Snilay@cs.wisc.edu 8910447Snilay@cs.wisc.edu // Add a property name 9010447Snilay@cs.wisc.edu void addPropertyName(const String& property_name_); 9110447Snilay@cs.wisc.edu void addPropertyName(const String& property_name_, const String& property_default_); 9210447Snilay@cs.wisc.edu const vector<String>* getPropertyNames() const; 9310447Snilay@cs.wisc.edu 9410447Snilay@cs.wisc.edu // Check if all parameters needed exist in the m_parameters_ 9510447Snilay@cs.wisc.edu void checkParameters() const; 9610447Snilay@cs.wisc.edu // Check if all properties needed exist in the m_properties_ 9710447Snilay@cs.wisc.edu void checkProperties() const; 9810447Snilay@cs.wisc.edu 9910447Snilay@cs.wisc.edu // Get the pointer to parameters 10010447Snilay@cs.wisc.edu const ParameterMap* getParameters() const; 10110447Snilay@cs.wisc.edu const String getParameter(const String& parameter_name_) const; 10210447Snilay@cs.wisc.edu void setParameter(const String& parameter_name_, const String& parameter_value_); 10310447Snilay@cs.wisc.edu 10410447Snilay@cs.wisc.edu // Get the pointer to properties 10510447Snilay@cs.wisc.edu const PropertyMap* getProperties() const; 10610447Snilay@cs.wisc.edu const String getProperty(const String& property_name_) const; 10710447Snilay@cs.wisc.edu void setProperty(const String& property_name_, const String& property_value_); 10810447Snilay@cs.wisc.edu 10910447Snilay@cs.wisc.edu // Get the pointer to generated properties 11010447Snilay@cs.wisc.edu PropertyMap* getGenProperties(); 11110447Snilay@cs.wisc.edu const PropertyMap* getGenProperties() const; 11210447Snilay@cs.wisc.edu 11310447Snilay@cs.wisc.edu // Add an instance to this model. num_sub_instances_ specifies the 11410447Snilay@cs.wisc.edu // number of the same instance is added. 11510447Snilay@cs.wisc.edu void addSubInstances(Model* sub_instance_, double num_sub_instances_); 11610447Snilay@cs.wisc.edu // Get an instance by name. 11710447Snilay@cs.wisc.edu Model* getSubInstance(const String& sub_instance_name_); 11810447Snilay@cs.wisc.edu const Model* getSubInstance(const String& sub_instance_name_) const; 11910447Snilay@cs.wisc.edu // Check if an instance exists 12010447Snilay@cs.wisc.edu bool hasSubInstance(const String& sub_instance_name_) const; 12110447Snilay@cs.wisc.edu 12210447Snilay@cs.wisc.edu // Add a new area 12310447Snilay@cs.wisc.edu void addAreaResult(Result* area_); 12410447Snilay@cs.wisc.edu // Get the pointer to an area. The area is specified by name. 12510447Snilay@cs.wisc.edu Result* getAreaResult(const String& area_name_); 12610447Snilay@cs.wisc.edu const Result* getAreaResult(const String& area_name_) const; 12710447Snilay@cs.wisc.edu // Check if an area exists 12810447Snilay@cs.wisc.edu bool hasAreaResult(const String& area_name_) const; 12910447Snilay@cs.wisc.edu 13010447Snilay@cs.wisc.edu // Add a new ndd_power 13110447Snilay@cs.wisc.edu void addNddPowerResult(Result* ndd_power_); 13210447Snilay@cs.wisc.edu // Get the pointer to an ndd_power. The ndd_power is specified by name. 13310447Snilay@cs.wisc.edu Result* getNddPowerResult(const String& ndd_power_name_); 13410447Snilay@cs.wisc.edu const Result* getNddPowerResult(const String& ndd_power_name_) const; 13510447Snilay@cs.wisc.edu // Check if a ndd_power exists 13610447Snilay@cs.wisc.edu bool hasNddPowerResult(const String& ndd_power_name_) const; 13710447Snilay@cs.wisc.edu 13810447Snilay@cs.wisc.edu // Add a new event 13910447Snilay@cs.wisc.edu void addEventResult(Result* event_); 14010447Snilay@cs.wisc.edu // Get the pointer to an event. The event is specified by name. 14110447Snilay@cs.wisc.edu Result* getEventResult(const String& event_name_); 14210447Snilay@cs.wisc.edu const Result* getEventResult(const String& event_name_) const; 14310447Snilay@cs.wisc.edu // Check if an event exists 14410447Snilay@cs.wisc.edu bool hasEventResult(const String& event_name_) const; 14510447Snilay@cs.wisc.edu 14610447Snilay@cs.wisc.edu // Get the pointer to the TechModel. 14710447Snilay@cs.wisc.edu const TechModel* getTechModel() const; 14810447Snilay@cs.wisc.edu 14910447Snilay@cs.wisc.edu // Clone and return a new instance 15010447Snilay@cs.wisc.edu virtual Model* clone() const; 15110447Snilay@cs.wisc.edu 15210447Snilay@cs.wisc.edu // Checks to make sure all required parameters are present, makes sure that the model 15310447Snilay@cs.wisc.edu // has not been constructed yet, and calls constructModel. This function is not meant 15410447Snilay@cs.wisc.edu // to be overwritten by child classes; constructModel should be overwritten instead 15510447Snilay@cs.wisc.edu void construct(); 15610447Snilay@cs.wisc.edu // Update checks whether the model needs updating, whether all properties have been specified, 15710447Snilay@cs.wisc.edu // and calls updateModel if update is necessary. This function is not meant 15810447Snilay@cs.wisc.edu // to be overwritten by child classes; updateModel should be overwritten instead 15910447Snilay@cs.wisc.edu void update(); 16010447Snilay@cs.wisc.edu // Evaluate checks whether the model needs to be evaluated. Note that this function is 16110447Snilay@cs.wisc.edu // not meant to be overwritten by child classes; evaluateModel should be overwritten 16210447Snilay@cs.wisc.edu // instead 16310447Snilay@cs.wisc.edu void evaluate(); 16410447Snilay@cs.wisc.edu void use(const String& event_name_); 16510447Snilay@cs.wisc.edu void use(); 16610447Snilay@cs.wisc.edu 16710447Snilay@cs.wisc.edu // Resolve query hierarchy and process query 16810447Snilay@cs.wisc.edu const void* parseQuery(const String& query_type_, const String& query_hier_, const String& query_sub_field_); 16910447Snilay@cs.wisc.edu // Process the query 17010447Snilay@cs.wisc.edu virtual const void* processQuery(const String& query_type_, const String& query_sub_field_); 17110447Snilay@cs.wisc.edu 17210447Snilay@cs.wisc.edu // Print hierarchically 17310447Snilay@cs.wisc.edu void printHierarchy(const String& query_type_, const String& query_sub_field_, const String& prepend_str_, int detail_level_, ostream& ost_) const; 17410447Snilay@cs.wisc.edu void printInstHierarchy(const String& prepend_str_, int detail_level_, ostream& ost_) const; 17510447Snilay@cs.wisc.edu 17610447Snilay@cs.wisc.edu protected: 17710447Snilay@cs.wisc.edu // Query area 17810447Snilay@cs.wisc.edu const Result* queryArea(const String& area_name_) const; 17910447Snilay@cs.wisc.edu // Query non-data-dependent power 18010447Snilay@cs.wisc.edu const Result* queryNddPower(const String& ndd_power_name_); 18110447Snilay@cs.wisc.edu // Query event energy cost 18210447Snilay@cs.wisc.edu const Result* queryEventEnergyCost(const String& event_name_); 18310447Snilay@cs.wisc.edu 18410447Snilay@cs.wisc.edu // Constructs the model 18510447Snilay@cs.wisc.edu virtual void constructModel() = 0; 18610447Snilay@cs.wisc.edu // Updates timing related information of the model 18710447Snilay@cs.wisc.edu virtual void updateModel(); 18810447Snilay@cs.wisc.edu // Evaluate non data dependent power of the model 18910447Snilay@cs.wisc.edu virtual void evaluateModel(); 19010447Snilay@cs.wisc.edu virtual void useModel(const String& event_name_); 19110447Snilay@cs.wisc.edu virtual void useModel(); 19210447Snilay@cs.wisc.edu 19310447Snilay@cs.wisc.edu private: 19410447Snilay@cs.wisc.edu // Private copy constructor. Use clone to perform copy operation. 19510447Snilay@cs.wisc.edu Model(const Model& model_); 19610447Snilay@cs.wisc.edu 19710447Snilay@cs.wisc.edu private: 19810447Snilay@cs.wisc.edu // Name of this instance 19910447Snilay@cs.wisc.edu String m_instance_name_; 20010447Snilay@cs.wisc.edu // Set if this model is the top model 20110447Snilay@cs.wisc.edu bool m_is_top_model_; 20210447Snilay@cs.wisc.edu 20310447Snilay@cs.wisc.edu // Contains the parameters of a model 20410447Snilay@cs.wisc.edu // Parameters are needed in order to constructModel() and CANNOT be 20510447Snilay@cs.wisc.edu // changed after constructModel() has been called 20610447Snilay@cs.wisc.edu ParameterMap* m_parameters_; 20710447Snilay@cs.wisc.edu // Contains the names of all model parameters 20810447Snilay@cs.wisc.edu vector<String>* m_parameter_names_; 20910447Snilay@cs.wisc.edu // Contains the properties of a model 21010447Snilay@cs.wisc.edu // Properties are required in order to updateModel() and CAN be 21110447Snilay@cs.wisc.edu // changed be changed after constructModel(). Call updateModel() 21210447Snilay@cs.wisc.edu // after properties have been changed to use the new properties 21310447Snilay@cs.wisc.edu PropertyMap* m_properties_; 21410447Snilay@cs.wisc.edu // Contains the property names needed to update the model 21510447Snilay@cs.wisc.edu vector<String>* m_property_names_; 21610447Snilay@cs.wisc.edu // Contains generated properties of the model 21710447Snilay@cs.wisc.edu // Generated properties are used mostly as a scratch space for 21810447Snilay@cs.wisc.edu // variables used in the model that must be passed from one 21910447Snilay@cs.wisc.edu // function to another 22010447Snilay@cs.wisc.edu PropertyMap* m_generated_properties_; 22110447Snilay@cs.wisc.edu 22210447Snilay@cs.wisc.edu // Contains the instances of this model 22310447Snilay@cs.wisc.edu Map<SubModel*>* m_sub_instances_; 22410447Snilay@cs.wisc.edu // Contains the area resulst of a model 22510447Snilay@cs.wisc.edu Map<Result*>* m_area_map_; 22610447Snilay@cs.wisc.edu // Contains the noo power results of a model 22710447Snilay@cs.wisc.edu Map<Result*>* m_ndd_power_map_; 22810447Snilay@cs.wisc.edu // Contains the event results of a model 22910447Snilay@cs.wisc.edu Map<Result*>* m_event_map_; 23010447Snilay@cs.wisc.edu // Pointer to a TechModel which contains the technology information 23110447Snilay@cs.wisc.edu const TechModel* m_tech_model_; 23210447Snilay@cs.wisc.edu 23310447Snilay@cs.wisc.edu // Set when a model is constructed 23410447Snilay@cs.wisc.edu bool m_constructed_; 23510447Snilay@cs.wisc.edu // Set when a model is updated 23610447Snilay@cs.wisc.edu bool m_updated_; 23710447Snilay@cs.wisc.edu // Set when a model is evaluated 23810447Snilay@cs.wisc.edu bool m_evaluated_; 23910447Snilay@cs.wisc.edu 24010447Snilay@cs.wisc.edu }; // class Model 24110447Snilay@cs.wisc.edu} // namespace DSENT 24210447Snilay@cs.wisc.edu 24310447Snilay@cs.wisc.edu#endif // __DSENT_MODEL_MODEL_H__ 24410447Snilay@cs.wisc.edu 245