OpenADFortTk (basic)
src/lib/support/IntrinsicXlationTable.h
Go to the documentation of this file.
00001 // -*-Mode: C++;-*-
00002 // $Header: /Volumes/cvsrep/developer/OpenADFortTk/src/IntrinsicXlationTable.h,v 1.8 2006/05/12 16:12:22 utke Exp $
00003 
00004 
00005 #ifndef IntrinsicXlationTable_H 
00006 #define IntrinsicXlationTable_H
00007 
00008 #include <iostream>
00009 #include <vector>
00010 
00011 #include "Open64IRInterface/Open64BasicTypes.h"
00012 
00013 
00014 namespace fortTkSupport { 
00015 
00043   class IntrinsicXlationTable {
00044   public:
00045   
00046     enum TableType { 
00047       W2X, // A table optimized for WHIRL->XAIF lookups
00048       X2W  // A table optimized for XAIF->WHIRL lookups
00049     };
00050 
00055     enum WNOprClass {
00056       WNCall             =0, // A WHIRL function or subroutine call
00057       WNIntrinCall       =1, // A WHIRL intrinsics call
00058       WNIntrinOp         =2, // A WHIRL intrinsics operation
00059       WNExpr             =3, // A WHIRL expression
00060       WNOprClass_UNKNOWN =4  // special, reserved for searching table
00061     };
00062 
00063     static const std::string toString(const WNOprClass& oprcl);
00064   
00069     enum XAIFOpr {
00070       XAIFSubCall,
00071       XAIFFuncCall,
00072       XAIFIntrin,
00073       XAIFBoolOp,
00074       XAIFOpr_UNKNOWN   // special, reserved for searching table
00075     };
00076 
00077     static const std::string toString(const XAIFOpr& opr);
00078 
00079     struct WHIRLInfo {
00080       WNOprClass oprcl;   // class of the WN operator
00081       OPERATOR opr;       // the WN operator
00082       const char* name;   // string qualifier for calls
00083       unsigned int numop; // number of operands to intrinsic
00084       unsigned int numOptional; // number of optional arguments
00085       void dump(std::ostream& os = std::cerr) const;
00086       void ddump() const;
00087     };
00088   
00099     struct XAIFInfo {
00100       XAIFOpr opr;        // the XAIF 'operator'
00101       const char* name;   // intrinsic name
00102       const char* key;    // disambiguates otherwise identical xaif intrinsics
00103       unsigned int numop; // number of operands to intrinsic
00104       void dump(std::ostream& os = std::cerr) const;
00105       void ddump() const;
00106     };
00107 
00111     struct Entry {
00112       WHIRLInfo whirl_info;
00113       XAIFInfo xaif_info;
00114     };
00115 
00116   public:
00117     IntrinsicXlationTable(const TableType& tt);
00118 
00119     ~IntrinsicXlationTable();
00120 
00124     struct XAIFInfoPair {  
00125       XAIFInfoPair(bool aBoolean,
00126                    const XAIFInfo& anXAIFInfo);
00127       bool first;
00128       const XAIFInfo& second;
00129     private:
00133       XAIFInfoPair();
00134     };
00135 
00139     XAIFInfoPair findXAIFInfo(OPERATOR opr, const char* name, bool mustFind=true);
00140     
00141     WHIRLInfo* findWHIRLInfo(XAIFOpr opr, const char* name, const char* key);
00142 
00143     void dump(std::ostream& os = std::cerr) const;
00144     void ddump() const;
00145 
00146   private:
00147 
00151     IntrinsicXlationTable(const IntrinsicXlationTable& p);
00152 
00156     IntrinsicXlationTable& operator=(const IntrinsicXlationTable& p);
00157 
00158     class LtSortedTable {
00159     public:
00160       LtSortedTable(TableType aTableType, bool ignoreXaifKey=false); 
00161       ~LtSortedTable();
00162 
00163       // return true if e1 < e2; false otherwise
00164       bool operator()(const Entry* e1, const Entry* e2) const;
00165 
00166       // required for binary_search(..), lower_bound(..) on GCC 3.3 (?!)
00167       bool operator()(Entry*& e1, const Entry& e2) {
00168         return operator()(dynamic_cast<Entry*>(e1), 
00169                           dynamic_cast<const Entry*>(&e2));
00170       }
00171       bool operator()(const Entry& e1, Entry*& e2) {
00172         return operator()(dynamic_cast<const Entry*>(&e1), 
00173                           dynamic_cast<Entry*>(e2));
00174       }
00175     
00176       // required for binary_search(..), lower_bound(..) on GCC 3.3 (?!)
00177       bool operator()(const Entry& e1, const Entry& e2) {
00178         return operator()(dynamic_cast<const Entry*>(&e1), 
00179                           dynamic_cast<const Entry*>(&e2));
00180       }
00181       bool operator()(const Entry*& e1, const Entry*& e2) {
00182         return operator()(dynamic_cast<const Entry*>(e1), 
00183                           dynamic_cast<const Entry*>(e2));
00184       }
00185     
00186     private:
00190       LtSortedTable();
00191     
00192     private:
00193       TableType myTableType;         // sorting type
00194       bool      myIgnoreXaifKeyFlag; // only meaningful in X2W mode
00195     };
00196   
00197     typedef std::vector<Entry*>     SortedTable;
00198     typedef SortedTable::iterator   SortedTableIt;
00199     typedef SortedTable::value_type SortedTableVal;
00200 
00201   private:
00202   
00203     TableType   myTableType;
00204     SortedTable mySortedTable;
00205   
00206     static Entry        ourTable[];
00207     static unsigned int ourTableSize;
00208 
00209   };
00210 
00211 } 
00212 
00213 #endif
00214 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines