sparcfrontend.h

Go to the documentation of this file.
00001 
00002 #ifndef SPARCFRONTEND_H
00003 #define SPARCFRONTEND_H
00004 
00005 // Class SparcFrontEnd: derived from FrontEnd, with source machine specific
00006 // behaviour
00007 
00008 #include <set>
00009 #include "decoder.h"
00010 #include "exp.h"            // Ugh... just for enum OPER
00011 #include "frontend.h"       // In case included bare, e.g. ProcTest.cpp
00012 
00013 class FrontEnd;
00014 class SparcDecoder;
00015 struct DecodeResult;
00016 class CallStatement;
00017 
00018 class SparcFrontEnd : public FrontEnd
00019 {
00020 public:
00021     /*
00022      * Constructor. Takes some parameters to save passing these around a lot
00023      */
00024     SparcFrontEnd(BinaryFile *pBF, Prog* prog, BinaryFileFactory* pbff);
00025 
00026     /**
00027      * Virtual destructor.
00028      */
00029 virtual ~SparcFrontEnd();
00030 
00031 virtual platform getFrontEndId() { return PLAT_SPARC; }
00032 
00033     /*
00034      * processProc. This is the main function for decoding a procedure.
00035      * This overrides the base class processProc to do source machine
00036      * specific things (but often calls the base class to do most of the
00037      * work. Sparc is an exception)
00038      * If frag is true, we are decoding only a fragment of the proc
00039      * If spec is true, this is a speculative decode (so give up on any invalid
00040      * instruction)
00041      * Returns true on a good decode
00042      */
00043 virtual bool    processProc(ADDRESS uAddr, UserProc* pProc, std::ofstream &os,
00044     bool frag = false, bool spec = false);
00045 
00046 virtual std::vector<Exp*> &getDefaultParams();
00047 virtual std::vector<Exp*> &getDefaultReturns();
00048 
00049 virtual ADDRESS getMainEntryPoint( bool &gotMain );
00050 
00051 private:
00052 
00053     void    warnDCTcouple(ADDRESS uAt, ADDRESS uDest);
00054     bool    optimise_DelayCopy(ADDRESS src, ADDRESS dest, int delta,
00055               ADDRESS uUpper);
00056     BasicBlock* optimise_CallReturn(CallStatement* call, RTL* rtl, RTL* delay, UserProc* pProc);
00057 
00058     void    handleBranch(ADDRESS dest, ADDRESS hiAddress, BasicBlock*& newBB, Cfg* cfg, TargetQueue& tq);
00059     void    handleCall(UserProc *proc, ADDRESS dest, BasicBlock* callBB, Cfg* cfg, ADDRESS address, int offset = 0);
00060 
00061     void    case_unhandled_stub(ADDRESS addr);
00062 
00063     bool    case_CALL(ADDRESS& address, DecodeResult& inst, DecodeResult& delay_inst, std::list<RTL*>*& BB_rtls,
00064                 UserProc* proc, std::list<CallStatement*>& callList, std::ofstream &os, bool isPattern = false);
00065 
00066     void    case_SD(ADDRESS& address, int delta, ADDRESS hiAddress, DecodeResult& inst, DecodeResult& delay_inst,
00067                 std::list<RTL*>*& BB_rtls, Cfg* cfg, TargetQueue& tq, std::ofstream &os);
00068 
00069     bool    case_DD(ADDRESS& address, int delta, DecodeResult& inst, DecodeResult& delay_inst,
00070                 std::list<RTL*>*& BB_rtls, TargetQueue& tq, UserProc* proc, std::list<CallStatement*>& callList);
00071 
00072     bool    case_SCD(ADDRESS& address, int delta, ADDRESS hiAddress, DecodeResult& inst, DecodeResult& delay_inst,
00073                 std::list<RTL*>*& BB_rtls, Cfg* cfg, TargetQueue& tq);
00074 
00075     bool    case_SCDAN(ADDRESS& address, int delta, ADDRESS hiAddress, DecodeResult& inst, DecodeResult& delay_inst,
00076                    std::list<RTL*>*& BB_rtls, Cfg* cfg, TargetQueue& tq);
00077 
00078     void    emitNop(std::list<RTL*>* pRtls, ADDRESS uAddr);
00079     void    emitCopyPC(std::list<RTL*>* pRtls, ADDRESS uAddr);
00080     unsigned fetch4(unsigned char* ptr);
00081     void    appendAssignment(Exp* lhs, Exp* rhs, Type* type, ADDRESS addr, std::list<RTL*>* lrtl);
00082     void    quadOperation(ADDRESS addr, std::list<RTL*>* lrtl, OPER op);
00083 
00084     bool    helperFunc(ADDRESS dest, ADDRESS addr, std::list<RTL*>* lrtl);
00085     void    gen32op32gives64(OPER op, std::list<RTL*>* lrtl, ADDRESS addr);
00086     bool    helperFuncLong(ADDRESS dest, ADDRESS addr, std::list<RTL*>* lrtl, std::string& name);
00087     //void  setReturnLocations(CalleeEpilogue* epilogue, int iReg);
00088 
00089     // This struct represents a single nop instruction. Used as a substitute delay slot instruction
00090     DecodeResult nop_inst;
00091     
00092 };
00093 
00094 #endif

Generated on Tue Sep 19 21:18:32 2006 for Boomerang by  doxygen 1.4.6