📄 names.c
字号:
/****************************************************************Copyright 1990, 1992 - 1994 by AT&T Bell Laboratories and Bellcore.Permission to use, copy, modify, and distribute this softwareand its documentation for any purpose and without fee is herebygranted, provided that the above copyright notice appear in allcopies and that both that the copyright notice and thispermission notice and warranty disclaimer appear in supportingdocumentation, and that the names of AT&T Bell Laboratories orBellcore or any of their entities not be used in advertising orpublicity pertaining to distribution of the software withoutspecific, written prior permission.AT&T and Bellcore disclaim all warranties with regard to thissoftware, including all implied warranties of merchantabilityand fitness. In no event shall AT&T or Bellcore be liable forany special, indirect or consequential damages or any damageswhatsoever resulting from loss of use, data or profits, whetherin an action of contract, negligence or other tortious action,arising out of or in connection with the use or performance ofthis software.****************************************************************/#include "defs.h"#include "output.h"#include "names.h"#include "iob.h"/* Names generated by the translator are guaranteed to be unique from the Fortan names because Fortran does not allow underscores in identifiers, and all of the system generated names do have underscores. The various naming conventions are outlined below: FORMAT APPLICATION ---------------------------------------------------------------------- io_# temporaries generated by IO calls; these will contain the device number (e.g. 5, 6, 0) ret_val function return value, required for complex and character functions. ret_val_len length of the return value in character functions ssss_len length of character argument "ssss" c_# member of the literal pool, where # is an arbitrary label assigned by the system cs_# short integer constant in the literal pool t_# expression temporary, # is the depth of arguments on the stack. L# label "#", given by user in the Fortran program. This is unique because Fortran labels are numeric pad_# label on an init field required for alignment xxx_init label on a common block union, if a block data requires a separate declaration*//* generate variable references */ char *#ifdef KR_headersc_type_decl(type, is_extern) int type; int is_extern;#elsec_type_decl(int type, int is_extern)#endif{ static char buff[100]; switch (type) { case TYREAL: if (!is_extern || !forcedouble) { strcpy (buff, "real");break; } case TYDREAL: strcpy (buff, "doublereal"); break; case TYCOMPLEX: if (is_extern) strcpy (buff, "/* Complex */ VOID"); else strcpy (buff, "complex"); break; case TYDCOMPLEX:if (is_extern) strcpy (buff, "/* Double Complex */ VOID"); else strcpy (buff, "doublecomplex"); break; case TYADDR: case TYINT1: case TYSHORT: case TYLONG:#ifdef TYQUAD case TYQUAD:#endif case TYLOGICAL1: case TYLOGICAL2: case TYLOGICAL: strcpy(buff, typename[type]); break; case TYCHAR: if (is_extern) strcpy (buff, "/* Character */ VOID"); else strcpy (buff, "char"); break; case TYUNKNOWN: strcpy (buff, "UNKNOWN");/* If a procedure's type is unknown, assume it's a subroutine */ if (!is_extern) break;/* Subroutines must return an INT, because they might return a label value. Even if one doesn't, the caller will EXPECT it to. */ case TYSUBR: strcpy (buff, "/* Subroutine */ int"); break; case TYERROR: strcpy (buff, "ERROR"); break; case TYVOID: strcpy (buff, "void"); break; case TYCILIST: strcpy (buff, "cilist"); break; case TYICILIST: strcpy (buff, "icilist"); break; case TYOLIST: strcpy (buff, "olist"); break; case TYCLLIST: strcpy (buff, "cllist"); break; case TYALIST: strcpy (buff, "alist"); break; case TYINLIST: strcpy (buff, "inlist"); break; case TYFTNLEN: strcpy (buff, "ftnlen"); break; default: sprintf (buff, "BAD DECL '%d'", type); break; } /* switch */ return buff;} /* c_type_decl */ char *new_func_length(Void){ return "ret_val_len"; } char *#ifdef KR_headersnew_arg_length(arg) Namep arg;#elsenew_arg_length(Namep arg)#endif{ static char buf[64]; sprintf (buf, "%s_len", arg->fvarname); return buf;} /* new_arg_length *//* declare_new_addr -- Add a new local variable to the function, given a pointer to an Addrblock structure (which must have the uname_tag set) This list of idents will be printed in reverse (i.e., chronological) order */ void#ifdef KR_headersdeclare_new_addr(addrp) struct Addrblock *addrp;#elsedeclare_new_addr(struct Addrblock *addrp)#endif{ extern chainp new_vars; new_vars = mkchain((char *)cpexpr((expptr)addrp), new_vars);} /* declare_new_addr */ void#ifdef KR_headerswr_nv_ident_help(outfile, addrp) FILE *outfile; struct Addrblock *addrp;#elsewr_nv_ident_help(FILE *outfile, struct Addrblock *addrp)#endif{ int eltcount = 0; if (addrp == (struct Addrblock *) NULL) return; if (addrp -> isarray) { frexpr (addrp -> memoffset); addrp -> memoffset = ICON(0); eltcount = addrp -> ntempelt; addrp -> ntempelt = 0; addrp -> isarray = 0; } /* if */ out_addr (outfile, addrp); if (eltcount) nice_printf (outfile, "[%d]", eltcount);} /* wr_nv_ident_help */ int#ifdef KR_headersnv_type_help(addrp) struct Addrblock *addrp;#elsenv_type_help(struct Addrblock *addrp)#endif{ if (addrp == (struct Addrblock *) NULL) return -1; return addrp -> vtype;} /* nv_type_help *//* lit_name -- returns a unique identifier for the given literal. Make the label useful, when possible. For example: 1 -> c_1 (constant 1) 2 -> c_2 (constant 2) 1000 -> c_1000 (constant 1000) 1000000 -> c_b<memno> (big constant number) 1.2 -> c_1_2 (constant 1.2) 1.234345 -> c_b<memno> (big constant number) -1 -> c_n1 (constant -1) -1.0 -> c_n1_0 (constant -1.0) .true. -> c_true (constant true) .false. -> c_false (constant false) default -> c_b<memno> (default label)*/ char *#ifdef KR_headerslit_name(litp) struct Literal *litp;#elselit_name(struct Literal *litp)#endif{ static char buf[CONST_IDENT_MAX]; ftnint val; char *fmt; if (litp == (struct Literal *) NULL) return NULL; switch (litp -> littype) { case TYINT1: val = litp -> litval.litival; if (val >= 256 || val < -255) sprintf (buf, "ci1_b%d", litp -> litnum); else if (val < 0) sprintf (buf, "ci1_n%ld", -val); else sprintf(buf, "ci1__%ld", val); break; case TYSHORT: val = litp -> litval.litival; if (val >= 32768 || val <= -32769) sprintf (buf, "cs_b%d", litp -> litnum); else if (val < 0) sprintf (buf, "cs_n%ld", -val); else sprintf (buf, "cs__%ld", val); break; case TYLONG:#ifdef TYQUAD case TYQUAD:#endif val = litp -> litval.litival; if (val >= 100000 || val <= -10000) sprintf (buf, "c_b%d", litp -> litnum); else if (val < 0) sprintf (buf, "c_n%ld", -val); else sprintf (buf, "c__%ld", val); break; case TYLOGICAL1: fmt = "cl1_%s"; goto spr_logical; case TYLOGICAL2: fmt = "cl2_%s"; goto spr_logical; case TYLOGICAL: fmt = "c_%s"; spr_logical: sprintf (buf, fmt, (litp -> litval.litival ? "true" : "false")); break; case TYREAL: case TYDREAL: /* Given a limit of 6 or 8 character on external names, */ /* few f.p. values can be meaningfully encoded in the */ /* constant name. Just going with the default cb_# */ /* seems to be the best course for floating-point */ /* constants. */ case TYCHAR: /* Shouldn't be any of these */ case TYADDR: case TYCOMPLEX: case TYDCOMPLEX: case TYSUBR: default: sprintf (buf, "c_b%d", litp -> litnum); } /* switch */ return buf;} /* lit_name */ char *#ifdef KR_headerscomm_union_name(count) int count;#elsecomm_union_name(int count)#endif{ static char buf[12]; sprintf(buf, "%d", count); return buf; }/* wr_globals -- after every function has been translated, we need to output the global declarations, such as the static table of constant values */ void#ifdef KR_headerswr_globals(outfile) FILE *outfile;#elsewr_globals(FILE *outfile)#endif{ struct Literal *litp, *lastlit; extern int hsize; char *litname; int did_one, t; struct Constblock cb; ftnint x, y; if (nliterals == 0) return; lastlit = litpool + nliterals; did_one = 0; for (litp = litpool; litp < lastlit; litp++) { if (!litp->lituse) continue; litname = lit_name(litp); if (!did_one) { margin_printf(outfile, "/* Table of constant values */\n\n"); did_one = 1; } cb.vtype = litp->littype; if (litp->littype == TYCHAR) { x = litp->litval.litival2[0] + litp->litval.litival2[1]; if (y = x % hsize) x += y = hsize - y; nice_printf(outfile, "static struct { %s fill; char val[%ld+1];", halign, x); nice_printf(outfile, " char fill2[%ld];", hsize - 1); nice_printf(outfile, " } %s_st = { 0,", litname); cb.vleng = ICON(litp->litval.litival2[0]); cb.Const.ccp = litp->cds[0]; cb.Const.ccp1.blanks = litp->litval.litival2[1] + y; cb.vtype = TYCHAR; out_const(outfile, &cb); frexpr(cb.vleng); nice_printf(outfile, " };\n"); nice_printf(outfile, "#define %s %s_st.val\n", litname, litname); continue; } nice_printf(outfile, "static %s %s = ", c_type_decl(litp->littype,0), litname); t = litp->littype; if (ONEOF(t, MSKREAL|MSKCOMPLEX)) { cb.vstg = 1; cb.Const.cds[0] = litp->cds[0]; cb.Const.cds[1] = litp->cds[1]; } else { memcpy((char *)&cb.Const, (char *)&litp->litval, sizeof(cb.Const)); cb.vstg = 0; } out_const(outfile, &cb); nice_printf (outfile, ";\n"); } /* for */ if (did_one) nice_printf (outfile, "\n");} /* wr_globals */ ftnint#ifdef KR_headerscommlen(vl) register chainp vl;#elsecommlen(register chainp vl)#endif{ ftnint size; int type; struct Dimblock *t; Namep v; while(vl->nextp) vl = vl->nextp; v = (Namep)vl->datap; type = v->vtype; if (type == TYCHAR) size = v->vleng->constblock.Const.ci; else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -