17 #ifndef __CPUI_UNIFY__
18 #define __CPUI_UNIFY__
27 op_type, var_type, const_type, block_type
43 uint4 getType(
void)
const {
return type; }
44 void setOp(
PcodeOp *o) { storespot.op = o; }
45 PcodeOp *getOp(
void)
const {
return storespot.op; }
46 void setVarnode(
Varnode *v) { storespot.vn = v; }
47 Varnode *getVarnode(
void)
const {
return storespot.vn; }
48 void setBlock(
BlockBasic *b) { storespot.bl = b; }
49 BlockBasic *getBlock(
void)
const {
return storespot.bl; }
50 void setConstant(uintb val);
51 uintb getConstant(
void)
const {
return *storespot.cn; }
52 void printVarDecl(ostream &s,int4
id,
const UnifyCPrinter &cprinter)
const;
53 string getBaseName(
void)
const;
62 virtual uintb getConstant(
UnifyState &state)
const=0;
63 virtual void writeExpression(ostream &s,
UnifyCPrinter &printstate)
const=0;
70 int4 getId(
void)
const {
return constindex; }
72 virtual uintb getConstant(
UnifyState &state)
const;
73 virtual void writeExpression(ostream &s,
UnifyCPrinter &printstate)
const;
80 uintb getVal(
void)
const {
return val; }
82 virtual uintb getConstant(
UnifyState &state)
const;
83 virtual void writeExpression(ostream &s,
UnifyCPrinter &printstate)
const;
91 virtual uintb getConstant(
UnifyState &state)
const;
92 virtual void writeExpression(ostream &s,
UnifyCPrinter &printstate)
const;
100 virtual uintb getConstant(
UnifyState &state)
const;
101 virtual void writeExpression(ostream &s,
UnifyCPrinter &printstate)
const;
109 virtual uintb getConstant(
UnifyState &state)
const;
110 virtual void writeExpression(ostream &s,
UnifyCPrinter &printstate)
const;
118 virtual uintb getConstant(
UnifyState &state)
const;
119 virtual void writeExpression(ostream &s,
UnifyCPrinter &printstate)
const;
127 virtual uintb getConstant(
UnifyState &state)
const;
128 virtual void writeExpression(ostream &s,
UnifyCPrinter &printstate)
const;
136 virtual uintb getConstant(
UnifyState &state)
const;
137 virtual void writeExpression(ostream &s,
UnifyCPrinter &printstate)
const;
147 virtual uintb getConstant(
UnifyState &state)
const;
148 virtual void writeExpression(ostream &s,
UnifyCPrinter &printstate)
const;
162 list<PcodeOp *>::const_iterator iter;
163 list<PcodeOp *>::const_iterator enditer;
166 PcodeOp *getCurrentOp(
void)
const {
return *iter; }
167 void initialize(
Varnode *vn) { onestep =
false; iter = vn->beginDescend(); enditer = vn->endDescend(); }
173 return (iter!=enditer); }
181 int4 getState(
void)
const {
return state; }
182 void initialize(int4 end) { state = -1; endstate = end; }
183 bool step(
void) { ++state;
return (state != endstate); }
187 vector<TraverseConstraint *> traverselist;
188 int4 currentconstraint;
194 int4 getCurrentIndex(
void)
const {
return currentconstraint; }
195 void setCurrentIndex(int4 val) { currentconstraint = val; }
196 int4 getState(
void)
const {
return state; }
197 void setState(int4 val) { state = val; }
208 int4 getId(
void)
const {
return uniqid; }
209 int4 getMaxNum(
void) {
return maxnum; }
213 virtual void buildTraverseState(
UnifyState &state);
214 virtual void setId(int4 &
id) { uniqid = id;
id += 1; }
215 virtual void collectTypes(vector<UnifyDatatype> &typelist)
const {}
216 virtual int4 getBaseIndex(
void)
const {
return -1; }
217 virtual void print(ostream &s,
UnifyCPrinter &printstate)
const=0;
218 virtual bool isDummy(
void)
const {
return false; }
219 virtual void removeDummy(
void) {}
227 virtual bool step(
UnifyState &state) {
return true; }
228 virtual void collectTypes(vector<UnifyDatatype> &typelist)
const { typelist[opindex] =
UnifyDatatype(UnifyDatatype::op_type); }
229 virtual int4 getBaseIndex(
void)
const {
return opindex; }
230 virtual void print(ostream &s,
UnifyCPrinter &printstate)
const {}
231 virtual bool isDummy(
void)
const {
return true; }
239 virtual bool step(
UnifyState &state) {
return true; }
240 virtual void collectTypes(vector<UnifyDatatype> &typelist)
const { typelist[varindex] =
UnifyDatatype(UnifyDatatype::var_type); }
241 virtual int4 getBaseIndex(
void)
const {
return varindex; }
242 virtual void print(ostream &s,
UnifyCPrinter &printstate)
const {}
243 virtual bool isDummy(
void)
const {
return true; }
251 virtual bool step(
UnifyState &state) {
return true; }
252 virtual void collectTypes(vector<UnifyDatatype> &typelist)
const { typelist[constindex] =
UnifyDatatype(UnifyDatatype::const_type); }
253 virtual int4 getBaseIndex(
void)
const {
return constindex; }
254 virtual void print(ostream &s,
UnifyCPrinter &printstate)
const {}
255 virtual bool isDummy(
void)
const {
return true; }
266 virtual void print(ostream &s,
UnifyCPrinter &printstate)
const;
278 virtual void collectTypes(vector<UnifyDatatype> &typelist)
const;
279 virtual int4 getBaseIndex(
void)
const {
return varindex; }
280 virtual void print(ostream &s,
UnifyCPrinter &printstate)
const;
291 virtual void collectTypes(vector<UnifyDatatype> &typelist)
const;
292 virtual int4 getBaseIndex(
void)
const {
return constindex; }
293 virtual void print(ostream &s,
UnifyCPrinter &printstate)
const;
300 ConstraintOpCopy(int4 oldind,int4 newind) { oldopindex = oldind; newopindex = newind; maxnum = (oldopindex > newopindex) ? oldopindex : newopindex; }
303 virtual void collectTypes(vector<UnifyDatatype> &typelist)
const;
304 virtual int4 getBaseIndex(
void)
const {
return oldopindex; }
305 virtual void print(ostream &s,
UnifyCPrinter &printstate)
const;
310 vector<OpCode> opcodes;
312 ConstraintOpcode(int4 ind,
const vector<OpCode> &o) { maxnum = opindex = ind; opcodes = o; }
313 const vector<OpCode> &getOpCodes(
void)
const {
return opcodes; }
316 virtual void collectTypes(vector<UnifyDatatype> &typelist)
const;
317 virtual int4 getBaseIndex(
void)
const {
return opindex; }
318 virtual void print(ostream &s,
UnifyCPrinter &printstate)
const;
326 ConstraintOpCompare(int4 op1ind,int4 op2ind,
bool val) { op1index = op1ind; op2index = op2ind; istrue = val; maxnum = (op1index > op2index) ? op1index : op2index; }
329 virtual void collectTypes(vector<UnifyDatatype> &typelist)
const;
330 virtual int4 getBaseIndex(
void)
const {
return op1index; }
331 virtual void print(ostream &s,
UnifyCPrinter &printstate)
const;
339 ConstraintOpInput(int4 oind,int4 vind,int4 sl) { opindex = oind; varnodeindex = vind; slot = sl; maxnum = (opindex > varnodeindex) ? opindex : varnodeindex; }
342 virtual void collectTypes(vector<UnifyDatatype> &typelist)
const;
343 virtual int4 getBaseIndex(
void)
const {
return varnodeindex; }
344 virtual void print(ostream &s,
UnifyCPrinter &printstate)
const;
351 ConstraintOpInputAny(int4 oind,int4 vind) { opindex = oind; varnodeindex = vind; maxnum = (opindex > varnodeindex) ? opindex : varnodeindex; }
355 virtual void collectTypes(vector<UnifyDatatype> &typelist)
const;
356 virtual int4 getBaseIndex(
void)
const {
return varnodeindex; }
357 virtual void print(ostream &s,
UnifyCPrinter &printstate)
const;
364 ConstraintOpOutput(int4 oind,int4 vind) { opindex = oind; varnodeindex = vind; maxnum = (opindex > varnodeindex) ? opindex : varnodeindex; }
367 virtual void collectTypes(vector<UnifyDatatype> &typelist)
const;
368 virtual int4 getBaseIndex(
void)
const {
return varnodeindex; }
369 virtual void print(ostream &s,
UnifyCPrinter &printstate)
const;
380 virtual void collectTypes(vector<UnifyDatatype> &typelist)
const;
381 virtual void print(ostream &s,
UnifyCPrinter &printstate)
const;
389 ConstraintParamConst(int4 oind,int4 sl,int4 cind) { opindex = oind; slot=sl; constindex = cind; maxnum = (opindex > constindex) ? opindex : constindex; }
392 virtual void collectTypes(vector<UnifyDatatype> &typelist)
const;
393 virtual int4 getBaseIndex(
void)
const {
return constindex; }
394 virtual void print(ostream &s,
UnifyCPrinter &printstate)
const;
401 ConstraintVarnodeCopy(int4 oldind,int4 newind) { oldvarindex = oldind; newvarindex = newind; maxnum = (oldvarindex > newvarindex) ? oldvarindex : newvarindex; }
404 virtual void collectTypes(vector<UnifyDatatype> &typelist)
const;
405 virtual int4 getBaseIndex(
void)
const {
return oldvarindex; }
406 virtual void print(ostream &s,
UnifyCPrinter &printstate)
const;
414 ConstraintVarCompare(int4 var1ind,int4 var2ind,
bool val) { var1index = var1ind; var2index = var2ind; istrue = val; maxnum = (var1index > var2index) ? var1index : var2index; }
417 virtual void collectTypes(vector<UnifyDatatype> &typelist)
const;
418 virtual int4 getBaseIndex(
void)
const {
return var1index; }
419 virtual void print(ostream &s,
UnifyCPrinter &printstate)
const;
426 ConstraintDef(int4 oind,int4 vind) { opindex = oind; varindex = vind; maxnum = (opindex > varindex) ? opindex : varindex; }
429 virtual void collectTypes(vector<UnifyDatatype> &typelist)
const;
430 virtual int4 getBaseIndex(
void)
const {
return opindex; }
431 virtual void print(ostream &s,
UnifyCPrinter &printstate)
const;
438 ConstraintDescend(int4 oind,int4 vind) { opindex = oind; varindex = vind; maxnum = (opindex > varindex) ? opindex : varindex; }
440 virtual void buildTraverseState(
UnifyState &state);
443 virtual void collectTypes(vector<UnifyDatatype> &typelist)
const;
444 virtual int4 getBaseIndex(
void)
const {
return opindex; }
445 virtual void print(ostream &s,
UnifyCPrinter &printstate)
const;
452 ConstraintLoneDescend(int4 oind,int4 vind) { opindex = oind; varindex = vind; maxnum = (opindex > varindex) ? opindex : varindex; }
455 virtual void collectTypes(vector<UnifyDatatype> &typelist)
const;
456 virtual int4 getBaseIndex(
void)
const {
return opindex; }
457 virtual void print(ostream &s,
UnifyCPrinter &printstate)
const;
465 ConstraintOtherInput(int4 oind,int4 v_in,int4 v_out) { maxnum = opindex = oind; varindex_in = v_in; varindex_out = v_out;
466 if (varindex_in > maxnum) maxnum = varindex_in;
if (varindex_out > maxnum) maxnum = varindex_out; }
468 virtual int4 getBaseIndex(
void)
const {
return varindex_out; }
470 virtual void collectTypes(vector<UnifyDatatype> &typelist)
const;
471 virtual void print(ostream &s,
UnifyCPrinter &printstate)
const;
480 maxnum = (const1index > const2index) ? const1index : const2index; }
483 virtual void collectTypes(vector<UnifyDatatype> &typelist)
const;
484 virtual int4 getBaseIndex(
void)
const {
return const1index; }
485 virtual void print(ostream &s,
UnifyCPrinter &printstate)
const;
492 vector<UnifyConstraint *> constraintlist;
496 UnifyConstraint *getConstraint(int4 slot)
const {
return constraintlist[slot]; }
498 int4 numConstraints(
void)
const {
return constraintlist.size(); }
499 void deleteConstraint(int4 slot);
504 virtual void collectTypes(vector<UnifyDatatype> &typelist)
const;
505 virtual void buildTraverseState(
UnifyState &state);
506 virtual void setId(int4 &
id);
507 virtual int4 getBaseIndex(
void)
const {
return constraintlist.back()->getBaseIndex(); }
508 virtual void print(ostream &s,
UnifyCPrinter &printstate)
const;
509 virtual void removeDummy(
void);
519 virtual void buildTraverseState(
UnifyState &state);
520 virtual int4 getBaseIndex(
void)
const {
return -1; }
521 virtual void print(ostream &s,
UnifyCPrinter &printstate)
const;
535 virtual int4 getBaseIndex(
void)
const {
return newopindex; }
537 virtual void collectTypes(vector<UnifyDatatype> &typelist)
const;
538 virtual void print(ostream &s,
UnifyCPrinter &printstate)
const;
548 virtual int4 getBaseIndex(
void)
const {
return newvarindex; }
550 virtual void collectTypes(vector<UnifyDatatype> &typelist)
const;
551 virtual void print(ostream &s,
UnifyCPrinter &printstate)
const;
559 ConstraintSetInput(int4 oind,
RHSConstant *sl,int4 varind) { opindex = oind; slot=sl; varindex = varind; maxnum = (opindex > varindex) ? opindex : varindex; }
562 virtual int4 getBaseIndex(
void)
const {
return varindex; }
564 virtual void collectTypes(vector<UnifyDatatype> &typelist)
const;
565 virtual void print(ostream &s,
UnifyCPrinter &printstate)
const;
578 virtual void collectTypes(vector<UnifyDatatype> &typelist)
const;
579 virtual void print(ostream &s,
UnifyCPrinter &printstate)
const;
589 virtual int4 getBaseIndex(
void)
const {
return opindex; }
591 virtual void collectTypes(vector<UnifyDatatype> &typelist)
const;
592 virtual void print(ostream &s,
UnifyCPrinter &printstate)
const;
601 virtual int4 getBaseIndex(
void)
const {
return opindex; }
603 virtual void collectTypes(vector<UnifyDatatype> &typelist)
const;
604 virtual void print(ostream &s,
UnifyCPrinter &printstate)
const;
609 vector<UnifyDatatype> storemap;
610 vector<TraverseConstraint *> traverselist;
615 int4 numTraverse(
void)
const {
return traverselist.size(); }
619 Funcdata *getFunction(
void)
const {
return fd; }
621 void setFunction(
Funcdata *f) { fd = f; }
622 void initialize(int4
id,
Varnode *vn);
623 void initialize(int4
id,
PcodeOp *op);
627 vector<UnifyDatatype> storemap;
628 vector<string> namemap;
633 vector<OpCode> opcodelist;
635 void printGetOpList(ostream &s);
636 void printRuleHeader(ostream &s);
640 int4 getDepth(
void)
const {
return depth; }
641 void incDepth(
void) { depth += 1; }
642 void decDepth(
void) { depth -= 1; }
643 void printIndent(ostream &s)
const {
for(int4 i=0;i<depth+1;++i) s <<
" "; }
644 void printAbort(ostream &s);
645 void popDepth(ostream &s,int4 newdepth);
646 const string &getName(int4
id)
const {
return namemap[id]; }
647 void initializeRuleAction(
ConstraintGroup *g,int4 opparam,
const vector<OpCode> &olist);
649 void setClassName(
const string &nm) { classname = nm; }
650 void addNames(
const map<string,int4> &nmmap);
651 void printVarDecls(ostream &s)
const;
652 void print(ostream &s);