architecture.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2009 by Touati Sid                                      *
00003  *   Sid-nospam.Touati-nospam@univ-cotedazur.fr                                      *
00004  *   Copyright  INRIA and the University of Versailles                     *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU Library General Public     *
00016  *   License along with this program (LGPL); if not, write to the          *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  *   Exception : this software requires a licence  of the LEDA libary.     *
00020  *   If you are from academia, you can get a free leda binary licence 
00021  *   allowing you to use freely our DDG library.                           *
00022  *   Otherwise, you can buy a LEDA licence from algorithmic-solutions      *
00023  *   http://www.algorithmic-solutions.com                                  *
00024  *   LEDA binaries and source codes are excluded from this LGPL.           *
00025  *   Obtaining a LEDA licence is not mandatory to use our GPL software     *
00026  *   If the user wants, he can  create a free source-compatible replacement*
00027  *   for LEDA, and he is allowed to use our software under LGPL.           *
00028  ***************************************************************************/
00029 
00030 #ifndef __architecture_H
00031 #define __architecture_H
00032 
00040 #endif
00041 #ifndef DDGARCHITECTURE_H
00042 #define DDGARCHITECTURE_H
00043 
00044 #include <LEDA/core/list.h>
00045 #include <LEDA/core/d_array.h>
00046 #include "ddg_exceptions.h"
00047 
00048 #include "instructions_types.h"
00053 #ifndef MAX_STRING
00054 #define MAX_STRING 1000
00055 #endif
00056 namespace DDG {
00057 
00061 class ARCHITECTURE{
00062 protected:
00063 int cpt_regtypes; // a counter incremented for each new register type
00064 int cpt_instructions_types; // a counter incremented for each new
00065 bool default_arch;
00066 bool is_ual_semantic;
00067 private:    
00068 LEDA::d_array<int,REGISTER_TYPES> reg_types;
00069 LEDA::d_array<int,INSTRUCTIONS_TYPES> inst_types;
00070 public:
00071     ARCHITECTURE();
00072     ~ARCHITECTURE();
00073     bool read_from_xml(const char *);
00074     bool read_from_arch(const char *);
00075     void clear();
00076     bool check() const;
00077     void write_to_xml(const char*) const;
00078     LEDA::list<int> get_list_regtypes_id() const;
00079     LEDA::list<int> get_list_instructions_types_id() const;
00080     LEDA::d_array<int,REGISTER_TYPES>  get_dictionary_regtypes() const {return reg_types;}
00081     LEDA::d_array<int,INSTRUCTIONS_TYPES> get_dictionary_instructions_types() const {return inst_types;}
00082   
00083     
00084     int get_register_type_id(std::string regtype_name) const;
00085     std::string get_register_typename(int regtype_id) const;
00086     bool exist_register_typename(std::string reg_typename) const;
00087     bool exist_register_type_id(int registertype_id) const;
00088     bool exist_instruction_type_id(int id) const;
00089     bool exist_instruction_type_opcode(std::string opcode) const;
00090     
00091     int create_new_instruction_type_id();
00092     int create_new_regtype_id();
00093     void set_default_arch();
00094     void new_register_type(REGISTER_TYPES rt);
00095     void new_instruction_type(INSTRUCTIONS_TYPES it);
00096 
00101     bool is_default_arch()
00102     {
00103         return default_arch;
00104     }
00105 
00110     bool get_ual_semantic() const{
00111       return is_ual_semantic;
00112     }
00113     
00118     void set_ual_semantic(bool ual){
00119       is_ual_semantic = ual;
00120     }
00121     
00127     REGISTER_TYPES get_register_type_by_id(int id) const
00128     {
00129         if (exist_register_type_id(id)) return reg_types[id];
00130         else {
00131             throw BadRegType();
00132         }
00133     }
00134 
00140     INSTRUCTIONS_TYPES get_instruction_type_by_id(int id) const
00141     {
00142         if (exist_instruction_type_id(id)) return inst_types[id];
00143         else throw BadInstructionType(id);
00144     }
00145     int number_of_registers_types() const;
00146     int number_of_instructions_types() const;
00147     int get_the_unique_register_type_id() const;
00148     INSTRUCTIONS_TYPES get_instruction_type_by_opcode(std::string opcode) const;
00149     void write_to_arch(const char * filename) const;
00150     LEDA::list<REGISTER_TYPES> get_list_register_types() const;
00155     LEDA::list<REGISTER_TYPES> T() const {return get_list_register_types();}
00156     int pick_an_instruction_type_id() const;
00157 
00162     int get_instruction_type_id(std::string stropcode)const
00163     {
00164         return (this->get_instruction_type_by_opcode(stropcode)).opcode_id();
00165     }
00166    
00167     
00168 };
00169 
00170 }
00171 
00172 #endif

January 2009, by Sid Touati (Copyright INRIA and University of Versailles)