My Project
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
virtual bool checkIntPromotionForExtension(const PcodeOp *op) const =0
Check if integer promotion forces a cast for the input to the given extension.
The base datatype class for the decompiler.
Definition: type.hh:62
TypeFactory * tlst
Type factory associated with the Architecture.
Definition: cast.hh:54
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.
IntPromotionCode
Types of integer promotion.
Definition: cast.hh:46
The value is promoted using signed extension.
Definition: cast.hh:50
virtual bool checkIntPromotionForCompare(const PcodeOp *op, int4 slot) const =0
Check if integer promotion forces a cast for the given comparison op and slot.
virtual bool isZextCast(Datatype *outtype, Datatype *intype) const =0
Is zero-extending an input data-type, producing an output data-type, considered a cast...
virtual bool isExtensionCastImplied(const PcodeOp *op, const PcodeOp *readOp) const =0
Is the given ZEXT/SEXT cast implied by the expression its in?
void setTypeFactory(TypeFactory *t)
Establish the data-type factory.
Definition: cast.cc:21
virtual Datatype * arithmeticOutputStandard(const PcodeOp *op)=0
What is the output data-type produced by the given integer arithmetic operation.
A strategy for applying type casts.
Definition: cast.hh:40
Lowest level operation of the p-code language.
Definition: op.hh:58
virtual int4 localExtensionType(const Varnode *vn) const =0
Decide on integer promotion by examining just local properties of the given Varnode.
The value is promoted using unsigned extension.
Definition: cast.hh:49
A low-level variable or contiguous set of bytes described by an Address and a size.
Definition: varnode.hh:65
Casting strategies that are specific to the Java language.
Definition: cast.hh:178
CastStrategy(void)
Constructor.
Definition: cast.hh:57
Classes for describing and printing data-types.
The value is promoted using either signed or unsigned extension.
Definition: cast.hh:51
The type of integer promotion cannot be determined.
Definition: cast.hh:48
virtual bool isSextCast(Datatype *outtype, Datatype *intype) const =0
Is sign-extending an input data-type, producing an output data-type, considered a cast...
Casting strategies that are specific to the C language.
Definition: cast.hh:158
int4 promoteSize
Size of int data-type, (size that integers get promoted to)
Definition: cast.hh:55
Container class for all Datatype objects in an Architecture.
Definition: type.hh:380
virtual ~CastStrategy(void)
Destructor.
Definition: cast.hh:59
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.
There is no integer promotion.
Definition: cast.hh:47
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.
virtual int4 intPromotionType(const Varnode *vn) const =0
Calculate the integer promotion code of a given Varnode.