Specifically if we encounter the PTR keyword

Issue a specific suppressible warning if we encounter the PTR keyword.
This usually indicates someone mistakenly using MASM syntax in NASM.

This introduces a generic infrastructure for issuing warnings for such
keywords.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
This commit is contained in:
H. Peter Anvin 2016-05-09 12:05:56 -07:00
parent 934f0478d4
commit 69550eac55
6 changed files with 18 additions and 4 deletions

2
nasm.c
View File

@ -171,6 +171,7 @@ static const struct warning {
{"hle", "invalid hle prefixes", true},
{"bnd", "invalid bnd prefixes", true},
{"zext-reloc", "relocation zero-extended to match output format", true},
{"ptr", "non-NASM keyword used in other assemblers", true},
};
static bool want_usage;
@ -1958,7 +1959,6 @@ static bool skip_this_pass(int severity)
if ((severity & ERR_MASK) > ERR_WARNING)
return false;
/*
* passn is 1 on the very first pass only.
* pass0 is 2 on the code-generation (final) pass only.

1
nasm.h
View File

@ -421,6 +421,7 @@ enum ccode { /* condition code names */
#define TFLAG_BRC_OPT (1 << 1) /* may or may not have braces. opmasks {k1} */
#define TFLAG_BRC_ANY (TFLAG_BRC | TFLAG_BRC_OPT)
#define TFLAG_BRDCAST (1 << 2) /* broadcasting decorator */
#define TFLAG_WARN (1 << 3) /* warning only, treat as ID */
static inline uint8_t get_cond_opcode(enum ccode c)
{

View File

@ -135,7 +135,8 @@ static inline vefunc nasm_set_verror(vefunc ve)
#define ERR_WARN_HLE WARN(13) /* bad HLE prefixes */
#define ERR_WARN_BND WARN(14) /* bad BND prefixes */
#define ERR_WARN_ZEXTRELOC WARN(15) /* relocation zero-extended */
#define ERR_WARN_MAX 15 /* the highest numbered one */
#define ERR_WARN_PTR WARN(16) /* not a NASM keyword */
#define ERR_WARN_MAX 16 /* the highest numbered one */
/*
* Wrappers around malloc, realloc and free. nasm_malloc will

View File

@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 1996-2009 The NASM Authors - All Rights Reserved
* Copyright 1996-2016 The NASM Authors - All Rights Reserved
* See the file AUTHORS included with the NASM distribution for
* the specific copyright holders.
*
@ -167,6 +167,11 @@ int stdscan(void *private_data, struct tokenval *tv)
* is it actually a register or instruction name, or what? */
token_type = nasm_token_hash(ourcopy, tv);
if (unlikely(tv->t_flag & TFLAG_WARN)) {
nasm_error(ERR_WARNING|ERR_PASS1|ERR_WARN_PTR,
"%s is not a NASM keyword", tv->t_charptr);
}
if (likely(!(tv->t_flag & TFLAG_BRC))) {
/* most of the tokens fall into this case */
return token_type;

4
test/ptr.asm Normal file
View File

@ -0,0 +1,4 @@
;; This should warn but still assemble, as the code is correct
mov eax,dword ptr
ptr:

View File

@ -1,6 +1,6 @@
## --------------------------------------------------------------------------
##
## Copyright 1996-2013 The NASM Authors - All Rights Reserved
## Copyright 1996-2016 The NASM Authors - All Rights Reserved
## See the file AUTHORS included with the NASM distribution for
## the specific copyright holders.
##
@ -76,6 +76,9 @@ word
yword
zword
% TOKEN_ID, 0, TFLAG_WARN, 0
ptr
% TOKEN_FLOAT, 0, 0, 0
__infinity__
__nan__