2001-06-06 20:29:01 +00:00
|
|
|
//===-- llvm/ConstPoolVals.h - Constant Value nodes --------------*- C++ -*--=//
|
|
|
|
//
|
|
|
|
// This file contains the declarations for the ConstPoolVal class and all of
|
|
|
|
// its subclasses, which represent the different type of constant pool values
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CONSTPOOLVALS_H
|
|
|
|
#define LLVM_CONSTPOOLVALS_H
|
|
|
|
|
|
|
|
#include "llvm/User.h"
|
|
|
|
#include "llvm/SymTabValue.h"
|
2001-07-23 17:46:59 +00:00
|
|
|
#include "llvm/Support/DataTypes.h"
|
2001-06-06 20:29:01 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
class ArrayType;
|
|
|
|
class StructType;
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ConstPoolVal Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
class ConstPoolVal : public User {
|
|
|
|
SymTabValue *Parent;
|
|
|
|
|
2001-07-14 06:07:58 +00:00
|
|
|
friend class ValueHolder<ConstPoolVal, SymTabValue, SymTabValue>;
|
2001-06-06 20:29:01 +00:00
|
|
|
inline void setParent(SymTabValue *parent) {
|
|
|
|
Parent = parent;
|
|
|
|
}
|
|
|
|
|
2001-07-20 19:13:28 +00:00
|
|
|
protected:
|
2001-06-06 20:29:01 +00:00
|
|
|
inline ConstPoolVal(const Type *Ty, const string &Name = "")
|
|
|
|
: User(Ty, Value::ConstantVal, Name) { Parent = 0; }
|
|
|
|
|
2001-07-20 19:13:28 +00:00
|
|
|
public:
|
2001-06-06 20:29:01 +00:00
|
|
|
// Specialize setName to handle symbol table majik...
|
|
|
|
virtual void setName(const string &name);
|
|
|
|
|
|
|
|
// Static constructor to create a '0' constant of arbitrary type...
|
|
|
|
static ConstPoolVal *getNullConstant(const Type *Ty);
|
|
|
|
|
|
|
|
// clone() - Create a copy of 'this' value that is identical in all ways
|
|
|
|
// except the following:
|
|
|
|
// * The value has no parent
|
|
|
|
// * The value has no name
|
|
|
|
//
|
|
|
|
virtual ConstPoolVal *clone() const = 0;
|
|
|
|
|
|
|
|
virtual string getStrValue() const = 0;
|
|
|
|
virtual bool equals(const ConstPoolVal *V) const = 0;
|
|
|
|
|
|
|
|
inline const SymTabValue *getParent() const { return Parent; }
|
|
|
|
inline SymTabValue *getParent() { return Parent; }
|
2001-07-14 06:07:58 +00:00
|
|
|
inline const Value *getParentV() const { return Parent->getSTVParent(); }
|
|
|
|
inline Value *getParentV() { return Parent->getSTVParent(); }
|
2001-06-06 20:29:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Classes to represent constant pool variable defs
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
//===---------------------------------------------------------------------------
|
|
|
|
// ConstPoolBool - Boolean Values
|
|
|
|
//
|
|
|
|
class ConstPoolBool : public ConstPoolVal {
|
|
|
|
bool Val;
|
|
|
|
ConstPoolBool(const ConstPoolBool &CP);
|
|
|
|
public:
|
2001-07-21 19:02:43 +00:00
|
|
|
ConstPoolBool(const Type *Ty, bool V, const string &Name = "");
|
2001-06-06 20:29:01 +00:00
|
|
|
ConstPoolBool(bool V, const string &Name = "");
|
|
|
|
|
|
|
|
virtual string getStrValue() const;
|
|
|
|
virtual bool equals(const ConstPoolVal *V) const;
|
|
|
|
|
|
|
|
virtual ConstPoolVal *clone() const { return new ConstPoolBool(*this); }
|
|
|
|
|
|
|
|
inline bool getValue() const { return Val; }
|
|
|
|
|
|
|
|
// setValue - Be careful... if there is more than one 'use' of this node, then
|
|
|
|
// they will ALL see the value that you set...
|
|
|
|
//
|
|
|
|
inline void setValue(bool v) { Val = v; }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-07-20 19:13:28 +00:00
|
|
|
//===---------------------------------------------------------------------------
|
|
|
|
// ConstPoolInt - Superclass of ConstPoolSInt & ConstPoolUInt, to make dealing
|
|
|
|
// with integral constants easier.
|
|
|
|
//
|
|
|
|
class ConstPoolInt : public ConstPoolVal {
|
|
|
|
protected:
|
|
|
|
union {
|
|
|
|
int64_t Signed;
|
|
|
|
uint64_t Unsigned;
|
|
|
|
} Val;
|
|
|
|
ConstPoolInt(const ConstPoolInt &CP);
|
|
|
|
public:
|
|
|
|
ConstPoolInt(const Type *Ty, int64_t V, const string &Name = "");
|
|
|
|
ConstPoolInt(const Type *Ty, uint64_t V, const string &Name = "");
|
|
|
|
|
|
|
|
virtual bool equals(const ConstPoolVal *V) const;
|
|
|
|
|
2001-07-21 19:02:43 +00:00
|
|
|
// equalsInt - Provide a helper method that can be used to determine if the
|
2001-07-20 19:13:28 +00:00
|
|
|
// constant contained within is equal to a constant. This only works for very
|
|
|
|
// small values, because this is all that can be represented with all types.
|
|
|
|
//
|
2001-07-21 19:02:43 +00:00
|
|
|
bool equalsInt(unsigned char V) const {
|
2001-07-20 19:13:28 +00:00
|
|
|
assert(V <= 127 && "equals: Can only be used with very small constants!");
|
|
|
|
return Val.Unsigned == V;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ConstPoolInt::get static method: return a constant pool int with the
|
|
|
|
// specified value. as above, we work only with very small values here.
|
|
|
|
//
|
|
|
|
static ConstPoolInt *get(const Type *Ty, unsigned char V);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-06-06 20:29:01 +00:00
|
|
|
//===---------------------------------------------------------------------------
|
|
|
|
// ConstPoolSInt - Signed Integer Values [sbyte, short, int, long]
|
|
|
|
//
|
2001-07-20 19:13:28 +00:00
|
|
|
class ConstPoolSInt : public ConstPoolInt {
|
|
|
|
ConstPoolSInt(const ConstPoolSInt &CP) : ConstPoolInt(CP) {}
|
2001-06-06 20:29:01 +00:00
|
|
|
public:
|
|
|
|
ConstPoolSInt(const Type *Ty, int64_t V, const string &Name = "");
|
|
|
|
|
|
|
|
virtual ConstPoolVal *clone() const { return new ConstPoolSInt(*this); }
|
|
|
|
|
|
|
|
virtual string getStrValue() const;
|
|
|
|
|
|
|
|
static bool isValueValidForType(const Type *Ty, int64_t V);
|
2001-07-20 19:13:28 +00:00
|
|
|
inline int64_t getValue() const { return Val.Signed; }
|
2001-06-06 20:29:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//===---------------------------------------------------------------------------
|
|
|
|
// ConstPoolUInt - Unsigned Integer Values [ubyte, ushort, uint, ulong]
|
|
|
|
//
|
2001-07-20 19:13:28 +00:00
|
|
|
class ConstPoolUInt : public ConstPoolInt {
|
|
|
|
ConstPoolUInt(const ConstPoolUInt &CP) : ConstPoolInt(CP) {}
|
2001-06-06 20:29:01 +00:00
|
|
|
public:
|
|
|
|
ConstPoolUInt(const Type *Ty, uint64_t V, const string &Name = "");
|
|
|
|
|
|
|
|
virtual ConstPoolVal *clone() const { return new ConstPoolUInt(*this); }
|
|
|
|
|
|
|
|
virtual string getStrValue() const;
|
|
|
|
|
|
|
|
static bool isValueValidForType(const Type *Ty, uint64_t V);
|
2001-07-20 19:13:28 +00:00
|
|
|
inline uint64_t getValue() const { return Val.Unsigned; }
|
2001-06-06 20:29:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//===---------------------------------------------------------------------------
|
|
|
|
// ConstPoolFP - Floating Point Values [float, double]
|
|
|
|
//
|
|
|
|
class ConstPoolFP : public ConstPoolVal {
|
|
|
|
double Val;
|
|
|
|
ConstPoolFP(const ConstPoolFP &CP);
|
|
|
|
public:
|
|
|
|
ConstPoolFP(const Type *Ty, double V, const string &Name = "");
|
|
|
|
|
|
|
|
virtual ConstPoolVal *clone() const { return new ConstPoolFP(*this); }
|
|
|
|
virtual string getStrValue() const;
|
|
|
|
virtual bool equals(const ConstPoolVal *V) const;
|
|
|
|
|
|
|
|
static bool isValueValidForType(const Type *Ty, double V);
|
|
|
|
inline double getValue() const { return Val; }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//===---------------------------------------------------------------------------
|
|
|
|
// ConstPoolType - Type Declarations
|
|
|
|
//
|
|
|
|
class ConstPoolType : public ConstPoolVal {
|
|
|
|
const Type *Val;
|
|
|
|
ConstPoolType(const ConstPoolType &CPT);
|
|
|
|
public:
|
|
|
|
ConstPoolType(const Type *V, const string &Name = "");
|
|
|
|
|
|
|
|
virtual ConstPoolVal *clone() const { return new ConstPoolType(*this); }
|
|
|
|
virtual string getStrValue() const;
|
|
|
|
virtual bool equals(const ConstPoolVal *V) const;
|
|
|
|
|
|
|
|
inline const Type *getValue() const { return Val; }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//===---------------------------------------------------------------------------
|
|
|
|
// ConstPoolArray - Constant Array Declarations
|
|
|
|
//
|
|
|
|
class ConstPoolArray : public ConstPoolVal {
|
|
|
|
ConstPoolArray(const ConstPoolArray &CPT);
|
|
|
|
public:
|
|
|
|
ConstPoolArray(const ArrayType *T, vector<ConstPoolVal*> &V,
|
|
|
|
const string &Name = "");
|
|
|
|
|
|
|
|
virtual ConstPoolVal *clone() const { return new ConstPoolArray(*this); }
|
|
|
|
virtual string getStrValue() const;
|
|
|
|
virtual bool equals(const ConstPoolVal *V) const;
|
|
|
|
|
2001-07-07 08:36:50 +00:00
|
|
|
inline const vector<Use> &getValues() const { return Operands; }
|
2001-06-06 20:29:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//===---------------------------------------------------------------------------
|
|
|
|
// ConstPoolStruct - Constant Struct Declarations
|
|
|
|
//
|
|
|
|
class ConstPoolStruct : public ConstPoolVal {
|
|
|
|
ConstPoolStruct(const ConstPoolStruct &CPT);
|
|
|
|
public:
|
|
|
|
ConstPoolStruct(const StructType *T, vector<ConstPoolVal*> &V,
|
|
|
|
const string &Name = "");
|
|
|
|
|
|
|
|
virtual ConstPoolVal *clone() const { return new ConstPoolStruct(*this); }
|
|
|
|
virtual string getStrValue() const;
|
|
|
|
virtual bool equals(const ConstPoolVal *V) const;
|
|
|
|
|
2001-07-07 08:36:50 +00:00
|
|
|
inline const vector<Use> &getValues() const { return Operands; }
|
2001-06-06 20:29:01 +00:00
|
|
|
};
|
|
|
|
|
2001-07-20 21:11:07 +00:00
|
|
|
//===---------------------------------------------------------------------------
|
|
|
|
// External functions
|
|
|
|
//
|
|
|
|
|
|
|
|
// Convenience functions to get the value of an integer constant, for an
|
|
|
|
// appropriate integer or non-integer type that can be held in an integer.
|
|
|
|
// The type of the argument must be the following:
|
|
|
|
// GetSignedIntConstantValue: signed integer or bool
|
|
|
|
// GetUnsignedIntConstantValue: unsigned integer, bool, or pointer
|
|
|
|
// GetConstantValueAsSignedInt: any of the above, but the value
|
|
|
|
// must fit into a int64_t.
|
|
|
|
//
|
|
|
|
// isValidConstant is set to true if a valid constant was found.
|
|
|
|
//
|
|
|
|
int64_t GetSignedIntConstantValue (const Value* val, bool& isValidConst);
|
|
|
|
uint64_t GetUnsignedIntConstantValue (const Value* val, bool& isValidConst);
|
|
|
|
int64_t GetConstantValueAsSignedInt (const Value* val, bool& isValidConst);
|
|
|
|
|
|
|
|
//===---------------------------------------------------------------------------
|
|
|
|
|
2001-06-06 20:29:01 +00:00
|
|
|
#endif
|