src/Emu/Utility/ExtraOpInfoWrapper.h

説明を見る。
00001 // 
00002 // Copyright (c) 2005-2008 Kenichi Watanabe.
00003 // Copyright (c) 2005-2008 Yasuhiro Watari.
00004 // Copyright (c) 2005-2008 Hironori Ichibayashi.
00005 // Copyright (c) 2008-2009 Kazuo Horio.
00006 // Copyright (c) 2009-2013 Naruki Kurata.
00007 // Copyright (c) 2005-2013 Ryota Shioya.
00008 // Copyright (c) 2005-2013 Masahiro Goshima.
00009 // 
00010 // This software is provided 'as-is', without any express or implied
00011 // warranty. In no event will the authors be held liable for any damages
00012 // arising from the use of this software.
00013 // 
00014 // Permission is granted to anyone to use this software for any purpose,
00015 // including commercial applications, and to alter it and redistribute it
00016 // freely, subject to the following restrictions:
00017 // 
00018 // 1. The origin of this software must not be misrepresented; you must not
00019 // claim that you wrote the original software. If you use this software
00020 // in a product, an acknowledgment in the product documentation would be
00021 // appreciated but is not required.
00022 // 
00023 // 2. Altered source versions must be plainly marked as such, and must not be
00024 // misrepresented as being the original software.
00025 // 
00026 // 3. This notice may not be removed or altered from any source
00027 // distribution.
00028 // 
00029 // 
00030 
00031 
00032 //
00033 // [U[`fR[_fR[hbp
00034 //
00035 
00036 #ifndef EMU_UTILITY_EXTRA_OP_INFO_WRAPPER_H
00037 #define EMU_UTILITY_EXTRA_OP_INFO_WRAPPER_H
00038 
00039 #include "Emu/Utility/CommonOpInfo.h"
00040 #include "Emu/Utility/OpEmulationState.h"
00041 
00042 namespace Onikiri
00043 {
00044     namespace EmulatorUtility
00045     {
00046         template<class TISAInfo>
00047         class ExtraOpEmuStateWrapper : public OpStateIF
00048         {
00049         private:
00050             OpEmulationState* m_emuState;
00051 
00052         public:
00053             ExtraOpEmuStateWrapper( OpEmulationState* emuState ) : m_emuState(emuState)
00054             {
00055             }
00056 
00057             ~ExtraOpEmuStateWrapper()
00058             {
00059             }
00060 
00061             // OpStateIF
00062             PC GetPC() const
00063             {
00064                 return Addr( 
00065                     m_emuState->GetPID(),
00066                     m_emuState->GetTID(),
00067                     m_emuState->GetPC() );
00068             }
00069 
00070             const u64 GetSrc(const int index) const
00071             {
00072                 return m_emuState->GetSrc( index );
00073             }
00074 
00075             const u64 GetDst(const int index) const
00076             {
00077                 return m_emuState->GetDst( index );
00078             }
00079 
00080             void SetDst(const int index, const u64 value)
00081             {
00082                 return m_emuState->SetDst( index, value );
00083             }
00084 
00085             void SetTakenPC(const PC takenPC)
00086             {
00087                 m_emuState->SetTakenPC( takenPC.address );
00088             }
00089 
00090             PC GetTakenPC() const
00091             {
00092                 return Addr( 
00093                     m_emuState->GetPID(),
00094                     m_emuState->GetTID(),
00095                     m_emuState->GetTakenPC() );
00096             }
00097 
00098             void SetTaken(const bool taken)
00099             {
00100                 m_emuState->SetTaken( taken );
00101             }
00102 
00103             bool GetTaken() const
00104             {
00105                 return m_emuState->GetTaken();
00106             }
00107 
00108             // MemIF
00109             void Read( MemAccess* access )
00110             {
00111                 m_emuState->GetOpState()->Read( access );
00112             }
00113 
00114             void Write( MemAccess* access )
00115             {
00116                 m_emuState->GetOpState()->Write( access );
00117             }
00118         };
00119 
00120         template<class TISAInfo>
00121         class ExtraOpInfoWrapper : public CommonOpInfo<TISAInfo> 
00122         {
00123             ExtraOpInfoIF* m_exOp;
00124         public:
00125             using CommonOpInfo<TISAInfo>::SetDstRegOpMap;
00126             using CommonOpInfo<TISAInfo>::SetSrcRegOpMap;
00127             using CommonOpInfo<TISAInfo>::SetDstRegNum;
00128             using CommonOpInfo<TISAInfo>::SetSrcRegNum;
00129             using CommonOpInfo<TISAInfo>::SetDstReg;
00130             using CommonOpInfo<TISAInfo>::SetSrcReg;
00131             using CommonOpInfo<TISAInfo>::SetEmulationFunc;
00132         
00133             ExtraOpInfoWrapper() : 
00134                 CommonOpInfo<TISAInfo>( OpClass( OpClassCode::UNDEF ) ),
00135                 m_exOp(0)
00136             {
00137                 SetEmulationFunc( &EmulationFunctionProxy );
00138             }
00139 
00140             void SetExtraOpInfo( ExtraOpInfoIF* exOp )
00141             {
00142                 m_exOp = exOp;
00143 
00144                 // CommonOpInfo f
00145                 SetDstRegNum( m_exOp->GetDstNum() );
00146                 SetSrcRegNum( m_exOp->GetSrcNum() );
00147                 
00148                 for( int i = 0; i < m_exOp->GetDstNum(); i++ ){
00149                     SetDstRegOpMap( i, i );
00150                     SetDstReg( i, m_exOp->GetDstOperand( i ) );
00151                 }
00152                 for( int i = 0; i < m_exOp->GetSrcNum(); i++ ){
00153                     SetSrcRegOpMap( i, i );
00154                     SetSrcReg( i, m_exOp->GetSrcOperand( i ) );
00155                 }
00156             }
00157 
00158             ExtraOpInfoIF* GetExtraOpInfo() const
00159             {
00160                 return m_exOp;
00161             }
00162 
00163             static void EmulationFunctionProxy( OpEmulationState* emuState )
00164             {
00165                 OpInfo* base = emuState->GetOpInfo();
00166                 ExtraOpInfoWrapper* wrapper = static_cast<ExtraOpInfoWrapper*>(base);
00167                 ASSERT( wrapper != 0 );
00168 
00169                 ExtraOpEmuStateWrapper<TISAInfo> tmpState( emuState );
00170 
00171                 // タs
00172                 ExtraOpInfoIF* exOpInfo = wrapper->GetExtraOpInfo();
00173                 exOpInfo->Execute( &tmpState );
00174             }
00175 
00176             // OpInfo タ
00177             const OpClass& GetOpClass() const
00178             {
00179                 ASSERT( m_exOp != 0 );
00180                 return m_exOp->GetOpClass();
00181             }
00182             int GetSrcOperand(const int index) const
00183             {
00184                 ASSERT( m_exOp != 0 );
00185                 return m_exOp->GetSrcOperand(index);
00186             }
00187             int GetDstOperand(const int index) const
00188             {
00189                 ASSERT( m_exOp != 0 );
00190                 return m_exOp->GetDstOperand(index);
00191             }
00192             int GetSrcNum() const
00193             {
00194                 ASSERT( m_exOp != 0 );
00195                 return m_exOp->GetSrcNum();
00196             }
00197             int GetDstNum() const
00198             {
00199                 ASSERT( m_exOp != 0 );
00200                 return m_exOp->GetDstNum();
00201             }
00202             int GetMicroOpNum() const
00203             {
00204                 ASSERT( m_exOp != 0 );
00205                 return m_exOp->GetMicroOpNum();
00206             }
00207             int GetMicroOpIndex() const
00208             {
00209                 ASSERT( m_exOp != 0 );
00210                 return m_exOp->GetMicroOpIndex();
00211             }
00212             const char* GetMnemonic() const
00213             {
00214                 ASSERT( m_exOp != 0 );
00215                 return m_exOp->GetMnemonic();
00216             }
00217         };
00218 
00219     } // namespace EmulatorUtility
00220 } // namespace Onikiri
00221 
00222 #endif
00223 

Onikiri2に対してTue Jun 18 14:34:20 2013に生成されました。  doxygen 1.4.7