mycpu/cinstruction.h

00001 
00008 #ifndef CINSTRUCTION_H
00009 #define CINSTRUCTION_H 1
00010 
00011 #include <iostream>
00012 #include <list>
00013 
00014 /* forward declare CCPU */
00015 class CCPU;
00016 
00022 class CInstruction
00023 {
00024   public:
00034     CInstruction(std::string name)
00035       : m_name(name)
00036     {}
00037 
00047     virtual ~CInstruction()
00048     {}
00049 
00059     virtual bool operator==(std::string& name)
00060     {
00061       return name == m_name;
00062     }
00063 
00073     virtual CInstruction& operator()(CCPU *cpu)
00074     {
00075       execute(cpu);
00076       return *this;
00077     }
00078 
00088     virtual const std::string& getName()
00089     {
00090       return m_name;
00091     }
00092 
00102     virtual std::ostream& dump(std::ostream& stream)
00103     {
00104       stream << m_name;
00105       return stream;
00106     }
00107 
00118     friend std::ostream& operator<<(std::ostream& stream, CInstruction& instr)
00119     {
00120       return instr.dump(stream);
00121     }
00122 
00132     virtual const unsigned parseRegister(const std::string& str);
00133 
00145     virtual void checkRegister(CCPU *cpu, const unsigned regidx);
00146 
00156     virtual CInstruction *factory() = 0;
00157 
00168     virtual void compile(std::list<std::string>& params) = 0;
00169 
00179     virtual void execute(CCPU *cpu) = 0;
00180 
00181   protected:
00182     /* members */
00184     std::string m_name;
00185 };
00186 
00187 #endif
00188 
00189 /* vim: set et sw=2 ts=2: */

Generated on Thu May 14 18:19:16 2009 for mycpu by  doxygen 1.5.3