mirror of
https://github.com/netwide-assembler/nasm.git
synced 2024-11-27 08:10:07 +08:00
stdscan: switch to stdscan_get/set routines
Instead of manipulating stdscan buffer pointer directly we switch to a routine interface. This allow us to unify stdscan access: ie caller should "talk" to stdscan via stdscan_get/set routines. Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
This commit is contained in:
parent
bafd877d48
commit
917117ff69
4
nasm.c
4
nasm.c
@ -1365,7 +1365,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
|
||||
}
|
||||
case D_ABSOLUTE: /* [ABSOLUTE address] */
|
||||
stdscan_reset();
|
||||
stdscan_bufptr = value;
|
||||
stdscan_set(value);
|
||||
tokval.t_type = TOKEN_INVALID;
|
||||
e = evaluate(stdscan, NULL, &tokval, NULL, pass2,
|
||||
nasm_error, NULL);
|
||||
@ -1470,7 +1470,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
|
||||
break;
|
||||
case D_DEFAULT: /* [DEFAULT] */
|
||||
stdscan_reset();
|
||||
stdscan_bufptr = value;
|
||||
stdscan_set(value);
|
||||
tokval.t_type = TOKEN_INVALID;
|
||||
if (stdscan(NULL, &tokval) == TOKEN_SPECIAL) {
|
||||
switch ((int)tokval.t_integer) {
|
||||
|
@ -299,7 +299,7 @@ static void aout_deflabel(char *name, int32_t segment, int64_t offset,
|
||||
while (*p && nasm_isspace(*p))
|
||||
p++;
|
||||
stdscan_reset();
|
||||
stdscan_bufptr = p;
|
||||
stdscan_set(p);
|
||||
tokval.t_type = TOKEN_INVALID;
|
||||
e = evaluate(stdscan, NULL, &tokval, NULL, 1, nasm_error, NULL);
|
||||
if (e) {
|
||||
@ -379,7 +379,7 @@ static void aout_deflabel(char *name, int32_t segment, int64_t offset,
|
||||
struct tokenval tokval;
|
||||
expr *e;
|
||||
int fwd = false;
|
||||
char *saveme = stdscan_bufptr; /* bugfix? fbk 8/10/00 */
|
||||
char *saveme = stdscan_get(); /* bugfix? fbk 8/10/00 */
|
||||
|
||||
if (!bsd) {
|
||||
nasm_error(ERR_NONFATAL, "Linux a.out does not support"
|
||||
@ -393,7 +393,7 @@ static void aout_deflabel(char *name, int32_t segment, int64_t offset,
|
||||
*/
|
||||
sym->type |= SYM_WITH_SIZE;
|
||||
stdscan_reset();
|
||||
stdscan_bufptr = special + n;
|
||||
stdscan_set(special + n);
|
||||
tokval.t_type = TOKEN_INVALID;
|
||||
e = evaluate(stdscan, NULL, &tokval, &fwd, 0, nasm_error,
|
||||
NULL);
|
||||
@ -409,7 +409,7 @@ static void aout_deflabel(char *name, int32_t segment, int64_t offset,
|
||||
sym->size = reloc_value(e);
|
||||
}
|
||||
}
|
||||
stdscan_bufptr = saveme; /* bugfix? fbk 8/10/00 */
|
||||
stdscan_set(saveme); /* bugfix? fbk 8/10/00 */
|
||||
}
|
||||
special_used = true;
|
||||
}
|
||||
|
@ -152,8 +152,6 @@ static struct Reloc {
|
||||
struct Section *target;
|
||||
} *relocs, **reloctail;
|
||||
|
||||
extern char *stdscan_bufptr;
|
||||
|
||||
static uint8_t format_mode; /* 0 = original bin, 1 = extended bin */
|
||||
static int32_t current_section; /* only really needed if format_mode = 0 */
|
||||
static uint64_t origin;
|
||||
@ -985,7 +983,7 @@ static int bin_read_attribute(char **line, int *attribute,
|
||||
|
||||
/* Read and evaluate the expression. */
|
||||
stdscan_reset();
|
||||
stdscan_bufptr = exp;
|
||||
stdscan_set(exp);
|
||||
tokval.t_type = TOKEN_INVALID;
|
||||
e = evaluate(stdscan, NULL, &tokval, NULL, 1, nasm_error, NULL);
|
||||
if (e) {
|
||||
@ -1292,7 +1290,7 @@ static int bin_directive(enum directives directive, char *args, int pass)
|
||||
expr *e;
|
||||
|
||||
stdscan_reset();
|
||||
stdscan_bufptr = args;
|
||||
stdscan_set(args);
|
||||
tokval.t_type = TOKEN_INVALID;
|
||||
e = evaluate(stdscan, NULL, &tokval, NULL, 1, nasm_error, NULL);
|
||||
if (e) {
|
||||
|
@ -495,7 +495,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset,
|
||||
while (*p && nasm_isspace(*p))
|
||||
p++;
|
||||
stdscan_reset();
|
||||
stdscan_bufptr = p;
|
||||
stdscan_set(p);
|
||||
tokval.t_type = TOKEN_INVALID;
|
||||
e = evaluate(stdscan, NULL, &tokval, NULL, 1, nasm_error, NULL);
|
||||
if (e) {
|
||||
@ -630,7 +630,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset,
|
||||
struct tokenval tokval;
|
||||
expr *e;
|
||||
int fwd = 0;
|
||||
char *saveme = stdscan_bufptr; /* bugfix? fbk 8/10/00 */
|
||||
char *saveme = stdscan_get(); /* bugfix? fbk 8/10/00 */
|
||||
|
||||
while (special[n] && nasm_isspace(special[n]))
|
||||
n++;
|
||||
@ -639,7 +639,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset,
|
||||
* evaluate it.
|
||||
*/
|
||||
stdscan_reset();
|
||||
stdscan_bufptr = special + n;
|
||||
stdscan_set(special + n);
|
||||
tokval.t_type = TOKEN_INVALID;
|
||||
e = evaluate(stdscan, NULL, &tokval, &fwd, 0, nasm_error,
|
||||
NULL);
|
||||
@ -654,7 +654,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset,
|
||||
else
|
||||
sym->size = reloc_value(e);
|
||||
}
|
||||
stdscan_bufptr = saveme; /* bugfix? fbk 8/10/00 */
|
||||
stdscan_set(saveme); /* bugfix? fbk 8/10/00 */
|
||||
}
|
||||
special_used = true;
|
||||
}
|
||||
|
@ -499,7 +499,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset,
|
||||
while (*p && nasm_isspace(*p))
|
||||
p++;
|
||||
stdscan_reset();
|
||||
stdscan_bufptr = p;
|
||||
stdscan_set(p);
|
||||
tokval.t_type = TOKEN_INVALID;
|
||||
e = evaluate(stdscan, NULL, &tokval, NULL, 1, nasm_error, NULL);
|
||||
if (e) {
|
||||
@ -635,7 +635,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset,
|
||||
struct tokenval tokval;
|
||||
expr *e;
|
||||
int fwd = 0;
|
||||
char *saveme = stdscan_bufptr; /* bugfix? fbk 8/10/00 */
|
||||
char *saveme = stdscan_get(); /* bugfix? fbk 8/10/00 */
|
||||
|
||||
while (special[n] && nasm_isspace(special[n]))
|
||||
n++;
|
||||
@ -644,7 +644,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset,
|
||||
* evaluate it.
|
||||
*/
|
||||
stdscan_reset();
|
||||
stdscan_bufptr = special + n;
|
||||
stdscan_set(special + n);
|
||||
tokval.t_type = TOKEN_INVALID;
|
||||
e = evaluate(stdscan, NULL, &tokval, &fwd, 0, nasm_error,
|
||||
NULL);
|
||||
@ -659,7 +659,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset,
|
||||
else
|
||||
sym->size = reloc_value(e);
|
||||
}
|
||||
stdscan_bufptr = saveme; /* bugfix? fbk 8/10/00 */
|
||||
stdscan_set(saveme); /* bugfix? fbk 8/10/00 */
|
||||
}
|
||||
special_used = true;
|
||||
}
|
||||
|
@ -966,7 +966,7 @@ static void obj_deflabel(char *name, int32_t segment,
|
||||
struct tokenval tokval;
|
||||
|
||||
stdscan_reset();
|
||||
stdscan_bufptr = special;
|
||||
stdscan_set(special);
|
||||
tokval.t_type = TOKEN_INVALID;
|
||||
e = evaluate(stdscan, NULL, &tokval, NULL, 1, nasm_error, NULL);
|
||||
if (e) {
|
||||
@ -976,7 +976,7 @@ static void obj_deflabel(char *name, int32_t segment,
|
||||
else
|
||||
ext->commonelem = reloc_value(e);
|
||||
}
|
||||
special = stdscan_bufptr;
|
||||
special = stdscan_get();
|
||||
} else {
|
||||
nasm_error(ERR_NONFATAL,
|
||||
"`%s': element-size specifications only"
|
||||
|
10
parser.c
10
parser.c
@ -205,7 +205,7 @@ restart_parse:
|
||||
result->forw_ref = false;
|
||||
|
||||
stdscan_reset();
|
||||
stdscan_bufptr = buffer;
|
||||
stdscan_set(buffer);
|
||||
i = stdscan(NULL, &tokval);
|
||||
|
||||
result->label = NULL; /* Assume no label */
|
||||
@ -417,12 +417,12 @@ restart_parse:
|
||||
if (i && i != ',')
|
||||
i = stdscan(NULL, &tokval);
|
||||
} else if (i == '-' || i == '+') {
|
||||
char *save = stdscan_bufptr;
|
||||
char *save = stdscan_get();
|
||||
int token = i;
|
||||
sign = (i == '-') ? -1 : 1;
|
||||
i = stdscan(NULL, &tokval);
|
||||
if (i != TOKEN_FLOAT) {
|
||||
stdscan_bufptr = save;
|
||||
stdscan_set(save);
|
||||
i = tokval.t_type = token;
|
||||
goto is_expression;
|
||||
} else {
|
||||
@ -952,9 +952,9 @@ static int is_comma_next(void)
|
||||
int i;
|
||||
struct tokenval tv;
|
||||
|
||||
p = stdscan_bufptr;
|
||||
p = stdscan_get();
|
||||
i = stdscan(NULL, &tv);
|
||||
stdscan_bufptr = p;
|
||||
stdscan_set(p);
|
||||
return (i == ',' || i == ';' || !i);
|
||||
}
|
||||
|
||||
|
12
stdscan.c
12
stdscan.c
@ -50,10 +50,21 @@
|
||||
* formats. It keeps a succession of temporary-storage strings in
|
||||
* stdscan_tempstorage, which can be cleared using stdscan_reset.
|
||||
*/
|
||||
static char *stdscan_bufptr = NULL;
|
||||
static char **stdscan_tempstorage = NULL;
|
||||
static int stdscan_tempsize = 0, stdscan_templen = 0;
|
||||
#define STDSCAN_TEMP_DELTA 256
|
||||
|
||||
void stdscan_set(char *str)
|
||||
{
|
||||
stdscan_bufptr = str;
|
||||
}
|
||||
|
||||
char *stdscan_get(void)
|
||||
{
|
||||
return stdscan_bufptr;
|
||||
}
|
||||
|
||||
static void stdscan_pop(void)
|
||||
{
|
||||
nasm_free(stdscan_tempstorage[--stdscan_templen]);
|
||||
@ -94,7 +105,6 @@ static char *stdscan_copy(char *p, int len)
|
||||
return text;
|
||||
}
|
||||
|
||||
char *stdscan_bufptr = NULL;
|
||||
int stdscan(void *private_data, struct tokenval *tv)
|
||||
{
|
||||
char ourcopy[MAX_KEYWORD + 1], *r, *s;
|
||||
|
@ -37,10 +37,10 @@
|
||||
|
||||
#ifndef NASM_STDSCAN_H
|
||||
#define NASM_STDSCAN_H
|
||||
/*
|
||||
* Standard scanner.
|
||||
*/
|
||||
extern char *stdscan_bufptr;
|
||||
|
||||
/* Standard scanner */
|
||||
void stdscan_set(char *str);
|
||||
char *stdscan_get(void);
|
||||
void stdscan_reset(void);
|
||||
int stdscan(void *private_data, struct tokenval *tv);
|
||||
int nasm_token_hash(const char *token, struct tokenval *tv);
|
||||
|
Loading…
Reference in New Issue
Block a user