Ghidra Decompiler Analysis Engine
cast.hh
Go to the documentation of this file.
1 /* ###
2  * IP: GHIDRA
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
18 
19 #ifndef __CPUI_CAST__
20 #define __CPUI_CAST__
21 
22 #include "type.hh"
23 
24 class Varnode;
25 class PcodeOp;
26 
40 class CastStrategy {
41 public:
47  NO_PROMOTION = -1,
52  };
53 protected:
55  int4 promoteSize;
56 public:
57  CastStrategy(void) {}
58  void setTypeFactory(TypeFactory *t);
59  virtual ~CastStrategy(void) {}
60 
65  virtual int4 localExtensionType(const Varnode *vn) const=0;
66 
72  virtual int4 intPromotionType(const Varnode *vn) const=0;
73 
81  virtual bool checkIntPromotionForCompare(const PcodeOp *op,int4 slot) const=0;
82 
89  virtual bool checkIntPromotionForExtension(const PcodeOp *op) const=0;
90 
91 
99  virtual bool isExtensionCastImplied(const PcodeOp *op,const PcodeOp *readOp) const=0;
100 
111  virtual Datatype *castStandard(Datatype *reqtype,Datatype *curtype,bool care_uint_int,bool care_ptr_uint) const=0;
112 
117  virtual Datatype *arithmeticOutputStandard(const PcodeOp *op)=0;
118 
126  virtual bool isSubpieceCast(Datatype *outtype,Datatype *intype,uint4 offset) const=0;
127 
138  virtual bool isSubpieceCastEndian(Datatype *outtype,Datatype *intype,uint4 offset,bool isbigend) const=0;
139 
146  virtual bool isSextCast(Datatype *outtype,Datatype *intype) const=0;
147 
154  virtual bool isZextCast(Datatype *outtype,Datatype *intype) const=0;
155 };
156 
158 class CastStrategyC : public CastStrategy {
159 public:
160  virtual int4 localExtensionType(const Varnode *vn) const;
161  virtual int4 intPromotionType(const Varnode *vn) const;
162  virtual bool checkIntPromotionForCompare(const PcodeOp *op,int4 slot) const;
163  virtual bool checkIntPromotionForExtension(const PcodeOp *op) const;
164  virtual bool isExtensionCastImplied(const PcodeOp *op,const PcodeOp *readOp) const;
165  virtual Datatype *castStandard(Datatype *reqtype,Datatype *curtype,bool care_uint_int,bool care_ptr_uint) const;
166  virtual Datatype *arithmeticOutputStandard(const PcodeOp *op);
167  virtual bool isSubpieceCast(Datatype *outtype,Datatype *intype,uint4 offset) const;
168  virtual bool isSubpieceCastEndian(Datatype *outtype,Datatype *intype,uint4 offset,bool isbigend) const;
169  virtual bool isSextCast(Datatype *outtype,Datatype *intype) const;
170  virtual bool isZextCast(Datatype *outtype,Datatype *intype) const;
171 };
172 
179 public:
180  virtual Datatype *castStandard(Datatype *reqtype,Datatype *curtype,bool care_uint_int,bool care_ptr_uint) const;
181  virtual bool isZextCast(Datatype *outtype,Datatype *intype) const;
182 };
183 
184 #endif
CastStrategy::SIGNED_EXTENSION
@ SIGNED_EXTENSION
The value is promoted using signed extension.
Definition: cast.hh:50
CastStrategy::isSubpieceCast
virtual bool isSubpieceCast(Datatype *outtype, Datatype *intype, uint4 offset) const =0
Is truncating an input data-type, producing an output data-type, considered a cast.
CastStrategyJava
Casting strategies that are specific to the Java language.
Definition: cast.hh:178
CastStrategy::setTypeFactory
void setTypeFactory(TypeFactory *t)
Establish the data-type factory.
Definition: cast.cc:21
CastStrategyC::localExtensionType
virtual int4 localExtensionType(const Varnode *vn) const
Decide on integer promotion by examining just local properties of the given Varnode.
Definition: cast.cc:61
CastStrategyC::isSextCast
virtual bool isSextCast(Datatype *outtype, Datatype *intype) const
Is sign-extending an input data-type, producing an output data-type, considered a cast.
Definition: cast.cc:348
CastStrategy::arithmeticOutputStandard
virtual Datatype * arithmeticOutputStandard(const PcodeOp *op)=0
What is the output data-type produced by the given integer arithmetic operation.
CastStrategyC
Casting strategies that are specific to the C language.
Definition: cast.hh:158
CastStrategy::checkIntPromotionForExtension
virtual bool checkIntPromotionForExtension(const PcodeOp *op) const =0
Check if integer promotion forces a cast for the input to the given extension.
CastStrategy::promoteSize
int4 promoteSize
Size of int data-type, (size that integers get promoted to)
Definition: cast.hh:55
CastStrategyC::isExtensionCastImplied
virtual bool isExtensionCastImplied(const PcodeOp *op, const PcodeOp *readOp) const
Is the given ZEXT/SEXT cast implied by the expression its in?
Definition: cast.cc:169
CastStrategy::castStandard
virtual Datatype * castStandard(Datatype *reqtype, Datatype *curtype, bool care_uint_int, bool care_ptr_uint) const =0
Does there need to be a visible cast between the given data-types.
CastStrategyC::isSubpieceCast
virtual bool isSubpieceCast(Datatype *outtype, Datatype *intype, uint4 offset) const
Is truncating an input data-type, producing an output data-type, considered a cast.
Definition: cast.cc:311
CastStrategyC::checkIntPromotionForCompare
virtual bool checkIntPromotionForCompare(const PcodeOp *op, int4 slot) const
Check if integer promotion forces a cast for the given comparison op and slot.
Definition: cast.cc:28
PcodeOp
Lowest level operation of the p-code language.
Definition: op.hh:58
CastStrategyJava::castStandard
virtual Datatype * castStandard(Datatype *reqtype, Datatype *curtype, bool care_uint_int, bool care_ptr_uint) const
Does there need to be a visible cast between the given data-types.
Definition: cast.cc:368
Varnode
A low-level variable or contiguous set of bytes described by an Address and a size.
Definition: varnode.hh:65
CastStrategy::UNKNOWN_PROMOTION
@ UNKNOWN_PROMOTION
The type of integer promotion cannot be determined.
Definition: cast.hh:48
CastStrategy
A strategy for applying type casts.
Definition: cast.hh:40
CastStrategy::intPromotionType
virtual int4 intPromotionType(const Varnode *vn) const =0
Calculate the integer promotion code of a given Varnode.
CastStrategy::isSubpieceCastEndian
virtual bool isSubpieceCastEndian(Datatype *outtype, Datatype *intype, uint4 offset, bool isbigend) const =0
Is the given data-type truncation considered a cast, given endianess concerns.
Datatype
The base datatype class for the decompiler.
Definition: type.hh:62
TypeFactory
Container class for all Datatype objects in an Architecture.
Definition: type.hh:396
CastStrategy::isZextCast
virtual bool isZextCast(Datatype *outtype, Datatype *intype) const =0
Is zero-extending an input data-type, producing an output data-type, considered a cast.
CastStrategyC::isZextCast
virtual bool isZextCast(Datatype *outtype, Datatype *intype) const
Is zero-extending an input data-type, producing an output data-type, considered a cast.
Definition: cast.cc:358
CastStrategyC::isSubpieceCastEndian
virtual bool isSubpieceCastEndian(Datatype *outtype, Datatype *intype, uint4 offset, bool isbigend) const
Is the given data-type truncation considered a cast, given endianess concerns.
Definition: cast.cc:339
CastStrategyC::checkIntPromotionForExtension
virtual bool checkIntPromotionForExtension(const PcodeOp *op) const
Check if integer promotion forces a cast for the input to the given extension.
Definition: cast.cc:47
CastStrategy::isExtensionCastImplied
virtual bool isExtensionCastImplied(const PcodeOp *op, const PcodeOp *readOp) const =0
Is the given ZEXT/SEXT cast implied by the expression its in?
CastStrategy::checkIntPromotionForCompare
virtual bool checkIntPromotionForCompare(const PcodeOp *op, int4 slot) const =0
Check if integer promotion forces a cast for the given comparison op and slot.
type.hh
Classes for describing and printing data-types.
CastStrategyC::intPromotionType
virtual int4 intPromotionType(const Varnode *vn) const
Calculate the integer promotion code of a given Varnode.
Definition: cast.cc:98
CastStrategy::UNSIGNED_EXTENSION
@ UNSIGNED_EXTENSION
The value is promoted using unsigned extension.
Definition: cast.hh:49
CastStrategyJava::isZextCast
virtual bool isZextCast(Datatype *outtype, Datatype *intype) const
Is zero-extending an input data-type, producing an output data-type, considered a cast.
Definition: cast.cc:426
CastStrategyC::castStandard
virtual Datatype * castStandard(Datatype *reqtype, Datatype *curtype, bool care_uint_int, bool care_ptr_uint) const
Does there need to be a visible cast between the given data-types.
Definition: cast.cc:220
CastStrategy::isSextCast
virtual bool isSextCast(Datatype *outtype, Datatype *intype) const =0
Is sign-extending an input data-type, producing an output data-type, considered a cast.
CastStrategy::localExtensionType
virtual int4 localExtensionType(const Varnode *vn) const =0
Decide on integer promotion by examining just local properties of the given Varnode.
CastStrategy::tlst
TypeFactory * tlst
Type factory associated with the Architecture.
Definition: cast.hh:54
CastStrategyC::arithmeticOutputStandard
virtual Datatype * arithmeticOutputStandard(const PcodeOp *op)
What is the output data-type produced by the given integer arithmetic operation.
Definition: cast.cc:294
CastStrategy::IntPromotionCode
IntPromotionCode
Types of integer promotion.
Definition: cast.hh:46
CastStrategy::EITHER_EXTENSION
@ EITHER_EXTENSION
The value is promoted using either signed or unsigned extension.
Definition: cast.hh:51
CastStrategy::NO_PROMOTION
@ NO_PROMOTION
There is no integer promotion.
Definition: cast.hh:47