/* - regprop - printable representation of opcode */ static char * regprop( char *op ) { register char *p; static char buf[50]; (void) strcpy(buf, ":"); switch (OP(op)) { case BOL: p = "BOL"; break; case EOL: p = "EOL"; break; case ANY: p = "ANY"; break; case ANYOF: p = "ANYOF"; break; case ANYBUT: p = "ANYBUT"; break; case BRANCH: p = "BRANCH"; break; case EXACTLY: p = "EXACTLY"; break; case NOTHING: p = "NOTHING"; break; case BACK: p = "BACK"; break; case END: p = "END"; break; case OPEN+1: case OPEN+2: case OPEN+3: case OPEN+4: case OPEN+5: case OPEN+6: case OPEN+7: case OPEN+8: case OPEN+9: sprintf(buf+strlen(buf), "OPEN%d", OP(op)-OPEN); p = NULL; break; case CLOSE+1: case CLOSE+2: case CLOSE+3: case CLOSE+4: case CLOSE+5: case CLOSE+6: case CLOSE+7: case CLOSE+8: case CLOSE+9: sprintf(buf+strlen(buf), "CLOSE%d", OP(op)-CLOSE); p = NULL; break; case STAR: p = "STAR"; break; case PLUS: p = "PLUS"; break; case WORDA: p = "WORDA"; break; case WORDZ: p = "WORDZ"; break; default: regerror("corrupted opcode"); break; } if (p != NULL) (void) strcat(buf, p); return(buf); }
#define MW mmix_type_memaccess_wyde #define MT mmix_type_memaccess_tetra #define MO mmix_type_memaccess_octa #define M mmix_type_memaccess_block #define J mmix_type_jsr #define P mmix_type_pseudo #define OP(y) XCONCAT2 (mmix_operands_,y) /* Groups of instructions specified here must, if all are matching the same instruction, be consecutive, in order more-specific to less-specific match. */ const struct mmix_opcode mmix_opcodes[] = { {"trap", O (0), OP (xyz_opt), J}, {"fcmp", O (1), OP (regs), N}, {"flot", Z (8), OP (roundregs_z), N}, {"fun", O (2), OP (regs), N}, {"feql", O (3), OP (regs), N}, {"flotu", Z (10), OP (roundregs_z), N}, {"fadd", O (4), OP (regs), N}, {"fix", O (5), OP (roundregs), N}, {"sflot", Z (12), OP (roundregs_z), N}, {"fsub", O (6), OP (regs), N}, {"fixu", O (7), OP (roundregs), N}, {"sflotu", Z (14), OP (roundregs_z), N},
/**************** * transform n*64 bytes */ static void /*transform( MD5_CONTEXT *ctx, const void *buffer, size_t len )*/ transform( MD5_CONTEXT *ctx, byte *data ) { u32 correct_words[16]; register u32 A = ctx->A; register u32 B = ctx->B; register u32 C = ctx->C; register u32 D = ctx->D; u32 *cwp = correct_words; int i; byte *p1; for(i=0, p1=data; i < 16; i++, p1 += 4) correct_words[i] = p1[0] | (p1[1] << 8) | (p1[2] << 16) | (p1[3] << 24); #define OP(a, b, c, d, s, T) \ do \ { \ a += FF (b, c, d) + (*cwp++) + T; \ a = rol(a, s); \ a += b; \ } \ while (0) /* Before we start, one word about the strange constants. They are defined in RFC 1321 as T[i] = (int) (4294967296.0 * fabs (sin (i))), i=1..64 */ /* Round 1. */ OP (A, B, C, D, 7, 0xd76aa478); OP (D, A, B, C, 12, 0xe8c7b756); OP (C, D, A, B, 17, 0x242070db); OP (B, C, D, A, 22, 0xc1bdceee); OP (A, B, C, D, 7, 0xf57c0faf); OP (D, A, B, C, 12, 0x4787c62a); OP (C, D, A, B, 17, 0xa8304613); OP (B, C, D, A, 22, 0xfd469501); OP (A, B, C, D, 7, 0x698098d8); OP (D, A, B, C, 12, 0x8b44f7af); OP (C, D, A, B, 17, 0xffff5bb1); OP (B, C, D, A, 22, 0x895cd7be); OP (A, B, C, D, 7, 0x6b901122); OP (D, A, B, C, 12, 0xfd987193); OP (C, D, A, B, 17, 0xa679438e); OP (B, C, D, A, 22, 0x49b40821); #undef OP #define OP(f, a, b, c, d, k, s, T) \ do \ { \ a += f (b, c, d) + correct_words[k] + T; \ a = rol(a, s); \ a += b; \ } \ while (0) /* Round 2. */ OP (FG, A, B, C, D, 1, 5, 0xf61e2562); OP (FG, D, A, B, C, 6, 9, 0xc040b340); OP (FG, C, D, A, B, 11, 14, 0x265e5a51); OP (FG, B, C, D, A, 0, 20, 0xe9b6c7aa); OP (FG, A, B, C, D, 5, 5, 0xd62f105d); OP (FG, D, A, B, C, 10, 9, 0x02441453); OP (FG, C, D, A, B, 15, 14, 0xd8a1e681); OP (FG, B, C, D, A, 4, 20, 0xe7d3fbc8); OP (FG, A, B, C, D, 9, 5, 0x21e1cde6); OP (FG, D, A, B, C, 14, 9, 0xc33707d6); OP (FG, C, D, A, B, 3, 14, 0xf4d50d87); OP (FG, B, C, D, A, 8, 20, 0x455a14ed); OP (FG, A, B, C, D, 13, 5, 0xa9e3e905); OP (FG, D, A, B, C, 2, 9, 0xfcefa3f8); OP (FG, C, D, A, B, 7, 14, 0x676f02d9); OP (FG, B, C, D, A, 12, 20, 0x8d2a4c8a); /* Round 3. */ OP (FH, A, B, C, D, 5, 4, 0xfffa3942); OP (FH, D, A, B, C, 8, 11, 0x8771f681); OP (FH, C, D, A, B, 11, 16, 0x6d9d6122); OP (FH, B, C, D, A, 14, 23, 0xfde5380c); OP (FH, A, B, C, D, 1, 4, 0xa4beea44); OP (FH, D, A, B, C, 4, 11, 0x4bdecfa9); OP (FH, C, D, A, B, 7, 16, 0xf6bb4b60); OP (FH, B, C, D, A, 10, 23, 0xbebfbc70); OP (FH, A, B, C, D, 13, 4, 0x289b7ec6); OP (FH, D, A, B, C, 0, 11, 0xeaa127fa); OP (FH, C, D, A, B, 3, 16, 0xd4ef3085); OP (FH, B, C, D, A, 6, 23, 0x04881d05); OP (FH, A, B, C, D, 9, 4, 0xd9d4d039); OP (FH, D, A, B, C, 12, 11, 0xe6db99e5); OP (FH, C, D, A, B, 15, 16, 0x1fa27cf8); OP (FH, B, C, D, A, 2, 23, 0xc4ac5665); /* Round 4. */ OP (FI, A, B, C, D, 0, 6, 0xf4292244); OP (FI, D, A, B, C, 7, 10, 0x432aff97); OP (FI, C, D, A, B, 14, 15, 0xab9423a7); OP (FI, B, C, D, A, 5, 21, 0xfc93a039); OP (FI, A, B, C, D, 12, 6, 0x655b59c3); OP (FI, D, A, B, C, 3, 10, 0x8f0ccc92); OP (FI, C, D, A, B, 10, 15, 0xffeff47d); OP (FI, B, C, D, A, 1, 21, 0x85845dd1); OP (FI, A, B, C, D, 8, 6, 0x6fa87e4f); OP (FI, D, A, B, C, 15, 10, 0xfe2ce6e0); OP (FI, C, D, A, B, 6, 15, 0xa3014314); OP (FI, B, C, D, A, 13, 21, 0x4e0811a1); OP (FI, A, B, C, D, 4, 6, 0xf7537e82); OP (FI, D, A, B, C, 11, 10, 0xbd3af235); OP (FI, C, D, A, B, 2, 15, 0x2ad7d2bb); OP (FI, B, C, D, A, 9, 21, 0xeb86d391); /* Put checksum in context given as argument. */ ctx->A += A; ctx->B += B; ctx->C += C; ctx->D += D; }
void arp_print(netdissect_options *ndo, const u_char *bp, u_int length, u_int caplen) { const struct arp_pkthdr *ap; u_short pro, hrd, op, linkaddr; ap = (const struct arp_pkthdr *)bp; ND_TCHECK(*ap); hrd = HRD(ap); pro = PRO(ap); op = OP(ap); /* if its ATM then call the ATM ARP printer for Frame-relay ARP most of the fields are similar to Ethernet so overload the Ethernet Printer and set the linkaddr type for linkaddr_string() accordingly */ switch(hrd) { case ARPHRD_ATM2225: atmarp_print(ndo, bp, length, caplen); return; case ARPHRD_FRELAY: linkaddr = LINKADDR_FRELAY; break; default: linkaddr = LINKADDR_ETHER; break; } if (!ND_TTEST2(*ar_tpa(ap), PROTO_LEN(ap))) { ND_PRINT((ndo, "[|ARP]")); ND_DEFAULTPRINT((const u_char *)ap, length); return; } if (!ndo->ndo_eflag) { ND_PRINT((ndo, "ARP, ")); } /* print hardware type/len and proto type/len */ if ((pro != ETHERTYPE_IP && pro != ETHERTYPE_TRAIL) || PROTO_LEN(ap) != 4 || HRD_LEN(ap) == 0 || ndo->ndo_vflag) { ND_PRINT((ndo, "%s (len %u), %s (len %u)", tok2str(arphrd_values, "Unknown Hardware (%u)", hrd), HRD_LEN(ap), tok2str(ethertype_values, "Unknown Protocol (0x%04x)", pro), PROTO_LEN(ap))); /* don't know know about the address formats */ if (!ndo->ndo_vflag) { goto out; } } /* print operation */ printf("%s%s ", ndo->ndo_vflag ? ", " : "", tok2str(arpop_values, "Unknown (%u)", op)); switch (op) { case ARPOP_REQUEST: ND_PRINT((ndo, "who-has %s", ipaddr_string(TPA(ap)))); if (memcmp((const char *)ezero, (const char *)THA(ap), HRD_LEN(ap)) != 0) ND_PRINT((ndo, " (%s)", linkaddr_string(THA(ap), linkaddr, HRD_LEN(ap)))); ND_PRINT((ndo, " tell %s", ipaddr_string(SPA(ap)))); break; case ARPOP_REPLY: ND_PRINT((ndo, "%s is-at %s", ipaddr_string(SPA(ap)), linkaddr_string(SHA(ap), linkaddr, HRD_LEN(ap)))); break; case ARPOP_REVREQUEST: ND_PRINT((ndo, "who-is %s tell %s", linkaddr_string(THA(ap), linkaddr, HRD_LEN(ap)), linkaddr_string(SHA(ap), linkaddr, HRD_LEN(ap)))); break; case ARPOP_REVREPLY: ND_PRINT((ndo, "%s at %s", linkaddr_string(THA(ap), linkaddr, HRD_LEN(ap)), ipaddr_string(TPA(ap)))); break; case ARPOP_INVREQUEST: ND_PRINT((ndo, "who-is %s tell %s", linkaddr_string(THA(ap), linkaddr, HRD_LEN(ap)), linkaddr_string(SHA(ap), linkaddr, HRD_LEN(ap)))); break; case ARPOP_INVREPLY: ND_PRINT((ndo,"%s at %s", linkaddr_string(THA(ap), linkaddr, HRD_LEN(ap)), ipaddr_string(TPA(ap)))); break; default: ND_DEFAULTPRINT((const u_char *)ap, caplen); return; } out: ND_PRINT((ndo, ", length %u", length)); return; trunc: ND_PRINT((ndo, "[|ARP]")); }
#include "ngspice/ifsim.h" #include "ngspice/devdefs.h" #include "vcvsdefs.h" #include "ngspice/suffix.h" IFparm VCVSpTable[] = { /* parameters */ IOPU("gain", VCVS_GAIN, IF_REAL,"Voltage gain"), IP("sens_gain",VCVS_GAIN_SENS,IF_FLAG,"flag to request sensitivity WRT gain"), OPU("pos_node", VCVS_POS_NODE, IF_INTEGER, "Positive node of source"), OPU("neg_node", VCVS_NEG_NODE, IF_INTEGER, "Negative node of source"), OPU("cont_p_node",VCVS_CONT_P_NODE,IF_INTEGER, "Positive node of contr. source"), OPU("cont_n_node",VCVS_CONT_N_NODE,IF_INTEGER, "Negative node of contr. source"), IP("ic", VCVS_IC, IF_REAL, "Initial condition of controlling source"), OP("i", VCVS_CURRENT, IF_REAL, "Output current"), OP("v", VCVS_VOLTS, IF_REAL, "Output voltage"), OP("p", VCVS_POWER, IF_REAL, "Power"), OPU("sens_dc", VCVS_QUEST_SENS_DC, IF_REAL, "dc sensitivity "), OPU("sens_real", VCVS_QUEST_SENS_REAL,IF_REAL, "real part of ac sensitivity"), OPU("sens_imag", VCVS_QUEST_SENS_IMAG,IF_REAL, "imag part of ac sensitivity"), OPU("sens_mag", VCVS_QUEST_SENS_MAG, IF_REAL, "sensitivity of ac magnitude"), OPU("sens_ph", VCVS_QUEST_SENS_PH, IF_REAL, "sensitivity of ac phase"), OPU("sens_cplx", VCVS_QUEST_SENS_CPLX, IF_COMPLEX, "ac sensitivity") }; char *VCVSnames[] = { "V+", "V-", "VC+", "VC-"
/* - dissect - figure out what matched what, no back references == static const char *dissect(struct match *m, const char *start, \ == const char *stop, sopno startst, sopno stopst); */ static const char * /* == stop (success) always */ dissect(struct match *m, const char *start, const char *stop, sopno startst, sopno stopst) { int i; sopno ss; /* start sop of current subRE */ sopno es; /* end sop of current subRE */ const char *sp; /* start of string matched by it */ const char *stp; /* string matched by it cannot pass here */ const char *rest; /* start of rest of string */ const char *tail; /* string unmatched by rest of RE */ sopno ssub; /* start sop of subsubRE */ sopno esub; /* end sop of subsubRE */ const char *ssp; /* start of string matched by subsubRE */ const char *sep; /* end of string matched by subsubRE */ const char *oldssp; /* previous ssp */ const char *dp; AT("diss", start, stop, startst, stopst); sp = start; for (ss = startst; ss < stopst; ss = es) { /* identify end of subRE */ es = ss; switch (OP(m->g->strip[es])) { case OPLUS_: case OQUEST_: es += OPND(m->g->strip[es]); break; case OCH_: while (OP(m->g->strip[es]) != O_CH) es += OPND(m->g->strip[es]); break; } es++; /* figure out what it matched */ switch (OP(m->g->strip[ss])) { case OEND: assert(nope); break; case OCHAR: sp += XMBRTOWC(NULL, sp, stop - start, &m->mbs, 0); break; case OBOL: case OEOL: case OBOW: case OEOW: break; case OANY: case OANYOF: sp += XMBRTOWC(NULL, sp, stop - start, &m->mbs, 0); break; case OBACK_: case O_BACK: assert(nope); break; /* cases where length of match is hard to find */ case OQUEST_: stp = stop; for (;;) { /* how long could this one be? */ rest = walk(m, sp, stp, ss, es, false); assert(rest != NULL); /* it did match */ /* could the rest match the rest? */ tail = walk(m, rest, stop, es, stopst, false); if (tail == stop) break; /* yes! */ /* no -- try a shorter match for this one */ stp = rest - 1; assert(stp >= sp); /* it did work */ } ssub = ss + 1; esub = es - 1; /* did innards match? */ if (walk(m, sp, rest, ssub, esub, false) != NULL) { dp = dissect(m, sp, rest, ssub, esub); assert(dp == rest); } else /* no */ assert(sp == rest); sp = rest; break; case OPLUS_: stp = stop; for (;;) { /* how long could this one be? */ rest = walk(m, sp, stp, ss, es, false); assert(rest != NULL); /* it did match */ /* could the rest match the rest? */ tail = walk(m, rest, stop, es, stopst, false); if (tail == stop) break; /* yes! */ /* no -- try a shorter match for this one */ stp = rest - 1; assert(stp >= sp); /* it did work */ } ssub = ss + 1; esub = es - 1; ssp = sp; oldssp = ssp; for (;;) { /* find last match of innards */ sep = walk(m, ssp, rest, ssub, esub, false); if (sep == NULL || sep == ssp) break; /* failed or matched null */ oldssp = ssp; /* on to next try */ ssp = sep; } if (sep == NULL) { /* last successful match */ sep = ssp; ssp = oldssp; } assert(sep == rest); /* must exhaust substring */ assert(walk(m, ssp, sep, ssub, esub, false) == rest); dp = dissect(m, ssp, sep, ssub, esub); assert(dp == sep); sp = rest; break; case OCH_: stp = stop; for (;;) { /* how long could this one be? */ rest = walk(m, sp, stp, ss, es, false); assert(rest != NULL); /* it did match */ /* could the rest match the rest? */ tail = walk(m, rest, stop, es, stopst, false); if (tail == stop) break; /* yes! */ /* no -- try a shorter match for this one */ stp = rest - 1; assert(stp >= sp); /* it did work */ } ssub = ss + 1; esub = ss + OPND(m->g->strip[ss]) - 1; assert(OP(m->g->strip[esub]) == OOR1); for (;;) { /* find first matching branch */ if (walk(m, sp, rest, ssub, esub, false) == rest) break; /* it matched all of it */ /* that one missed, try next one */ assert(OP(m->g->strip[esub]) == OOR1); esub++; assert(OP(m->g->strip[esub]) == OOR2); ssub = esub + 1; esub += OPND(m->g->strip[esub]); if (OP(m->g->strip[esub]) == OOR2) esub--; else assert(OP(m->g->strip[esub]) == O_CH); } dp = dissect(m, sp, rest, ssub, esub); assert(dp == rest); sp = rest; break; case O_PLUS: case O_QUEST: case OOR1: case OOR2: case O_CH: assert(nope); break; case OLPAREN: i = OPND(m->g->strip[ss]); assert(0 < i && i <= m->g->nsub); m->pmatch[i].rm_so = sp - m->offp; break; case ORPAREN: i = OPND(m->g->strip[ss]); assert(0 < i && i <= m->g->nsub); m->pmatch[i].rm_eo = sp - m->offp; break; default: /* uh oh */ assert(nope); break; } } assert(sp == stop); return(sp); }
/* - step - map set of states reachable before char to set reachable after == static states step(struct re_guts *g, sopno start, sopno stop, \ == states bef, int ch, states aft); == #define BOL (OUT-1) == #define EOL (BOL-1) == #define BOLEOL (BOL-2) == #define NOTHING (BOL-3) == #define BOW (BOL-4) == #define EOW (BOL-5) == #define BADCHAR (BOL-6) == #define NONCHAR(c) ((c) <= OUT) */ static states step(struct re_guts *g, sopno start, /* start state within strip */ sopno stop, /* state after stop state within strip */ states bef, /* states reachable before */ wint_t ch, /* character or NONCHAR code */ states aft) /* states already known reachable after */ { cset *cs; sop s; sopno pc; onestate here; /* note, macros know this name */ sopno look; int i; for (pc = start, INIT(here, pc); pc != stop; pc++, INC(here)) { s = g->strip[pc]; switch (OP(s)) { case OEND: assert(pc == stop-1); break; case OCHAR: /* only characters can match */ assert(!NONCHAR(ch) || ch != OPND(s)); if (ch == OPND(s)) FWD(aft, bef, 1); break; case OBOL: if (ch == BOL || ch == BOLEOL) FWD(aft, bef, 1); break; case OEOL: if (ch == EOL || ch == BOLEOL) FWD(aft, bef, 1); break; case OBOW: if (ch == BOW) FWD(aft, bef, 1); break; case OEOW: if (ch == EOW) FWD(aft, bef, 1); break; case OANY: if (!NONCHAR(ch)) FWD(aft, bef, 1); break; case OANYOF: cs = &g->sets[OPND(s)]; if (!NONCHAR(ch) && CHIN(cs, ch)) FWD(aft, bef, 1); break; case OBACK_: /* ignored here */ case O_BACK: FWD(aft, aft, 1); break; case OPLUS_: /* forward, this is just an empty */ FWD(aft, aft, 1); break; case O_PLUS: /* both forward and back */ FWD(aft, aft, 1); i = ISSETBACK(aft, OPND(s)); BACK(aft, aft, OPND(s)); if (!i && ISSETBACK(aft, OPND(s))) { /* oho, must reconsider loop body */ pc -= OPND(s) + 1; INIT(here, pc); } break; case OQUEST_: /* two branches, both forward */ FWD(aft, aft, 1); FWD(aft, aft, OPND(s)); break; case O_QUEST: /* just an empty */ FWD(aft, aft, 1); break; case OLPAREN: /* not significant here */ case ORPAREN: FWD(aft, aft, 1); break; case OCH_: /* mark the first two branches */ FWD(aft, aft, 1); assert(OP(g->strip[pc+OPND(s)]) == OOR2); FWD(aft, aft, OPND(s)); break; case OOR1: /* done a branch, find the O_CH */ if (ISSTATEIN(aft, here)) { for (look = 1; OP(s = g->strip[pc+look]) != O_CH; look += OPND(s)) assert(OP(s) == OOR2); FWD(aft, aft, look + 1); } break; case OOR2: /* propagate OCH_'s marking */ FWD(aft, aft, 1); if (OP(g->strip[pc+OPND(s)]) != O_CH) { assert(OP(g->strip[pc+OPND(s)]) == OOR2); FWD(aft, aft, OPND(s)); } break; case O_CH: /* just empty */ FWD(aft, aft, 1); break; default: /* ooooops... */ assert(nope); break; } } return(aft); }
/* - p_simp_re - parse a simple RE, an atom possibly followed by a repetition == static int p_simp_re(struct parse *p, int starordinary, size_t reclimit); */ static int /* was the simple RE an unbackslashed $? */ p_simp_re( struct parse *p, int starordinary, /* is a leading * an ordinary character? */ size_t reclimit) { int c; int count; int count2; sopno pos, i; sopno subno; # define BACKSL (1<<CHAR_BIT) _DIAGASSERT(p != NULL); pos = HERE(); /* repetion op, if any, covers from here */ assert(MORE()); /* caller should have ensured this */ c = GETNEXT(); if (c == '\\') { REQUIRE(MORE(), REG_EESCAPE); c = BACKSL | (unsigned char)GETNEXT(); } switch (c) { case '.': if (p->g->cflags®_NEWLINE) nonnewline(p); else EMIT(OANY, 0); break; case '[': p_bracket(p); break; case BACKSL|'{': SETERROR(REG_BADRPT); break; case BACKSL|'(': p->g->nsub++; subno = p->g->nsub; if (subno < NPAREN) p->pbegin[subno] = HERE(); EMIT(OLPAREN, subno); /* the MORE here is an error heuristic */ if (MORE() && !SEETWO('\\', ')')) p_bre(p, '\\', ')', reclimit); if (subno < NPAREN) { p->pend[subno] = HERE(); assert(p->pend[subno] != 0); } EMIT(ORPAREN, subno); REQUIRE(EATTWO('\\', ')'), REG_EPAREN); break; case BACKSL|')': /* should not get here -- must be user */ case BACKSL|'}': SETERROR(REG_EPAREN); break; case BACKSL|'1': case BACKSL|'2': case BACKSL|'3': case BACKSL|'4': case BACKSL|'5': case BACKSL|'6': case BACKSL|'7': case BACKSL|'8': case BACKSL|'9': i = (c&~BACKSL) - '0'; assert(i < NPAREN); if (p->pend[i] != 0) { assert(i <= p->g->nsub); EMIT(OBACK_, i); assert(p->pbegin[i] != 0); assert(OP(p->strip[p->pbegin[i]]) == OLPAREN); assert(OP(p->strip[p->pend[i]]) == ORPAREN); (void) dupl(p, p->pbegin[i]+1, p->pend[i]); EMIT(O_BACK, i); } else SETERROR(REG_ESUBREG); p->g->backrefs = 1; break; case '*': REQUIRE(starordinary, REG_BADRPT); /* FALLTHROUGH */ default: ordinary(p, c &~ BACKSL); break; } if (EAT('*')) { /* implemented as +? */ /* this case does not require the (y|) trick, noKLUDGE */ INSERT(OPLUS_, pos); ASTERN(O_PLUS, pos); INSERT(OQUEST_, pos); ASTERN(O_QUEST, pos); } else if (EATTWO('\\', '{')) { count = p_count(p); if (EAT(',')) { if (MORE() && isdigit((unsigned char)PEEK())) { count2 = p_count(p); REQUIRE(count <= count2, REG_BADBR); } else /* single number with comma */ count2 = INFINITY; } else /* just a single number */ count2 = count; repeat(p, pos, count, count2, 0); if (!EATTWO('\\', '}')) { /* error heuristics */ while (MORE() && !SEETWO('\\', '}')) NEXT(); REQUIRE(MORE(), REG_EBRACE); SETERROR(REG_BADBR); } } else if (c == (unsigned char)'$') /* $ (but not \$) ends it */ return(1); return(0); }
int CRegExp::regmatch(TCHAR *prog) { TCHAR *scan; // Current node. TCHAR *next; // Next node. for (scan = prog; scan != NULL; scan = next) { next = regnext(scan); switch (OP(scan)) { case BOL: if (reginput != regbol) return(0); break; case EOL: if (*reginput != _T('\0')) return(0); break; case ANY: if (*reginput == _T('\0')) return(0); reginput++; break; case EXACTLY: { size_t len; TCHAR *const opnd = OPERAND(scan); // Inline the first character, for speed. if (*opnd != *reginput) return(0); len = _tcslen(opnd); if (len > 1 && _tcsncmp(opnd, reginput, len) != 0) return(0); reginput += len; break; } case ANYOF: if (*reginput == _T('\0') || _tcschr(OPERAND(scan), *reginput) == NULL) return(0); reginput++; break; case ANYBUT: if (*reginput == _T('\0') || _tcschr(OPERAND(scan), *reginput) != NULL) return(0); reginput++; break; case NOTHING: break; case BACK: break; case OPEN+1: case OPEN+2: case OPEN+3: case OPEN+4: case OPEN+5: case OPEN+6: case OPEN+7: case OPEN+8: case OPEN+9: { const int no = OP(scan) - OPEN; TCHAR *const input = reginput; if (regmatch(next)) { // Don't set startp if some later // invocation of the same parentheses // already has. if (startp[no] == NULL) startp[no] = input; return(1); } else return(0); break; } case CLOSE+1: case CLOSE+2: case CLOSE+3: case CLOSE+4: case CLOSE+5: case CLOSE+6: case CLOSE+7: case CLOSE+8: case CLOSE+9: { const int no = OP(scan) - CLOSE; TCHAR *const input = reginput; if (regmatch(next)) { // Don't set endp if some later // invocation of the same parentheses // already has. if (endp[no] == NULL) endp[no] = input; return(1); } else return(0); break; } case BRANCH: { TCHAR *const save = reginput; if (OP(next) != BRANCH) // No choice. next = OPERAND(scan); // Avoid recursion. else { while (OP(scan) == BRANCH) { if (regmatch(OPERAND(scan))) return(1); reginput = save; scan = regnext(scan); } return(0); // NOTREACHED } break; } case STAR: case PLUS: { const TCHAR nextch = (OP(next) == EXACTLY) ? *OPERAND(next) : _T('\0'); size_t no; TCHAR *const save = reginput; const size_t min = (OP(scan) == STAR) ? 0 : 1; for (no = regrepeat(OPERAND(scan)) + 1; no > min; no--) { reginput = save + no - 1; // If it could work, try it. if (nextch == _T('\0') || *reginput == nextch) if (regmatch(next)) return(1); } return(0); break; } case END: return(1); // Success! break; default: //TRACE0("regexp corruption\n"); LastError = "regexp corruption"; return(0); break; } } // We get here only if there's trouble -- normally "case END" is // the terminating point. //TRACE0("corrupted pointers\n"); LastError = "corrupted pointers"; return(0); }
/* * s_print - print the strip for debugging */ static void s_print(struct re_guts *g, FILE *d) { sop *s; cset *cs; int done = 0; sop opnd; int col = 0; ssize_t last; sopno offset = 2; # define GAP() { if (offset % 5 == 0) { \ if (col > 40) { \ fprintf(d, "\n\t"); \ col = 0; \ } else { \ fprintf(d, " "); \ col++; \ } \ } else \ col++; \ offset++; \ } if (OP(g->strip[0]) != OEND) fprintf(d, "missing initial OEND!\n"); for (s = &g->strip[1]; !done; s++) { opnd = OPND(*s); switch (OP(*s)) { case OEND: fprintf(d, "\n"); done = 1; break; case OCHAR: if (strchr("\\|()^$.[+*?{}!<> ", (char)opnd) != NULL) fprintf(d, "\\%c", (char)opnd); else fprintf(d, "%s", regchar((char)opnd)); break; case OBOL: fprintf(d, "^"); break; case OEOL: fprintf(d, "$"); break; case OBOW: fprintf(d, "\\{"); break; case OEOW: fprintf(d, "\\}"); break; case OANY: fprintf(d, "."); break; case OANYOF: fprintf(d, "[(%ld)", (long)opnd); #ifdef __NetBSD__ cs = &g->sets[opnd]; last = -1; for (size_t i = 0; i < g->csetsize+1; i++) /* +1 flushes */ if (CHIN(cs, i) && i < g->csetsize) { if (last < 0) { fprintf(d, "%s", regchar(i)); last = i; } } else { if (last >= 0) { if (last != (ssize_t)i - 1) fprintf(d, "-%s", regchar(i - 1)); last = -1; } } #endif fprintf(d, "]"); break; case OBACK_: fprintf(d, "(\\<%ld>", (long)opnd); break; case O_BACK: fprintf(d, "<%ld>\\)", (long)opnd); break; case OPLUS_: fprintf(d, "(+"); if (OP(*(s+opnd)) != O_PLUS) fprintf(d, "<%ld>", (long)opnd); break; case O_PLUS: if (OP(*(s-opnd)) != OPLUS_) fprintf(d, "<%ld>", (long)opnd); fprintf(d, "+)"); break; case OQUEST_: fprintf(d, "(?"); if (OP(*(s+opnd)) != O_QUEST) fprintf(d, "<%ld>", (long)opnd); break; case O_QUEST: if (OP(*(s-opnd)) != OQUEST_) fprintf(d, "<%ld>", (long)opnd); fprintf(d, "?)"); break; case OLPAREN: fprintf(d, "((<%ld>", (long)opnd); break; case ORPAREN: fprintf(d, "<%ld>))", (long)opnd); break; case OCH_: fprintf(d, "<"); if (OP(*(s+opnd)) != OOR2) fprintf(d, "<%ld>", (long)opnd); break; case OOR1: if (OP(*(s-opnd)) != OOR1 && OP(*(s-opnd)) != OCH_) fprintf(d, "<%ld>", (long)opnd); fprintf(d, "|"); break; case OOR2: fprintf(d, "|"); if (OP(*(s+opnd)) != OOR2 && OP(*(s+opnd)) != O_CH) fprintf(d, "<%ld>", (long)opnd); break; case O_CH: if (OP(*(s-opnd)) != OOR1) fprintf(d, "<%ld>", (long)opnd); fprintf(d, ">"); break; default: #ifdef __FreeBSD__ fprintf(d, "!%ld(%ld)!", OP(*s), opnd); #else fprintf(d, "!%d(%d)!", OP(*s), opnd); #endif break; } if (!done) GAP(); } }
#endif #define MNEM CGEN_SYNTAX_MNEMONIC /* syntax value for mnemonic */ #define OP(field) CGEN_SYNTAX_MAKE_FIELD (OPERAND (field)) /* The instruction table. */ static const CGEN_OPCODE openrisc_cgen_insn_opcode_table[MAX_INSNS] = { /* Special null first entry. A `num' value of zero is thus invalid. Also, the special `invalid' insn resides here. */ { { 0, 0, 0, 0 }, {{0}}, 0, {0}}, /* l.j ${abs-26} */ { { 0, 0, 0, 0 }, { { MNEM, ' ', OP (ABS_26), 0 } }, & ifmt_l_j, { 0x0 } }, /* l.jal ${abs-26} */ { { 0, 0, 0, 0 }, { { MNEM, ' ', OP (ABS_26), 0 } }, & ifmt_l_j, { 0x4000000 } }, /* l.jr $rA */ { { 0, 0, 0, 0 }, { { MNEM, ' ', OP (RA), 0 } }, & ifmt_l_jr, { 0x14000000 } }, /* l.jalr $rA */
OP OPCodes::getMOVConversion(string param1, string param2) { int src = getRegisterNum(param1); int dest = getRegisterNum(param2); if (dest == -1) // store OPs { if (src == 0) { return OP("STA", 12, 3); } else if (src == 1) { return OP("STX", 16, 3); } else if (src == 2) { return OP("STL", 20, 3); } else if (src == 3) { return OP("STB", 120, 3); } else if (src == 4) { return OP("STS", 124, 3); } else if (src == 5) { return OP("STT", 132, 3); } else { return OP("ERROR",0,0); } } else // load OPs { if (dest == 0) { return OP("LDA", 0, 3); } else if (dest == 1) { return OP("LDX", 4, 3); } else if (dest == 2) { return OP("LDL", 8, 3); } else if (dest == 3) { return OP("LDB", 104, 3); } else if (dest == 4) { return OP("LDS", 108, 3); } else if (dest == 5) { return OP("LDT", 116, 3); } else { return OP("ERROR", 0, 0); } } }
OP OPCodes::getOP(string oper) { int sizeOffset = 0; // increases the size of certain operations if (oper[0] == '+') { oper = oper.substr(1, oper.length()); sizeOffset = 1; } if (oper == "ADDR") { return OP(oper, 144, 2 + sizeOffset); } else if (oper == "COMPR") { return OP(oper, 160,2 + sizeOffset); } else if (oper == "SUBR") { return OP(oper, 148,2 + sizeOffset); } else if (oper == "ADD") { return OP(oper, 24,3 + sizeOffset); } else if (oper == "SUB") { return OP(oper, 28,3 + sizeOffset); } else if (oper == "MUL") { return OP(oper, 32,3 + sizeOffset); } else if (oper == "DIV") { return OP(oper, 36,3 + sizeOffset); } else if (oper == "COMP") { return OP(oper, 40,3 + sizeOffset); } else if (oper == "J") { return OP(oper, 60,3 + sizeOffset); } else if (oper == "JEQ") { return OP(oper, 48,3 + sizeOffset); } else if (oper == "JGT") { return OP(oper, 52,3 + sizeOffset); } else if (oper == "JLT") { return OP(oper, 56,3 + sizeOffset); } else if (oper == "JSUB") { return OP(oper, 72,3 + sizeOffset); } else if (oper == "LDCH") { return OP(oper, 80,3 + sizeOffset); } else if (oper == "RSUB") { return OP(oper, 76,3 + sizeOffset); } else if (oper == "TIX") { return OP(oper, 44,3 + sizeOffset); } else if (oper == "TIXR") { return OP(oper, 184,2 + sizeOffset); } else if (oper == "RD") { return OP(oper, 216,3 + sizeOffset); } else if (oper == "TD") { return OP(oper, 224,3 + sizeOffset); } else if (oper == "WD") { return OP(oper, 220,3 + sizeOffset); } else if (oper == "STCH") { return OP(oper, 84,3 + sizeOffset); } else if (oper == "CLEAR") { return OP(oper, 180,2 + sizeOffset); } else if (oper == "MOV") { return OP(oper, 0,3 + sizeOffset); } else return OP("ERROR",0,0); }
static int /* 0 failure, 1 success */ regmatch( char * prog ) { char * scan; /* Current node. */ char * next; /* Next node. */ scan = prog; #ifdef DEBUG if (scan != NULL && regnarrate) err_printf("%s(\n", regprop(scan)); #endif while (scan != NULL) { #ifdef DEBUG if (regnarrate) err_printf("%s...\n", regprop(scan)); #endif next = regnext(scan); switch (OP(scan)) { case BOL: if (reginput != regbol) return(0); break; case EOL: if (*reginput != '\0') return(0); break; case WORDA: /* Must be looking at a letter, digit, or _ */ if ((!isalnum(*reginput)) && *reginput != '_') return(0); /* Prev must be BOL or nonword */ if (reginput > regbol && (isalnum(reginput[-1]) || reginput[-1] == '_')) return(0); break; case WORDZ: /* Must be looking at non letter, digit, or _ */ if (isalnum(*reginput) || *reginput == '_') return(0); /* We don't care what the previous char was */ break; case ANY: if (*reginput == '\0') return(0); reginput++; break; case EXACTLY: { register int len; register char *opnd; opnd = OPERAND(scan); /* Inline the first character, for speed. */ if (*opnd != *reginput) return(0); len = strlen(opnd); if (len > 1 && strncmp(opnd, reginput, len) != 0) return(0); reginput += len; } break; case ANYOF: if (*reginput == '\0' || strchr(OPERAND(scan), *reginput) == NULL) return(0); reginput++; break; case ANYBUT: if (*reginput == '\0' || strchr(OPERAND(scan), *reginput) != NULL) return(0); reginput++; break; case NOTHING: break; case BACK: break; case OPEN+1: case OPEN+2: case OPEN+3: case OPEN+4: case OPEN+5: case OPEN+6: case OPEN+7: case OPEN+8: case OPEN+9: { register int no; register const char *save; no = OP(scan) - OPEN; save = reginput; if (regmatch(next)) { /* * Don't set startp if some later * invocation of the same parentheses * already has. */ if (regstartp[no] == NULL) regstartp[no] = save; return(1); } else return(0); } break; case CLOSE+1: case CLOSE+2: case CLOSE+3: case CLOSE+4: case CLOSE+5: case CLOSE+6: case CLOSE+7: case CLOSE+8: case CLOSE+9: { register int no; register const char *save; no = OP(scan) - CLOSE; save = reginput; if (regmatch(next)) { /* * Don't set endp if some later * invocation of the same parentheses * already has. */ if (regendp[no] == NULL) regendp[no] = save; return(1); } else return(0); } break; case BRANCH: { register const char *save; if (OP(next) != BRANCH) /* No choice. */ next = OPERAND(scan); /* Avoid recursion. */ else { do { save = reginput; if (regmatch(OPERAND(scan))) return(1); reginput = save; scan = regnext(scan); } while (scan != NULL && OP(scan) == BRANCH); return(0); /* NOTREACHED */ } } break; case STAR: case PLUS: { register char nextch; register int no; register const char *save; register int min; /* * Lookahead to avoid useless match attempts * when we know what character comes next. */ nextch = '\0'; if (OP(next) == EXACTLY) nextch = *OPERAND(next); min = (OP(scan) == STAR) ? 0 : 1; save = reginput; no = regrepeat(OPERAND(scan)); while (no >= min) { /* If it could work, try it. */ if (nextch == '\0' || *reginput == nextch) if (regmatch(next)) return(1); /* Couldn't or didn't -- back up. */ no--; reginput = save + no; } return(0); } break; case END: return(1); /* Success! */ break; default: regerror("memory corruption"); return(0); break; } scan = next; } /* * We get here only if there's trouble -- normally "case END" is * the terminating point. */ regerror("corrupted pointers"); return(0); }
Token scan(FILE* fp) { // The character we are reading in: static char c; // Indicates if this is the first call to scan: static int first_time = 1; // If this is the first call if (first_time) { c = getc(fp); first_time = 0; } // We begin in the start state: static state curr_state = START_STATE; // The token to return to the caller: Token token; // An index used to remember the value characters: int value_idx = -1; // Run the machine: while (1) { switch (curr_state) { case START_STATE: if (c == TAB || c == WS || c == NL) { curr_state = START_STATE; c = getc(fp); } else if (OP(c)) { curr_state = OP_STATE; } else if (c == SEMI) { curr_state = SEMI_STATE; } else if (c == EOF) { curr_state = EOF_STATE; } else if (isdigit(c)){ curr_state = INT_STATE; } else { token.value[++value_idx] = c; token.value[++value_idx] = '\0'; token.t = TOK_ERROR; return token; } break; case INT_STATE: if (c == SEMI) { token.value[++value_idx] = '\0'; token.t = TOK_INT; curr_state = SEMI_STATE; return token; } else if (OP(c)) { token.value[++value_idx] = '\0'; curr_state = OP_STATE; token.t = TOK_INT; return token; } else if (c == TAB || c == WS || c == NL) { token.value[++value_idx] = '\0'; curr_state = START_STATE; token.t = TOK_INT; c = getc(fp); return token; } else if (c >= '0' && c <= '9'){ token.value[++value_idx] = c; curr_state = INT_STATE; c = getc(fp); } else { token.value[++value_idx] = c; token.value[++value_idx] = '\0'; token.t = TOK_ERROR; return token; } break; case SEMI_STATE: token.value[++value_idx] = ';'; token.value[++value_idx] = '\0'; token.t = TOK_SEMI; c = getc(fp); curr_state = START_STATE; return token; break; case OP_STATE: if (OP(c)) { token.value[++value_idx] = c; token.value[++value_idx] = '\0'; curr_state = START_STATE; token.t = whatOP(token.value[value_idx - 1]); c = getc(fp); return token; } else if (c == SEMI) { curr_state = SEMI_STATE; } else if (c == TAB || c == WS || c == NL) { curr_state = START_STATE; } else if (c == EOF) { curr_state = EOF_STATE; } else if (isdigit(c)){ // value character curr_state = INT_STATE; } else { token.value[++value_idx] = c; token.value[++value_idx] = '\0'; token.t = TOK_ERROR; return token; } break; case EOF_STATE: sprintf(token.value, "end of file"); token.t = TOK_ENDOFFILE; curr_state = EOF_STATE; return token; default: token.t = TOK_ERROR; sprintf(token.value, "unexpected input character: %c", c); return token; } } }
CRegExp* CRegExp::RegComp(const TCHAR *exp) { TCHAR *scan; int flags; if (exp == NULL) return NULL; bCompiled = TRUE; // First pass: determine size, legality. bEmitCode = FALSE; regparse = (TCHAR *)exp; regnpar = 1; regsize = 0L; regdummy[0] = NOTHING; regdummy[1] = regdummy[2] = 0; regcode = regdummy; if (reg(0, &flags) == NULL) return(NULL); // Allocate space. delete program; program = new TCHAR[regsize]; memset( program, 0, regsize * sizeof(TCHAR) ); if (program == NULL) return NULL; // Second pass: emit code. bEmitCode = TRUE; regparse = (TCHAR *)exp; regnpar = 1; regcode = program; if (reg(0, &flags) == NULL) return NULL; // Dig out information for optimizations. regstart = _T('\0'); // Worst-case defaults. reganch = 0; regmust = NULL; regmlen = 0; scan = program; // First BRANCH. if (OP(regnext(scan)) == END) { // Only one top-level choice. scan = OPERAND(scan); // Starting-point info. if (OP(scan) == EXACTLY) regstart = *OPERAND(scan); else if (OP(scan) == BOL) reganch = 1; // If there's something expensive in the r.e., find the // longest literal string that must appear and make it the // regmust. Resolve ties in favor of later strings, since // the regstart check works with the beginning of the r.e. // and avoiding duplication strengthens checking. Not a // strong reason, but sufficient in the absence of others. if (flags&SPSTART) { char *longest = NULL; size_t len = 0; for (; scan != NULL; scan = regnext(scan)) if (OP(scan) == EXACTLY && _tcslen(OPERAND(scan)) >= (unsigned int) len) { longest = OPERAND(scan); len = _tcslen(OPERAND(scan)); } regmust = longest; regmlen = (int)len; } } return this; }
#define MNEM CGEN_SYNTAX_MNEMONIC /* syntax value for mnemonic */ #define OPERAND(op) NIOS_OPERAND_##op #define OP(field) CGEN_SYNTAX_MAKE_FIELD (OPERAND (field)) /* The instruction table. */ static const CGEN_OPCODE nios_cgen_insn_opcode_table[MAX_INSNS] = { /* Special null first entry. A `num' value of zero is thus invalid. Also, the special `invalid' insn resides here. */ { { 0 } }, /* ext8s $m16_Ra,$i1 */ { { 0, 0, 0, 0 }, { { MNEM, ' ', OP (M16_RA), ',', OP (I1), 0 } }, & ifmt_ext8s16, { 0x7400 } }, /* st8s [$m16_Ra],$m16_R0,$i1 */ { { 0, 0, 0, 0 }, { { MNEM, ' ', '[', OP (M16_RA), ']', ',', OP (M16_R0), ',', OP (I1), 0 } }, & ifmt_ext8s16, { 0x7600 } }, /* sts8s [$m16_sp,$i10],$m16_R0 */ { { 0, 0, 0, 0 }, { { MNEM, ' ', '[', OP (M16_SP), ',', OP (I10), ']', ',', OP (M16_R0), 0 } }, & ifmt_sts8s16, { 0x6000 } }, /* st8d [$m16_Ra],$m16_R0 */
/* - regcomp - compile a regular expression into internal code * * We can't allocate space until we know how big the compiled form will be, * but we can't compile it (and thus know how big it is) until we've got a * place to put the code. So we cheat: we compile it twice, once with code * generation turned off and size counting turned on, and once "for real". * This also means that we don't allocate space until we are sure that the * thing really will compile successfully, and we never have to move the * code and thus invalidate pointers into it. (Note that it has to be in * one piece because free() must be able to free it all.) * * Beware that the optimization-preparation code in here knows about some * of the structure of the compiled regexp. */ regexp * regcomp(char *exp,int *patternsize) { register regexp *r; register char *scan; register char *longest; register int len; int flags; /* commented out by ethan extern char *malloc(); */ if (exp == NULL) FAIL("NULL argument"); /* First pass: determine size, legality. */ regparse = exp; regnpar = 1; regsize = 0L; regcode = ®dummy; regc(MAGIC); if (reg(0, &flags) == NULL) return(NULL); /* Small enough for pointer-storage convention? */ if (regsize >= 32767L) /* Probably could be 65535L. */ FAIL("regexp too big"); /* Allocate space. */ *patternsize=sizeof(regexp) + (unsigned)regsize; r = (regexp *)malloc(sizeof(regexp) + (unsigned)regsize); if (r == NULL) FAIL("out of space"); /* Second pass: emit code. */ regparse = exp; regnpar = 1; regcode = r->program; regc(MAGIC); if (reg(0, &flags) == NULL) return(NULL); /* Dig out information for optimizations. */ r->regstart = '\0'; /* Worst-case defaults. */ r->reganch = 0; r->regmust = NULL; r->regmlen = 0; scan = r->program+1; /* First BRANCH. */ if (OP(regnext(scan)) == END) { /* Only one top-level choice. */ scan = OPERAND(scan); /* Starting-point info. */ if (OP(scan) == EXACTLY) r->regstart = *OPERAND(scan); else if (OP(scan) == BOL) r->reganch++; /* * If there's something expensive in the r.e., find the * longest literal string that must appear and make it the * regmust. Resolve ties in favor of later strings, since * the regstart check works with the beginning of the r.e. * and avoiding duplication strengthens checking. Not a * strong reason, but sufficient in the absence of others. */ if (flags&SPSTART) { longest = NULL; len = 0; for (; scan != NULL; scan = regnext(scan)) if (OP(scan) == EXACTLY && strlen(OPERAND(scan)) >= len) { longest = OPERAND(scan); len = strlen(OPERAND(scan)); } r->regmust = longest; r->regmlen = len; } } return(r); }
/* - backref - figure out what matched what, figuring in back references == static const char *backref(struct match *m, const char *start, \ == const char *stop, sopno startst, sopno stopst, sopno lev); */ static const char * /* == stop (success) or NULL (failure) */ backref(struct match *m, const char *start, const char *stop, sopno startst, sopno stopst, sopno lev, /* PLUS nesting level */ int rec) { int i; sopno ss; /* start sop of current subRE */ const char *sp; /* start of string matched by it */ sopno ssub; /* start sop of subsubRE */ sopno esub; /* end sop of subsubRE */ const char *ssp; /* start of string matched by subsubRE */ const char *dp; size_t len; int hard; sop s; regoff_t offsave; cset *cs; wint_t wc; AT("back", start, stop, startst, stopst); sp = start; /* get as far as we can with easy stuff */ hard = 0; for (ss = startst; !hard && ss < stopst; ss++) switch (OP(s = m->g->strip[ss])) { case OCHAR: if (sp == stop) return(NULL); sp += XMBRTOWC(&wc, sp, stop - sp, &m->mbs, BADCHAR); if (wc != OPND(s)) return(NULL); break; case OANY: if (sp == stop) return(NULL); sp += XMBRTOWC(&wc, sp, stop - sp, &m->mbs, BADCHAR); if (wc == BADCHAR) return (NULL); break; case OANYOF: if (sp == stop) return (NULL); cs = &m->g->sets[OPND(s)]; sp += XMBRTOWC(&wc, sp, stop - sp, &m->mbs, BADCHAR); if (wc == BADCHAR || !CHIN(cs, wc)) return(NULL); break; case OBOL: if ((sp == m->beginp && !(m->eflags®_NOTBOL)) || (sp > m->offp && sp < m->endp && *(sp-1) == '\n' && (m->g->cflags®_NEWLINE))) { /* yes */ } else return(NULL); break; case OEOL: if ( (sp == m->endp && !(m->eflags®_NOTEOL)) || (sp < m->endp && *sp == '\n' && (m->g->cflags®_NEWLINE)) ) { /* yes */ } else return(NULL); break; case OBOW: if (sp < m->endp && ISWORD(*sp) && ((sp == m->beginp && !(m->eflags®_NOTBOL)) || (sp > m->offp && !ISWORD(*(sp-1))))) { /* yes */ } else return(NULL); break; case OEOW: if (( (sp == m->endp && !(m->eflags®_NOTEOL)) || (sp < m->endp && *sp == '\n' && (m->g->cflags®_NEWLINE)) || (sp < m->endp && !ISWORD(*sp)) ) && (sp > m->beginp && ISWORD(*(sp-1))) ) { /* yes */ } else return(NULL); break; case O_QUEST: break; case OOR1: /* matches null but needs to skip */ ss++; s = m->g->strip[ss]; do { assert(OP(s) == OOR2); ss += OPND(s); } while (OP(s = m->g->strip[ss]) != O_CH); /* note that the ss++ gets us past the O_CH */ break; default: /* have to make a choice */ hard = 1; break; } if (!hard) { /* that was it! */ if (sp != stop) return(NULL); return(sp); } ss--; /* adjust for the for's final increment */ /* the hard stuff */ AT("hard", sp, stop, ss, stopst); s = m->g->strip[ss]; switch (OP(s)) { case OBACK_: /* the vilest depths */ i = OPND(s); assert(0 < i && i <= m->g->nsub); if (m->pmatch[i].rm_eo == -1) return(NULL); assert(m->pmatch[i].rm_so != -1); len = m->pmatch[i].rm_eo - m->pmatch[i].rm_so; if (len == 0 && rec++ > MAX_RECURSION) return(NULL); assert(stop - m->beginp >= len); if (sp > stop - len) return(NULL); /* not enough left to match */ ssp = m->offp + m->pmatch[i].rm_so; if (memcmp(sp, ssp, len) != 0) return(NULL); while (m->g->strip[ss] != SOP(O_BACK, i)) ss++; return(backref(m, sp+len, stop, ss+1, stopst, lev, rec)); case OQUEST_: /* to null or not */ dp = backref(m, sp, stop, ss+1, stopst, lev, rec); if (dp != NULL) return(dp); /* not */ return(backref(m, sp, stop, ss+OPND(s)+1, stopst, lev, rec)); case OPLUS_: assert(m->lastpos != NULL); assert(lev+1 <= m->g->nplus); m->lastpos[lev+1] = sp; return(backref(m, sp, stop, ss+1, stopst, lev+1, rec)); case O_PLUS: if (sp == m->lastpos[lev]) /* last pass matched null */ return(backref(m, sp, stop, ss+1, stopst, lev-1, rec)); /* try another pass */ m->lastpos[lev] = sp; dp = backref(m, sp, stop, ss-OPND(s)+1, stopst, lev, rec); if (dp == NULL) return(backref(m, sp, stop, ss+1, stopst, lev-1, rec)); else return(dp); case OCH_: /* find the right one, if any */ ssub = ss + 1; esub = ss + OPND(s) - 1; assert(OP(m->g->strip[esub]) == OOR1); for (;;) { /* find first matching branch */ dp = backref(m, sp, stop, ssub, esub, lev, rec); if (dp != NULL) return(dp); /* that one missed, try next one */ if (OP(m->g->strip[esub]) == O_CH) return(NULL); /* there is none */ esub++; assert(OP(m->g->strip[esub]) == OOR2); ssub = esub + 1; esub += OPND(m->g->strip[esub]); if (OP(m->g->strip[esub]) == OOR2) esub--; else assert(OP(m->g->strip[esub]) == O_CH); } /* NOTREACHED */ break; case OLPAREN: /* must undo assignment if rest fails */ i = OPND(s); assert(0 < i && i <= m->g->nsub); offsave = m->pmatch[i].rm_so; m->pmatch[i].rm_so = sp - m->offp; dp = backref(m, sp, stop, ss+1, stopst, lev, rec); if (dp != NULL) return(dp); m->pmatch[i].rm_so = offsave; return(NULL); case ORPAREN: /* must undo assignment if rest fails */ i = OPND(s); assert(0 < i && i <= m->g->nsub); offsave = m->pmatch[i].rm_eo; m->pmatch[i].rm_eo = sp - m->offp; dp = backref(m, sp, stop, ss+1, stopst, lev, rec); if (dp != NULL) return(dp); m->pmatch[i].rm_eo = offsave; return(NULL); default: /* uh oh */ assert(nope); break; } /* "can't happen" */ assert(nope); /* NOTREACHED */ return "shut up gcc"; }
static int fx_init(struct emu10k1_card *card) { struct patch_manager *mgr = &card->mgr; struct dsp_patch *patch; struct dsp_rpatch *rpatch; s32 left, right; int i; u32 pc = 0; u32 patch_n; for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) { mgr->ctrl_gpr[i][0] = -1; mgr->ctrl_gpr[i][1] = -1; } for (i = 0; i < 512; i++) OP(6, 0x40, 0x40, 0x40, 0x40); for (i = 0; i < 256; i++) sblive_writeptr_tag(card, 0, FXGPREGBASE + i, 0, TANKMEMADDRREGBASE + i, 0, TAGLIST_END); /* !! The number bellow must equal the number of patches, currently 11 !! */ mgr->current_pages = (11 + PATCHES_PER_PAGE - 1) / PATCHES_PER_PAGE; for (i = 0; i < mgr->current_pages; i++) { mgr->patch[i] = (void *)__get_free_page(GFP_KERNEL); if (mgr->patch[i] == NULL) { mgr->current_pages = i; fx_cleanup(mgr); return -ENOMEM; } memset(mgr->patch[i], 0, PAGE_SIZE); } pc = 0; patch_n = 0; //first free GPR = 0x11b /* FX volume correction and Volume control*/ INPUT_PATCH_START(patch, "Pcm L vol", 0x0, 0); GET_OUTPUT_GPR(patch, 0x100, 0x0); GET_CONTROL_GPR(patch, 0x106, "Vol", 0, 0x7fffffff); GET_DYNAMIC_GPR(patch, 0x112); OP(4, 0x112, 0x40, PCM_IN_L, 0x44); //*4 OP(0, 0x100, 0x040, 0x112, 0x106); //*vol INPUT_PATCH_END(patch); INPUT_PATCH_START(patch, "Pcm R vol", 0x1, 0); GET_OUTPUT_GPR(patch, 0x101, 0x1); GET_CONTROL_GPR(patch, 0x107, "Vol", 0, 0x7fffffff); GET_DYNAMIC_GPR(patch, 0x112); OP(4, 0x112, 0x40, PCM_IN_R, 0x44); OP(0, 0x101, 0x040, 0x112, 0x107); INPUT_PATCH_END(patch); // CD-Digital In Volume control INPUT_PATCH_START(patch, "CD-Digital Vol L", 0x12, 0); GET_OUTPUT_GPR(patch, 0x10c, 0x12); GET_CONTROL_GPR(patch, 0x10d, "Vol", 0, 0x7fffffff); OP(0, 0x10c, 0x040, SPDIF_CD_L, 0x10d); INPUT_PATCH_END(patch); INPUT_PATCH_START(patch, "CD-Digital Vol R", 0x13, 0); GET_OUTPUT_GPR(patch, 0x10e, 0x13); GET_CONTROL_GPR(patch, 0x10f, "Vol", 0, 0x7fffffff); OP(0, 0x10e, 0x040, SPDIF_CD_R, 0x10f); INPUT_PATCH_END(patch); //Volume Correction for Multi-channel Inputs INPUT_PATCH_START(patch, "Multi-Channel Gain", 0x08, 0); patch->input=patch->output=0x3F00; GET_OUTPUT_GPR(patch, 0x113, MULTI_FRONT_L); GET_OUTPUT_GPR(patch, 0x114, MULTI_FRONT_R); GET_OUTPUT_GPR(patch, 0x115, MULTI_REAR_L); GET_OUTPUT_GPR(patch, 0x116, MULTI_REAR_R); GET_OUTPUT_GPR(patch, 0x117, MULTI_CENTER); GET_OUTPUT_GPR(patch, 0x118, MULTI_LFE); OP(4, 0x113, 0x40, MULTI_FRONT_L, 0x44); OP(4, 0x114, 0x40, MULTI_FRONT_R, 0x44); OP(4, 0x115, 0x40, MULTI_REAR_L, 0x44); OP(4, 0x116, 0x40, MULTI_REAR_R, 0x44); OP(4, 0x117, 0x40, MULTI_CENTER, 0x44); OP(4, 0x118, 0x40, MULTI_LFE, 0x44); INPUT_PATCH_END(patch); //Routing patch start ROUTING_PATCH_START(rpatch, "Routing"); GET_INPUT_GPR(rpatch, 0x100, 0x0); GET_INPUT_GPR(rpatch, 0x101, 0x1); GET_INPUT_GPR(rpatch, 0x10c, 0x12); GET_INPUT_GPR(rpatch, 0x10e, 0x13); GET_INPUT_GPR(rpatch, 0x113, MULTI_FRONT_L); GET_INPUT_GPR(rpatch, 0x114, MULTI_FRONT_R); GET_INPUT_GPR(rpatch, 0x115, MULTI_REAR_L); GET_INPUT_GPR(rpatch, 0x116, MULTI_REAR_R); GET_INPUT_GPR(rpatch, 0x117, MULTI_CENTER); GET_INPUT_GPR(rpatch, 0x118, MULTI_LFE); GET_DYNAMIC_GPR(rpatch, 0x102); GET_DYNAMIC_GPR(rpatch, 0x103); GET_OUTPUT_GPR(rpatch, 0x104, 0x8); GET_OUTPUT_GPR(rpatch, 0x105, 0x9); GET_OUTPUT_GPR(rpatch, 0x10a, 0x2); GET_OUTPUT_GPR(rpatch, 0x10b, 0x3); /* input buffer */ OP(6, 0x102, AC97_IN_L, 0x40, 0x40); OP(6, 0x103, AC97_IN_R, 0x40, 0x40); /* Digital In + PCM + MULTI_FRONT-> AC97 out (front speakers)*/ OP(6, AC97_FRONT_L, 0x100, 0x10c, 0x113); CONNECT(MULTI_FRONT_L, AC97_FRONT_L); CONNECT(PCM_IN_L, AC97_FRONT_L); CONNECT(SPDIF_CD_L, AC97_FRONT_L); OP(6, AC97_FRONT_R, 0x101, 0x10e, 0x114); CONNECT(MULTI_FRONT_R, AC97_FRONT_R); CONNECT(PCM_IN_R, AC97_FRONT_R); CONNECT(SPDIF_CD_R, AC97_FRONT_R); /* Digital In + PCM + AC97 In + PCM1 + MULTI_REAR --> Rear Channel */ OP(6, 0x104, PCM1_IN_L, 0x100, 0x115); OP(6, 0x104, 0x104, 0x10c, 0x102); CONNECT(MULTI_REAR_L, ANALOG_REAR_L); CONNECT(AC97_IN_L, ANALOG_REAR_L); CONNECT(PCM_IN_L, ANALOG_REAR_L); CONNECT(SPDIF_CD_L, ANALOG_REAR_L); CONNECT(PCM1_IN_L, ANALOG_REAR_L); OP(6, 0x105, PCM1_IN_R, 0x101, 0x116); OP(6, 0x105, 0x105, 0x10e, 0x103); CONNECT(MULTI_REAR_R, ANALOG_REAR_R); CONNECT(AC97_IN_R, ANALOG_REAR_R); CONNECT(PCM_IN_R, ANALOG_REAR_R); CONNECT(SPDIF_CD_R, ANALOG_REAR_R); CONNECT(PCM1_IN_R, ANALOG_REAR_R); /* Digital In + PCM + AC97 In + MULTI_FRONT --> Digital out */ OP(6, 0x10a, 0x100, 0x102, 0x10c); OP(6, 0x10a, 0x10a, 0x113, 0x40); CONNECT(MULTI_FRONT_L, DIGITAL_OUT_L); CONNECT(PCM_IN_L, DIGITAL_OUT_L); CONNECT(AC97_IN_L, DIGITAL_OUT_L); CONNECT(SPDIF_CD_L, DIGITAL_OUT_L); OP(6, 0x10b, 0x101, 0x103, 0x10e); OP(6, 0x10b, 0x10b, 0x114, 0x40); CONNECT(MULTI_FRONT_R, DIGITAL_OUT_R); CONNECT(PCM_IN_R, DIGITAL_OUT_R); CONNECT(AC97_IN_R, DIGITAL_OUT_R); CONNECT(SPDIF_CD_R, DIGITAL_OUT_R); /* AC97 In --> ADC Recording Buffer */ OP(6, ADC_REC_L, 0x102, 0x40, 0x40); CONNECT(AC97_IN_L, ADC_REC_L); OP(6, ADC_REC_R, 0x103, 0x40, 0x40); CONNECT(AC97_IN_R, ADC_REC_R); /* fx12:Analog-Center */ OP(6, ANALOG_CENTER, 0x117, 0x40, 0x40); CONNECT(MULTI_CENTER, ANALOG_CENTER); /* fx11:Analog-LFE */ OP(6, ANALOG_LFE, 0x118, 0x40, 0x40); CONNECT(MULTI_LFE, ANALOG_LFE); /* fx12:Digital-Center */ OP(6, DIGITAL_CENTER, 0x117, 0x40, 0x40); CONNECT(MULTI_CENTER, DIGITAL_CENTER); /* fx11:Analog-LFE */ OP(6, DIGITAL_LFE, 0x118, 0x40, 0x40); CONNECT(MULTI_LFE, DIGITAL_LFE); ROUTING_PATCH_END(rpatch); // Rear volume control OUTPUT_PATCH_START(patch, "Vol Rear L", 0x8, 0); GET_INPUT_GPR(patch, 0x104, 0x8); GET_CONTROL_GPR(patch, 0x119, "Vol", 0, 0x7fffffff); OP(0, ANALOG_REAR_L, 0x040, 0x104, 0x119); OUTPUT_PATCH_END(patch); OUTPUT_PATCH_START(patch, "Vol Rear R", 0x9, 0); GET_INPUT_GPR(patch, 0x105, 0x9); GET_CONTROL_GPR(patch, 0x11a, "Vol", 0, 0x7fffffff); OP(0, ANALOG_REAR_R, 0x040, 0x105, 0x11a); OUTPUT_PATCH_END(patch); //Master volume control on front-digital OUTPUT_PATCH_START(patch, "Vol Master L", 0x2, 1); GET_INPUT_GPR(patch, 0x10a, 0x2); GET_CONTROL_GPR(patch, 0x108, "Vol", 0, 0x7fffffff); OP(0, DIGITAL_OUT_L, 0x040, 0x10a, 0x108); OUTPUT_PATCH_END(patch); OUTPUT_PATCH_START(patch, "Vol Master R", 0x3, 1); GET_INPUT_GPR(patch, 0x10b, 0x3); GET_CONTROL_GPR(patch, 0x109, "Vol", 0, 0x7fffffff); OP(0, DIGITAL_OUT_R, 0x040, 0x10b, 0x109); OUTPUT_PATCH_END(patch); /* delimiter patch */ patch = PATCH(mgr, patch_n); patch->code_size = 0; sblive_writeptr(card, DBG, 0, 0); // mgr->lock = SPIN_LOCK_UNLOCKED; //Master volume mgr->ctrl_gpr[SOUND_MIXER_VOLUME][0] = 8; mgr->ctrl_gpr[SOUND_MIXER_VOLUME][1] = 9; // left = card->ac97.mixer_state[SOUND_MIXER_VOLUME] & 0xff; // right = (card->ac97.mixer_state[SOUND_MIXER_VOLUME] >> 8) & 0xff; // left = right = 0x43; left = right = 100; emu10k1_set_volume_gpr(card, 8, left, 1 << 5); emu10k1_set_volume_gpr(card, 9, right, 1 << 5); //Rear volume mgr->ctrl_gpr[ SOUND_MIXER_OGAIN ][0] = 0x19; mgr->ctrl_gpr[ SOUND_MIXER_OGAIN ][1] = 0x1a; // card->ac97.mixer_state[SOUND_MIXER_OGAIN] = (right << 8) | left; // card->ac97.supported_mixers |= SOUND_MASK_OGAIN; // card->ac97.stereo_mixers |= SOUND_MASK_OGAIN; emu10k1_set_volume_gpr(card, 0x19, left, VOL_5BIT); emu10k1_set_volume_gpr(card, 0x1a, right, VOL_5BIT); //PCM Volume mgr->ctrl_gpr[SOUND_MIXER_PCM][0] = 6; mgr->ctrl_gpr[SOUND_MIXER_PCM][1] = 7; // left = card->ac97.mixer_state[SOUND_MIXER_PCM] & 0xff; // right = (card->ac97.mixer_state[SOUND_MIXER_PCM] >> 8) & 0xff; emu10k1_set_volume_gpr(card, 6, left, VOL_5BIT); emu10k1_set_volume_gpr(card, 7, right, VOL_5BIT); //CD-Digital Volume mgr->ctrl_gpr[SOUND_MIXER_DIGITAL1][0] = 0xd; mgr->ctrl_gpr[SOUND_MIXER_DIGITAL1][1] = 0xf; // left = right = 67; // card->ac97.mixer_state[SOUND_MIXER_DIGITAL1] = (right << 8) | left; // card->ac97.supported_mixers |= SOUND_MASK_DIGITAL1; // card->ac97.stereo_mixers |= SOUND_MASK_DIGITAL1; emu10k1_set_volume_gpr(card, 0xd, left, VOL_5BIT); emu10k1_set_volume_gpr(card, 0xf, right, VOL_5BIT); //hard wire the ac97's pcm, we'll do that in dsp code instead. // emu10k1_ac97_write(&card->ac97, 0x18, 0x0); // card->ac97_supported_mixers &= ~SOUND_MASK_PCM; // card->ac97_stereo_mixers &= ~SOUND_MASK_PCM; //set Igain to 0dB by default, maybe consider hardwiring it here. // emu10k1_ac97_write(&card->ac97, AC97_RECORD_GAIN, 0x0000); // card->ac97.mixer_state[SOUND_MIXER_IGAIN] = 0x101; return 0; }
static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) { AnmContext *s = avctx->priv_data; const uint8_t *buf = avpkt->data; const int buf_size = avpkt->size; const uint8_t *buf_end = buf + buf_size; uint8_t *dst, *dst_end; int count; if(avctx->reget_buffer(avctx, &s->frame) < 0){ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return -1; } dst = s->frame.data[0]; dst_end = s->frame.data[0] + s->frame.linesize[0]*avctx->height; if (buf[0] != 0x42) { av_log_ask_for_sample(avctx, "unknown record type\n"); return buf_size; } if (buf[1]) { av_log_ask_for_sample(avctx, "padding bytes not supported\n"); return buf_size; } buf += 4; s->x = 0; do { /* if statements are ordered by probability */ #define OP(buf, pixel, count) \ op(&dst, dst_end, (buf), buf_end, (pixel), (count), &s->x, avctx->width, s->frame.linesize[0]) int type = bytestream_get_byte(&buf); count = type & 0x7F; type >>= 7; if (count) { if (OP(type ? NULL : &buf, -1, count)) break; } else if (!type) { int pixel; count = bytestream_get_byte(&buf); /* count==0 gives nop */ pixel = bytestream_get_byte(&buf); if (OP(NULL, pixel, count)) break; } else { int pixel; type = bytestream_get_le16(&buf); count = type & 0x3FFF; type >>= 14; if (!count) { if (type == 0) break; // stop if (type == 2) { av_log_ask_for_sample(avctx, "unknown opcode"); return AVERROR_INVALIDDATA; } continue; } pixel = type == 3 ? bytestream_get_byte(&buf) : -1; if (type == 1) count += 0x4000; if (OP(type == 2 ? &buf : NULL, pixel, count)) break; } } while (buf + 1 < buf_end); *data_size = sizeof(AVFrame); *(AVFrame*)data = s->frame; return buf_size; }
BOOST_UBLAS_INLINE typename vector_unary_traits<E, OP>::result_type apply_to_all (const vector_expression<E> &e, const OP& op = OP() ) { typedef typename vector_unary_traits<E, OP>::expression_type expression_type; return expression_type (e ()); }
void describe_ppc_trap(ExceptionInformation *xp) { pc where = xpPC(xp); opcode the_trap = *where, instr; int err_arg2, ra, rs; Boolean identified = false; if ((the_trap & OP_MASK) == OP(major_opcode_TRI)) { /* TWI/TDI. If the RA field is "nargs", that means that the instruction is either a number-of-args check or an event-poll. Otherwise, the trap is some sort of typecheck. */ if (RA_field(the_trap) == nargs) { switch (TO_field(the_trap)) { case TO_NE: if (xpGPR(xp, nargs) < D_field(the_trap)) { fprintf(dbgout, "Too few arguments (no opt/rest)\n"); } else { fprintf(dbgout, "Too many arguments (no opt/rest)\n"); } identified = true; break; case TO_GT: fprintf(dbgout, "Event poll !\n"); identified = true; break; case TO_HI: fprintf(dbgout, "Too many arguments (with opt)\n"); identified = true; break; case TO_LT: fprintf(dbgout, "Too few arguments (with opt/rest/key)\n"); identified = true; break; default: /* some weird trap, not ours. */ identified = false; break; } } else { /* A type or boundp trap of some sort. */ switch (TO_field(the_trap)) { case TO_EQ: /* Boundp traps are of the form: treqi rX,unbound where some preceding instruction is of the form: lwz/ld rX,symbol.value(rY). The error message should try to say that rY is unbound. */ if (D_field(the_trap) == unbound) { #ifdef PPC64 instr = scan_for_instr(LD_instruction(RA_field(the_trap), unmasked_register, offsetof(lispsymbol,vcell)-fulltag_misc), D_RT_IMM_MASK, where); #else instr = scan_for_instr(LWZ_instruction(RA_field(the_trap), unmasked_register, offsetof(lispsymbol,vcell)-fulltag_misc), D_RT_IMM_MASK, where); #endif if (instr) { ra = RA_field(instr); if (lisp_reg_p(ra)) { fprintf(dbgout, "Unbound variable: %s\n", print_lisp_object(xpGPR(xp,ra))); identified = true; } } } break; case TO_NE: /* A type check. If the type (the immediate field of the trap instruction) is a header type, an "lbz rX,misc_header_offset(rY)" should precede it, in which case we say that "rY is not of header type <type>." If the type is not a header type, then rX should have been set by a preceding "clrlwi rX,rY,29/30". In that case, scan backwards for an RLWINM instruction that set rX and report that rY isn't of the indicated type. */ err_arg2 = D_field(the_trap); if (nodeheader_tag_p(err_arg2) || immheader_tag_p(err_arg2)) { instr = scan_for_instr(LBZ_instruction(RA_field(the_trap), unmasked_register, misc_subtag_offset), D_RT_IMM_MASK, where); if (instr) { ra = RA_field(instr); if (lisp_reg_p(ra)) { fprintf(dbgout, "value 0x%lX is not of the expected header type 0x%02X\n", xpGPR(xp, ra), err_arg2); identified = true; } } } else { /* Not a header type, look for rlwinm whose RA field matches the_trap's */ instr = scan_for_instr((OP(major_opcode_RLWINM) | (the_trap & RA_MASK)), (OP_MASK | RA_MASK), where); if (instr) { rs = RS_field(instr); if (lisp_reg_p(rs)) { fprintf(dbgout, "value 0x%lX is not of the expected type 0x%02X\n", xpGPR(xp, rs), err_arg2); identified = true; } } } break; } } } else { /* a "TW <to>,ra,rb" instruction." twltu sp,rN is stack-overflow on SP. twgeu rX,rY is subscript out-of-bounds, which was preceded by an "lwz rM,misc_header_offset(rN)" instruction. rM may or may not be the same as rY, but no other header would have been loaded before the trap. */ switch (TO_field(the_trap)) { case TO_LO: if (RA_field(the_trap) == sp) { fprintf(dbgout, "Stack overflow! Run away! Run away!\n"); identified = true; } break; case (TO_HI|TO_EQ): instr = scan_for_instr(OP(major_opcode_LWZ) | (D_MASK & misc_header_offset), (OP_MASK | D_MASK), where); if (instr) { ra = RA_field(instr); if (lisp_reg_p(ra)) { fprintf(dbgout, "Bad index %d for vector %lX length %d\n", unbox_fixnum(xpGPR(xp, RA_field(the_trap))), xpGPR(xp, ra), unbox_fixnum(xpGPR(xp, RB_field(the_trap)))); identified = true; } } break; } } if (!identified) { fprintf(dbgout, "Unknown trap: 0x%08x\n", the_trap); } }
Copyright 1992 Regents of the University of California. All rights reserved. Author: 1987 Kartikeya Mayaram, U. C. Berkeley CAD Group **********/ #include "ngspice/ngspice.h" #include "ngspice/devdefs.h" #include "numddefs.h" #include "ngspice/suffix.h" IFparm NUMDpTable[] = { /* parameters */ IP("off", NUMD_OFF, IF_FLAG, "Initially off"), IP("ic.file", NUMD_IC_FILE, IF_REAL, "Initial conditions file"), IOP("area", NUMD_AREA, IF_REAL, "Area factor"), IP("save", NUMD_PRINT, IF_INTEGER, "Save Solutions"), IPR("print", NUMD_PRINT, IF_INTEGER, "Print Solutions"), OP("vd", NUMD_VD, IF_REAL, "Voltage"), OPR("voltage", NUMD_VD, IF_REAL, "Voltage"), OP("id", NUMD_ID, IF_REAL, "Current"), OPR("current", NUMD_ID, IF_REAL, "Current"), OP("g11", NUMD_G11, IF_REAL, "Conductance"), OPR("conductance", NUMD_G11, IF_REAL, "Conductance"), OP("c11", NUMD_C11, IF_REAL, "Capacitance"), OPR("capacitance", NUMD_C11, IF_REAL, "Capacitance"), OP("y11", NUMD_Y11, IF_COMPLEX, "Admittance"), OPU("g12", NUMD_G12, IF_REAL, "Conductance"), OPU("c12", NUMD_C12, IF_REAL, "Capacitance"), OPU("y12", NUMD_Y12, IF_COMPLEX, "Admittance"), OPU("g21", NUMD_G21, IF_REAL, "Conductance"), OPU("c21", NUMD_C21, IF_REAL, "Capacitance"), OPU("y21", NUMD_Y21, IF_COMPLEX, "Admittance"), OPU("g22", NUMD_G22, IF_REAL, "Conductance"),
Copyright 1990 Regents of the University of California. All rights reserved. Authors: 1985 Thomas L. Quarles 1993 Stephen R. Whiteley ****************************************************************************/ #include "spice.h" #include <stdio.h> #include "resdefs.h" #include "uflags.h" static IFparm RESpTable[] = { /* parameters */ IOPP( "resistance", RES_RESIST, IF_REAL,"Resistance"), IOPZU("temp", RES_TEMP, IF_REAL,"Instance operating temperature"), IOPQU("w", RES_WIDTH, IF_REAL,"Width"), IOPZU("l", RES_LENGTH, IF_REAL,"Length"), OP( "c", RES_CURRENT,IF_REAL,"Current"), OP( "p", RES_POWER, IF_REAL,"Power"), } ; static IFparm RESmPTable[] = { /* model parameters */ IOPQ( "rsh", RES_MOD_RSH, IF_REAL,"Sheet resistance"), IOPZ( "narrow", RES_MOD_NARROW, IF_REAL,"Narrowing of resistor"), IOPQ( "tc1", RES_MOD_TC1, IF_REAL,"First order temp. coefficient"), IOPQO("tc2", RES_MOD_TC2, IF_REAL,"Second order temp. coefficient"), IOPX( "defw", RES_MOD_DEFWIDTH, IF_REAL,"Default device width"), IOPXU("tnom", RES_MOD_TNOM, IF_REAL,"Parameter measurement temperature"), IP( "r", RES_MOD_R, IF_FLAG,"Device is a resistor model"), }; static char *RESnames[] = { "R+",
#define OPERAND(op) OR1K_OPERAND_##op #define MNEM CGEN_SYNTAX_MNEMONIC /* syntax value for mnemonic */ #define OP(field) CGEN_SYNTAX_MAKE_FIELD (OPERAND (field)) /* The instruction table. */ static const CGEN_OPCODE or1k_cgen_insn_opcode_table[MAX_INSNS] = { /* Special null first entry. A `num' value of zero is thus invalid. Also, the special `invalid' insn resides here. */ { { 0, 0, 0, 0 }, {{0}}, 0, {0}}, /* l.j ${disp26} */ { { 0, 0, 0, 0 }, { { MNEM, ' ', OP (DISP26), 0 } }, & ifmt_l_j, { 0x0 } }, /* l.adrp $rD,${disp21} */ { { 0, 0, 0, 0 }, { { MNEM, ' ', OP (RD), ',', OP (DISP21), 0 } }, & ifmt_l_adrp, { 0x8000000 } }, /* l.jal ${disp26} */ { { 0, 0, 0, 0 }, { { MNEM, ' ', OP (DISP26), 0 } }, & ifmt_l_j, { 0x4000000 } }, /* l.jr $rB */
#define OPERAND(op) MT_OPERAND_##op #define MNEM CGEN_SYNTAX_MNEMONIC /* syntax value for mnemonic */ #define OP(field) CGEN_SYNTAX_MAKE_FIELD (OPERAND (field)) /* The instruction table. */ static const CGEN_OPCODE mt_cgen_insn_opcode_table[MAX_INSNS] = { /* Special null first entry. A `num' value of zero is thus invalid. Also, the special `invalid' insn resides here. */ { { 0, 0, 0, 0 }, {{0}}, 0, {0}}, /* add $frdrrr,$frsr1,$frsr2 */ { { 0, 0, 0, 0 }, { { MNEM, ' ', OP (FRDRRR), ',', OP (FRSR1), ',', OP (FRSR2), 0 } }, & ifmt_add, { 0x0 } }, /* addu $frdrrr,$frsr1,$frsr2 */ { { 0, 0, 0, 0 }, { { MNEM, ' ', OP (FRDRRR), ',', OP (FRSR1), ',', OP (FRSR2), 0 } }, & ifmt_add, { 0x2000000 } }, /* addi $frdr,$frsr1,#$imm16 */ { { 0, 0, 0, 0 }, { { MNEM, ' ', OP (FRDR), ',', OP (FRSR1), ',', '#', OP (IMM16), 0 } }, & ifmt_addi, { 0x1000000 } }, /* addui $frdr,$frsr1,#$imm16z */
void setup_opcodes(void) { for(int i = 0; i < 5; i++) { for(int j = 0; j < 256; j++) { op[i][j] = illegal_opcode; } } #define OP(args, opcode, fn) do { op[args][opcode] = fn; opnames[args][opcode] = #fn; } while(0) OP(ZERO, 0x00, zrtrue); OP(ZERO, 0x01, zrfalse); OP(ZERO, 0x02, zprint); OP(ZERO, 0x03, zprint_ret); OP(ZERO, 0x04, znop); if(zversion <= 4) OP(ZERO, 0x05, zsave); if(zversion <= 4) OP(ZERO, 0x06, zrestore); OP(ZERO, 0x07, zrestart); OP(ZERO, 0x08, zret_popped); if(zversion <= 4) OP(ZERO, 0x09, zpop); else OP(ZERO, 0x09, zcatch); OP(ZERO, 0x0a, zquit); OP(ZERO, 0x0b, znew_line); if (zversion == 3) OP(ZERO, 0x0c, zshow_status); else if(zversion >= 4) OP(ZERO, 0x0c, znop); /* §15: Technically illegal in V4+, but a V5 Wishbringer accidentally uses this opcode. */ if(zversion >= 3) OP(ZERO, 0x0d, zverify); if(zversion >= 5) OP(ZERO, 0x0e, zextended); if(zversion >= 5) OP(ZERO, 0x0f, zpiracy); OP(ONE, 0x00, zjz); OP(ONE, 0x01, zget_sibling); OP(ONE, 0x02, zget_child); OP(ONE, 0x03, zget_parent); OP(ONE, 0x04, zget_prop_len); OP(ONE, 0x05, zinc); OP(ONE, 0x06, zdec); OP(ONE, 0x07, zprint_addr); if(zversion >= 4) OP(ONE, 0x08, zcall_1s); OP(ONE, 0x09, zremove_obj); OP(ONE, 0x0a, zprint_obj); OP(ONE, 0x0b, zret); OP(ONE, 0x0c, zjump); OP(ONE, 0x0d, zprint_paddr); OP(ONE, 0x0e, zload); if(zversion <= 4) OP(ONE, 0x0f, znot); else OP(ONE, 0x0f, zcall_1n); OP(TWO, 0x01, zje); OP(TWO, 0x02, zjl); OP(TWO, 0x03, zjg); OP(TWO, 0x04, zdec_chk); OP(TWO, 0x05, zinc_chk); OP(TWO, 0x06, zjin); OP(TWO, 0x07, ztest); OP(TWO, 0x08, zor); OP(TWO, 0x09, zand); OP(TWO, 0x0a, ztest_attr); OP(TWO, 0x0b, zset_attr); OP(TWO, 0x0c, zclear_attr); OP(TWO, 0x0d, zstore); OP(TWO, 0x0e, zinsert_obj); OP(TWO, 0x0f, zloadw); OP(TWO, 0x10, zloadb); OP(TWO, 0x11, zget_prop); OP(TWO, 0x12, zget_prop_addr); OP(TWO, 0x13, zget_next_prop); OP(TWO, 0x14, zadd); OP(TWO, 0x15, zsub); OP(TWO, 0x16, zmul); OP(TWO, 0x17, zdiv); OP(TWO, 0x18, zmod); if(zversion >= 4) OP(TWO, 0x19, zcall_2s); if(zversion >= 5) OP(TWO, 0x1a, zcall_2n); if(zversion >= 5) OP(TWO, 0x1b, zset_colour); if(zversion >= 5) OP(TWO, 0x1c, zthrow); OP(VAR, 0x00, zcall); OP(VAR, 0x01, zstorew); OP(VAR, 0x02, zstoreb); OP(VAR, 0x03, zput_prop); OP(VAR, 0x04, zread); OP(VAR, 0x05, zprint_char); OP(VAR, 0x06, zprint_num); OP(VAR, 0x07, zrandom); OP(VAR, 0x08, zpush); OP(VAR, 0x09, zpull); if(zversion >= 3) OP(VAR, 0x0a, zsplit_window); if(zversion >= 3) OP(VAR, 0x0b, zset_window); if(zversion >= 4) OP(VAR, 0x0c, zcall_vs2); if(zversion >= 4) OP(VAR, 0x0d, zerase_window); if(zversion >= 4) OP(VAR, 0x0e, zerase_line); if(zversion >= 4) OP(VAR, 0x0f, zset_cursor); if(zversion >= 4) OP(VAR, 0x10, zget_cursor); if(zversion >= 4) OP(VAR, 0x11, zset_text_style); if(zversion >= 4) OP(VAR, 0x12, znop); /* XXX buffer_mode */ if(zversion >= 3) OP(VAR, 0x13, zoutput_stream); if(zversion >= 3) OP(VAR, 0x14, zinput_stream); if(zversion >= 3) OP(VAR, 0x15, zsound_effect); if(zversion >= 4) OP(VAR, 0x16, zread_char); if(zversion >= 4) OP(VAR, 0x17, zscan_table); if(zversion >= 5) OP(VAR, 0x18, znot); if(zversion >= 5) OP(VAR, 0x19, zcall_vn); if(zversion >= 5) OP(VAR, 0x1a, zcall_vn2); if(zversion >= 5) OP(VAR, 0x1b, ztokenise); if(zversion >= 5) OP(VAR, 0x1c, zencode_text); if(zversion >= 5) OP(VAR, 0x1d, zcopy_table); if(zversion >= 5) OP(VAR, 0x1e, zprint_table); if(zversion >= 5) OP(VAR, 0x1f, zcheck_arg_count); if(zversion >= 5) OP(EXT, 0x00, zsave5); if(zversion >= 5) OP(EXT, 0x01, zrestore5); if(zversion >= 5) OP(EXT, 0x02, zlog_shift); if(zversion >= 5) OP(EXT, 0x03, zart_shift); if(zversion >= 5) OP(EXT, 0x04, zset_font); if(zversion >= 6) OP(EXT, 0x05, znop); /* XXX draw_picture */ if(zversion >= 6) OP(EXT, 0x06, zpicture_data); if(zversion >= 6) OP(EXT, 0x07, znop); /* XXX erase_picture */ if(zversion >= 6) OP(EXT, 0x08, znop); /* XXX set_margins */ if(zversion >= 5) OP(EXT, 0x09, zsave_undo); if(zversion >= 5) OP(EXT, 0x0a, zrestore_undo); if(zversion >= 5) OP(EXT, 0x0b, zprint_unicode); if(zversion >= 5) OP(EXT, 0x0c, zcheck_unicode); if(zversion >= 5) OP(EXT, 0x0d, zset_true_colour); if(zversion >= 6) OP(EXT, 0x10, znop); /* XXX move_window */ if(zversion >= 6) OP(EXT, 0x11, znop); /* XXX window_size */ if(zversion >= 6) OP(EXT, 0x12, znop); /* XXX window_style */ if(zversion >= 6) OP(EXT, 0x13, zget_wind_prop); if(zversion >= 6) OP(EXT, 0x14, znop); /* XXX scroll_window */ if(zversion >= 6) OP(EXT, 0x15, zpop_stack); if(zversion >= 6) OP(EXT, 0x16, znop); /* XXX read_mouse */ if(zversion >= 6) OP(EXT, 0x17, znop); /* XXX mouse_window */ if(zversion >= 6) OP(EXT, 0x18, zpush_stack); if(zversion >= 6) OP(EXT, 0x19, znop); /* XXX put_wind_prop */ if(zversion >= 6) OP(EXT, 0x1a, zprint_form); if(zversion >= 6) OP(EXT, 0x1b, zmake_menu); if(zversion >= 6) OP(EXT, 0x1c, znop); /* XXX picture_table */ if(zversion >= 6) OP(EXT, 0x1d, zbuffer_screen); /* Zoom extensions. */ OP(EXT, 0x80, zstart_timer); OP(EXT, 0x81, zstop_timer); OP(EXT, 0x82, zread_timer); OP(EXT, 0x83, zprint_timer); #undef OP }
IOPU("temp", VBIC_TEMP, IF_REAL, "Instance temperature"), IOPU("dtemp", VBIC_DTEMP, IF_REAL, "Instance delta temperature"), IOPU("m", VBIC_M, IF_REAL, "Multiplier"), OPU("collnode", VBIC_QUEST_COLLNODE, IF_INTEGER, "Number of collector node"), OPU("basenode", VBIC_QUEST_BASENODE, IF_INTEGER, "Number of base node"), OPU("emitnode", VBIC_QUEST_EMITNODE, IF_INTEGER, "Number of emitter node"), OPU("subsnode", VBIC_QUEST_SUBSNODE, IF_INTEGER, "Number of substrate node"), OPU("collCXnode",VBIC_QUEST_COLLCXNODE,IF_INTEGER, "Internal collector node"), OPU("collCInode",VBIC_QUEST_COLLCINODE,IF_INTEGER, "Internal collector node"), OPU("baseBXnode",VBIC_QUEST_BASEBXNODE,IF_INTEGER, "Internal base node"), OPU("baseBInode",VBIC_QUEST_BASEBINODE,IF_INTEGER, "Internal base node"), OPU("baseBPnode",VBIC_QUEST_BASEBPNODE,IF_INTEGER, "Internal base node"), OPU("emitEInode",VBIC_QUEST_EMITEINODE,IF_INTEGER, "Internal emitter node"), OPU("subsSInode",VBIC_QUEST_SUBSSINODE,IF_INTEGER, "Internal substrate node"), OP("vbe", VBIC_QUEST_VBE, IF_REAL, "B-E voltage"), OP("vbc", VBIC_QUEST_VBC, IF_REAL, "B-C voltage"), OP("ic", VBIC_QUEST_CC, IF_REAL, "Collector current"), OP("ib", VBIC_QUEST_CB, IF_REAL, "Base current"), OP("ie", VBIC_QUEST_CE, IF_REAL, "Emitter current"), OP("is", VBIC_QUEST_CS, IF_REAL, "Substrate current"), OP("gm", VBIC_QUEST_GM, IF_REAL, "Small signal transconductance dIc/dVbe"), OP("go", VBIC_QUEST_GO, IF_REAL, "Small signal output conductance dIc/dVbc"), OP("gpi", VBIC_QUEST_GPI, IF_REAL, "Small signal input conductance dIb/dVbe"), OP("gmu", VBIC_QUEST_GMU, IF_REAL, "Small signal conductance dIb/dVbc"), OP("gx", VBIC_QUEST_GX, IF_REAL, "Conductance from base to internal base"), OP("cbe", VBIC_QUEST_CBE, IF_REAL, "Internal base to emitter capacitance"), OP("cbex", VBIC_QUEST_CBEX, IF_REAL, "External base to emitter capacitance"), OP("cbc", VBIC_QUEST_CBC, IF_REAL, "Internal base to collector capacitance"), OP("cbcx", VBIC_QUEST_CBCX, IF_REAL, "External Base to collector capacitance"), OP("cbep", VBIC_QUEST_CBEP, IF_REAL, "Parasitic Base to emitter capacitance"),
void Hlsl11GeneratorInstance::PrintOperationNodeInit(OperationNode* node) { OperationNode::Operation operation = node->GetOperation(); switch(operation) { case OperationNode::operationNegate: text << '-'; PrintNode(node->GetA()); break; case OperationNode::operationAdd: PrintNode(node->GetA()); text << " + "; PrintNode(node->GetB()); break; case OperationNode::operationSubtract: PrintNode(node->GetA()); text << " - "; PrintNode(node->GetB()); break; case OperationNode::operationMultiply: PrintNode(node->GetA()); text << " * "; PrintNode(node->GetB()); break; case OperationNode::operationDivide: PrintNode(node->GetA()); text << " / "; PrintNode(node->GetB()); break; case OperationNode::operationLess: PrintNode(node->GetA()); text << " < "; PrintNode(node->GetB()); break; case OperationNode::operationLessEqual: PrintNode(node->GetA()); text << " <= "; PrintNode(node->GetB()); break; case OperationNode::operationEqual: PrintNode(node->GetA()); text << " == "; PrintNode(node->GetB()); break; case OperationNode::operationNotEqual: PrintNode(node->GetA()); text << " != "; PrintNode(node->GetB()); break; case OperationNode::operationGetInstanceID: text << "sI"; break; case OperationNode::operationScreenToTexture: PrintNode(node->GetA()); text << " * float2(0.5f, -0.5f) + float2(0.5f, 0.5f)"; break; default: { // остались только функции, которые делаются простым преобразованием имени const char* name; switch(operation) { #define OP(o, n) case OperationNode::operation##o: name = #n; break OP(Float11to2, float2); OP(Float111to3, float3); OP(Float1111to4, float4); OP(Float31to4, float4); OP(Float211to4, float4); OP(Dot, dot); OP(Cross, cross); OP(Mul, mul); OP(Length, length); OP(Normalize, normalize); OP(Lerp, lerp); OP(Pow, pow); OP(Min, min); OP(Max, max); OP(Abs, abs); OP(Sqrt, sqrt); OP(Sin, sin); OP(Cos, cos); OP(Atan2, atan2); OP(Exp, exp); OP(Exp2, exp2); OP(Log, log); OP(Saturate, saturate); OP(Ddx, ddx); OP(Ddy, ddy); OP(Floor, floor); OP(Ceil, ceil); OP(Mod, fmod); #undef OP default: THROW("Invalid operation type"); } // вывести text << name << '('; int argumentsCount = node->GetArgumentsCount(); for(int i = 0; i < argumentsCount; ++i) { if(i) text << ", "; PrintNode(node->GetArgument(i)); } text << ')'; } } }