本文整理汇总了C++中OP函数的典型用法代码示例。如果您正苦于以下问题:C++ OP函数的具体用法?C++ OP怎么用?C++ OP使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了OP函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: regprop
/*
- 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);
}
示例2: OP
#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},
示例3: transform
/****************
* 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);
//.........这里部分代码省略.........
示例4: arp_print
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",
//.........这里部分代码省略.........
示例5: IOPU
#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-"
示例6: stop
/*
- 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 */
//.........这里部分代码省略.........
示例7: step
/*
- 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)) {
//.........这里部分代码省略.........
示例8: p_simp_re
/*
- 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(',')) {
//.........这里部分代码省略.........
示例9: regnext
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);
//.........这里部分代码省略.........
示例10: s_print
/*
* 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:
//.........这里部分代码省略.........
示例11: OP
#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 */
示例12: getRegisterNum
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); }
}
}
示例13: if
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);
}
示例14: regmatch
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
//.........这里部分代码省略.........
示例15: scan
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;
//.........这里部分代码省略.........