mirror of
https://github.com/netwide-assembler/nasm.git
synced 2025-10-10 00:25:06 -04:00
eval: drop passing (critical) as an argument
There is no point in passing (critical) as an argument when we alredy rely on a bunch of static variables. If eval needs to be reentrant, we should instead have something like "struct eval_state" and pass a pointer to that as an argument. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
This commit is contained in:
96
asm/eval.c
96
asm/eval.c
@@ -68,6 +68,7 @@ static int tempexpr_size;
|
|||||||
static struct tokenval *tokval; /* The current token */
|
static struct tokenval *tokval; /* The current token */
|
||||||
static int i; /* The t_type of tokval */
|
static int i; /* The t_type of tokval */
|
||||||
|
|
||||||
|
static int critical;
|
||||||
static void *scpriv;
|
static void *scpriv;
|
||||||
static int *opflags;
|
static int *opflags;
|
||||||
|
|
||||||
@@ -280,28 +281,28 @@ static expr *segment_part(expr * e)
|
|||||||
* | number
|
* | number
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static expr *rexp0(int), *rexp1(int), *rexp2(int), *rexp3(int);
|
static expr *rexp0(void), *rexp1(void), *rexp2(void), *rexp3(void);
|
||||||
|
|
||||||
static expr *expr0(int), *expr1(int), *expr2(int), *expr3(int);
|
static expr *expr0(void), *expr1(void), *expr2(void), *expr3(void);
|
||||||
static expr *expr4(int), *expr5(int), *expr6(int);
|
static expr *expr4(void), *expr5(void), *expr6(void);
|
||||||
|
|
||||||
/* This inline is a placeholder for the root of the basic expression */
|
/* This inline is a placeholder for the root of the basic expression */
|
||||||
static inline expr *bexpr(int critical)
|
static inline expr *bexpr(void)
|
||||||
{
|
{
|
||||||
return rexp0(critical);
|
return rexp0();
|
||||||
}
|
}
|
||||||
|
|
||||||
static expr *rexp0(int critical)
|
static expr *rexp0(void)
|
||||||
{
|
{
|
||||||
expr *e, *f;
|
expr *e, *f;
|
||||||
|
|
||||||
e = rexp1(critical);
|
e = rexp1();
|
||||||
if (!e)
|
if (!e)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
while (i == TOKEN_DBL_OR) {
|
while (i == TOKEN_DBL_OR) {
|
||||||
i = scan(scpriv, tokval);
|
i = scan(scpriv, tokval);
|
||||||
f = rexp1(critical);
|
f = rexp1();
|
||||||
if (!f)
|
if (!f)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (!(is_simple(e) || is_just_unknown(e)) ||
|
if (!(is_simple(e) || is_just_unknown(e)) ||
|
||||||
@@ -318,17 +319,17 @@ static expr *rexp0(int critical)
|
|||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
static expr *rexp1(int critical)
|
static expr *rexp1(void)
|
||||||
{
|
{
|
||||||
expr *e, *f;
|
expr *e, *f;
|
||||||
|
|
||||||
e = rexp2(critical);
|
e = rexp2();
|
||||||
if (!e)
|
if (!e)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
while (i == TOKEN_DBL_XOR) {
|
while (i == TOKEN_DBL_XOR) {
|
||||||
i = scan(scpriv, tokval);
|
i = scan(scpriv, tokval);
|
||||||
f = rexp2(critical);
|
f = rexp2();
|
||||||
if (!f)
|
if (!f)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (!(is_simple(e) || is_just_unknown(e)) ||
|
if (!(is_simple(e) || is_just_unknown(e)) ||
|
||||||
@@ -345,16 +346,16 @@ static expr *rexp1(int critical)
|
|||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
static expr *rexp2(int critical)
|
static expr *rexp2(void)
|
||||||
{
|
{
|
||||||
expr *e, *f;
|
expr *e, *f;
|
||||||
|
|
||||||
e = rexp3(critical);
|
e = rexp3();
|
||||||
if (!e)
|
if (!e)
|
||||||
return NULL;
|
return NULL;
|
||||||
while (i == TOKEN_DBL_AND) {
|
while (i == TOKEN_DBL_AND) {
|
||||||
i = scan(scpriv, tokval);
|
i = scan(scpriv, tokval);
|
||||||
f = rexp3(critical);
|
f = rexp3();
|
||||||
if (!f)
|
if (!f)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (!(is_simple(e) || is_just_unknown(e)) ||
|
if (!(is_simple(e) || is_just_unknown(e)) ||
|
||||||
@@ -370,12 +371,12 @@ static expr *rexp2(int critical)
|
|||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
static expr *rexp3(int critical)
|
static expr *rexp3(void)
|
||||||
{
|
{
|
||||||
expr *e, *f;
|
expr *e, *f;
|
||||||
int64_t v;
|
int64_t v;
|
||||||
|
|
||||||
e = expr0(critical);
|
e = expr0();
|
||||||
if (!e)
|
if (!e)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@@ -384,7 +385,7 @@ static expr *rexp3(int critical)
|
|||||||
i == TOKEN_LEG) {
|
i == TOKEN_LEG) {
|
||||||
int j = i;
|
int j = i;
|
||||||
i = scan(scpriv, tokval);
|
i = scan(scpriv, tokval);
|
||||||
f = expr0(critical);
|
f = expr0();
|
||||||
if (!f)
|
if (!f)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@@ -435,17 +436,17 @@ static expr *rexp3(int critical)
|
|||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
static expr *expr0(int critical)
|
static expr *expr0(void)
|
||||||
{
|
{
|
||||||
expr *e, *f;
|
expr *e, *f;
|
||||||
|
|
||||||
e = expr1(critical);
|
e = expr1();
|
||||||
if (!e)
|
if (!e)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
while (i == '|') {
|
while (i == '|') {
|
||||||
i = scan(scpriv, tokval);
|
i = scan(scpriv, tokval);
|
||||||
f = expr1(critical);
|
f = expr1();
|
||||||
if (!f)
|
if (!f)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (!(is_simple(e) || is_just_unknown(e)) ||
|
if (!(is_simple(e) || is_just_unknown(e)) ||
|
||||||
@@ -461,17 +462,17 @@ static expr *expr0(int critical)
|
|||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
static expr *expr1(int critical)
|
static expr *expr1(void)
|
||||||
{
|
{
|
||||||
expr *e, *f;
|
expr *e, *f;
|
||||||
|
|
||||||
e = expr2(critical);
|
e = expr2();
|
||||||
if (!e)
|
if (!e)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
while (i == '^') {
|
while (i == '^') {
|
||||||
i = scan(scpriv, tokval);
|
i = scan(scpriv, tokval);
|
||||||
f = expr2(critical);
|
f = expr2();
|
||||||
if (!f)
|
if (!f)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (!(is_simple(e) || is_just_unknown(e)) ||
|
if (!(is_simple(e) || is_just_unknown(e)) ||
|
||||||
@@ -487,17 +488,17 @@ static expr *expr1(int critical)
|
|||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
static expr *expr2(int critical)
|
static expr *expr2(void)
|
||||||
{
|
{
|
||||||
expr *e, *f;
|
expr *e, *f;
|
||||||
|
|
||||||
e = expr3(critical);
|
e = expr3();
|
||||||
if (!e)
|
if (!e)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
while (i == '&') {
|
while (i == '&') {
|
||||||
i = scan(scpriv, tokval);
|
i = scan(scpriv, tokval);
|
||||||
f = expr3(critical);
|
f = expr3();
|
||||||
if (!f)
|
if (!f)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (!(is_simple(e) || is_just_unknown(e)) ||
|
if (!(is_simple(e) || is_just_unknown(e)) ||
|
||||||
@@ -513,18 +514,18 @@ static expr *expr2(int critical)
|
|||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
static expr *expr3(int critical)
|
static expr *expr3(void)
|
||||||
{
|
{
|
||||||
expr *e, *f;
|
expr *e, *f;
|
||||||
|
|
||||||
e = expr4(critical);
|
e = expr4();
|
||||||
if (!e)
|
if (!e)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
while (i == TOKEN_SHL || i == TOKEN_SHR || i == TOKEN_SAR) {
|
while (i == TOKEN_SHL || i == TOKEN_SHR || i == TOKEN_SAR) {
|
||||||
int j = i;
|
int j = i;
|
||||||
i = scan(scpriv, tokval);
|
i = scan(scpriv, tokval);
|
||||||
f = expr4(critical);
|
f = expr4();
|
||||||
if (!f)
|
if (!f)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (!(is_simple(e) || is_just_unknown(e)) ||
|
if (!(is_simple(e) || is_just_unknown(e)) ||
|
||||||
@@ -552,17 +553,17 @@ static expr *expr3(int critical)
|
|||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
static expr *expr4(int critical)
|
static expr *expr4(void)
|
||||||
{
|
{
|
||||||
expr *e, *f;
|
expr *e, *f;
|
||||||
|
|
||||||
e = expr5(critical);
|
e = expr5();
|
||||||
if (!e)
|
if (!e)
|
||||||
return NULL;
|
return NULL;
|
||||||
while (i == '+' || i == '-') {
|
while (i == '+' || i == '-') {
|
||||||
int j = i;
|
int j = i;
|
||||||
i = scan(scpriv, tokval);
|
i = scan(scpriv, tokval);
|
||||||
f = expr5(critical);
|
f = expr5();
|
||||||
if (!f)
|
if (!f)
|
||||||
return NULL;
|
return NULL;
|
||||||
switch (j) {
|
switch (j) {
|
||||||
@@ -577,18 +578,18 @@ static expr *expr4(int critical)
|
|||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
static expr *expr5(int critical)
|
static expr *expr5(void)
|
||||||
{
|
{
|
||||||
expr *e, *f;
|
expr *e, *f;
|
||||||
|
|
||||||
e = expr6(critical);
|
e = expr6();
|
||||||
if (!e)
|
if (!e)
|
||||||
return NULL;
|
return NULL;
|
||||||
while (i == '*' || i == '/' || i == '%' ||
|
while (i == '*' || i == '/' || i == '%' ||
|
||||||
i == TOKEN_SDIV || i == TOKEN_SMOD) {
|
i == TOKEN_SDIV || i == TOKEN_SMOD) {
|
||||||
int j = i;
|
int j = i;
|
||||||
i = scan(scpriv, tokval);
|
i = scan(scpriv, tokval);
|
||||||
f = expr6(critical);
|
f = expr6();
|
||||||
if (!f)
|
if (!f)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (j != '*' && (!(is_simple(e) || is_just_unknown(e)) ||
|
if (j != '*' && (!(is_simple(e) || is_just_unknown(e)) ||
|
||||||
@@ -777,7 +778,7 @@ static int64_t eval_ifunc(int64_t val, enum ifunc func)
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
static expr *expr6(int critical)
|
static expr *expr6(void)
|
||||||
{
|
{
|
||||||
int32_t type;
|
int32_t type;
|
||||||
expr *e;
|
expr *e;
|
||||||
@@ -795,18 +796,18 @@ static expr *expr6(int critical)
|
|||||||
switch (i) {
|
switch (i) {
|
||||||
case '-':
|
case '-':
|
||||||
i = scan(scpriv, tokval);
|
i = scan(scpriv, tokval);
|
||||||
e = expr6(critical);
|
e = expr6();
|
||||||
if (!e)
|
if (!e)
|
||||||
return NULL;
|
return NULL;
|
||||||
return scalar_mult(e, -1L, false);
|
return scalar_mult(e, -1L, false);
|
||||||
|
|
||||||
case '+':
|
case '+':
|
||||||
i = scan(scpriv, tokval);
|
i = scan(scpriv, tokval);
|
||||||
return expr6(critical);
|
return expr6();
|
||||||
|
|
||||||
case '~':
|
case '~':
|
||||||
i = scan(scpriv, tokval);
|
i = scan(scpriv, tokval);
|
||||||
e = expr6(critical);
|
e = expr6();
|
||||||
if (!e)
|
if (!e)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (is_just_unknown(e))
|
if (is_just_unknown(e))
|
||||||
@@ -820,7 +821,7 @@ static expr *expr6(int critical)
|
|||||||
|
|
||||||
case '!':
|
case '!':
|
||||||
i = scan(scpriv, tokval);
|
i = scan(scpriv, tokval);
|
||||||
e = expr6(critical);
|
e = expr6();
|
||||||
if (!e)
|
if (!e)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (is_just_unknown(e))
|
if (is_just_unknown(e))
|
||||||
@@ -836,7 +837,7 @@ static expr *expr6(int critical)
|
|||||||
{
|
{
|
||||||
enum ifunc func = tokval->t_integer;
|
enum ifunc func = tokval->t_integer;
|
||||||
i = scan(scpriv, tokval);
|
i = scan(scpriv, tokval);
|
||||||
e = expr6(critical);
|
e = expr6();
|
||||||
if (!e)
|
if (!e)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (is_just_unknown(e))
|
if (is_just_unknown(e))
|
||||||
@@ -851,7 +852,7 @@ static expr *expr6(int critical)
|
|||||||
|
|
||||||
case TOKEN_SEG:
|
case TOKEN_SEG:
|
||||||
i = scan(scpriv, tokval);
|
i = scan(scpriv, tokval);
|
||||||
e = expr6(critical);
|
e = expr6();
|
||||||
if (!e)
|
if (!e)
|
||||||
return NULL;
|
return NULL;
|
||||||
e = segment_part(e);
|
e = segment_part(e);
|
||||||
@@ -871,7 +872,7 @@ static expr *expr6(int critical)
|
|||||||
|
|
||||||
case '(':
|
case '(':
|
||||||
i = scan(scpriv, tokval);
|
i = scan(scpriv, tokval);
|
||||||
e = bexpr(critical);
|
e = bexpr();
|
||||||
if (!e)
|
if (!e)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (i != ')') {
|
if (i != ')') {
|
||||||
@@ -972,7 +973,7 @@ static expr *expr6(int critical)
|
|||||||
}
|
}
|
||||||
|
|
||||||
expr *evaluate(scanner sc, void *scprivate, struct tokenval *tv,
|
expr *evaluate(scanner sc, void *scprivate, struct tokenval *tv,
|
||||||
int *fwref, int critical, struct eval_hints *hints)
|
int *fwref, int crit, struct eval_hints *hints)
|
||||||
{
|
{
|
||||||
expr *e;
|
expr *e;
|
||||||
expr *f = NULL;
|
expr *f = NULL;
|
||||||
@@ -983,8 +984,7 @@ expr *evaluate(scanner sc, void *scprivate, struct tokenval *tv,
|
|||||||
if (hint)
|
if (hint)
|
||||||
hint->type = EAH_NOHINT;
|
hint->type = EAH_NOHINT;
|
||||||
|
|
||||||
critical &= ~CRITICAL;
|
critical = crit & ~CRITICAL;
|
||||||
|
|
||||||
scan = sc;
|
scan = sc;
|
||||||
scpriv = scprivate;
|
scpriv = scprivate;
|
||||||
tokval = tv;
|
tokval = tv;
|
||||||
@@ -998,13 +998,13 @@ expr *evaluate(scanner sc, void *scprivate, struct tokenval *tv,
|
|||||||
while (ntempexprs) /* initialize temporary storage */
|
while (ntempexprs) /* initialize temporary storage */
|
||||||
nasm_free(tempexprs[--ntempexprs]);
|
nasm_free(tempexprs[--ntempexprs]);
|
||||||
|
|
||||||
e = bexpr(critical);
|
e = bexpr();
|
||||||
if (!e)
|
if (!e)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (i == TOKEN_WRT) {
|
if (i == TOKEN_WRT) {
|
||||||
i = scan(scpriv, tokval); /* eat the WRT */
|
i = scan(scpriv, tokval); /* eat the WRT */
|
||||||
f = expr6(critical);
|
f = expr6();
|
||||||
if (!f)
|
if (!f)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user