00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 static char USMID[] = "\n@(#)5.0_pl/sources/fortout.c 5.2 05/27/99 10:30:26\n";
00042
00043 # include "defines.h"
00044
00045 # include "host.m"
00046 # include "host.h"
00047 # include "target.m"
00048 # include "target.h"
00049
00050 # include "globals.m"
00051 # include "tokens.m"
00052 # include "sytb.m"
00053
00054 # include "globals.h"
00055 # include "tokens.h"
00056 # include "sytb.h"
00057
00058 static void print_attr_f(int, FILE *);
00059 static char start[20];
00060 static int start_column;
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078 void print_scp_to_fortran(int ln_fw_idx,
00079 int ln_lw_idx,
00080 int pgm_attr_idx,
00081 FILE *outfile)
00082
00083 {
00084 int attr_idx;
00085 int i;
00086 int ln_idx;
00087
00088
00089 for (i=1; i < 20; i++) start[i] = '\0';
00090 start[0] = '\n';
00091 start_column = 1;
00092
00093 fprintf(outfile, "%s!DIR$ FREE", start);
00094
00095 print_attr_f(pgm_attr_idx, outfile);
00096
00097 for (ln_idx = ln_fw_idx; ln_idx <= ln_lw_idx; ln_idx++) {
00098 attr_idx = LN_ATTR_IDX(ln_idx);
00099
00100 switch (AT_OBJ_CLASS(attr_idx)) {
00101 case Data_Obj:
00102
00103 if (ATD_CLASS(attr_idx) != Dummy_Argument) {
00104 print_attr_f(attr_idx, outfile);
00105 }
00106 break;
00107
00108 case Pgm_Unit:
00109
00110 if (ATP_IN_INTERFACE_BLK(attr_idx)) {
00111
00112 if (ATP_IN_UNNAMED_INTERFACE(attr_idx)) {
00113 print_attr_f(attr_idx, outfile);
00114 }
00115 }
00116 else if (attr_idx != pgm_attr_idx) {
00117 print_attr_f(attr_idx, outfile);
00118 }
00119 break;
00120
00121 case Label:
00122 break;
00123
00124 case Derived_Type:
00125 case Interface:
00126 case Namelist_Grp:
00127 case Stmt_Func:
00128 print_attr_f(attr_idx, outfile);
00129 break;
00130 }
00131 }
00132
00133 fprintf(outfile, "%sEND\n", start);
00134
00135 return;
00136 }
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154 static void print_attr_f (int attr_idx,
00155 FILE *outfile)
00156
00157 {
00158 char *comma;
00159 int i;
00160 int len;
00161 int newlen;
00162 int num_dargs;
00163 #ifdef KEY
00164 int save_start_column = 0;
00165 #else
00166 int save_start_column;
00167 #endif
00168 int sn_idx;
00169
00170
00171 switch (AT_OBJ_CLASS(attr_idx)) {
00172 case Data_Obj:
00173
00174 if (ATD_IN_COMMON(attr_idx) &&
00175 SB_FIRST_ATTR_IDX(ATD_STOR_BLK_IDX(attr_idx)) == attr_idx) {
00176
00177
00178
00179 if (SB_BLANK_COMMON(ATD_STOR_BLK_IDX(attr_idx))) {
00180 fprintf(outfile, "%sCOMMON // ", start);
00181 fprintf(outfile, "%sCOMMON /%s/ ", start,
00182 SB_NAME_PTR(ATD_STOR_BLK_IDX(attr_idx)));
00183 }
00184 }
00185
00186 if (ATD_TYPE_IDX(attr_idx) != NULL_IDX) {
00187 fprintf(outfile, "%s%s :: ", start,
00188 print_type_f(ATD_TYPE_IDX(attr_idx)));
00189 }
00190 else {
00191 fprintf(outfile, "%s", start);
00192 }
00193 fprintf(outfile, "%s", AT_OBJ_NAME_PTR(attr_idx));
00194 break;
00195
00196 case Pgm_Unit:
00197 num_dargs = 0;
00198
00199 switch (ATP_PGM_UNIT(attr_idx)) {
00200 case Pgm_Unknown:
00201 break;
00202
00203 case Function:
00204 case Subroutine:
00205 fprintf(outfile, "%s", start);
00206 len = start_column - 1;
00207
00208 if (ATP_IN_UNNAMED_INTERFACE(attr_idx)) {
00209 fprintf(outfile, "INTERFACE ");
00210 save_start_column = start_column;
00211
00212 if (start_column <= 18) {
00213 start[start_column++] = ' ';
00214 start[start_column++] = ' ';
00215 }
00216 fprintf(outfile, "%s", start);
00217 len = start_column - 1;
00218 }
00219
00220 if (ATP_RECURSIVE(attr_idx)) {
00221 fprintf(outfile, "RECURSIVE ");
00222 len = 10;
00223 }
00224
00225 if (ATP_PURE(attr_idx)) {
00226 fprintf(outfile, "PURE ");
00227 len += 5;
00228 }
00229
00230 if (ATP_ELEMENTAL(attr_idx)) {
00231 fprintf(outfile, "ELEMENTAL ");
00232 len += 10;
00233 }
00234
00235 if (ATP_PGM_UNIT(attr_idx) == Function) {
00236 fprintf(outfile, "FUNCTION ");
00237 len += 9;
00238 }
00239 else {
00240 fprintf(outfile, "SUBROUTINE ");
00241 len += 11;
00242 }
00243
00244 fprintf(outfile,"%s(", AT_OBJ_NAME_PTR(attr_idx));
00245 len += AT_NAME_LEN(attr_idx) + 2;
00246
00247 if (ATP_EXPL_ITRFC(attr_idx) && ATP_EXTRA_DARG(attr_idx)) {
00248 num_dargs = ATP_NUM_DARGS(attr_idx) - 1;
00249 sn_idx = ATP_FIRST_IDX(attr_idx) + 1;
00250 }
00251 else {
00252 num_dargs = ATP_NUM_DARGS(attr_idx);
00253 sn_idx = ATP_FIRST_IDX(attr_idx);
00254 }
00255
00256 comma = " ";
00257
00258 for (i = num_dargs; i > 0; i--) {
00259 newlen = len + AT_NAME_LEN(SN_ATTR_IDX(sn_idx)) + 1;
00260
00261 if (newlen > 78) {
00262 fprintf(outfile, "%s &%s & ", comma, start);
00263 len = 6 + start_column - 1;
00264 }
00265 else {
00266 fprintf(outfile, "%s", comma);
00267 len++;
00268 }
00269
00270 fprintf(outfile, "%s", AT_OBJ_NAME_PTR(SN_ATTR_IDX(sn_idx)));
00271 len += AT_NAME_LEN(SN_ATTR_IDX(sn_idx));
00272 sn_idx = sn_idx++;
00273 comma = ",";
00274 }
00275
00276 fprintf(outfile, ")");
00277
00278 if (ATP_RSLT_NAME(attr_idx)) {
00279
00280 if ((len + 10 + AT_NAME_LEN(ATP_RSLT_IDX(attr_idx))) > 80) {
00281 fprintf(outfile, " &%s & ", start);
00282 }
00283 fprintf(outfile, " RESULT(%s)",
00284 AT_OBJ_NAME_PTR(ATP_RSLT_IDX(attr_idx)));
00285 }
00286
00287 if (num_dargs > 0) {
00288 sn_idx = ATP_EXTRA_DARG(attr_idx) ? ATP_FIRST_IDX(attr_idx) + 1:
00289 ATP_FIRST_IDX(attr_idx);
00290
00291 for (i = ATP_NUM_DARGS(attr_idx); i > 0; i--) {
00292 print_attr_f(SN_ATTR_IDX(sn_idx), outfile);
00293 sn_idx = sn_idx++;
00294 }
00295 }
00296
00297 if (ATP_PGM_UNIT(attr_idx) == Function) {
00298 fprintf(outfile, "%sEND FUNCTION", start);
00299 }
00300 else {
00301 fprintf(outfile, "%sEND SUBROUTINE", start);
00302 }
00303
00304 if (ATP_IN_UNNAMED_INTERFACE(attr_idx)) {
00305
00306 if (save_start_column != start_column) {
00307 start[--start_column] = '\0';
00308 start[--start_column] = '\0';
00309 }
00310 fprintf(outfile, "%sEND INTERFACE", start);
00311 }
00312
00313 break;
00314
00315 case Program:
00316 fprintf(outfile, "%sPROGRAM %s", start, AT_OBJ_NAME_PTR(attr_idx));
00317 break;
00318
00319 case Blockdata:
00320 fprintf(outfile, "%sBLOCKDATA %s", start, AT_OBJ_NAME_PTR(attr_idx));
00321
00322 break;
00323
00324 case Module:
00325 fprintf(outfile, "%sMODULE %s", start, AT_OBJ_NAME_PTR(attr_idx));
00326 break;
00327 }
00328
00329 if (ATP_DCL_EXTERNAL(attr_idx)) {
00330 fprintf(outfile, "%sEXTERNAL %s", start, AT_OBJ_NAME_PTR(attr_idx));
00331 }
00332
00333 if (ATP_STACK_DIR(attr_idx)) {
00334 fprintf(outfile, "%s!DIR$ STACK", start);
00335 }
00336
00337 if (ATP_SAVE_ALL(attr_idx)) {
00338 fprintf(outfile, "%sSAVE", start);
00339 }
00340
00341 if (ATP_SYMMETRIC(attr_idx)) {
00342 fprintf(outfile, "%s!DIR$ SYMMETRIC", start);
00343 }
00344
00345 if (ATP_USES_EREGS(attr_idx)) {
00346 fprintf(outfile, "%s!DIR$ USES_EREGS", start);
00347 }
00348 break;
00349
00350 case Label:
00351 break;
00352
00353 case Derived_Type:
00354 sn_idx = ATT_FIRST_CPNT_IDX(attr_idx);
00355 fprintf(outfile, "%sTYPE :: %s", start, AT_OBJ_NAME_PTR(attr_idx));
00356 save_start_column = start_column;
00357
00358 if (start_column <= 18) {
00359 start[start_column++] = ' ';
00360 start[start_column++] = ' ';
00361 }
00362
00363 for (i = ATT_NUM_CPNTS(attr_idx); i > 0; i--) {
00364 print_attr_f(SN_ATTR_IDX(sn_idx), outfile);
00365 sn_idx = SN_SIBLING_LINK(sn_idx);
00366 }
00367
00368 if (save_start_column != start_column) {
00369 start[--start_column] = '\0';
00370 start[--start_column] = '\0';
00371 }
00372
00373 fprintf(outfile, "%sEND TYPE %s", start, AT_OBJ_NAME_PTR(attr_idx));
00374 break;
00375
00376 case Interface:
00377 sn_idx = ATI_FIRST_SPECIFIC_IDX(attr_idx);
00378 fprintf(outfile, "%sINTERFACE %s", start,
00379 (ATI_UNNAMED_INTERFACE(attr_idx) ? " " :
00380 AT_OBJ_NAME_PTR(attr_idx)));
00381
00382 save_start_column = start_column;
00383
00384 if (start_column <= 18) {
00385 start[start_column++] = ' ';
00386 start[start_column++] = ' ';
00387 }
00388
00389
00390 for (i = ATI_NUM_SPECIFICS(attr_idx); i > 0; i--) {
00391
00392 if (ATP_PROC(SN_ATTR_IDX(sn_idx)) == Module_Proc) {
00393 fprintf(outfile, "%sMODULE PROCEDURE %s", start,
00394 AT_OBJ_NAME_PTR(SN_ATTR_IDX(sn_idx)));
00395 }
00396 else {
00397 print_attr_f(SN_ATTR_IDX(sn_idx), outfile);
00398 }
00399 sn_idx = SN_SIBLING_LINK(sn_idx);
00400 }
00401
00402 if (save_start_column != start_column) {
00403 start[--start_column] = '\0';
00404 start[--start_column] = '\0';
00405 }
00406
00407 fprintf(outfile, "%sEND INTERFACE", start);
00408
00409 if (ATI_DCL_INTRINSIC(attr_idx)) {
00410 fprintf(outfile, "%sINTRINSIC :: %s", start,
00411 AT_OBJ_NAME_PTR(attr_idx));
00412 }
00413
00414 break;
00415
00416 case Namelist_Grp:
00417
00418 sn_idx = ATN_FIRST_NAMELIST_IDX(attr_idx);
00419 len = 80;
00420
00421 for (i = ATN_NUM_NAMELIST(attr_idx); i > 0; i--) {
00422 newlen = len + AT_NAME_LEN(SN_ATTR_IDX(sn_idx)) + 1;
00423
00424 if (newlen > 80) {
00425 fprintf(outfile, "%sNAMELIST /%s/ ", start,
00426 AT_OBJ_NAME_PTR(attr_idx));
00427 len = AT_NAME_LEN(attr_idx) + 12 + start_column - 1;
00428 }
00429 else {
00430 fprintf(outfile, "%s", ",");
00431 len++;
00432 }
00433
00434 fprintf(outfile, "%s", AT_OBJ_NAME_PTR(SN_ATTR_IDX(sn_idx)));
00435 len += AT_NAME_LEN(SN_ATTR_IDX(sn_idx));
00436 sn_idx = SN_SIBLING_LINK(sn_idx);
00437 }
00438
00439 # ifdef _DEBUG
00440
00441 if (ATN_NAMELIST_DESC(attr_idx) != NULL_IDX) {
00442
00443 if (len > 64) {
00444 fprintf(outfile, "%s", start);
00445 }
00446
00447 fprintf(outfile, " ! (%s)",
00448 AT_OBJ_NAME_PTR(ATN_NAMELIST_DESC(attr_idx)));
00449 }
00450 # endif
00451 break;
00452
00453 case Stmt_Func:
00454 break;
00455
00456 }
00457
00458 fflush(outfile);
00459 return;
00460
00461 }
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479 char *print_type_f(int type_idx)
00480
00481 {
00482 int kind;
00483 static char str[80];
00484 char str1[80];
00485
00486
00487 if (type_idx == NULL_IDX) {
00488 sprintf(str, "NULL");
00489 }
00490 else if (TYP_TYPE(type_idx) <= Last_Linear_Type) {
00491
00492 if (TYP_DESC(type_idx) == Star_Typed) {
00493 sprintf(str, "%s * %d",
00494 basic_type_str[TYP_TYPE(type_idx)],
00495 TYP_DCL_VALUE(type_idx));
00496 }
00497 else if (TYP_DESC(type_idx) == Kind_Typed) {
00498 sprintf(str, "%s (kind=%d)",
00499 basic_type_str[TYP_TYPE(type_idx)],
00500 TYP_DCL_VALUE(type_idx));
00501 }
00502 else {
00503
00504
00505
00506 switch (TYP_LINEAR(type_idx)) {
00507 case Integer_1:
00508 case Logical_1:
00509 kind = 1;
00510 break;
00511 case Integer_2:
00512 case Logical_2:
00513 kind = 2;
00514 break;
00515 case Integer_4:
00516 case Logical_4:
00517 case Real_4:
00518 case Complex_4:
00519 kind = 4;
00520 break;
00521 case Integer_8:
00522 case Logical_8:
00523 case Real_8:
00524 case Complex_8:
00525 kind = 8;
00526 break;
00527 case Real_16:
00528 case Complex_16:
00529 kind = 16;
00530 break;
00531 default:
00532 kind = 0;
00533 break;
00534 }
00535
00536 if (kind == 0) {
00537 sprintf(str, "%s", basic_type_str[TYP_TYPE(type_idx)]);
00538 }
00539 else {
00540 sprintf(str, "%s (%d)", basic_type_str[TYP_TYPE(type_idx)], kind);
00541 }
00542 }
00543 }
00544 else if (TYP_TYPE(type_idx) == Typeless) {
00545 sprintf(str, "Typeless * %s",
00546 CONVERT_CVAL_TO_STR((&TYP_BIT_LEN(type_idx)),
00547 Integer_8,
00548 str1));
00549 }
00550 else if (TYP_TYPE(type_idx) != Character) {
00551 sprintf(str, "type(%s)", AT_OBJ_NAME_PTR(TYP_IDX(type_idx)));
00552 }
00553 else if (TYP_CHAR_CLASS(type_idx) == Assumed_Size_Char) {
00554 sprintf(str, "CHARACTER*(*)");
00555 }
00556 else if (TYP_CHAR_CLASS(type_idx) == Const_Len_Char) {
00557 sprintf(str, "CHARACTER*(%s)",
00558 convert_to_string(&CN_CONST(TYP_IDX(type_idx)),
00559 CN_TYPE_IDX(TYP_IDX(type_idx)),
00560 str1));
00561 }
00562 else {
00563 sprintf(str, "CHARACTER*(%s)", AT_OBJ_NAME_PTR(TYP_IDX(type_idx)));
00564 }
00565
00566 return(str);
00567
00568 }
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586 void print_const_f(FILE *outfile,
00587 int cn_idx)
00588
00589 {
00590 long64 i;
00591 long64 length;
00592 int type_idx;
00593 char str[80];
00594
00595
00596 type_idx = CN_TYPE_IDX(cn_idx);
00597
00598 switch (TYP_TYPE(type_idx)) {
00599 case Typeless:
00600 convert_to_string_fmt = Hex_Fmt;
00601 fprintf(outfile, "0x%s", convert_to_string(&CN_CONST(cn_idx),
00602 type_idx,
00603 str));
00604
00605 if (TYP_BIT_LEN(type_idx) > TARGET_BITS_PER_WORD) {
00606
00607 length = (TYP_BIT_LEN(type_idx) + TARGET_BITS_PER_WORD - 1) /
00608 TARGET_BITS_PER_WORD;
00609 for (i = 1; i < length; i++) {
00610 convert_to_string_fmt = Hex_Fmt;
00611 fprintf(outfile, " %s",
00612 convert_to_string(&CP_CONSTANT(CN_POOL_IDX(cn_idx)+i),
00613 type_idx,
00614 str));
00615 }
00616 }
00617
00618 break;
00619
00620 case Integer:
00621 fprintf(outfile, "%s", convert_to_string(&CN_CONST(cn_idx),type_idx,str));
00622 break;
00623
00624 case Real:
00625 fprintf(outfile, "%s", convert_to_string(&CN_CONST(cn_idx),type_idx,str));
00626 break;
00627
00628 case Character:
00629 fprintf(outfile, "\"%s\"", (char *) &CN_CONST(cn_idx));
00630 break;
00631
00632 case Logical:
00633 fprintf(outfile, "%s", (THIS_IS_TRUE(&(CN_CONST(cn_idx)), type_idx) ?
00634 ".TRUE." : ".FALSE."));
00635 break;
00636
00637 case Complex:
00638 fprintf(outfile, "%s", convert_to_string(&CN_CONST(cn_idx),type_idx,str));
00639 break;
00640 }
00641
00642 return;
00643
00644 }