38 #include <sys/types.h>
52 #include "llvm/Config/config.h"
57 #define SIZE_MAX UINT_MAX
122 #define PEEK() (*p->next)
123 #define PEEK2() (*(p->next+1))
124 #define MORE() (p->next < p->end)
125 #define MORE2() (p->next+1 < p->end)
126 #define SEE(c) (MORE() && PEEK() == (c))
127 #define SEETWO(a, b) (MORE() && MORE2() && PEEK() == (a) && PEEK2() == (b))
128 #define EAT(c) ((SEE(c)) ? (NEXT(), 1) : 0)
129 #define EATTWO(a, b) ((SEETWO(a, b)) ? (NEXT2(), 1) : 0)
130 #define NEXT() (p->next++)
131 #define NEXT2() (p->next += 2)
132 #define NEXTn(n) (p->next += (n))
133 #define GETNEXT() (*p->next++)
134 #define SETERROR(e) seterr(p, (e))
135 #define REQUIRE(co, e) (void)((co) || SETERROR(e))
136 #define MUSTSEE(c, e) (REQUIRE(MORE() && PEEK() == (c), e))
137 #define MUSTEAT(c, e) (REQUIRE(MORE() && GETNEXT() == (c), e))
138 #define MUSTNOTSEE(c, e) (REQUIRE(!MORE() || PEEK() != (c), e))
139 #define EMIT(op, sopnd) doemit(p, (sop)(op), (size_t)(sopnd))
140 #define INSERT(op, pos) doinsert(p, (sop)(op), HERE()-(pos)+1, pos)
141 #define AHEAD(pos) dofwd(p, pos, HERE()-(pos))
142 #define ASTERN(sop, pos) EMIT(sop, HERE()-pos)
143 #define HERE() (p->slen)
144 #define THERE() (p->slen - 1)
145 #define THERETHERE() (p->slen - 2)
146 #define DROP(n) (p->slen -= (n))
148 #ifdef _POSIX2_RE_DUP_MAX
149 #define DUPMAX _POSIX2_RE_DUP_MAX
153 #define INFINITY (DUPMAX + 1)
156 static int never = 0;
169 struct parse *p = &pa;
173 # define GOODFLAGS(f) (f)
175 # define GOODFLAGS(f) ((f)&~REG_DUMP)
187 len = strlen((
const char *)pattern);
194 p->
ssize = len/(size_t)2*(
size_t)3 + (size_t)1;
197 if (p->
strip == NULL) {
204 p->
next = (
char *)pattern;
208 for (i = 0; i <
NPAREN; i++) {
231 if (cflags®_EXTENDED)
233 else if (cflags®_NOSPEC)
276 while (
MORE() && (c =
PEEK()) !=
'|' && c != stop)
339 #ifndef POSIX_MISTAKE
382 if (c >=
'1' && c <=
'9') {
388 backrefnum = c -
'0';
389 if (p->
pend[backrefnum] == 0) {
397 assert(backrefnum <= p->g->nsub);
423 if (!( c ==
'*' || c ==
'+' || c ==
'?' ||
460 repeat(p, pos, count, count2);
473 if (!( c ==
'*' || c ==
'+' || c ==
'?' ||
541 # define BACKSL (1<<CHAR_BIT)
595 if (p->
pend[i] != 0) {
621 }
else if (
EATTWO(
'\\',
'{')) {
631 repeat(p, pos, count, count2);
654 count = count*10 + (
GETNEXT() -
'0');
675 if (p->
next + 5 < p->
end && strncmp(p->
next,
"[:<:]]", 6) == 0) {
680 if (p->
next + 5 < p->
end && strncmp(p->
next,
"[:>:]]", 6) == 0) {
712 for (i = p->
g->
csetsize - 1; i >= 0; i--)
713 if (
CHIN(cs, i) && isalpha(i)) {
724 for (i = p->
g->
csetsize - 1; i >= 0; i--)
737 if (
nch(p, cs) == 1) {
801 for (i = start; i <= finish; i++)
823 if (strncmp(cp->
name, sp, len) == 0 && cp->
name[len] ==
'\0')
825 if (cp->
name == NULL) {
832 while ((c = *u++) !=
'\0')
834 for (u = cp->
multis; *u !=
'\0'; u += strlen(u) + 1)
889 if (strncmp(cp->
name, sp, len) == 0 && cp->
name[len] ==
'\0')
906 return ((
uch)tolower(ch));
907 else if (islower(ch))
908 return ((
uch)toupper(ch));
921 char *oldnext = p->
next;
922 char *oldend = p->
end;
963 char *oldnext = p->
next;
964 char *oldend = p->
end;
991 # define REP(f, t) ((f)*8 + (t))
992 # define MAP(n) (((n) <= 1) ? (n) : ((n) == INFINITY) ? INF : N)
1009 repeat(p, start+1, 1, to);
1027 copy =
dupl(p, start+1, finish+1);
1028 assert(copy == finish+4);
1029 repeat(p, copy, 1, to-1);
1036 copy =
dupl(p, start, finish);
1037 repeat(p, copy, from-1, to-1);
1040 copy =
dupl(p, start, finish);
1041 repeat(p, copy, from-1, to);
1080 if (nc > SIZE_MAX /
sizeof(
cset))
1082 assert(nc % CHAR_BIT == 0);
1083 nbytes = nc / CHAR_BIT * css;
1085 ptr = (
cset *)realloc((
char *)p->
g->
sets, nc *
sizeof(
cset));
1090 ptr = (
uch *)realloc((
char *)p->
g->
setbits, nbytes);
1095 for (
i = 0;
i < no;
i++)
1098 (void) memset((
char *)p->
g->
setbits + (nbytes - css), 0, css);
1104 cs = &p->
g->
sets[no];
1106 cs->
mask = 1 << ((no) % CHAR_BIT);
1133 for (i = 0; i < css; i++)
1158 for (cs2 = &p->
g->
sets[0]; cs2 < top; cs2++)
1159 if (cs2->
hash == h && cs2 != cs) {
1161 for (i = 0; i < css; i++)
1162 if (!!
CHIN(cs2, i) != !!
CHIN(cs, i))
1173 return((
int)(cs - p->
g->
sets));
1185 for (i = 0; i < css; i++)
1202 for (i = 0; i < css; i++)
1217 cs->
smultis += strlen(cp) + 1;
1265 int ncols = (g->
ncsets+(CHAR_BIT-1)) / CHAR_BIT;
1266 unsigned uc = (
uch)c;
1268 for (i = 0, col = g->
setbits; i < ncols; i++, col += g->csetsize)
1282 int ncols = (g->
ncsets+(CHAR_BIT-1)) / CHAR_BIT;
1283 unsigned uc1 = (
uch)c1;
1284 unsigned uc2 = (
uch)c2;
1286 for (i = 0, col = g->
setbits; i < ncols; i++, col += g->csetsize)
1287 if (col[uc1] != col[uc2])
1307 for (c = CHAR_MIN; c <= CHAR_MAX; c++)
1308 if (cats[c] == 0 &&
isinsets(g, c)) {
1311 for (c2 = c+1; c2 <= CHAR_MAX; c2++)
1312 if (cats[c2] == 0 &&
samesets(g, c, c2))
1326 sopno len = finish - start;
1333 (void) memmove((
char *)(p->
strip + p->
slen),
1334 (
char *)(p->
strip + start), (
size_t)len*
sizeof(
sop));
1386 for (i = 1; i <
NPAREN; i++) {
1387 if (p->
pbegin[i] >= pos) {
1390 if (p->
pend[i] >= pos) {
1395 memmove((
char *)&p->
strip[pos+1], (
char *)&p->
strip[pos],
1422 if (p->
ssize >= size)
1425 if ((uintptr_t)size > SIZE_MAX /
sizeof(
sop)) {
1446 if ((uintptr_t)p->
slen > SIZE_MAX /
sizeof(
sop)) {
1453 if (g->
strip == NULL) {
1485 scan = g->
strip + 1;
1491 newstart = scan - 1;
1513 if (newlen > g->
mlen) {
1526 g->
must = malloc((
size_t)g->
mlen + 1);
1527 if (g->
must == NULL) {
1533 for (i = g->
mlen; i > 0; i--) {
1534 while (
OP(s = *scan++) !=
OCHAR)
1537 *cp++ = (char)
OPND(s);
1557 scan = g->
strip + 1;
1565 if (plusnest > maxnest)
static void nonnewline(struct parse *)
static void p_ere_exp(struct parse *)
static int p_simp_re(struct parse *, int)
static int firstch(struct parse *, cset *)
static struct cname cnames[]
static int samesets(struct re_guts *, int, int)
static int freezeset(struct parse *, cset *)
static void mccase(struct parse *, cset *)
static void p_b_term(struct parse *, cset *)
static void categorize(struct parse *, struct re_guts *)
static void findmust(struct parse *, struct re_guts *)
int llvm_regcomp(llvm_regex_t *preg, const char *pattern, int cflags)
static int seterr(struct parse *, int)
void llvm_regfree(llvm_regex_t *)
static cset * allocset(struct parse *)
static void stripsnug(struct parse *, struct re_guts *)
static void dofwd(struct parse *, sopno, sop)
static void doemit(struct parse *, sop, size_t)
static void bothcases(struct parse *, int)
static int nch(struct parse *, cset *)
size_t llvm_strlcpy(char *dst, const char *src, size_t siz)
auto count(R &&Range, const E &Element) -> typename std::iterator_traits< decltype(std::begin(Range))>::difference_type
Wrapper function around std::count to count the number of times an element Element occurs in the give...
static void enlarge(struct parse *, sopno)
static void p_ere(struct parse *, int)
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
static void mcadd(struct parse *, cset *, const char *)
static void doinsert(struct parse *, sop, size_t, sopno)
for(unsigned i=0, e=MI->getNumOperands();i!=e;++i)
static void p_b_cclass(struct parse *, cset *)
static void p_bracket(struct parse *)
static void freeset(struct parse *, cset *)
static char p_b_symbol(struct parse *)
static void ordinary(struct parse *, int)
static void p_bre(struct parse *, int, int)
static int p_count(struct parse *)
static struct cclass cclasses[]
static char p_b_coll_elem(struct parse *, int)
static void p_b_eclass(struct parse *, cset *)
static char othercase(int)
static sopno dupl(struct parse *, sopno, sopno)
static void repeat(struct parse *, sopno, int, int)
static sopno pluscount(struct parse *, struct re_guts *)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static void p_str(struct parse *)
static int isinsets(struct re_guts *, int)
static Expected< BitVector > scan(StringRef &S, StringRef Original)
static void mcinvert(struct parse *, cset *)