Add GetValueFloat() for numeric PTypes

This commit is contained in:
Randy Heit 2016-03-29 22:24:59 -05:00
parent feb5ab31cc
commit 299019ea15
2 changed files with 59 additions and 2 deletions

View file

@ -412,6 +412,12 @@ int PType::GetValueInt(void *addr) const
return 0; return 0;
} }
double PType::GetValueFloat(void *addr) const
{
assert(0 && "Cannot get value for this type");
return 0;
}
//========================================================================== //==========================================================================
// //
// PType :: GetStoreOp // PType :: GetStoreOp
@ -724,6 +730,17 @@ int PInt::GetValueInt(void *addr) const
} }
} }
//==========================================================================
//
// PInt :: GetValueFloat
//
//==========================================================================
double PInt::GetValueFloat(void *addr) const
{
return GetValueInt(addr);
}
//========================================================================== //==========================================================================
// //
// PInt :: GetStoreOp // PInt :: GetStoreOp
@ -962,16 +979,27 @@ void PFloat::SetValue(void *addr, double val)
//========================================================================== //==========================================================================
int PFloat::GetValueInt(void *addr) const int PFloat::GetValueInt(void *addr) const
{
return xs_ToInt(GetValueFloat(addr));
}
//==========================================================================
//
// PFloat :: GetValueFloat
//
//==========================================================================
double PFloat::GetValueFloat(void *addr) const
{ {
assert(((intptr_t)addr & (Align - 1)) == 0 && "unaligned address"); assert(((intptr_t)addr & (Align - 1)) == 0 && "unaligned address");
if (Size == 4) if (Size == 4)
{ {
return xs_ToInt(*(float *)addr); return *(float *)addr;
} }
else else
{ {
assert(Size == 8); assert(Size == 8);
return xs_ToInt(*(double *)addr); return *(double *)addr;
} }
} }
@ -1145,6 +1173,18 @@ int PFixed::GetValueInt(void *addr) const
return *(fixed_t *)addr >> FRACBITS; return *(fixed_t *)addr >> FRACBITS;
} }
//==========================================================================
//
// PFixed :: GetValueFloat
//
//==========================================================================
double PFixed::GetValueFloat(void *addr) const
{
assert(((intptr_t)addr & (Align - 1)) == 0 && "unaligned address");
return FIXED2DBL(*(fixed_t *)addr);
}
//========================================================================== //==========================================================================
// //
// PFixed :: GetStoreOp // PFixed :: GetStoreOp
@ -1212,6 +1252,18 @@ int PAngle::GetValueInt(void *addr) const
return *(angle_t *)addr / ANGLE_1; return *(angle_t *)addr / ANGLE_1;
} }
//==========================================================================
//
// PAngle :: GetValueFloat
//
//==========================================================================
double PAngle::GetValueFloat(void *addr) const
{
assert(((intptr_t)addr & (Align - 1)) == 0 && "unaligned address");
return (double)(*(angle_t *)addr) / ANGLE_1;
}
//========================================================================== //==========================================================================
// //
// PAngle :: GetStoreOp // PAngle :: GetStoreOp

View file

@ -192,6 +192,7 @@ 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;
virtual double GetValueFloat(void *addr) const;
// Gets the opcode to store from a register to memory // Gets the opcode to store from a register to memory
virtual int GetStoreOp() const; virtual int GetStoreOp() const;
@ -323,6 +324,7 @@ public:
virtual void SetValue(void *addr, int val); virtual void SetValue(void *addr, int val);
virtual void SetValue(void *addr, double val); virtual void SetValue(void *addr, double val);
virtual int GetValueInt(void *addr) const; virtual int GetValueInt(void *addr) const;
virtual double GetValueFloat(void *addr) const;
virtual int GetStoreOp() const; virtual int GetStoreOp() const;
virtual int GetLoadOp() const; virtual int GetLoadOp() const;
virtual int GetRegType() const; virtual int GetRegType() const;
@ -348,6 +350,7 @@ public:
virtual void SetValue(void *addr, int val); virtual void SetValue(void *addr, int val);
virtual void SetValue(void *addr, double val); virtual void SetValue(void *addr, double val);
virtual int GetValueInt(void *addr) const; virtual int GetValueInt(void *addr) const;
virtual double GetValueFloat(void *addr) const;
virtual int GetStoreOp() const; virtual int GetStoreOp() const;
virtual int GetLoadOp() const; virtual int GetLoadOp() const;
virtual int GetRegType() const; virtual int GetRegType() const;
@ -415,6 +418,7 @@ public:
virtual void SetValue(void *addr, int val); virtual void SetValue(void *addr, int val);
virtual void SetValue(void *addr, double val); virtual void SetValue(void *addr, double val);
virtual int GetValueInt(void *addr) const; virtual int GetValueInt(void *addr) const;
virtual double GetValueFloat(void *addr) const;
virtual int GetStoreOp() const; virtual int GetStoreOp() const;
virtual int GetLoadOp() const; virtual int GetLoadOp() const;
}; };
@ -428,6 +432,7 @@ public:
virtual void SetValue(void *addr, int val); virtual void SetValue(void *addr, int val);
virtual void SetValue(void *addr, double val); virtual void SetValue(void *addr, double val);
virtual int GetValueInt(void *addr) const; virtual int GetValueInt(void *addr) const;
virtual double GetValueFloat(void *addr) const;
virtual int GetStoreOp() const; virtual int GetStoreOp() const;
virtual int GetLoadOp() const; virtual int GetLoadOp() const;
}; };