📄 txt.c
字号:
* a store -- * put it into a register then * store it. */ if(t->op == ONAME || t->op == OINDREG || t->op == OIND) { switch(tt) { default: a = AMOVL; break; case TUCHAR: case TCHAR: a = AMOVB; break; case TUSHORT: case TSHORT: a = AMOVW; break; case TFLOAT: a = AMOVS; break; case TDOUBLE: a = AMOVT; break; case TVLONG: case TUVLONG: a = AMOVQ; break; } if(!typefd[ft] && vconst(f) == 0) { gins(a, f, t); return; } if(ft == tt) regalloc(&nod, t, f); else regalloc(&nod, t, Z); gmove(f, &nod); gins(a, &nod, t); regfree(&nod); return; } /* * type x type cross table */ a = AGOK; switch(ft) { case TDOUBLE: case TFLOAT: switch(tt) { case TDOUBLE: a = AMOVT; break; case TFLOAT: a = ACVTTS; if(ft == TFLOAT) a = AMOVT; break; case TINT: case TUINT: case TLONG: case TULONG: case TUVLONG: case TVLONG: case TIND: case TSHORT: case TUSHORT: case TCHAR: case TUCHAR: /*warn(Z, "float to fix"); /**/ regalloc(&nod, f, Z); /* should be type float */ gins(ACVTTQ, f, &nod); gins(AMOVT, &nod, nodrat); regfree(&nod); gins(AMOVQ, nodrat, t); gmove(t, t); if(nrathole < SZ_VLONG) nrathole = SZ_VLONG; return; } break; case TVLONG: case TUVLONG: switch(tt) { case TDOUBLE: case TFLOAT: goto fxtofl; case TINT: case TUINT: case TLONG: case TULONG: case TIND: case TSHORT: case TUSHORT: case TCHAR: case TUCHAR: a = AMOVL; break; case TVLONG: case TUVLONG: a = AMOVQ; break; } break; case TINT: case TUINT: case TULONG: case TLONG: case TIND: switch(tt) { case TDOUBLE: case TFLOAT: goto fxtofl; case TVLONG: case TUVLONG: if (ft == TULONG || ft == TUINT) { a = AMOVLU; break; } case TINT: case TUINT: case TLONG: case TULONG: case TIND: case TSHORT: case TUSHORT: case TCHAR: case TUCHAR: a = AMOVQ; break; } break; case TSHORT: switch(tt) { case TDOUBLE: case TFLOAT: goto fxtofl; case TINT: case TUINT: case TULONG: case TLONG: case TVLONG: case TUVLONG: case TIND: a = AMOVW; break; case TSHORT: case TUSHORT: case TCHAR: case TUCHAR: a = AMOVQ; break; } break; case TUSHORT: switch(tt) { case TDOUBLE: case TFLOAT: goto fxtofl; case TINT: case TUINT: case TLONG: case TULONG: case TVLONG: case TUVLONG: case TIND: a = AMOVWU; break; case TSHORT: case TUSHORT: case TCHAR: case TUCHAR: a = AMOVQ; break; } break; case TCHAR: switch(tt) { case TDOUBLE: case TFLOAT: goto fxtofl; case TINT: case TUINT: case TLONG: case TULONG: case TVLONG: case TUVLONG: case TIND: case TSHORT: case TUSHORT: a = AMOVB; break; case TCHAR: case TUCHAR: a = AMOVQ; break; } break; case TUCHAR: switch(tt) { case TDOUBLE: case TFLOAT: fxtofl: /*warn(Z, "fix to float"); /**/ regalloc(&nod, t, Z); /* should be type float */ gins(AMOVQ, f, nodrat); gins(AMOVT, nodrat, &nod); a = ACVTQT; if(tt == TFLOAT) a = ACVTQS; gins(a, &nod, t); regfree(&nod); if(nrathole < SZ_VLONG) nrathole = SZ_VLONG; return; case TINT: case TUINT: case TLONG: case TULONG: case TVLONG: case TUVLONG: case TIND: case TSHORT: case TUSHORT: a = AMOVBU; break; case TCHAR: case TUCHAR: a = AMOVQ; break; } break; } if(a == AMOVQ || a == AMOVS || a == AMOVT) if(samaddr(f, t)) return; gins(a, f, t);}voidgins(int a, Node *f, Node *t){ nextpc(); p->as = a; if(f != Z) naddr(f, &p->from); if(t != Z) naddr(t, &p->to); if(debug['g']) print("%P\n", p);}voidgopcode(int o, Node *f1, Node *f2, Node *t){ int a, et; Adr ta; Node nod; et = TLONG; if(f1 != Z && f1->type != T) { if(f1->op == OCONST && t != Z && t->type != T) et = t->type->etype; else et = f1->type->etype; } a = AGOK; switch(o) { case OAS: gmove(f1, t); return; case OASADD: case OADD: a = AADDL; if(et == TFLOAT) a = AADDS; else if(et == TDOUBLE) a = AADDT; else if(et == TVLONG || et == TUVLONG) a = AADDQ; break; case OASSUB: case OSUB: a = ASUBL; if(et == TFLOAT) a = ASUBS; else if(et == TDOUBLE) a = ASUBT; else if(et == TVLONG || et == TUVLONG) a = ASUBQ; break; case OASOR: case OOR: a = AOR; break; case OASAND: case OAND: a = AAND; break; case OASXOR: case OXOR: a = AXOR; break; case OASLSHR: case OLSHR: a = ASRLL; if(et == TVLONG || et == TUVLONG) a = ASRLQ; break; case OASASHR: case OASHR: a = ASRAL; if(et == TVLONG || et == TUVLONG) a = ASRAQ; break; case OASASHL: case OASHL: a = ASLLL; if(et == TVLONG || et == TUVLONG) a = ASLLQ; break; case OFUNC: a = AJSR; break; case OASLMUL: case OLMUL: case OASMUL: case OMUL: a = AMULL; if(et == TFLOAT) a = AMULS; else if(et == TDOUBLE) a = AMULT; else if(et == TVLONG || et == TUVLONG) a = AMULQ; break; case OASDIV: case ODIV: a = ADIVL; if(et == TFLOAT) a = ADIVS; else if(et == TDOUBLE) a = ADIVT; else if(et == TVLONG || et == TUVLONG) a = ADIVQ; break; case OASMOD: case OMOD: a = AMODL; if(et == TVLONG || et == TUVLONG) a = AMODQ; break; case OASLMOD: case OLMOD: a = AMODLU; if(et == TVLONG || et == TUVLONG) a = AMODQU; break; case OASLDIV: case OLDIV: a = ADIVLU; if(et == TVLONG || et == TUVLONG) a = ADIVQU; break; case OEQ: case ONE: a = ACMPEQ; if(typefd[et]) a = ACMPTEQ; else if (vconst(t) == 0) { a = (o == OEQ) ? ABEQ : ABNE; t = Z; break; } goto cmp; case OLT: case OGE: a = ACMPGT; if(typefd[et]) a = ACMPTGT; else if (vconst(t) == 0) { a = (o == OLT) ? ABLT : ABGE; t = Z; break; } goto cmp; case OLE: case OGT: a = ACMPGE; if(typefd[et]) a = ACMPTGE; else if(vconst(t) == 0) { a = (o == OLE)? ABLE: ABGT; t = Z; break; } goto cmp; case OLO: case OHS: a = ACMPUGT; goto cmp; case OLS: case OHI: a = ACMPUGE; goto cmp; cmp: nextpc(); p->as = a; raddr(f1, p); naddr(t, &p->from); regalloc(&nod, t, Z); naddr(&nod, &p->to); if(debug['g']) print("%P\n", p); if(o == OEQ || o == OLT || o == OLE || o == OLO || o == OLS) a = typefd[et]? AFBNE: ABNE; else a = typefd[et]? AFBEQ: ABEQ; nextpc(); p->as = a; naddr(&nod, &p->from); regfree(&nod); if(debug['g']) print("%P\n", p); return; } if(a == AGOK) diag(Z, "bad in gopcode %O", o); nextpc(); p->as = a; if(f1 != Z) naddr(f1, &p->from); if(f2 != Z) { naddr(f2, &ta); p->reg = ta.reg; if(ta.type == D_CONST && ta.offset == 0) p->reg = REGZERO; } if(t != Z) naddr(t, &p->to); if(debug['g']) print("%P\n", p);}samaddr(Node *f, Node *t){ if(f->op != t->op) return 0; switch(f->op) { case OREGISTER: if(f->reg != t->reg) break; return 1; } return 0;}voidgbranch(int o){ int a; a = AGOK; switch(o) { case ORETURN: a = ARET; break; case OGOTO: a = AJMP; break; } nextpc(); if(a == AGOK) { diag(Z, "bad in gbranch %O", o); nextpc(); } p->as = a;}voidpatch(Prog *op, long pc){ op->to.offset = pc; op->to.type = D_BRANCH;}voidgpseudo(int a, Sym *s, Node *n){ nextpc(); p->as = a; p->from.type = D_OREG; p->from.sym = s; p->reg = (profileflg ? 0 : NOPROF); p->from.name = D_EXTERN; if(s->class == CSTATIC) p->from.name = D_STATIC; naddr(n, &p->to); if(a == ADATA || a == AGLOBL) pc--;}intsconst(Node *n){ vlong vv; if(n->op == OCONST) { if(!typefd[n->type->etype]) { vv = n->vconst; if(vv >= -32766LL && vv < 32766LL) return 1; } } return 0;}intsval(long v){ if(v >= -32766L && v < 32766L) return 1; return 0;}intbval(vlong v){ if(v >= 0LL && v < 256LL) return 1; return 0;}intbconst(Node *n){ vlong vv; if(n->op == OCONST) { if(!typefd[n->type->etype]) { vv = n->vconst; if(vv >= 0LL && vv < 256LL) return 1; } } return 0;}longexreg(Type *t){ long o; if(typechlp[t->etype]) { if(exregoffset <= 12) return 0; o = exregoffset; exregoffset--; return o; } if(typefd[t->etype]) { if(exfregoffset <= 19) return 0; o = exfregoffset + NREG; exfregoffset--; return o; } return 0;}schar ewidth[NTYPE] ={ -1, /* [TXXX] */ SZ_CHAR, /* [TCHAR] */ SZ_CHAR, /* [TUCHAR] */ SZ_SHORT, /* [TSHORT] */ SZ_SHORT, /* [TUSHORT] */ SZ_INT, /* [TINT] */ SZ_INT, /* [TUINT] */ SZ_LONG, /* [TLONG] */ SZ_LONG, /* [TULONG] */ SZ_VLONG, /* [TVLONG] */ SZ_VLONG, /* [TUVLONG] */ SZ_FLOAT, /* [TFLOAT] */ SZ_DOUBLE, /* [TDOUBLE] */ SZ_IND, /* [TIND] */ 0, /* [TFUNC] */ -1, /* [TARRAY] */ 0, /* [TVOID] */ -1, /* [TSTRUCT] */ -1, /* [TUNION] */ SZ_INT, /* [TENUM] */};long ncast[NTYPE] ={ 0, /* [TXXX] */ BCHAR|BUCHAR, /* [TCHAR] */ BCHAR|BUCHAR, /* [TUCHAR] */ BSHORT|BUSHORT, /* [TSHORT] */ BSHORT|BUSHORT, /* [TUSHORT] */ BINT|BUINT|BLONG|BULONG|BIND, /* [TINT] */ BINT|BUINT|BLONG|BULONG|BIND, /* [TUINT] */ BINT|BUINT|BLONG|BULONG|BIND, /* [TLONG] */ BINT|BUINT|BLONG|BULONG|BIND, /* [TULONG] */ BVLONG|BUVLONG, /* [TVLONG] */ BVLONG|BUVLONG, /* [TUVLONG] */ BFLOAT, /* [TFLOAT] */ BDOUBLE, /* [TDOUBLE] */ BLONG|BULONG|BIND, /* [TIND] */ 0, /* [TFUNC] */ 0, /* [TARRAY] */ 0, /* [TVOID] */ BSTRUCT, /* [TSTRUCT] */ BUNION, /* [TUNION] */ 0, /* [TENUM] */};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -