50#include "llvm/Config/config.h"
59 {
"alnum",
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\
62 {
"alpha",
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
""},
64 {
"cntrl",
"\007\b\t\n\v\f\r\1\2\3\4\5\6\16\17\20\21\22\23\24\
65\25\26\27\30\31\32\33\34\35\36\37\177",
67 {
"digit",
"0123456789",
""},
68 {
"graph",
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\
690123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~",
71 {
"lower",
"abcdefghijklmnopqrstuvwxyz",
""},
72 {
"print",
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\
730123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ ",
75 {
"punct",
"!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~",
""},
76 {
"space",
"\t\n\v\f\r ",
""},
77 {
"upper",
"ABCDEFGHIJKLMNOPQRSTUVWXYZ",
""},
78 {
"xdigit",
"0123456789ABCDEFabcdef",
""},
85}
cnames[] = {{
"NUL",
'\0'},
101 {
"vertical-tab",
'\v'},
105 {
"carriage-return",
'\r'},
129 {
"exclamation-mark",
'!'},
130 {
"quotation-mark",
'"'},
131 {
"number-sign",
'#'},
132 {
"dollar-sign",
'$'},
133 {
"percent-sign",
'%'},
135 {
"apostrophe",
'\''},
136 {
"left-parenthesis",
'('},
137 {
"right-parenthesis",
')'},
142 {
"hyphen-minus",
'-'},
159 {
"less-than-sign",
'<'},
160 {
"equals-sign",
'='},
161 {
"greater-than-sign",
'>'},
162 {
"question-mark",
'?'},
163 {
"commercial-at",
'@'},
164 {
"left-square-bracket",
'['},
166 {
"reverse-solidus",
'\\'},
167 {
"right-square-bracket",
']'},
169 {
"circumflex-accent",
'^'},
172 {
"grave-accent",
'`'},
174 {
"left-curly-bracket",
'{'},
175 {
"vertical-line",
'|'},
176 {
"right-brace",
'}'},
177 {
"right-curly-bracket",
'}'},
244#define PEEK() (*p->next)
245#define PEEK2() (*(p->next + 1))
246#define MORE() (p->end - p->next > 0)
247#define MORE2() (p->end - p->next > 1)
248#define SEE(c) (MORE() && PEEK() == (c))
249#define SEETWO(a, b) (MORE2() && PEEK() == (a) && PEEK2() == (b))
250#define EAT(c) ((SEE(c)) ? (NEXT(), 1) : 0)
251#define EATTWO(a, b) ((SEETWO(a, b)) ? (NEXT2(), 1) : 0)
252#define NEXT() (p->next++)
253#define NEXT2() (p->next += 2)
254#define NEXTn(n) (p->next += (n))
255#define GETNEXT() (*p->next++)
256#define SETERROR(e) seterr(p, (e))
257#define REQUIRE(co, e) (void)((co) || SETERROR(e))
258#define MUSTSEE(c, e) (REQUIRE(MORE() && PEEK() == (c), e))
259#define MUSTEAT(c, e) (REQUIRE(MORE() && GETNEXT() == (c), e))
260#define MUSTNOTSEE(c, e) (REQUIRE(!MORE() || PEEK() != (c), e))
261#define EMIT(op, sopnd) doemit(p, (sop)(op), (size_t)(sopnd))
262#define INSERT(op, pos) doinsert(p, (sop)(op), HERE() - (pos) + 1, pos)
263#define AHEAD(pos) dofwd(p, pos, HERE() - (pos))
264#define ASTERN(sop, pos) EMIT(sop, HERE() - pos)
265#define HERE() (p->slen)
266#define THERE() (p->slen - 1)
267#define THERETHERE() (p->slen - 2)
268#define DROP(n) (p->slen -= (n))
270#ifdef _POSIX2_RE_DUP_MAX
271#define DUPMAX _POSIX2_RE_DUP_MAX
275#define REGINFINITY (DUPMAX + 1)
290 struct parse *p = &pa;
294#define GOODFLAGS(f) (f)
296#define GOODFLAGS(f) ((f) & ~REG_DUMP)
308 len = strlen(pattern);
316 p->ssize = len / (size_t)2 * (
size_t)3 + (size_t)1;
317 p->strip = (
sop *)calloc(p->ssize,
sizeof(
sop));
319 if (p->strip == NULL) {
327 p->end = p->next + len;
330 for (i = 0; i <
NPAREN; i++) {
346 g->categories = &
g->catspace[-(CHAR_MIN)];
347 (void)memset((
char *)
g->catspace, 0,
NC *
sizeof(
cat_t));
398 while (
MORE() && (c =
PEEK()) !=
'|' && c != stop)
448 p->pbegin[subno] =
HERE();
453 p->pend[subno] =
HERE();
454 assert(p->pend[subno] != 0);
502 if (c >=
'1' && c <=
'9') {
508 backrefnum = c -
'0';
509 if (p->pend[backrefnum] == 0) {
517 assert(backrefnum <= p->
g->nsub);
519 assert(p->pbegin[backrefnum] != 0);
522 (void)
dupl(p, p->pbegin[backrefnum] + 1, p->pend[backrefnum]);
543 if (!(c ==
'*' || c ==
'+' || c ==
'?' ||
580 repeat(p, pos, count, count2);
593 if (!(c ==
'*' || c ==
'+' || c ==
'?' ||
657#define BACKSL (1 << CHAR_BIT)
684 p->pbegin[subno] =
HERE();
690 p->pend[subno] =
HERE();
691 assert(p->pend[subno] != 0);
709 i = (c & ~BACKSL) -
'0';
711 if (p->pend[i] != 0) {
714 assert(p->pbegin[i] != 0);
717 (void)
dupl(p, p->pbegin[i] + 1, p->pend[i]);
738 }
else if (
EATTWO(
'\\',
'{')) {
748 repeat(p, pos, count, count2);
770 count = count * 10 + (
GETNEXT() -
'0');
789 if (p->end - p->next > 5) {
790 if (strncmp(p->next,
"[:<:]]", 6) == 0) {
795 if (strncmp(p->next,
"[:>:]]", 6) == 0) {
828 for (i = p->g->csetsize - 1; i >= 0; i--)
829 if (
CHIN(cs, i) && isalpha(i)) {
840 for (i = p->g->csetsize - 1; i >= 0; i--)
853 if (
nch(p, cs) == 1) {
917 for (i = start; i <= finish; i++)
927 const char *sp = p->next;
937 if (strncmp(cp->
name, sp, len) == 0 && cp->
name[len] ==
'\0')
939 if (cp->
name == NULL) {
946 while ((c = *u++) !=
'\0')
948 for (u = cp->
multis; *u !=
'\0'; u += strlen(u) + 1)
987 const char *sp = p->next;
999 if (strncmp(cp->
name, sp, len) == 0 && strlen(cp->
name) == len)
1015 return ((
uch)tolower(ch));
1016 else if (islower(ch))
1017 return ((
uch)toupper(ch));
1028 const char *oldnext = p->next;
1029 const char *oldend = p->end;
1035 p->end = bracket + 2;
1040 assert(p->next == bracket + 2);
1049 cat_t *cap = p->g->categories;
1056 cap[ch] = p->g->ncategories++;
1066 const char *oldnext = p->next;
1067 const char *oldend = p->end;
1068 static const char bracket[4] = {
'^',
'\n',
']',
'\0'};
1071 p->end = bracket + 3;
1073 assert(p->next == bracket + 3);
1089#define REP(f, t) ((f) * 8 + (t))
1090#define MAP(n) (((n) <= 1) ? (n) : ((n) == REGINFINITY) ? INF : N)
1100 DROP(finish - start);
1107 repeat(p, start + 1, 1, to);
1125 copy =
dupl(p, start + 1, finish + 1);
1126 assert(copy == finish + 4);
1127 repeat(p, copy, 1, to - 1);
1134 copy =
dupl(p, start, finish);
1135 repeat(p, copy, from - 1, to - 1);
1138 copy =
dupl(p, start, finish);
1139 repeat(p, copy, from - 1, to);
1163 int no = p->g->ncsets++;
1167 size_t css = (size_t)p->g->csetsize;
1170 if (no >= p->ncsalloc) {
1173 p->ncsalloc += CHAR_BIT;
1175 if (nc > SIZE_MAX /
sizeof(
cset))
1177 assert(nc % CHAR_BIT == 0);
1178 nbytes = nc / CHAR_BIT * css;
1180 ptr = (
cset *)realloc((
char *)p->g->sets, nc *
sizeof(
cset));
1185 ptr = (
uch *)realloc((
char *)p->g->setbits, nbytes);
1188 p->g->setbits = ptr;
1190 for (i = 0; i < no; i++)
1191 p->g->sets[i].ptr = p->g->setbits + css * (i / CHAR_BIT);
1193 (void)memset((
char *)p->g->setbits + (nbytes - css), 0, css);
1196 if (p->g->sets == NULL || p->g->setbits == NULL)
1199 cs = &p->g->sets[no];
1200 cs->
ptr = p->g->setbits + css * ((no) / CHAR_BIT);
1201 cs->
mask = 1 << ((no) % CHAR_BIT);
1210 free(p->g->setbits);
1211 p->g->setbits = NULL;
1223 cset *top = &p->g->sets[p->g->ncsets];
1224 size_t css = (size_t)p->g->csetsize;
1226 for (i = 0; i < css; i++)
1245 cset *top = &p->g->sets[p->g->ncsets];
1247 size_t css = (size_t)p->g->csetsize;
1250 for (cs2 = &p->g->sets[0]; cs2 < top; cs2++)
1251 if (cs2->
hash == h && cs2 != cs) {
1253 for (i = 0; i < css; i++)
1254 if (!!
CHIN(cs2, i) != !!
CHIN(cs, i))
1265 return ((
int)(cs - p->g->sets));
1274 size_t css = (size_t)p->g->csetsize;
1276 for (i = 0; i < css; i++)
1288 size_t css = (size_t)p->g->csetsize;
1291 for (i = 0; i < css; i++)
1304 cs->
smultis += strlen(cp) + 1;
1347 int ncols = (
g->ncsets + (CHAR_BIT - 1)) / CHAR_BIT;
1348 unsigned uc = (
uch)c;
1350 for (i = 0, col =
g->setbits; i < ncols; i++, col += g->csetsize)
1363 int ncols = (
g->ncsets + (CHAR_BIT - 1)) / CHAR_BIT;
1364 unsigned uc1 = (
uch)c1;
1365 unsigned uc2 = (
uch)c2;
1367 for (i = 0, col =
g->setbits; i < ncols; i++, col += g->csetsize)
1368 if (col[uc1] != col[uc2])
1377 cat_t *cats =
g->categories;
1386 for (c = CHAR_MIN; c <= CHAR_MAX; c++)
1388 cat =
g->ncategories++;
1390 for (c2 = c + 1; c2 <= CHAR_MAX; c2++)
1391 if (cats[c2] == 0 &&
samesets(
g, c, c2))
1404 sopno len = finish - start;
1410 assert(p->ssize >= p->slen + len);
1411 (void)memmove((
char *)(p->strip + p->slen), (
char *)(p->strip + start),
1412 (
size_t)len *
sizeof(
sop));
1433 if (p->slen >= p->ssize)
1434 enlarge(p, (p->ssize + 1) / 2 * 3);
1435 assert(p->slen < p->ssize);
1438 p->strip[p->slen++] =
SOP(
op, opnd);
1460 for (i = 1; i <
NPAREN; i++) {
1461 if (p->pbegin[i] >= pos) {
1464 if (p->pend[i] >= pos) {
1469 memmove((
char *)&p->strip[pos + 1], (
char *)&p->strip[pos],
1470 (
HERE() - pos - 1) *
sizeof(
sop));
1483 p->strip[pos] =
OP(p->strip[pos]) |
value;
1492 if (p->ssize >= size)
1495 if ((uintptr_t)size > SIZE_MAX /
sizeof(
sop)) {
1500 sp = (
sop *)realloc(p->strip, size *
sizeof(
sop));
1513 g->nstates = p->slen;
1514 if ((uintptr_t)p->slen > SIZE_MAX /
sizeof(
sop)) {
1515 g->strip = p->strip;
1520 g->strip = (
sop *)realloc((
char *)p->strip, p->slen *
sizeof(
sop));
1521 if (
g->strip == NULL) {
1523 g->strip = p->strip;
1551 scan =
g->strip + 1;
1557 newstart = scan - 1;
1578 if (newlen >
g->mlen) {
1591 g->must = malloc((
size_t)
g->mlen + 1);
1592 if (
g->must == NULL) {
1598 for (i =
g->mlen; i > 0; i--) {
1599 while (
OP(s = *scan++) !=
OCHAR)
1601 assert(cp < g->must +
g->mlen);
1621 scan =
g->strip + 1;
1629 if (plusnest > maxnest)
for(const MachineOperand &MO :llvm::drop_begin(OldMI.operands(), Desc.getNumOperands()))
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Given that RA is a live value
INLINE void g(uint32_t *state, size_t a, size_t b, size_t c, size_t d, uint32_t x, uint32_t y)
static void mccase(struct parse *, cset *)
static int samesets(struct re_guts *, int, int)
static void stripsnug(struct parse *, struct re_guts *)
static void mcadd(struct parse *, cset *, const char *)
static char p_b_coll_elem(struct parse *, int)
static void p_ere_exp(struct parse *)
static sopno dupl(struct parse *, sopno, sopno)
static char othercase(int)
static void p_b_cclass(struct parse *, cset *)
static void doemit(struct parse *, sop, size_t)
static void nonnewline(struct parse *)
static void p_b_eclass(struct parse *, cset *)
static int freezeset(struct parse *, cset *)
static struct cclass cclasses[]
static struct cname cnames[]
static void ordinary(struct parse *, int)
static void categorize(struct parse *, struct re_guts *)
static void p_str(struct parse *)
static void bothcases(struct parse *, int)
static void repeat(struct parse *, sopno, int, int)
int llvm_regcomp(llvm_regex_t *preg, const char *pattern, int cflags)
static void p_b_term(struct parse *, cset *)
static int isinsets(struct re_guts *, int)
static void p_bre(struct parse *, int, int)
static int nch(struct parse *, cset *)
static void doinsert(struct parse *, sop, size_t, sopno)
static sopno pluscount(struct parse *, struct re_guts *)
static void p_ere(struct parse *, int)
static char p_b_symbol(struct parse *)
static void findmust(struct parse *, struct re_guts *)
static cset * allocset(struct parse *)
static void p_bracket(struct parse *)
static void dofwd(struct parse *, sopno, sop)
static int p_count(struct parse *)
static void enlarge(struct parse *, sopno)
static int p_simp_re(struct parse *, int)
static void freeset(struct parse *, cset *)
static void mcinvert(struct parse *, cset *)
static int seterr(struct parse *, int)
static int firstch(struct parse *, cset *)
size_t llvm_strlcpy(char *dst, const char *src, size_t siz)
void llvm_regfree(llvm_regex_t *)