Main Page | Modules | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages | Examples

ac_regbank.H

00001 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 
00003 /*  ArchC Storage Library for the ArchC architecture simulators
00004     Copyright (C) 2002-2004  The ArchC Team
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Lesser General Public
00008     License as published by the Free Software Foundation; either
00009     version 2.1 of the License, or (at your option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     Lesser General Public License for more details.
00015 */
00016 
00017 /********************************************************/
00018 /* The ArchC storage device base class.                 */
00019 /* Author:  Sandro Rigo                                 */
00020 /*                                                      */
00021 /*                                                      */
00022 /* The ArchC Team                                       */
00023 /* Computer Systems Laboratory (LSC)                    */
00024 /* IC-UNICAMP                                           */
00025 /* http://www.lsc.ic.unicamp.br                         */
00026 /********************************************************/
00027 
00029 
00035 
00036 #ifndef _AC_REGBANK_H
00037 #define _AC_REGBANK_H
00038 
00039 #include "ac_storage.H"
00040 
00041 class ac_resources;
00042   
00045 template<class T>class ac_regbank: public ac_storage {
00046 public:
00047   
00049   T read( unsigned address ){
00050 
00051 #ifdef AC_STATS  
00052     ac_resources::ac_sim_stats.add_access(name);
00053 #endif
00054 
00055     return *((T *)(Data+((address)*sizeof(T)))); 
00056   }
00057 
00059   ac_Dword read_double( unsigned address ){
00060 
00061 #ifdef AC_STATS  
00062     ac_resources::ac_sim_stats.add_access(name);
00063 #endif
00064 
00065     return *((ac_Dword *)(Data+((address)*sizeof(ac_word)*2))); 
00066   }
00067 
00068 
00070   void write( unsigned address , T datum  ){
00071 #ifdef AC_MEM_HIERARCHY
00072     if(ac_resources::ac_wait_sig)
00073       return;
00074 #endif
00075   
00076 #ifdef AC_UPDATE_LOG
00077     changes.push_back( change_log(address, datum , sc_simulation_time()));
00078 #endif
00079   
00080     *((T *)(Data+((address)*sizeof(T)))) = datum;
00081   
00082 #ifdef AC_STATS
00083     ac_resources::ac_sim_stats.add_access(name);
00084 #endif
00085   }
00086 
00087 
00088 #ifdef AC_DELAY
00089 
00090   void write( unsigned address , T datum, unsigned time ){
00091     delays.push_back( change_log( address, datum, (time * ac_resources::time_step) + ac_resources::time_step + sc_simulation_time()));
00092   }
00093 #endif
00094 
00096   ac_regbank( char* name, unsigned size=sizeof(T) ):ac_storage(name,size*sizeof(T)){}
00097 
00099   void load( char* file ){
00100 
00101     ifstream input;
00102     string read;
00103     string word;
00104     T data;
00105     istringstream line;
00106 
00107     bool is_addr;
00108 
00109     int  addr=0;
00110 
00111     // Looking for initialization file.
00112     input.open(file);
00113     if(!input){
00114       AC_ERROR("Could not open input file:" << file);
00115     }
00116     else{
00117       
00118       while( !input.eof() ){
00119 
00120         line.clear();
00121         getline(input, read);
00122         line.str(read);
00123                         
00124         is_addr = 1;
00125 
00126         //Processing line
00127         while(line >> word){
00128 
00129           if( word == ".text" ){
00130             AC_ERROR("Should not load code into the register bank: " << name);
00131             return;
00132           }
00133                                                 
00134           if( word == ".data" ){
00135             continue;
00136           }
00137 
00138           //Processing word
00139           if( is_addr ){
00140             addr = strtol(word.c_str(), NULL, 16);
00141             is_addr = 0;
00142           }
00143           else{
00144             data = (T)strtol( word.c_str(), NULL, 16);
00145             write(addr,data);
00146             addr+= sizeof(T);
00147           }
00148         }
00149       }
00150     }
00151   }
00152 };
00153 
00154 #endif //_AC_REGBANK_H
00155 
00156 
00157 
00158 

Generated on Thu Jun 24 08:30:05 2004 for ArchC by doxygen 1.3.4