@@ -29,91 +29,94 @@ class EdgeValue {
2929 enum Type { Top, Integer, String, FloatingPoint };
3030
3131private:
32- std::variant<llvm::APInt, llvm::APFloat, std::string, std::nullptr_t > value =
33- nullptr ;
34- Type type ;
32+ std::variant<llvm::APInt, llvm::APFloat, std::string, std::nullptr_t >
33+ ValVariant = nullptr ;
34+ Type VariantType ;
3535
3636public:
37- EdgeValue (const llvm::Value *val );
38- EdgeValue (const EdgeValue &ev );
39- EdgeValue (llvm::APInt &&vi );
40- EdgeValue (const llvm::APInt &vi );
41- EdgeValue (llvm::APFloat &&vf );
42- EdgeValue (long long vi );
43- EdgeValue (int vi );
44- EdgeValue (double d );
45- EdgeValue (float d );
46- EdgeValue (std::string &&vs );
37+ EdgeValue (const llvm::Value *Val );
38+ EdgeValue (const EdgeValue &EV );
39+ EdgeValue (llvm::APInt &&VI );
40+ EdgeValue (const llvm::APInt &VI );
41+ EdgeValue (llvm::APFloat &&VF );
42+ EdgeValue (long long VI );
43+ EdgeValue (int VI );
44+ EdgeValue (double Double );
45+ EdgeValue (float Float );
46+ EdgeValue (std::string &&VS );
4747 EdgeValue (std::nullptr_t );
4848 ~EdgeValue ();
49- const static EdgeValue top ;
50- bool tryGetInt (uint64_t &res ) const ;
51- bool tryGetFP (double &res ) const ;
52- bool tryGetString (std::string &res ) const ;
53- bool isTop () const ;
54- bool isNumeric () const ;
55- bool isString () const ;
56- Type getKind () const ;
49+ const static EdgeValue TopValue ;
50+ [[nodiscard]] bool tryGetInt (uint64_t &Res ) const ;
51+ [[nodiscard]] bool tryGetFP (double &Res ) const ;
52+ [[nodiscard]] bool tryGetString (std::string &Res ) const ;
53+ [[nodiscard]] bool isTop () const ;
54+ [[nodiscard]] bool isNumeric () const ;
55+ [[nodiscard]] bool isString () const ;
56+ [[nodiscard]] Type getKind () const ;
5757 // std::unique_ptr<ObjectLLVM> asObjLLVM(llvm::LLVMContext &ctx) const;
58- bool sqSubsetEq (const EdgeValue &other ) const ;
59- EdgeValue performBinOp (llvm::BinaryOperator::BinaryOps op ,
60- const EdgeValue &other ) const ;
61- EdgeValue typecast (Type dest , unsigned bits ) const ;
62- EdgeValue &operator =(const EdgeValue &ev );
58+ [[nodiscard]] bool sqSubsetEq (const EdgeValue &Other ) const ;
59+ [[nodiscard]] EdgeValue performBinOp (llvm::BinaryOperator::BinaryOps Op ,
60+ const EdgeValue &Other ) const ;
61+ [[nodiscard]] EdgeValue typecast (Type Dest , unsigned Bits ) const ;
62+ EdgeValue &operator =(const EdgeValue &EV );
6363
6464 operator bool ();
65- friend bool operator ==(const EdgeValue &v1 , const EdgeValue &v2 );
65+ friend bool operator ==(const EdgeValue &Lhs , const EdgeValue &Rhs );
6666
6767 // binary operators
68- friend EdgeValue operator +(const EdgeValue &v1 , const EdgeValue &v2 );
69- friend EdgeValue operator -(const EdgeValue &v1 , const EdgeValue &v2 );
70- friend EdgeValue operator *(const EdgeValue &v1 , const EdgeValue &v2 );
71- friend EdgeValue operator /(const EdgeValue &v1 , const EdgeValue &v2 );
72- friend EdgeValue operator %(const EdgeValue &v1 , const EdgeValue &v2 );
73- friend EdgeValue operator &(const EdgeValue &v1 , const EdgeValue &v2 );
74- friend EdgeValue operator |(const EdgeValue &v1 , const EdgeValue &v2 );
75- friend EdgeValue operator ^(const EdgeValue &v1 , const EdgeValue &v2 );
76- friend EdgeValue operator <<(const EdgeValue &v1 , const EdgeValue &v2 );
77- friend EdgeValue operator >>(const EdgeValue &v1 , const EdgeValue &v2 );
78- static int compare (const EdgeValue &v1 , const EdgeValue &v2 );
68+ friend EdgeValue operator +(const EdgeValue &Lhs , const EdgeValue &Rhs );
69+ friend EdgeValue operator -(const EdgeValue &Lhs , const EdgeValue &Rhs );
70+ friend EdgeValue operator *(const EdgeValue &Lhs , const EdgeValue &Rhs );
71+ friend EdgeValue operator /(const EdgeValue &Lhs , const EdgeValue &Rhs );
72+ friend EdgeValue operator %(const EdgeValue &Lhs , const EdgeValue &Rhs );
73+ friend EdgeValue operator &(const EdgeValue &Lhs , const EdgeValue &Rhs );
74+ friend EdgeValue operator |(const EdgeValue &Lhs , const EdgeValue &Rhs );
75+ friend EdgeValue operator ^(const EdgeValue &Lhs , const EdgeValue &Rhs );
76+ friend EdgeValue operator <<(const EdgeValue &Lhs , const EdgeValue &Rhs );
77+ friend EdgeValue operator >>(const EdgeValue &Lhs , const EdgeValue &Rhs );
78+ static int compare (const EdgeValue &Lhs , const EdgeValue &Rhs );
7979
8080 // unary operators
8181 EdgeValue operator -() const ;
8282 EdgeValue operator ~() const ;
83- friend std::ostream &operator <<(std::ostream &os , const EdgeValue &ev );
84- static std::string typeToString (Type ty );
83+ friend std::ostream &operator <<(std::ostream &Os , const EdgeValue &EV );
84+ static std::string typeToString (Type Ty );
8585};
8686class EdgeValueSet ;
8787typedef EdgeValueSet ev_t ;
8888
89- ev_t performBinOp (llvm::BinaryOperator::BinaryOps op , const ev_t &v1 ,
90- const ev_t &v2 , size_t maxSize );
91- ev_t performTypecast (const ev_t &ev , EdgeValue::Type dest , unsigned bits );
92- Ordering compare (const ev_t &v1 , const ev_t &v2 );
93- ev_t join (const ev_t &v1 , const ev_t &v2 , size_t maxSize );
89+ ev_t performBinOp (llvm::BinaryOperator::BinaryOps Op , const ev_t &Lhs ,
90+ const ev_t &Rhs , size_t MaxSize );
91+ ev_t performTypecast (const ev_t &Ev , EdgeValue::Type Dest , unsigned Bits );
92+ Ordering compare (const ev_t &Lhs , const ev_t &Rhs );
93+ ev_t join (const ev_t &Lhs , const ev_t &Rhs , size_t MaxSize );
9494// / \brief implements square subset equal
95- bool operator <(const ev_t &v1 , const ev_t &v2 );
96- bool isTopValue (const ev_t &v );
97- std::ostream &operator <<(std::ostream &os , const ev_t &v );
95+ bool operator <(const ev_t &Lhs , const ev_t &Rhs );
96+ bool isTopValue (const ev_t &Val );
97+ std::ostream &operator <<(std::ostream &Os , const ev_t &Val );
9898
9999} // namespace psr
100100
101101namespace std {
102102
103103template <> struct hash <psr::EdgeValue> {
104- hash () {}
105- size_t operator ()(const psr::EdgeValue &val) const {
106- auto hc = hash<int >()(val.getKind ());
107- uint64_t asInt;
108- double asFloat;
109- string asString;
110- if (val.tryGetInt (asInt))
111- return hash<uint64_t >()(asInt) * 31 + hc;
112- else if (val.tryGetFP (asFloat))
113- return hash<double >()(round (asFloat)) * 31 + hc;
114- else if (val.tryGetString (asString))
115- return hash<string>()(asString) * 31 + hc;
116- return hc;
104+ hash () = default ;
105+ size_t operator ()(const psr::EdgeValue &Val) const {
106+ auto Hash = hash<int >()(Val.getKind ());
107+ uint64_t AsInt;
108+ double AsFloat;
109+ string AsString;
110+ if (Val.tryGetInt (AsInt)) {
111+ return hash<uint64_t >()(AsInt) * 31 + Hash;
112+ }
113+ if (Val.tryGetFP (AsFloat)) {
114+ return hash<double >()(round (AsFloat)) * 31 + Hash;
115+ }
116+ if (Val.tryGetString (AsString)) {
117+ return hash<string>()(AsString) * 31 + Hash;
118+ }
119+ return Hash;
117120 }
118121};
119122
0 commit comments