diff options
author | H. Peter Anvin <hpa@zytor.com> | 2018-12-22 23:09:54 -0800 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2018-12-24 12:45:58 -0800 |
commit | 11599f49da963a0cf71970ad69fe66de981d35ee (patch) | |
tree | 0426512f6a8204d5a121b3e33caad33d525f22a7 | |
parent | e7c75e55212c8e88b5574ff746a375146bc02373 (diff) | |
download | nasm-11599f49da963a0cf71970ad69fe66de981d35ee.tar.gz |
Factor out size tokens and annotate with the corresponding size
There is space in the token table to explicitly encode the size
corresponding to a size token. We might as well do so...
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
-rw-r--r-- | asm/parser.c | 9 | ||||
-rw-r--r-- | asm/tokens.dat | 18 | ||||
-rw-r--r-- | include/nasm.h | 36 |
3 files changed, 42 insertions, 21 deletions
diff --git a/asm/parser.c b/asm/parser.c index c76696c2..9349e25e 100644 --- a/asm/parser.c +++ b/asm/parser.c @@ -767,7 +767,8 @@ is_expression: } first = false; op->type = 0; /* so far, no override */ - while (i == TOKEN_SPECIAL) { /* size specifiers */ + /* size specifiers */ + while (i == TOKEN_SPECIAL || i == TOKEN_SIZE) { switch (tokval.t_integer) { case S_BYTE: if (!setsize) /* we want to use only the first */ @@ -835,7 +836,8 @@ is_expression: mref = true; bracket = (i == '['); i = stdscan(NULL, &tokval); /* then skip the colon */ - while (i == TOKEN_SPECIAL || i == TOKEN_PREFIX) { + while (i == TOKEN_SPECIAL || i == TOKEN_SIZE || + i == TOKEN_PREFIX) { process_size_override(result, op); i = stdscan(NULL, &tokval); } @@ -880,7 +882,8 @@ is_expression: } i = stdscan(NULL, &tokval); /* then skip the colon */ - while (i == TOKEN_SPECIAL || i == TOKEN_PREFIX) { + while (i == TOKEN_SPECIAL || i == TOKEN_SIZE || + i == TOKEN_PREFIX) { process_size_override(result, op); i = stdscan(NULL, &tokval); } diff --git a/asm/tokens.dat b/asm/tokens.dat index d5345e19..bd89d0a0 100644 --- a/asm/tokens.dat +++ b/asm/tokens.dat @@ -60,24 +60,26 @@ xrelease bnd nobnd -% TOKEN_SPECIAL, 0, 0, S_* -abs +% TOKEN_SIZE, 0, SIZE_*, S_* byte +word dword +qword +tword +oword +yword +zword + +% TOKEN_SPECIAL, 0, 0, S_* +abs far long near nosplit -oword -qword rel short strict to -tword -word -yword -zword % TOKEN_ID, 0, TFLAG_WARN, 0 ptr diff --git a/include/nasm.h b/include/nasm.h index eb376b16..c2a80562 100644 --- a/include/nasm.h +++ b/include/nasm.h @@ -167,7 +167,8 @@ enum token_type { /* token types, other than chars */ TOKEN_INSN, /* instruction name */ TOKEN_HERE, /* $ */ TOKEN_BASE, /* $$ */ - TOKEN_SPECIAL, /* BYTE, WORD, DWORD, QWORD, FAR, NEAR, etc */ + TOKEN_SIZE, /* BYTE, WORD, DWORD, QWORD, etc */ + TOKEN_SPECIAL, /* REL, FAR, NEAR, STRICT, NOSPLIT, etc */ TOKEN_PREFIX, /* A32, O16, LOCK, REPNZ, TIMES, etc */ TOKEN_SHL, /* << or <<< */ TOKEN_SHR, /* >> */ @@ -1081,25 +1082,40 @@ extern const struct dfmt *dfmt; #define TYS_ELEMENTS(x) ((x) << 8) +/* Sizes corresponding to various tokens */ +enum byte_sizes { + SIZE_BYTE = 1, + SIZE_WORD = 2, + SIZE_DWORD = 4, + SIZE_QWORD = 8, + SIZE_TWORD = 10, + SIZE_OWORD = 16, + SIZE_YWORD = 32, + SIZE_ZWORD = 64 +}; + enum special_tokens { - SPECIAL_ENUM_START = PREFIX_ENUM_LIMIT, - S_ABS = SPECIAL_ENUM_START, - S_BYTE, + SIZE_ENUM_START = PREFIX_ENUM_LIMIT, + S_BYTE = SIZE_ENUM_START, + S_WORD, S_DWORD, + S_QWORD, + S_TWORD, + S_OWORD, + S_YWORD, + S_ZWORD, + SIZE_ENUM_LIMIT, + + SPECIAL_ENUM_START = SIZE_ENUM_LIMIT, + S_ABS = SPECIAL_ENUM_START, S_FAR, S_LONG, S_NEAR, S_NOSPLIT, - S_OWORD, - S_QWORD, S_REL, S_SHORT, S_STRICT, S_TO, - S_TWORD, - S_WORD, - S_YWORD, - S_ZWORD, SPECIAL_ENUM_LIMIT }; |