Skip to content
Snippets Groups Projects
STARSInstruction.h 1.11 KiB
Newer Older
#ifndef STARSInstruction_h
#define STARSInstruction_h

#include <stdint.h>
#include <assert.h>

class STARS_Instruction_t;

class STARS_InstructionID_t
{
	public:

		// constructor sets private data
		STARS_InstructionID_t(uintptr_t p_id) : m_id(p_id) { }

		
		/* for ease of porting, we allow casting directly to an EA_t */
		operator const STARS_ea_t () const {return m_id; }

		/* most of the time, though, we should map the ID to an insn */
		const STARS_Instruction_t* GetInstruction() 
		{ 
			const STARS_Instruction_t* ret=id_to_insn_map[m_id]; 
			assert(ret); 
			return ret;
		};
		operator const STARS_Instruction_t* ()  { return GetInstruction(); }


		void AddIDToInsnMapping(const STARS_Instruction_t* to) const { id_to_insn_map[m_id]=to; } 

	protected:

		uintptr_t m_id;
		static std::map<uintptr_t, const STARS_Instruction_t*> id_to_insn_map;

};

class STARS_Instruction_t
{
	public:
		
		STARS_Instruction_t(const STARS_InstructionID_t& p_id) : m_id(p_id) 
			{ p_id.AddIDToInsnMapping(this);}

		virtual STARS_InstructionID_t GetNextInstructionID()=0;

	protected:
		STARS_InstructionID_t m_id;

};

#endif