00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef _STATEMENT_H_
00034 #define _STATEMENT_H_
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 #include <vector>
00047 #include <set>
00048 #include <list>
00049 #include <map>
00050 #include <ostream>
00051 #include <iostream>
00052 #include <assert.h>
00053
00054 #include "memo.h"
00055 #include "exphelp.h"
00056 #include "types.h"
00057 #include "managed.h"
00058 #include "dataflow.h"
00059 #include "boomerang.h"
00060
00061 class BasicBlock;
00062 typedef BasicBlock *PBB;
00063 class Prog;
00064 class Proc;
00065 class UserProc;
00066 class Exp;
00067 class Const;
00068 class RefExp;
00069 class Cfg;
00070 class Type;
00071 class Statement;
00072 class Signature;
00073 class StmtVisitor;
00074 class StmtExpVisitor;
00075 class StmtModifier;
00076 class StmtPartModifier;
00077 class HLLCode;
00078 class Assign;
00079 class RTL;
00080 class XMLProgParser;
00081 class ReturnStatement;
00082
00083 typedef std::set<UserProc*> CycleSet;
00084
00085
00086
00087
00088
00089 enum STMT_KIND {
00090 STMT_ASSIGN = 0,
00091 STMT_PHIASSIGN,
00092 STMT_IMPASSIGN,
00093 STMT_BOOLASSIGN,
00094
00095 STMT_CALL,
00096 STMT_RET,
00097 STMT_BRANCH,
00098 STMT_GOTO,
00099 STMT_CASE,
00100 STMT_IMPREF,
00101 STMT_JUNCTION
00102 };
00103
00104
00105
00106
00107
00108
00109 enum BRANCH_TYPE {
00110 BRANCH_JE = 0,
00111 BRANCH_JNE,
00112 BRANCH_JSL,
00113 BRANCH_JSLE,
00114 BRANCH_JSGE,
00115 BRANCH_JSG,
00116 BRANCH_JUL,
00117 BRANCH_JULE,
00118 BRANCH_JUGE,
00119 BRANCH_JUG,
00120 BRANCH_JMI,
00121 BRANCH_JPOS,
00122 BRANCH_JOF,
00123 BRANCH_JNOF,
00124 BRANCH_JPAR
00125 };
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136 class Statement {
00137 protected:
00138 PBB pbb;
00139 UserProc *proc;
00140 int number;
00141 #if USE_DOMINANCE_NUMS
00142 int dominanceNum;
00143 public:
00144 int getDomNumber() {return dominanceNum;}
00145 void setDomNumber(int dn) {dominanceNum = dn;}
00146 protected:
00147 #endif
00148 STMT_KIND kind;
00149 Statement *parent;
00150 RangeMap ranges;
00151 RangeMap savedInputRanges;
00152
00153 unsigned int lexBegin, lexEnd;
00154
00155 public:
00156
00157 Statement() : pbb(NULL), proc(NULL), number(0), parent(NULL) { }
00158 virtual ~Statement() { }
00159
00160
00161 PBB getBB() { return pbb; }
00162 void setBB(PBB bb) {pbb = bb; }
00163
00164
00165
00166 void setProc(UserProc *p);
00167 UserProc* getProc() {return proc;}
00168
00169 int getNumber() {return number;}
00170 virtual void setNumber(int num) {number = num;}
00171
00172 STMT_KIND getKind() { return kind;}
00173 void setKind(STMT_KIND k) {kind = k;}
00174
00175 void setParent(Statement* par) {parent = par;}
00176 Statement* getParent() {return parent;}
00177
00178 RangeMap &getRanges() { return ranges; }
00179 void clearRanges() { ranges.clear(); }
00180
00181 virtual Statement* clone() = 0;
00182
00183
00184 virtual bool accept(StmtVisitor* visitor) = 0;
00185 virtual bool accept(StmtExpVisitor* visitor) = 0;
00186 virtual bool accept(StmtModifier* visitor) = 0;
00187 virtual bool accept(StmtPartModifier* visitor) = 0;
00188
00189 void setLexBegin(unsigned int n) { lexBegin = n; }
00190 void setLexEnd(unsigned int n) { lexEnd = n; }
00191 unsigned int getLexBegin() { return lexBegin; }
00192 unsigned int getLexEnd() { return lexEnd; }
00193 Exp *getExpAtLex(unsigned int begin, unsigned int end);
00194
00195
00196
00197 virtual bool isDefinition() = 0;
00198
00199
00200 bool isNullStatement();
00201
00202 virtual bool isTyping() {return false;}
00203
00204 bool isAssign() {return kind == STMT_ASSIGN;}
00205
00206 bool isAssignment() {return kind == STMT_ASSIGN || kind == STMT_PHIASSIGN ||
00207 kind == STMT_IMPASSIGN || kind == STMT_BOOLASSIGN;}
00208
00209 bool isPhi() {return kind == STMT_PHIASSIGN; }
00210
00211 bool isImplicit() {return kind == STMT_IMPASSIGN;}
00212
00213 bool isFlagAssgn();
00214
00215 bool isImpRef() {return kind == STMT_IMPREF;}
00216
00217 virtual bool isGoto() { return kind == STMT_GOTO; }
00218 virtual bool isBranch() { return kind == STMT_BRANCH; }
00219
00220
00221 bool isJunction() { return kind == STMT_JUNCTION; }
00222
00223
00224 bool isCall() { return kind == STMT_CALL; }
00225
00226
00227 bool isBool() { return kind == STMT_BOOLASSIGN; }
00228
00229
00230 bool isReturn() { return kind == STMT_RET; }
00231
00232
00233
00234 bool isHL_ICT() {return kind == STMT_CASE; }
00235
00236 bool isCase() {return kind == STMT_CASE; }
00237
00238
00239 bool isFpush();
00240 bool isFpop();
00241
00242
00243
00244 virtual void getDefinitions(LocationSet &def) {}
00245
00246
00247 virtual void setLeftFor(Exp* forExp, Exp* newExp) {assert(0);}
00248 virtual bool definesLoc(Exp* loc) {return false;}
00249
00250
00251 virtual bool usesExp(Exp *e) = 0;
00252
00253
00254 virtual void print(std::ostream &os, bool html = false) = 0;
00255 void printAsUse(std::ostream &os) {os << std::dec << number;}
00256 void printAsUseBy(std::ostream &os) {os << std::dec << number;}
00257 void printNum(std::ostream &os) {os << std::dec << number;}
00258 char* prints();
00259 void dump();
00260
00261
00262 virtual bool search(Exp *search, Exp *&result) = 0;
00263 virtual bool searchAll(Exp* search, std::list<Exp*>& result) = 0;
00264
00265
00266 virtual bool searchAndReplace(Exp *search, Exp *replace, bool cc = false) = 0;
00267
00268
00269 static bool canPropagateToExp(Exp* e);
00270
00271
00272
00273
00274
00275 bool propagateTo(bool& convert, std::map<Exp*, int, lessExpStar>* destCounts = NULL,
00276 LocationSet* usedByDomPhi = NULL, bool force = false);
00277 bool propagateFlagsTo();
00278
00279
00280 virtual void generateCode(HLLCode *hll, BasicBlock *pbb, int indLevel) = 0;
00281
00282
00283 virtual void simplify() = 0;
00284
00285
00286
00287 virtual void simplifyAddr() {}
00288
00289
00290 void mapRegistersToLocals();
00291
00292
00293 void replaceSubscriptsWithLocals();
00294
00295
00296 void insertCasts();
00297
00298
00299
00300 virtual void fixSuccessor() {}
00301
00302
00303 virtual void genConstraints(LocationSet& cons) {}
00304
00305
00306 virtual void dfaTypeAnalysis(bool& ch) {}
00307 Type* meetWithFor(Type* ty, Exp* e, bool& ch);
00308
00309
00310 protected:
00311 void updateRanges(RangeMap &output, std::list<Statement*> &execution_paths, bool notTaken = false);
00312 public:
00313 RangeMap &getSavedInputRanges() { return savedInputRanges; }
00314 RangeMap getInputRanges();
00315 virtual void rangeAnalysis(std::list<Statement*> &execution_paths);
00316
00317
00318 bool isFirstStatementInBB();
00319 bool isLastStatementInBB();
00320 Statement* getNextStatementInBB();
00321 Statement* getPreviousStatementInBB();
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332 void addUsedLocs(LocationSet& used, bool cc = false, bool memOnly = false);
00333
00334 bool addUsedLocals(LocationSet& used);
00335
00336 void bypass();
00337
00338
00339
00340
00341 bool replaceRef(Exp* e, Assign *def, bool& convert);
00342
00343
00344 void findConstants(std::list<Const*>& lc);
00345
00346
00347 int setConscripts(int n);
00348 void clearConscripts();
00349
00350
00351 void stripSizes();
00352
00353
00354 void subscriptVar(Exp* e, Statement* def );
00355
00356
00357 bool castConst(int num, Type* ty);
00358
00359
00360 void dfaMapLocals();
00361
00362
00363
00364
00365
00366
00367 virtual Type* getTypeFor(Exp* e) { return NULL;}
00368
00369 virtual void setTypeFor(Exp* e, Type* ty) {assert(0);}
00370
00371
00372
00373
00374 bool doPropagateTo(Exp* e, Assign* def, bool& convert);
00375 bool calcMayAlias(Exp *e1, Exp *e2, int size);
00376 bool mayAlias(Exp *e1, Exp *e2, int size);
00377
00378 friend class XMLProgParser;
00379 };
00380
00381
00382 std::ostream& operator<<(std::ostream& os, Statement* p);
00383 std::ostream& operator<<(std::ostream& os, StatementSet* p);
00384 std::ostream& operator<<(std::ostream& os, LocationSet* p);
00385
00386
00387
00388
00389
00390 class TypingStatement : public Statement {
00391 protected:
00392 Type* type;
00393 public:
00394 TypingStatement(Type* ty);
00395
00396
00397 Type* getType() {return type;}
00398 void setType(Type* ty) {type = ty;}
00399
00400 virtual bool isTyping() {return true;}
00401 };
00402
00403
00404
00405
00406 class Assignment : public TypingStatement {
00407 protected:
00408 Exp* lhs;
00409 public:
00410
00411 Assignment(Exp* lhs);
00412
00413 Assignment(Type* ty, Exp* lhs);
00414
00415 virtual ~Assignment();
00416
00417
00418 virtual Statement* clone() = 0;
00419
00420
00421
00422
00423 bool operator<(const Assignment& o) {return lhs < o.lhs;}
00424
00425
00426 virtual bool accept(StmtVisitor* visitor) = 0;
00427 virtual bool accept(StmtExpVisitor* visitor) = 0;
00428 virtual bool accept(StmtModifier* visitor) = 0;
00429 virtual bool accept(StmtPartModifier* visitor) = 0;
00430
00431 virtual void print(std::ostream& os, bool html = false);
00432 virtual void printCompact(std::ostream& os, bool html = false) = 0;
00433
00434 virtual Type* getTypeFor(Exp* e);
00435 virtual void setTypeFor(Exp* e, Type* ty);
00436
00437 virtual bool usesExp(Exp *e);
00438
00439 virtual bool isDefinition() { return true; }
00440 virtual void getDefinitions(LocationSet &defs);
00441 virtual bool definesLoc(Exp* loc);
00442
00443
00444 virtual Exp* getLeft() { return lhs; }
00445 virtual void setLeftFor(Exp* forExp, Exp* newExp) {lhs = newExp; }
00446
00447
00448 void setLeft(Exp* e) { lhs = e; }
00449
00450
00451 int getMemDepth();
00452
00453
00454 virtual bool search(Exp *search, Exp *&result) = 0;
00455 virtual bool searchAll(Exp* search, std::list<Exp*>& result) = 0;
00456
00457
00458 virtual bool searchAndReplace(Exp *search, Exp *replace, bool cc = false) = 0;
00459
00460 void generateCode(HLLCode *hll, BasicBlock *pbb, int indLevel) {}
00461
00462
00463 virtual void simplify() = 0;
00464
00465
00466 virtual void simplifyAddr();
00467
00468
00469 virtual void genConstraints(LocationSet& cons);
00470
00471
00472 void dfaTypeAnalysis(bool& ch);
00473
00474 friend class XMLProgParser;
00475 };
00476
00477
00478
00479 class Assign : public Assignment {
00480 Exp* rhs;
00481 Exp* guard;
00482
00483 public:
00484
00485 Assign(Exp* lhs, Exp* rhs, Exp* guard = NULL);
00486
00487 Assign(Type* ty, Exp* lhs, Exp* rhs, Exp* guard = NULL);
00488
00489 Assign() : Assignment(NULL), rhs(NULL), guard(NULL) {}
00490
00491 Assign(Assign& o);
00492
00493 ~Assign() {}
00494
00495
00496 virtual Statement* clone();
00497
00498
00499 virtual Exp* getRight() { return rhs; }
00500 Exp*& getRightRef() { return rhs; }
00501
00502
00503 void setRight(Exp* e) { rhs = e; }
00504
00505
00506
00507
00508 virtual bool accept(StmtVisitor* visitor);
00509 virtual bool accept(StmtExpVisitor* visitor);
00510 virtual bool accept(StmtModifier* visitor);
00511 virtual bool accept(StmtPartModifier* visitor);
00512
00513 virtual void printCompact(std::ostream& os, bool html = false);
00514
00515
00516 void setGuard(Exp* g) {guard = g;}
00517 Exp* getGuard() {return guard;}
00518 bool isGuarded() {return guard != NULL;}
00519
00520 virtual bool usesExp(Exp *e);
00521 virtual bool isDefinition() { return true; }
00522
00523
00524 virtual bool search(Exp* search, Exp*& result);
00525 virtual bool searchAll(Exp* search, std::list<Exp*>& result);
00526
00527
00528 virtual bool searchAndReplace(Exp *search, Exp *replace, bool cc = false);
00529
00530
00531 int getMemDepth();
00532
00533
00534 virtual void generateCode(HLLCode *hll, BasicBlock *pbb, int indLevel);
00535
00536
00537 virtual void simplify();
00538
00539
00540 virtual void simplifyAddr();
00541
00542
00543 virtual void fixSuccessor();
00544
00545
00546 virtual void genConstraints(LocationSet& cons);
00547
00548
00549 void dfaTypeAnalysis(bool& ch);
00550
00551
00552 void rangeAnalysis(std::list<Statement*> &execution_paths);
00553
00554
00555 bool match(const char *pattern, std::map<std::string, Exp*> &bindings);
00556
00557 friend class XMLProgParser;
00558 };
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572 struct PhiInfo {
00573
00574
00575 PhiInfo() : def(0), e(0) {}
00576 Statement* def;
00577 Exp* e;
00578 };
00579 class PhiAssign : public Assignment {
00580 public:
00581 typedef std::vector<PhiInfo> Definitions;
00582 typedef Definitions::iterator iterator;
00583 private:
00584 Definitions defVec;
00585 public:
00586
00587 PhiAssign(Exp* lhs)
00588 : Assignment(lhs) {kind = STMT_PHIASSIGN;}
00589
00590 PhiAssign(Type* ty, Exp* lhs)
00591 : Assignment(ty, lhs) {kind = STMT_PHIASSIGN;}
00592
00593 PhiAssign(Assign& o);
00594
00595 virtual ~PhiAssign() {}
00596
00597
00598 virtual Statement* clone();
00599
00600
00601 virtual Exp* getRight() { return NULL; }
00602
00603
00604 virtual bool accept(StmtVisitor* visitor);
00605 virtual bool accept(StmtExpVisitor* visitor);
00606 virtual bool accept(StmtModifier* visitor);
00607 virtual bool accept(StmtPartModifier* visitor);
00608
00609 virtual void printCompact(std::ostream& os, bool html = false);
00610
00611
00612 virtual bool search(Exp* search, Exp*& result);
00613 virtual bool searchAll(Exp* search, std::list<Exp*>& result);
00614
00615
00616 virtual bool searchAndReplace(Exp *search, Exp *replace, bool cc = false);
00617
00618
00619 virtual void simplify();
00620
00621
00622 virtual void genConstraints(LocationSet& cons);
00623
00624
00625 void dfaTypeAnalysis(bool& ch);
00626
00627
00628
00629
00630
00631
00632 Statement* getStmtAt(int idx) {return defVec[idx].def;}
00633 PhiInfo& getAt(int idx) {return defVec[idx];}
00634 void putAt(int idx, Statement* d, Exp* e);
00635 void simplifyRefs();
00636 virtual int getNumDefs() {return defVec.size();}
00637 Definitions& getDefs() {return defVec;}
00638
00639 bool hasGlobalFuncParam();
00640
00641 iterator begin() {return defVec.begin();}
00642 iterator end() {return defVec.end();}
00643 iterator erase(iterator it) {return defVec.erase(it);}
00644
00645
00646 void convertToAssign(Exp* rhs);
00647
00648
00649 void enumerateParams(std::list<Exp*>& le);
00650
00651 protected:
00652 friend class XMLProgParser;
00653 };
00654
00655
00656
00657 class ImplicitAssign : public Assignment {
00658 public:
00659
00660 ImplicitAssign(Exp* lhs);
00661
00662 ImplicitAssign(Type* ty, Exp* lhs);
00663
00664 ImplicitAssign(ImplicitAssign& o);
00665
00666 virtual ~ImplicitAssign();
00667
00668
00669 virtual Statement* clone();
00670
00671
00672 void dfaTypeAnalysis(bool& ch);
00673
00674
00675 virtual bool search(Exp* search, Exp*& result);
00676 virtual bool searchAll(Exp* search, std::list<Exp*>& result);
00677
00678
00679 virtual bool searchAndReplace(Exp *search, Exp *replace, bool cc = false);
00680
00681 virtual void printCompact(std::ostream& os, bool html = false);
00682
00683
00684 virtual Exp* getRight() { return NULL; }
00685 virtual void simplify() {}
00686
00687
00688 virtual bool accept(StmtVisitor* visitor);
00689 virtual bool accept(StmtExpVisitor* visitor);
00690 virtual bool accept(StmtModifier* visitor);
00691 virtual bool accept(StmtPartModifier* visitor);
00692
00693 };
00694
00695
00696
00697
00698
00699 class BoolAssign: public Assignment {
00700 BRANCH_TYPE jtCond;
00701 Exp* pCond;
00702
00703 bool bFloat;
00704 int size;
00705 public:
00706 BoolAssign(int size);
00707 virtual ~BoolAssign();
00708
00709
00710 virtual Statement* clone();
00711
00712
00713 virtual bool accept(StmtVisitor* visitor);
00714 virtual bool accept(StmtExpVisitor* visitor);
00715 virtual bool accept(StmtModifier* visitor);
00716 virtual bool accept(StmtPartModifier* visitor);
00717
00718
00719
00720 void setCondType(BRANCH_TYPE cond, bool usesFloat = false);
00721 BRANCH_TYPE getCond(){return jtCond;}
00722 bool isFloat(){return bFloat;}
00723 void setFloat(bool b) { bFloat = b; }
00724
00725
00726 Exp* getCondExpr();
00727 void setCondExpr(Exp* pss);
00728
00729 void setCondExprND(Exp* e) { pCond = e; }
00730
00731 int getSize() {return size;}
00732 void makeSigned();
00733
00734 virtual void printCompact(std::ostream& os = std::cout, bool html = false);
00735
00736
00737 virtual void generateCode(HLLCode *hll, BasicBlock *pbb, int indLevel);
00738
00739
00740 virtual void simplify();
00741
00742
00743 virtual bool isDefinition() { return true; }
00744 virtual void getDefinitions(LocationSet &def);
00745 virtual Exp* getRight() { return getCondExpr(); }
00746 virtual bool usesExp(Exp *e);
00747 virtual bool search(Exp *search, Exp *&result);
00748 virtual bool searchAll(Exp* search, std::list<Exp*>& result);
00749 virtual bool searchAndReplace(Exp *search, Exp *replace, bool cc = false);
00750
00751 void setLeftFromList(std::list<Statement*>* stmts);
00752
00753 virtual void dfaTypeAnalysis(bool& ch);
00754
00755 friend class XMLProgParser;
00756 };
00757
00758
00759
00760
00761 class ImpRefStatement : public TypingStatement {
00762 Exp* addressExp;
00763 public:
00764
00765 ImpRefStatement(Type* ty, Exp* a) : TypingStatement(ty), addressExp(a) {
00766 kind = STMT_IMPREF;
00767 }
00768 Exp* getAddressExp() {return addressExp;}
00769 Type* getType() {return type;}
00770 void meetWith(Type* ty, bool& ch);
00771
00772
00773 virtual Statement* clone();
00774 virtual bool accept(StmtVisitor*);
00775 virtual bool accept(StmtExpVisitor*);
00776 virtual bool accept(StmtModifier*);
00777 virtual bool accept(StmtPartModifier*);
00778 virtual bool isDefinition() {return false;}
00779 virtual bool usesExp(Exp*) {return false;}
00780 virtual bool search(Exp*, Exp*&);
00781 virtual bool searchAll(Exp*, std::list<Exp*, std::allocator<Exp*> >&);
00782 virtual bool searchAndReplace(Exp*, Exp*, bool cc = false);
00783 virtual void generateCode(HLLCode*, BasicBlock*, int) {}
00784 virtual void simplify();
00785 virtual void print(std::ostream& os, bool html = false);
00786
00787 };
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799 class GotoStatement: public Statement {
00800 protected:
00801 Exp* pDest;
00802
00803 bool m_isComputed;
00804
00805
00806 public:
00807 GotoStatement();
00808 GotoStatement(ADDRESS jumpDest);
00809 virtual ~GotoStatement();
00810
00811
00812 virtual Statement* clone();
00813
00814
00815 virtual bool accept(StmtVisitor* visitor);
00816 virtual bool accept(StmtExpVisitor* visitor);
00817 virtual bool accept(StmtModifier* visitor);
00818 virtual bool accept(StmtPartModifier* visitor);
00819
00820
00821
00822 void setDest(Exp* pd);
00823 void setDest(ADDRESS addr);
00824 virtual Exp* getDest();
00825
00826
00827 ADDRESS getFixedDest();
00828
00829
00830 void adjustFixedDest(int delta);
00831
00832
00833
00834 void setIsComputed(bool b = true);
00835 bool isComputed();
00836
00837 virtual void print(std::ostream& os = std::cout, bool html = false);
00838
00839
00840 virtual bool search(Exp*, Exp*&);
00841
00842
00843 virtual bool searchAndReplace(Exp* search, Exp* replace, bool cc = false);
00844
00845
00846
00847 virtual bool searchAll(Exp* search, std::list<Exp*> &result);
00848
00849
00850 virtual void generateCode(HLLCode *hll, BasicBlock *pbb, int indLevel);
00851
00852
00853 virtual void simplify();
00854
00855
00856 virtual bool isDefinition() { return false;}
00857 virtual bool usesExp(Exp*);
00858
00859 friend class XMLProgParser;
00860 };
00861
00862 class JunctionStatement: public Statement {
00863 public:
00864 JunctionStatement() { kind = STMT_JUNCTION; }
00865
00866 Statement* clone() { return new JunctionStatement(); }
00867
00868
00869 bool accept(StmtVisitor* visitor);
00870 bool accept(StmtExpVisitor* visitor);
00871 bool accept(StmtModifier* visitor);
00872 bool accept(StmtPartModifier* visitor);
00873
00874
00875 bool isDefinition() { return false; }
00876
00877 bool usesExp(Exp *e) { return false; }
00878
00879 void print(std::ostream &os, bool html = false);
00880
00881
00882 bool search(Exp *search, Exp *&result) { return false; }
00883 bool searchAll(Exp* search, std::list<Exp*>& result) { return false; }
00884
00885
00886 bool searchAndReplace(Exp *search, Exp *replace, bool cc = false) { return false; }
00887
00888
00889 void generateCode(HLLCode *hll, BasicBlock *pbb, int indLevel) { }
00890
00891
00892 void simplify() { }
00893
00894 void rangeAnalysis(std::list<Statement*> &execution_paths);
00895 bool isLoopJunction();
00896 };
00897
00898
00899
00900
00901 class BranchStatement: public GotoStatement {
00902 BRANCH_TYPE jtCond;
00903 Exp* pCond;
00904 bool bFloat;
00905
00906
00907 int size;
00908 RangeMap ranges2;
00909
00910 public:
00911 BranchStatement();
00912 virtual ~BranchStatement();
00913
00914
00915 virtual Statement* clone();
00916
00917
00918 virtual bool accept(StmtVisitor* visitor);
00919 virtual bool accept(StmtExpVisitor* visitor);
00920 virtual bool accept(StmtModifier* visitor);
00921 virtual bool accept(StmtPartModifier* visitor);
00922
00923
00924
00925 void setCondType(BRANCH_TYPE cond, bool usesFloat = false);
00926 BRANCH_TYPE getCond(){ return jtCond; }
00927 bool isFloat(){ return bFloat; }
00928 void setFloat(bool b) { bFloat = b; }
00929
00930
00931 Exp* getCondExpr();
00932 void setCondExpr(Exp* pe);
00933
00934 void setCondExprND(Exp* e) { pCond = e; }
00935
00936 PBB getFallBB();
00937 PBB getTakenBB();
00938 void setFallBB(PBB bb);
00939 void setTakenBB(PBB bb);
00940
00941
00942
00943 void makeSigned();
00944
00945 virtual void print(std::ostream& os = std::cout, bool html = false);
00946
00947
00948 virtual bool search(Exp *search, Exp *&result);
00949
00950
00951 virtual bool searchAndReplace(Exp* search, Exp* replace, bool cc = false);
00952
00953
00954
00955 virtual bool searchAll(Exp* search, std::list<Exp*> &result);
00956
00957
00958 virtual void generateCode(HLLCode *hll, BasicBlock *pbb, int indLevel);
00959
00960
00961 virtual bool usesExp(Exp *e);
00962
00963
00964 void rangeAnalysis(std::list<Statement*> &execution_paths);
00965 RangeMap &getRangesForOutEdgeTo(PBB out);
00966 RangeMap &getRanges2Ref() { return ranges2; }
00967 void setRanges2(RangeMap &r) { ranges2 = r; }
00968 void limitOutputWithCondition(RangeMap &output, Exp *e);
00969
00970
00971 virtual void simplify();
00972
00973
00974 virtual void genConstraints(LocationSet& cons);
00975
00976
00977 void dfaTypeAnalysis(bool& ch);
00978
00979 friend class XMLProgParser;
00980 };
00981
00982
00983
00984
00985
00986 struct SWITCH_INFO {
00987 Exp* pSwitchVar;
00988 char chForm;
00989 int iLower;
00990 int iUpper;
00991 ADDRESS uTable;
00992 int iNumTable;
00993 int iOffset;
00994
00995 };
00996
00997 class CaseStatement: public GotoStatement {
00998 SWITCH_INFO* pSwitchInfo;
00999 public:
01000 CaseStatement();
01001 virtual ~CaseStatement();
01002
01003
01004 virtual Statement* clone();
01005
01006
01007 virtual bool accept(StmtVisitor* visitor);
01008 virtual bool accept(StmtExpVisitor* visitor);
01009 virtual bool accept(StmtModifier* visitor);
01010 virtual bool accept(StmtPartModifier* visitor);
01011
01012
01013 SWITCH_INFO* getSwitchInfo();
01014 void setSwitchInfo(SWITCH_INFO* pss);
01015
01016 virtual void print(std::ostream& os = std::cout, bool html = false);
01017
01018
01019 virtual bool searchAndReplace(Exp* search, Exp* replace, bool cc = false);
01020
01021
01022
01023 virtual bool searchAll(Exp* search, std::list<Exp*> &result);
01024
01025
01026 virtual void generateCode(HLLCode *hll, BasicBlock *pbb, int indLevel);
01027
01028
01029 virtual bool usesExp(Exp *e);
01030 public:
01031
01032
01033 virtual void simplify();
01034
01035 friend class XMLProgParser;
01036 };
01037
01038
01039
01040
01041 class CallStatement: public GotoStatement {
01042 bool returnAfterCall;
01043
01044
01045 StatementList arguments;
01046
01047
01048
01049
01050 StatementList defines;
01051
01052
01053
01054
01055 Proc* procDest;
01056
01057
01058
01059 Signature* signature;
01060
01061
01062
01063 UseCollector useCol;
01064
01065
01066
01067 DefCollector defCol;
01068
01069
01070
01071
01072 ReturnStatement* calleeReturn;
01073
01074 public:
01075 CallStatement();
01076 virtual ~CallStatement();
01077
01078 virtual void setNumber(int num);
01079
01080 virtual Statement* clone();
01081
01082
01083 virtual bool accept(StmtVisitor* visitor);
01084 virtual bool accept(StmtExpVisitor* visitor);
01085 virtual bool accept(StmtModifier* visitor);
01086 virtual bool accept(StmtPartModifier* visitor);
01087
01088 void setArguments(StatementList& args);
01089
01090
01091
01092 void setSigArguments();
01093 StatementList& getArguments() {return arguments;}
01094 void updateArguments();
01095
01096 int findDefine(Exp *e);
01097 void removeDefine(Exp *e);
01098 void addDefine(ImplicitAssign* as);
01099
01100
01101
01102 void updateDefines();
01103 StatementList* calcResults();
01104 ReturnStatement* getCalleeReturn() {return calleeReturn; }
01105 void setCalleeReturn(ReturnStatement* ret) {calleeReturn = ret;}
01106 bool isChildless();
01107 Exp *getProven(Exp *e);
01108 Signature* getSignature() {return signature;}
01109
01110
01111
01112 Exp *localiseExp(Exp *e);
01113 void localiseComp(Exp* e);
01114
01115
01116 Exp* bypassRef(RefExp* r, bool& ch);
01117 void clearUseCollector() {useCol.clear();}
01118 void addArgument(Exp *e, UserProc* proc);
01119 Exp* findDefFor(Exp* e);
01120 Exp* getArgumentExp(int i);
01121 void setArgumentExp(int i, Exp *e);
01122 void setNumArguments(int i);
01123 int getNumArguments();
01124 void removeArgument(int i);
01125 Type *getArgumentType(int i);
01126 void truncateArguments();
01127 void clearLiveEntry();
01128 void eliminateDuplicateArgs();
01129
01130
01131 void rangeAnalysis(std::list<Statement*> &execution_paths);
01132
01133 virtual void print(std::ostream& os = std::cout, bool html = false);
01134
01135
01136 virtual bool search(Exp *search, Exp *&result);
01137
01138
01139 virtual bool searchAndReplace(Exp* search, Exp* replace, bool cc = false);
01140
01141
01142
01143 virtual bool searchAll(Exp* search, std::list<Exp*> &result);
01144
01145
01146
01147 void setReturnAfterCall(bool b);
01148 bool isReturnAfterCall();
01149
01150
01151
01152 void setPostCallExpList(std::list<Exp*>* le);
01153 std::list<Exp*>* getPostCallExpList();
01154
01155
01156 void setDestProc(Proc* dest);
01157 Proc* getDestProc();
01158
01159
01160 virtual void genConstraints(LocationSet& cons);
01161
01162
01163 void dfaTypeAnalysis(bool& ch);
01164
01165
01166 virtual void generateCode(HLLCode *hll, BasicBlock *pbb, int indLevel);
01167
01168
01169 virtual bool usesExp(Exp *e);
01170
01171
01172 virtual bool isDefinition();
01173 virtual void getDefinitions(LocationSet &defs);
01174
01175 virtual bool definesLoc(Exp* loc);
01176 virtual void setLeftFor(Exp* forExp, Exp* newExp);
01177
01178
01179
01180
01181 virtual void simplify();
01182
01183
01184
01185 void decompile();
01186
01187
01188
01189
01190 virtual Type* getTypeFor(Exp* e);
01191 virtual void setTypeFor(Exp* e, Type* ty);
01192 DefCollector* getDefCollector() {return &defCol;}
01193 UseCollector* getUseCollector() {return &useCol;}
01194 void useBeforeDefine(Exp* x) {useCol.insert(x);}
01195 void removeLiveness(Exp* e) {useCol.remove(e);}
01196 void removeAllLive() {useCol.clear();}
01197
01198 StatementList& getDefines() {return defines;}
01199
01200
01201 bool ellipsisProcessing(Prog* prog);
01202 bool convertToDirect();
01203
01204 void useColFromSsaForm(Statement* s) {useCol.fromSSAform(proc, s);}
01205 private:
01206
01207 void addSigParam(Type* ty, bool isScanf);
01208 Assign* makeArgAssign(Type* ty, Exp* e);
01209
01210 protected:
01211
01212 void updateDefineWithType(int n);
01213 void appendArgument(Assignment* as) {arguments.append(as);}
01214 friend class XMLProgParser;
01215 };
01216
01217
01218
01219
01220
01221
01222
01223 class ReturnStatement : public Statement {
01224 protected:
01225
01226 ADDRESS retAddr;
01227
01228
01229
01230
01231
01232
01233
01234
01235
01236
01237
01238
01239
01240 DefCollector col;
01241
01242
01243
01244
01245
01246 StatementList modifieds;
01247
01248
01249
01250
01251
01252 StatementList returns;
01253
01254 public:
01255 ReturnStatement();
01256 virtual ~ReturnStatement();
01257
01258 typedef StatementList::iterator iterator;
01259 iterator begin() {return returns.begin();}
01260 iterator end() {return returns.end();}
01261 iterator erase(iterator it) {return returns.erase(it);}
01262 StatementList& getModifieds() {return modifieds;}
01263 StatementList& getReturns() {return returns;}
01264 unsigned getNumReturns() {return returns.size(); }
01265 void updateModifieds();
01266 void updateReturns();
01267
01268 virtual void print(std::ostream& os = std::cout, bool html = false);
01269
01270
01271 virtual bool search(Exp*, Exp*&);
01272
01273
01274 virtual bool searchAndReplace(Exp* search, Exp* replace, bool cc = false);
01275
01276
01277 virtual bool searchAll(Exp* search, std::list<Exp*> &result);
01278
01279
01280 virtual bool usesExp(Exp *e);
01281
01282 virtual void getDefinitions(LocationSet &defs);
01283
01284 void removeModified(Exp* loc);
01285 void removeReturn(Exp* loc);
01286 void addReturn(Assignment* a);
01287
01288 Type* getTypeFor(Exp* e);
01289 void setTypeFor(Exp* e, Type* ty);
01290
01291
01292 virtual void simplify();
01293
01294 virtual bool isDefinition() { return true; }
01295
01296
01297 Exp* subscriptWithDef(Exp* e);
01298
01299
01300 virtual Statement* clone();
01301
01302
01303 virtual bool accept(StmtVisitor* visitor);
01304 virtual bool accept(StmtExpVisitor* visitor);
01305 virtual bool accept(StmtModifier* visitor);
01306 virtual bool accept(StmtPartModifier* visitor);
01307
01308 virtual bool definesLoc(Exp* loc);
01309
01310
01311 virtual void generateCode(HLLCode *hll, BasicBlock *pbb, int indLevel);
01312
01313
01314
01315
01316 DefCollector* getCollector() {return &col;}
01317
01318
01319 ADDRESS getRetAddr() {return retAddr;}
01320 void setRetAddr(ADDRESS r) {retAddr = r;}
01321
01322
01323 Exp* findDefFor(Exp* e) {return col.findDefFor(e);}
01324
01325 virtual void dfaTypeAnalysis(bool& ch);
01326
01327
01328 StatementList* getCleanReturns();
01329
01330
01331
01332
01333 friend class XMLProgParser;
01334 };
01335
01336
01337 #endif // __STATEMENT_H__