Add code generation simplification methods to PType

- To assist with using PType with DECORATE expression code generation,
  added GetStoreOp(), GetLoadOp(), and GetRegType() to PType.
This commit is contained in:
Randy Heit 2013-08-23 21:52:04 -05:00
parent 2ec3cbddb9
commit b5d37348f6
2 changed files with 216 additions and 0 deletions

View File

@ -229,6 +229,42 @@ int PType::GetValueInt(void *addr) const
return 0; return 0;
} }
//==========================================================================
//
// PType :: GetStoreOp
//
//==========================================================================
int PType::GetStoreOp() const
{
assert(0 && "Cannot store this type");
return OP_NOP;
}
//==========================================================================
//
// PType :: GetLoadOp
//
//==========================================================================
int PType::GetLoadOp() const
{
assert(0 && "Cannot load this type");
return OP_NOP;
}
//==========================================================================
//
// PType :: GetRegType
//
//==========================================================================
int PType::GetRegType() const
{
assert(0 && "No register for this type");
return REGT_NIL;
}
//========================================================================== //==========================================================================
// //
// PType :: IsMatch // PType :: IsMatch
@ -446,6 +482,71 @@ int PInt::GetValueInt(void *addr) const
} }
} }
//==========================================================================
//
// PInt :: GetStoreOp
//
//==========================================================================
int PInt::GetStoreOp() const
{
if (Size == 4)
{
return OP_SW;
}
else if (Size == 1)
{
return OP_SB;
}
else if (Size == 2)
{
return OP_SH;
}
else
{
assert(0 && "Unhandled integer size");
return OP_NOP;
}
}
//==========================================================================
//
// PInt :: GetLoadOp
//
//==========================================================================
int PInt::GetLoadOp() const
{
if (Size == 4)
{
return OP_LW;
}
else if (Size == 1)
{
return Unsigned ? OP_LBU : OP_LB;
}
else if (Size == 2)
{
return Unsigned ? OP_LHU : OP_LH;
}
else
{
assert(0 && "Unhandled integer size");
return OP_NOP;
}
}
//==========================================================================
//
// PInt :: GetRegType
//
//==========================================================================
int PInt::GetRegType() const
{
return REGT_INT;
}
/* PFloat *****************************************************************/ /* PFloat *****************************************************************/
IMPLEMENT_CLASS(PFloat) IMPLEMENT_CLASS(PFloat)
@ -512,6 +613,57 @@ int PFloat::GetValueInt(void *addr) const
} }
} }
//==========================================================================
//
// PFloat :: GetStoreOp
//
//==========================================================================
int PFloat::GetStoreOp() const
{
if (Size == 4)
{
return OP_SSP;
}
else
{
assert(Size == 8);
return OP_SDP;
}
}
//==========================================================================
//
// PFloat :: GetLoadOp
//
//==========================================================================
int PFloat::GetLoadOp() const
{
if (Size == 4)
{
return OP_LSP;
}
else
{
assert(Size == 8);
return OP_LDP;
}
assert(0 && "Cannot load this type");
return OP_NOP;
}
//==========================================================================
//
// PFloat :: GetRegType
//
//==========================================================================
int PFloat::GetRegType() const
{
return REGT_FLOAT;
}
/* PString ****************************************************************/ /* PString ****************************************************************/
IMPLEMENT_CLASS(PString) IMPLEMENT_CLASS(PString)
@ -527,6 +679,17 @@ PString::PString()
{ {
} }
//==========================================================================
//
// PString :: GetRegType
//
//==========================================================================
int PString::GetRegType() const
{
return REGT_STRING;
}
/* PName ******************************************************************/ /* PName ******************************************************************/
IMPLEMENT_CLASS(PName) IMPLEMENT_CLASS(PName)
@ -622,6 +785,39 @@ PPointer::PPointer(PType *pointsat)
Align = __alignof(void *); Align = __alignof(void *);
} }
//==========================================================================
//
// PPointer :: GetStoreOp
//
//==========================================================================
int PPointer::GetStoreOp() const
{
return OP_SP;
}
//==========================================================================
//
// PPointer :: GetLoadOp
//
//==========================================================================
int PPointer::GetLoadOp() const
{
return PointedType->IsKindOf(RUNTIME_CLASS(PClass)) ? OP_LO : OP_LP;
}
//==========================================================================
//
// PPointer :: GetRegType
//
//==========================================================================
int PPointer::GetRegType() const
{
return REGT_POINTER;
}
//========================================================================== //==========================================================================
// //
// PPointer :: IsMatch // PPointer :: IsMatch

View File

@ -174,6 +174,14 @@ public:
// Gets the value of a variable of this type at (addr) // Gets the value of a variable of this type at (addr)
virtual int GetValueInt(void *addr) const; virtual int GetValueInt(void *addr) const;
// Gets the opcode to store from a register to memory
virtual int GetStoreOp() const;
// Gets the opcode to load from memory to a register
virtual int GetLoadOp() const;
// Gets the register type for this type
virtual int GetRegType() const;
// Returns true if this type matches the two identifiers. Referring to the // Returns true if this type matches the two identifiers. Referring to the
// above table, any type is identified by at most two characteristics. Each // above table, any type is identified by at most two characteristics. Each
@ -229,6 +237,9 @@ public:
virtual void SetValue(void *addr, int val); virtual void SetValue(void *addr, int val);
virtual int GetValueInt(void *addr) const; virtual int GetValueInt(void *addr) const;
virtual int GetStoreOp() const;
virtual int GetLoadOp() const;
virtual int GetRegType() const;
bool Unsigned; bool Unsigned;
protected: protected:
@ -243,6 +254,9 @@ public:
virtual void SetValue(void *addr, int val); virtual void SetValue(void *addr, int val);
virtual int GetValueInt(void *addr) const; virtual int GetValueInt(void *addr) const;
virtual int GetStoreOp() const;
virtual int GetLoadOp() const;
virtual int GetRegType() const;
protected: protected:
PFloat(); PFloat();
}; };
@ -252,6 +266,8 @@ class PString : public PBasicType
DECLARE_CLASS(PString, PBasicType); DECLARE_CLASS(PString, PBasicType);
public: public:
PString(); PString();
virtual int GetRegType() const;
}; };
// Variations of integer types ---------------------------------------------- // Variations of integer types ----------------------------------------------
@ -295,6 +311,10 @@ public:
PType *PointedType; PType *PointedType;
virtual int GetStoreOp() const;
virtual int GetLoadOp() const;
virtual int GetRegType() const;
virtual bool IsMatch(intptr_t id1, intptr_t id2) const; virtual bool IsMatch(intptr_t id1, intptr_t id2) const;
virtual void GetTypeIDs(intptr_t &id1, intptr_t &id2) const; virtual void GetTypeIDs(intptr_t &id1, intptr_t &id2) const;
protected: protected: