aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--amd64/emit.c20
-rw-r--r--amd64/isel.c2
-rw-r--r--amd64/sysv.c2
-rw-r--r--c/builtin.c16
-rw-r--r--c/c.c46
-rw-r--r--c/lex.c40
-rw-r--r--common.h2
-rw-r--r--io.c26
-rw-r--r--ir/abi0.c4
-rw-r--r--ir/intrin.c6
-rw-r--r--ir/ir.c28
-rw-r--r--ir/optmem.c2
-rw-r--r--ir/regalloc.c4
-rw-r--r--main.c8
-rw-r--r--type.c6
15 files changed, 106 insertions, 106 deletions
diff --git a/amd64/emit.c b/amd64/emit.c
index e7dd724..fff73f0 100644
--- a/amd64/emit.c
+++ b/amd64/emit.c
@@ -449,12 +449,12 @@ encode(uchar **pcode, const struct desc *tab, int ntab, enum irclass k, struct o
}
}
-#define DEFINSTR1(X, ...) \
- static void \
- X(uchar **pcode, enum irclass k, struct oper oper) \
- { \
- static const struct desc tab[] = { __VA_ARGS__ }; \
- encode(pcode, tab, arraylength(tab), k, oper, mkoper(0,)); \
+#define DEFINSTR1(X, ...) \
+ static void \
+ X(uchar **pcode, enum irclass k, struct oper oper) \
+ { \
+ static const struct desc tab[] = { __VA_ARGS__ }; \
+ encode(pcode, tab, countof(tab), k, oper, mkoper(0,)); \
}
#define DEFINSTR2(X, ...) \
@@ -462,7 +462,7 @@ encode(uchar **pcode, const struct desc *tab, int ntab, enum irclass k, struct o
X(uchar **pcode, enum irclass k, struct oper dst, struct oper src) \
{ \
static const struct desc tab[] = { __VA_ARGS__ }; \
- encode(pcode, tab, arraylength(tab), k, dst, src); \
+ encode(pcode, tab, countof(tab), k, dst, src); \
}
DEFINSTR2(Xmovb,
@@ -500,7 +500,7 @@ static void Xmov(uchar **pcode, enum irclass k, struct oper dst, struct oper src
[KF32] = 7,
[KF64] = 10,
};
- encode(pcode, all + k2off[k], arraylength(all) - k2off[k], k, dst, src);
+ encode(pcode, all + k2off[k], countof(all) - k2off[k], k, dst, src);
}
DEFINSTR2(Xmovsxl,
{8, PGPR, PMEM, "\x63", EN_RM}, /* MOVSXD r64, m32 */
@@ -702,10 +702,10 @@ Ximul(uchar **pcode, enum irclass k, struct oper dst, struct oper s1, struct ope
}
assert(s2.t == OIMM);
if ((uint)(s2.imm + 128) < 256) {
- encode(pcode, imm8tab, arraylength(imm8tab), k, dst, s1);
+ encode(pcode, imm8tab, countof(imm8tab), k, dst, s1);
B(s2.imm);
} else {
- encode(pcode, imm32tab, arraylength(imm32tab), k, dst, s1);
+ encode(pcode, imm32tab, countof(imm32tab), k, dst, s1);
I32(s2.imm);
}
}
diff --git a/amd64/isel.c b/amd64/isel.c
index be2f769..77d5b9e 100644
--- a/amd64/isel.c
+++ b/amd64/isel.c
@@ -640,7 +640,7 @@ amd64_isel(struct function *fn)
for (i = 0; i < blk->ins.n; ++i) {
struct instr *ins = &instrtab[blk->ins.p[i]];
sel(fn, ins, blk, &i);
- if (ins->op < arraylength(opflags) && kisint(insrescls(*ins))) {
+ if (ins->op < countof(opflags) && kisint(insrescls(*ins))) {
if (opflags[ins->op] & ZF) iflagsrc = ins - instrtab;
else if (opflags[ins->op] & CLOBF) iflagsrc = -1;
}
diff --git a/amd64/sysv.c b/amd64/sysv.c
index 020f597..486c0c0 100644
--- a/amd64/sysv.c
+++ b/amd64/sysv.c
@@ -69,7 +69,7 @@ static int
abiarg(short r[2], uchar cls[2], uchar *r2off, int *ni, int *nf, int *ns, union irtype typ)
{
static const uchar intregs[] = { RDI, RSI, RDX, RCX, R8, R9 };
- enum { NINT = arraylength(intregs), NFLT = 8 };
+ enum { NINT = countof(intregs), NFLT = 8 };
int ret, ni_save, nf_save;
if (!typ.isagg) {
diff --git a/c/builtin.c b/c/builtin.c
index 9a8a12b..913d6b3 100644
--- a/c/builtin.c
+++ b/c/builtin.c
@@ -24,12 +24,12 @@ callcheck(const struct span *span, int nparam, const union type *param, int narg
return ok;
}
-#define DEF_FNLIKE_SEMA(name, retty, ...) \
- static bool \
- name##_sema(struct comp *cm, struct expr *ex) { \
- union type par[] = { {{0}}, __VA_ARGS__ }; \
- ex->ty = retty; \
- return callcheck(&ex->span, arraylength(par)-1, par+1, ex->narg, ex->sub+1); \
+#define DEF_FNLIKE_SEMA(name, retty, ...) \
+ static bool \
+ name##_sema(struct comp *cm, struct expr *ex) { \
+ union type par[] = { {{0}}, __VA_ARGS__ }; \
+ ex->ty = retty; \
+ return callcheck(&ex->span, countof(par)-1, par+1, ex->narg, ex->sub+1); \
}
static bool
@@ -111,7 +111,7 @@ static const struct {
void
putbuiltins(struct env *env)
{
- for (int i = 0; i < arraylength(tab); ++i) {
+ for (int i = 0; i < countof(tab); ++i) {
const char *intern(const char *);
envadddecl(env, &(struct decl) {
.name = intern(tab[i].name),
@@ -124,7 +124,7 @@ putbuiltins(struct env *env)
bool
hasbuiltin(const char *name, uint len)
{
- for (int i = 0; i < arraylength(tab); ++i)
+ for (int i = 0; i < countof(tab); ++i)
if (!strncmp(name, tab[i].name, len))
return 1;
return 0;
diff --git a/c/c.c b/c/c.c
index a452a4a..1a18ad3 100644
--- a/c/c.c
+++ b/c/c.c
@@ -143,7 +143,7 @@ isdecltok(struct comp *cm)
kw(__typeof__), kw(typeof), kw(typeof_unqual),
#undef _
};
- return ((uint)tk.t-TKWBEGIN_) < arraylength(kws) && kws[tk.t-TKWBEGIN_];
+ return ((uint)tk.t-TKWBEGIN_) < countof(kws) && kws[tk.t-TKWBEGIN_];
}
}
@@ -158,7 +158,7 @@ struct tagged { /* a tagged type declaration */
struct span span;
};
static struct tagged envtaggedbuf[1<<7];
-static vec_of(struct tagged) envtagged = VINIT(envtaggedbuf, arraylength(envtaggedbuf));
+static vec_of(struct tagged) envtagged = VINIT(envtaggedbuf, countof(envtaggedbuf));
struct env {
struct env *up;
/* list of decls is implicitly envdecls[decl..ndecl] */
@@ -689,7 +689,7 @@ callexpr(struct comp *cm, const struct span *span_, const struct expr *callee)
union type ty = callee->ty;
const struct typedata *td = NULL;
struct expr argbuf[10];
- vec_of(struct expr) args = VINIT(argbuf, arraylength(argbuf));
+ vec_of(struct expr) args = VINIT(argbuf, countof(argbuf));
bool spanok = joinspan(&span.ex, span_->ex);
bool printsig = 0;
const struct builtin *builtin = NULL;
@@ -890,7 +890,7 @@ vaargexpr(struct comp *cm, struct span *span)
static inline int
tkprec(int tt)
{
- return ((uint)tt < arraylength(bintab)) ? bintab[tt].prec : 0;
+ return ((uint)tt < countof(bintab)) ? bintab[tt].prec : 0;
}
static struct expr initializer(struct comp *cm, union type *ty, enum evalmode ev,
@@ -944,7 +944,7 @@ Unary:
unops[nunop].span = tk.span;
unops[nunop].t0 = 0;
unops[nunop].tt = tk.t;
- if (++nunop >= arraylength(unops)) {
+ if (++nunop >= countof(unops)) {
ex = exprparse(cm, 999, NULL, 0);
break;
}
@@ -972,7 +972,7 @@ Unary:
}
unops[nunop].span = span;
unops[nunop].ty = decl.ty;
- if (++nunop >= arraylength(unops)) {
+ if (++nunop >= countof(unops)) {
ex = exprparse(cm, 999, NULL, 0);
break;
}
@@ -1418,7 +1418,7 @@ iniwrite(struct comp *cm, struct initparser *ip, uint off, uint bitsiz, uint bit
*init->tail = new;
init->tail = &new->next;
if (!bitsiz) for (uint i = off, end = i + typesize(ex->ty); i < end; ++i) {
- if (BSSIZE(end) > arraylength(init->zero)) break;
+ if (BSSIZE(end) > countof(init->zero)) break;
bsclr(init->zero, i);
}
}
@@ -1439,7 +1439,7 @@ iniwriterec(struct comp *cm, struct initparser *ip, uint off, struct expr *ex)
static struct initcur *
iniadvance(struct initparser *ip, struct initcur *c, const struct span *span)
{
- if (c - ip->buf >= arraylength(ip->buf) - 1)
+ if (c - ip->buf >= countof(ip->buf) - 1)
fatal(span, "too many nested initializers");
return c + 1;
}
@@ -1519,7 +1519,7 @@ Retry:
goto Retry;
} else if (objectp(targ) && targ.bits != ex.ty.bits) {
struct initcur *next = iniadvance(ip, ip->sub, &ex.span);
- if (ip->sub - ip->buf == arraylength(ip->buf) - 1)
+ if (ip->sub - ip->buf == countof(ip->buf) - 1)
fatal(&ex.span, "too many nested initializers");
++ip->sub->idx;
*next = (struct initcur) { targ, .off = ip->sub->off + off };
@@ -1705,7 +1705,7 @@ initializer(struct comp *cm, union type *ty, enum evalmode ev, bool globl,
return ex;
}
- assert(arraylength(res.zero) == 1);
+ assert(countof(res.zero) == 1);
if (ev != EVSTATICINI) {
memset(res.zero, 0xFF, sizeof res.zero);
}
@@ -1790,7 +1790,7 @@ initializer(struct comp *cm, union type *ty, enum evalmode ev, bool globl,
*ty = mkarrtype(typechild(*ty), ty->flag & TFCHLDQUAL, len);
}
- assert(arraylength(res.zero) == 1);
+ assert(countof(res.zero) == 1);
siz = typesize(*ty);
if (siz && siz <= 64)
res.zero->u &= ~0ull >> (64 - siz);
@@ -1810,7 +1810,7 @@ buildagg(struct comp *cm, enum typetag tt, const char *name, int id)
union type t;
struct span flexspan;
struct namedfield fbuf[32];
- vec_of(struct namedfield) fld = VINIT(fbuf, arraylength(fbuf));
+ vec_of(struct namedfield) fld = VINIT(fbuf, countof(fbuf));
struct typedata td = {tt};
bool isunion = tt == TYUNION;
const char *tag = isunion ? "union" : "struct";
@@ -2445,10 +2445,10 @@ decltypes(struct comp *cm, struct decllist *list, const char **name, struct span
if (!usingdeclparamtmp) {
usingdeclparamtmp = 1;
- vinit(&params, declparamtmp, arraylength(declparamtmp));
- vinit(&qual, declpqualtmp, arraylength(declpqualtmp));
- vinit(&names, declpnamestmp, arraylength(declpnamestmp));
- vinit(&spans, declpspanstmp, arraylength(declpspanstmp));
+ vinit(&params, declparamtmp, countof(declparamtmp));
+ vinit(&qual, declpqualtmp, countof(declpqualtmp));
+ vinit(&names, declpnamestmp, countof(declpnamestmp));
+ vinit(&spans, declpspanstmp, countof(declpspanstmp));
}
node.span = tk.span;
@@ -2527,7 +2527,7 @@ declarator(struct declstate *st, struct comp *cm, struct span span0) {
struct span namespan ={0};
if (!inidecltmp) {
inidecltmp = 1;
- for (int i = 0; i < arraylength(decltmp); ++i) {
+ for (int i = 0; i < countof(decltmp); ++i) {
decltmp[i].next = declfreelist;
declfreelist = &decltmp[i];
}
@@ -2859,7 +2859,7 @@ geninit(struct function *fn, union type t, union ref dst, const struct expr *src
uint align = typealign(t);
struct bitset azero[1] = {0};
- if (BSSIZE(siz) <= arraylength(ini->zero)) {
+ if (BSSIZE(siz) <= countof(ini->zero)) {
for (int i = 0; i < siz; i += align) {
for (int j = 0; j < align; ++j) {
if (bstest(ini->zero, i + j)) {
@@ -2868,9 +2868,9 @@ geninit(struct function *fn, union type t, union ref dst, const struct expr *src
}
}
}
- if (bscount(azero, arraylength(azero)) < 32) {
+ if (bscount(azero, countof(azero)) < 32) {
/* write individual zeros at non initialized gaps */
- for (uint i = 0; bsiter(&i, azero, arraylength(azero)) && i < siz; i += align) {
+ for (uint i = 0; bsiter(&i, azero, countof(azero)) && i < siz; i += align) {
adr = irbinop(fn, Oadd, KPTR, dst, mkref(RICON, i));
addinstr(fn, mkinstr(Ostore8 + ilog2(align), 0, .l = adr, .r = ZEROREF));
}
@@ -3166,7 +3166,7 @@ static union ref
condexprvalue(struct function *fn, const struct expr *ex, bool discard)
{
union ref refbuf[8];
- struct condphis phis = { ex->t == ECOND ? ex->ty : mktype(TYBOOL), VINIT(refbuf, arraylength(refbuf)) };
+ struct condphis phis = { ex->t == ECOND ? ex->ty : mktype(TYBOOL), VINIT(refbuf, countof(refbuf)) };
struct block *dst = newblk(fn);
condexprrec(fn, ex, discard ? NULL : &phis, dst);
useblk(fn, dst);
@@ -3191,7 +3191,7 @@ compilecall(struct function *fn, const struct expr *ex)
struct expr *sub = ex->sub;
const struct typedata *td = &typedata[sub[0].ty.dat];
struct instr insnsbuf[10];
- vec_of(struct instr) insns = VINIT(insnsbuf, arraylength(insnsbuf));
+ vec_of(struct instr) insns = VINIT(insnsbuf, countof(insnsbuf));
if (sub[0].t == ESYM && sub[0].sym->isbuiltin) {
return sub[0].sym->builtin->comp(fn, (struct expr *)ex, 0);
@@ -3701,7 +3701,7 @@ genswitch(struct comp *cm, struct function *fn, const struct expr *ex)
struct switchstmt *stsave = cm->switchstmt, st = {0};
enum irclass k = type2cls[scalartypet(ex->ty)];
struct swcase casebuf[8];
- vinit(&st.cases, casebuf, arraylength(casebuf));
+ vinit(&st.cases, casebuf, countof(casebuf));
assert(k);
end = newblk(fn);
diff --git a/c/lex.c b/c/lex.c
index 6a043e7..2068f14 100644
--- a/c/lex.c
+++ b/c/lex.c
@@ -54,7 +54,7 @@ identkeyword(struct token *tk, const char *s, int len)
#include "keywords.def"
#undef _
};
- int l = 0, h = arraylength(kwtab) - 1, i, cmp;
+ int l = 0, h = countof(kwtab) - 1, i, cmp;
tk->extwarn = 0;
tk->blue = 0;
@@ -87,7 +87,7 @@ fillchrbuf(struct lexer *lx)
{
const uchar *p = lx->dat + lx->idx;
int i = lx->chrbuf0, idx = lx->idx, c;
- int rem = arraylength(lx->chrbuf) - i;
+ int rem = countof(lx->chrbuf) - i;
assert(rem >= 0);
if (rem > 0) {
for (int j = 0; j < rem; ++j) {
@@ -98,7 +98,7 @@ fillchrbuf(struct lexer *lx)
lx->chrbuf0 = 0;
i = rem;
- for (; i < arraylength(lx->chrbuf); ++i) {
+ for (; i < countof(lx->chrbuf); ++i) {
int n;
/* skip backslash-newline */
while ((n = 2, (p[0] == '\\') & (p[1] == '\n')) || (ccopt.trigraph && !memcmp(p, "\?\?/\n", n = 4))) {
@@ -140,7 +140,7 @@ next(struct lexer *lx)
{
int c;
- if (lx->chrbuf0 >= arraylength(lx->chrbuf))
+ if (lx->chrbuf0 >= countof(lx->chrbuf))
fillchrbuf(lx);
lx->chridx = lx->chridxbuf[lx->chrbuf0];
c = lx->chrbuf[lx->chrbuf0];
@@ -152,8 +152,8 @@ next(struct lexer *lx)
static int
peek(struct lexer *lx, int off)
{
- assert(off < arraylength(lx->chrbuf));
- if (lx->chrbuf0 + off >= arraylength(lx->chrbuf))
+ assert(off < countof(lx->chrbuf));
+ if (lx->chrbuf0 + off >= countof(lx->chrbuf))
fillchrbuf(lx);
return lx->chrbuf[lx->chrbuf0 + off];
}
@@ -581,7 +581,7 @@ Begin:
int n = 0;
tmp[n++] = c;
while (isppnum(tmp[n-1], peek(lx, 0))) {
- assert(n < arraylength(tmp)-1 && "too big");
+ assert(n < countof(tmp)-1 && "too big");
tmp[n++] = next(lx);
}
tmp[n] = 0;
@@ -599,7 +599,7 @@ Begin:
int n = 0;
tmp[n++] = c;
while (!aissep(c = peek(lx, 0))) {
- assert(n < arraylength(tmp)-1 && "too big");
+ assert(n < countof(tmp)-1 && "too big");
tmp[n++] = next(lx);
}
tmp[n] = 0;
@@ -831,7 +831,7 @@ tokpaste(struct lexer *lx, struct token *dst, const struct token *l, const struc
};
struct span span = l->span;
- for (int i = 0; i < arraylength(tab); ++i)
+ for (int i = 0; i < countof(tab); ++i)
if (tab[i].s[0] == l->t && tab[i].s[1] == r->t)
return dst->t = tab[i].t, 1;
@@ -971,7 +971,7 @@ pushmacstk(struct lexer *lx, const struct span *span, const struct macrostack *m
{
struct macrostack *l = lx->macstk;
if (!l) l = mstk;
- else if ((++l == mstk+arraylength(mstk))) fatal(span, "macro depth limit reached");
+ else if ((++l == mstk+countof(mstk))) fatal(span, "macro depth limit reached");
l->rlist = m->rlist;
l->macno = m->macno;
l->idx = 0;
@@ -1079,7 +1079,7 @@ expandfnmacro(struct lexer *lx, struct span *span, struct macro *mac)
excessspan = tk.span;
toomany = 1;
} else if (i < mac->nparam - mac->variadic) {
- assert(i < arraylength(args) || "too many args in fn-like macro");
+ assert(i < countof(args) || "too many args in fn-like macro");
args[i].idx = cur;
args[i].n = len;
cur = argsbuf.n;
@@ -1295,7 +1295,7 @@ tkprec(int tt)
[TKLOGIOR] = 3,
['?'] = 2,
};
- if ((uint)tt < arraylength(tab))
+ if ((uint)tt < countof(tab))
return tab[tt] - 1;
return -1;
}
@@ -1314,7 +1314,7 @@ Unary:
switch (elex(lx, &tk)) {
case '-': case '~': case '!':
unops[nunop++] = tk.t;
- if (nunop >= arraylength(unops)) {
+ if (nunop >= countof(unops)) {
x = expr(lx, &xu, 999, ignore);
break;
}
@@ -1467,7 +1467,7 @@ static void
ppif(struct lexer *lx, const struct span *span)
{
vlong v = expr(lx, NULL, 0, 0);
- assert(nppcnd < arraylength(ppcndstk) && "too many nested #if");
+ assert(nppcnd < countof(ppcndstk) && "too many nested #if");
ppcndstk[nppcnd].ifspan = span->sl;
ppcndstk[nppcnd].filedepth = includedepth;
ppcndstk[nppcnd].cnd = v ? PPCNDTRUE : PPCNDFALSE;
@@ -1486,7 +1486,7 @@ ppifxdef(struct lexer *lx, bool defp, const struct span *span)
return;
}
if (!defp && lx->firstdirective) lx->inclguard = tk.s;
- assert(nppcnd < arraylength(ppcndstk) && "too many nested #if");
+ assert(nppcnd < countof(ppcndstk) && "too many nested #if");
ppcndstk[nppcnd].ifspan = span->sl;
ppcndstk[nppcnd].filedepth = includedepth;
ppcndstk[nppcnd].cnd = (findmac(tk.s) == NULL) ^ defp ? PPCNDTRUE : PPCNDFALSE;
@@ -1734,7 +1734,7 @@ findppcmd(const struct token *tk)
"undef",
"warning",
};
- int l = 0, h = arraylength(tab) - 1, i, cmp;
+ int l = 0, h = countof(tab) - 1, i, cmp;
const char *s = tk->s;
if (tk->t == TKWif) return PPIF;
@@ -1805,7 +1805,7 @@ lex(struct lexer *lx, struct token *tk_)
case PPIF: /* increment nesting level */
case PPIFDEF:
case PPIFNDEF:
- assert(nppcnd < arraylength(ppcndstk) && "too many nested #if");
+ assert(nppcnd < countof(ppcndstk) && "too many nested #if");
ppcndstk[nppcnd].ifspan = tk->span.sl;
ppcndstk[nppcnd].cnd = PPCNDTAKEN;
ppcndstk[nppcnd++].elsep = 0;
@@ -2006,7 +2006,7 @@ addpredefmacros(struct arena **tmparena)
case STDC23: tok_ver.s = "202311L"; break;
}
tok_ver.len = 7;
- for (int i = 0; i < arraylength(macs); ++i) {
+ for (int i = 0; i < countof(macs); ++i) {
macs[i].name = intern(macs[i].name);
putmac(&macs[i]);
}
@@ -2027,7 +2027,7 @@ addpredefmacros(struct arena **tmparena)
vpushn(&ppcmdline, "\0\0\0\0\0\0", 6);
lx->dat = f->p = ppcmdline.p;
lx->tmparena = tmparena;
- lx->chrbuf0 = arraylength(lx->chrbuf);
+ lx->chrbuf0 = countof(lx->chrbuf);
lx->firstdirective = 1;
while (!lx->eof) lex(lx, NULL);
}
@@ -2059,7 +2059,7 @@ initlexer(struct lexer *lx, const char **err, const char *file)
lx->dat = f->p;
lx->ndat = f->n;
lx->tmparena = &tmparena;
- lx->chrbuf0 = arraylength(lx->chrbuf);
+ lx->chrbuf0 = countof(lx->chrbuf);
lx->firstdirective = 1;
lx->nppcnd0 = nppcnd;
return getfilename(fileid) != file ? LXFILESEEN : LXOK;
diff --git a/common.h b/common.h
index 2b2bfd7..30b3cea 100644
--- a/common.h
+++ b/common.h
@@ -34,7 +34,7 @@ typedef unsigned uint;
#define static_assert(x) _Static_assert(x, #x)
#define in_range(x, Lo, Hi) ((uint) (x) - (Lo) <= (Hi) - (Lo)) /* lo <= x <= hi; lo > 0, hi > 0 */
#define alignup(x, A) (((x) + ((A) - 1)) & -(A))
-#define arraylength(a) (sizeof(a) / sizeof 0[a])
+#define countof(a) (sizeof(a) / sizeof 0[a])
enum { SPANFILEBITS = 10 };
struct span {
diff --git a/io.c b/io.c
index c697f0d..895f204 100644
--- a/io.c
+++ b/io.c
@@ -810,12 +810,12 @@ getpredeffile(struct memfile **pf, const char *name)
{
struct file *f;
struct fileuid uid;
- uint h, id, n = arraylength(fileht);
+ uint h, id, n = countof(fileht);
uid.dev = -11;
uid.ino = hashs(0, name);
for (id = h = uid.dev ^ uid.ino;; ++id) {
- id &= arraylength(fileht) - 1;
+ id &= countof(fileht) - 1;
f = fileht[id];
if (f && f->uid.dev == uid.dev && f->uid.ino == uid.ino) {
break;
@@ -842,7 +842,7 @@ openfile(const char **err, struct memfile **pf, const char *path)
struct stat st;
struct file *f;
struct fileuid uid;
- uint h, id, n = arraylength(fileht);
+ uint h, id, n = countof(fileht);
if (*path == '@' && path[1] == ':') {
uid.dev = -1;
@@ -855,7 +855,7 @@ openfile(const char **err, struct memfile **pf, const char *path)
uid.dev = st.st_dev, uid.ino = st.st_ino;
}
for (id = h = uid.dev ^ uid.ino;; ++id) {
- id &= arraylength(fileht) - 1;
+ id &= countof(fileht) - 1;
f = fileht[id];
if (f && f->uid.dev == uid.dev && f->uid.ino == uid.ino) {
break;
@@ -882,14 +882,14 @@ openfile(const char **err, struct memfile **pf, const char *path)
const char *
getfilename(int id)
{
- assert((uint)id < arraylength(fileht) && fileht[id]);
+ assert((uint)id < countof(fileht) && fileht[id]);
return fileht[id]->path;
}
struct memfile *
getfile(int id)
{
- assert((uint)id < arraylength(fileht) && fileht[id]);
+ assert((uint)id < countof(fileht) && fileht[id]);
return &fileht[id]->f;
}
@@ -898,7 +898,7 @@ addfileline(int id, uint off)
{
vec_of(uint) *lineoffs;
- assert((uint)id < arraylength(fileht) && fileht[id]);
+ assert((uint)id < countof(fileht) && fileht[id]);
lineoffs = (void *)&fileht[id]->lineoffs;
if (lineoffs->n && off > lineoffs->p[lineoffs->n-1])
vpush(lineoffs, off);
@@ -910,7 +910,7 @@ getfilepos(int *line, int *col, int id, uint off)
uint *offs, n;
int l = 0, h, i = 0;
- assert((uint)id < arraylength(fileht) && fileht[id]);
+ assert((uint)id < countof(fileht) && fileht[id]);
offs = fileht[id]->lineoffs.p;
n = fileht[id]->lineoffs.n;
h = n - 1;
@@ -930,7 +930,7 @@ getfilepos(int *line, int *col, int id, uint off)
bool
isoncefile(int id, const char **guard)
{
- assert(id < arraylength(fileht) && fileht[id]);
+ assert(id < countof(fileht) && fileht[id]);
*guard = fileht[id]->guardmac;
return fileht[id]->once;
}
@@ -938,7 +938,7 @@ isoncefile(int id, const char **guard)
void
markfileonce(int id, const char *guard)
{
- assert(id < arraylength(fileht) && fileht[id]);
+ assert(id < countof(fileht) && fileht[id]);
fileht[id]->once = 1;
fileht[id]->guardmac = guard;
}
@@ -946,21 +946,21 @@ markfileonce(int id, const char *guard)
void
markfileseen(int id)
{
- assert(id < arraylength(fileht) && fileht[id]);
+ assert(id < countof(fileht) && fileht[id]);
fileht[id]->seen = 1;
}
bool
isfileseen(int id)
{
- assert(id < arraylength(fileht) && fileht[id]);
+ assert(id < countof(fileht) && fileht[id]);
return fileht[id]->seen;
}
void
closefile(int id)
{
- assert(id < arraylength(fileht) && fileht[id]);
+ assert(id < countof(fileht) && fileht[id]);
mapclose(&fileht[id]->f);
}
diff --git a/ir/abi0.c b/ir/abi0.c
index 00090e3..1547722 100644
--- a/ir/abi0.c
+++ b/ir/abi0.c
@@ -253,7 +253,7 @@ void
abi0_call(struct function *fn, struct instr *ins, struct block *blk, int *curi)
{
union ref retmem;
- struct abiargsvec abiargs = {VINIT(abiargsbuf, arraylength(abiargsbuf))};
+ struct abiargsvec abiargs = {VINIT(abiargsbuf, countof(abiargsbuf))};
bool sretarghidden = 0;
int ni, nf, ns, vararg, nret = 0;
struct call *call = &calltab.p[ins->r.i];
@@ -363,7 +363,7 @@ abi0(struct function *fn)
{
uint nparam = typedata[fn->fnty.dat].nmemb;
const union type *paramty = typedata[fn->fnty.dat].param;
- struct abiargsvec abiargs = {VINIT(abiargsbuf, arraylength(abiargsbuf))};
+ struct abiargsvec abiargs = {VINIT(abiargsbuf, countof(abiargsbuf))};
int rvovar = -1;
int ni = 0, nf = 0, ns = 0, istart = 0;
uchar r2off;
diff --git a/ir/intrin.c b/ir/intrin.c
index 8c1a128..cd2865a 100644
--- a/ir/intrin.c
+++ b/ir/intrin.c
@@ -50,7 +50,7 @@ lowerintrin(struct function *fn)
{
struct block *blk = fn->entry;
static struct arg argsbuf[64];
- vec_of(struct arg) args = VINIT(argsbuf, arraylength(argsbuf));
+ vec_of(struct arg) args = VINIT(argsbuf, countof(argsbuf));
do {
for (int i = 0; i < blk->ins.n; ++i) {
@@ -58,7 +58,7 @@ lowerintrin(struct function *fn)
if (ins->op == Oarg)
vpush(&args, ((struct arg){ &ins->r, &ins->l }));
else if (ins->op == Ocall)
- vinit(&args, argsbuf, arraylength(argsbuf));
+ vinit(&args, argsbuf, countof(argsbuf));
else if (ins->op == Ointrin) {
int arg0 = i - args.n;
assert(calltab.p[ins->r.i].narg == args.n);
@@ -67,7 +67,7 @@ lowerintrin(struct function *fn)
delinstr(blk, arg0);
else
abi0_call(fn, ins, blk, &i);
- vinit(&args, argsbuf, arraylength(argsbuf));
+ vinit(&args, argsbuf, countof(argsbuf));
}
}
assert(args.n == 0);
diff --git a/ir/ir.c b/ir/ir.c
index 4a092b3..dbd6206 100644
--- a/ir/ir.c
+++ b/ir/ir.c
@@ -43,13 +43,13 @@ irinit(struct function *fn)
ninstr = 0;
instrfreelist = -1;
- vinit(&calltab, callsbuf, arraylength(callsbuf));
+ vinit(&calltab, callsbuf, countof(callsbuf));
for (int i = 0; i < phitab.n; ++i) xbfree(phitab.p[i]);
- vinit(&phitab, phisbuf, arraylength(phisbuf));
- if (!dattab.p) vinit(&dattab, datsbuf, arraylength(datsbuf));
- if (naddrht >= arraylength(addrht)/2)
+ vinit(&phitab, phisbuf, countof(phisbuf));
+ if (!dattab.p) vinit(&dattab, datsbuf, countof(datsbuf));
+ if (naddrht >= countof(addrht)/2)
memset(addrht, naddrht = 0, sizeof addrht);
- if (nconht >= arraylength(conht)/2)
+ if (nconht >= countof(conht)/2)
memset(conht, nconht = 0, sizeof conht);
if (!type2cls[TYINT]) {
for (int i = TYBOOL; i <= TYUVLONG; ++i) {
@@ -75,9 +75,9 @@ static int
addaddr(const struct addr *addr)
{
uint h = hashb(0, addr, sizeof *addr);
- uint i = h, n = arraylength(addrht);
+ uint i = h, n = countof(addrht);
for (;; ++i) {
- i &= arraylength(addrht) - 1;
+ i &= countof(addrht) - 1;
if (!addrht[i].base.bits && !addrht[i].index.bits) {
addrht[i] = *addr;
++naddrht;
@@ -93,10 +93,10 @@ static int
addcon(const struct xcon *con)
{
uint h = hashb(0, con, sizeof *con);
- uint i = h, n = arraylength(conht);
+ uint i = h, n = countof(conht);
assert(con->issym || con->isdat || con->cls);
for (;; ++i) {
- i &= arraylength(conht) - 1;
+ i &= countof(conht) - 1;
if (!conht[i].issym && !conht[i].isdat && !conht[i].cls) {
conht[i] = *con;
++nconht;
@@ -346,7 +346,7 @@ allocinstr(void)
t = instrfreelist;
memcpy(&instrfreelist, &instrtab[t], sizeof(int));
} else {
- assert(ninstr < arraylength(instrtab));
+ assert(ninstr < countof(instrtab));
t = ninstr++;
}
if (instruse[t] != instrusebuf[t])
@@ -361,11 +361,11 @@ adduse(struct block *ublk, int ui, union ref r) {
struct use user = { ublk, ui };
if (r.t != RTMP) return;
- if (instrnuse[r.i] < arraylength(instrusebuf[r.i])) {
+ if (instrnuse[r.i] < countof(instrusebuf[r.i])) {
instruse[r.i][instrnuse[r.i]++] = user;
- } else if (instrnuse[r.i] == arraylength(*instrusebuf)) {
+ } else if (instrnuse[r.i] == countof(*instrusebuf)) {
struct use *use = NULL;
- xbgrow(&use, arraylength(*instrusebuf) + 2);
+ xbgrow(&use, countof(*instrusebuf) + 2);
memcpy(use, instruse[r.i], sizeof(*instrusebuf));
use[instrnuse[r.i]++] = user;
instruse[r.i] = use;
@@ -389,7 +389,7 @@ deluse(struct block *ublk, int ui, union ref r) {
return 0;
Shrink:
- if (instrnuse[r.i] == arraylength(*instrusebuf) + 1) {
+ if (instrnuse[r.i] == countof(*instrusebuf) + 1) {
struct use *use = instruse[r.i];
instruse[r.i] = instrusebuf[r.i];
memcpy(instruse[r.i], use, sizeof *instrusebuf);
diff --git a/ir/optmem.c b/ir/optmem.c
index 3f5852b..7bd0d1a 100644
--- a/ir/optmem.c
+++ b/ir/optmem.c
@@ -234,7 +234,7 @@ mem2reg(struct function *fn)
FREQUIRE(FNUSE);
- if (fn->nblk <= 64 * arraylength(bsbuf[0])) {
+ if (fn->nblk <= 64 * countof(bsbuf[0])) {
sb.sealed = bsbuf[0];
sb.marked = bsbuf[1];
memset(bsbuf[0], 0, BSSIZE(fn->nblk) * sizeof *bsbuf[0]);
diff --git a/ir/regalloc.c b/ir/regalloc.c
index cf40266..9abd3c6 100644
--- a/ir/regalloc.c
+++ b/ir/regalloc.c
@@ -82,7 +82,7 @@ fixlive(struct function *fn)
struct bitset definedbuf[4] = {0};
struct bitset *defined = definedbuf;
- if (BSSIZE(ninstr) >= arraylength(definedbuf))
+ if (BSSIZE(ninstr) >= countof(definedbuf))
defined = xcalloc(sizeof *defined * BSSIZE(ninstr));
npendingphi = 0;
@@ -1241,7 +1241,7 @@ regalloc(struct function *fn)
fn->regusage = 0;
fn->stksiz = alignup(fn->stksiz, 8);
fn->isleaf = 1;
- vinit(&stkslotrefs, stkslotrefsbuf, arraylength(stkslotrefsbuf));
+ vinit(&stkslotrefs, stkslotrefsbuf, countof(stkslotrefsbuf));
/* put into reverse post order */
sortrpo(fn);
diff --git a/main.c b/main.c
index 8498a45..d38a0cd 100644
--- a/main.c
+++ b/main.c
@@ -113,7 +113,7 @@ optparse(char **args)
while ((arg = *++args)) {
if (*arg++ != '-' || !*arg) {
- assert(task.ninf < arraylength(task.inf) && "too many infiles");
+ assert(task.ninf < countof(task.inf) && "too many infiles");
task.inf[task.ninf] = arg[-1] != '-' ? arg-1 : "/dev/stdin";
task.inft[task.ninf] = ft ? ft : ftdetect(arg-1);
++task.ninf;
@@ -263,7 +263,7 @@ tempfile(const char *path, const char *ext)
static int cc1(const char *out, const char *in);
-static const char *tempobj[arraylength(task.inf)], *tempout;
+static const char *tempobj[countof(task.inf)], *tempout;
static void
mktemps(void) {
for (int i = 0; i < task.ninf; ++i) {
@@ -324,7 +324,7 @@ dolink(void)
static const char *cmdbuf[10];
pid_t p;
int wstat;
- vec_of(const char *) cmd = VINIT(cmdbuf, arraylength(cmdbuf));
+ vec_of(const char *) cmd = VINIT(cmdbuf, countof(cmdbuf));
/* TODO don't depend on external c compiler, find lib and runtime paths and
* invoke linker directly.. */
@@ -484,7 +484,7 @@ sysinclpaths(void)
"/usr/local/include",
"/usr/include"
};
- for (int i = 0; i < arraylength(paths); ++i)
+ for (int i = 0; i < countof(paths); ++i)
addinclpath(paths[i]);
}
diff --git a/type.c b/type.c
index dab0457..a18903c 100644
--- a/type.c
+++ b/type.c
@@ -66,9 +66,9 @@ tdequ(const struct typedata *a, const struct typedata *b)
static ushort
interntd(const struct typedata *td)
{
- uint h, i, n = arraylength(typedata);
+ uint h, i, n = countof(typedata);
for (i = h = hashtd(td); n--; ++i) {
- struct typedata *slot = &typedata[i &= arraylength(typedata) - 1];
+ struct typedata *slot = &typedata[i &= countof(typedata) - 1];
if (!slot->t) {
uint nmemb;
static struct arena *datarena;
@@ -185,7 +185,7 @@ completetype(const char *name, int id, struct typedata *td)
{
assert(td->t == TYENUM || td->t == TYSTRUCT || td->t == TYUNION);
td->id = id;
- assert(id < arraylength(ttypenames) && "too many tag types");
+ assert(id < countof(ttypenames) && "too many tag types");
if (ttypenames[id])
assert(ttypenames[id] == name && "bad redefn");
else