#ifndef _SYSYF_CONSTANT_H_ #define _SYSYF_CONSTANT_H_ #include "User.h" #include "Value.h" #include "Type.h" namespace SysYF { namespace IR { class Constant : public User { protected: explicit Constant(Ptr ty, const std::string &name = "", unsigned num_ops = 0) : User(ty, name, num_ops) {} void init(Ptr ty, const std::string &name = "", unsigned num_ops = 0) {} // int value; public: ~Constant() = default; }; class ConstantInt : public Constant { private: int value_; explicit ConstantInt(Ptr ty, int val) : Constant(ty,"",0),value_(val) {} void init(Ptr ty, int val); public: static int get_value(Ptr const_val) { return const_val->value_; } int get_value() { return value_; } static Ptr create(int val, Ptr m); static Ptr create(bool val, Ptr m); virtual std::string print() override; }; class ConstantFloat : public Constant { private: float value_; explicit ConstantFloat(Ptr ty,float val) : Constant(ty,"",0),value_(val) {} void init(Ptr ty, float val); public: static float get_value(Ptr const_val) { return const_val->value_; } float get_value() { return value_; } static Ptr create(float val, Ptr m); virtual std::string print() override; }; class ConstantArray : public Constant { private: PtrVec const_array; explicit ConstantArray(Ptr ty, const PtrVec &val); void init(Ptr ty, const PtrVec &val); public: ~ConstantArray() = default; Ptr get_element_value(int index); unsigned get_size_of_array() { return const_array.size(); } static Ptr create(Ptr ty, const PtrVec &val); virtual std::string print() override; }; class ConstantZero : public Constant { private: explicit ConstantZero(Ptr ty) : Constant(ty,"",0) {} void init(Ptr ty); public: static Ptr create(Ptr ty, Ptr m); virtual std::string print() override; }; } } #endif //_SYSYF_CONSTANT_H_