/** * @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: CInstruction() {} CInstruction(std::map& jumpaddr) : m_jumpaddr(jumpaddr) {} /** * @method ~CInstruction * @brief Default dtor * @param - * @return - * @globalvars none * @exception none * @conditions none */ virtual ~CInstruction() {} virtual void exec(CMem& mem, std::vector& instr) = 0; protected: std::map m_jumpaddr; }; class CFlagInstruction : public CInstruction { public: public: CFlagInstruction(bool& zero, bool& sign) : f_zero(zero), f_sign(sign) {} CFlagInstruction(bool& zero, bool& sign, std::map& jumpaddr) : CInstruction::CInstruction(jumpaddr), f_zero(zero), f_sign(sign) {} virtual void exec(CMem& mem, std::vector& instr) = 0; protected: bool &f_zero, &f_sign; }; class CInc : public CInstruction { public: void exec(CMem& mem, std::vector& instr); }; class CDec : public CInstruction { public: void exec(CMem& mem, std::vector& instr); }; class CAdd : public CInstruction { public: void exec(CMem& mem, std::vector& instr); }; class CSub : public CInstruction { public: void exec(CMem& mem, std::vector& instr); }; class CMul : public CInstruction { public: void exec(CMem& mem, std::vector& instr); }; class CDiv : public CInstruction { public: void exec(CMem& mem, std::vector& instr); }; class CLoad : public CInstruction { public: void exec(CMem& mem, std::vector& instr); }; class CStore : public CInstruction { public: void exec(CMem& mem, std::vector& instr); }; class CTest : public CFlagInstruction { public: CTest(bool& zero, bool& sign) : CFlagInstruction::CFlagInstruction(zero, sign) {} void exec(CMem& mem, std::vector& instr); }; class CLabel : public CInstruction { public: void exec(CMem& mem, std::vector& instr) {} }; class CJumpa : public CInstruction { public: CJumpa(std::map& jumpaddr) : CInstruction::CInstruction(jumpaddr) {} void exec(CMem& mem, std::vector& instr); }; class CJumpz : public CFlagInstruction { public: CJumpz(bool& zero, bool& sign, std::map& jumpaddr) : CFlagInstruction::CFlagInstruction(zero, sign, jumpaddr) {} void exec(CMem& mem, std::vector& instr); }; class CJumps : public CFlagInstruction { public: CJumps(bool& zero ,bool& sign, std::map& jumpaddr) : CFlagInstruction::CFlagInstruction(zero, sign, jumpaddr) {} void exec(CMem& mem, std::vector& instr); }; class CWrite : public CInstruction { public: void exec(CMem& mem, std::vector& instr); }; #endif /* vim: set et sw=2 ts=2: */