/** * @module cinstruction * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) * @brief abstract class cpu instructions * @date 17.04.2009 */ #ifndef CINSTRUCTION_H #define CINSTRUCTION_H #include #include #include "cmem.h" /** * @class CInstruction * * Parses a simple line based scriptfile with some limitations: * first function (starting a block) must be a read-command, * last must be a write-command (ending this block). * * read- and write-commands have hard coded parameters, number#1 being a filetype. * Classes handling certain filetypes must be of type CFile. * Custom functions will be passed to CFile::callFunc(). * * On error ParserError will be thrown. */ class CInstruction { public: /** * @method ~CInstruction * @brief Default dtor * @param - * @return - * @globalvars none * @exception none * @conditions none */ virtual ~CInstruction() {} virtual void exec(CMem& mem, std::vector& instr) = 0; }; class CFlagInstruction : public CInstruction { public: void exec(CMem& mem, std::vector& instr) {} virtual void exec(CMem& mem, std::vector& instr, bool& flag) = 0; }; class CInc : public CInstruction { public: virtual void exec(CMem& mem, std::vector& instr); }; class CDec : public CInstruction { public: virtual void exec(CMem& mem, std::vector& instr); }; class CAdd : public CInstruction { public: virtual void exec(CMem& mem, std::vector& instr); }; class CSub : public CInstruction { public: virtual void exec(CMem& mem, std::vector& instr); }; class CMul : public CInstruction { public: virtual void exec(CMem& mem, std::vector& instr); }; class CDiv : public CInstruction { public: virtual void exec(CMem& mem, std::vector& instr); }; class CLoad : public CInstruction { public: virtual void exec(CMem& mem, std::vector& instr); }; class CStore : public CInstruction { public: virtual void exec(CMem& mem, std::vector& instr); }; class CTest : public CFlagInstruction { public: void exec(CMem& mem, std::vector& instr, bool& flag) {} virtual void test(CMem& mem, std::vector& instr, bool& f_zero, bool& f_sign); }; class CLabel : public CInstruction { public: void exec(CMem& mem, std::vector& instr) {} }; class CJumpa : public CInstruction { public: CJumpa(std::map& jumpaddr) : m_jumpaddr(jumpaddr) {} virtual void exec(CMem& mem, std::vector& instr); protected: std::map m_jumpaddr; }; class CJumpz : public CFlagInstruction { public: CJumpz(std::map& jumpaddr) : m_jumpaddr(jumpaddr) {} virtual void exec(CMem& mem, std::vector& instr, bool& f_zero); protected: std::map m_jumpaddr; }; class CJumps : public CFlagInstruction { public: CJumps(std::map& jumpaddr) : m_jumpaddr(jumpaddr) {} virtual void exec(CMem& mem, std::vector& instr, bool& f_sign); protected: std::map m_jumpaddr; }; class CWrite : public CInstruction { public: virtual void exec(CMem& mem, std::vector& instr); }; #endif /* vim: set et sw=2 ts=2: */