#ifndef _OPR_H_ #define _OPR_H_ /* * file opr.h */ typedef enum { FALSE = 0, TRUE } Boolean; typedef enum { bad_opr_type, opr_index, opr_reg, opr_imm, opr_label } opr_kind; /* * operand base class */ class operand { private: unsigned int used : 1, // operand referenced defined : 1, // operand used as a destination unused_flags : 30; public: operand(void) { used = FALSE; defined = FALSE; } Boolean is_used(void) { return (Boolean)used; } void set_used(void) { used = TRUE; } Boolean is_def(void) { return (Boolean)defined; } void set_def(void) { defined = TRUE; } void unset_used(void) { used = FALSE; } // // Overloaded new // // default version of new (required by older C++ compilers) void *operator new( unsigned int num_bytes ) { assert( FALSE ); return NULL; } // new function which allocates from a memory pool void *operator new( unsigned int num_bytes, pool *mem_pool ) { return mem_pool->GetMem( num_bytes ); } // Memory is recovered by deleting the memory pool. So delete // should do nothing. void operator delete( void *addr ) {/* do nothing */} // // --- virtual functions --- // // common virtual functions // virtual opr_kind get_kind(void) { return bad_opr_type; } // // oprand_imm // virtual void set_imm( short int val ) { assert(FALSE); } virtual short int get_imm(void) { assert( FALSE ); return (short int)0; } // // oprand_reg // virtual void set_vreg( unsigned short int vreg ) { assert(FALSE); } virtual void set_rreg( real_reg_num rreg ) { assert(FALSE); } virtual unsigned short int get_vreg(void) { assert(FALSE); return (short int)0; } virtual real_reg_num get_rreg(void) { assert(FALSE); return (real_reg_num)0; } reg_kind get_reg_kind(void) { assert( FALSE ); return reg_bad_type; } // // oprand_rindex // virtual void set_base_reg( registor reg ) { assert(FALSE); } virtual void set_offset( short int off ) { assert(FALSE); } virtual registor get_base_reg(void) { registor base_reg; assert( FALSE ); return base_reg; } virtual unsigned short int get_offset(void) { assert( FALSE ); return 0; } // // oprand_rindex // virtual void set_label( const char *l ) { assert( FALSE ); } virtual char *get_label(void) { return NULL; } }; // operand class operand_imm : public operand { private: short int imm; public: operand_imm(void) : operand() { imm = 0; } void set_imm( short int val ) { imm = val; } short int get_imm(void) { return imm; } opr_kind get_kind(void) { return opr_imm; } }; // operand_imm class operand_reg : public operand { private: registor reg; public: void set_vreg( unsigned short int vreg ) { reg.set_vreg(vreg); } void set_rreg( real_reg_num rreg ) { reg.set_rreg(rreg); } unsigned short int get_vreg(void) { return reg.get_vreg(); } real_reg_num get_rreg(void) { return get_rreg(); } reg_kind get_reg_kind(void) { return get_reg_kind(); } opr_kind get_kind(void) { return opr_reg; } }; // operand_reg class operand_rindex : public operand { private: registor base_reg; short int offset; // note that offset can be signed ex: -16(r1) public: operand_rindex(void) : operand() { offset = 0; } void set_base_reg( registor reg ) { base_reg = reg; } void set_offset( short int off ) { offset = off; } registor get_base_reg(void) { return base_reg; } unsigned short int get_offset(void) { return offset; } opr_kind get_kind(void) { return opr_index; } }; // operand_rindex class operand_label : public operand { private: char *label; public: operand_label(void) : operand() { label = NULL; } void set_label( const char *l ) { label = (char *)l; } char *get_label(void) { return label; } opr_kind get_kind(void) { return opr_label; } }; // operand_label #endif
back to Polymorphic Types in C++