|
OpenADFortTk (basic)
|
00001 // -*-Mode: C++;-*- 00002 // $Header: /Volumes/cvsrep/developer/OpenADFortTk/src/lib/support/IntrinsicXlationTable.cxx,v 1.28 2006/05/12 16:12:22 utke Exp $ 00003 00004 #include <stdlib.h> 00005 #include <algorithm> 00006 00007 00008 #include "IntrinsicXlationTable.h" 00009 #include "Open64IRInterface/wn_attr.h" 00010 #include "Diagnostics.h" 00011 00012 namespace fortTkSupport { 00013 00014 IntrinsicXlationTable::Entry IntrinsicXlationTable::ourTable[] = { 00015 00016 // ------------------------------------------------------- 00017 // WHIRL calls, expressions and intrinsics that correspond to XAIF 00018 // Intrinsics. 00019 // 00020 // For OPR_INTRINSIC_OP, the WHIRL string is the INTRINSIC_basename() 00021 // (cf. wintrinsic.h, wutil.cxx) 00022 // ------------------------------------------------------- 00023 00024 // Common mathematical functions 00025 { { WNExpr, OPR_NEG, NULL, 1, 0 }, { XAIFIntrin, "minus_scal", NULL, 1 } }, 00026 { { WNExpr, OPR_ADD, NULL, 2, 0 }, { XAIFIntrin, "add_scal_scal", NULL, 2 } }, 00027 { { WNExpr, OPR_SUB, NULL, 2, 0 }, { XAIFIntrin, "sub_scal_scal", NULL, 2 } }, 00028 { { WNExpr, OPR_MPY, NULL, 2, 0 }, { XAIFIntrin, "mul_scal_scal", NULL, 2 } }, 00029 { { WNExpr, OPR_DIV, NULL, 2, 0 }, { XAIFIntrin, "div_scal_scal", NULL, 2 } }, 00030 { { WNCall, OPR_CALL, "SQRT", 1, 0 }, { XAIFIntrin, "sqrt_scal", "0_SQRT", 1 } }, 00031 { { WNCall, OPR_CALL, "DSQRT", 1, 0 }, { XAIFIntrin, "sqrt_scal", "1_DSQRT", 1 } }, 00032 { { WNExpr, OPR_SQRT, NULL, 1, 0 }, { XAIFIntrin, "sqrt_scal", "2_SQRT", 1 } }, 00033 { { WNCall, OPR_CALL, "SUM", 1, 0 }, { XAIFIntrin, "sum_arr", NULL, 1 } }, 00034 // modulo/remainder 00035 { { WNExpr, OPR_MOD, NULL, 2, 0 }, { XAIFIntrin, "bogus_modulo_scal_scal", "0_MODULO", 2 } }, 00036 { { WNCall, OPR_CALL, "MODULO", 2, 0 }, { XAIFIntrin, "bogus_modulo_scal_scal", "1_MODULO", 2 } }, 00037 { { WNExpr, OPR_REM, NULL, 2, 0 }, { XAIFIntrin, "mod_scal_scal", "0_MOD", 2 } }, 00038 { { WNIntrinOp, OPR_INTRINSIC_OP, "AMOD", 2, 0 }, { XAIFIntrin, "mod_scal_scal", "1_AMOD", 2 } }, 00039 { { WNIntrinOp, OPR_INTRINSIC_OP, "DMOD", 2, 0 }, { XAIFIntrin, "mod_scal_scal", "2_DMOD", 2 } }, 00040 { { WNCall, OPR_CALL, "MOD", 2, 0 }, { XAIFIntrin, "mod_scal_scal", "3_MOD", 2 } }, 00041 // trigonometric 00042 { { WNCall, OPR_CALL, "SIN", 1, 0 }, { XAIFIntrin, "sin_scal", "0_SIN", 1 } }, 00043 { { WNCall, OPR_CALL, "DSIN", 1, 0 }, { XAIFIntrin, "sin_scal", "1_DSIN", 1 } }, 00044 { { WNCall, OPR_CALL, "COS", 1, 0 }, { XAIFIntrin, "cos_scal", "0_COS", 1 } }, 00045 { { WNCall, OPR_CALL, "DCOS", 1, 0 }, { XAIFIntrin, "cos_scal", "1_DCOS", 1 } }, 00046 { { WNCall, OPR_CALL, "TAN", 1, 0 }, { XAIFIntrin, "tan_scal", "0_TAN", 1 } }, 00047 { { WNCall, OPR_CALL, "OAD_TAN", 1, 0 }, { XAIFIntrin, "oad_tan_scal", "0_TAN", 1 } }, 00048 { { WNCall, OPR_CALL, "DTAN", 1, 0 }, { XAIFIntrin, "tan_scal", "1_DTAN", 1 } }, 00049 { { WNCall, OPR_CALL, "ASIN", 1, 0 }, { XAIFIntrin, "arcsin_scal", "0_ASIN", 1 } }, 00050 { { WNCall, OPR_CALL, "ACOS", 1, 0 }, { XAIFIntrin, "arccos_scal", "0_ACOS", 1 } }, 00051 { { WNCall, OPR_CALL, "ATAN", 1, 0 }, { XAIFIntrin, "arctan_scal", "0_ATAN", 1 } }, 00052 { { WNCall, OPR_CALL, "SINH", 1, 0 }, { XAIFIntrin, "sinh_scal", "0_SINH", 1 } }, 00053 { { WNCall, OPR_CALL, "DSINH", 1, 0 }, { XAIFIntrin, "sinh_scal", "1_DSINH", 1 } }, 00054 { { WNCall, OPR_CALL, "COSH", 1, 0 }, { XAIFIntrin, "cosh_scal", "0_COSH", 1 } }, 00055 { { WNCall, OPR_CALL, "DCOSH", 1, 0 }, { XAIFIntrin, "cosh_scal", "1_DCOSH", 1 } }, 00056 { { WNCall, OPR_CALL, "TANH", 1, 0 }, { XAIFIntrin, "tanh_scal", "0_TANH", 1 } }, 00057 { { WNCall, OPR_CALL, "DTANH", 1, 0 }, { XAIFIntrin, "tanh_scal", "1_DTANH", 1 } }, 00058 // exp/log 00059 { { WNCall, OPR_CALL, "EXP", 1, 0 }, { XAIFIntrin, "exp_scal", "0_EXP", 1 } }, 00060 { { WNCall, OPR_CALL, "DEXP", 1, 0 }, { XAIFIntrin, "exp_scal", "1_DEXP", 1 } }, 00061 { { WNCall, OPR_CALL, "LOG", 1, 0 }, { XAIFIntrin, "ln_scal", "0_LOG", 1 } }, 00062 { { WNCall, OPR_CALL, "DLOG", 1, 0 }, { XAIFIntrin, "ln_scal", "1_DLOG", 1 } }, 00063 { { WNCall, OPR_CALL, "ALOG", 1, 0 }, { XAIFIntrin, "ln_scal", "2_ALOG", 1 } }, 00064 { { WNCall, OPR_CALL, "LOG10", 1, 0 }, { XAIFIntrin, "log10", NULL, 1 } }, 00065 { { WNIntrinOp, OPR_INTRINSIC_OP, "EXPEXPR", 2, 0 }, { XAIFIntrin, "pow_scal_scal", NULL, 2 } }, 00066 // string operations 00067 { { WNIntrinOp, OPR_INTRINSIC_OP, "CEQEXPR", 2, 0 }, { XAIFIntrin, "string_eq_scal_scal", NULL, 2 } }, 00068 { { WNIntrinOp, OPR_INTRINSIC_OP, "CNEEXPR", 2, 0 }, { XAIFIntrin, "string_ne_scal_scal", NULL, 2 } }, 00069 { { WNIntrinOp, OPR_INTRINSIC_OP, "CGEEXPR", 2, 0 }, { XAIFIntrin, "string_ge_scal_scal", NULL, 2 } }, 00070 { { WNIntrinOp, OPR_INTRINSIC_OP, "CGTEXPR", 2, 0 }, { XAIFIntrin, "string_gt_scal_scal", NULL, 2 } }, 00071 { { WNIntrinOp, OPR_INTRINSIC_OP, "CLEEXPR", 2, 0 }, { XAIFIntrin, "string_le_scal_scal", NULL, 2 } }, 00072 { { WNIntrinOp, OPR_INTRINSIC_OP, "CLTEXPR", 2, 0 }, { XAIFIntrin, "string_lt_scal_scal", NULL, 2 } }, 00073 { { WNIntrinOp, OPR_INTRINSIC_OP, "LEN", 1, 0 }, { XAIFIntrin, "len", "0_LEN_OP", 1 } }, 00074 { { WNCall, OPR_CALL, "INDEX", 3, 1 }, { XAIFIntrin, "index", "0_INDEX_CALL", 3 } }, 00075 { { WNCall, OPR_CALL, "LEN", 1, 0 }, { XAIFIntrin, "len", "1_LEN_CALL", 1 } }, 00076 { { WNCall, OPR_CALL, "LEN_TRIM",1, 0 }, { XAIFIntrin, "len_trim", NULL, 1 } }, 00077 { { WNCall, OPR_CALL, "TRIM", 1, 0 }, { XAIFIntrin, "trim", NULL, 1 } }, 00078 { { WNCall, OPR_CALL, "SCAN", 2, 0 }, { XAIFIntrin, "scan", NULL, 2 } }, 00079 { { WNCall, OPR_CALL, "ICHAR", 1, 0 }, { XAIFIntrin, "ichar", NULL, 1 } }, 00080 // Rounding, conversion 00081 { { WNExpr, OPR_ABS, NULL, 1, 0 }, { XAIFIntrin, "abs_scal", "0_ABS", 1 } }, 00082 { { WNCall, OPR_CALL, "ABS", 1, 0 }, { XAIFIntrin, "abs_scal", "1_ABS", 1 } }, 00083 { { WNCall, OPR_CALL, "DABS", 1, 0 }, { XAIFIntrin, "abs_scal", "2_DABS", 1 } }, 00084 { { WNCall, OPR_CALL, "IABS", 1, 0 }, { XAIFIntrin, "iabs_scal", "0_IABS", 1 } }, 00085 { { WNCall, OPR_CALL, "SIGN", 2, 0 }, { XAIFIntrin, "sign_scal_scal", "0_SIGN", 2 } }, 00086 { { WNCall, OPR_CALL, "DSIGN", 2, 0 }, { XAIFIntrin, "sign_scal_scal", "1_SIGN", 2 } }, 00087 { { WNExpr, OPR_RND, NULL, 1, 0 }, { XAIFIntrin, "bogus_round_scal", NULL, 1 } }, 00088 { { WNExpr, OPR_TRUNC, NULL, 1, 0 }, { XAIFIntrin, "int_scal", "0_INT", 1 } }, 00089 { { WNCall, OPR_CALL, "INT", 1, 0 }, { XAIFIntrin, "int_scal", "1_INT", 1 } }, 00090 { { WNCall, OPR_CALL, "NINT", 1, 0 }, { XAIFIntrin, "nint_scal", NULL, 1 } }, 00091 { { WNCall, OPR_CALL, "TRANSFER",2, 0 }, { XAIFIntrin, "transfer", NULL, 2 } }, 00092 { { WNExpr, OPR_CEIL, NULL, 1, 0 }, { XAIFIntrin, "bogus_ceil_scal", NULL, 1 } }, 00093 { { WNExpr, OPR_FLOOR, NULL, 1, 0 }, { XAIFIntrin, "bogus_floor_scal", NULL, 1 } }, 00094 { { WNCall, OPR_CALL, "REAL", 1, 0 }, { XAIFIntrin, "real_scal", "0_REAL", 1 } }, 00095 { { WNCall, OPR_CALL, "FLOAT", 1, 0 }, { XAIFIntrin, "real_scal", "1_REAL", 1 } }, 00096 { { WNCall, OPR_CALL, "DBLE", 1, 0 }, { XAIFIntrin, "real_scal", "2_REAL", 1 } }, 00097 { { WNCall, OPR_CALL, "AIMAG", 1, 0 }, { XAIFIntrin, "imag_scal", NULL, 1 } }, 00098 { { WNCall, OPR_CALL, "TRANSPOSE",1, 0 }, { XAIFIntrin, "transpose_arr", NULL, 1 } }, 00099 { { WNCall, OPR_CALL, "RESHAPE", 2, 0 }, { XAIFIntrin, "reshape_arr", NULL, 2 } }, 00100 { { WNExpr, OPR_COMPLEX, NULL, 2, 0 }, { XAIFIntrin, "complex_scal", NULL, 2 } }, 00101 // Logical (and bitwise logical) operations 00102 { { WNExpr, OPR_BNOT, NULL, 1, 0 }, { XAIFBoolOp, "b_not", NULL, 1 } }, 00103 { { WNExpr, OPR_BAND, NULL, 2, 0 }, { XAIFBoolOp, "b_and", NULL, 2 } }, 00104 { { WNExpr, OPR_BIOR, NULL, 2, 0 }, { XAIFBoolOp, "b_or", NULL, 2 } }, 00105 { { WNExpr, OPR_BXOR, NULL, 2, 0 }, { XAIFBoolOp, "b_xor", NULL, 2 } }, 00106 { { WNExpr, OPR_LNOT, NULL, 1, 0 }, { XAIFBoolOp, "not", NULL, 1 } }, 00107 { { WNExpr, OPR_LAND, NULL, 2, 0 }, { XAIFBoolOp, "and", NULL, 2 } }, 00108 { { WNExpr, OPR_LIOR, NULL, 2, 0 }, { XAIFBoolOp, "or", NULL, 2 } }, 00109 { { WNExpr, OPR_CAND, NULL, 2, 0 }, { XAIFBoolOp, "bogus_cand_scal_scal", NULL, 2 } }, 00110 { { WNExpr, OPR_CIOR, NULL, 2, 0 }, { XAIFBoolOp, "bogus_cor_scal_scal", NULL, 2 } }, 00111 { { WNExpr, OPR_EQ, NULL, 2, 0 }, { XAIFBoolOp, "equal", NULL, 2 } }, 00112 { { WNExpr, OPR_NE, NULL, 2, 0 }, { XAIFBoolOp, "not_equal", NULL, 2 } }, 00113 { { WNExpr, OPR_GT, NULL, 2, 0 }, { XAIFBoolOp, "greater_than", NULL, 2 } }, 00114 { { WNExpr, OPR_GE, NULL, 2, 0 }, { XAIFBoolOp, "greater_or_equal", NULL, 2 } }, 00115 { { WNExpr, OPR_LT, NULL, 2, 0 }, { XAIFBoolOp, "less_than", NULL, 2 } }, 00116 { { WNExpr, OPR_LE, NULL, 2, 0 }, { XAIFBoolOp, "less_or_equal", NULL, 2 } }, 00117 { { WNCall, OPR_CALL, "ANY", 1, 0 }, { XAIFIntrin, "any", NULL, 1 } }, 00118 // Misc. 00119 { { WNCall, OPR_CALL, "MAXLOC", 1, 0 }, { XAIFIntrin, "maxloc_arr", NULL, 1 } }, 00120 { { WNCall, OPR_CALL, "MINLOC", 1, 0 }, { XAIFIntrin, "minloc_arr", NULL, 1 } }, 00121 { { WNCall, OPR_CALL, "LBOUND", 2, 0 }, { XAIFIntrin, "lbound", NULL, 2 } }, 00122 { { WNCall, OPR_CALL, "UBOUND", 2, 0 }, { XAIFIntrin, "ubound", NULL, 2 } }, 00123 { { WNCall, OPR_CALL, "SIZE", 2, 1 }, { XAIFIntrin, "size", NULL, 2 } }, 00124 { { WNCall, OPR_CALL, "SHAPE", 1, 1 }, { XAIFIntrin, "shape_arr", NULL, 1 } }, 00125 { { WNIntrinOp, OPR_INTRINSIC_OP, "F90INDEX",2, 0 }, { XAIFIntrin, "index", "1_INDEX_OP", 2 } }, 00126 { { WNExpr, OPR_SHL, NULL, 2, 0 }, { XAIFIntrin, "bogus_shl_scal_scal", NULL, 2 } }, 00127 { { WNExpr, OPR_ASHR, NULL, 2, 0 }, { XAIFIntrin, "bogus_ashr_scal_scal", NULL, 2 } }, 00128 { { WNCall, OPR_CALL, "PRESENT", 1, 0 }, { XAIFIntrin, "present", NULL, 1 } }, 00129 { { WNCall, OPR_CALL, "ASSOCIATED", 1, 0 }, { XAIFIntrin, "associated", NULL, 1 } }, 00130 { { WNCall, OPR_CALL, "ALLOCATED", 1, 0 }, { XAIFIntrin, "allocated", NULL, 1 } }, 00131 { { WNCall, OPR_CALL, "_ALLOCATE", 1, 0 }, { XAIFIntrin, "allocate", NULL, 1 } }, 00132 { { WNIntrinOp, OPR_NULLIFY, NULL , 1, 0 }, { XAIFIntrin, "nullify", NULL, 1 } }, 00133 { { WNCall, OPR_CALL, "_DEALLOCATE", 1, 0 }, { XAIFIntrin, "deallocate", NULL, 1 } }, 00134 // max/min etc. are turned into special subroutine calls by the canonicalizer except for integer expressions; 00135 // nc stands for not-canonicalized 00136 { { WNExpr, OPR_MAX, NULL, 2, 0 }, { XAIFIntrin, "nc_max_scal_scal", NULL, 2 } }, 00137 { { WNCall, OPR_CALL, "MAXVAL", 1, 0 }, { XAIFIntrin, "nc_maxval", NULL, 1 } }, 00138 { { WNExpr, OPR_MIN, NULL, 2, 0 }, { XAIFIntrin, "nc_min_scal_scal", NULL, 2 } }, 00139 { { WNCall, OPR_CALL, "MINVAL", 1, 0 }, { XAIFIntrin, "nc_minval", NULL, 1 } } 00140 00141 }; 00142 00143 unsigned int IntrinsicXlationTable::ourTableSize = 00144 (sizeof(IntrinsicXlationTable::ourTable) / sizeof(IntrinsicXlationTable::Entry)); 00145 00146 const std::string IntrinsicXlationTable::toString(const WNOprClass& oprcl) { 00147 std::string retStr; 00148 switch (oprcl) { 00149 case WNCall: 00150 retStr="WNCall"; 00151 break; 00152 case WNIntrinCall: 00153 retStr="WNIntrinCall"; 00154 break; 00155 case WNIntrinOp: 00156 retStr="WNIntrinOp"; 00157 break; 00158 case WNExpr: 00159 retStr="WNExpr"; 00160 break; 00161 default: 00162 FORTTK_DIE("IntrinsicXlationTable::toString: unknown WNOprClass " << (int)oprcl); 00163 break; 00164 } 00165 return retStr; // should never reach 00166 } 00167 00168 const std::string IntrinsicXlationTable::toString(const XAIFOpr& opr) { 00169 std::string retStr; 00170 switch (opr) { 00171 case XAIFSubCall: 00172 retStr="XAIFSubCall"; 00173 break; 00174 case XAIFFuncCall: 00175 retStr="XAIFFuncCall"; 00176 break; 00177 case XAIFIntrin: 00178 retStr="XAIFIntrinsic"; 00179 break; 00180 case XAIFBoolOp: 00181 retStr="XAIFBoolOp"; 00182 break; 00183 default: 00184 FORTTK_DIE("IntrinsicXlationTable::toString: unknown XAIFOpr "<< (int)opr); 00185 break; 00186 } 00187 return retStr; 00188 } 00189 00190 void IntrinsicXlationTable::WHIRLInfo::dump(std::ostream& os) const { 00191 os << "{ " 00192 << toString(oprcl).c_str() << ", " 00193 << OPERATOR_name(opr) << ", " 00194 << ((name) ? name : "<null>") << ", " 00195 << numop 00196 << " }"; 00197 } 00198 00199 void IntrinsicXlationTable::WHIRLInfo::ddump() const { 00200 dump(std::cerr); 00201 } 00202 00203 void IntrinsicXlationTable::XAIFInfo::dump(std::ostream& os) const { 00204 os << "{ " 00205 << toString(opr).c_str() << ", " 00206 << ((name) ? name : "<null>") << ", " 00207 << ((key) ? key : "<null>") << ", " 00208 << numop 00209 << " }"; 00210 } 00211 00212 void IntrinsicXlationTable::XAIFInfo::ddump() const { 00213 dump(std::cerr); 00214 } 00215 00216 IntrinsicXlationTable::LtSortedTable::LtSortedTable(TableType aTableType, bool ignoreXaifKey) : 00217 myTableType(aTableType), 00218 myIgnoreXaifKeyFlag(ignoreXaifKey) { 00219 } 00220 00221 IntrinsicXlationTable::LtSortedTable::~LtSortedTable() { 00222 } 00223 00224 bool IntrinsicXlationTable::LtSortedTable:: operator()(const Entry* e1, 00225 const Entry* e2) const { 00226 if (myTableType == W2X) { 00227 // 1. whirl_info.opr is the primary sorting key 00228 if (e1->whirl_info.opr == e2->whirl_info.opr) { 00229 00230 // Either 1) both whirl_info.oprcl will be equal or 2) one will 00231 // be 'WNOprClass_UNKNOWN' (the search item) 00232 WNOprClass cl = (e1->whirl_info.oprcl == WNOprClass_UNKNOWN) ? 00233 e2->whirl_info.oprcl : e1->whirl_info.oprcl; 00234 00235 switch (cl) { 00236 case WNCall: 00237 case WNIntrinCall: 00238 case WNIntrinOp: 00239 // 2. whirl_info.name is the secondary sorting key 00240 return (strcmp(e1->whirl_info.name, e2->whirl_info.name) < 0); 00241 case WNExpr: 00242 // 2. There is no secondary sorting key 00243 return false; // e1 and e2 are equal 00244 default: 00245 FORTTK_DIE("Internal IntrinsicXlationTable error: Unknown WNOprClass: " 00246 << cl); 00247 } 00248 } 00249 else { 00250 return (e1->whirl_info.opr < e2->whirl_info.opr); 00251 } 00252 } 00253 else if (myTableType == X2W) { 00254 // 1. xaif_info.opr is the primary sorting key 00255 if (e1->xaif_info.opr == e2->xaif_info.opr) { 00256 // 2. xaif_info.name is the secondary sorting key 00257 int cmp = (strcmp(e1->xaif_info.name, e2->xaif_info.name)); 00258 if (!myIgnoreXaifKeyFlag && cmp == 0) { 00259 // 3. xaif_info.key, if available, is the tertiary sorting key 00260 if (e1->xaif_info.key && e2->xaif_info.key) { 00261 return (strcmp(e1->xaif_info.key, e2->xaif_info.key) < 0); 00262 } 00263 else if (e1->xaif_info.key) /* && !e2->xaif_info.key */ { 00264 return false; // e1 > e2 00265 } 00266 else if (e2->xaif_info.key) /* && !e1->xaif_info.key */ { 00267 return true; // e1 < e2 00268 } 00269 // fall-through 00270 } 00271 return (cmp < 0); 00272 } 00273 else { 00274 return (e1->xaif_info.opr < e2->xaif_info.opr); 00275 } 00276 } 00277 else { 00278 FORTTK_DIE("Internal IntrinsicXlationTable error: Unknown TableType: " 00279 << myTableType); 00280 } 00281 } 00282 00283 IntrinsicXlationTable::IntrinsicXlationTable(const TableType& aTableType) : 00284 myTableType(aTableType), 00285 mySortedTable(SortedTable(ourTableSize)) { 00286 // Initialize it 00287 for (unsigned int i = 0; i < ourTableSize; ++i) { 00288 Entry* e = &ourTable[i]; 00289 mySortedTable[i] = e; 00290 } 00291 // Sort it ascendingly 00292 std::sort(mySortedTable.begin(), 00293 mySortedTable.end(), 00294 LtSortedTable(myTableType)); 00295 } 00296 00297 IntrinsicXlationTable::~IntrinsicXlationTable() 00298 { 00299 } 00300 00301 IntrinsicXlationTable::XAIFInfoPair::XAIFInfoPair(bool aBoolean, 00302 const IntrinsicXlationTable::XAIFInfo& anXAIFInfo) : 00303 first(aBoolean), 00304 second(anXAIFInfo) { 00305 } 00306 00307 IntrinsicXlationTable::XAIFInfoPair IntrinsicXlationTable::findXAIFInfo(OPERATOR opr, 00308 const char* name, 00309 bool mustFind) { 00310 if (myTableType != W2X) 00311 FORTTK_DIE("IntrinsicXlationTable::findXAIFInfo: wrong TableType"); 00312 static Entry toFind; 00313 toFind.whirl_info.oprcl = WNOprClass_UNKNOWN; 00314 toFind.whirl_info.opr = opr; 00315 toFind.whirl_info.name = name; 00316 LtSortedTable lt(myTableType); 00317 SortedTableIt it = std::lower_bound(mySortedTable.begin(), 00318 mySortedTable.end(), 00319 toFind, lt); 00320 if (it != mySortedTable.end() && !lt(*it, toFind) && !lt(toFind, *it)) { 00321 return XAIFInfoPair(true,const_cast<const XAIFInfo&>((*it)->xaif_info)); 00322 } 00323 if (mustFind) 00324 FORTTK_DIE("IntrinsicXlationTable::findXAIFInfo: unknown opr=" 00325 << OPERATOR_name(opr) 00326 << ",name=" 00327 << name); 00328 return XAIFInfoPair(false,toFind.xaif_info); 00329 } 00330 00331 IntrinsicXlationTable::WHIRLInfo* 00332 IntrinsicXlationTable::findWHIRLInfo(XAIFOpr opr, 00333 const char* name, 00334 const char* key) { 00335 if (myTableType != X2W) 00336 FORTTK_DIE("IntrinsicXlationTable::findWHIRLInfo: wrong TableType"); 00337 static Entry toFind; 00338 toFind.xaif_info.opr = opr; 00339 toFind.xaif_info.name = name; 00340 toFind.xaif_info.key = (key && key[0] == '\0') ? NULL : key; 00341 bool ignoreKey = (toFind.xaif_info.key == NULL); 00342 LtSortedTable lt(myTableType, ignoreKey); 00343 SortedTableIt it = std::lower_bound(mySortedTable.begin(), 00344 mySortedTable.end(), 00345 toFind, 00346 lt); 00347 if (it != mySortedTable.end() && !lt(*it, toFind) && !lt(toFind, *it)) { 00348 Entry* foundItem = *it; // may be multiple matches if key is NULL 00349 return &(foundItem->whirl_info); 00350 } 00351 FORTTK_DIE("IntrinsicXlationTable::findWHIRLInfo: unknown opr=" 00352 << toString(opr).c_str() 00353 << ",name=" 00354 << name 00355 << ",key=" 00356 << key); 00357 return NULL; 00358 } 00359 00360 class PrintEntry : public std::unary_function<IntrinsicXlationTable::Entry*, void> { 00361 public: 00362 PrintEntry(std::ostream& anOstream, IntrinsicXlationTable::TableType aTableType) : 00363 myOstream(anOstream), 00364 myTableType(aTableType) { 00365 } 00366 ~PrintEntry() { 00367 } 00368 void operator() (IntrinsicXlationTable::Entry* anEntry) { 00369 if (myTableType == IntrinsicXlationTable::W2X) { 00370 anEntry->whirl_info.dump(myOstream); 00371 myOstream << " "; 00372 anEntry->xaif_info.dump(myOstream); 00373 myOstream << std::endl; 00374 } 00375 else if (myTableType == IntrinsicXlationTable::X2W) { 00376 anEntry->xaif_info.dump(myOstream); 00377 myOstream << " "; 00378 anEntry->whirl_info.dump(myOstream); 00379 myOstream << std::endl; 00380 } 00381 else { 00382 FORTTK_DIE("Internal IntrinsicXlationTable error: Unknown TableType: " 00383 << myTableType); 00384 } 00385 } 00386 private: 00387 std::ostream& myOstream; 00388 IntrinsicXlationTable::TableType myTableType; 00389 }; 00390 00391 void IntrinsicXlationTable::dump(std::ostream& os) const { 00392 os << "Begin Intrinsic Table\n"; 00393 std::for_each(mySortedTable.begin(), 00394 mySortedTable.end(), 00395 PrintEntry(os, 00396 myTableType)); 00397 os << "End Intrinsic Table" << std::endl; 00398 } 00399 00400 void IntrinsicXlationTable::ddump() const { 00401 dump(std::cerr); 00402 } 00403 00404 }