From b5d37348f60bb3ef8c964d97a990c8e484b7e701 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Fri, 23 Aug 2013 21:52:04 -0500 Subject: [PATCH] Add code generation simplification methods to PType - To assist with using PType with DECORATE expression code generation, added GetStoreOp(), GetLoadOp(), and GetRegType() to PType. --- src/dobjtype.cpp | 196 +++++++++++++++++++++++++++++++++++++++++++++++ src/dobjtype.h | 20 +++++ 2 files changed, 216 insertions(+) diff --git a/src/dobjtype.cpp b/src/dobjtype.cpp index 6d459dc27..267efe43b 100644 --- a/src/dobjtype.cpp +++ b/src/dobjtype.cpp @@ -229,6 +229,42 @@ int PType::GetValueInt(void *addr) const 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 @@ -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 *****************************************************************/ 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 ****************************************************************/ IMPLEMENT_CLASS(PString) @@ -527,6 +679,17 @@ PString::PString() { } +//========================================================================== +// +// PString :: GetRegType +// +//========================================================================== + +int PString::GetRegType() const +{ + return REGT_STRING; +} + /* PName ******************************************************************/ IMPLEMENT_CLASS(PName) @@ -622,6 +785,39 @@ PPointer::PPointer(PType *pointsat) 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 diff --git a/src/dobjtype.h b/src/dobjtype.h index 053b93072..09c6a3fd0 100644 --- a/src/dobjtype.h +++ b/src/dobjtype.h @@ -174,6 +174,14 @@ public: // Gets the value of a variable of this type at (addr) 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 // 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 int GetValueInt(void *addr) const; + virtual int GetStoreOp() const; + virtual int GetLoadOp() const; + virtual int GetRegType() const; bool Unsigned; protected: @@ -243,6 +254,9 @@ public: virtual void SetValue(void *addr, int val); virtual int GetValueInt(void *addr) const; + virtual int GetStoreOp() const; + virtual int GetLoadOp() const; + virtual int GetRegType() const; protected: PFloat(); }; @@ -252,6 +266,8 @@ class PString : public PBasicType DECLARE_CLASS(PString, PBasicType); public: PString(); + + virtual int GetRegType() const; }; // Variations of integer types ---------------------------------------------- @@ -295,6 +311,10 @@ public: 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 void GetTypeIDs(intptr_t &id1, intptr_t &id2) const; protected: