📄 printsym.c
字号:
printf("ARG"); break; case R_TEMP: printf("TEMP"); break; case R_ADJUST: printf("ADJUST"); break; }}/* * Print out in a formatted manner. The stack contains a list of * arguments evaluated in reverse order with the first being * the format string. The parameter passed to the function is the * first in a series of Nodes describing the stack contents. */public print_formatted(n, argv)Node n;char **argv;{ if(n->value.printform.lang == nil || n->value.printform.lang == primlang) (*language_op(findlanguage("ASSEMBLER"), L_PRINTF))(n, argv); else (*language_op(n->value.printform.lang, L_PRINTF))(n, argv);}static Vquad mask_reg;public getregbit(n)Integer n;{ if(n > 31) { return(mask_reg.val[0] & (1 << (n - 32))); } else { return(mask_reg.val[1] & (1 << n)); }}/* * Print out the value on top of the stack according to the given type. * If it is not a vector register or is $vmr then do nothing. */public printval_with_mask(t, op, tt)Symbol t;Operator op;Node tt;{ Symbol s; Symbol a = t->type; Stack *savesp, *newsp; Symbol eltype; long elsize; integer bit_position = 0, i; Vquad *xvmr; char val0[10], val1[10], *str; checkref(t); if (t->class == TYPEREF) { resolveRef(t); } if(tt == nil) { xvmr = (Vquad *)vreg(VMR); mask_reg.val[0] = xvmr->val[0]; mask_reg.val[1] = xvmr->val[1]; } else { mask_reg.val[0] = 0; mask_reg.val[1] = 0; str = (char *)tt->value.arg[0]; if(strpbrk(str, "Xx.+- ")) { sp -= sizeof(struct Vreg); error("illegal mask"); } i =strlen(str); if(i > 8) { strcpy(val1, str + i - 8); if(i < 17) { strncpy(val0, str, i - 8); } else { sp -= sizeof(struct Vreg); error("illegal mask"); } if(sscanf(val1, "%lx", &mask_reg.val[1]) != 1) { sp -= sizeof(struct Vreg); error("illegal mask"); } if(sscanf(val0, "%lx", &mask_reg.val[0]) != 1) { sp -= sizeof(struct Vreg); error("illegal mask"); } } else { mask_reg.val[0] = 0; if(sscanf(str, "%lx", &mask_reg.val[1]) != 1) { sp -= sizeof(struct Vreg); error("illegal mask"); } } } savesp = sp; sp -= (size(a)); newsp = sp; eltype = rtype(a->type); elsize = size(eltype); for (sp += elsize; sp <= savesp; sp += 2*elsize, bit_position++) { if(op == O_TMASK) { if(getregbit(bit_position)) { printf("%s[%d] : ", ident(t->name), bit_position); printval(eltype); printf("\n"); } else { pop(Vquad); continue; } } else { if(getregbit(bit_position)) { pop(Vquad); continue; } else { printf("%s[%d] : ", ident(t->name), bit_position); printval(eltype); printf("\n"); } } } sp = newsp; return;}public void arith_exception_decode(r)long r;{ if(r & 0x2f) { printf("(arithmetic exception "); if(r & 0x20) { printf(", integer overflow"); } if(r & 0x8) { printf(", floating overflow"); } if(r & 0x4) { printf(", floating reserved operand"); } if(r & 0x2) { printf(", floating divide by zero"); } if(r & 0x1) { printf(", floating underflow"); } printf(", dst register mask is 0x%02x", (r >> 16) & 0xff); printf(")"); } else { printf("no arithmetic exceptions "); } }public Boolean vexception_decode(r)Vquad *r;{ if(!(r->val[0] & 0x3ff0)) { if(r->val[0] & 0x8000) { if(r->val[0] & 0xf) { printf("(reserved operand "); if(r->val[0] & 0x8) { printf(", overflow"); } if(r->val[0] & 0x2) { printf(", divide by zero"); } if(r->val[0] & 0x1) { printf(", underflow"); } printf(")"); return(true); } } } return(false);}/* * Print out the value on top of the stack according to the given type. */public printval(t)Symbol t;{ Symbol s; Vquad value; double r; long l; checkref(t); if (t->class == TYPEREF) { resolveRef(t); } switch (t->class) { case PROC: case FUNC: s = pop(Symbol); printf("\"%s\"", symname(s)); if(t->class == FUNC) { printf(" is a function"); } else { printf(" is a procedure"); } break; case TYPE: if(streq(ident(t->name), "$vquad")) { popn(sizeof(Vquad), &r); if(!vexception_decode(&r)) { printf("("); prtreal(r); printf(")"); } return; } if(streq(ident(t->name), "vint")) { popn(sizeof(Vquad), &value); if(!vexception_decode(&value)) { printf("%d", value.val[0]); } return; } if(streq(ident(t->name), "vhex")) { popn(sizeof(Vquad), &value); if(!vexception_decode(&value)) { printf("(0x%X,0x%X)", value.val[0], value.val[1]); } return; } if(streq(ident(t->name), "vfloat")) { popn(sizeof(Vquad), &value); if(!vexception_decode(&value)) { printf("("); prtreal(value.val[0]); printf(","); prtreal(value.val[1]); printf(")"); } return; } /* if not the special case of TYPE, fall thru to RANGE: */ case RANGE: if(streq(ident(t->type->name), "vint")) { popn(sizeof(Vquad), &value); if(!vexception_decode(&value)) { printf("%d", value.val[0]); } return; } else { if(streq(ident(t->type->name), "vhex")) { popn(sizeof(Vquad), &value); if(!vexception_decode(&value)) { printf("(0x%X,0x%X)", value.val[0], value.val[1]); } return; } else { if(streq(ident(t->type->name), "vfloat")) { popn(sizeof(Vquad), &value); if(!vexception_decode(&value)) { printf("("); prtreal(value.val[0]); printf(","); prtreal(value.val[1]); printf(")"); } return; } else { if(streq(ident(t->type->name), "$vquad")) { popn(sizeof(Vquad), &r); if(!vexception_decode(&r)) { printf("("); prtreal(r); printf(")"); } return; } } } } /* if not the special case of RANGE, fall thru to default: */ default: if(isvreg(t) && t->symvalue.raddr.reg == VAER) { l = pop(long); arith_exception_decode(l); return; } if(isvreg(t) && t->symvalue.raddr.reg == VMR) { value = pop(Vquad); printf("0x%04x %04x %04x %04x", (value.val[0] >> 16) & 0x0ffff, (value.val[0] ) & 0x0ffff, (value.val[1] >> 16) & 0x0ffff, (value.val[1] ) & 0x0ffff); return; } if (t->language == nil) { error("unknown language"); } else if (t->language == primlang) { (*language_op(findlanguage(C), L_PRINTVAL))(t); } else { (*language_op(t->language, L_PRINTVAL))(t); } break; }}/* * Print out the value of a record, field by field. */public printrecord(s)Symbol s;{ Symbol f; if (s->chain == nil) { error("record has no fields"); } printf("("); sp -= size(s); f = s->chain; if (f != nil) { for (;;) { printfield(f); f = f->chain; if (f == nil) break; printf(", "); } } printf(")");}/* * Print out a field. */private printfield(f)Symbol f;{ Stack *savesp; register int off, len; printf("%s = ", symname(f)); savesp = sp; off = f->symvalue.field.offset; len = f->symvalue.field.length; sp += ((off + len + BITSPERBYTE - 1) div BITSPERBYTE); printval(f); sp = savesp;}/* * Print out the contents of an array. * Haven't quite figured out what the best format is. * * This is rather inefficient. * * The "2*elsize" is there since "printval" drops the stack by elsize. */public printarray(a)Symbol a;{ Stack *savesp, *newsp; Symbol eltype; long elsize; String sep; savesp = sp; sp -= (size(a)); newsp = sp; eltype = rtype(a->type); elsize = size(eltype); printf("("); if (eltype->class == RECORD or eltype->class == ARRAY or eltype->class == VARNT) { sep = "\n"; putchar('\n'); } else { sep = ", "; } for (sp += elsize; sp <= savesp; sp += 2*elsize) { if (sp - elsize != newsp) { fputs(sep, stdout); } printval(eltype); } sp = newsp; if (streq(sep, "\n")) { putchar('\n'); } printf(")");}/* * Print out the value of a real number in Pascal notation. * This is, unfortunately, different than what one gets * from "%g" in printf. */public prtreal(r)double r;{ extern char *index(); char buf[256]; sprintf(buf, "%g", r); if (buf[0] == '.') { printf("0%s", buf); } else if (buf[0] == '-' and buf[1] == '.') { printf("-0%s", &buf[1]); } else { printf("%s", buf); } if (index(buf, '.') == nil) { printf(".0"); }}/* jlr006 * Print out an "H" format floating point number. * For now, punt and just dump it in hex. Should snarf Fortran's * routine, or wait until vcc handles both dbx and long float. */public prth(h)struct hfloat h;{ printf("0x%04x%04x%04x%04x", h.exponent, h.frac1, h.frac2, h.frac3);} /* * Print out a character using ^? notation for unprintables. */public printchar(c)char c;{ if (c == 0) { putchar('\\'); putchar('0'); } else if (c == '\n') { putchar('\\'); putchar('n'); } else if (c > 0 and c < ' ') { putchar('^'); putchar(c - 1 + 'A'); } else if (c >= ' ' && c <= '~') { putchar(c); } else { printf("\\0%o",c); }}/* * Print out a value for a range type (integer, char, or boolean). */public printRangeVal (val, t)long val;Symbol t;{ if (t == t_boolean->type or istypename(t->type, "boolean")) { if ((boolean) val) { printf("true"); } else { printf("false"); } } else if (t == t_char->type or istypename(t->type, "char")) { if (varIsSet("$hexchars")) { printf("0x%lx", val); } else { putchar('\''); printchar(val); putchar('\''); } } else if (varIsSet("$hexints")) { printf("0x%lx", val); } else if (t->symvalue.rangev.lower >= 0) { printf("%lu", val); } else { printf("%ld", val); }}/* * Print out an enumerated value by finding the corresponding * name in the enumeration list. */public printEnum (i, t)integer i;Symbol t;{ register Symbol e; e = t->chain; while (e != nil and e->symvalue.constval->value.lcon != i) { e = e->chain; } if (e != nil) { printf("%s", symname(e)); } else { printf("%d", i); }}/* * Print out a null-terminated string (pointer to char) * starting at the given address. */public printString (addr, quotes)Address addr;boolean quotes;{ register Address a; register integer i, len; register boolean endofstring; union { char ch[sizeof(Word)]; int word; } u; if (varIsSet("$hexstrings")) { printf("0x%x", addr); } else { if (quotes) { putchar('"'); } a = addr; endofstring = false; while (not endofstring) { dread(&u, a, sizeof(u)); i = 0; do { if (u.ch[i] == '\0') { endofstring = true; } else { printchar(u.ch[i]); } ++i; } while (i < sizeof(Word) and not endofstring); a += sizeof(Word); } if (quotes) { putchar('"'); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -