mirror of
https://github.com/yasm/yasm
synced 2026-08-26 22:26:05 -04:00
Now that the gas preproc supports .rept, remove it from the gas parser.
svn path=/trunk/yasm/; revision=2266
This commit is contained in:
parent
6ede18e881
commit
fd03e1eef5
4 changed files with 1 additions and 269 deletions
|
|
@ -486,53 +486,6 @@ dir_line(yasm_parser_gas *parser_gas, unsigned int param)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/* Macro directives */
|
||||
|
||||
static yasm_bytecode *
|
||||
dir_rept(yasm_parser_gas *parser_gas, unsigned int param)
|
||||
{
|
||||
yasm_intnum *intn;
|
||||
yasm_expr *e = parse_expr(parser_gas);
|
||||
|
||||
if (!e) {
|
||||
yasm_error_set(YASM_ERROR_SYNTAX,
|
||||
N_("expression expected after `%s'"),
|
||||
".rept");
|
||||
return NULL;
|
||||
}
|
||||
intn = yasm_expr_get_intnum(&e, 0);
|
||||
|
||||
if (!intn) {
|
||||
yasm_error_set(YASM_ERROR_NOT_ABSOLUTE,
|
||||
N_("rept expression not absolute"));
|
||||
} else if (yasm_intnum_sign(intn) < 0) {
|
||||
yasm_error_set(YASM_ERROR_VALUE,
|
||||
N_("rept expression is negative"));
|
||||
} else {
|
||||
gas_rept *rept = yasm_xmalloc(sizeof(gas_rept));
|
||||
STAILQ_INIT(&rept->lines);
|
||||
rept->startline = cur_line;
|
||||
rept->numrept = yasm_intnum_get_uint(intn);
|
||||
rept->numdone = 0;
|
||||
rept->line = NULL;
|
||||
rept->linepos = 0;
|
||||
rept->ended = 0;
|
||||
rept->oldbuf = NULL;
|
||||
rept->oldbuflen = 0;
|
||||
rept->oldbufpos = 0;
|
||||
parser_gas->rept = rept;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static yasm_bytecode *
|
||||
dir_endr(yasm_parser_gas *parser_gas, unsigned int param)
|
||||
{
|
||||
/* Shouldn't ever get here unless we didn't get a DIR_REPT first */
|
||||
yasm_error_set(YASM_ERROR_SYNTAX, N_("endr without matching rept"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Alignment directives */
|
||||
|
||||
static yasm_bytecode *
|
||||
|
|
@ -1715,9 +1668,6 @@ static dir_lookup dirs_static[] = {
|
|||
{".data", dir_data_section, 0, INITIAL},
|
||||
{".text", dir_text_section, 0, INITIAL},
|
||||
{".section", dir_section, 0, SECTION_DIRECTIVE},
|
||||
/* macro directives */
|
||||
{".rept", dir_rept, 0, INITIAL},
|
||||
{".endr", dir_endr, 0, INITIAL},
|
||||
/* empty space/fill directives */
|
||||
{".skip", dir_skip, 0, INITIAL},
|
||||
{".space", dir_skip, 0, INITIAL},
|
||||
|
|
|
|||
|
|
@ -71,8 +71,6 @@ gas_parser_do_parse(yasm_object *object, yasm_preproc *pp,
|
|||
|
||||
parser_gas.state = INITIAL;
|
||||
|
||||
parser_gas.rept = NULL;
|
||||
|
||||
for (i=0; i<10; i++)
|
||||
parser_gas.local[i] = 0;
|
||||
|
||||
|
|
@ -83,12 +81,6 @@ gas_parser_do_parse(yasm_object *object, yasm_preproc *pp,
|
|||
|
||||
gas_parser_parse(&parser_gas);
|
||||
|
||||
/* Check for ending inside a rept */
|
||||
if (parser_gas.rept) {
|
||||
yasm_error_set(YASM_ERROR_SYNTAX, N_("rept without matching endr"));
|
||||
yasm_errwarn_propagate(errwarns, parser_gas.rept->startline);
|
||||
}
|
||||
|
||||
/* Check for ending inside a comment */
|
||||
if (parser_gas.state == COMMENT) {
|
||||
yasm_warn_set(YASM_WARN_GENERAL, N_("end of file in comment"));
|
||||
|
|
|
|||
|
|
@ -64,26 +64,6 @@ typedef union {
|
|||
} yystype;
|
||||
#define YYSTYPE yystype
|
||||
|
||||
typedef struct gas_rept_line {
|
||||
STAILQ_ENTRY(gas_rept_line) link;
|
||||
YYCTYPE *data; /* line characters */
|
||||
size_t len; /* length of data */
|
||||
} gas_rept_line;
|
||||
|
||||
typedef struct gas_rept {
|
||||
STAILQ_HEAD(reptlinelist, gas_rept_line) lines; /* repeated lines */
|
||||
unsigned long startline; /* line number of rept directive */
|
||||
unsigned long numrept; /* number of repititions to generate */
|
||||
unsigned long numdone; /* number of repititions executed so far */
|
||||
/*@null@*/ gas_rept_line *line; /* next line to repeat */
|
||||
size_t linepos; /* position to start pulling chars from line */
|
||||
int ended; /* seen endr directive yet? */
|
||||
|
||||
YYCTYPE *oldbuf; /* saved previous fill buffer */
|
||||
size_t oldbuflen; /* previous fill buffer length */
|
||||
size_t oldbufpos; /* position in previous fill buffer */
|
||||
} gas_rept;
|
||||
|
||||
enum gas_parser_state {
|
||||
INITIAL,
|
||||
COMMENT,
|
||||
|
|
@ -134,8 +114,6 @@ typedef struct yasm_parser_gas {
|
|||
yystype peek_tokval;
|
||||
char peek_tokch;
|
||||
|
||||
/*@null@*/ gas_rept *rept;
|
||||
|
||||
/* Index of local labels; what's stored here is the /next/ index,
|
||||
* so these are all 0 at start.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -50,82 +50,6 @@ RCSID("$Id$");
|
|||
#define TOK ((char *)s->tok)
|
||||
#define TOKLEN (size_t)(cursor-s->tok)
|
||||
|
||||
static size_t
|
||||
rept_input(yasm_parser_gas *parser_gas, /*@out@*/ YYCTYPE *buf,
|
||||
size_t max_size)
|
||||
{
|
||||
gas_rept *rept = parser_gas->rept;
|
||||
size_t numleft = max_size;
|
||||
YYCTYPE *bufp = buf;
|
||||
|
||||
/* If numrept is 0, copy out just the line end characters */
|
||||
if (rept->numrept == 0) {
|
||||
/* Skip first line, which contains .line */
|
||||
rept->line = STAILQ_NEXT(rept->line, link);
|
||||
if (!rept->line) {
|
||||
rept->numrept = 1;
|
||||
rept->numdone = 1;
|
||||
}
|
||||
while (rept->numrept == 0 && numleft > 0) {
|
||||
*bufp++ = rept->line->data[rept->line->len-1];
|
||||
rept->line = STAILQ_NEXT(rept->line, link);
|
||||
if (!rept->line) {
|
||||
rept->numrept = 1;
|
||||
rept->numdone = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Copy out the previous fill buffer until we're *really* done */
|
||||
if (rept->numdone == rept->numrept) {
|
||||
size_t numcopy = rept->oldbuflen - rept->oldbufpos;
|
||||
if (numcopy > numleft)
|
||||
numcopy = numleft;
|
||||
memcpy(bufp, &rept->oldbuf[rept->oldbufpos], numcopy);
|
||||
numleft -= numcopy;
|
||||
bufp += numcopy;
|
||||
rept->oldbufpos += numcopy;
|
||||
|
||||
if (rept->oldbufpos == rept->oldbuflen) {
|
||||
/* Delete lines, then delete rept and clear rept state */
|
||||
gas_rept_line *cur, *next;
|
||||
cur = STAILQ_FIRST(&rept->lines);
|
||||
while (cur) {
|
||||
next = STAILQ_NEXT(cur, link);
|
||||
yasm_xfree(cur->data);
|
||||
yasm_xfree(cur);
|
||||
cur = next;
|
||||
}
|
||||
yasm_xfree(rept->oldbuf);
|
||||
yasm_xfree(rept);
|
||||
parser_gas->rept = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
while (numleft > 0 && rept->numdone < rept->numrept) {
|
||||
/* Copy from line data to buf */
|
||||
size_t numcopy = rept->line->len - rept->linepos;
|
||||
if (numcopy > numleft)
|
||||
numcopy = numleft;
|
||||
memcpy(bufp, &rept->line->data[rept->linepos], numcopy);
|
||||
numleft -= numcopy;
|
||||
bufp += numcopy;
|
||||
rept->linepos += numcopy;
|
||||
|
||||
/* Update locations if needed */
|
||||
if (rept->linepos == rept->line->len) {
|
||||
rept->line = STAILQ_NEXT(rept->line, link);
|
||||
rept->linepos = 0;
|
||||
}
|
||||
if (rept->line == NULL) {
|
||||
rept->numdone++;
|
||||
rept->line = STAILQ_FIRST(&rept->lines);
|
||||
}
|
||||
}
|
||||
|
||||
return (max_size-numleft);
|
||||
}
|
||||
|
||||
/* Bridge function to convert byte-oriented parser with line-oriented
|
||||
* preprocessor.
|
||||
*/
|
||||
|
|
@ -197,10 +121,7 @@ fill(yasm_parser_gas *parser_gas, YYCTYPE *cursor)
|
|||
yasm_xfree(s->bot);
|
||||
s->bot = buf;
|
||||
}
|
||||
if (parser_gas->rept && parser_gas->rept->ended) {
|
||||
/* Pull from rept lines instead of preproc */
|
||||
cnt = rept_input(parser_gas, s->lim, BSIZE);
|
||||
} else if((cnt = preproc_input(parser_gas, s->lim, BSIZE)) == 0) {
|
||||
if((cnt = preproc_input(parser_gas, s->lim, BSIZE)) == 0) {
|
||||
s->eof = &s->lim[cnt]; *s->eof++ = '\n';
|
||||
}
|
||||
s->lim += cnt;
|
||||
|
|
@ -271,13 +192,10 @@ strbuf_append(size_t count, YYCTYPE *cursor, yasm_scanner *s, int ch)
|
|||
int
|
||||
gas_parser_lex(YYSTYPE *lvalp, yasm_parser_gas *parser_gas)
|
||||
{
|
||||
/*@null@*/ gas_rept *rept = parser_gas->rept;
|
||||
yasm_scanner *s = &parser_gas->s;
|
||||
YYCTYPE *cursor = s->cur;
|
||||
size_t count;
|
||||
YYCTYPE savech;
|
||||
int linestart;
|
||||
gas_rept_line *new_line;
|
||||
|
||||
/* Handle one token of lookahead */
|
||||
if (parser_gas->peek_token != NONE) {
|
||||
|
|
@ -292,10 +210,6 @@ gas_parser_lex(YYSTYPE *lvalp, yasm_parser_gas *parser_gas)
|
|||
if (s->eof && cursor == s->eof)
|
||||
return 0;
|
||||
|
||||
/* Handle rept */
|
||||
if (rept && !rept->ended)
|
||||
goto rept_directive;
|
||||
|
||||
/* Jump to proper "exclusive" states */
|
||||
switch (parser_gas->state) {
|
||||
case COMMENT:
|
||||
|
|
@ -642,106 +556,4 @@ stringconst_scan:
|
|||
goto stringconst_scan;
|
||||
}
|
||||
*/
|
||||
|
||||
rept_directive:
|
||||
strbuf = yasm_xmalloc(STRBUF_ALLOC_SIZE);
|
||||
strbuf_size = STRBUF_ALLOC_SIZE;
|
||||
count = 0;
|
||||
linestart = 1;
|
||||
|
||||
|
||||
rept_scan:
|
||||
SCANINIT();
|
||||
|
||||
/*!re2c
|
||||
[\n;] {
|
||||
/* Line ending, save in lines */
|
||||
new_line = yasm_xmalloc(sizeof(gas_rept_line));
|
||||
if (cursor == s->eof) {
|
||||
yasm_xfree(strbuf);
|
||||
return 0;
|
||||
}
|
||||
strbuf_append(count++, cursor, s, s->tok[0]);
|
||||
new_line->data = strbuf;
|
||||
new_line->len = count;
|
||||
STAILQ_INSERT_TAIL(&rept->lines, new_line, link);
|
||||
/* Allocate new strbuf */
|
||||
strbuf = yasm_xmalloc(STRBUF_ALLOC_SIZE);
|
||||
strbuf_size = STRBUF_ALLOC_SIZE;
|
||||
count = 0;
|
||||
/* Mark start of line */
|
||||
linestart = 1;
|
||||
goto rept_scan;
|
||||
}
|
||||
'.rept' {
|
||||
int i;
|
||||
if (linestart) {
|
||||
/* We don't support nested right now, error */
|
||||
yasm_error_set(YASM_ERROR_GENERAL,
|
||||
N_("nested rept not supported"));
|
||||
yasm_errwarn_propagate(parser_gas->errwarns, cur_line);
|
||||
}
|
||||
for (i=0; i<6; i++)
|
||||
strbuf_append(count++, cursor, s, s->tok[i]);
|
||||
goto rept_scan;
|
||||
}
|
||||
'.endr' {
|
||||
if (linestart) {
|
||||
/* We're done, kick off the main lexer */
|
||||
rept->line = STAILQ_FIRST(&rept->lines);
|
||||
if (!rept->line) {
|
||||
/* Didn't get any intervening data? Empty repeat, so
|
||||
* don't even bother.
|
||||
*/
|
||||
yasm_xfree(strbuf);
|
||||
yasm_xfree(rept);
|
||||
parser_gas->rept = NULL;
|
||||
} else {
|
||||
rept->ended = 1;
|
||||
|
||||
/* Add .line as first line to get line numbers correct */
|
||||
new_line = yasm_xmalloc(sizeof(gas_rept_line));
|
||||
new_line->data = yasm_xmalloc(40);
|
||||
sprintf((char *)new_line->data, ".line %lu;",
|
||||
rept->startline+1);
|
||||
new_line->len = strlen((char *)new_line->data);
|
||||
STAILQ_INSERT_HEAD(&rept->lines, new_line, link);
|
||||
|
||||
/* Save previous fill buffer */
|
||||
rept->oldbuf = parser_gas->s.bot;
|
||||
rept->oldbuflen = s->lim - s->bot;
|
||||
rept->oldbufpos = cursor - s->bot;
|
||||
|
||||
/* Reset fill */
|
||||
s->bot = NULL;
|
||||
s->tok = NULL;
|
||||
s->ptr = NULL;
|
||||
s->cur = NULL;
|
||||
s->lim = NULL;
|
||||
s->top = NULL;
|
||||
s->eof = NULL;
|
||||
cursor = NULL;
|
||||
YYFILL(1);
|
||||
}
|
||||
|
||||
goto scan;
|
||||
} else {
|
||||
int i;
|
||||
for (i=0; i<6; i++)
|
||||
strbuf_append(count++, cursor, s, s->tok[i]);
|
||||
goto rept_scan;
|
||||
}
|
||||
}
|
||||
|
||||
any {
|
||||
if (cursor == s->eof) {
|
||||
yasm_xfree(strbuf);
|
||||
return 0;
|
||||
}
|
||||
strbuf_append(count++, cursor, s, s->tok[0]);
|
||||
linestart = 0;
|
||||
goto rept_scan;
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue