For constructs like TIMES xx RESB yy merge the TIMES and RESB and feed
a single reservation to the backend; this can (obviously) be
dramatically faster.
Add byte count in listings for <incbin> and repeat count to <rept>; to
make them more reasonable in length shorten to <bin ...> and <rep ...>
respectively, and don't require leading zeroes in bin/rep/res count.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Print a warning if one tries to assemble an obsolete instruction,
unless there is an exact match for the CPU directive.
For example:
CPU 386
POP CS ; Warning - obsolete instruction
CPU 8086
POP CS ; No warning
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Fix the definition of IF_CPU_LEVEL_MASK (which was missing the top
bit, IFM_ANY itself).
Add CPU definitions that we actually have into directiv.c.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Have warnings.pl give a warning(!) message if a warning definition is
found to be duplicated, including the location of both
definitions. Much better than silently creating bogus output.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
If an UTF-8 value exceeds 0x7fffffff, there is no legitimate encoding
for it. However, using FE or FF as leading bytes provide at least some
kind of encoding. This is assembly, and the programmer is (almost?)
always right. It might be worthwhile to add a suppressible warning for
invalid UTF-8 strings in general, though, including any character >
0x10ffff, surrogates, or a string that is constructed by hand.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Returning NULL makes more sense than returning the initial pointer
(the only other sensible alternative would be to return a pointer the
final null character.)
This currently can't happen, as all callers to nasm_skip_string()
currently explicitly tests for an initial quote.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
The merging of adjacent ' or " strings really does nothing but
introduce gratuitous incompatiblities; drop it.
Allow *some* control characters (BEL BS TAB ESC) in
nasm_unquote_cstr().
The ` state machine can be greatly simplified by treating \0 as just
another character and let it terminate the string in appropriate
contexts, just like `. The only difference with ` is when it occurs
in state st_backslash: you can't escape the null character.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
TOKEN_ID is from enum pp_token_type, but struct Type has enum
token_type. TOK_ID seems to be a matched one.s
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Split the code for getting a line of tokens from the code that sets
verror and detokenizes the resulting string.
While we are at it, merge the handling of EOF and ^Z into the general
loop in read_line().
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
The smacro expansion code was virtually impossible to understand, and
was leading to very strange failures. Clean it up, and do much better
handling of magic macros. This should also allow for recursive
macros, but recursive macros are extremely tricky in that it is very
hard to keep them from recursing forever, unless there is at least one
argument which is never expanded. They are not currently implemented.
Even so, I believe token pasting makes it possible to create infinite
loops; e.g.:
%define foo foo %+
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
In nasm_unquote_cstr(), disallow any control character, not just
NUL. This will matter when allowing quoting symbols.
Merge nasm_unquote() and nasm_unquote_cstr().
Strings can now be concatenated, C style: adjacent quoted strings
(including whitespace-separated) are merged into a single string.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
All directives which create single-line macros now have %i... variants
to define case-insensitive versions. Case insensitive rather sucks,
but at least this way it is consistent.
Single-line macro parameters can now be evaluated as a number, as done
by %assign. To do so, declare a parameter starting with =, for
example:
%define foo(x,=y) mov [x],macro_array_y
... would evaluate y as a number but leave x as a string.
NOTE: it would arguably be better to have this as a per-instance
basis, but it is easily handled by having a secondary macro called
with the same argument twice.
Finally, add a more consistent method for defining "magic" macros,
which need to be evaluated at runtime. For now, it is only used by the
special macros __FILE__, __LINE__, __BITS__, __PTR__, and __PASS__.
__PTR__ is a new macro which evaluates to word, dword or qword
matching the value of __BITS__.
The magic macro framework, however, provides a natural hook for a
future plug-in infrastructure to hook into a scripting language.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Zeroing reserved space in a progbits section really should be a
separate warning class, so it can be controlled independently.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
TOKEN_SIZE size values ended up in the wrong place, which caused
parser errors due to being mistaken as flags.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
"compiler.h" already includes a bunch of common include files. There
is absolutely no reason to duplicate them in individual files, and in
fact it robs us of central control of how these files are used.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
For almost everything we should use "nctype.h". Right now we don't
have a nasm_toupper() to use <ctype.h> for things that need toupper().
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
In BR 3392539, the error:
helloW.s:18: error: label `rurt' changed during code generation
[-w+error=label-redef-late]
... occurs a number of times after we have already issued an
error. This is because the erroring instruction computes to a
different size during code generation; this causes each subsequent
label to cause a phase error.
The phase error simply doesn't make much sense to report: if we are
already committed to erroring out, it is more likely an error cascade
rather than an error in its own right, so just suppress it in that
case.
Reported-by: <russvz@comcast.net>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
There is absolutely no reason not to include <string.h> globally, and
with the inline function for mempcpy() we need it there anyway.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
In list_emit we walk over listerr_head freeing the list,
but the head pointer remain carrying old value. Need
to clean it up once traverse is done to not access
already freed memory later.
https://bugzilla.nasm.us/show_bug.cgi?id=3392538
Reported-by: russvz@comcast.net
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
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>
With buffered warnings, most warnings *must* be issued on every pass,
so ERR_PASS1 is simply wrong in most cases.
ERR_PASS1 now means "force this warning to be output even in
pass_first(). This is to be used for the case where the warning is
only executed in pass_first() code; this is highly discouraged as it
means the warnings will not appear in the list file and subsequent
passes may make the warning suddenly vanish.
ERR_PASS2 just as before suppresses an error or warning unless we are
in pass_final().
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
The use of pass0, pass1, pass2, and "pass" passed as an argument is
really confusing and already caused a severe bug in the 2.14.01
release cycle. Clean them up and be far more explicit about what
various passes mean.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
We want to strongly encourage writers of warnings to create warning
categories, so remove the flagless nasm_warn() and change nasm_warnf()
to nasm_warn().
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
The -Ov option is useful but was undocumented.
Add an initialization to keep gcc from complaining at optimization
level -Og.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
For debugging preprocessed code, it is useful to be able to ignore
%line directives rather than having to filter them out externally.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
? in identifiers turns out to be used in the field even in non-TASM
mode. Resolve this by allowing it in an identifier still, but treat
'?' by itself the same as we would a keyword, meaning that it needs to
be separated from other identifier characters.
In other words:
a ? b : c ; conditional expression
a?b:c ; seg:off expression seg = a?b, off = c
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Make strlist_free() take a pointer to a pointer, so we can set it to
NULL.
Buffer warnings on a strlist until we either get an error or we are in
pass 2. Hopefully this should let us get rid of a lot of the ERR_PASS*
bullshit, which far too often causes messages to get lost.
asm/labels.c contains one example of a warning that cannot be made
correct with a specific pass number.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Make it a selectable option at allocation time if a strlist should
contain only unique strings or not. If not, we omit the hash table and
strlist_find() will not do anything.
Add printf()-style functions to a strlist.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>