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

archc.H

00001 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 
00003 /*  ArchC Library for tools generated by the ArchC Pre-processor
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 /* archc.H - include file for ArchC library             */
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 
00028 #ifndef _ARCHC_H
00029 #define _ARCHC_H
00030 
00031 #include <systemc.h>
00032 #include <list>
00033 #include <iomanip>
00034 #include <iostream>
00035 #include <fstream>
00036 #include "ac_parms.H"
00037 #include "ac_log.H"
00038  
00039 using std::list;
00040 using std::setw;
00041 
00042 extern int ac_stop_flag;
00043 extern unsigned int ac_heap_ptr;
00044 
00045 extern int ac_argc;                       
00046 extern char **ac_argv;
00047 
00048 // Prototypes
00049 void ac_init_opt( int ac, char* av[]);
00050 void ac_init_app( int ac, char* av[]);
00051 
00052 
00053 
00055 // ArchC Defines                        //
00057 
00058 #define ac_err stderr
00059 #define IDENT         0
00060 
00061 
00062 #define AC_ERROR( msg )    cerr<< "ArchC ERROR: " << msg  <<'\n'
00063 #define AC_SAY( msg )      cerr<< "ArchC: " << msg  <<'\n'
00064 
00065 #define AC_RUN_ERROR( str, args...) \
00066   fprintf(stderr, "ArchC Runtime error (ac_pc=%#x; ac_instr_counter=%llu): " str, (int) ac_pc, ac_instr_counter, args);
00067 #define AC_RUN_MSG( str )  fprintf(stderr, str);
00068 
00069 #define ac_trace( f )      extern ofstream trace_file; extern bool ac_do_trace; ac_do_trace = 1; trace_file.open( f )
00070 #define ac_close_trace     trace_file.close
00071 
00072 #ifndef AC_VERIFY
00073 //ArchC simulator initialization
00074 #define ac_init( processor) \
00075   extern char* appfilename; \
00076   ac_init_opt( ac, av);\
00077   ac_init_app( ac, av);\
00078   extern ac_storage* IMem; \
00079   IMem = processor.IM; \
00080   processor.APP_MEM->load(appfilename); \
00081   processor.time_step =  clk.period().to_double() / (sc_get_default_time_unit()).to_double(); \
00082   processor.set_args(ac_argc, ac_argv);\
00083 
00084 #else
00085 
00086 //ArchC simulator initialization
00087 #define ac_init( processor) \
00088   extern char* appfilename; \
00089   ac_init_opt( ac, av);\
00090   ac_init_app( ac, av);\
00091   extern ac_storage* IMem; \
00092   IMem = processor.IM; \
00093   processor.APP_MEM->load(appfilename); \
00094         processor.time_step =  clk.period().to_double() / (sc_get_default_time_unit()).to_double(); \
00095   processor.set_args(ac_argc, ac_argv);\
00096   processor.set_queue(av[0]);\
00097 
00098 #endif
00099 
00100 
00102 //ArchC class for instructions signals //
00103 //used in behavioral simulation        //
00105 class ac_instr{
00106 
00107   unsigned  instr[AC_DEC_FIELD_NUMBER];
00108 
00109 public:
00110 
00112   ac_instr( unsigned *im_instr ){
00113 
00114     if( im_instr )
00115       for( int j =0; j<AC_DEC_FIELD_NUMBER; j++) {
00116         instr[j] = im_instr[j];
00117       }
00118     else
00119       for( int j =0; j<AC_DEC_FIELD_NUMBER; j++) {
00120         instr[j] = 0;
00121       }
00122   }
00123     
00125   ac_instr(){
00126 
00127     for( int j =0; j<AC_DEC_FIELD_NUMBER; j++) {
00128       instr[j] = 0;
00129     }
00130   }
00131 
00133   ac_instr & operator= ( const ac_instr &i){
00134     
00135     for( int j =0; j<AC_DEC_FIELD_NUMBER; j++){
00136       instr[j] = i.instr[j];
00137     }
00138     return *this;
00139   }
00140   
00141   friend bool operator== (const ac_instr & i1,
00142                           const ac_instr & i2){
00143     bool flag = true;
00144     
00145     for( int j =0; j<AC_DEC_FIELD_NUMBER; j++) {
00146       flag = flag && (i1.instr[j] == i2.instr[j]);
00147     }
00148     
00149     return flag;
00150   }
00151   
00152   //Used by stream insertion operator
00153   void print (ostream & os) const{
00154     for( int j =0; j<AC_DEC_FIELD_NUMBER; j++)
00155       os << instr[j]<< ",";
00156     os << endl;
00157   }
00158 
00159   friend ostream& operator<< (ostream &os,
00160                               const ac_instr &i){
00161     i.print(os);
00162     return os;
00163   }
00164   
00166   operator bool () const {return true;}
00167 
00169   unsigned get( const int i ){ return instr[i];  }
00170  
00172   void put(const unsigned data, const unsigned i ){ instr[i] = data;  }
00173 };
00174 
00175 //Struct used for decoded instructions cache
00176 struct cache_item {
00177 
00178   bool valid;
00179   ac_instr* instr_p;
00180 };
00181 
00182 //Functions used to calculate the instr/s of the simulation
00183 void InitStat();
00184 void PrintStat();
00185 
00186 //Start simulation
00187 void ac_start(int argc=0, char *argv[]=0);
00188 
00189 //Stop simulation (may receive exit status)
00190 void ac_stop(int status=0);
00191 
00192 
00193 #endif //_ARCHC_H

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