|
OpenADFortTk (basic)
|
00001 // ########################################################## 00002 // # This file is part of OpenADFortTk. # 00003 // # The full COPYRIGHT notice can be found in the top # 00004 // # level directory of the OpenADFortTk source tree. # 00005 // # For more information visit # 00006 // # http://www.mcs.anl.gov/openad # 00007 // ########################################################## 00008 00009 /* ==================================================================== 00010 * ==================================================================== 00011 * 00012 * Description: 00013 * 00014 * Translate an OPC_IO subtree into the appropriate Fortran constructs. 00015 * Recursive translation of WN nodes should only use WN2F_Translate(), 00016 * with exception of IO_ITEMS which are handled locally! 00017 * 00018 * The Fortran I/O statements have the following syntax: 00019 * 00020 * <statement_keyword> <control_list> <I/O list> 00021 * 00022 * where 00023 * 00024 * <statement_keyword> ::= <IOS enumeration as defined in wio.h> 00025 * <control_list> ::= <IOU, IOF, and IOC items from wio.h> 00026 * <I/O list> ::= <IOL items from wio.h> 00027 * 00028 * ==================================================================== 00029 * ==================================================================== 00030 */ 00031 00032 #include "Open64IRInterface/Open64BasicTypes.h" 00033 00034 #include "wn2xaif.h" 00035 #include "wn2xaif_mem.h" 00036 #include "wn2xaif_io.h" 00037 #include "st2xaif.h" 00038 #include "ty2xaif.h" 00039 00040 using namespace whirl2xaif; 00041 using namespace xml; // for xml::ostream, etc 00042 00043 // xlate_IO_IOS_BACKSPACE 00044 static void 00045 WN2F_ios_backspace(xml::ostream& xos, WN *wn, PUXlationContext& ctxt); 00046 00047 static void 00048 WN2F_ios_close(xml::ostream& xos, WN *wn, PUXlationContext& ctxt); 00049 00050 static void 00051 WN2F_ios_definefile(xml::ostream& xos, WN *wn, PUXlationContext& ctxt); 00052 00053 static void 00054 WN2F_ios_delete(xml::ostream& xos, WN *wn, PUXlationContext& ctxt); 00055 00056 static void 00057 WN2F_ios_endfile(xml::ostream& xos, WN *wn, PUXlationContext& ctxt); 00058 00059 static void 00060 WN2F_ios_find(xml::ostream& xos, WN *wn, PUXlationContext& ctxt); 00061 00062 static void 00063 WN2F_ios_inquire(xml::ostream& xos, WN *wn, PUXlationContext& ctxt); 00064 00065 static void 00066 WN2F_ios_namelist(xml::ostream& xos, WN *wn, PUXlationContext& ctxt); 00067 00068 static void 00069 WN2F_ios_open(xml::ostream& xos, WN *wn, PUXlationContext& ctxt); 00070 00071 static void 00072 WN2F_ios_rewind(xml::ostream& xos, WN *wn, PUXlationContext& ctxt); 00073 00074 static void 00075 WN2F_ios_unlock(xml::ostream& xos, WN *wn, PUXlationContext& ctxt); 00076 00077 static void 00078 WN2F_ios_accept(xml::ostream& xos, WN *wn, PUXlationContext& ctxt); 00079 00080 static void 00081 WN2F_ios_decode(xml::ostream& xos, WN *wn, PUXlationContext& ctxt); 00082 00083 static void 00084 WN2F_ios_encode(xml::ostream& xos, WN *wn, PUXlationContext& ctxt); 00085 00086 static void 00087 WN2F_ios_print(xml::ostream& xos, WN *wn, PUXlationContext& ctxt); 00088 00089 static void 00090 WN2F_ios_read(xml::ostream& xos, WN *wn, PUXlationContext& ctxt); 00091 00092 static void 00093 WN2F_ios_rewrite(xml::ostream& xos, WN *wn, PUXlationContext& ctxt); 00094 00095 static void 00096 WN2F_ios_type(xml::ostream& xos, WN *wn, PUXlationContext& ctxt); 00097 00098 static void 00099 WN2F_ios_write(xml::ostream& xos, WN *wn, PUXlationContext& ctxt); 00100 00101 static void 00102 WN2F_ios_cr(xml::ostream& xos, WN *wn, PUXlationContext& ctxt); 00103 00104 00105 static BOOL 00106 xlate_IO_ITEM_unit(xml::ostream& xos, WN *item, PUXlationContext& ctxt); 00107 00108 static BOOL 00109 xlate_IO_ITEM_format(xml::ostream& xos, WN* item, PUXlationContext& ctxt); 00110 00111 static BOOL 00112 xlate_IO_ITEM_control(xml::ostream& xos, WN* item, PUXlationContext& ctxt); 00113 00114 static BOOL 00115 xlate_IO_ITEM_list(xml::ostream& xos, WN *item, PUXlationContext& ctxt); 00116 00117 // ************************** Forward Declarations *************************** 00118 00119 // FIXME: REMOVE 00120 /* A rather special IOC item to replace an IOF_LABEL item. This 00121 * value is only valid when ORIGFMT_IOCTRL is TRUE! */ 00122 static UINT32 Origfmt_Ioctrl_Label; 00123 00124 // *************************************************************************** 00125 00126 typedef void (*XlateWNHandlerFunc)(xml::ostream&, WN *, PUXlationContext&); 00127 static XlateWNHandlerFunc XlateWNio_HandlerTable[IOSTATEMENT_LAST+1]; 00128 static bool HandlerTableInitialized = false; 00129 00130 static void 00131 WN2F_Io_initialize(void) 00132 { 00133 XlateWNio_HandlerTable[IOS_BACKSPACE] = &WN2F_ios_backspace; 00134 XlateWNio_HandlerTable[IOS_CLOSE] = &WN2F_ios_close; 00135 XlateWNio_HandlerTable[IOS_DEFINEFILE] = &WN2F_ios_definefile; 00136 XlateWNio_HandlerTable[IOS_DELETE] = &WN2F_ios_delete; 00137 XlateWNio_HandlerTable[IOS_ENDFILE] = &WN2F_ios_endfile; 00138 XlateWNio_HandlerTable[IOS_FIND] = &WN2F_ios_find; 00139 XlateWNio_HandlerTable[IOS_INQUIRE] = &WN2F_ios_inquire; 00140 XlateWNio_HandlerTable[IOS_NAMELIST] = &WN2F_ios_namelist; 00141 XlateWNio_HandlerTable[IOS_OPEN] = &WN2F_ios_open; 00142 XlateWNio_HandlerTable[IOS_REWIND] = &WN2F_ios_rewind; 00143 XlateWNio_HandlerTable[IOS_UNLOCK] = &WN2F_ios_unlock; 00144 XlateWNio_HandlerTable[IOS_ACCEPT] = &WN2F_ios_accept; 00145 XlateWNio_HandlerTable[IOS_DECODE] = &WN2F_ios_decode; 00146 XlateWNio_HandlerTable[IOS_ENCODE] = &WN2F_ios_encode; 00147 XlateWNio_HandlerTable[IOS_PRINT] = &WN2F_ios_print; 00148 XlateWNio_HandlerTable[IOS_READ] = &WN2F_ios_read; 00149 XlateWNio_HandlerTable[IOS_REWRITE] = &WN2F_ios_rewrite; 00150 XlateWNio_HandlerTable[IOS_TYPE] = &WN2F_ios_type; 00151 XlateWNio_HandlerTable[IOS_WRITE] = &WN2F_ios_write; 00152 XlateWNio_HandlerTable[IOS_CR_FWF] = &WN2F_ios_cr; 00153 XlateWNio_HandlerTable[IOS_CR_FRN] = &WN2F_ios_read; 00154 XlateWNio_HandlerTable[IOS_CR_FWN] = &WN2F_ios_write; 00155 XlateWNio_HandlerTable[IOS_CR_FWU] = &WN2F_ios_cr; 00156 XlateWNio_HandlerTable[IOS_CR_FRF] = &WN2F_ios_cr; 00157 XlateWNio_HandlerTable[IOS_CR_FRU] = &WN2F_ios_cr; 00158 XlateWNio_HandlerTable[IOS_CR_OPEN] = &WN2F_ios_open; 00159 XlateWNio_HandlerTable[IOS_CR_CLOSE] = &WN2F_ios_close; 00160 XlateWNio_HandlerTable[IOS_CR_REWIND] = &WN2F_ios_rewind; 00161 XlateWNio_HandlerTable[IOS_CR_INQUIRE] = &WN2F_ios_inquire; 00162 XlateWNio_HandlerTable[IOS_CR_ENDFILE] = &WN2F_ios_endfile; 00163 XlateWNio_HandlerTable[IOS_CR_BACKSPACE] = &WN2F_ios_backspace; 00164 00165 } /* WN2F_Io_initialize */ 00166 00167 00168 static BOOL 00169 Is_Cray_IO(IOSTATEMENT ios) 00170 { 00171 BOOL res ; 00172 res = (ios == IOS_CR_FWF) || (ios == IOS_CR_FWU) || (ios == IOS_CR_FRF) 00173 || (ios == IOS_CR_FRU) || (ios == IOS_CR_OPEN) || (ios == IOS_CR_CLOSE) 00174 || (ios == IOS_CR_REWIND) || (ios == IOS_CR_INQUIRE) 00175 || (ios == IOS_CR_ENDFILE) || (ios == IOS_CR_FRN) || (ios == IOS_CR_FWN) 00176 || (ios == IOS_CR_BACKSPACE); 00177 return res ; 00178 } 00179 00180 // *************************************************************************** 00181 00182 void 00183 whirl2xaif::xlate_IO(xml::ostream& xos, WN *wn, PUXlationContext& ctxt) 00184 { 00185 FORTTK_ASSERT(WN_operator(wn) == OPR_IO, fortTkSupport::Diagnostics::UnexpectedInput); 00186 00187 static UINT32 unique_label = 99999U; 00188 00189 // Initialize table on demand for now 00190 if (!HandlerTableInitialized) { // FIXME 00191 WN2F_Io_initialize(); 00192 HandlerTableInitialized = true; 00193 } 00194 00195 // FIXME Should we use the string given by an IOC_VARFMT_ORIGFMT for a 00196 // IOF_LABEL? 00197 INT ios_kid = 0; 00198 for ( ; (ios_kid < WN_kid_count(wn) && 00199 WN_io_item(WN_kid(wn, ios_kid)) != IOC_VARFMT_ORIGFMT); 00200 ios_kid++); 00201 if (ios_kid < WN_kid_count(wn)) { 00202 ctxt.currentXlationContext().setFlag(XlationContext::ORIGFMT_IOCTRL); 00203 Origfmt_Ioctrl_Label = unique_label--; // cf. W2CF_Symtab_Unique_Label 00204 } 00205 00206 /* FIXME Now dispatch to the appropriate handler routine for each kind of 00207 * IO statement, after beginning the statement on a new line and 00208 * setting the appropriate ctxt flags. */ 00209 ctxt.currentXlationContext().setFlag(XlationContext::IO_STMT); 00210 //ctxt.currentXlationContext().setFlag(no_newline); 00211 00212 const IOSTATEMENT ios = WN_IOSTMT(wn); 00213 FORTTK_ASSERT(XlateWNio_HandlerTable[ios] != NULL, 00214 fortTkSupport::Diagnostics::UnexpectedOpr << get_iostatement_name(ios)); 00215 00216 if (Is_Cray_IO(ios)) 00217 ctxt.currentXlationContext().setFlag(XlationContext::CRAY_IO); 00218 XlateWNio_HandlerTable[ios](xos, wn, ctxt); 00219 ctxt.currentXlationContext().unsetFlag(XlationContext::CRAY_IO); 00220 00221 } 00222 00223 00224 BOOL 00225 whirl2xaif::xlate_IO_ITEM(xml::ostream& xos, WN* item, PUXlationContext& ctxt) 00226 { 00227 // Returns TRUE when something (anything) was emitted for this item. 00228 BOOL emitted = FALSE; 00229 00230 /* Any pointer-argument to an io-item should be dereferenced. Most 00231 * notably, this applies for an LDA of a character string in a FMT 00232 * specifier, but it also applies for a variety of other arguments. 00233 * Such dereferences are specified within the xlate_IO routines. 00234 */ 00235 if (ctxt.currentXlationContext().isFlag(XlationContext::DEREF_IO_ITEM)) 00236 ctxt.currentXlationContext().setFlag(XlationContext::DEREF_ADDR); 00237 else 00238 ctxt.currentXlationContext().unsetFlag(XlationContext::DEREF_ADDR); 00239 00240 if (IS_IO_ITEM_IOU(item)) 00241 emitted = xlate_IO_ITEM_unit(xos, item, ctxt); 00242 else if (IS_IO_ITEM_IOF(item)) 00243 emitted = xlate_IO_ITEM_format(xos, item, ctxt); 00244 else if (IS_IO_ITEM_IOC(item)) 00245 emitted = xlate_IO_ITEM_control(xos, item, ctxt); 00246 else if (IS_IO_ITEM_IOL(item)) 00247 emitted = xlate_IO_ITEM_list(xos, item, ctxt); 00248 else 00249 FORTTK_DIE(fortTkSupport::Diagnostics::UnexpectedOpr 00250 << (IOITEM_name(WN_IOITEM(item)) != NULL ? 00251 IOITEM_name(WN_IOITEM(item)) : "unknown_name")); 00252 00253 return emitted; 00254 } /* xlate_IO_ITEM */ 00255 00256 00257 // *************************************************************************** 00258 // 00259 // *************************************************************************** 00260 00261 // FIXME: merge with next function 00262 static void 00263 xlate_IOControlList(xml::ostream& xos, WN *ios, 00264 INT from_kid, INT to_kid, PUXlationContext& ctxt) 00265 { 00266 // Emit an IO control list (IOU, IOF, and IOC) 00267 for (INT ios_kid = from_kid; ios_kid <= to_kid; ++ios_kid) { 00268 xos << BegElem("xaif:Argument") << Attr("position", ios_kid+1); //FIXME 00269 ctxt.createXlationContext(); 00270 xlate_IO_ITEM(xos, WN_kid(ios, ios_kid), ctxt); 00271 ctxt.deleteXlationContext(); 00272 xos << EndElem; 00273 } 00274 } 00275 00276 static void 00277 xlate_IOList(xml::ostream& xos, WN *ios, INT from_kid, PUXlationContext& ctxt) 00278 { 00279 /* Emit an IOL list, starting at the given kid index and 00280 * continuing to the last kid. */ 00281 for (INT ios_kid = from_kid; ios_kid < WN_kid_count(ios); ++ios_kid) { 00282 xos << BegElem("xaif:Argument") << Attr("position", ios_kid+1); // FIXME 00283 ctxt.createXlationContext(); 00284 xlate_IO_ITEM(xos, WN_kid(ios, ios_kid), ctxt); 00285 ctxt.deleteXlationContext(); 00286 xos << EndElem; 00287 } 00288 } 00289 00290 00291 /*---------------------- IO Item Handler-routines ---------------------*/ 00292 /*---------------------------------------------------------------------*/ 00293 00294 static BOOL 00295 xlate_IO_ITEM_unit(xml::ostream& xos, WN *item, PUXlationContext& ctxt) 00296 { 00297 /* Any arguments assumed to be by reference unless otherwise noted */ 00298 ctxt.currentXlationContext().setFlag(XlationContext::DEREF_ADDR); 00299 00300 switch (WN_io_item(item)) { 00301 case IOU_NONE: 00302 xos << Comment("unit=*"); 00303 break; 00304 00305 case IOU_DEFAULT: /* asterisk or double astrisk */ 00306 xos << BegComment << "unit=" 00307 << ((WN_const_val(WN_kid0(item)) == 0) ? "**" : "*") << EndComment; 00308 break; 00309 00310 case IOU_EXTERNAL: /* unit number */ 00311 case IOU_DOPE: 00312 case IOU_INTERNAL: /* substring or array reference */ 00313 xos << "unit***="; 00314 TranslateWN(xos, WN_kid0(item), ctxt); // FIXME 00315 break; 00316 00317 default: 00318 FORTTK_DIE(fortTkSupport::Diagnostics::UnexpectedOpr << IOITEM_name(WN_IOITEM(item))); 00319 xos << BegComment << "unit=" << IOITEM_name(WN_IOITEM(item)) 00320 << EndComment; 00321 break; 00322 } /*switch*/ 00323 00324 return TRUE; // FIXME 00325 } 00326 00327 00328 static BOOL 00329 xlate_IO_ITEM_format(xml::ostream& xos, WN* item, PUXlationContext& ctxt) 00330 { 00331 /* Any arguments assumed to be by reference unless otherwise noted */ 00332 ctxt.currentXlationContext().setFlag(XlationContext::DEREF_ADDR); 00333 00334 switch (WN_io_item(item)) 00335 { 00336 case IOF_NONE: 00337 if (ctxt.currentXlationContext().isFlag(XlationContext::CRAY_IO) 00338 && 00339 ctxt.currentXlationContext().isFlag(XlationContext::FMT_IO)) { 00340 xos << Comment("fmt=*"); 00341 } 00342 break; 00343 00344 case IOF_ASSIGNED_VAR: 00345 /* The front-end should never generate these, since they are converted 00346 * into IOF_CHAR_EXPR items. Should we for any reason start regenerating 00347 * these, this is the place where it should occur. 00348 */ 00349 FORTTK_ASSERT_WARN(FALSE, 00350 fortTkSupport::Diagnostics::UnexpectedOpr << IOITEM_name(WN_IOITEM(item))); 00351 xos << BegComment << "fmt=" << IOITEM_name(WN_IOITEM(item)) << EndComment; 00352 #if 0 00353 TranslateWN(xos, WN_kid0(item), ctxt); 00354 #endif 00355 break; 00356 00357 case IOF_LABEL: 00358 /* a FORMAT label or character-string expression */ 00359 if (ctxt.currentXlationContext().isFlag(XlationContext::ORIGFMT_IOCTRL)) { 00360 xos << BegComment << "fmt=" << Num2Str(Origfmt_Ioctrl_Label, "%lld") 00361 << EndComment; 00362 } else { 00363 xos << "fmt***"; 00364 TranslateWN(xos, WN_kid0(item), ctxt); 00365 } 00366 break; 00367 00368 case IOF_CHAR_EXPR: 00369 /* a character-substring expression */ 00370 xos << BegComment << "fmt="; 00371 WN2F_String_Argument(xos, WN_kid0(item), /* base */ 00372 WN_kid1(item), /* length */ ctxt); 00373 xos << EndComment; 00374 break; 00375 00376 case IOF_LIST_DIRECTED: 00377 xos << Comment("fmt=*"); 00378 break; 00379 00380 case IOF_NAMELIST_DIRECTED: 00381 xos << Comment("NML=*"); 00382 TranslateWN(xos, WN_kid(item,WN_kid_count(item)-1), ctxt); 00383 Clear_BE_ST_w2fc_referenced(WN_st(WN_kid(item,WN_kid_count(item)-1))); 00384 /* don't dump out Namelist name and corresponding type 00385 * in *.w2f.f file.When call TranslateWN,the namelist name(st entry) will 00386 * be set "referenced".Clear the flag.--------fzhao 00387 */ 00388 break; 00389 00390 case IOF_UNFORMATTED: 00391 break; 00392 00393 case IOF_CR_PARSFMT: 00394 break; 00395 00396 case IOF_CR_FMTSRC: 00397 case IOF_CR_FMTSRC_DOPE: 00398 { 00399 xos << Comment("fmt***"); 00400 WN * kid0 = WN_kid0(item); 00401 if (!IS_IO_NULL_OPR(kid0)) 00402 TranslateWN(xos, kid0, ctxt); 00403 break; 00404 } 00405 default: 00406 FORTTK_DIE(fortTkSupport::Diagnostics::UnexpectedOpr << IOITEM_name(WN_IOITEM(item))); 00407 xos << BegComment << "fmt=" << IOITEM_name(WN_IOITEM(item)) 00408 << EndComment; 00409 break; 00410 } /*switch*/ 00411 00412 return TRUE; // FIXME 00413 } 00414 00415 00416 static BOOL 00417 xlate_IO_ITEM_control(xml::ostream& xos, WN* item, PUXlationContext& ctxt) 00418 { 00419 /* Return TRUE if a control specifier was emitted. */ 00420 const IOITEM item_kind = WN_IOITEM(item); 00421 00422 switch (item_kind) { 00423 case IOC_KEY: 00424 /* TODO: associate this with IOC_KEY */ 00425 FORTTK_DEVMSG(0, fortTkSupport::Diagnostics::Unimplemented << "IOC" << IOITEM_name(item_kind)); 00426 xos << BegComment << "ctr=" << IOITEM_name(item_kind) << "=< ??? >" 00427 << EndComment; 00428 break; 00429 00430 case IOC_KEY_START: 00431 case IOC_KEY_END: 00432 case IOC_KEY_CHARACTER: 00433 case IOC_KEY_INTEGER: 00434 case IOC_NML: /* TODO: remove from IOC enumeration! It is redundant */ 00435 FORTTK_DEVMSG(0, fortTkSupport::Diagnostics::Unimplemented << "IOC" << IOITEM_name(item_kind)); 00436 xos << BegComment << "ctr=" << IOITEM_name(item_kind) << EndComment; 00437 break; 00438 00439 case IOC_EXIST: 00440 case IOC_NAMED: 00441 case IOC_OPENED: 00442 /* LOGICAL argument */ 00443 FORTTK_ASSERT(WN_kid_count(item) >= 1, 00444 "Unexpected kid count " << WN_kid_count(item)); 00445 xos << IOITEM_name(item_kind) << "***="; 00446 ctxt.currentXlationContext().setFlag(XlationContext::HAS_LOGICAL_ARG); 00447 if (TY_kind(WN_Tree_Type(WN_kid0(item))) != KIND_SCALAR) 00448 ctxt.currentXlationContext().setFlag(XlationContext::DEREF_ADDR); 00449 TranslateWN(xos, WN_kid0(item), ctxt); 00450 ctxt.currentXlationContext().unsetFlag(XlationContext::HAS_LOGICAL_ARG); 00451 break; 00452 00453 case IOC_READONLY: 00454 case IOC_SHARED: 00455 case IOC_U: 00456 xos << BegComment << "ctr=" << IOITEM_name(item_kind) << EndComment; 00457 break; 00458 00459 case IOC_VARFMT: 00460 break; 00461 00462 case IOC_VARFMT_ORIGFMT: 00463 /* We assume a label-number already has been assigned for 00464 * this FORMAT statement into Origfmt_Ioctrl_Label. See 00465 * also IOF_LABEL. Expect the string argument to be an 00466 * LDA of a string-constant (ST of class CONST). Note that 00467 * a string-constant always is '\0' terminated. 00468 */ 00469 FORTTK_ASSERT_WARN((WN_operator(WN_kid0(item)) == OPR_LDA && 00470 ST_class(WN_st(WN_kid0(item))) == CLASS_CONST), 00471 fortTkSupport::Diagnostics::UnexpectedOpr << IOITEM_name(WN_IOITEM(item))); 00472 //ctxt.currentXlationContext().unsetFlag(no_newline); 00473 xos << "FORMAT " << Num2Str(Origfmt_Ioctrl_Label, "%lld") 00474 << Targ_String_Address(STC_val(WN_st(WN_kid0(item)))); 00475 break; 00476 00477 case IOC_ERR: 00478 case IOC_EOR: 00479 case IOC_END: 00480 xos << IOITEM_name(item_kind); 00481 FORTTK_ASSERT_WARN((WN_operator(WN_kid0(item)) == OPR_GOTO), 00482 fortTkSupport::Diagnostics::UnexpectedOpr << WN_operator(item)); 00483 xos << WN_label_number(WN_kid0(item)); 00484 break; 00485 00486 case IOC_CR_FLFLAG: 00487 case IOC_CR_EDFLAG: 00488 case IOC_ERRFLAG: 00489 case IOC_CR_EEEFLAG: 00490 break; 00491 00492 default: 00493 /* The usual case; an arbitrary non-logic expression argument, 00494 * which is usually an integral value, an array, or a character 00495 * string. 00496 */ 00497 xos << IOITEM_name(item_kind) << "="; 00498 if (TY_kind(WN_Tree_Type(WN_kid0(item))) != KIND_SCALAR) 00499 ctxt.currentXlationContext().setFlag(XlationContext::DEREF_ADDR); 00500 00501 /* if kid count > 1, then it's a character object */ 00502 if (WN_kid_count(item) == 1) 00503 TranslateWN(xos, WN_kid0(item), ctxt); 00504 else 00505 WN2F_String_Argument(xos,WN_kid0(item),WN_kid1(item),ctxt); 00506 break; 00507 } 00508 00509 return TRUE; 00510 } 00511 00512 namespace whirl2xaif { 00513 00514 void 00515 WN2F_implied_do(xml::ostream& xos, WN *wn, PUXlationContext& ctxt); 00516 00517 }; /* namespace whirl2xaif */ 00518 00519 static BOOL 00520 xlate_IO_ITEM_list(xml::ostream& xos, WN *item, PUXlationContext& ctxt) 00521 { 00522 const IOITEM item_kind = WN_IOITEM(item); 00523 00524 switch (item_kind) { 00525 case IOL_VAR: 00526 case IOL_ARRAY: 00527 case IOL_CHAR_ARRAY: 00528 case IOL_RECORD: 00529 if (WN_operator(WN_kid0(item)) == OPR_LDID && 00530 ST_sclass(WN_st(WN_kid0(item))) == SCLASS_FORMAL && 00531 TY_Is_Pointer(WN_ty(WN_kid0(item))) && 00532 TY_Is_Pointer(TY_pointed(WN_ty(WN_kid0(item))))) { 00533 /* Work around a f77 bug */ 00534 WN_set_ty(WN_kid0(item), TY_pointed(WN_ty(WN_kid0(item)))); 00535 } 00536 ctxt.currentXlationContext().setFlag(XlationContext::DEREF_ADDR); /* Assume pass-by-reference */ 00537 TranslateWN(xos, WN_kid0(item), ctxt); 00538 break; 00539 00540 case IOL_CHAR: { 00541 WN * len = WN_kid1(item); 00542 if (ctxt.currentXlationContext().isFlag(XlationContext::CRAY_IO)) /* typecode is kid1 */ 00543 len = WN_kid2(item); 00544 00545 WN2F_String_Argument(xos, WN_kid0(item), /* base */ 00546 len /* length */, ctxt); 00547 } 00548 break; 00549 00550 case IOL_EXPR: 00551 ctxt.currentXlationContext().unsetFlag(XlationContext::DEREF_ADDR); /* Assume pass-by-value */ 00552 TranslateWN(xos, WN_kid0(item), ctxt); 00553 break; 00554 00555 case IOL_IMPLIED_DO: 00556 case IOL_IMPLIED_DO_1TRIP: 00557 ctxt.currentXlationContext().unsetFlag(XlationContext::DEREF_ADDR); /* Handled specially */ 00558 WN2F_implied_do(xos, item, ctxt); /* Defined in WN2F_stmt.c */ 00559 break; 00560 00561 case IOL_LOGICAL: 00562 ctxt.currentXlationContext().setFlag(XlationContext::HAS_LOGICAL_ARG); 00563 ctxt.currentXlationContext().unsetFlag(XlationContext::DEREF_ADDR); /* Assume pass-by-value */ 00564 TranslateWN(xos, WN_kid0(item), ctxt); 00565 break; 00566 00567 case IOL_DOPE: { 00568 INT32 kids = WN_kid_count(item); 00569 00570 /* base address */ 00571 ctxt.currentXlationContext().setFlag(XlationContext::DEREF_ADDR); 00572 TranslateWN(xos, WN_kid0(item), ctxt); 00573 #if 0 //August 00574 if (kids > 2) { /* implied do? */ 00575 /* Generate the subscript list - part may be in dope address, */ 00576 /* set up several stmts ago. may just get INTCONST(0) here */ 00577 INT32 i = 2 ; 00578 while (i < kids) { 00579 TranslateWN(xos, WN_kid(item,i), ctxt); 00580 } 00581 } 00582 #endif 00583 } 00584 break; 00585 00586 default: 00587 FORTTK_DIE(fortTkSupport::Diagnostics::UnexpectedOpr << IOITEM_name(WN_IOITEM(item))); 00588 xos << IOITEM_name(WN_IOITEM(item)); 00589 break; 00590 } /* switch */ 00591 00592 return TRUE; 00593 } 00594 00595 00596 // *************************************************************************** 00597 // SGI IO 00598 // *************************************************************************** 00599 00600 static void 00601 WN2F_ios_backspace(xml::ostream& xos, WN *wn, PUXlationContext& ctxt) 00602 { 00603 /* The kids should be an IOU, followed a sequence of IOCs. Always 00604 * use the explicit UNIT keyword, unless there is exactly one kid an 00605 * it is an IOU. 00606 */ 00607 FORTTK_ASSERT(WN_IOSTMT(wn) == IOS_BACKSPACE 00608 || WN_IOSTMT(wn) == IOS_CR_BACKSPACE, 00609 fortTkSupport::Diagnostics::UnexpectedOpr << IOSTATEMENT_name(WN_IOSTMT(wn))); 00610 00611 xos << "BACKSPACE"; 00612 if (WN_kid_count(wn) == 1 && IS_IO_ITEM_IOU(WN_kid0(wn))) 00613 xlate_IO_ITEM(xos, WN_kid0(wn), ctxt); 00614 else 00615 xlate_IOControlList(xos, wn, 00616 0 /* from kid*/, WN_kid_count(wn)-1 /* to kid*/, 00617 ctxt); 00618 00619 } /* WN2F_ios_backspace */ 00620 00621 00622 static void 00623 WN2F_ios_close(xml::ostream& xos, WN *wn, PUXlationContext& ctxt) 00624 { 00625 /* The kids should be an IOU, followed a sequence of IOCs. Always 00626 * use the explicit UNIT keyword. 00627 */ 00628 FORTTK_ASSERT(WN_IOSTMT(wn) == IOS_CLOSE||WN_IOSTMT(wn) == IOS_CR_CLOSE, 00629 fortTkSupport::Diagnostics::UnexpectedOpr << IOSTATEMENT_name(WN_IOSTMT(wn))); 00630 00631 fortTkSupport::WNId stmtid = ctxt.findWNId(wn); 00632 xos << BegElem(XAIFStrings.elem_Marker()) 00633 << Attr("statement_id", stmtid) 00634 << BegAttr("annotation") << WhirlIdAnnotVal(stmtid) 00635 << " [CLOSE***]" << EndAttr 00636 << EndElem; 00637 00638 #if 0 // FIXME 00639 xos << "CLOSE"; 00640 xlate_IOControlList(xos, wn, 00641 0 /* from kid*/, WN_kid_count(wn)-1 /* to kid*/, 00642 ctxt); 00643 #endif 00644 } /* WN2F_ios_close */ 00645 00646 00647 static void 00648 WN2F_ios_definefile(xml::ostream& xos, WN *wn, PUXlationContext& ctxt) 00649 { 00650 /* The kids should be an IOU, followed a sequence of IOCs. Always 00651 * use the explicit UNIT keyword. 00652 */ 00653 FORTTK_ASSERT(WN_io_statement(wn) == IOS_DEFINEFILE && 00654 WN_kid_count(wn) == 5 && 00655 WN_io_item(WN_kid(wn, 1)) == IOC_MAXREC && 00656 WN_io_item(WN_kid(wn, 2)) == IOC_RECL && 00657 WN_io_item(WN_kid(wn, 3)) == IOC_U && 00658 WN_io_item(WN_kid(wn, 4)) == IOC_ASSOCIATEVARIABLE, 00659 fortTkSupport::Diagnostics::UnexpectedOpr << IOSTATEMENT_name(WN_IOSTMT(wn))); 00660 00661 xos << "DEFINE FILE"; 00662 00663 xlate_IO_ITEM_unit(xos, WN_kid(wn, 0), ctxt); 00664 xos << "("; 00665 00666 if (TY_kind(WN_Tree_Type(WN_kid0(WN_kid(wn, 1)))) != KIND_SCALAR) 00667 ctxt.currentXlationContext().setFlag(XlationContext::DEREF_ADDR); 00668 TranslateWN(xos, WN_kid0(WN_kid(wn, 1)), ctxt); 00669 ctxt.currentXlationContext().unsetFlag(XlationContext::DEREF_ADDR); 00670 xos << ","; 00671 00672 if (TY_kind(WN_Tree_Type(WN_kid0(WN_kid(wn, 2)))) != KIND_SCALAR) 00673 ctxt.currentXlationContext().setFlag(XlationContext::DEREF_ADDR); 00674 TranslateWN(xos, WN_kid0(WN_kid(wn, 2)), ctxt); 00675 ctxt.currentXlationContext().unsetFlag(XlationContext::DEREF_ADDR); 00676 xos << ","; 00677 00678 xos << "U"; 00679 xos << ","; 00680 00681 if (TY_kind(WN_Tree_Type(WN_kid0(WN_kid(wn, 4)))) != KIND_SCALAR) 00682 ctxt.currentXlationContext().setFlag(XlationContext::DEREF_ADDR); 00683 TranslateWN(xos, WN_kid0(WN_kid(wn, 4)), ctxt); 00684 xos << ")"; 00685 00686 } /* WN2F_ios_definefile */ 00687 00688 00689 static void 00690 WN2F_ios_delete(xml::ostream& xos, WN *wn, PUXlationContext& ctxt) 00691 { 00692 /* The kids should be an IOU, followed a sequence of IOCs. Always 00693 * use the explicit UNIT keyword. 00694 */ 00695 FORTTK_ASSERT(WN_IOSTMT(wn) == IOS_DELETE, 00696 fortTkSupport::Diagnostics::UnexpectedOpr << IOSTATEMENT_name(WN_IOSTMT(wn))); 00697 00698 xos << "DELETE"; 00699 xlate_IOControlList(xos, wn, 00700 0 /* from kid*/, WN_kid_count(wn)-1 /* to kid*/, ctxt); 00701 } /* WN2F_ios_delete */ 00702 00703 00704 static void 00705 WN2F_ios_endfile(xml::ostream& xos, WN *wn, PUXlationContext& ctxt) 00706 { 00707 /* The kids should be an IOU, followed a sequence of IOCs. Always 00708 * use the explicit UNIT keyword, unless there is exactly one kid an 00709 * it is an IOU. 00710 */ 00711 FORTTK_ASSERT(WN_IOSTMT(wn) == IOS_ENDFILE 00712 || WN_IOSTMT(wn) == IOS_CR_ENDFILE, 00713 fortTkSupport::Diagnostics::UnexpectedOpr << IOSTATEMENT_name(WN_IOSTMT(wn))); 00714 00715 xos << "ENDFILE"; 00716 if (WN_kid_count(wn) == 1 && IS_IO_ITEM_IOU(WN_kid0(wn))) 00717 xlate_IO_ITEM(xos, WN_kid0(wn), ctxt); 00718 else 00719 xlate_IOControlList(xos, wn, 00720 0 /* from kid*/, WN_kid_count(wn)-1 /* to kid*/, ctxt); 00721 00722 } /* WN2F_ios_endfile */ 00723 00724 00725 static void 00726 WN2F_ios_find(xml::ostream& xos, WN *wn, PUXlationContext& ctxt) 00727 { 00728 /* The kids should be an IOU, followed a sequence of IOCs. Always 00729 * use the explicit UNIT keyword. 00730 */ 00731 FORTTK_ASSERT(WN_IOSTMT(wn) == IOS_FIND, 00732 fortTkSupport::Diagnostics::UnexpectedOpr << IOSTATEMENT_name(WN_IOSTMT(wn))); 00733 00734 xos << "FIND"; 00735 xlate_IOControlList(xos, wn, 00736 0 /* from kid*/, WN_kid_count(wn)-1 /* to kid*/, ctxt); 00737 } /* WN2F_ios_find */ 00738 00739 00740 static void 00741 WN2F_ios_inquire(xml::ostream& xos, WN *wn, PUXlationContext& ctxt) 00742 { 00743 /* The kids should be an optional IOU, followed a sequence of IOCs. 00744 * Always use the explicit UNIT keyword when the IOU is present. 00745 */ 00746 FORTTK_ASSERT(WN_IOSTMT(wn) == IOS_INQUIRE || 00747 WN_IOSTMT(wn) == IOS_CR_INQUIRE, 00748 fortTkSupport::Diagnostics::UnexpectedOpr << IOSTATEMENT_name(WN_IOSTMT(wn))); 00749 00750 xos << BegElem(XAIFStrings.elem_Marker()) 00751 << Attr("statement_id", ctxt.currentXlationContext().getNewVertexId()) 00752 << BegAttr("annotation") << WhirlIdAnnotVal(ctxt.findWNId(wn)) 00753 << " [INQUIRE***]" << EndAttr 00754 << EndElem; 00755 00756 #if 0 00757 xos << "INQUIRE"; 00758 xlate_IOControlList(xos, wn, 00759 0, /* from kid*/ 00760 WN_kid_count(wn)-1, /* to kid*/ 00761 ctxt); 00762 #endif 00763 00764 } /* WN2F_ios_inquire */ 00765 00766 00767 static void 00768 WN2F_ios_namelist(xml::ostream& xos, WN *wn, PUXlationContext& ctxt) 00769 { 00770 FORTTK_ASSERT(WN_IOSTMT(wn) == IOS_NAMELIST, 00771 fortTkSupport::Diagnostics::UnexpectedOpr << IOSTATEMENT_name(WN_IOSTMT(wn))); 00772 00773 xos << "NAMELIST/"; 00774 xlate_IO_ITEM(xos, WN_kid1(wn), ctxt); 00775 xos << "/"; 00776 00777 if (WN_kid_count(wn) > 2) 00778 xlate_IOList(xos, wn, 2, ctxt); 00779 00780 } /* WN2F_ios_namelist */ 00781 00782 00783 static void 00784 WN2F_ios_open(xml::ostream& xos, WN *wn, PUXlationContext& ctxt) 00785 { 00786 /* The kids should be an IOU, followed a sequence of IOCs. Always 00787 * use the explicit UNIT keyword. 00788 */ 00789 FORTTK_ASSERT(WN_IOSTMT(wn) == IOS_OPEN || WN_IOSTMT(wn) == IOS_CR_OPEN, 00790 fortTkSupport::Diagnostics::UnexpectedOpr << IOSTATEMENT_name(WN_IOSTMT(wn))); 00791 00792 fortTkSupport::WNId stmtid = ctxt.findWNId(wn); 00793 xos << BegElem(XAIFStrings.elem_Marker()) 00794 << Attr("statement_id", stmtid) 00795 << BegAttr("annotation") << WhirlIdAnnotVal(stmtid) 00796 << " [OPEN***]" << EndAttr 00797 << EndElem; 00798 } /* WN2F_ios_open */ 00799 00800 00801 static void 00802 WN2F_ios_rewind(xml::ostream& xos, WN *wn, PUXlationContext& ctxt) { 00803 FORTTK_ASSERT(WN_IOSTMT(wn) == IOS_REWIND || WN_IOSTMT(wn) == IOS_CR_REWIND, 00804 fortTkSupport::Diagnostics::UnexpectedOpr << IOSTATEMENT_name(WN_IOSTMT(wn))); 00805 fortTkSupport::WNId stmtid = ctxt.findWNId(wn); 00806 xos << BegElem(XAIFStrings.elem_Marker()) 00807 << Attr("statement_id", stmtid) 00808 << BegAttr("annotation") << WhirlIdAnnotVal(stmtid) 00809 << " [REWIND***]" << EndAttr; 00810 xos << EndElem; 00811 } /* WN2F_ios_rewind */ 00812 00813 00814 static void 00815 WN2F_ios_unlock(xml::ostream& xos, WN *wn, PUXlationContext& ctxt) 00816 { 00817 /* The kids should be an IOU, followed a sequence of IOCs. Always 00818 * use the explicit UNIT keyword, unless there is exactly one kid an 00819 * it is an IOU. 00820 */ 00821 FORTTK_ASSERT(WN_IOSTMT(wn) == IOS_UNLOCK, 00822 fortTkSupport::Diagnostics::UnexpectedOpr << IOSTATEMENT_name(WN_IOSTMT(wn))); 00823 00824 xos << "UNLOCK"; 00825 if (WN_kid_count(wn) == 1 && IS_IO_ITEM_IOU(WN_kid0(wn))) 00826 xlate_IO_ITEM(xos, WN_kid0(wn), ctxt); 00827 else 00828 xlate_IOControlList(xos, wn, 00829 0 /* from kid*/, WN_kid_count(wn)-1 /* to kid*/, ctxt); 00830 00831 } /* WN2F_ios_unlock */ 00832 00833 00834 static void 00835 WN2F_ios_accept(xml::ostream& xos, WN *wn, PUXlationContext& ctxt) 00836 { 00837 /* The kids should be an IOF, followed a sequence of IOLs. 00838 */ 00839 FORTTK_ASSERT(WN_IOSTMT(wn) == IOS_ACCEPT, 00840 fortTkSupport::Diagnostics::UnexpectedOpr << IOSTATEMENT_name(WN_IOSTMT(wn))); 00841 00842 xos << "ACCEPT"; 00843 xlate_IO_ITEM(xos, WN_kid0(wn), ctxt); 00844 if (WN_kid_count(wn) > 1) { 00845 xlate_IOList(xos, wn, 1, ctxt); 00846 } 00847 } /* WN2F_ios_accept */ 00848 00849 00850 static void 00851 WN2F_ios_decode(xml::ostream& xos, WN *wn, PUXlationContext& ctxt) 00852 { 00853 /* The kids should be an IOU, followed by an IOF, followed by a 00854 * sequence of IOCs and a sequence of IOLs. Use keywords only 00855 * when the IOC list is non-empty. Note that the IOU contains 00856 * both the integer expression (c) and the scalar or array 00857 * reference (a) in "ENCODE (c, f, a [,IOSTAT=ios][,ERR=s]) iolist". 00858 */ 00859 INT iol_kid; 00860 00861 FORTTK_ASSERT(WN_IOSTMT(wn) == IOS_DECODE, 00862 fortTkSupport::Diagnostics::UnexpectedOpr << IOSTATEMENT_name(WN_IOSTMT(wn))); 00863 00864 /* This is needed for the translation of the number of characters and 00865 * the buffer we decode characters from. 00866 */ 00867 ctxt.currentXlationContext().setFlag(XlationContext::DEREF_ADDR); 00868 00869 xos << "DECODE("; 00870 00871 /* Translate the number of characters */ 00872 FORTTK_ASSERT_WARN(WN_IOITEM(WN_kid0(wn)) == IOU_INTERNAL && 00873 WN_kid_count(WN_kid0(wn)) >= 2, 00874 fortTkSupport::Diagnostics::UnexpectedOpr << IOITEM_name(WN_IOITEM(WN_kid0(wn)))); 00875 TranslateWN(xos, WN_kid1(WN_kid0(wn)), ctxt); 00876 00877 /* Translate the format */ 00878 xos << ","; 00879 xlate_IO_ITEM(xos, WN_kid1(wn), ctxt); 00880 00881 /* Translate the buffer we decode from */ 00882 xos << ","; 00883 TranslateWN(xos, WN_kid0(WN_kid0(wn)), ctxt); 00884 00885 /* Translate the EOSTAT and the ERR items */ 00886 iol_kid = 2; 00887 if (WN_kid_count(wn) > 2 && IS_IO_ITEM_IOC(WN_kid(wn, 2))) { 00888 iol_kid = 3; 00889 xos << ","; 00890 xlate_IO_ITEM(xos, WN_kid(wn, 2), ctxt); 00891 } 00892 if (WN_kid_count(wn) > 3 && IS_IO_ITEM_IOC(WN_kid(wn, 3))) { 00893 iol_kid = 4; 00894 xos << ","; 00895 xlate_IO_ITEM(xos, WN_kid(wn, 3), ctxt); 00896 } 00897 xos << ")"; 00898 00899 /* Get the io_list */ 00900 if (WN_kid_count(wn) > iol_kid) 00901 xlate_IOList(xos, wn, iol_kid, ctxt); 00902 00903 } /* WN2F_ios_decode */ 00904 00905 00906 static void 00907 WN2F_ios_encode(xml::ostream& xos, WN *wn, PUXlationContext& ctxt) 00908 { 00909 /* The kids should be an IOU, followed by an IOF, followed by a 00910 * sequence of IOCs and a sequence of IOLs. Use keywords only 00911 * when the IOC list is non-empty. Note that the IOU contains 00912 * both the integer expression (c) and the scalar or array 00913 * reference (a) in "ENCODE (c, f, a [,IOSTAT=ios][,ERR=s]) iolist". 00914 */ 00915 INT iol_kid; 00916 00917 FORTTK_ASSERT(WN_IOSTMT(wn) == IOS_ENCODE, 00918 fortTkSupport::Diagnostics::UnexpectedOpr << IOSTATEMENT_name(WN_IOSTMT(wn))); 00919 00920 /* This is needed for the translation of the number of characters and 00921 * the buffer we encode characters from. 00922 */ 00923 ctxt.currentXlationContext().setFlag(XlationContext::DEREF_ADDR); 00924 00925 xos << "ENCODE("; 00926 00927 /* Translate the number of characters */ 00928 FORTTK_ASSERT_WARN(WN_IOITEM(WN_kid0(wn)) == IOU_INTERNAL && 00929 WN_kid_count(WN_kid0(wn)) >= 2, 00930 fortTkSupport::Diagnostics::UnexpectedOpr << IOITEM_name(WN_IOITEM(WN_kid0(wn)))); 00931 TranslateWN(xos, WN_kid1(WN_kid0(wn)), ctxt); 00932 00933 /* Translate the format */ 00934 xos << ","; 00935 xlate_IO_ITEM(xos, WN_kid1(wn), ctxt); 00936 00937 /* Translate the buffer we encode from */ 00938 xos << ","; 00939 TranslateWN(xos, WN_kid0(WN_kid0(wn)), ctxt); 00940 00941 /* Translate the EOSTAT and the ERR items */ 00942 iol_kid = 2; 00943 if (WN_kid_count(wn) > 2 && IS_IO_ITEM_IOC(WN_kid(wn, 2))) { 00944 iol_kid = 3; 00945 xos << ","; 00946 xlate_IO_ITEM(xos, WN_kid(wn, 2), ctxt); 00947 } 00948 if (WN_kid_count(wn) > 3 && IS_IO_ITEM_IOC(WN_kid(wn, 3))) { 00949 iol_kid = 4; 00950 xos << ","; 00951 xlate_IO_ITEM(xos, WN_kid(wn, 3), ctxt); 00952 } 00953 xos << ")"; 00954 00955 /* Get the io_list */ 00956 if (WN_kid_count(wn) > iol_kid) 00957 xlate_IOList(xos, wn, iol_kid, ctxt); 00958 00959 } /* WN2F_ios_encode */ 00960 00961 00962 static void 00963 WN2F_ios_print(xml::ostream& xos, WN *wn, PUXlationContext& ctxt) 00964 { 00965 INT iol_kid; 00966 00967 /* The kids should be an IOF, followed a sequence of IOLs. 00968 */ 00969 FORTTK_ASSERT(WN_IOSTMT(wn) == IOS_PRINT, 00970 fortTkSupport::Diagnostics::UnexpectedOpr << IOSTATEMENT_name(WN_IOSTMT(wn))); 00971 00972 xos << "PRINT"; 00973 00974 //ctxt.currentXlationContext().setFlag(issue_ioc_asterisk); 00975 00976 /* We do not really expect to have a unit specification for a "PRINT" 00977 * statement, but just in the case one occurs anyway, we skip it here. 00978 */ 00979 if (IS_IO_ITEM_IOU(WN_kid0(wn))) 00980 iol_kid = 2; /* kid 1 must be the format */ 00981 else 00982 iol_kid = 1; /* Missing unit number */ 00983 xlate_IO_ITEM(xos, WN_kid(wn, iol_kid-1), ctxt); 00984 if (WN_kid_count(wn) > iol_kid) { 00985 xlate_IOList(xos, wn, iol_kid, ctxt); 00986 } 00987 00988 //ctxt.currentXlationContext().unsetFlag(issue_ioc_asterisk); 00989 00990 } /* WN2F_ios_print */ 00991 00992 00993 static void 00994 WN2F_ios_read(xml::ostream& xos, WN *wn, PUXlationContext& ctxt) 00995 { 00996 /* The kids should be an IOU, followed by an IOF, followed by a 00997 * sequence of IOCs and a sequence of IOLs. Use keywords only 00998 * when the IOC list is non-empty. The IOL should be a sequence 00999 * of addresses into which the values read should be put. In 01000 * the whirl2f output these addresses must be dereferenced. 01001 */ 01002 INT iol_kid; 01003 BOOL use_keyword; 01004 01005 01006 xos << "READ"; 01007 //ctxt.currentXlationContext().setFlag(issue_ioc_asterisk); 01008 01009 /* Determine whether or not we have the "READ f [,iolist]" format. 01010 */ 01011 if (WN_IOITEM(WN_kid0(wn)) == IOU_DEFAULT && 01012 IS_IO_ITEM_IOF(WN_kid1(wn)) && 01013 WN_IOITEM(WN_kid1(wn)) != IOF_NAMELIST_DIRECTED && 01014 (WN_kid_count(wn) == 2 || IS_IO_ITEM_IOL(WN_kid(wn, 2)))) { 01015 xlate_IO_ITEM(xos, WN_kid0(wn), ctxt); 01016 iol_kid = 2; 01017 if (WN_kid_count(wn) > 2) 01018 xos << ","; 01019 } else { 01020 for (iol_kid = 0; 01021 (iol_kid < WN_kid_count(wn)) && !IS_IO_ITEM_IOL(WN_kid(wn, iol_kid)); 01022 iol_kid++); 01023 01024 /* Get the IOU, IOF, and IOC items */ 01025 xlate_IOControlList(xos, wn, 01026 0, /* from kid*/ 01027 iol_kid-1, /* to kid*/ 01028 ctxt); 01029 } 01030 01031 /* Get the io_list */ 01032 if (iol_kid < WN_kid_count(wn)) { 01033 ctxt.currentXlationContext().setFlag(XlationContext::DEREF_IO_ITEM); /* Assume pass-by-reference */ 01034 xlate_IOList(xos, wn, iol_kid, ctxt); 01035 } 01036 01037 //ctxt.currentXlationContext().unsetFlag(issue_ioc_asterisk); 01038 01039 } /* WN2F_ios_read */ 01040 01041 01042 static void 01043 WN2F_ios_rewrite(xml::ostream& xos, WN *wn, PUXlationContext& ctxt) 01044 { 01045 /* The kids should be an IOU, followed by an IOF, followed by a 01046 * sequence of IOCs and a sequence of IOLs. Use keywords only 01047 * when the IOC list is non-empty. 01048 */ 01049 INT iol_kid; 01050 01051 FORTTK_ASSERT(WN_IOSTMT(wn) == IOS_REWRITE, 01052 fortTkSupport::Diagnostics::UnexpectedOpr << IOSTATEMENT_name(WN_IOSTMT(wn))); 01053 01054 xos << "REWRITE"; 01055 //ctxt.currentXlationContext().setFlag(issue_ioc_asterisk); 01056 01057 for (iol_kid = 0; 01058 (iol_kid < WN_kid_count(wn)) && !IS_IO_ITEM_IOL(WN_kid(wn, iol_kid)); 01059 iol_kid++); 01060 01061 /* Get the IOU, IOF, and IOC items */ 01062 xlate_IOControlList(xos, wn, 01063 0, /* from kid*/ 01064 iol_kid-1, /* to kid*/ 01065 ctxt); 01066 01067 /* Get the io_list */ 01068 if (iol_kid < WN_kid_count(wn)) 01069 xlate_IOList(xos, wn, iol_kid, ctxt); 01070 01071 //ctxt.currentXlationContext().unsetFlag(issue_ioc_asterisk); 01072 01073 } /* WN2F_ios_rewrite */ 01074 01075 01076 static void 01077 WN2F_ios_type(xml::ostream& xos, WN *wn, PUXlationContext& ctxt) 01078 { 01079 /* The kids should be an IOF, followed a sequence of IOLs. 01080 */ 01081 FORTTK_ASSERT(WN_IOSTMT(wn) == IOS_TYPE, 01082 fortTkSupport::Diagnostics::UnexpectedOpr << IOSTATEMENT_name(WN_IOSTMT(wn))); 01083 01084 xos << "TYPE"; 01085 xlate_IO_ITEM(xos, WN_kid0(wn), ctxt); 01086 if (WN_kid_count(wn) > 1) { 01087 xlate_IOList(xos, wn, 1, ctxt); 01088 } 01089 } /* WN2F_ios_type */ 01090 01091 01092 static void 01093 WN2F_ios_write(xml::ostream& xos, WN *wn, PUXlationContext& ctxt) 01094 { 01095 /* The kids should be an IOU, followed by an IOF, followed by a 01096 * sequence of IOCs and a sequence of IOLs. Use keywords only 01097 * when the IOC list is non-empty. 01098 */ 01099 fortTkSupport::WNId stmtid = ctxt.findWNId(wn); 01100 xos << BegElem(XAIFStrings.elem_Marker()) 01101 << Attr("statement_id", stmtid) 01102 << BegAttr("annotation") << WhirlIdAnnotVal(stmtid) 01103 << " [WRITE***]" << EndAttr; 01104 01105 #if 0 // FIXME: comment out for now 01106 //ctxt.currentXlationContext().setFlag(issue_ioc_asterisk); 01107 01108 INT iol_kid; 01109 for (iol_kid = 0; 01110 (iol_kid < WN_kid_count(wn)) && !IS_IO_ITEM_IOL(WN_kid(wn, iol_kid)); 01111 iol_kid++); 01112 01113 /* Get the IOU, IOF, and IOC items */ 01114 xlate_IOControlList(xos, wn, 01115 0 /* from kid */, iol_kid-1 /* to kid */, ctxt); 01116 01117 /* Get the io_list */ 01118 if (iol_kid < WN_kid_count(wn)) 01119 xlate_IOList(xos, wn, iol_kid, ctxt); 01120 01121 //ctxt.currentXlationContext().unsetFlag(issue_ioc_asterisk); 01122 #endif 01123 xos << EndElem; 01124 01125 } /* WN2F_ios_write */ 01126 01127 01128 // *************************************************************************** 01129 // Cray IO 01130 // *************************************************************************** 01131 01132 static void 01133 WN2F_ios_cr(xml::ostream& xos, WN *wn, PUXlationContext& ctxt) 01134 { 01135 // Craylibs IO - write/read The kids should be an IOS, with kids of IO_ITEMS 01136 IOSTATEMENT iostmt = WN_io_statement(wn); 01137 FORTTK_ASSERT(iostmt == IOS_CR_FWF || iostmt == IOS_CR_FWU 01138 || iostmt == IOS_CR_FRF || iostmt == IOS_CR_FRU, 01139 fortTkSupport::Diagnostics::UnexpectedOpr << IOSTATEMENT_name(iostmt)); 01140 01141 //ctxt.currentXlationContext().setFlag(issue_ioc_asterisk); 01142 01143 /* decide if read/write formatted/unformatted */ 01144 if (iostmt == IOS_CR_FWF || iostmt == IOS_CR_FRF) 01145 ctxt.currentXlationContext().setFlag(XlationContext::FMT_IO) ; 01146 01147 const char* io_op = "WRITE***"; 01148 if (iostmt == IOS_CR_FRF || iostmt == IOS_CR_FRU) { 01149 io_op = "READ***" ; 01150 } 01151 01152 fortTkSupport::WNId stmtid = ctxt.findWNId(wn); 01153 xos << BegElem(XAIFStrings.elem_Marker()) 01154 << Attr("statement_id", stmtid) 01155 << BegAttr("annotation") << WhirlIdAnnotVal(stmtid) 01156 << " [" << io_op << "]" << EndAttr; 01157 01158 #if 0 // FIXME: comment out for now 01159 /* count items in control list */ 01160 INT iol_kid; 01161 for (iol_kid = 0; 01162 (iol_kid < WN_kid_count(wn)) && !IS_IO_ITEM_IOL(WN_kid(wn, iol_kid)); 01163 iol_kid++); 01164 01165 /* Get the IOU, IOF, and IOC items */ 01166 xlate_IOControlList(xos, wn, 01167 0 /* from kid */, iol_kid-1 /* to kid */, ctxt); 01168 01169 /* Get the IOL (io_list) */ 01170 if (iol_kid < WN_kid_count(wn)) 01171 xlate_IOList(xos, wn, iol_kid, ctxt); 01172 01173 //reset_PUXlationContex_issue_ioc_asterisk(ctxt); 01174 #endif 01175 01176 xos << EndElem; 01177 } 01178