OpenADFortTk (basic)
src/sexp2whirl/sexp2wn.cxx
Go to the documentation of this file.
00001 // -*-Mode: C++;-*-
00002 // $Header: /Volumes/cvsrep/developer/OpenADFortTk/src/sexp2whirl/sexp2wn.cxx,v 1.10 2006/05/12 16:12:22 utke Exp $
00003 
00004 #include <stdlib.h>
00005 
00006 #include <sexp.h>
00007 
00008 #include "Open64IRInterface/Open64BasicTypes.h"
00009 
00010 #include "Diagnostics.h"
00011 #include "sexp2wn.i"
00012 #include "sexp2wn.h"
00013 
00014 #include "SexpTags.h"
00015 #include "sexputil.h"
00016 
00017 using namespace sexp2whirl;
00018 
00019 
00020 //***************************************************************************
00021 // Translate any S-expression AST node
00022 //***************************************************************************
00023 
00024 // TranslateWN: see header. 
00025 WN* 
00026 sexp2whirl::TranslateWN(sexp_t* sx)
00027 {   
00028   using namespace sexp;
00029 
00030   // The task of translation is dispatched to the appropriate handler
00031   // registered in the handler table.
00032   static WNXlationTable handlerTable;
00033   
00034   if (!sx || is_null_list(sx)) { 
00035     return NULL; 
00036   }
00037   
00038   OPERATOR opr = GetWhirlOpr(sx);
00039   FORTTK_DEVMSG(3, "Translating " << OPERATOR_name(opr));
00040   
00041   // Dispatch to the appropriate handler for this construct.
00042   return handlerTable[opr](sx);
00043 }
00044 
00045 
00046 // TranslateWNChildren: see header.
00047 std::vector<WN*>
00048 sexp2whirl::TranslateWNChildren(sexp_t* sx)
00049 {   
00050   using namespace sexp;
00051   
00052   // Sanity check
00053   FORTTK_ASSERT(is_list(sx), fortTkSupport::Diagnostics::UnexpectedInput);  
00054 
00055   // Translate all children
00056   std::vector<WN*> vecWN;
00057   
00058   INT nkids = 0;
00059   for (sexp_t* kid_sx = get_wnast_kid0(sx); kid_sx; 
00060        kid_sx = get_next(kid_sx)) {
00061     WN* kidwn = TranslateWN(kid_sx);
00062     vecWN.push_back(kidwn);
00063   }
00064   
00065   return vecWN;
00066 }
00067 
00068 
00069 //***************************************************************************
00070 // Commonly used routines for extracting information from S-expressions
00071 //***************************************************************************
00072 
00073 // GetWhirlSym
00074 ST_IDX 
00075 sexp2whirl::GetWhirlSym(sexp_t* sx)
00076 {
00077   using namespace sexp;
00078   
00079   // Sanity check
00080   FORTTK_ASSERT(is_list(sx), fortTkSupport::Diagnostics::UnexpectedInput);  
00081   
00082   sexp_t* tag_sx = get_elem0(sx);
00083   const char* tagstr = get_value(tag_sx);
00084   FORTTK_ASSERT(tag_sx && strcmp(tagstr, SexpTags::ST) == 0,
00085                 fortTkSupport::Diagnostics::UnexpectedInput);
00086   
00087   // Convert st_idx
00088   sexp_t* lvl_st = get_elem1(sx);
00089   sexp_t* idx_st = get_elem2(sx);
00090   SYMTAB_IDX lvl = (SYMTAB_IDX)get_value_ui32(lvl_st);
00091   UINT32 idx = get_value_ui32(idx_st);
00092   ST_IDX st_idx = make_ST_IDX(idx, lvl);  
00093   return st_idx;
00094 }
00095 
00096 
00097 // GetWhirlTy
00098 TY_IDX
00099 sexp2whirl::GetWhirlTy(sexp_t* sx)
00100 {
00101   using namespace sexp;
00102   
00103   // Sanity check
00104   FORTTK_ASSERT(is_list(sx), fortTkSupport::Diagnostics::UnexpectedInput);  
00105   
00106   sexp_t* tag_sx = get_elem0(sx);
00107   const char* tagstr = get_value(tag_sx);
00108   FORTTK_ASSERT(tag_sx && strcmp(tagstr, SexpTags::TY) == 0,
00109                 fortTkSupport::Diagnostics::UnexpectedInput);
00110   
00111   // Convert ty_idx
00112   // - ignore name
00113   sexp_t* idx_sx = get_elem2(sx);
00114   sexp_t* algn_sx = get_elem3(sx);
00115   UINT32 idx = get_value_ui32(idx_sx);
00116   UINT32 algn = get_value_ui32(algn_sx);
00117   
00118   TY_IDX ty_idx = make_TY_IDX(idx);
00119   Set_TY_align(ty_idx, algn);
00120   
00121   return ty_idx;
00122 }
00123 
00124 
00125 // GetWhirlOpr
00126 OPERATOR
00127 sexp2whirl::GetWhirlOpr(sexp_t* sx)
00128 {
00129   // FIXME: this could benefit from a one-element cache
00130   using namespace sexp;
00131 
00132   static const int SZ = 28;
00133   static char OPRNM_full[SZ+4] = "OPR_"; // prepend skipped "OPR_"
00134   static char* OPRNM = OPRNM_full+4;
00135   
00136   // Sanity check
00137   FORTTK_ASSERT(is_list(sx), fortTkSupport::Diagnostics::UnexpectedInput);  
00138   
00139   // Convert operator
00140   sexp_t* opr_sx = get_elem0(sx);
00141   const char* opr_nm = get_value(opr_sx);
00142   strncpy(OPRNM, opr_nm, SZ); OPRNM[SZ-1] = '\0';
00143   OPERATOR opr = Name_To_OPERATOR(OPRNM_full);
00144   
00145   return opr;
00146 }
00147 
00148 
00149 // GetWhirlOpcode
00150 OPCODE
00151 sexp2whirl::GetWhirlOpc(sexp_t* sx)
00152 {
00153   using namespace sexp;
00154   
00155   OPERATOR opr = GetWhirlOpr(sx);
00156 
00157   sexp_t* rty_sx = get_elem1(sx);
00158   const char* rty_nm = get_value(rty_sx);
00159   TYPE_ID rty = Name_To_Mtype(rty_nm);
00160   
00161   sexp_t* dty_sx = get_elem2(sx);
00162   const char* dty_nm = get_value(dty_sx);
00163   TYPE_ID dty = Name_To_Mtype(dty_nm);
00164   
00165   OPCODE opc = OPCODE_make_op(opr, rty, dty);
00166   return opc;
00167 }
00168 
00169 
00170 // GetWhirlSymRef
00171 ST_IDX
00172 sexp2whirl::GetWhirlSymRef(sexp_t* sx)
00173 {
00174   using namespace sexp;
00175 
00176   // Sanity check
00177   FORTTK_ASSERT(is_list(sx), fortTkSupport::Diagnostics::UnexpectedInput);  
00178   
00179   sexp_t* tag_sx = get_elem0(sx);
00180   const char* tagstr = get_value(tag_sx);
00181   FORTTK_ASSERT(tag_sx && strcmp(tagstr, SexpTags::ST) == 0,
00182                 fortTkSupport::Diagnostics::UnexpectedInput);
00183 
00184   // Convert st_idx
00185   // - ignore name
00186   sexp_t* lvl_sx = get_elem2(sx);
00187   sexp_t* idx_sx = get_elem3(sx);
00188   SYMTAB_IDX lvl = (SYMTAB_IDX)get_value_ui32(lvl_sx);
00189   UINT32 idx = get_value_ui32(idx_sx);
00190   ST_IDX st_idx = make_ST_IDX(idx, lvl);  
00191   return st_idx;
00192 }
00193 
00194 
00195 // GetWhirlTyUse
00196 TY_IDX
00197 sexp2whirl::GetWhirlTyUse(sexp_t* sx)
00198 {
00199   using namespace sexp;
00200 
00201   // Sanity check
00202   FORTTK_ASSERT(is_list(sx), fortTkSupport::Diagnostics::UnexpectedInput);  
00203   
00204   sexp_t* tag_sx = get_elem0(sx);
00205   const char* tagstr = get_value(tag_sx);
00206   FORTTK_ASSERT(tag_sx && strcmp(tagstr, SexpTags::TY) == 0,
00207                 fortTkSupport::Diagnostics::UnexpectedInput);
00208 
00209   // Convert ty_idx
00210   // - ignore name
00211   sexp_t* idx_sx = get_elem2(sx);
00212   sexp_t* algn_sx = get_elem3(sx);
00213   UINT32 idx = get_value_ui32(idx_sx);
00214   UINT32 algn = get_value_ui32(algn_sx);
00215   
00216   TY_IDX ty_idx = make_TY_IDX(idx);
00217   Set_TY_align(ty_idx, algn);
00218   
00219   return ty_idx;
00220 }
00221 
00222 
00223 // GetWhirlFlg
00224 const char*
00225 sexp2whirl::GetWhirlFlg(sexp_t* sx)
00226 {
00227   using namespace sexp;
00228   
00229   // Sanity check
00230   FORTTK_ASSERT(is_list(sx), fortTkSupport::Diagnostics::UnexpectedInput);
00231   
00232   sexp_t* tag_sx = get_elem0(sx);
00233   const char* tagstr = get_value(tag_sx);
00234   FORTTK_ASSERT(tag_sx && strcmp(tagstr, SexpTags::FLG) == 0,
00235                 fortTkSupport::Diagnostics::UnexpectedInput);
00236   
00237   // Get the flag string
00238   sexp_t* flg_sx = get_elem1(sx);
00239   FORTTK_ASSERT(flg_sx, fortTkSupport::Diagnostics::UnexpectedInput);
00240   
00241   const char* flg = get_value(flg_sx);
00242   return flg;
00243 }
00244 
00245 
00246 // GetWhirlOpaqueFlg
00247 UINT64
00248 sexp2whirl::GetWhirlOpaqueFlg(sexp_t* sx)
00249 {
00250   using namespace sexp;
00251   
00252   // Sanity check
00253   FORTTK_ASSERT(is_list(sx), fortTkSupport::Diagnostics::UnexpectedInput);
00254   
00255   sexp_t* tag_sx = get_elem0(sx);
00256   const char* tagstr = get_value(tag_sx);
00257   FORTTK_ASSERT(tag_sx && strcmp(tagstr, SexpTags::OFLG) == 0,
00258                 fortTkSupport::Diagnostics::UnexpectedInput);
00259   
00260   // Get the flag string
00261   sexp_t* flg_sx = get_elem1(sx);
00262   FORTTK_ASSERT(flg_sx, fortTkSupport::Diagnostics::UnexpectedInput);
00263   
00264   UINT64 flg = get_value_ui64(flg_sx);
00265   return flg;
00266 }
00267 
00268 
00269 //***************************************************************************
00270 // Structured Control Flow Statements: translation of these is
00271 //   superceded by construction of the control flow graph.
00272 //***************************************************************************
00273 
00274 WN*
00275 sexp2whirl::xlate_FUNC_ENTRY(sexp_t* sx)
00276 {
00277   using namespace sexp;
00278   
00279   OPCODE opc = GetWhirlOpc(sx); // WN_OPR
00280 
00281   FORTTK_ASSERT(OPCODE_operator(opc) == OPR_FUNC_ENTRY, 
00282                 fortTkSupport::Diagnostics::UnexpectedInput);
00283   
00284   sexp_t* attrs_sx = get_wnast_attrs(sx); // WN_ATTRS
00285   sexp_t* st_idx_sx = get_elem0(attrs_sx);
00286   ST_IDX st_idx = GetWhirlSymRef(st_idx_sx);
00287   
00288   std::vector<WN*> kids = TranslateWNChildren(sx); // KIDs
00289 
00290   INT16 nkids = (INT16)kids.size();
00291   WN* pragmasWN = kids[nkids-3];
00292   WN* varrefsWN = kids[nkids-2];
00293   WN* bodyWN    = kids[nkids-1];
00294 
00295   WN* wn = WN_CreateEntry(nkids - 3, st_idx, bodyWN, pragmasWN, varrefsWN);
00296   for (INT16 i = 0; i < (nkids - 3); ++i) {
00297     WN_kid(wn,i) = kids[i];
00298   }
00299   
00300   return wn;
00301 }
00302 
00303 
00304 WN* 
00305 sexp2whirl::xlate_BLOCK(sexp_t* sx)
00306 {
00307   using namespace sexp;
00308   
00309   OPCODE opc = GetWhirlOpc(sx); // WN_OPR
00310 
00311   FORTTK_ASSERT(OPCODE_operator(opc) == OPR_BLOCK, fortTkSupport::Diagnostics::UnexpectedInput);
00312   
00313   sexp_t* attrs_sx = get_wnast_attrs(sx); // WN_ATTRS
00314 
00315   WN* blkWN = WN_CreateBlock();
00316   for (sexp_t* kid_sx = get_wnast_kid0(sx); kid_sx; // KIDs
00317        kid_sx = get_next(kid_sx)) {
00318     WN* wn = TranslateWN(kid_sx);
00319     WN_INSERT_BlockLast(blkWN, wn);
00320   }
00321 
00322   return blkWN;
00323 }
00324 
00325 
00326 WN* 
00327 sexp2whirl::xlate_REGION(sexp_t* sx)
00328 {
00329   FORTTK_DIE(fortTkSupport::Diagnostics::Unimplemented);
00330   return NULL;
00331 }
00332 
00333 
00334 WN* 
00335 sexp2whirl::xlate_structured_cf(sexp_t* sx)
00336 {
00337   using namespace sexp;
00338   
00339   OPCODE opc = GetWhirlOpc(sx); // WN_OPR
00340 
00341   OPERATOR opr = OPCODE_operator(opc);
00342   FORTTK_ASSERT(opr == OPR_DO_LOOP || opr == OPR_DO_WHILE || 
00343                 opr == OPR_WHILE_DO || opr == OPR_IF, 
00344                 fortTkSupport::Diagnostics::UnexpectedInput); 
00345   
00346   std::vector<WN*> kids = TranslateWNChildren(sx); // KIDs
00347   WN* wn = WN_Create(opc, kids.size());
00348   for (INT i = 0; i < kids.size(); ++i) {
00349     WN_kid(wn,i) = kids[i];
00350   }
00351   
00352   sexp_t* attrs_sx = get_wnast_attrs(sx); // WN_ATTRS
00353   if (opr == OPR_IF) {
00354     sexp_t* flags_sx = get_elem0(attrs_sx); 
00355     UINT32 flg = (UINT32)GetWhirlOpaqueFlg(flags_sx);
00356     WN_if_flag(wn) = flg;
00357   }
00358   
00359   return wn;
00360 }
00361 
00362 
00363 //***************************************************************************
00364 // Unstructured Control Flow Statements
00365 //***************************************************************************
00366 
00367 WN*
00368 sexp2whirl::xlate_IMPLIED_DO(sexp_t* sx)
00369 {
00370   FORTTK_DIE(fortTkSupport::Diagnostics::Unimplemented);
00371   return NULL;
00372 }
00373 
00374 
00375 WN* 
00376 sexp2whirl::xlate_GOTOx_LABEL(sexp_t* sx)
00377 {  
00378   using namespace sexp;
00379   
00380   OPCODE opc = GetWhirlOpc(sx); // WN_OPR
00381   
00382   OPERATOR opr = OPCODE_operator(opc);
00383   FORTTK_ASSERT(opr == OPR_GOTO || opr == OPR_GOTO_OUTER_BLOCK ||
00384                 opr == OPR_REGION_EXIT || opr == OPR_LABEL, 
00385                 fortTkSupport::Diagnostics::UnexpectedInput); 
00386   
00387   sexp_t* attrs_sx = get_wnast_attrs(sx); // WN_ATTRS
00388   sexp_t* lbl_sx = get_elem0(attrs_sx); 
00389   INT32 lbl = get_value_i32(lbl_sx);
00390 
00391   WN* wn = NULL;
00392   if (opr == OPR_GOTO) {
00393     wn = WN_CreateGoto(lbl);
00394   }
00395   else if (opr == OPR_GOTO_OUTER_BLOCK) {
00396     sexp_t* lbl_lvl_sx = get_elem1(attrs_sx); 
00397     UINT32 lbl_lvl = get_value_ui32(lbl_lvl_sx);
00398     wn = WN_CreateGotoOuterBlock(lbl, lbl_lvl);
00399   }
00400   else if (opr == OPR_REGION_EXIT) {  
00401     wn = WN_CreateRegionExit(lbl);
00402   }
00403   else if (opr == OPR_LABEL) {
00404     sexp_t* flags_sx = get_elem1(attrs_sx); 
00405     UINT32 flg = (UINT32)GetWhirlOpaqueFlg(flags_sx);
00406     
00407     WN* kidWN = TranslateWN(get_wnast_kid0(sx)); // KID 0
00408 
00409     wn = WN_CreateLabel(lbl, flg, kidWN);
00410   }
00411   
00412   return wn;
00413 }
00414 
00415 
00416 WN*
00417 sexp2whirl::xlate_multiBR(sexp_t* sx)
00418 {
00419   using namespace sexp;
00420   
00421   OPCODE opc = GetWhirlOpc(sx); // WN_OPR
00422   
00423   OPERATOR opr = OPCODE_operator(opc);
00424   FORTTK_ASSERT(opr == OPR_SWITCH || opr == OPR_COMPGOTO, 
00425                 fortTkSupport::Diagnostics::UnexpectedInput); 
00426   
00427   sexp_t* attrs_sx = get_wnast_attrs(sx); // WN_ATTRS
00428   sexp_t* nentries_sx = get_elem0(attrs_sx); 
00429   INT32 nentries = get_value_i32(nentries_sx);
00430 
00431   sexp_t* llbl_sx = get_elem1(attrs_sx); 
00432   INT32 llbl = get_value_i32(llbl_sx);
00433 
00434   std::vector<WN*> kids = TranslateWNChildren(sx); // KIDs
00435   WN* wn = WN_Create(opc, kids.size());
00436   for (INT i = 0; i < kids.size(); ++i) {
00437     WN_kid(wn,i) = kids[i];
00438   }
00439   WN_num_entries(wn) = nentries;
00440   WN_last_label(wn) = llbl;
00441   
00442   return wn;
00443 }
00444 
00445 
00446 WN*
00447 sexp2whirl::xlate_CASEGOTO(sexp_t* sx)
00448 {
00449   using namespace sexp;
00450   
00451   OPCODE opc = GetWhirlOpc(sx); // WN_OPR
00452 
00453   FORTTK_ASSERT(OPCODE_operator(opc) == OPR_CASEGOTO, fortTkSupport::Diagnostics::UnexpectedInput);
00454   
00455   sexp_t* attrs_sx = get_wnast_attrs(sx); // WN_ATTRS
00456   sexp_t* cval_sx = get_elem0(attrs_sx); 
00457   INT64 cval = get_value_i64(cval_sx);
00458 
00459   sexp_t* lbl_sx = get_elem1(attrs_sx); 
00460   INT32 lbl = get_value_i32(lbl_sx);
00461   
00462   WN* wn = WN_CreateCasegoto(cval, lbl);
00463   return wn;
00464 }
00465 
00466 
00467 WN* 
00468 sexp2whirl::xlate_AGOTO(sexp_t* sx)
00469 {
00470   FORTTK_DIE(fortTkSupport::Diagnostics::Unimplemented);
00471   return NULL;
00472 }
00473 
00474 
00475 WN*
00476 sexp2whirl::xlate_ALTENTRY(sexp_t* sx)
00477 {
00478   FORTTK_DIE(fortTkSupport::Diagnostics::Unimplemented);  
00479   return NULL;
00480 }
00481 
00482 
00483 WN* 
00484 sexp2whirl::xlate_condBR(sexp_t* sx)
00485 {
00486   using namespace sexp;
00487   
00488   OPCODE opc = GetWhirlOpc(sx); // WN_OPR
00489 
00490   OPERATOR opr = OPCODE_operator(opc);
00491   FORTTK_ASSERT(opr == OPR_TRUEBR || opr == OPR_FALSEBR,
00492                 fortTkSupport::Diagnostics::UnexpectedInput);
00493 
00494   sexp_t* attrs_sx = get_wnast_attrs(sx); // WN_ATTRS
00495   sexp_t* lbl_sx = get_elem0(attrs_sx); 
00496   INT32 lbl = get_value_i32(lbl_sx);
00497   
00498   WN* kidWN = TranslateWN(get_wnast_kid0(sx)); // KID 0
00499 
00500   WN* wn = WN_Create(opc, 1);
00501   WN_label_number(wn) = lbl;
00502   WN_kid0(wn) = kidWN;
00503   return wn;
00504 }
00505 
00506 
00507 WN* 
00508 sexp2whirl::xlate_RETURNx(sexp_t* sx)
00509 {
00510   using namespace sexp;
00511   
00512   OPCODE opc = GetWhirlOpc(sx); // WN_OPR
00513   
00514   OPERATOR opr = OPCODE_operator(opc);
00515   FORTTK_ASSERT(opr == OPR_RETURN || opr == OPR_RETURN_VAL,
00516                 fortTkSupport::Diagnostics::UnexpectedInput); 
00517   
00518   sexp_t* attrs_sx = get_wnast_attrs(sx); // WN_ATTRS
00519   
00520   WN* wn = NULL;
00521   if (opr == OPR_RETURN_VAL) {
00522     WN* kidWN = TranslateWN(get_wnast_kid0(sx)); // KID 0
00523     wn = WN_CreateReturn_Val(opc, kidWN);
00524   }
00525   else {
00526     wn = WN_CreateReturn();
00527   }
00528 
00529   return wn;
00530 }
00531 
00532 
00533 //***************************************************************************
00534 // Calls
00535 //***************************************************************************
00536 
00537 WN* 
00538 sexp2whirl::xlate_xCALL(sexp_t* sx)
00539 {
00540   using namespace sexp;
00541   
00542   OPCODE opc = GetWhirlOpc(sx); // WN_OPR
00543   
00544   OPERATOR opr = OPCODE_operator(opc);
00545   FORTTK_ASSERT(opr == OPR_CALL || opr == OPR_ICALL || 
00546                 opr == OPR_VFCALL || opr == OPR_PICCALL ||
00547                 opr == OPR_INTRINSIC_CALL || opr == OPR_INTRINSIC_OP, 
00548                 fortTkSupport::Diagnostics::UnexpectedInput); 
00549   
00550   std::vector<WN*> kids = TranslateWNChildren(sx); // KIDs
00551   WN* wn = WN_Create(opc, kids.size());
00552   for (INT i = 0; i < kids.size(); ++i) {
00553     WN_kid(wn,i) = kids[i];
00554   }
00555   
00556   sexp_t* attrs_sx = get_wnast_attrs(sx); // WN_ATTRS
00557   if (opr == OPR_CALL || opr == OPR_PICCALL) {
00558     sexp_t* st_idx_sx = get_elem0(attrs_sx); 
00559     ST_IDX st_idx = GetWhirlSymRef(st_idx_sx);
00560     WN_st_idx(wn) = st_idx;
00561   } 
00562   else if (opr == OPR_ICALL || opr == OPR_VFCALL) {
00563     sexp_t* ty_idx_sx = get_elem0(attrs_sx); 
00564     TY_IDX ty_idx = GetWhirlTyUse(ty_idx_sx);
00565     WN_set_ty(wn, ty_idx);
00566   } 
00567   else {
00568     sexp_t* intrn_sx = get_elem0(attrs_sx);
00569     const char* intrn_nm = get_value(intrn_sx);
00570     INTRINSIC intrn = Name_To_INTRINSIC(intrn_nm);
00571     WN_intrinsic(wn) = intrn;
00572   }
00573   if (opr != OPR_VFCALL) {
00574     sexp_t* flags_sx = get_elem1(attrs_sx); 
00575     UINT32 flg = (UINT32)GetWhirlOpaqueFlg(flags_sx);
00576     WN_call_flag(wn) = flg;
00577   }
00578 
00579   return wn;
00580 }
00581 
00582 
00583 WN* 
00584 sexp2whirl::xlate_IO(sexp_t* sx)
00585 {
00586   using namespace sexp;
00587   
00588   OPCODE opc = GetWhirlOpc(sx); // WN_OPR
00589 
00590   FORTTK_ASSERT(OPCODE_operator(opc) == OPR_IO, fortTkSupport::Diagnostics::UnexpectedInput);
00591   
00592   sexp_t* attrs_sx = get_wnast_attrs(sx); // WN_ATTRS
00593   sexp_t* ios_sx = get_elem0(attrs_sx); 
00594   const char* ios_nm = get_value(ios_sx);
00595   IOSTATEMENT ios = Name_To_IOSTATEMENT(ios_nm);
00596 
00597   sexp_t* flags_sx = get_elem1(attrs_sx);
00598   UINT32 flg = (UINT32)GetWhirlOpaqueFlg(flags_sx);
00599 
00600   std::vector<WN*> kids = TranslateWNChildren(sx); // KIDs
00601   WN* wn = WN_CreateIo(ios, kids.size());
00602   for (INT i = 0; i < kids.size(); ++i) {
00603     WN_kid(wn,i) = kids[i];
00604   }
00605   WN_io_flag(wn) = flg;
00606 
00607   return wn;
00608 }
00609 
00610 
00611 WN* 
00612 sexp2whirl::xlate_IO_ITEM(sexp_t* sx)
00613 {
00614   using namespace sexp;
00615   
00616   OPCODE opc = GetWhirlOpc(sx); // WN_OPR
00617 
00618   FORTTK_ASSERT(OPCODE_operator(opc) == OPR_IO_ITEM, fortTkSupport::Diagnostics::UnexpectedInput);
00619   
00620   sexp_t* attrs_sx = get_wnast_attrs(sx); // WN_ATTRS
00621   sexp_t* ioi_sx = get_elem0(attrs_sx); 
00622   const char* ioi_nm = get_value(ioi_sx);
00623   IOITEM ioi = Name_To_IOITEM(ioi_nm);
00624   
00625   sexp_t* ty_idx_sx = get_elem1(attrs_sx);
00626   TY_IDX ty_idx = GetWhirlTyUse(ty_idx_sx);
00627   
00628   std::vector<WN*> kids = TranslateWNChildren(sx); // KIDs
00629   WN* wn = WN_CreateIoItemN(ioi, kids.size(), ty_idx);
00630   for (INT i = 0; i < kids.size(); ++i) {
00631     WN_kid(wn,i) = kids[i];
00632   }
00633 
00634   return wn;
00635 }
00636 
00637 WN*
00638 sexp2whirl::xlate_INTERFACE(sexp_t* sx) {
00639   using namespace sexp;
00640   OPCODE opc = GetWhirlOpc(sx); // WN_OPR
00641   OPERATOR opr = OPCODE_operator(opc);
00642   FORTTK_ASSERT(opr == OPR_INTERFACE, fortTkSupport::Diagnostics::UnexpectedInput);
00643   // FUNC_ENTRY nodes under interface look different!
00644   std::vector<WN*> interfaceKids;
00645   for (sexp_t* kid_sx = get_wnast_kid0(sx); 
00646        kid_sx; 
00647        kid_sx = get_next(kid_sx)) {
00648     OPERATOR kid_opr = GetWhirlOpr(kid_sx);
00649     WN* kidwn=0; 
00650     // see if it is a FUNC_ENTRY: 
00651     if (kid_opr == OPR_FUNC_ENTRY) { 
00652       std::vector<WN*> formalArguments = TranslateWNChildren(kid_sx);
00653       // make the FUNC_ENTRY: 
00654       kidwn = WN_Create (OPC_FUNC_ENTRY, formalArguments.size());
00655       sexp_t* attrs_sx = get_wnast_attrs(kid_sx); // WN_ATTRS
00656       sexp_t* st_idx_sx = get_elem0(attrs_sx);
00657       ST_IDX st_idx = GetWhirlSymRef(st_idx_sx);
00658       WN_entry_name(kidwn) = st_idx;
00659       for (INT i = 0; i < formalArguments.size(); ++i) {
00660         WN_kid(kidwn,i) = formalArguments[i];
00661       }
00662     } 
00663     else { 
00664       kidwn = TranslateWN(kid_sx);
00665     }
00666     interfaceKids.push_back(kidwn);
00667   }
00668   WN* wn = WN_Create(opc, interfaceKids.size());
00669   for (INT i = 0; i < interfaceKids.size(); ++i) {
00670     WN_kid(wn,i) = interfaceKids[i];
00671   }
00672   sexp_t* attrs_sx = get_wnast_attrs(sx); // WN_ATTRS
00673   sexp_t* cur_sx = get_elem0(attrs_sx);
00674   ST_IDX st_idx = GetWhirlSymRef(cur_sx);
00675   WN_st_idx(wn) = st_idx;
00676   return wn;
00677 }
00678 
00679 //***************************************************************************
00680 // Other Statements
00681 //***************************************************************************
00682 
00683 WN*
00684 sexp2whirl::xlate_misc_stmt(sexp_t* sx)
00685 {
00686   using namespace sexp;
00687   
00688   OPCODE opc = GetWhirlOpc(sx); // WN_OPR
00689   
00690   OPERATOR opr = OPCODE_operator(opc);
00691   FORTTK_ASSERT(opr == OPR_EVAL ||
00692                 opr == OPR_PREFETCH || opr == OPR_PREFETCHX ||
00693                 opr == OPR_COMMENT || 
00694                 opr == OPR_TRAP || opr == OPR_ASSERT || opr == OPR_AFFIRM ||
00695                 opr == OPR_FORWARD_BARRIER || opr == OPR_BACKWARD_BARRIER ||
00696                 opr == OPR_DEALLOCA ||
00697                 opr == OPR_USE || opr == OPR_NAMELIST || 
00698                 opr == OPR_IMPLICIT_BND || opr == OPR_NULLIFY || 
00699                 opr == OPR_INTERFACE || opr == OPR_ARRAY_CONSTRUCT,
00700                 fortTkSupport::Diagnostics::UnexpectedInput);
00701   
00702   std::vector<WN*> kids = TranslateWNChildren(sx); // KIDs
00703   WN* wn = WN_Create(opc, kids.size());
00704   for (INT i = 0; i < kids.size(); ++i) {
00705     WN_kid(wn,i) = kids[i];
00706   }
00707   
00708   sexp_t* attrs_sx = get_wnast_attrs(sx); // WN_ATTRS
00709   sexp_t* cur_sx = get_elem0(attrs_sx);
00710   if (OPERATOR_has_sym(opr)) {
00711     ST_IDX st_idx = GetWhirlSymRef(cur_sx);
00712     WN_st_idx(wn) = st_idx;
00713     cur_sx = get_next(cur_sx);
00714   }
00715   if (OPERATOR_has_offset(opr)) {
00716     WN_OFFSET ofst = get_value_ui32(cur_sx);
00717     WN_offset(wn) = ofst;
00718     cur_sx = get_next(cur_sx);
00719   }
00720   if (OPERATOR_has_flags(opr)) {
00721     UINT32 flg = (UINT32)GetWhirlOpaqueFlg(cur_sx);
00722     WN_set_flag(wn, flg);
00723     cur_sx = get_next(cur_sx);
00724   }
00725   
00726   return wn;
00727 }
00728 
00729 
00730 WN*
00731 sexp2whirl::xlate_xPRAGMA(sexp_t* sx)
00732 {
00733   using namespace sexp;
00734   
00735   OPCODE opc = GetWhirlOpc(sx); // WN_OPR
00736   
00737   OPERATOR opr = OPCODE_operator(opc);
00738   FORTTK_ASSERT(opr == OPR_PRAGMA || opr == OPR_XPRAGMA, 
00739                 fortTkSupport::Diagnostics::UnexpectedInput); 
00740   
00741   sexp_t* attrs_sx = get_wnast_attrs(sx); // WN_ATTRS
00742   
00743   sexp_t* prag_sx = get_elem0(attrs_sx);
00744   WN_PRAGMA_ID prag = (WN_PRAGMA_ID)get_value_ui32(prag_sx);
00745   
00746   sexp_t* st_idx_sx = get_elem1(attrs_sx);
00747   ST_IDX st_idx = GetWhirlSymRef(st_idx_sx);
00748   
00749   sexp_t* flags_sx = get_elem2(attrs_sx);
00750   UINT16 flg = (UINT16)GetWhirlOpaqueFlg(flags_sx);
00751 
00752   WN* wn = NULL;
00753   if (opr == OPR_PRAGMA) {
00754     sexp_t* cval_sx = get_elem3(attrs_sx); // end WN_ATTRS
00755     INT64 cval = get_value_i64(cval_sx);
00756     
00757     wn = WN_CreatePragma(prag, st_idx, 0, 0);
00758     WN_const_val(wn) = cval;
00759   } 
00760   else {
00761     WN* kidWN = TranslateWN(get_wnast_kid0(sx)); // KID 0
00762     wn = WN_CreateXpragma(prag, st_idx, 1 /*kid_count*/);
00763     WN_kid0(wn) = kidWN;
00764   }
00765   
00766   return wn;
00767 }
00768 
00769 
00770 //***************************************************************************
00771 // Loads (In WHIRL, loads are expressions.)
00772 // Stores (In WHIRL, stores are statements.)
00773 //***************************************************************************
00774 
00775 WN* 
00776 sexp2whirl::xlate_LDA_LDMA(sexp_t* sx)
00777 {
00778   using namespace sexp;
00779   
00780   OPCODE opc = GetWhirlOpc(sx); // WN_OPR
00781   
00782   OPERATOR opr = OPCODE_operator(opc);
00783   FORTTK_ASSERT(opr == OPR_LDA || opr == OPR_LDMA, fortTkSupport::Diagnostics::UnexpectedInput);
00784 
00785   sexp_t* attrs_sx = get_wnast_attrs(sx); // WN_ATTRS
00786   sexp_t* st_idx_sx = get_elem0(attrs_sx);
00787   ST_IDX st_idx = GetWhirlSymRef(st_idx_sx);
00788   
00789   sexp_t* ofst_sx = get_elem1(attrs_sx);
00790   WN_OFFSET ofst = get_value_ui32(ofst_sx);
00791 
00792   sexp_t* ty_idx_sx = get_elem2(attrs_sx);
00793   TY_IDX ty_idx = GetWhirlTyUse(ty_idx_sx);
00794 
00795   sexp_t* fldid_sx = get_elem3(attrs_sx);
00796   UINT fldid = get_value_ui32(ofst_sx);
00797 
00798   WN* wn = NULL;
00799   if (opr == OPR_LDA) {
00800     wn = WN_CreateLda(opc, ofst, ty_idx, st_idx, fldid);
00801   }
00802   else {
00803     wn = WN_CreateLdma(opc, ofst, ty_idx, st_idx, fldid);
00804   }
00805   
00806   return wn;
00807 }
00808 
00809 
00810 WN* 
00811 sexp2whirl::xlate_LDID_STID(sexp_t* sx)
00812 {
00813   using namespace sexp;
00814   
00815   OPCODE opc = GetWhirlOpc(sx); // WN_OPR
00816 
00817   OPERATOR opr = OPCODE_operator(opc);
00818   FORTTK_ASSERT(opr == OPR_LDID 
00819                 || 
00820                 opr == OPR_STID
00821                 || 
00822                 opr == OPR_PSTID, 
00823                 fortTkSupport::Diagnostics::UnexpectedInput);
00824   
00825   sexp_t* attrs_sx = get_wnast_attrs(sx); // WN_ATTRS
00826   sexp_t* st_idx_sx = get_elem0(attrs_sx);
00827   ST_IDX st_idx = GetWhirlSymRef(st_idx_sx);
00828   
00829   sexp_t* ofst_sx = get_elem1(attrs_sx);
00830   WN_OFFSET ofst = get_value_ui32(ofst_sx);
00831   
00832   sexp_t* ty_idx_sx = get_elem2(attrs_sx);
00833   TY_IDX ty_idx = GetWhirlTyUse(ty_idx_sx);
00834  
00835   sexp_t* fldid_sx = get_elem3(attrs_sx);
00836   UINT fldid = get_value_ui32(fldid_sx);
00837   
00838   WN* wn = NULL;
00839   if (opr == OPR_STID) {
00840     WN* kidWN = TranslateWN(get_wnast_kid0(sx)); // KID 0
00841     wn = WN_CreateStid(opc, ofst, st_idx, ty_idx, kidWN, fldid);
00842   }
00843   else if (opr == OPR_PSTID) { 
00844     WN* kidWN = TranslateWN(get_wnast_kid0(sx)); // KID 0
00845     wn = WN_CreatePStid(opc, ofst, st_idx, ty_idx, kidWN, fldid);
00846   }
00847   else {
00848     wn = WN_CreateLdid(opc, ofst, st_idx, ty_idx, fldid);
00849   }
00850   
00851   return wn;
00852 } 
00853 
00854 
00855 WN* 
00856 sexp2whirl::xlate_IDNAME(sexp_t* sx)
00857 {
00858   using namespace sexp;
00859   
00860   OPCODE opc = GetWhirlOpc(sx); // WN_OPR
00861 
00862   FORTTK_ASSERT(OPCODE_operator(opc) == OPR_IDNAME, fortTkSupport::Diagnostics::UnexpectedInput);
00863   
00864   sexp_t* attrs_sx = get_wnast_attrs(sx); // WN_ATTRS
00865   sexp_t* st_idx_sx = get_elem0(attrs_sx);
00866   ST_IDX st_idx = GetWhirlSymRef(st_idx_sx);
00867   
00868   sexp_t* ofst_sx = get_elem1(attrs_sx);
00869   WN_OFFSET ofst = get_value_ui32(ofst_sx);
00870   
00871   WN* wn = WN_CreateIdname(ofst, st_idx);
00872   return wn;
00873 }
00874 
00875 
00876 WN* 
00877 sexp2whirl::xlate_xLOADx_xSTOREx(sexp_t* sx)
00878 {
00879   using namespace sexp;
00880   
00881   OPCODE opc = GetWhirlOpc(sx); // WN_OPR
00882 
00883   OPERATOR opr = OPCODE_operator(opc);
00884   FORTTK_ASSERT(opr == OPR_ILOAD || opr == OPR_MLOAD || opr == OPR_ILOADX ||
00885                 opr == OPR_ISTORE || opr == OPR_MSTORE || opr == OPR_ISTOREX ||
00886                 opr == OPR_PSTORE ,
00887                 fortTkSupport::Diagnostics::UnexpectedInput);
00888 
00889   std::vector<WN*> kids = TranslateWNChildren(sx); // KIDs
00890   WN* wn = WN_Create(opc, kids.size());
00891   for (INT i = 0; i < kids.size(); ++i) {
00892     WN_kid(wn,i) = kids[i];
00893   }
00894 
00895   sexp_t* attrs_sx = get_wnast_attrs(sx); // WN_ATTRS
00896   sexp_t* cur_sx = get_elem0(attrs_sx);
00897   if (opr == OPR_ILOAD || opr == OPR_MLOAD || 
00898       opr == OPR_ISTORE || opr == OPR_MSTORE ||
00899       opr == OPR_PSTORE) {
00900     sexp_t* ofst_sx = cur_sx;
00901     WN_OFFSET ofst = get_value_ui32(ofst_sx);
00902     WN_offset(wn) = ofst;
00903     
00904     sexp_t* fldid_sx = get_next(ofst_sx);
00905     UINT fldid = get_value_ui32(fldid_sx);
00906     WN_set_field_id(wn, fldid);
00907     
00908     cur_sx = get_next(fldid_sx);
00909   }
00910   
00911   TY_IDX ty_idx1 = GetWhirlTyUse(cur_sx);
00912   WN_set_ty(wn, ty_idx1);
00913   cur_sx = get_next(cur_sx);
00914   
00915   if (opr == OPR_ILOAD || opr == OPR_ILOADX) {
00916     TY_IDX ty_idx2 = GetWhirlTyUse(cur_sx);
00917     WN_set_load_addr_ty(wn, ty_idx2);
00918   }
00919   
00920   return wn;
00921 }
00922 
00923 //***************************************************************************
00924 // Array Operators (N-ary Operations)
00925 //***************************************************************************
00926 
00927 WN*
00928 sexp2whirl::xlate_ARRAYx(sexp_t* sx)
00929 {
00930   using namespace sexp;
00931   
00932   OPCODE opc = GetWhirlOpc(sx); // WN_OPR
00933   
00934   OPERATOR opr = OPCODE_operator(opc);
00935   FORTTK_ASSERT(opr == OPR_ARRAY || opr == OPR_ARRAYEXP || 
00936                 opr == OPR_ARRSECTION, fortTkSupport::Diagnostics::UnexpectedInput);
00937   
00938   std::vector<WN*> kids = TranslateWNChildren(sx); // KIDs
00939   WN* wn = WN_Create(opc, kids.size());
00940   for (INT i = 0; i < kids.size(); ++i) {
00941     WN_kid(wn,i) = kids[i];
00942   }
00943 
00944   sexp_t* attrs_sx = get_wnast_attrs(sx); // WN_ATTRS
00945   if (opr == OPR_ARRAY || opr == OPR_ARRSECTION) {
00946     sexp_t* sz_sx = get_elem0(attrs_sx);
00947     WN_ESIZE sz = get_value_i64(sz_sx);
00948     WN_element_size(wn) = sz;
00949   }
00950   
00951   return wn;
00952 }
00953 
00954 
00955 //***************************************************************************
00956 // Type Conversion
00957 //***************************************************************************
00958 
00959 WN* 
00960 sexp2whirl::xlate_CVT_CVTL(sexp_t* sx)
00961 {
00962   using namespace sexp;
00963   
00964   OPCODE opc = GetWhirlOpc(sx); // WN_OPR
00965   
00966   OPERATOR opr = OPCODE_operator(opc);
00967   FORTTK_ASSERT(opr == OPR_CVT || opr == OPR_CVTL, fortTkSupport::Diagnostics::UnexpectedInput);
00968   
00969   WN* wn = WN_Create(opc, 1);
00970   WN* kidWN = TranslateWN(get_wnast_kid0(sx)); // KID 0
00971   WN_kid0(wn) = kidWN;
00972 
00973   sexp_t* attrs_sx = get_wnast_attrs(sx); // WN_ATTRS
00974   if (opr == OPR_CVTL) {
00975     sexp_t* cvtlbits_sx = get_elem0(attrs_sx);
00976     INT16 cvtlbits = (INT16)get_value_i32(cvtlbits_sx);
00977     WN_cvtl_bits(wn) = cvtlbits;
00978   }
00979   
00980   return wn;
00981 }
00982 
00983 
00984 WN* 
00985 sexp2whirl::xlate_TAS(sexp_t* sx)
00986 {
00987   using namespace sexp;
00988   
00989   OPCODE opc = GetWhirlOpc(sx); // WN_OPR
00990   
00991   FORTTK_ASSERT(OPCODE_operator(opc) == OPR_BLOCK, fortTkSupport::Diagnostics::UnexpectedInput);
00992   
00993   sexp_t* attrs_sx = get_wnast_attrs(sx); // WN_ATTRS
00994   sexp_t* ty_idx_sx = get_elem0(attrs_sx);
00995   TY_IDX ty_idx = GetWhirlTyUse(ty_idx_sx);
00996   
00997   WN* kidWN = TranslateWN(get_wnast_kid0(sx)); // KID 0
00998   
00999   WN* wn = WN_Tas(OPCODE_rtype(opc), ty_idx, kidWN);
01000   return wn;
01001 }
01002 
01003 
01004 //***************************************************************************
01005 // Leaf (Other)
01006 //***************************************************************************
01007 
01008 WN* 
01009 sexp2whirl::xlate_INTCONST(sexp_t* sx)
01010 {
01011   using namespace sexp;
01012   
01013   OPCODE opc = GetWhirlOpc(sx); // WN_OPR
01014   
01015   FORTTK_ASSERT(OPCODE_operator(opc) == OPR_INTCONST, 
01016                 fortTkSupport::Diagnostics::UnexpectedInput); 
01017   
01018   sexp_t* attrs_sx = get_wnast_attrs(sx); // WN_ATTRS
01019   sexp_t* val_sx = get_elem0(attrs_sx);
01020   INT64 val = get_value_i64(val_sx);
01021   
01022   WN* wn = WN_CreateIntconst(opc, val);
01023   return wn;
01024 }
01025 
01026 
01027 WN* 
01028 sexp2whirl::xlate_CONST(sexp_t* sx)
01029 {
01030   using namespace sexp;
01031   
01032   OPCODE opc = GetWhirlOpc(sx); // WN_OPR
01033   
01034   FORTTK_ASSERT(OPCODE_operator(opc) == OPR_CONST, fortTkSupport::Diagnostics::UnexpectedInput); 
01035   
01036   sexp_t* attrs_sx = get_wnast_attrs(sx); // WN_ATTRS
01037   sexp_t* st_idx_sx = get_elem0(attrs_sx);
01038   ST_IDX st_idx = GetWhirlSymRef(st_idx_sx);
01039 
01040   WN* wn = WN_CreateConst(opc, st_idx);
01041   return wn;
01042 }
01043 
01044 
01045 //***************************************************************************
01046 // Expression Operators: Unary Operations
01047 //***************************************************************************
01048 
01049 WN*
01050 sexp2whirl::xlate_UnaryOp(sexp_t* sx)
01051 {
01052   using namespace sexp;
01053   
01054   OPCODE opc = GetWhirlOpc(sx); // WN_OPR
01055   
01056   FORTTK_ASSERT(OPCODE_nkids(opc) == 1, 
01057                 fortTkSupport::Diagnostics::UnexpectedInput << OPCODE_name(opc));
01058   
01059   sexp_t* attrs_sx = get_wnast_attrs(sx); // WN_ATTRS
01060   WN* kidWN = TranslateWN(get_wnast_kid0(sx)); // KID 0
01061   
01062   // Use WN_Create() instead of distinguishing between WN_Unary() and
01063   // WN_Trunc(), etc.
01064   WN* wn = WN_Create(opc, 1);
01065   WN_kid0(wn) = kidWN;
01066   return wn;
01067 }
01068 
01069 WN* 
01070 sexp2whirl::xlate_STRCTFLD(sexp_t* sx)
01071 {
01072   using namespace sexp;
01073   
01074   OPCODE opc = GetWhirlOpc(sx); // WN_OPR
01075   
01076   FORTTK_ASSERT(OPCODE_operator(opc) == OPR_STRCTFLD, fortTkSupport::Diagnostics::UnexpectedInput);
01077 
01078   std::vector<WN*> kids = TranslateWNChildren(sx); // KIDs
01079   WN* wn = WN_Create(opc, kids.size());
01080   for (INT i = 0; i < kids.size(); ++i) {
01081     WN_kid(wn,i) = kids[i];
01082   }
01083 
01084   sexp_t* attrs_sx = get_wnast_attrs(sx); // WN_ATTRS
01085   sexp_t* cur_sx = get_elem0(attrs_sx);
01086 
01087   TY_IDX ty_idx1 = GetWhirlTyUse(cur_sx);
01088   WN_set_load_addr_ty(wn, ty_idx1);
01089   cur_sx = get_next(cur_sx);
01090 
01091   TY_IDX ty_idx2 = GetWhirlTyUse(cur_sx);
01092   WN_set_ty(wn, ty_idx2);
01093   cur_sx = get_next(cur_sx);
01094 
01095   UINT fldid = get_value_ui32(cur_sx);
01096   WN_set_field_id(wn, fldid);
01097     
01098   return wn;
01099 }
01100 
01101 WN* 
01102 sexp2whirl::xlate_PARM(sexp_t* sx)
01103 {
01104   using namespace sexp;
01105   
01106   OPCODE opc = GetWhirlOpc(sx); // WN_OPR
01107   
01108   FORTTK_ASSERT(OPCODE_operator(opc) == OPR_PARM, fortTkSupport::Diagnostics::UnexpectedInput);
01109   
01110   sexp_t* attrs_sx = get_wnast_attrs(sx); // WN_ATTRS
01111   sexp_t* flags_sx = get_elem0(attrs_sx); 
01112   UINT32 flg = (UINT32)GetWhirlOpaqueFlg(flags_sx);
01113 
01114   sexp_t* ty_idx_sx = get_elem1(attrs_sx);
01115   TY_IDX ty_idx = GetWhirlTyUse(ty_idx_sx);
01116   
01117   WN* kidWN = TranslateWN(get_wnast_kid0(sx)); // KID 0
01118   
01119   WN* wn = WN_CreateParm(OPCODE_rtype(opc), kidWN, ty_idx, flg);
01120   return wn;
01121 }
01122 
01123 
01124 WN* 
01125 sexp2whirl::xlate_ALLOCA(sexp_t* sx)
01126 {
01127   FORTTK_DIE(fortTkSupport::Diagnostics::Unimplemented);
01128   return NULL;
01129 }
01130 
01131 
01132 //***************************************************************************
01133 // Expression Operators: Binary Operations
01134 //***************************************************************************
01135 
01136 WN*
01137 sexp2whirl::xlate_BinaryOp(sexp_t* sx)
01138 {
01139   using namespace sexp;
01140   
01141   OPCODE opc = GetWhirlOpc(sx); // WN_OPR
01142   
01143   FORTTK_ASSERT(OPCODE_nkids(opc) == 2, 
01144                 fortTkSupport::Diagnostics::UnexpectedInput << OPCODE_name(opc));
01145   
01146   sexp_t* attrs_sx = get_wnast_attrs(sx); // WN_ATTRS
01147   std::vector<WN*> kids = TranslateWNChildren(sx); // KIDs
01148   FORTTK_ASSERT(kids.size() == 2, fortTkSupport::Diagnostics::UnexpectedInput);
01149 
01150   // Use WN_Create() instead of distinguishing between WN_Binary() and
01151   // WN_Relational()
01152   WN* wn = WN_Create(opc, 2);
01153   WN_kid0(wn) = kids[0];
01154   WN_kid1(wn) = kids[1];
01155   
01156   return wn;
01157 }
01158 
01159 
01160 //***************************************************************************
01161 // Expression Operators: Ternary Operations; N-ary Operations
01162 //***************************************************************************
01163 
01164 WN*
01165 sexp2whirl::xlate_TernaryOp(sexp_t* sx)
01166 {
01167   using namespace sexp;
01168   
01169   OPCODE opc = GetWhirlOpc(sx); // WN_OPR
01170   
01171   FORTTK_ASSERT(OPCODE_nkids(opc) == 3, 
01172                 fortTkSupport::Diagnostics::UnexpectedInput << OPCODE_name(opc));
01173   
01174   sexp_t* attrs_sx = get_wnast_attrs(sx); // WN_ATTRS
01175   std::vector<WN*> kids = TranslateWNChildren(sx); // KIDs
01176   FORTTK_ASSERT(kids.size() == 3, fortTkSupport::Diagnostics::UnexpectedInput);
01177 
01178   WN* wn = WN_Create(opc, 3);
01179   WN_kid0(wn) = kids[0];
01180   WN_kid1(wn) = kids[1];
01181   WN_kid2(wn) = kids[2];
01182 
01183   return wn;
01184 }
01185 
01186 
01187 //***************************************************************************
01188 // WNXlationTable
01189 //***************************************************************************
01190 
01191 WN*
01192 sexp2whirl::xlate_unknown(sexp_t* sx)
01193 {
01194   // Warn about opcodes we cannot translate, but keep translating.
01195   OPERATOR opr = GetWhirlOpr(sx);
01196   
01197   FORTTK_DEVMSG(0, fortTkSupport::Diagnostics::UnexpectedOpr << OPERATOR_name(opr));
01198   return NULL;
01199 }
01200 
01201 
01202 #define TABLE_SZ (OPERATOR_LAST + 1)
01203 #define INIT_TABLE_SZ \
01204   (sizeof(WNXlationTable::initTable) / sizeof(WNXlationTable::InitEntry))
01205 
01206 
01207 bool WNXlationTable::initialized = false;
01208 
01209 WNXlationTable::Handler WNXlationTable::table[TABLE_SZ];
01210 unsigned int WNXlationTable::tableSz = TABLE_SZ;
01211 
01212 WNXlationTable::InitEntry WNXlationTable::initTable[] = {
01213   
01214   // Note: Organization generally corresponds to that in
01215   // Open64/documentation/whirl.tex
01216   
01217   // Structured control flow
01218   { OPR_FUNC_ENTRY,           &xlate_FUNC_ENTRY },
01219   { OPR_BLOCK,                &xlate_BLOCK },
01220   { OPR_REGION,               &xlate_REGION },
01221   { OPR_DO_LOOP,              &xlate_structured_cf },
01222   { OPR_DO_WHILE,             &xlate_structured_cf },
01223   { OPR_WHILE_DO,             &xlate_structured_cf },
01224   { OPR_IF,                   &xlate_structured_cf },
01225   
01226   // Other control flow
01227   { OPR_IMPLIED_DO,           &xlate_IMPLIED_DO },
01228   { OPR_GOTO,                 &xlate_GOTOx_LABEL },
01229   { OPR_GOTO_OUTER_BLOCK,     &xlate_GOTOx_LABEL },
01230   { OPR_SWITCH,               &xlate_multiBR },
01231   { OPR_CASEGOTO,             &xlate_CASEGOTO },
01232   { OPR_COMPGOTO,             &xlate_multiBR },
01233   { OPR_AGOTO,                &xlate_AGOTO },
01234   { OPR_REGION_EXIT,          &xlate_GOTOx_LABEL },
01235   { OPR_ALTENTRY,             &xlate_ALTENTRY },
01236   { OPR_TRUEBR,               &xlate_condBR },
01237   { OPR_FALSEBR,              &xlate_condBR },
01238   { OPR_RETURN,               &xlate_RETURNx },
01239   { OPR_RETURN_VAL,           &xlate_RETURNx },
01240   { OPR_LABEL,                &xlate_GOTOx_LABEL },
01241 
01242   // Statements: Calls
01243   { OPR_CALL,                 &xlate_xCALL },
01244   { OPR_ICALL,                &xlate_xCALL },
01245   { OPR_VFCALL,               &xlate_xCALL },
01246   { OPR_PICCALL,              &xlate_xCALL },
01247   { OPR_INTRINSIC_CALL,       &xlate_xCALL },
01248   { OPR_IO,                   &xlate_IO },
01249 
01250   // Statements: Other
01251   { OPR_EVAL,                 &xlate_misc_stmt },
01252   { OPR_PRAGMA,               &xlate_xPRAGMA },
01253   { OPR_XPRAGMA,              &xlate_xPRAGMA },
01254   { OPR_PREFETCH,             &xlate_misc_stmt },
01255   { OPR_PREFETCHX,            &xlate_misc_stmt },
01256   { OPR_COMMENT,              &xlate_misc_stmt },
01257   { OPR_TRAP,                 &xlate_misc_stmt },
01258   { OPR_ASSERT,               &xlate_misc_stmt },
01259   { OPR_AFFIRM,               &xlate_misc_stmt },
01260   { OPR_FORWARD_BARRIER,      &xlate_misc_stmt },
01261   { OPR_BACKWARD_BARRIER,     &xlate_misc_stmt },
01262   { OPR_DEALLOCA,             &xlate_misc_stmt },
01263 
01264   { OPR_USE,                  &xlate_misc_stmt },
01265   { OPR_NAMELIST,             &xlate_misc_stmt },
01266   { OPR_IMPLICIT_BND,         &xlate_misc_stmt },  
01267   { OPR_NULLIFY,              &xlate_misc_stmt },
01268   { OPR_INTERFACE,            &xlate_INTERFACE },
01269   { OPR_ARRAY_CONSTRUCT,      &xlate_misc_stmt },
01270   
01271   // Memory Access (or assignment and variable references)
01272   { OPR_LDA,                  &xlate_LDA_LDMA },  // Leaf
01273   { OPR_LDMA,                 &xlate_LDA_LDMA },  // Leaf
01274   { OPR_IDNAME,               &xlate_IDNAME },    // Leaf; like a mem-ref
01275   { OPR_LDID,                 &xlate_LDID_STID },
01276   { OPR_STID,                 &xlate_LDID_STID },
01277   { OPR_ILOAD,                &xlate_xLOADx_xSTOREx },
01278   { OPR_ILOADX,               &xlate_xLOADx_xSTOREx },
01279   { OPR_MLOAD,                &xlate_xLOADx_xSTOREx },
01280 
01281   { OPR_ISTORE,               &xlate_xLOADx_xSTOREx },
01282   { OPR_ISTOREX,              &xlate_xLOADx_xSTOREx },
01283   { OPR_MSTORE,               &xlate_xLOADx_xSTOREx },
01284 
01285   { OPR_PSTID,                &xlate_LDID_STID }, // pointer version of STID 
01286   { OPR_PSTORE,               &xlate_xLOADx_xSTOREx }, // pointer version of store
01287 
01288   // Type conversion
01289   { OPR_CVT,                  &xlate_CVT_CVTL },
01290   { OPR_CVTL,                 &xlate_CVT_CVTL },
01291   { OPR_TAS,                  &xlate_TAS },
01292   
01293   // Expressions: Unary operations
01294   { OPR_INTCONST,             &xlate_INTCONST }, // Leaf
01295   { OPR_CONST,                &xlate_CONST },    // Leaf
01296 
01297   { OPR_NEG,                  &xlate_UnaryOp },
01298   { OPR_ABS,                  &xlate_UnaryOp },
01299   { OPR_SQRT,                 &xlate_UnaryOp },
01300   { OPR_RSQRT,                &xlate_UnaryOp },
01301   { OPR_RECIP,                &xlate_UnaryOp },
01302   { OPR_REALPART,             &xlate_UnaryOp }, // OPR_FIRSTPART
01303   { OPR_IMAGPART,             &xlate_UnaryOp }, // OPR_SECONDPART
01304   { OPR_PAREN,                &xlate_UnaryOp },
01305   { OPR_RND,                  &xlate_UnaryOp },
01306   { OPR_TRUNC,                &xlate_UnaryOp },
01307   { OPR_CEIL,                 &xlate_UnaryOp },
01308   { OPR_FLOOR,                &xlate_UnaryOp },
01309   { OPR_BNOT,                 &xlate_UnaryOp },
01310   { OPR_LNOT,                 &xlate_UnaryOp },
01311   // FIXME: LOWPART, HIGHPART, MINPART, MAXPART, ILDA, EXTRACT_BITS
01312   // structure field access
01313   { OPR_STRCTFLD,             &xlate_STRCTFLD },
01314   { OPR_PARM,                 &xlate_PARM },
01315   // FIXME: ASM_INPUT
01316   { OPR_ALLOCA,               &xlate_ALLOCA },
01317 
01318   // Expressions: Binary operations
01319   { OPR_COMPLEX,              &xlate_BinaryOp }, // OPR_PAIR
01320   { OPR_ADD,                  &xlate_BinaryOp },
01321   { OPR_SUB,                  &xlate_BinaryOp },
01322   { OPR_MPY,                  &xlate_BinaryOp },
01323   // FIXME: HIGHMPY, XMPY
01324   { OPR_DIV,                  &xlate_BinaryOp },
01325   { OPR_MOD,                  &xlate_BinaryOp },
01326   { OPR_REM,                  &xlate_BinaryOp },
01327   // FIXME: DIVREM
01328   { OPR_MAX,                  &xlate_BinaryOp },
01329   { OPR_MIN,                  &xlate_BinaryOp },
01330   // FIXME: MINMAX
01331   { OPR_EQ,                   &xlate_BinaryOp },
01332   { OPR_NE,                   &xlate_BinaryOp },
01333   { OPR_GE,                   &xlate_BinaryOp },
01334   { OPR_GT,                   &xlate_BinaryOp },
01335   { OPR_LE,                   &xlate_BinaryOp },
01336   { OPR_LT,                   &xlate_BinaryOp },
01337   { OPR_BAND,                 &xlate_BinaryOp },
01338   { OPR_BIOR,                 &xlate_BinaryOp },
01339   { OPR_BNOR,                 &xlate_BinaryOp },
01340   { OPR_BXOR,                 &xlate_BinaryOp },
01341   { OPR_LAND,                 &xlate_BinaryOp },
01342   { OPR_LIOR,                 &xlate_BinaryOp },
01343   { OPR_CAND,                 &xlate_BinaryOp },
01344   { OPR_CIOR,                 &xlate_BinaryOp },
01345   { OPR_SHL,                  &xlate_BinaryOp },
01346   { OPR_ASHR,                 &xlate_BinaryOp },
01347   { OPR_LSHR,                 &xlate_BinaryOp },
01348   // FIXME: COMPOSE_BITS, RROTATE, COMMA, RCOMMA
01349   
01350   // Expressions: Ternary operations
01351   { OPR_SELECT,               &xlate_TernaryOp },
01352   // FIXME: CSELECT
01353   { OPR_MADD,                 &xlate_TernaryOp },
01354   { OPR_MSUB,                 &xlate_TernaryOp },
01355   { OPR_NMADD,                &xlate_TernaryOp },
01356   { OPR_NMSUB,                &xlate_TernaryOp },
01357 
01358   // Expressions: N-ary operations
01359   { OPR_ARRAY,                &xlate_ARRAYx },
01360   { OPR_INTRINSIC_OP,         &xlate_xCALL },
01361   { OPR_IO_ITEM,              &xlate_IO_ITEM },
01362   { OPR_TRIPLET,              &xlate_TernaryOp },
01363   { OPR_SRCTRIPLET,           &xlate_TernaryOp },
01364   { OPR_ARRAYEXP,             &xlate_ARRAYx },
01365   { OPR_ARRSECTION,           &xlate_ARRAYx },
01366   { OPR_WHERE,                &xlate_TernaryOp },
01367   
01368   
01369   { OPERATOR_UNKNOWN,         &xlate_unknown } // just for convenience
01370 };
01371 
01372 unsigned int WNXlationTable::initTableSz = INIT_TABLE_SZ;
01373 
01374 #undef TABLE_SZ
01375 #undef INIT_TABLE_SZ
01376 
01377 
01378 WNXlationTable::WNXlationTable()
01379 {
01380   // Initialize table with default handler
01381   for (int i = 0; i < tableSz; ++i) {
01382     table[i] = &xlate_unknown;
01383   }
01384   
01385   // Initialize the table using 'initTable'
01386   for (int i = 0; i < initTableSz; ++i) {
01387     table[initTable[i].opr] = initTable[i].fn;
01388   }
01389   
01390   initialized = true; // could use to this initialize on demand
01391 }
01392 
01393 WNXlationTable::~WNXlationTable()
01394 {
01395 }
01396 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines